From 00b644fb0809fbb2419549a97b39c2634f3ebdef Mon Sep 17 00:00:00 2001
From: Sviatoslav Nekhaienko <snekhaienko@slb.com>
Date: Thu, 10 Dec 2020 16:24:00 +0200
Subject: [PATCH] remove hardcoded v1

---
 .../schema/converter/PropertiesProcessor.java |   6 +-
 .../schema/converter/tags/Definition.java     |   1 -
 .../converter/PropertiesProcessorTest.java    | 102 ++++++++++++++++++
 3 files changed, 105 insertions(+), 4 deletions(-)
 create mode 100644 indexer-core/src/test/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessorTest.java

diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessor.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessor.java
index 4d9c1af58..d51c78fc2 100644
--- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessor.java
+++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessor.java
@@ -74,8 +74,8 @@ public class PropertiesProcessor {
         this.pathPrefixWithDot = Objects.isNull(pathPrefix)  || pathPrefix.isEmpty() ? "" : pathPrefix + ".";
     }
 
-    protected Stream<Map<String, Object>> processItem(AllOfItem allOfItem) {
-        Preconditions.checkNotNull(allOfItem, "ref cannot be null");
+    public Stream<Map<String, Object>> processItem(AllOfItem allOfItem) {
+        Preconditions.checkNotNull(allOfItem, "allOfItem cannot be null");
 
         String ref = allOfItem.getRef();
 
@@ -84,7 +84,7 @@ public class PropertiesProcessor {
     }
 
     public Stream<Map<String, Object>> processRef(String ref) {
-        Preconditions.checkNotNull(ref, "allOfItem cannot be null");
+        Preconditions.checkNotNull(ref, "reference cannot be null");
 
         if (!ref.contains(DEF_PREFIX)) {
             log.warning("Unknown definition:" + ref);
diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/tags/Definition.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/tags/Definition.java
index 942f031f6..f1b820f38 100644
--- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/tags/Definition.java
+++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/tags/Definition.java
@@ -20,6 +20,5 @@ import java.util.Map;
 
 @Data
 public class Definition {
-    private String type;
     private Map<String, TypeProperty> properties;
 }
diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessorTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessorTest.java
new file mode 100644
index 000000000..ada399a25
--- /dev/null
+++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessorTest.java
@@ -0,0 +1,102 @@
+// Copyright 2017-2020, Schlumberger
+//
+// Licensed 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.
+
+package org.opengroup.osdu.indexer.schema.converter;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
+import org.opengroup.osdu.core.common.model.http.AppException;
+import org.opengroup.osdu.indexer.schema.converter.tags.AllOfItem;
+import org.opengroup.osdu.indexer.schema.converter.tags.Definition;
+import org.opengroup.osdu.indexer.schema.converter.tags.Definitions;
+import org.opengroup.osdu.indexer.schema.converter.tags.TypeProperty;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+public class PropertiesProcessorTest {
+
+    private static final String PATH = "given_path";
+    private static final String DEFINITIONS_PREFIX = "#/definitions/";
+
+    @Test(expected = AppException.class)
+    public void should_fail_on_unknown_reference_definition() {
+        JaxRsDpsLog log = Mockito.mock(JaxRsDpsLog.class);
+
+        new PropertiesProcessor(Mockito.mock(Definitions.class), log).processRef(DEFINITIONS_PREFIX + "unknownDefinition");
+    }
+
+    @Test
+    public void should_not_process_special_reference() {
+        JaxRsDpsLog log = Mockito.mock(JaxRsDpsLog.class);
+
+        assertFalse(new PropertiesProcessor(null, log)
+                .processRef(DEFINITIONS_PREFIX + "anyCrsGeoJsonFeatureCollection").findAny().isPresent());
+    }
+
+    @Test
+    public void should_return_special_type() {
+        JaxRsDpsLog log = Mockito.mock(JaxRsDpsLog.class);
+
+        String res = new PropertiesProcessor(null, PATH, log)
+                .processRef(DEFINITIONS_PREFIX + "core_dl_geopoint").map(Object::toString).reduce("", String::concat);
+        assertEquals("{path=" + PATH + ", kind=core:dl:geopoint:1.0.0}", res);
+    }
+
+    @Test
+    public void should_process_definition_correctly() {
+        JaxRsDpsLog log = Mockito.mock(JaxRsDpsLog.class);
+
+        Definitions definitions = new Definitions();
+        Definition definition = new Definition();
+
+        TypeProperty property = new TypeProperty();
+        property.setFormat("string");
+        String propertyName = "propName";
+
+        Map<String, TypeProperty> properties = new LinkedHashMap<>();
+        properties.put(propertyName, property);
+
+        definition.setProperties(properties);
+
+        String defName = "defName";
+        definitions.add(defName, definition);
+
+        String res = new PropertiesProcessor(definitions, PATH, log)
+                .processRef(DEFINITIONS_PREFIX + defName).map(Object::toString).reduce("", String::concat);
+        assertEquals(res, "{path="+ PATH + "." + propertyName + ", kind=string}");
+    }
+
+    @Test
+    public void should_return_int_item() {
+        JaxRsDpsLog log = Mockito.mock(JaxRsDpsLog.class);
+
+        AllOfItem allOfItem = new AllOfItem();
+
+        TypeProperty property = new TypeProperty();
+        property.setFormat("integer");
+
+        Map<String, TypeProperty> properties = new LinkedHashMap<>();
+        properties.put(PATH, property);
+        allOfItem.setProperties(properties);
+
+        String res = new PropertiesProcessor(Mockito.mock(Definitions.class), log)
+                .processItem(allOfItem).map(Object::toString).reduce("", String::concat);
+        assertEquals("{path=" + PATH + ", kind=int}", res);
+    }
+}
\ No newline at end of file
-- 
GitLab