From 1528d77dabd9d43629d1364bcb58e38f628b2f2c Mon Sep 17 00:00:00 2001
From: Mark Chance <mark.chance@hitachivantara.com>
Date: Thu, 3 Oct 2024 11:17:47 -0400
Subject: [PATCH] test feature flag on and off

---
 .../SchemaToStorageFormatImplTest.java        | 37 ++++++++-----
 .../Generated/type/Type.1.0.0.json.FF.res     | 41 ++++++++++++++
 .../Generated/type/Type.1.0.0.json.res        |  4 +-
 .../WorkProduct.1.0.0.json.FF.res             | 53 +++++++++++++++++++
 .../work-product/WorkProduct.1.0.0.json.res   |  6 +--
 5 files changed, 124 insertions(+), 17 deletions(-)
 create mode 100644 indexer-core/src/test/resources/converter/R3-json-schema/Generated/type/Type.1.0.0.json.FF.res
 create mode 100644 indexer-core/src/test/resources/converter/R3-json-schema/Generated/work-product/WorkProduct.1.0.0.json.FF.res

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 d4141cd80..d1849ad57 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,12 +16,9 @@ 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;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 import org.opengroup.osdu.core.common.feature.IFeatureFlag;
@@ -65,16 +62,16 @@ public class SchemaToStorageFormatImplTest {
 
     private IFeatureFlag featureFlag;
 
+    private SchemaConverterPropertiesConfig schemaConverterPropertiesConfig;
     @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();
+        schemaConverterPropertiesConfig = new SchemaConverterPropertiesConfig(featureFlag);
         schemaToStorageFormatImpl
-                = new SchemaToStorageFormatImpl(objectMapper, jaxRsDpsLog,
-                    new SchemaConverterPropertiesConfig(featureFlag), virtualPropertiesSchemaCache);
+            = new SchemaToStorageFormatImpl(objectMapper, jaxRsDpsLog,
+                schemaConverterPropertiesConfig, virtualPropertiesSchemaCache);
     }
 
     @Test
@@ -171,23 +168,39 @@ public class SchemaToStorageFormatImplTest {
     }
 
     @Test
-    public void folderPassed() throws URISyntaxException, IOException {
+    public void folderPassedWithFF() throws URISyntaxException, IOException {
+        folderPassed(true);
+    }
+
+    @Test
+    public void folderPassedFFOff() throws URISyntaxException, IOException {
+        folderPassed(false);
+    }
 
+    public void folderPassed(boolean map2StringFF) throws URISyntaxException, IOException {
         String folder = "/converter/R3-json-schema";
         Path path = Paths.get(this.getClass().getResource(folder).toURI());
         Files.walk(path)
                 .filter(Files::isRegularFile)
                 .filter(f -> f.toString().endsWith(".json"))
-                .forEach(f -> testSingleFile(f.toString().replaceAll("\\\\", "/").substring(f.toString().replaceAll("\\\\", "/").indexOf(folder)), "osdu:osdu:Wellbore:1.0.0"));
+                .forEach(f -> testSingleFile(
+                        f.toString().replaceAll("\\\\", "/").substring(f.toString().replaceAll("\\\\", "/").indexOf(folder)),
+                        "osdu:osdu:Wellbore:1.0.0",
+                        map2StringFF
+                ));
     }
 
     private void testSingleFile(String filename, String kind) {
+        testSingleFile(filename, kind, false);
+    }
+
+    private void testSingleFile(String filename, String kind, boolean map2StringFF) {
+        when(featureFlag.isFeatureEnabled(MAP_BOOL2STRING_FEATURE_NAME)).thenReturn(map2StringFF);
+        schemaConverterPropertiesConfig.resetToDefault();
         String json = getSchemaFromSchemaService(filename);
 
         Map<String, Object> converted = schemaToStorageFormatImpl.convertToMap(json, kind);
-        String resource = filename +
-                ((featureFlag.isFeatureEnabled(MAP_BOOL2STRING_FEATURE_NAME))?".FF":"")+
-                ".res";
+        String resource = filename + (map2StringFF?".FF":"")+ ".res";
         if (!existsStorageSchema(resource)) resource = filename + ".res";
         Map<String, Object> expected = getStorageSchema(resource);
 
diff --git a/indexer-core/src/test/resources/converter/R3-json-schema/Generated/type/Type.1.0.0.json.FF.res b/indexer-core/src/test/resources/converter/R3-json-schema/Generated/type/Type.1.0.0.json.FF.res
new file mode 100644
index 000000000..c2e7cffc4
--- /dev/null
+++ b/indexer-core/src/test/resources/converter/R3-json-schema/Generated/type/Type.1.0.0.json.FF.res
@@ -0,0 +1,41 @@
+{
+  "kind": "osdu:osdu:Wellbore:1.0.0",
+  "schema": [
+    {
+      "kind": "string",
+      "path": "Description"
+    },
+    {
+      "kind": "string",
+      "path": "Schema"
+    },
+    {
+      "kind": "[]string",
+      "path": "NaturalKeys"
+    },
+    {
+      "kind": "string",
+      "path": "SchemaID"
+    },
+    {
+      "kind": "string",
+      "path": "Name"
+    },
+    {
+      "kind": "string",
+      "path": "SchemaKind"
+    },
+    {
+      "kind": "boolean",
+      "path": "IsReferenceValueType"
+    },
+    {
+      "kind": "[]link",
+      "path": "GovernanceAuthorities"
+    },
+    {
+      "kind": "string",
+      "path": "GovernanceModel"
+    }
+  ]
+}
diff --git a/indexer-core/src/test/resources/converter/R3-json-schema/Generated/type/Type.1.0.0.json.res b/indexer-core/src/test/resources/converter/R3-json-schema/Generated/type/Type.1.0.0.json.res
index ad5d44bec..c2817db53 100644
--- a/indexer-core/src/test/resources/converter/R3-json-schema/Generated/type/Type.1.0.0.json.res
+++ b/indexer-core/src/test/resources/converter/R3-json-schema/Generated/type/Type.1.0.0.json.res
@@ -26,7 +26,7 @@
       "path": "SchemaKind"
     },
     {
-      "kind": "boolean",
+      "kind": "bool",
       "path": "IsReferenceValueType"
     },
     {
@@ -38,4 +38,4 @@
       "path": "GovernanceModel"
     }
   ]
-}
\ No newline at end of file
+}
diff --git a/indexer-core/src/test/resources/converter/R3-json-schema/Generated/work-product/WorkProduct.1.0.0.json.FF.res b/indexer-core/src/test/resources/converter/R3-json-schema/Generated/work-product/WorkProduct.1.0.0.json.FF.res
new file mode 100644
index 000000000..ea7b4ff22
--- /dev/null
+++ b/indexer-core/src/test/resources/converter/R3-json-schema/Generated/work-product/WorkProduct.1.0.0.json.FF.res
@@ -0,0 +1,53 @@
+{
+  "kind": "osdu:osdu:Wellbore:1.0.0",
+  "schema": [
+    {
+      "kind": "[]link",
+      "path": "Components"
+    },
+    {
+      "kind": "boolean",
+      "path": "IsExtendedLoad"
+    },
+    {
+      "kind": "boolean",
+      "path": "IsDiscoverable"
+    },
+    {
+      "kind": "string",
+      "path": "Name"
+    },
+    {
+      "kind": "string",
+      "path": "Description"
+    },
+    {
+      "kind": "datetime",
+      "path": "CreationDateTime"
+    },
+    {
+      "kind": "[]string",
+      "path": "Tags"
+    },
+    {
+      "kind": "string",
+      "path": "SubmitterName"
+    },
+    {
+      "kind": "[]string",
+      "path": "BusinessActivities"
+    },
+    {
+      "kind": "[]string",
+      "path": "AuthorIDs"
+    },
+    {
+      "kind": "[]string",
+      "path": "Annotations"
+    },
+    {
+       "kind": "[]object",
+       "path": "LineageAssertions"
+    }
+  ]
+}
\ No newline at end of file
diff --git a/indexer-core/src/test/resources/converter/R3-json-schema/Generated/work-product/WorkProduct.1.0.0.json.res b/indexer-core/src/test/resources/converter/R3-json-schema/Generated/work-product/WorkProduct.1.0.0.json.res
index ea7b4ff22..d341d7f8d 100644
--- a/indexer-core/src/test/resources/converter/R3-json-schema/Generated/work-product/WorkProduct.1.0.0.json.res
+++ b/indexer-core/src/test/resources/converter/R3-json-schema/Generated/work-product/WorkProduct.1.0.0.json.res
@@ -6,11 +6,11 @@
       "path": "Components"
     },
     {
-      "kind": "boolean",
+      "kind": "bool",
       "path": "IsExtendedLoad"
     },
     {
-      "kind": "boolean",
+      "kind": "bool",
       "path": "IsDiscoverable"
     },
     {
@@ -50,4 +50,4 @@
        "path": "LineageAssertions"
     }
   ]
-}
\ No newline at end of file
+}
-- 
GitLab