aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorEdwin Lawrance <Edwin.Lawrance@amdocs.com>2018-07-12 16:28:57 +0100
committerEdwin Lawrance <Edwin.Lawrance@amdocs.com>2018-08-01 17:23:05 +0100
commit8fb6b69f8ddc607d0413dc851f629a2e300e1be9 (patch)
tree0cff609b5a0d334781230d93a3b62692763f994f /src/test
parent77ce5bb14520c262f27995da98e13f64fb9912f5 (diff)
Updating Search service to be ES 6.1.2 compliant
Payload to Elastic Search is translated to comply ES6.1.2 PUT and POST calls now have content-type header Added functionality for dynamic templates Change-Id: I2a44a8a9999ec01a3bad1fb6999fe35bb6ef70d1 Issue-ID: AAI-1376 Signed-off-by: Edwin Lawrance <Edwin.Lawrance@amdocs.com>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/aai/sa/rest/IndexApiTest.java9
-rw-r--r--src/test/java/org/onap/aai/sa/rest/StubEsController.java9
-rw-r--r--src/test/java/org/onap/aai/sa/searchdbabstraction/util/ElasticSearchPayloadTranslatorTest.java50
-rw-r--r--src/test/resources/json/dynamic-custom-template.json12
-rw-r--r--src/test/resources/json/es-payload-translation.json24
5 files changed, 101 insertions, 3 deletions
diff --git a/src/test/java/org/onap/aai/sa/rest/IndexApiTest.java b/src/test/java/org/onap/aai/sa/rest/IndexApiTest.java
index 8f3bfac..60e798a 100644
--- a/src/test/java/org/onap/aai/sa/rest/IndexApiTest.java
+++ b/src/test/java/org/onap/aai/sa/rest/IndexApiTest.java
@@ -21,6 +21,7 @@
package org.onap.aai.sa.rest;
+import org.junit.Before;
// import org.glassfish.jersey.server.ResourceConfig;
// import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;
@@ -75,6 +76,11 @@ public class IndexApiTest {
// }
//
//
+
+ @Before
+ public void setup() throws Exception {
+ System.setProperty("CONFIG_HOME", System.getProperty("user.dir")+ File.separator + "src/test/resources/json");
+ }
/**
* Tests the dynamic shcema creation flow that send the request
@@ -177,7 +183,8 @@ public class IndexApiTest {
+ "\"tokenizer\": \"whitespace\","
+ "\"filter\": [\"lowercase\",\"asciifolding\"]}}}}";
String EXPECTED_MAPPINGS =
- "{\"properties\": {"
+ "{\"dynamic_templates\":[{\"strings\":{\"match_mapping_type\":\"string\",\"match\":\"*\",\"mapping\":{\"type\":\"text\",\"fielddata\":true}}}]"
+ + ",\"properties\": {"
+ "\"serverName\": {"
+ "\"type\": \"string\", "
+ "\"index\": \"analyzed\", "
diff --git a/src/test/java/org/onap/aai/sa/rest/StubEsController.java b/src/test/java/org/onap/aai/sa/rest/StubEsController.java
index fe72090..8cd25a6 100644
--- a/src/test/java/org/onap/aai/sa/rest/StubEsController.java
+++ b/src/test/java/org/onap/aai/sa/rest/StubEsController.java
@@ -31,6 +31,7 @@ import org.onap.aai.sa.searchdbabstraction.util.DocumentSchemaUtil;
import org.onap.aai.sa.searchdbabstraction.entity.Document;
import org.onap.aai.sa.rest.DocumentSchema;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -67,8 +68,12 @@ public class StubEsController implements DocumentStoreInterface {
OperationResult opResult = new OperationResult();
opResult.setResultCode(200);
- opResult.setResult(index + "@" + analysisConfig.getEsIndexSettings() + "@"
- + DocumentSchemaUtil.generateDocumentMappings(documentSchema));
+ try {
+ opResult.setResult(index + "@" + analysisConfig.getEsIndexSettings() + "@"
+ + DocumentSchemaUtil.generateDocumentMappings(documentSchema));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
return opResult;
}
diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/util/ElasticSearchPayloadTranslatorTest.java b/src/test/java/org/onap/aai/sa/searchdbabstraction/util/ElasticSearchPayloadTranslatorTest.java
new file mode 100644
index 0000000..11b2acb
--- /dev/null
+++ b/src/test/java/org/onap/aai/sa/searchdbabstraction/util/ElasticSearchPayloadTranslatorTest.java
@@ -0,0 +1,50 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.sa.searchdbabstraction.util;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.aai.sa.rest.TestUtils;
+
+public class ElasticSearchPayloadTranslatorTest {
+
+ private final String SIMPLE_DOC_SCHEMA_JSON = "src/test/resources/json/simpleDocument.json";
+
+ @Before
+ public void setup() throws Exception {
+ System.setProperty("CONFIG_HOME", System.getProperty("user.dir")+ File.separator + "src/test/resources/json");
+ }
+
+ @Test
+ public void testPayloadTranslation_FromStringToText() throws Exception {
+ File schemaFile = new File(SIMPLE_DOC_SCHEMA_JSON);
+ String documentJson = TestUtils.readFileToString(schemaFile);
+ assertTrue(documentJson.contains("\"data-type\":\"string\""));
+ assertTrue(documentJson.contains("\"searchable\":true"));
+ String translatedPayload = ElasticSearchPayloadTranslator.translateESPayload(documentJson);
+ assertTrue(translatedPayload.contains("\"data-type\":\"text\""));
+ assertTrue(translatedPayload.contains("\"index\":true"));
+ }
+}
diff --git a/src/test/resources/json/dynamic-custom-template.json b/src/test/resources/json/dynamic-custom-template.json
new file mode 100644
index 0000000..a7bd5ae
--- /dev/null
+++ b/src/test/resources/json/dynamic-custom-template.json
@@ -0,0 +1,12 @@
+"dynamic_templates":[
+ {
+ "strings":{
+ "match_mapping_type":"string",
+ "match": "*",
+ "mapping":{
+ "type":"text",
+ "fielddata":true
+ }
+ }
+ }
+], \ No newline at end of file
diff --git a/src/test/resources/json/es-payload-translation.json b/src/test/resources/json/es-payload-translation.json
new file mode 100644
index 0000000..e5290b0
--- /dev/null
+++ b/src/test/resources/json/es-payload-translation.json
@@ -0,0 +1,24 @@
+{
+ "attr-translations": [
+ {
+ "from": "\"data-type\":\"string\"",
+ "to": "\"data-type\":\"text\",\"fielddata\":true"
+ },
+ {
+ "from": "\"type\":\"string\",\"index\":\"analyzed\"",
+ "to": "\"type\":\"text\",\"index\":\"true\",\"fielddata\":true"
+ },
+ {
+ "from": "\"type\":\"string\",\"index\":\"not_analyzed\"",
+ "to": "\"type\":\"keyword\",\"index\":\"true\""
+ },
+ {
+ "from": "\"type\":\"string\"",
+ "to": "\"type\":\"text\",\"fielddata\":true"
+ },
+ {
+ "from": "searchable",
+ "to": "index"
+ }
+ ]
+} \ No newline at end of file