From 06d31abe3065205c87447687ad87c05e602c97d7 Mon Sep 17 00:00:00 2001 From: renealr Date: Mon, 19 Mar 2018 10:50:27 -0400 Subject: add endpoint to query suggestion via ES Added logic to ensure that search data service is able to handle suggests type request Issue-ID: AAI-896 Change-Id: I11b3e8dadc5f7023017f01055c24e9c014813eb5 Signed-off-by: renealr --- .../org/onap/aai/sa/rest/StubEsController.java | 67 ++++++++++++---------- .../dao/ElasticSearchHttpControllerTest.java | 23 +++++--- 2 files changed, 54 insertions(+), 36 deletions(-) (limited to 'src/test/java') 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 d5d77ab..c792391 100644 --- a/src/test/java/org/onap/aai/sa/rest/StubEsController.java +++ b/src/test/java/org/onap/aai/sa/rest/StubEsController.java @@ -35,9 +35,8 @@ import java.util.HashMap; import java.util.Map; /** - * This class implements a stubbed version of the document store DAO so - * that we can run unit tests without trying to connect to a real - * document store. + * This class implements a stubbed version of the document store DAO so that we can run unit tests + * without trying to connect to a real document store. */ public class StubEsController implements DocumentStoreInterface { @@ -48,7 +47,7 @@ public class StubEsController implements DocumentStoreInterface { /** * */ - //private IndexAPIHarness indexAPIHarness; + // private IndexAPIHarness indexAPIHarness; StubEsController() { analysisConfig = new AnalysisConfiguration(); @@ -56,10 +55,8 @@ public class StubEsController implements DocumentStoreInterface { "src/test/resources/json/analysis-config.json"); } - @Override - public OperationResult createIndex(String index, - DocumentSchema documentSchema) { + public OperationResult createIndex(String index, DocumentSchema documentSchema) { // Just return an OK result, with the parameters that we were passed // bundled in the response string. This allows unit tests to validate @@ -77,7 +74,8 @@ public class StubEsController implements DocumentStoreInterface { public OperationResult createDynamicIndex(String index, String dynamicSchema) { OperationResult opResult = new OperationResult(); opResult.setResultCode(200); - // Directly return the json as this flow should not edit the json in any way + // Directly return the json as this flow should not edit the json in any + // way opResult.setResult(dynamicSchema); return opResult; } @@ -98,11 +96,9 @@ public class StubEsController implements DocumentStoreInterface { } @Override - public DocumentOperationResult createDocument(String indexName, - DocumentStoreDataEntity document, - boolean allowImplicitIndexCreation) - throws DocumentStoreOperationException { - + public DocumentOperationResult createDocument(String indexName, DocumentStoreDataEntity document, + boolean allowImplicitIndexCreation) throws DocumentStoreOperationException { + DocumentOperationResult opResult = buildSampleDocumentOperationResult(); if (indexName.equals(DOES_NOT_EXIST_INDEX)) { @@ -120,11 +116,9 @@ public class StubEsController implements DocumentStoreInterface { } @Override - public DocumentOperationResult updateDocument(String indexName, - DocumentStoreDataEntity document, - boolean allowImplicitIndexCreation) - throws DocumentStoreOperationException { - + public DocumentOperationResult updateDocument(String indexName, DocumentStoreDataEntity document, + boolean allowImplicitIndexCreation) throws DocumentStoreOperationException { + DocumentOperationResult opResult = buildSampleDocumentOperationResult(); if (indexName.equals(DOES_NOT_EXIST_INDEX)) { @@ -142,11 +136,10 @@ public class StubEsController implements DocumentStoreInterface { } @Override - public DocumentOperationResult deleteDocument(String indexName, - DocumentStoreDataEntity document) throws DocumentStoreOperationException { + public DocumentOperationResult deleteDocument(String indexName, DocumentStoreDataEntity document) + throws DocumentStoreOperationException { DocumentOperationResult opResult = buildSampleDocumentOperationResult(); - if (indexName.equals(DOES_NOT_EXIST_INDEX)) { opResult.setResultCode(404); } else { @@ -162,8 +155,8 @@ public class StubEsController implements DocumentStoreInterface { } @Override - public DocumentOperationResult getDocument(String indexName, - DocumentStoreDataEntity document) throws DocumentStoreOperationException { + public DocumentOperationResult getDocument(String indexName, DocumentStoreDataEntity document) + throws DocumentStoreOperationException { DocumentOperationResult opResult = buildSampleDocumentOperationResult(); if (indexName.equals(DOES_NOT_EXIST_INDEX)) { @@ -176,8 +169,8 @@ public class StubEsController implements DocumentStoreInterface { } @Override - public SearchOperationResult search(String indexName, - String queryText) throws DocumentStoreOperationException { + public SearchOperationResult search(String indexName, String queryText) + throws DocumentStoreOperationException { SearchOperationResult opResult = buildSampleSearchOperationResult(); @@ -192,8 +185,8 @@ public class StubEsController implements DocumentStoreInterface { } @Override - public SearchOperationResult searchWithPayload(String indexName, - String query) throws DocumentStoreOperationException { + public SearchOperationResult searchWithPayload(String indexName, String query) + throws DocumentStoreOperationException { SearchOperationResult opResult = buildSampleSearchOperationResult(); if (indexName.equals(DOES_NOT_EXIST_INDEX)) { @@ -207,7 +200,23 @@ public class StubEsController implements DocumentStoreInterface { } @Override - public OperationResult performBulkOperations(BulkRequest[] requests) throws DocumentStoreOperationException { + public SearchOperationResult suggestionQueryWithPayload(String indexName, String query) + throws DocumentStoreOperationException { + SearchOperationResult opResult = new SearchOperationResult(); + + if (indexName.equals(DOES_NOT_EXIST_INDEX)) { + opResult.setResultCode(404); + } else { + opResult.setResultCode(200); + opResult.setResult(indexName + "@" + query); + } + + return opResult; + } + + @Override + public OperationResult performBulkOperations(BulkRequest[] requests) + throws DocumentStoreOperationException { OperationResult opResult = new OperationResult(); opResult.setResultCode(200); @@ -247,4 +256,4 @@ public class StubEsController implements DocumentStoreInterface { } -} \ No newline at end of file +} diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpControllerTest.java b/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpControllerTest.java index ddaf7da..10e7d2c 100644 --- a/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpControllerTest.java +++ b/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpControllerTest.java @@ -22,6 +22,7 @@ package org.onap.aai.sa.searchdbabstraction.elasticsearch.dao; import org.json.JSONException; import org.json.JSONObject; +import org.junit.Assert; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -39,8 +40,10 @@ public class ElasticSearchHttpControllerTest { private static ElasticSearchHttpController elasticSearch; private static AAIEntityTestObject testDocument; - private static final String indexMappings = "{\r\n \"properties\": {\r\n \"entityType\": {\r\n \"type\": \"string\"\r\n },\r\n \"edgeTagQueryEntityFieldName\": {\r\n \"type\": \"string\",\r\n \"index\": \"no\"\r\n },\r\n \"edgeTagQueryEntityFieldValue\": {\r\n \"type\": \"string\",\r\n \"index\": \"no\"\r\n },\r\n \"searchTagIDs\" : {\r\n \"type\" : \"string\"\r\n },\r\n \"searchTags\": {\r\n \"type\": \"string\",\r\n \"analyzer\": \"nGram_analyzer\",\r\n \"search_analyzer\": \"whitespace_analyzer\"\r\n }\r\n }\r\n}"; - private static final String indexSettings = "{\r\n \"analysis\": {\r\n \"filter\": {\r\n \"nGram_filter\": {\r\n \"type\": \"nGram\",\r\n \"min_gram\": 1,\r\n \"max_gram\": 50,\r\n \"token_chars\": [\r\n \"letter\",\r\n \"digit\",\r\n \"punctuation\",\r\n \"symbol\"\r\n ]\r\n }\r\n },\r\n \"analyzer\": {\r\n \"nGram_analyzer\": {\r\n \"type\": \"custom\",\r\n \"tokenizer\": \"whitespace\",\r\n \"filter\": [\r\n \"lowercase\",\r\n \"asciifolding\",\r\n \"nGram_filter\"\r\n ]\r\n },\r\n \"whitespace_analyzer\": {\r\n \"type\": \"custom\",\r\n \"tokenizer\": \"whitespace\",\r\n \"filter\": [\r\n \"lowercase\",\r\n \"asciifolding\"\r\n ]\r\n }\r\n }\r\n }\r\n}"; + private static final String indexMappings = + "{\r\n \"properties\": {\r\n \"entityType\": {\r\n \"type\": \"string\"\r\n },\r\n \"edgeTagQueryEntityFieldName\": {\r\n \"type\": \"string\",\r\n \"index\": \"no\"\r\n },\r\n \"edgeTagQueryEntityFieldValue\": {\r\n \"type\": \"string\",\r\n \"index\": \"no\"\r\n },\r\n \"searchTagIDs\" : {\r\n \"type\" : \"string\"\r\n },\r\n \"searchTags\": {\r\n \"type\": \"string\",\r\n \"analyzer\": \"nGram_analyzer\",\r\n \"search_analyzer\": \"whitespace_analyzer\"\r\n }\r\n }\r\n}"; + private static final String indexSettings = + "{\r\n \"analysis\": {\r\n \"filter\": {\r\n \"nGram_filter\": {\r\n \"type\": \"nGram\",\r\n \"min_gram\": 1,\r\n \"max_gram\": 50,\r\n \"token_chars\": [\r\n \"letter\",\r\n \"digit\",\r\n \"punctuation\",\r\n \"symbol\"\r\n ]\r\n }\r\n },\r\n \"analyzer\": {\r\n \"nGram_analyzer\": {\r\n \"type\": \"custom\",\r\n \"tokenizer\": \"whitespace\",\r\n \"filter\": [\r\n \"lowercase\",\r\n \"asciifolding\",\r\n \"nGram_filter\"\r\n ]\r\n },\r\n \"whitespace_analyzer\": {\r\n \"type\": \"custom\",\r\n \"tokenizer\": \"whitespace\",\r\n \"filter\": [\r\n \"lowercase\",\r\n \"asciifolding\"\r\n ]\r\n }\r\n }\r\n }\r\n}"; @Before public void setUp() throws Exception { @@ -62,7 +65,8 @@ public class ElasticSearchHttpControllerTest { @Test public void testCreateTable() throws Exception { - OperationResult result = elasticSearch.createTable("test", "aai-entities", indexSettings, indexMappings); + OperationResult result = + elasticSearch.createTable("test", "aai-entities", indexSettings, indexMappings); System.out.println(result); } @@ -145,6 +149,13 @@ public class ElasticSearchHttpControllerTest { System.out.println(result); } + @Test + public void testsuggestionQueryWithPayload() throws Exception { + + Assert.assertNotNull(elasticSearch.suggestionQueryWithPayload("autoSuggest", "suggest-index")); + + } + @Test public void testDeleteIndex() throws Exception { OperationResult result = elasticSearch.deleteIndex("test"); @@ -216,12 +227,10 @@ public class ElasticSearchHttpControllerTest { @Override public String getContentInJson() { try { - return new JSONObject() - .put("entityType", entityType) + return new JSONObject().put("entityType", entityType) .put("edgeTagQueryEntityFieldName", edgeTagQueryEntityFieldName) .put("edgeTagQueryEntityFieldValue", edgeTagQueryEntityFieldValue) - .put("searchTagIDs", searchTagIDs) - .put("searchTags", searchTags).toString(); + .put("searchTagIDs", searchTagIDs).put("searchTags", searchTags).toString(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); -- cgit 1.2.3-korg