Commit c1e6dce4 authored by Abhishek Kumar (SLB)'s avatar Abhishek Kumar (SLB)
Browse files

Adding JUnit

parent 5ac3cb70
Pipeline #117460 failed with stages
in 137 minutes and 39 seconds
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opengroup.osdu</groupId>
......@@ -100,6 +102,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.3</version>
</dependency>
<dependency>
......@@ -158,8 +161,14 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.2.2</version>
<version>2.13.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.13.3</version>
</dependency>
</dependencies>
<build>
......
......@@ -62,7 +62,7 @@ public class RemoveOperationHandler implements SchemaValidationHandler{
if(!pattern.matcher(path).matches() || !isAtRoot(path))
return false;
Iterator<String> fieldNameItr = schemaDiff.getTargetDefinition().fieldNames();
Iterator<String> fieldNameItr = schemaDiff.getTargetSchema().fieldNames();
while(fieldNameItr.hasNext()) {
String fieldName = fieldNameItr.next();
if(pattern.matcher(fieldName).matches()) {
......
package org.opengroup.osdu.schema.validation.version.handler.common;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.opengroup.osdu.schema.exceptions.ApplicationException;
import org.opengroup.osdu.schema.util.SchemaUtil;
import org.opengroup.osdu.schema.util.TestUtility;
import org.opengroup.osdu.schema.validation.version.SchemaValidationType;
import org.opengroup.osdu.schema.validation.version.handler.SchemaValidationHandler;
......@@ -28,6 +32,9 @@ public class RemoveOperationHandlerTest {
@InjectMocks
RemoveOperationHandler removeOperationHandler;
@Mock
SchemaUtil schemaUtil;
@Test
public void testCompare_ValidChange_RemovePropWithOldTrue() throws IOException, ApplicationException {
......@@ -45,6 +52,102 @@ public class RemoveOperationHandlerTest {
}
}
@Test
public void testCompare_ValidChange_RemovePropInDefinition() throws IOException, ApplicationException {
List<SchemaBreakingChanges> schemaBreakingChanges = new ArrayList<>();
Set<String> processedArrayPath = new HashSet<>();
SchemaHandlerVO schemaHandlerVO = getMockSchemaHandlerVO("/schema_compare/remove_operation/allowed/base-schema.json"
,"/schema_compare/remove_operation/allowed/new-schema.json");
schemaHandlerVO.setValidationType(SchemaValidationType.MINOR);
Mockito.when(schemaUtil.isValidSchemaVersionChange("osdu:wks:AbstractCommonResources:1.0.0", "osdu:wks:AbstractCommonResources:1.1.0", SchemaValidationType.MINOR)).thenReturn(true);
List<SchemaPatch> schemaPatchList = TestUtility.findSchemaPatch(schemaHandlerVO.getSourceSchema(), schemaHandlerVO.getTargetSchema());
for(SchemaPatch patch : schemaPatchList) {
removeOperationHandler.compare(schemaHandlerVO, patch, schemaBreakingChanges, processedArrayPath);
if(schemaBreakingChanges.size() > 0)
Assert.fail();
}
}
@Test
public void testCompare_ValidChange_RemovePropInDefinition_WithPatchUpgrage() throws IOException, ApplicationException {
List<SchemaBreakingChanges> schemaBreakingChanges = new ArrayList<>();
Set<String> processedArrayPath = new HashSet<>();
SchemaHandlerVO schemaHandlerVO = getMockSchemaHandlerVO("/schema_compare/remove_operation/allowed-patch/base-schema.json"
,"/schema_compare/remove_operation/allowed-patch/new-schema.json");
schemaHandlerVO.setValidationType(SchemaValidationType.MINOR);
Mockito.when(schemaUtil.isValidSchemaVersionChange("osdu:wks:AbstractCommonResources:1.1.0", "osdu:wks:AbstractCommonResources:1.1.1", SchemaValidationType.MINOR)).thenReturn(true);
List<SchemaPatch> schemaPatchList = TestUtility.findSchemaPatch(schemaHandlerVO.getSourceSchema(), schemaHandlerVO.getTargetSchema());
for(SchemaPatch patch : schemaPatchList) {
removeOperationHandler.compare(schemaHandlerVO, patch, schemaBreakingChanges, processedArrayPath);
if(schemaBreakingChanges.size() > 0)
Assert.fail();
}
}
@Test
public void testCompare_ValidChange_RemovePropInDefinition_Patch() throws IOException, ApplicationException {
List<SchemaBreakingChanges> schemaBreakingChanges = new ArrayList<>();
Set<String> processedArrayPath = new HashSet<>();
SchemaHandlerVO schemaHandlerVO = getMockSchemaHandlerVO("/schema_compare/remove_operation/allowed-patch/base-schema.json"
,"/schema_compare/remove_operation/allowed-patch/new-schema.json");
schemaHandlerVO.setValidationType(SchemaValidationType.PATCH);
Mockito.when(schemaUtil.isValidSchemaVersionChange("osdu:wks:AbstractCommonResources:1.1.0", "osdu:wks:AbstractCommonResources:1.1.1", SchemaValidationType.PATCH)).thenReturn(true);
List<SchemaPatch> schemaPatchList = TestUtility.findSchemaPatch(schemaHandlerVO.getSourceSchema(), schemaHandlerVO.getTargetSchema());
for(SchemaPatch patch : schemaPatchList) {
removeOperationHandler.compare(schemaHandlerVO, patch, schemaBreakingChanges, processedArrayPath);
if(schemaBreakingChanges.size() > 0)
Assert.fail();
}
}
@Test
public void testCompare_BreakingChange_RemovePropInDefinition() throws IOException, ApplicationException {
List<SchemaBreakingChanges> schemaBreakingChanges = new ArrayList<>();
Set<String> processedArrayPath = new HashSet<>();
SchemaHandlerVO schemaHandlerVO = getMockSchemaHandlerVO("/schema_compare/remove_operation/allowed/new-schema.json",
"/schema_compare/remove_operation/allowed/base-schema.json"
);
List<SchemaPatch> schemaPatchList = TestUtility.findSchemaPatch(schemaHandlerVO.getSourceSchema(), schemaHandlerVO.getTargetSchema());
schemaHandlerVO.setValidationType(SchemaValidationType.MINOR);
Mockito.when(schemaUtil.isValidSchemaVersionChange("osdu:wks:AbstractCommonResources:1.1.0", "osdu:wks:AbstractCommonResources:1.0.0", SchemaValidationType.MINOR)).thenReturn(false);
for(SchemaPatch patch : schemaPatchList) {
removeOperationHandler.compare(schemaHandlerVO, patch, schemaBreakingChanges, processedArrayPath);
if(schemaBreakingChanges.size() > 0)
Assert.assertTrue(true);
else
Assert.fail();
}
}
@Test
public void testCompare_BreakingChange_RemovePropInDefinition_Patch() throws IOException, ApplicationException {
List<SchemaBreakingChanges> schemaBreakingChanges = new ArrayList<>();
Set<String> processedArrayPath = new HashSet<>();
SchemaHandlerVO schemaHandlerVO = getMockSchemaHandlerVO("/schema_compare/remove_operation/allowed-patch/new-schema.json",
"/schema_compare/remove_operation/allowed-patch/base-schema.json"
);
List<SchemaPatch> schemaPatchList = TestUtility.findSchemaPatch(schemaHandlerVO.getSourceSchema(), schemaHandlerVO.getTargetSchema());
schemaHandlerVO.setValidationType(SchemaValidationType.PATCH);
Mockito.when(schemaUtil.isValidSchemaVersionChange("osdu:wks:AbstractCommonResources:1.1.1", "osdu:wks:AbstractCommonResources:1.1.0", SchemaValidationType.PATCH)).thenReturn(false);
for(SchemaPatch patch : schemaPatchList) {
removeOperationHandler.compare(schemaHandlerVO, patch, schemaBreakingChanges, processedArrayPath);
if(schemaBreakingChanges.size() > 0)
Assert.assertTrue(true);
else
Assert.fail();
}
}
@Test
public void testCompare_BreakingChange_ChangeFromTrueToFalse() throws IOException, ApplicationException {
......
{
"osdu:wks:AbstractCommonResources:1.1.0": {
"x-osdu-inheriting-from-kind": [],
"x-osdu-license": "Copyright 2021, The Open Group \\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.",
"$schema": "http://json-schema.org/draft-07/schema#",
"x-osdu-schema-source": "osdu:wks:AbstractCommonResources:1.1.0",
"description": "Common resources to be injected at root 'data' level for every entity, which is persistable in Storage. The insertion is performed by the OsduSchemaComposer script.",
"title": "OSDU Common Resources",
"type": "object",
"properties": {
"ResourceHomeRegionID": {
"x-osdu-relationship": [
{
"EntityType": "OSDURegion",
"GroupType": "reference-data"
}
],
"pattern": "^[\\w\\-\\.]+:reference-data\\-\\-OSDURegion:[\\w\\-\\.\\:\\%]+:[0-9]*$",
"description": "The name of the home [cloud environment] region for this OSDU resource object.",
"title": "Resource Home Region ID",
"type": "string"
},
"ResourceHostRegionIDs": {
"description": "The name of the host [cloud environment] region(s) for this OSDU resource object.",
"title": "Resource Host Region ID",
"type": "array",
"items": {
"x-osdu-relationship": [
{
"EntityType": "OSDURegion",
"GroupType": "reference-data"
}
],
"pattern": "^[\\w\\-\\.]+:reference-data\\-\\-OSDURegion:[\\w\\-\\.\\:\\%]+:[0-9]*$",
"type": "string"
}
},
"ResourceLifecycleStatus": {
"x-osdu-relationship": [
{
"EntityType": "ResourceLifecycleStatus",
"GroupType": "reference-data"
}
],
"pattern": "^[\\w\\-\\.]+:reference-data\\-\\-ResourceLifecycleStatus:[\\w\\-\\.\\:\\%]+:[0-9]*$",
"description": "Describes the current Resource Lifecycle status.",
"title": "Resource Lifecycle Status",
"type": "string"
},
"ResourceSecurityClassification": {
"x-osdu-relationship": [
{
"EntityType": "ResourceSecurityClassification",
"GroupType": "reference-data"
}
],
"pattern": "^[\\w\\-\\.]+:reference-data\\-\\-ResourceSecurityClassification:[\\w\\-\\.\\:\\%]+:[0-9]*$",
"description": "Classifies the security level of the resource.",
"title": "Resource Security Classification",
"type": "string"
},
"ResourceCurationStatus": {
"x-osdu-relationship": [
{
"EntityType": "ResourceCurationStatus",
"GroupType": "reference-data"
}
],
"pattern": "^[\\w\\-\\.]+:reference-data\\-\\-ResourceCurationStatus:[\\w\\-\\.\\:\\%]+:[0-9]*$",
"description": "Describes the current Curation status.",
"title": "Resource Curation Status",
"type": "string"
},
"ExistenceKind": {
"x-osdu-relationship": [
{
"EntityType": "ExistenceKind",
"GroupType": "reference-data"
}
],
"pattern": "^[\\w\\-\\.]+:reference-data\\-\\-ExistenceKind:[\\w\\-\\.\\:\\%]+:[0-9]*$",
"description": "Where does this data resource sit in the cradle-to-grave span of its existence?",
"title": "Existence Kind",
"type": "string"
},
"Source": {
"description": "The entity that produced the record, or from which it is received; could be an organization, agency, system, internal team, or individual. For informational purposes only, the list of sources is not governed.",
"title": "Data Source",
"type": "string"
}
},
"$id": "https://schema.osdu.opengroup.org/json/abstract/AbstractCommonResources.1.0.0.json"
}
}
\ No newline at end of file
{
"osdu:wks:AbstractCommonResources:1.1.1": {
"x-osdu-inheriting-from-kind": [],
"x-osdu-license": "Copyright 2021, The Open Group \\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.",
"$schema": "http://json-schema.org/draft-07/schema#",
"x-osdu-schema-source": "osdu:wks:AbstractCommonResources:1.1.1",
"description": "Common resources to be injected at root 'data' level for every entity, which is persistable in Storage. The insertion is performed by the OsduSchemaComposer script.",
"title": "OSDU Common Resources",
"type": "object",
"properties": {
"ResourceHomeRegionID": {
"x-osdu-relationship": [
{
"EntityType": "OSDURegion",
"GroupType": "reference-data"
}
],
"pattern": "^[\\w\\-\\.]+:reference-data\\-\\-OSDURegion:[\\w\\-\\.\\:\\%]+:[0-9]*$",
"description": "The name of the home [cloud environment] region for this OSDU resource object.",
"title": "Resource Home Region ID",
"type": "string"
},
"ResourceHostRegionIDs": {
"description": "The name of the host [cloud environment] region(s) for this OSDU resource object.",
"title": "Resource Host Region ID",
"type": "array",
"items": {
"x-osdu-relationship": [
{
"EntityType": "OSDURegion",
"GroupType": "reference-data"
}
],
"pattern": "^[\\w\\-\\.]+:reference-data\\-\\-OSDURegion:[\\w\\-\\.\\:\\%]+:[0-9]*$",
"type": "string"
}
},
"ResourceLifecycleStatus": {
"x-osdu-relationship": [
{
"EntityType": "ResourceLifecycleStatus",
"GroupType": "reference-data"
}
],
"pattern": "^[\\w\\-\\.]+:reference-data\\-\\-ResourceLifecycleStatus:[\\w\\-\\.\\:\\%]+:[0-9]*$",
"description": "Describes the current Resource Lifecycle status.",
"title": "Resource Lifecycle Status",
"type": "string"
},
"ResourceSecurityClassification": {
"x-osdu-relationship": [
{
"EntityType": "ResourceSecurityClassification",
"GroupType": "reference-data"
}
],
"pattern": "^[\\w\\-\\.]+:reference-data\\-\\-ResourceSecurityClassification:[\\w\\-\\.\\:\\%]+:[0-9]*$",
"description": "Classifies the security level of the resource.",
"title": "Resource Security Classification",
"type": "string"
},
"ResourceCurationStatus": {
"x-osdu-relationship": [
{
"EntityType": "ResourceCurationStatus",
"GroupType": "reference-data"
}
],
"pattern": "^[\\w\\-\\.]+:reference-data\\-\\-ResourceCurationStatus:[\\w\\-\\.\\:\\%]+:[0-9]*$",
"description": "Describes the current Curation status.",
"title": "Resource Curation Status",
"type": "string"
},
"ExistenceKind": {
"x-osdu-relationship": [
{
"EntityType": "ExistenceKind",
"GroupType": "reference-data"
}
],
"pattern": "^[\\w\\-\\.]+:reference-data\\-\\-ExistenceKind:[\\w\\-\\.\\:\\%]+:[0-9]*$",
"description": "Where does this data resource sit in the cradle-to-grave span of its existence?",
"title": "Existence Kind",
"type": "string"
},
"Source": {
"description": "The entity that produced the record, or from which it is received; could be an organization, agency, system, internal team, or individual. For informational purposes only, the list of sources is not governed.",
"title": "Data Source",
"type": "string"
}
},
"$id": "https://schema.osdu.opengroup.org/json/abstract/AbstractCommonResources.1.0.0.json"
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment