aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorEdwin Lawrance <Edwin.Lawrance@amdocs.com>2018-09-13 11:19:43 +0100
committerLawrance, Edwin (el525a) <Edwin.Lawrance@amdocs.com>2018-09-14 11:01:13 +0100
commit82658daad05f982a8358581623f44a1554238a48 (patch)
tree6e6c757da7aa02c1a5745549791bf313a4f7a5c7 /src/test
parentfe84ae3b8d01ac2634d389f6b9d579319ea39f7a (diff)
Fix to not remove whitespaces in the payload to ES
Change-Id: I3547e79ff27220a49539d9cfdf48ac534f155f10 Issue-ID: AAI-1596 Signed-off-by: Edwin Lawrance <Edwin.Lawrance@amdocs.com>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/aai/sa/searchdbabstraction/util/ElasticSearchPayloadTranslatorTest.java19
-rw-r--r--src/test/resources/json/es-payload-translation.json22
-rw-r--r--src/test/resources/json/index-mapping.json28
3 files changed, 48 insertions, 21 deletions
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
index 11b2acb..ba5cb48 100644
--- a/src/test/java/org/onap/aai/sa/searchdbabstraction/util/ElasticSearchPayloadTranslatorTest.java
+++ b/src/test/java/org/onap/aai/sa/searchdbabstraction/util/ElasticSearchPayloadTranslatorTest.java
@@ -21,16 +21,19 @@
package org.onap.aai.sa.searchdbabstraction.util;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
import java.io.File;
+import java.io.FileInputStream;
+import org.apache.commons.io.IOUtils;
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";
+ private final String SIMPLE_DOC_SCHEMA_JSON = "src/test/resources/json/index-mapping.json";
@Before
public void setup() throws Exception {
@@ -38,13 +41,17 @@ public class ElasticSearchPayloadTranslatorTest {
}
@Test
- public void testPayloadTranslation_FromStringToText() throws Exception {
+ public void testPayloadTranslation() throws Exception {
+ String expectedErrMsg = "Sample error message for whitespace check";
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 documentJson = IOUtils.toString(new FileInputStream(schemaFile), "UTF-8");
+ assertTrue(documentJson.contains("\"type\": \"string\""));
+ assertTrue(documentJson.contains("\"index\": \"analyzed\""));
String translatedPayload = ElasticSearchPayloadTranslator.translateESPayload(documentJson);
- assertTrue(translatedPayload.contains("\"data-type\":\"text\""));
+ assertTrue(translatedPayload.contains("\"type\":\"text\""));
assertTrue(translatedPayload.contains("\"index\":true"));
+ assertTrue(translatedPayload.contains("\"fielddata\":true"));
+ assertFalse(documentJson.contains("\"index\":\"analyzed\""));
+ assertTrue(translatedPayload.contains("\"errMsg\":\""+expectedErrMsg+"\""));
}
}
diff --git a/src/test/resources/json/es-payload-translation.json b/src/test/resources/json/es-payload-translation.json
index e5290b0..58ed8f6 100644
--- a/src/test/resources/json/es-payload-translation.json
+++ b/src/test/resources/json/es-payload-translation.json
@@ -1,24 +1,16 @@
{
- "attr-translations": [
- {
- "from": "\"data-type\":\"string\"",
- "to": "\"data-type\":\"text\",\"fielddata\":true"
- },
+ "attr-translations": [
{
- "from": "\"type\":\"string\",\"index\":\"analyzed\"",
- "to": "\"type\":\"text\",\"index\":\"true\",\"fielddata\":true"
+ "query": "$..[?(@.type=='string' && @.index=='analyzed')]",
+ "update": {"type": "text", "index": true, "fielddata": true}
},
{
- "from": "\"type\":\"string\",\"index\":\"not_analyzed\"",
- "to": "\"type\":\"keyword\",\"index\":\"true\""
+ "query": "$..[?(@.type=='string' && @.index=='not_analyzed')]",
+ "update": {"type": "keyword", "index": true}
},
{
- "from": "\"type\":\"string\"",
- "to": "\"type\":\"text\",\"fielddata\":true"
- },
- {
- "from": "searchable",
- "to": "index"
+ "query": "$..[?(@.type=='string' && !@.index)]",
+ "update": {"type": "text", "fielddata": true}
}
]
} \ No newline at end of file
diff --git a/src/test/resources/json/index-mapping.json b/src/test/resources/json/index-mapping.json
new file mode 100644
index 0000000..e447092
--- /dev/null
+++ b/src/test/resources/json/index-mapping.json
@@ -0,0 +1,28 @@
+{
+ "fields": [
+ {"name": "validationId", "type": "string", "searchable": false},
+ {"name": "validationTimestamp1", "type": "date", "format": "MMM d y HH:m:s||dd-MM-yyyy HH:mm:ss||yyyy-MM-dd'T'HH:mm:ss.SSSZZ||MM\/dd\/yyyy||yyyyMMdd'T'HHmmssZ"},
+ {"name": "entityId", "type": "nested"},
+ {"name": "entityType", "type": "string", "index": "analyzed"},
+ {"name": "entityLink", "type": "string"},
+
+ {"name": "resourceVersion", "type": "string", "index": "not_analyzed"},
+ {"name": "violations", "type": "nested", "sub-fields": [
+ {"name": "violationId", "type": "string"},
+ {"name": "violationTimestamp", "type": "date", "format": "MMM d y HH:m:s||dd-MM-yyyy HH:mm:ss||yyyy-MM-dd'T'HH:mm:ss.SSSZZ||MM\/dd\/yyyy||yyyyMMdd'T'HHmmssZ"},
+ {"name": "modelName", "type": "string"},
+ {"name": "category", "type": "string"},
+ {"name": "severity", "type": "string"},
+ {"name": "violationType", "type": "string"},
+ {"name": "validationRule", "type": "string"},
+ {"name": "violationDetails", "type": "nested", "sub-fields": [
+ {"name": "entityId", "type": "nested"},
+ {"name": "entityType", "type": "string"},
+ {"name": "modelName", "type": "string"},
+ {"name": "MISSING_REL", "type": "string"}
+ ]},
+ {"name": "errorMessage", "type": "string", "errMsg": "Sample error message for whitespace check"}
+ ]}
+ ]
+
+}