From 005af95c8d2856e3a640936d94af088654f2e7bb Mon Sep 17 00:00:00 2001 From: Zhibin Mai <ZMai@slb.com> Date: Thu, 4 Aug 2022 18:07:52 -0500 Subject: [PATCH] Add unit tests --- .../service/StorageIndexerPayloadMapper.java | 1 - .../SchemaToStorageFormatImplTest.java | 31 ++++++++++++++++--- .../indexer/util/VirtualPropertyUtilTest.java | 31 +++++++++++++++++++ 3 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 indexer-core/src/test/java/org/opengroup/osdu/indexer/util/VirtualPropertyUtilTest.java 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 b71542b8c..3752dcb1b 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 f928fd5f8..3d2d3e0f8 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 000000000..8c9d2980d --- /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)); + } +} -- GitLab