Skip to content
Snippets Groups Projects
Commit 78579b44 authored by Mark Chance's avatar Mark Chance Committed by Marc Burnie [AWS]
Browse files

set feature flag testing

(cherry picked from commit 47e6c6ff)
parent 322a9256
No related branches found
No related tags found
1 merge request!874Cherry-pick 'Fix mapping boolean values to string' into release/0.28
......@@ -15,7 +15,9 @@
package org.opengroup.osdu.indexer.schema.converter;
import com.google.common.collect.ImmutableMap;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.indexer.schema.converter.config.SchemaConverterPropertiesConfig;
......@@ -25,48 +27,66 @@ import org.opengroup.osdu.indexer.schema.converter.tags.Definitions;
import org.opengroup.osdu.indexer.schema.converter.tags.Items;
import org.opengroup.osdu.indexer.schema.converter.tags.TypeProperty;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.opengroup.osdu.indexer.config.IndexerConfigurationProperties.MAP_BOOL2STRING_FEATURE_NAME;
import org.opengroup.osdu.core.common.feature.IFeatureFlag;
import org.springframework.beans.factory.annotation.Autowired;
import static org.opengroup.osdu.indexer.config.IndexerConfigurationProperties.MAP_BOOL2STRING_FEATURE_NAME;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@Import({IFeatureFlag.class})
@ContextConfiguration(classes = {PropertiesProcessorTest.class, IFeatureFlag.class})
@SpringBootTest(classes = {IFeatureFlag.class})
public class PropertiesProcessorTest {
private static final String PATH = "given_path";
private static final String DEFINITIONS_PREFIX = "#/definitions/";
@Autowired
@MockBean
private IFeatureFlag featureFlagChecker;
private SchemaConverterPropertiesConfig schemaConverterConfig;
@Before
public void setup() throws IOException {
initMocks(this);
schemaConverterConfig = new SchemaConverterPropertiesConfig(featureFlagChecker);
}
@Test
public void should_fail_on_bad_reference_definition() {
PropertiesProcessor propertiesProcessor = new PropertiesProcessor(Mockito.mock(Definitions.class), new SchemaConverterPropertiesConfig());
PropertiesProcessor propertiesProcessor = new PropertiesProcessor(Mockito.mock(Definitions.class),
schemaConverterConfig);
propertiesProcessor.processRef(DEFINITIONS_PREFIX + "unknownDefinition");
assertEquals(1, propertiesProcessor.getErrors().size());
}
@Test
public void should_fail_on_wrong_definition_format() {
PropertiesProcessor propertiesProcessor = new PropertiesProcessor(Mockito.mock(Definitions.class), new SchemaConverterPropertiesConfig());
PropertiesProcessor propertiesProcessor = new PropertiesProcessor(Mockito.mock(Definitions.class), schemaConverterConfig);
propertiesProcessor.processRef("unknownDefinition");
assertEquals(1, propertiesProcessor.getErrors().size());
}
@Test
public void should_not_process_special_reference() {
assertFalse(new PropertiesProcessor(null, new SchemaConverterPropertiesConfig())
assertFalse(new PropertiesProcessor(null, schemaConverterConfig)
.processRef(DEFINITIONS_PREFIX + "a:b:anyCrsGeoJsonFeatureCollection:1.0.0").findAny().isPresent());
}
@Test
public void should_return_special_type() {
String res = new PropertiesProcessor(null, PATH, new SchemaConverterPropertiesConfig())
String res = new PropertiesProcessor(null, PATH, schemaConverterConfig)
.processRef(DEFINITIONS_PREFIX + "a:b:core_dl_geopoint:1.0.0").map(Object::toString).reduce("", String::concat);
assertEquals("{path=" + PATH + ", kind=core:dl:geopoint:1.0.0}", res);
}
......@@ -90,7 +110,7 @@ public class PropertiesProcessorTest {
String defName = "a:b:defName:1.0.0";
definitions.add(defName, definition);
String res = new PropertiesProcessor(definitions, PATH, new SchemaConverterPropertiesConfig())
String res = new PropertiesProcessor(definitions, PATH, schemaConverterConfig)
.processRef(DEFINITIONS_PREFIX + defName).map(Object::toString).reduce("", String::concat);
assertEquals(res, "{path="+ PATH + "." + propertyName + ", kind=string}");
}
......@@ -108,15 +128,29 @@ public class PropertiesProcessorTest {
properties.put(PATH, property);
allOfItem.setProperties(properties);
String res = new PropertiesProcessor(Mockito.mock(Definitions.class), new SchemaConverterPropertiesConfig())
String res = new PropertiesProcessor(Mockito.mock(Definitions.class), schemaConverterConfig)
.processItem(allOfItem).map(Object::toString).reduce("", String::concat);
assertEquals("{path=" + PATH + ", kind=int}", res);
}
@Test
public void should_return_boolean_from_boolean_item() {
public void should_return_boolean_from_boolean_item_FF_OFF() {
// in the earlier versions boolean was translated to bool and
// this caused mapping boolean values like text as entry in StorageType entry in map is boolean
internal_should_return_boolean_from_boolean_item(false);
}
@Test
public void should_return_boolean_from_boolean_item_FF_ON() {
// in the earlier versions boolean was translated to bool and
// this caused mapping boolean values like text as entry in StorageType entry in map is boolean
internal_should_return_boolean_from_boolean_item(true);
}
private void internal_should_return_boolean_from_boolean_item(boolean ffFlag) {
when(this.featureFlagChecker.isFeatureEnabled(MAP_BOOL2STRING_FEATURE_NAME)).thenReturn(ffFlag);
when(schemaConverterConfig.getFeatureFlagChecker().isFeatureEnabled(MAP_BOOL2STRING_FEATURE_NAME)).thenReturn(ffFlag);
schemaConverterConfig.resetToDefault();
AllOfItem allOfItem = new AllOfItem();
JaxRsDpsLog log = Mockito.mock(JaxRsDpsLog.class);
......@@ -127,10 +161,11 @@ public class PropertiesProcessorTest {
properties.put(PATH, property);
allOfItem.setProperties(properties);
String res = new PropertiesProcessor(Mockito.mock(Definitions.class), new SchemaConverterPropertiesConfig())
.processItem(allOfItem).map(Object::toString).reduce("", String::concat);
String preferredType = (this.featureFlagChecker.isFeatureEnabled(MAP_BOOL2STRING_FEATURE_NAME))?"string":"boolean";
assertEquals("{{path=${PATH}, kind=${preferredType}}}", res);
assertEquals(
"{path="+PATH+", kind="+ (ffFlag?"boolean":"bool")+"}",
new PropertiesProcessor(Mockito.mock(Definitions.class), schemaConverterConfig)
.processItem(allOfItem).map(Object::toString).reduce("", String::concat)
);
}
@Test
......@@ -146,9 +181,9 @@ public class PropertiesProcessorTest {
properties.put(PATH, property);
allOfItem.setProperties(properties);
String res = new PropertiesProcessor(Mockito.mock(Definitions.class), new SchemaConverterPropertiesConfig())
String res = new PropertiesProcessor(Mockito.mock(Definitions.class), schemaConverterConfig)
.processItem(allOfItem).map(Object::toString).reduce("", String::concat);
assertEquals("{path=" + PATH + ", kind=boolean}", res);
assertEquals("{path=" + PATH + ", kind=bool}", res);
}
@Test
......@@ -174,7 +209,7 @@ public class PropertiesProcessorTest {
AllOfItem allOfItem = new AllOfItem();
allOfItem.setProperties(allOfItemProperties);
String res = new PropertiesProcessor(Mockito.mock(Definitions.class), new SchemaConverterPropertiesConfig())
String res = new PropertiesProcessor(Mockito.mock(Definitions.class), schemaConverterConfig)
.processItem(allOfItem).map(Object::toString).reduce("", String::concat);
assertEquals("{path="+ PATH + ", kind=nested, properties=[{path="+ PATH + ", kind=int}]}",res);
}
......@@ -202,7 +237,7 @@ public class PropertiesProcessorTest {
AllOfItem allOfItem = new AllOfItem();
allOfItem.setProperties(allOfItemProperties);
String res = new PropertiesProcessor(Mockito.mock(Definitions.class), new SchemaConverterPropertiesConfig())
String res = new PropertiesProcessor(Mockito.mock(Definitions.class), schemaConverterConfig)
.processItem(allOfItem).map(Object::toString).reduce("", String::concat);
assertEquals("{path="+ PATH + ", kind=flattened}",res);
}
......@@ -229,7 +264,7 @@ public class PropertiesProcessorTest {
AllOfItem allOfItem = new AllOfItem();
allOfItem.setProperties(allOfItemProperties);
String res = new PropertiesProcessor(Mockito.mock(Definitions.class), new SchemaConverterPropertiesConfig())
String res = new PropertiesProcessor(Mockito.mock(Definitions.class), schemaConverterConfig)
.processItem(allOfItem).map(Object::toString).reduce("", String::concat);
assertEquals("{path="+ PATH + ", kind=[]object}",res);
}
......@@ -251,7 +286,7 @@ public class PropertiesProcessorTest {
AllOfItem allOfItem = new AllOfItem();
allOfItem.setProperties(allOfItemProperties);
String res = new PropertiesProcessor(Mockito.mock(Definitions.class), new SchemaConverterPropertiesConfig())
String res = new PropertiesProcessor(Mockito.mock(Definitions.class), schemaConverterConfig)
.processItem(allOfItem).map(Object::toString).reduce("", String::concat);
assertEquals("{path="+ PATH + ", kind=[]int}",res);
}
......
......@@ -16,6 +16,7 @@ package org.opengroup.osdu.indexer.schema.converter;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.inject.Inject;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -23,10 +24,14 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.opengroup.osdu.core.common.feature.IFeatureFlag;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.indexer.cache.partitionsafe.VirtualPropertiesSchemaCache;
import org.opengroup.osdu.indexer.schema.converter.config.SchemaConverterPropertiesConfig;
import org.opengroup.osdu.indexer.schema.converter.exeption.SchemaProcessingException;
import static org.opengroup.osdu.indexer.config.IndexerConfigurationProperties.MAP_BOOL2STRING_FEATURE_NAME;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.test.context.junit4.SpringRunner;
......@@ -42,10 +47,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;
import static org.mockito.Mockito.*;
@RunWith(SpringRunner.class)
@Configuration
public class SchemaToStorageFormatImplTest {
private static final String KIND = "KIND_VAL";
......@@ -54,17 +59,22 @@ public class SchemaToStorageFormatImplTest {
private JaxRsDpsLog jaxRsDpsLog = Mockito.mock(JaxRsDpsLog.class);
@InjectMocks
private SchemaToStorageFormatImpl schemaToStorageFormatImpl
= new SchemaToStorageFormatImpl(objectMapper, jaxRsDpsLog
, new SchemaConverterPropertiesConfig());
private SchemaToStorageFormatImpl schemaToStorageFormatImpl;
@Mock
private VirtualPropertiesSchemaCache virtualPropertiesSchemaCache;
private IFeatureFlag featureFlag;
@Before
public void init() {
MockitoAnnotations.initMocks(this);
featureFlag = Mockito.mock(IFeatureFlag.class);
when(featureFlag.isFeatureEnabled(MAP_BOOL2STRING_FEATURE_NAME)).thenReturn(true);
virtualPropertiesSchemaCache = Mockito.mock(VirtualPropertiesSchemaCache.class);
// when(virtualPropertiesSchemaCache.put(Mockito.anyString(), Mockito.any())).doNothing();
schemaToStorageFormatImpl
= new SchemaToStorageFormatImpl(objectMapper, jaxRsDpsLog,
new SchemaConverterPropertiesConfig(featureFlag), virtualPropertiesSchemaCache);
}
@Test
......@@ -175,11 +185,19 @@ public class SchemaToStorageFormatImplTest {
String json = getSchemaFromSchemaService(filename);
Map<String, Object> converted = schemaToStorageFormatImpl.convertToMap(json, kind);
Map<String, Object> expected = getStorageSchema(filename + ".res");
String resource = filename +
((featureFlag.isFeatureEnabled(MAP_BOOL2STRING_FEATURE_NAME))?".FF":"")+
".res";
if (!existsStorageSchema(resource)) resource = filename + ".res";
Map<String, Object> expected = getStorageSchema(resource);
compareSchemas(expected, converted, filename);
}
private boolean existsStorageSchema(String s) {
return null != this.getClass().getResource(s);
}
private Map<String, Object> getStorageSchema(String s) {
TypeReference<Map<String, Object>> typeRef
......
......@@ -40,6 +40,7 @@ import java.util.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.when;
import static org.opengroup.osdu.indexer.config.IndexerConfigurationProperties.MAP_BOOL2STRING_FEATURE_NAME;
import static org.opengroup.osdu.indexer.model.Constants.AS_INGESTED_COORDINATES_FEATURE_NAME;
@RunWith(SpringRunner.class)
......@@ -48,7 +49,8 @@ import static org.opengroup.osdu.indexer.model.Constants.AS_INGESTED_COORDINATES
GeometryDecimator.class, PointExtractor.class, GeometryConversionService.class, FeatureFlagCache.class,
DpsHeaders.class, JobStatus.class, SchemaConverterPropertiesConfig.class, JaxRsDpsLog.class,
ServiceAccountJwtClientMock.class, VirtualPropertiesSchemaCacheMock.class, VirtualPropertiesSchemaCache.class, RequestInfoMock.class,
IFeatureFlag.class, StringParser.class})
IFeatureFlag.class, StringParser.class}
)
public class StorageIndexerPayloadMapperTest {
public static final String FIRST_OBJECT_INNER_PROPERTY = "FirstObjectInnerProperty";
......@@ -282,6 +284,7 @@ public class StorageIndexerPayloadMapperTest {
@Test
public void mapDataPayloadTestAsIngestedCoordinates() {
when(this.asIngestedCoordinatesFeatureFlag.isFeatureEnabled(AS_INGESTED_COORDINATES_FEATURE_NAME)).thenReturn(true);
when(this.asIngestedCoordinatesFeatureFlag.isFeatureEnabled(MAP_BOOL2STRING_FEATURE_NAME)).thenReturn(true);
ArrayList<String> asIngestedCoordinatesPaths = new ArrayList<>(Arrays.asList("SpatialLocation.AsIngestedCoordinates"));
Map<String, Object> storageRecordData = new HashMap<>();
......@@ -318,6 +321,7 @@ public class StorageIndexerPayloadMapperTest {
@Test
public void mapDataPayloadTestAsIngestedCoordinatesGeographicBottomHoleLocationAndSpatialLocation() {
when(this.asIngestedCoordinatesFeatureFlag.isFeatureEnabled(AS_INGESTED_COORDINATES_FEATURE_NAME)).thenReturn(true);
when(this.asIngestedCoordinatesFeatureFlag.isFeatureEnabled(MAP_BOOL2STRING_FEATURE_NAME)).thenReturn(true);
ArrayList<String> asIngestedCoordinatesPaths = new ArrayList<>(Arrays.asList("GeographicBottomHoleLocation.AsIngestedCoordinates", "SpatialLocation.AsIngestedCoordinates"));
Map<String, Object> storageRecordData = new HashMap<>();
......@@ -381,6 +385,7 @@ public class StorageIndexerPayloadMapperTest {
@Test
public void mapDataPayloadTestAsIngestedCoordinatesWithEmptyZCoordinate() {
when(this.asIngestedCoordinatesFeatureFlag.isFeatureEnabled(AS_INGESTED_COORDINATES_FEATURE_NAME)).thenReturn(true);
when(this.asIngestedCoordinatesFeatureFlag.isFeatureEnabled(MAP_BOOL2STRING_FEATURE_NAME)).thenReturn(true);
ArrayList<String> asIngestedCoordinatesPaths = new ArrayList<>(Arrays.asList("SpatialLocation.AsIngestedCoordinates"));
Map<String, Object> storageRecordData = new HashMap<>();
......
......@@ -26,7 +26,7 @@
"path": "Endian"
},
{
"kind": "boolean",
"kind": "bool",
"path": "LossyCompressionIndicator"
},
{
......
......@@ -70,7 +70,7 @@
"path": "hasAchievedTotalDepth"
},
{
"kind": "boolean",
"kind": "bool",
"path": "isActive"
},
{
......@@ -354,4 +354,4 @@
"path": "wellboreType"
}
]
}
\ No newline at end of file
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment