diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageIndexerPayloadMapper.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageIndexerPayloadMapper.java index b71542b8cf0d4e4187ca926e0b2cbf11b4065d8f..3752dcb1b44ecb5f473eb8c9dee6de34f2e5e4dc 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageIndexerPayloadMapper.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageIndexerPayloadMapper.java @@ -39,7 +39,6 @@ public class StorageIndexerPayloadMapper { private JobStatus jobStatus; @Inject private SchemaConverterConfig schemaConfig; - @Inject private IVirtualPropertiesSchemaCache virtualPropertiesSchemaCache; diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/schema/converter/SchemaToStorageFormatImplTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/schema/converter/SchemaToStorageFormatImplTest.java index f928fd5f89faa984683c12c94e6633d171b9f116..3d2d3e0f8ac966c4fe888fa16f44b8611c7e0299 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/schema/converter/SchemaToStorageFormatImplTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/schema/converter/SchemaToStorageFormatImplTest.java @@ -16,13 +16,19 @@ package org.opengroup.osdu.indexer.schema.converter; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.indexer.schema.converter.config.SchemaConverterPropertiesConfig; import org.opengroup.osdu.indexer.schema.converter.exeption.SchemaProcessingException; -import org.springframework.boot.test.context.SpringBootTest; +import org.opengroup.osdu.indexer.schema.converter.interfaces.IVirtualPropertiesSchemaCache; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; +import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; import java.net.URISyntaxException; @@ -36,8 +42,10 @@ import java.util.Map; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; -@SpringBootTest +@RunWith(SpringRunner.class) public class SchemaToStorageFormatImplTest { private static final String KIND = "KIND_VAL"; @@ -45,11 +53,20 @@ public class SchemaToStorageFormatImplTest { private ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build(); private JaxRsDpsLog jaxRsDpsLog = Mockito.mock(JaxRsDpsLog.class); - + + @InjectMocks private SchemaToStorageFormatImpl schemaToStorageFormatImpl = new SchemaToStorageFormatImpl(objectMapper, jaxRsDpsLog , new SchemaConverterPropertiesConfig()); + @Mock + private IVirtualPropertiesSchemaCache virtualPropertiesSchemaCache; + + @Before + public void init(){ + MockitoAnnotations.initMocks(this); + } + @Test public void dotsDefinitionFormat() { testSingleFile("/converter/new-definitions-format/colons-sample.json", "osdu:osdu:Wellbore:1.0.0"); @@ -130,6 +147,12 @@ public class SchemaToStorageFormatImplTest { testSingleFile("/converter/index-hints/nested-type-schema.json", "osdu:osdu:Wellbore:1.0.0"); } + @Test + public void virtualProperties() { + testSingleFile("/converter/index-virtual-properties/virtual-properties-schema.json", "osdu:wks:master-data--Wellbore:1.0.0"); + verify(this.virtualPropertiesSchemaCache, times(1)).put(Mockito.anyString(), Mockito.any()); + } + @Test public void folderPassed() throws URISyntaxException, IOException { @@ -194,4 +217,4 @@ public class SchemaToStorageFormatImplTest { Map<String, String> found = exp.stream().filter(e->item.get("path").equals(e.get("path"))).findAny().get(); assertEquals("File:" + filename + ", in " + itemPath, found.get("kind"), item.get("kind")); } -} \ No newline at end of file +} diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/VirtualPropertyUtilTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/VirtualPropertyUtilTest.java new file mode 100644 index 0000000000000000000000000000000000000000..8c9d2980d2012bad2a196c7a5d7be1a6b8733d3f --- /dev/null +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/VirtualPropertyUtilTest.java @@ -0,0 +1,31 @@ +package org.opengroup.osdu.indexer.util; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +public class VirtualPropertyUtilTest { + + @Test + public void isPropertyPathMatched() { + Assert.assertTrue(VirtualPropertyUtil.isPropertyPathMatched("data.FacilityName", "data.FacilityName")); + Assert.assertTrue(VirtualPropertyUtil.isPropertyPathMatched("data.ProjectedBottomHoleLocation.Wgs84Coordinates", "data.ProjectedBottomHoleLocation")); + + Assert.assertFalse(VirtualPropertyUtil.isPropertyPathMatched("data.FacilityName", "data.FacilityNameAliase")); + Assert.assertFalse(VirtualPropertyUtil.isPropertyPathMatched("data.ProjectedBottomHoleLocation.Wgs84Coordinates", "data.ProjectedBottomHole")); + Assert.assertFalse(VirtualPropertyUtil.isPropertyPathMatched("", "data.ProjectedBottomHole")); + Assert.assertFalse(VirtualPropertyUtil.isPropertyPathMatched(null, "data.ProjectedBottomHole")); + } + + @Test + public void removeDataPrefix() { + Assert.assertEquals("FacilityName", VirtualPropertyUtil.removeDataPrefix("data.FacilityName")); + Assert.assertEquals("FacilityName", VirtualPropertyUtil.removeDataPrefix("FacilityName")); + Assert.assertEquals("ProjectedBottomHoleLocation", VirtualPropertyUtil.removeDataPrefix("data.ProjectedBottomHoleLocation")); + Assert.assertEquals("ProjectedBottomHoleLocation", VirtualPropertyUtil.removeDataPrefix("ProjectedBottomHoleLocation")); + Assert.assertEquals("", VirtualPropertyUtil.removeDataPrefix("")); + Assert.assertNull(VirtualPropertyUtil.removeDataPrefix(null)); + } +}