aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/onap')
-rw-r--r--src/test/java/org/onap/aai/sa/rest/ApiUtilsTest.java19
-rw-r--r--src/test/java/org/onap/aai/sa/rest/BulkApiTest.java9
-rw-r--r--src/test/java/org/onap/aai/sa/rest/DocumentApiTest.java35
-rw-r--r--src/test/java/org/onap/aai/sa/rest/DocumentSchemaTest.java1
-rw-r--r--src/test/java/org/onap/aai/sa/rest/DocumentTest.java16
-rw-r--r--src/test/java/org/onap/aai/sa/rest/IndexApiTest.java4
-rw-r--r--src/test/java/org/onap/aai/sa/rest/SearchServiceApiHarness.java3
-rw-r--r--src/test/java/org/onap/aai/sa/rest/StubEsController.java6
-rw-r--r--src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/QueryTest.java364
-rw-r--r--src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/RangeQueryTest.java304
-rw-r--r--src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/TermQueryTest.java2
11 files changed, 369 insertions, 394 deletions
diff --git a/src/test/java/org/onap/aai/sa/rest/ApiUtilsTest.java b/src/test/java/org/onap/aai/sa/rest/ApiUtilsTest.java
index 593ec92..f205fa8 100644
--- a/src/test/java/org/onap/aai/sa/rest/ApiUtilsTest.java
+++ b/src/test/java/org/onap/aai/sa/rest/ApiUtilsTest.java
@@ -1,4 +1,4 @@
-/**
+/**
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
@@ -20,23 +20,18 @@
*/
package org.onap.aai.sa.rest;
-import static org.junit.Assert.assertEquals;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
import org.junit.Test;
-
public class ApiUtilsTest {
@Test
public void testHTTPStatusConversion() {
- String statusString;
- statusString = ApiUtils.getHttpStatusString(201);
- assertEquals(0, statusString.compareToIgnoreCase("Created"));
-
- statusString = ApiUtils.getHttpStatusString(207);
- assertEquals(0, statusString.compareToIgnoreCase("Multi-Status"));
-
- statusString = ApiUtils.getHttpStatusString(9999);
- assertEquals(0, statusString.compareToIgnoreCase("Unknown"));
+ assertThat(ApiUtils.getHttpStatusString(201), is(equalTo("Created")));
+ assertThat(ApiUtils.getHttpStatusString(207), is(equalTo("Multi-Status")));
+ assertThat(ApiUtils.getHttpStatusString(9999), is(equalTo("Unknown")));
}
}
diff --git a/src/test/java/org/onap/aai/sa/rest/BulkApiTest.java b/src/test/java/org/onap/aai/sa/rest/BulkApiTest.java
index eff4efc..23071eb 100644
--- a/src/test/java/org/onap/aai/sa/rest/BulkApiTest.java
+++ b/src/test/java/org/onap/aai/sa/rest/BulkApiTest.java
@@ -1,4 +1,4 @@
-/**
+/**
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
@@ -34,7 +34,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
-import org.springframework.test.web.servlet.ResultActions;
/**
@@ -78,13 +77,11 @@ public class BulkApiTest {
this.mockMvc.perform(post(TOP_URI).contentType(MediaType.APPLICATION_JSON).content(validPayloadStr))
.andExpect(status().isOk());
-
// Post a request to the bulk operations endpoint with an invalid
// operations list payload.
File inValidBulkOpsFile = new File("src/test/resources/json/bulk-ops-invalid.json");
String inValidPayloadStr = TestUtils.readFileToString(inValidBulkOpsFile);
- ResultActions invalid =
- this.mockMvc.perform(post(TOP_URI).contentType(MediaType.APPLICATION_JSON).content(inValidPayloadStr))
- .andExpect(status().isBadRequest());
+ this.mockMvc.perform(post(TOP_URI).contentType(MediaType.APPLICATION_JSON).content(inValidPayloadStr))
+ .andExpect(status().isBadRequest());
}
}
diff --git a/src/test/java/org/onap/aai/sa/rest/DocumentApiTest.java b/src/test/java/org/onap/aai/sa/rest/DocumentApiTest.java
index 4276f3d..dd1ad2f 100644
--- a/src/test/java/org/onap/aai/sa/rest/DocumentApiTest.java
+++ b/src/test/java/org/onap/aai/sa/rest/DocumentApiTest.java
@@ -1,4 +1,4 @@
-/**
+/**
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
@@ -27,8 +27,6 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import java.io.IOException;
-//import org.glassfish.jersey.server.ResourceConfig;
-//import org.glassfish.jersey.test.JerseyTest;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
@@ -168,37 +166,25 @@ public class DocumentApiTest {
}
- //
- // /**
- // * This test validates the behaviour of the 'Search Documents' GET request
- // * endpoint.
- // *
- // * @throws IOException
- // * @throws ParseException
- // */
+
+ /**
+ * This test validates the behaviour of the 'Search Documents' GET request endpoint.
+ *
+ * @throws Exception
+ */
@Ignore
- @Test
public void searchDocumentTest1() throws Exception {
- // String result = target(INDEXES_URI + INDEX_NAME + "/" + SEARCH_URI +
- // SIMPLE_QUERY).request().get(String.class);
-
MvcResult result = this.mockMvc
.perform(get(INDEXES_URI + INDEX_NAME + "/" + SEARCH_URI + SIMPLE_QUERY)
.contentType(MediaType.APPLICATION_JSON).header("If-Match", "1").content(CREATE_JSON_CONTENT))
.andReturn();
- // Our stub document store DAO returns the parameters that it was
- // passed as the result string, so now we can validate that our
- // endpoint invoked it with the correct parameters.
JSONParser parser = new JSONParser();
JSONObject json = (JSONObject) parser.parse(result.getResponse().getContentAsString());
assertTrue("Unexpected Result ", json.get("totalHits").toString().equals("1"));
-
-
}
- //
/**
* This test validates the behaviour of the 'Search Documents' GET request endpoint.
*
@@ -207,21 +193,14 @@ public class DocumentApiTest {
*/
@Test
public void searchDocumentTest2() throws Exception {
- // String result = target(INDEXES_URI + INDEX_NAME + "/" +
- // SEARCH_URI).request().post(Entity.json(COMPLEX_QUERY), String.class);
-
MvcResult result = this.mockMvc.perform(get(INDEXES_URI + INDEX_NAME + "/" + SEARCH_URI)
.contentType(MediaType.APPLICATION_JSON).content(COMPLEX_QUERY)).andReturn();
- // Our stub document store DAO returns the parameters that it was
- // passed as the result string, so now we can validate that our
- // endpoint invoked it with the correct parameters.
JSONParser parser = new JSONParser();
JSONObject json = (JSONObject) parser.parse(result.getResponse().getContentAsString());
JSONObject resultJson = (JSONObject) json.get("searchResult");
assertTrue("Unexpected Result ", resultJson.get("totalHits").toString().equals("1"));
-
}
}
diff --git a/src/test/java/org/onap/aai/sa/rest/DocumentSchemaTest.java b/src/test/java/org/onap/aai/sa/rest/DocumentSchemaTest.java
index b18928d..c2d5021 100644
--- a/src/test/java/org/onap/aai/sa/rest/DocumentSchemaTest.java
+++ b/src/test/java/org/onap/aai/sa/rest/DocumentSchemaTest.java
@@ -29,7 +29,6 @@ import java.io.File;
import java.io.IOException;
import org.junit.Test;
-
public class DocumentSchemaTest {
private final String SIMPLE_DOC_SCHEMA_JSON = "src/test/resources/json/simpleDocument.json";
diff --git a/src/test/java/org/onap/aai/sa/rest/DocumentTest.java b/src/test/java/org/onap/aai/sa/rest/DocumentTest.java
index 9fa5fe1..d16fe87 100644
--- a/src/test/java/org/onap/aai/sa/rest/DocumentTest.java
+++ b/src/test/java/org/onap/aai/sa/rest/DocumentTest.java
@@ -103,6 +103,7 @@ public class DocumentTest {
Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue());
}
+ @SuppressWarnings("unchecked")
@Test
public void testProcessPost_NotNullContent() throws Exception {
String transactionId = "transactionId-1";
@@ -117,7 +118,7 @@ public class DocumentTest {
Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
.thenThrow(IllegalArgumentException.class);
- ResponseEntity response =
+ ResponseEntity<?> response =
documentApi.processPost(content, request, headers, httpResponse, "index", documentStore);
Assert.assertNotNull(response);
Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
@@ -179,7 +180,7 @@ public class DocumentTest {
}
- //
+ @SuppressWarnings("unchecked")
@Test
public void testProcessSearchWithGet_ValidateThrowsException() throws Exception {
String transactionId = "transactionId-1";
@@ -207,7 +208,6 @@ public class DocumentTest {
}
- //
@Test
public void testProcessSearchWithGet_ValidateIsFalse() throws Exception {
String transactionId = "transactionId-1";
@@ -279,6 +279,7 @@ public class DocumentTest {
Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue());
}
+ @SuppressWarnings("unchecked")
@Test
public void testProcessPut_RequestThrowsException() throws Exception {
String transactionId = "transactionId-1";
@@ -319,7 +320,6 @@ public class DocumentTest {
Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
}
- @Ignore
@Test
public void testProcessPut_ResultInvalid() throws Exception {
String transactionId = "transactionId-1";
@@ -338,7 +338,7 @@ public class DocumentTest {
Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),
Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))
.thenReturn(true);
- Mockito.when(documentStore.updateDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class),
+ Mockito.when(documentStore.createDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class),
Mockito.anyBoolean())).thenReturn(result);
ResponseEntity<String> response =
documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore);
@@ -346,6 +346,7 @@ public class DocumentTest {
Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue());
}
+ @SuppressWarnings("unchecked")
@Test
public void testProcessDelete_RequestThrowsException() throws Exception {
String transactionId = "transactionId-1";
@@ -413,6 +414,7 @@ public class DocumentTest {
Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue());
}
+ @SuppressWarnings("unchecked")
@Test
public void testProcessGet_RequestThrowsException() throws Exception {
String transactionId = "transactionId-1";
@@ -496,6 +498,7 @@ public class DocumentTest {
Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue());
}
+ @SuppressWarnings("unchecked")
@Test
public void testQueryWithGetWithPayload_RequestThrowsException() throws Exception {
String transactionId = "transactionId-1";
@@ -555,6 +558,7 @@ public class DocumentTest {
Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
}
+ @SuppressWarnings("unchecked")
@Test
public void testCreateProcessIndex_IndexApi_RequestThrowsException() throws Exception {
String transactionId = "transactionId-1";
@@ -612,6 +616,7 @@ public class DocumentTest {
Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
}
+ @SuppressWarnings("unchecked")
@Test
public void testProcessDelete_IndexApi_RequestThrowsException() throws Exception {
String transactionId = "transactionId-1";
@@ -630,6 +635,7 @@ public class DocumentTest {
Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());
}
+ @SuppressWarnings("unchecked")
@Test
public void testProcessDelete_IndexApi_DeleteIndexException() throws Exception {
String transactionId = "transactionId-1";
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 cd33edd..ed84a7a 100644
--- a/src/test/java/org/onap/aai/sa/rest/IndexApiTest.java
+++ b/src/test/java/org/onap/aai/sa/rest/IndexApiTest.java
@@ -135,7 +135,7 @@ public class IndexApiTest {
successResult.setResult(SUCCESS_RESULT_STRING);
// Convert our success OperationResult to a standard REST Response...
- ResponseEntity successResponse = indexApi.responseFromOperationResult(successResult);
+ ResponseEntity<?> successResponse = indexApi.responseFromOperationResult(successResult);
// ...and validate that the Response is correctly populated.
assertEquals("Unexpected result code", SUCCESS_RESULT_CODE, successResponse.getStatusCodeValue());
@@ -148,7 +148,7 @@ public class IndexApiTest {
failureResult.setFailureCause(FAILURE_CAUSE_STRING);
// Convert our failure OperationResult to a standard REST Response...
- ResponseEntity failureResponse = indexApi.responseFromOperationResult(failureResult);
+ ResponseEntity<?> failureResponse = indexApi.responseFromOperationResult(failureResult);
// ...and validate that the Response is correctly populated.
assertEquals("Unexpected result code", FAILURE_RESULT_CODE, failureResponse.getStatusCodeValue());
diff --git a/src/test/java/org/onap/aai/sa/rest/SearchServiceApiHarness.java b/src/test/java/org/onap/aai/sa/rest/SearchServiceApiHarness.java
index 072b090..93e1d49 100644
--- a/src/test/java/org/onap/aai/sa/rest/SearchServiceApiHarness.java
+++ b/src/test/java/org/onap/aai/sa/rest/SearchServiceApiHarness.java
@@ -158,8 +158,7 @@ public class SearchServiceApiHarness extends SearchServiceApi {
@Override
protected boolean validateRequest(HttpHeaders headers, HttpServletRequest req, ApiUtils.Action action,
- String authPolicyFunctionName) throws Exception {
-
+ String authPolicyFunctionName) {
return authenticationShouldSucceed;
}
}
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 14a7534..cb4edbc 100644
--- a/src/test/java/org/onap/aai/sa/rest/StubEsController.java
+++ b/src/test/java/org/onap/aai/sa/rest/StubEsController.java
@@ -111,10 +111,6 @@ public class StubEsController implements DocumentStoreInterface {
opResult.setResultCode(404);
} else {
opResult.setResultCode(200);
- String id = "dummy";
- if (document.getId() != null) {
- id = document.getId();
- }
opResult.setResultVersion("1");
}
@@ -253,7 +249,7 @@ public class StubEsController implements DocumentStoreInterface {
SearchHit searchHit = new SearchHit();
Document doc = new Document();
doc.setEtag("etag1");
- Map<String, Object> content = new HashMap<String, Object>();
+ Map<String, Object> content = new HashMap<>();
content.put("key1", "value1");
doc.setContent(new JSONObject());
searchHit.setDocument(doc);
diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/QueryTest.java b/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/QueryTest.java
index 2f22605..e229348 100644
--- a/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/QueryTest.java
+++ b/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/QueryTest.java
@@ -1,4 +1,4 @@
-/**
+/**
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
@@ -32,182 +32,182 @@ import org.junit.Test;
public class QueryTest {
- /**
+ /**
* This test validates that we are able to marshal json structures representing term queries into POJOs and that we
* can then unmarshal those POJOs into ElasticSearch syntax.
- *
- * @throws JsonParseException
- * @throws JsonMappingException
- * @throws IOException
- */
- @Test
- public void termQueryTest() throws JsonParseException, JsonMappingException, IOException {
+ *
+ * @throws JsonParseException
+ * @throws JsonMappingException
+ * @throws IOException
+ */
+ @Test
+ public void termQueryTest() throws JsonParseException, JsonMappingException, IOException {
- Integer intValue = 1;
- String field = "searchTags";
- String termQueryWithIntegerValueJson = "{\"field\": \"" + field + "\", \"value\": " + intValue + "}";
- String termQueryWithIntegerValueExpectedES = "{\"term\": {\"" + field + "\" : " + intValue + "}}";
+ Integer intValue = 1;
+ String field = "searchTags";
+ String termQueryWithIntegerValueJson = "{\"field\": \"" + field + "\", \"value\": " + intValue + "}";
+ String termQueryWithIntegerValueExpectedES = "{\"term\": {\"" + field + "\" : " + intValue + "}}";
- Double doubleValue = 5.7;
- String termQueryWithDoubleValueJson = "{\"field\": \"" + field + "\", \"value\": " + doubleValue + "}";
- String termQueryWithDoubleValueExpectedES = "{\"term\": {\"" + field + "\" : " + doubleValue + "}}";
+ Double doubleValue = 5.7;
+ String termQueryWithDoubleValueJson = "{\"field\": \"" + field + "\", \"value\": " + doubleValue + "}";
+ String termQueryWithDoubleValueExpectedES = "{\"term\": {\"" + field + "\" : " + doubleValue + "}}";
- String stringValue = "theValue";
- String termQueryWithStringValueJson = "{\"field\": \"" + field + "\", \"value\": \"" + stringValue + "\"}";
- String termQueryWithStringValueExpectedES = "{\"term\": {\"" + field + "\" : \"" + stringValue + "\"}}";
+ String stringValue = "theValue";
+ String termQueryWithStringValueJson = "{\"field\": \"" + field + "\", \"value\": \"" + stringValue + "\"}";
+ String termQueryWithStringValueExpectedES = "{\"term\": {\"" + field + "\" : \"" + stringValue + "\"}}";
- ObjectMapper mapper = new ObjectMapper();
+ ObjectMapper mapper = new ObjectMapper();
- // Validate that we can marshal a term query where the supplied value
- // is an Integer.
- TermQuery integerTermQuery = mapper.readValue(termQueryWithIntegerValueJson, TermQuery.class);
+ // Validate that we can marshal a term query where the supplied value
+ // is an Integer.
+ TermQuery integerTermQuery = mapper.readValue(termQueryWithIntegerValueJson, TermQuery.class);
assertTrue(
"Expected value to be of type Integer, but was type "
+ integerTermQuery.getValue().getClass().getName(),
- integerTermQuery.getValue() instanceof Integer);
- assertEquals(intValue, integerTermQuery.getValue());
+ integerTermQuery.getValue() instanceof Integer);
+ assertEquals(intValue, integerTermQuery.getValue());
- assertTrue("ElasticSearch term query translation does not match the expected result",
- termQueryWithIntegerValueExpectedES.equals(integerTermQuery.toElasticSearch()));
+ assertTrue("ElasticSearch term query translation does not match the expected result",
+ termQueryWithIntegerValueExpectedES.equals(integerTermQuery.toElasticSearch()));
- // Validate that we can marshal a term query where the supplied value
- // is a Double.
- TermQuery doubleTermQuery = mapper.readValue(termQueryWithDoubleValueJson, TermQuery.class);
+ // Validate that we can marshal a term query where the supplied value
+ // is a Double.
+ TermQuery doubleTermQuery = mapper.readValue(termQueryWithDoubleValueJson, TermQuery.class);
assertTrue(
"Expected value to be of type Double, but was type " + doubleTermQuery.getValue().getClass().getName(),
- doubleTermQuery.getValue() instanceof Double);
- assertEquals(doubleValue, doubleTermQuery.getValue());
- assertTrue("ElasticSearch term query translation does not match the expected result",
- termQueryWithDoubleValueExpectedES.equals(doubleTermQuery.toElasticSearch()));
-
- // Validate that we can marshal a term query where the supplied value
- // is a String literal.
- TermQuery stringTermQuery = mapper.readValue(termQueryWithStringValueJson, TermQuery.class);
+ doubleTermQuery.getValue() instanceof Double);
+ assertEquals(doubleValue, doubleTermQuery.getValue());
+ assertTrue("ElasticSearch term query translation does not match the expected result",
+ termQueryWithDoubleValueExpectedES.equals(doubleTermQuery.toElasticSearch()));
+
+ // Validate that we can marshal a term query where the supplied value
+ // is a String literal.
+ TermQuery stringTermQuery = mapper.readValue(termQueryWithStringValueJson, TermQuery.class);
assertTrue(
"Expected value to be of type String, but was type " + stringTermQuery.getValue().getClass().getName(),
- stringTermQuery.getValue() instanceof String);
- assertEquals(stringValue, stringTermQuery.getValue());
- assertTrue("ElasticSearch term query translation does not match the expected result",
- termQueryWithStringValueExpectedES.equals(stringTermQuery.toElasticSearch()));
+ stringTermQuery.getValue() instanceof String);
+ assertEquals(stringValue, stringTermQuery.getValue());
+ assertTrue("ElasticSearch term query translation does not match the expected result",
+ termQueryWithStringValueExpectedES.equals(stringTermQuery.toElasticSearch()));
- }
+ }
- /**
+ /**
* This test validates that we are able to marshal json structures representing parsed queries into POJOs and that
* we can then unmarshal those POJOs into ElasticSearch syntax.
- *
- * @throws JsonParseException
- * @throws JsonMappingException
- * @throws IOException
- */
- @Test
- public void parsedQueryTest() throws JsonParseException, JsonMappingException, IOException {
-
- String field = "fieldname";
- String queryString = "The query string";
-
- String queryJson = "{\"field\": \"" + field + "\", \"query-string\": \"" + queryString + "\"}";
+ *
+ * @throws JsonParseException
+ * @throws JsonMappingException
+ * @throws IOException
+ */
+ @Test
+ public void parsedQueryTest() throws JsonParseException, JsonMappingException, IOException {
+
+ String field = "fieldname";
+ String queryString = "The query string";
+
+ String queryJson = "{\"field\": \"" + field + "\", \"query-string\": \"" + queryString + "\"}";
String queryExpectedES =
"{\"query_string\": {\"default_field\": \"" + field + "\", \"query\": \"" + queryString + "\"}}";
- ObjectMapper mapper = new ObjectMapper();
- ParsedQuery pq = mapper.readValue(queryJson, ParsedQuery.class);
+ ObjectMapper mapper = new ObjectMapper();
+ ParsedQuery pq = mapper.readValue(queryJson, ParsedQuery.class);
- assertTrue("Unexpected marshalled value for 'field' - expected: " + field + " actual: " + pq.getField(),
- field.equals(pq.getField()));
+ assertTrue("Unexpected marshalled value for 'field' - expected: " + field + " actual: " + pq.getField(),
+ field.equals(pq.getField()));
assertTrue("Unexpected marshalled value for 'query-string' - expected: " + queryString + " actual: "
+ pq.getQueryString(), queryString.equals(pq.getQueryString()));
assertTrue(
"Unexpected ElasticSearch syntax. Expected: " + queryExpectedES + " Actual: " + pq.toElasticSearch(),
- queryExpectedES.equals(pq.toElasticSearch()));
- }
+ queryExpectedES.equals(pq.toElasticSearch()));
+ }
- /**
+ /**
* This test validates that a ranged query cannot be parsed with values for both the 'gte' and 'gt' fields or the
* 'lte' and 'lt' fields, and that we do not allow mixing of numeric and date types in the same query.
- *
- * @throws JsonParseException
- * @throws IOException
- */
- @Test
- public void rangeQueryConflictingBoundsTest() throws JsonParseException, IOException {
+ *
+ * @throws JsonParseException
+ * @throws IOException
+ */
+ @Test
+ public void rangeQueryConflictingBoundsTest() throws JsonParseException, IOException {
String invalidGTAndGTE =
"{ \"field\": \"timestamp\", \"gte\": \"2016-10-06T00:00:00.558+03:00\", \"gt\": \"2016-10-06T23:59:59.558+03:00\"}";
String invalidLTAndLTE =
"{ \"field\": \"timestamp\", \"lte\": \"2016-10-06T00:00:00.558+03:00\", \"lt\": \"2016-10-06T23:59:59.558+03:00\"}";
- String invalidTypes = "{ \"field\": \"timestamp\", \"lte\": 5, \"gte\": \"2016-10-06T23:59:59.558+03:00\"}";
-
- ObjectMapper mapper = new ObjectMapper();
-
- // Attempt to parse a query where we are setting values for both the
- // 'greater than' and 'greater than and equal to' operators.
- boolean gotExpectedException = false;
- try {
- RangeQuery badRangeQuery = mapper.readValue(invalidGTAndGTE, RangeQuery.class);
- } catch (JsonMappingException e) {
- gotExpectedException = true;
- }
- assertTrue("Attempting to set both a 'gt' and 'gte' value on the same query should not have been allowed",
- gotExpectedException);
-
- // Attempt to parse a query where we are setting values for both the
- // 'less than' and 'less than and equal to' operators.
- gotExpectedException = false;
- try {
- RangeQuery badRangeQuery = mapper.readValue(invalidLTAndLTE, RangeQuery.class);
- } catch (JsonMappingException e) {
- gotExpectedException = true;
- }
- assertTrue("Attempting to set both a 'lt' and 'lte' value on the same query should not have been allowed",
- gotExpectedException);
-
- // Attempt to parse a query where we are mixing numeric and date values
- // in the same query.
- gotExpectedException = false;
- try {
- RangeQuery badRangeQuery = mapper.readValue(invalidTypes, RangeQuery.class);
- } catch (JsonMappingException e) {
- gotExpectedException = true;
- }
- assertTrue("Attempting to mix numeric and date values in the same query should not have been allowed",
- gotExpectedException);
+ String invalidTypes = "{ \"field\": \"timestamp\", \"lte\": 5, \"gte\": \"2016-10-06T23:59:59.558+03:00\"}";
+ ObjectMapper mapper = new ObjectMapper();
+ // Attempt to parse a query where we are setting values for both the
+ // 'greater than' and 'greater than and equal to' operators.
+ boolean gotExpectedException = false;
+ try {
+ mapper.readValue(invalidGTAndGTE, RangeQuery.class);
+ } catch (JsonMappingException e) {
+ gotExpectedException = true;
+ }
+ assertTrue("Attempting to set both a 'gt' and 'gte' value on the same query should not have been allowed",
+ gotExpectedException);
+
+ // Attempt to parse a query where we are setting values for both the
+ // 'less than' and 'less than and equal to' operators.
+ gotExpectedException = false;
+ try {
+ mapper.readValue(invalidLTAndLTE, RangeQuery.class);
+ } catch (JsonMappingException e) {
+ gotExpectedException = true;
+ }
+ assertTrue("Attempting to set both a 'lt' and 'lte' value on the same query should not have been allowed",
+ gotExpectedException);
+
+ // Attempt to parse a query where we are mixing numeric and date values
+ // in the same query.
+ gotExpectedException = false;
+ try {
+ mapper.readValue(invalidTypes, RangeQuery.class);
+ } catch (JsonMappingException e) {
+ gotExpectedException = true;
}
+ assertTrue("Attempting to mix numeric and date values in the same query should not have been allowed",
+ gotExpectedException);
- /**
+ }
+
+
+ /**
* This test validates that date range queries can be marshalled to a Java POJO and unmarshalled to ElasticSearch
* syntax.
- *
- * @throws JsonParseException
- * @throws JsonMappingException
- * @throws IOException
- */
- @Test
- public void dateRangeQueryTest() throws JsonParseException, JsonMappingException, IOException {
-
- String field = "timestamp";
- String greaterThanDate = "2016-10-06T00:00:00.558+03:00";
- String lessThanDate = "2016-10-06T23:59:59.558+03:00";
-
- ObjectMapper mapper = new ObjectMapper();
-
- // Generate a date range query using 'greater than or equal' and 'less
- // than or equal' operations.
+ *
+ * @throws JsonParseException
+ * @throws JsonMappingException
+ * @throws IOException
+ */
+ @Test
+ public void dateRangeQueryTest() throws JsonParseException, JsonMappingException, IOException {
+
+ String field = "timestamp";
+ String greaterThanDate = "2016-10-06T00:00:00.558+03:00";
+ String lessThanDate = "2016-10-06T23:59:59.558+03:00";
+
+ ObjectMapper mapper = new ObjectMapper();
+
+ // Generate a date range query using 'greater than or equal' and 'less
+ // than or equal' operations.
String dateRangeJson = "{ \"field\": \"" + field + "\", \"gte\": \"" + greaterThanDate + "\", \"lte\": \""
+ lessThanDate + "\"}";
- String dateRangeExpectedES =
- "{\"range\": {\"timestamp\": {\"gte\": \"2016-10-06T00:00:00.558+03:00\", \"lte\": \"2016-10-06T23:59:59.558+03:00\"}}}";
+ String dateRangeExpectedES =
+ "{\"range\": {\"timestamp\": {\"gte\": \"2016-10-06T00:00:00.558+03:00\", \"lte\": \"2016-10-06T23:59:59.558+03:00\"}}}";
- // Validate that the query is marshalled correctly to the POJO and that
- // the generated ElasticSearch syntax looks as expected.
- RangeQuery dateRangeQuery = mapper.readValue(dateRangeJson, RangeQuery.class);
+ // Validate that the query is marshalled correctly to the POJO and that
+ // the generated ElasticSearch syntax looks as expected.
+ RangeQuery dateRangeQuery = mapper.readValue(dateRangeJson, RangeQuery.class);
assertTrue("Unexpected marshalled value for 'field'. Expected: " + field + " Actual: "
+ dateRangeQuery.getField(), field.equals(dateRangeQuery.getField()));
@@ -222,19 +222,19 @@ public class QueryTest {
assertTrue(
"Unexpected ElasticSearch syntax. Expected: " + dateRangeExpectedES + " Actual: "
+ dateRangeQuery.toElasticSearch(),
- dateRangeExpectedES.equals(dateRangeQuery.toElasticSearch()));
+ dateRangeExpectedES.equals(dateRangeQuery.toElasticSearch()));
- // Generate a date range query using 'greater than' and 'less than or
- // equal' operations.
+ // Generate a date range query using 'greater than' and 'less than or
+ // equal' operations.
dateRangeJson = "{ \"field\": \"" + field + "\", \"gt\": \"" + greaterThanDate + "\", \"lte\": \""
+ lessThanDate + "\"}";
- dateRangeExpectedES =
- "{\"range\": {\"timestamp\": {\"gt\": \"2016-10-06T00:00:00.558+03:00\", \"lte\": \"2016-10-06T23:59:59.558+03:00\"}}}";
+ dateRangeExpectedES =
+ "{\"range\": {\"timestamp\": {\"gt\": \"2016-10-06T00:00:00.558+03:00\", \"lte\": \"2016-10-06T23:59:59.558+03:00\"}}}";
- // Validate that the query is marshalled correctly to the POJO and that
- // the generated ElasticSearch syntax looks as expected.
- dateRangeQuery = mapper.readValue(dateRangeJson, RangeQuery.class);
+ // Validate that the query is marshalled correctly to the POJO and that
+ // the generated ElasticSearch syntax looks as expected.
+ dateRangeQuery = mapper.readValue(dateRangeJson, RangeQuery.class);
assertTrue("Unexpected marshalled value for 'field'. Expected: " + field + " Actual: "
+ dateRangeQuery.getField(), field.equals(dateRangeQuery.getField()));
@@ -254,16 +254,16 @@ public class QueryTest {
assertTrue(
"Unexpected ElasticSearch syntax. Expected: " + dateRangeExpectedES + " Actual: "
+ dateRangeQuery.toElasticSearch(),
- dateRangeExpectedES.equals(dateRangeQuery.toElasticSearch()));
+ dateRangeExpectedES.equals(dateRangeQuery.toElasticSearch()));
- // Generate a date range query using only a 'greater than' operation.
+ // Generate a date range query using only a 'greater than' operation.
dateRangeJson = "{ \"field\": \"" + field + "\", \"gt\": \"" + greaterThanDate + "\"}";
dateRangeExpectedES = "{\"range\": {\"timestamp\": {\"gt\": \"2016-10-06T00:00:00.558+03:00\"}}}";
- // Validate that the query is marshalled correctly to the POJO and that
- // the generated ElasticSearch syntax looks as expected.
- dateRangeQuery = mapper.readValue(dateRangeJson, RangeQuery.class);
+ // Validate that the query is marshalled correctly to the POJO and that
+ // the generated ElasticSearch syntax looks as expected.
+ dateRangeQuery = mapper.readValue(dateRangeJson, RangeQuery.class);
assertTrue("Unexpected marshalled value for 'field'. Expected: " + field + " Actual: "
+ dateRangeQuery.getField(), field.equals(dateRangeQuery.getField()));
@@ -277,48 +277,48 @@ public class QueryTest {
assertTrue(
"Unexpected ElasticSearch syntax. Expected: " + dateRangeExpectedES + " Actual: "
+ dateRangeQuery.toElasticSearch(),
- dateRangeExpectedES.equals(dateRangeQuery.toElasticSearch()));
+ dateRangeExpectedES.equals(dateRangeQuery.toElasticSearch()));
- }
+ }
- /**
+ /**
* This test validates that numeric range queries can be marshalled to a Java POJO and unmarshalled to ElasticSearch
* syntax.
- *
- * @throws JsonParseException
- * @throws JsonMappingException
- * @throws IOException
- */
- @Test
- public void numericRangeQueryTest() throws JsonParseException, JsonMappingException, IOException {
-
- String field = "version";
- Integer greaterThanInt = 5;
- Integer lessThanInt = 100;
-
- ObjectMapper mapper = new ObjectMapper();
-
- // Generate a numeric range query using 'greater than or equal' and 'less
- // than or equal' operations.
- String numericRangeJson =
- "{ \"field\": \"" + field + "\", \"gte\": " + greaterThanInt + ", \"lte\": " + lessThanInt + "}";
- String numericRangeExpectedES =
- "{\"range\": {\"" + field + "\": {\"gte\": " + greaterThanInt + ", \"lte\": " + lessThanInt + "}}}";
-
- // Validate that the query is marshalled correctly to the POJO and that
- // the generated ElasticSearch syntax looks as expected.
- RangeQuery numericRangeQuery = mapper.readValue(numericRangeJson, RangeQuery.class);
+ *
+ * @throws JsonParseException
+ * @throws JsonMappingException
+ * @throws IOException
+ */
+ @Test
+ public void numericRangeQueryTest() throws JsonParseException, JsonMappingException, IOException {
+
+ String field = "version";
+ Integer greaterThanInt = 5;
+ Integer lessThanInt = 100;
+
+ ObjectMapper mapper = new ObjectMapper();
+
+ // Generate a numeric range query using 'greater than or equal' and 'less
+ // than or equal' operations.
+ String numericRangeJson =
+ "{ \"field\": \"" + field + "\", \"gte\": " + greaterThanInt + ", \"lte\": " + lessThanInt + "}";
+ String numericRangeExpectedES =
+ "{\"range\": {\"" + field + "\": {\"gte\": " + greaterThanInt + ", \"lte\": " + lessThanInt + "}}}";
+
+ // Validate that the query is marshalled correctly to the POJO and that
+ // the generated ElasticSearch syntax looks as expected.
+ RangeQuery numericRangeQuery = mapper.readValue(numericRangeJson, RangeQuery.class);
assertTrue("Unexpected marshalled value for 'field'. Expected: " + field + " Actual: "
+ numericRangeQuery.getField(), field.equals(numericRangeQuery.getField()));
assertTrue(
"Unexpected type for 'gte' value. Expected: Integer Actual: "
+ numericRangeQuery.getGte().getClass().getName(),
- numericRangeQuery.getGte() instanceof Integer);
+ numericRangeQuery.getGte() instanceof Integer);
assertTrue(
"Unexpected type for 'lte' value. Expected: Integer Actual: "
+ numericRangeQuery.getLte().getClass().getName(),
- numericRangeQuery.getLte() instanceof Integer);
+ numericRangeQuery.getLte() instanceof Integer);
assertEquals("Unexpected marshalled value for 'gte'. Expected: " + greaterThanInt + " Actual: "
+ numericRangeQuery.getGte(), greaterThanInt, numericRangeQuery.getGte());
assertEquals("Unexpected marshalled value for 'lte'. Expected: " + lessThanInt + " Actual: "
@@ -326,22 +326,22 @@ public class QueryTest {
assertTrue(
"Unexpected ElasticSearch syntax. Expected: " + numericRangeExpectedES + " Actual: "
+ numericRangeQuery.toElasticSearch(),
- numericRangeExpectedES.equals(numericRangeQuery.toElasticSearch()));
+ numericRangeExpectedES.equals(numericRangeQuery.toElasticSearch()));
- Double greaterThanDouble = 5.0;
- Double lessThanDouble = 100.0;
+ Double greaterThanDouble = 5.0;
+ Double lessThanDouble = 100.0;
- // Generate a date range query using 'greater than' and 'less than or
- // equal' operations.
- numericRangeJson =
- "{ \"field\": \"" + field + "\", \"gt\": " + greaterThanDouble + ", \"lte\": " + lessThanDouble + "}";
+ // Generate a date range query using 'greater than' and 'less than or
+ // equal' operations.
+ numericRangeJson =
+ "{ \"field\": \"" + field + "\", \"gt\": " + greaterThanDouble + ", \"lte\": " + lessThanDouble + "}";
numericRangeExpectedES = "{\"range\": {\"" + field + "\": {\"gt\": " + greaterThanDouble + ", \"lte\": "
+ lessThanDouble + "}}}";
- // Validate that the query is marshalled correctly to the POJO and that
- // the generated ElasticSearch syntax looks as expected.
- numericRangeQuery = mapper.readValue(numericRangeJson, RangeQuery.class);
+ // Validate that the query is marshalled correctly to the POJO and that
+ // the generated ElasticSearch syntax looks as expected.
+ numericRangeQuery = mapper.readValue(numericRangeJson, RangeQuery.class);
assertTrue("Unexpected marshalled value for 'field'. Expected: " + field + " Actual: "
+ numericRangeQuery.getField(), field.equals(numericRangeQuery.getField()));
@@ -352,7 +352,7 @@ public class QueryTest {
assertTrue(
"Unexpected type for 'lte' value. Expected: Double Actual: "
+ numericRangeQuery.getLte().getClass().getName(),
- numericRangeQuery.getLte() instanceof Double);
+ numericRangeQuery.getLte() instanceof Double);
assertEquals("Unexpected marshalled value for 'gt'. Expected: " + greaterThanDouble + " Actual: "
+ numericRangeQuery.getGt(), greaterThanDouble, numericRangeQuery.getGt());
@@ -363,7 +363,7 @@ public class QueryTest {
assertTrue(
"Unexpected ElasticSearch syntax. Expected: " + numericRangeExpectedES + " Actual: "
+ numericRangeQuery.toElasticSearch(),
- numericRangeExpectedES.equals(numericRangeQuery.toElasticSearch()));
- }
+ numericRangeExpectedES.equals(numericRangeQuery.toElasticSearch()));
+ }
}
diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/RangeQueryTest.java b/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/RangeQueryTest.java
index e8ca844..f048cee 100644
--- a/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/RangeQueryTest.java
+++ b/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/RangeQueryTest.java
@@ -1,149 +1,155 @@
-/**
- * ============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.searchapi;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import java.io.File;
-import java.io.IOException;
-import org.junit.Assert;
-import org.junit.Test;
-import org.onap.aai.sa.rest.TestUtils;
-
-public class RangeQueryTest {
-
- @Test(expected = IllegalArgumentException.class)
- public void testSetGt() {
-
- RangeQuery rq = new RangeQuery();
- rq.setLt(new String("2x"));
- Assert.assertEquals("2x", rq.getLt());
- Assert.assertNotNull(rq.toElasticSearch());
- Assert.assertNotNull(rq.toString());
- rq.setGt(new Integer(1));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testSetGte() {
-
- RangeQuery rq = new RangeQuery();
- rq.setGt(new Integer(1));
- Assert.assertNotNull(rq.toElasticSearch());
- Assert.assertNotNull(rq.toString());
- rq.setGte(new Integer(1));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testSetLt() {
-
- RangeQuery rq = new RangeQuery();
- rq.setLt(new Integer(1));
- rq.setFormat("format-1");
- Assert.assertEquals(rq.getFormat(), "format-1");
- Assert.assertNotNull(rq.toElasticSearch());
- Assert.assertNotNull(rq.toString());
-
- rq.setGt(new Integer(1));
- Assert.assertNotNull(rq.toElasticSearch());
- Assert.assertNotNull(rq.toString());
- rq.setLt(new String("10"));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testSetLte() {
- RangeQuery rq = new RangeQuery();
- rq.setGt(new Integer(1));
- rq.setTimeZone("CT");
- Assert.assertEquals(rq.getTimeZone(), "CT");
- Assert.assertNotNull(rq.toElasticSearch());
- Assert.assertNotNull(rq.toString());
-
- rq.setLte(new String("10"));
- }
-
- @Test
- public void testSearchStatementAggregations() throws IOException {
- File queryWithSubrangeFile = new File("src/test/resources/json/queries/query-with-subrange.json");
- String queryWithSubrangeStr = TestUtils.readFileToString(queryWithSubrangeFile);
-
- ObjectMapper mapper = new ObjectMapper();
- SearchStatement ss = mapper.readValue(queryWithSubrangeStr, SearchStatement.class);
-
- Aggregation a1 = getAggregationObject();
- Aggregation a2 = getAggregationObject();
- Aggregation[] aggs = new Aggregation[] {a1, a2};
- ss.setAggregations(aggs);
- Assert.assertNotNull(ss.toString());
- }
-
- private Aggregation getAggregationObject() {
- Aggregation a = new Aggregation();
-
- AggregationStatement as = new AggregationStatement();
- DateHistogramAggregation dha = new DateHistogramAggregation();
- dha.setField("field-1");
- dha.setInterval("interval-1");
- Assert.assertEquals(dha.getInterval(), "interval-1");
- dha.setTimeZone("CT");
- Assert.assertEquals(dha.getTimeZone(), "CT");
- dha.setFormat("format-1");
- Assert.assertEquals(dha.getFormat(), "format-1");
- dha.setSize(10);
- dha.setMinThreshold(1);
- Assert.assertNotNull(dha.toElasticSearch());
- Assert.assertNotNull(dha.toString());
- as.setDateHist(dha);
- as.toString();
-
- as.getNestedPath();
-
- DateRangeAggregation dra = new DateRangeAggregation();
- dra.setField("field-1");
- dra.setMinThreshold(1);
- dra.setFormat("format-1");
- Assert.assertEquals(dra.getFormat(), "format-1");
- DateRange dr = new DateRange();
- dr.setFromDate("01-12-2017");
- Assert.assertEquals(dr.getFromDate(), "01-12-2017");
- dr.setToDate("21-12-2017");
- Assert.assertEquals(dr.getToDate(), "21-12-2017");
- DateRange[] drs = {dr};
- dra.setDateRanges(drs);
- Assert.assertTrue(dra.getDateRanges().length == 1);
- Assert.assertNotNull(dra.toElasticSearch());
- Assert.assertNotNull(dra.toString());
- as.setDateRange(dra);
- as.toString();
-
- as.getNestedPath();
-
- GroupByAggregation gba = new GroupByAggregation();
- gba.setField("field-1");
- gba.setMinThreshold(1);
- Assert.assertNotNull(gba.toElasticSearch());
- Assert.assertNotNull(gba.toString());
- as.setGroupBy(gba);
- Assert.assertNotNull(as.toString());
-
- a.setStatement(as);
- Assert.assertNotNull(a.toString());
- return a;
- }
-}
+/**
+ * ============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.searchapi;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.File;
+import java.io.IOException;
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.aai.sa.rest.TestUtils;
+
+public class RangeQueryTest {
+
+ static {
+ // Set the location of the payload translation JSON file.
+ System.setProperty("CONFIG_HOME", "src/test/resources/json");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetGt() {
+ RangeQuery rq = new RangeQuery();
+ rq.setLt(new String("2x"));
+ Assert.assertEquals("2x", rq.getLt());
+ Assert.assertNotNull(rq.toElasticSearch());
+ Assert.assertNotNull(rq.toString());
+ rq.setGt(new Integer(1));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetGte() {
+ RangeQuery rq = new RangeQuery();
+ rq.setGt(new Integer(1));
+ Assert.assertNotNull(rq.toElasticSearch());
+ Assert.assertNotNull(rq.toString());
+ rq.setGte(new Integer(1));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetLt() {
+ RangeQuery rq = new RangeQuery();
+ rq.setLt(new Integer(1));
+ rq.setFormat("format-1");
+ assertThat(rq.getFormat(), is(equalTo("format-1")));
+ Assert.assertNotNull(rq.toElasticSearch());
+ Assert.assertNotNull(rq.toString());
+
+ rq.setGt(new Integer(1));
+ Assert.assertNotNull(rq.toElasticSearch());
+ Assert.assertNotNull(rq.toString());
+ rq.setLt(new String("10"));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetLte() {
+ RangeQuery rq = new RangeQuery();
+ rq.setGt(new Integer(1));
+ rq.setTimeZone("CT");
+ assertThat(rq.getTimeZone(), is(equalTo("CT")));
+ Assert.assertNotNull(rq.toElasticSearch());
+ Assert.assertNotNull(rq.toString());
+
+ rq.setLte(new String("10"));
+ }
+
+ @Test
+ public void testSearchStatementAggregations() throws IOException {
+ File queryWithSubrangeFile = new File("src/test/resources/json/queries/query-with-subrange.json");
+ String queryWithSubrangeStr = TestUtils.readFileToString(queryWithSubrangeFile);
+
+ ObjectMapper mapper = new ObjectMapper();
+ SearchStatement ss = mapper.readValue(queryWithSubrangeStr, SearchStatement.class);
+
+ Aggregation a1 = getAggregationObject();
+ Aggregation a2 = getAggregationObject();
+ Aggregation[] aggs = new Aggregation[] {a1, a2};
+ ss.setAggregations(aggs);
+ Assert.assertNotNull(ss.toString());
+ }
+
+ private Aggregation getAggregationObject() {
+ Aggregation a = new Aggregation();
+
+ AggregationStatement as = new AggregationStatement();
+ DateHistogramAggregation dha = new DateHistogramAggregation();
+ dha.setField("field-1");
+ dha.setInterval("interval-1");
+ assertThat(dha.getInterval(), is(equalTo("interval-1")));
+ dha.setTimeZone("CT");
+ assertThat(dha.getTimeZone(), is(equalTo("CT")));
+ dha.setFormat("format-1");
+ assertThat(dha.getFormat(), is(equalTo("format-1")));
+ dha.setSize(10);
+ dha.setMinThreshold(1);
+ Assert.assertNotNull(dha.toElasticSearch());
+ Assert.assertNotNull(dha.toString());
+ as.setDateHist(dha);
+ as.toString();
+
+ as.getNestedPath();
+
+ DateRangeAggregation dra = new DateRangeAggregation();
+ dra.setField("field-1");
+ dra.setMinThreshold(1);
+ dra.setFormat("format-1");
+ assertThat(dra.getFormat(), is(equalTo("format-1")));
+ DateRange dr = new DateRange();
+ dr.setFromDate("01-12-2017");
+ assertThat(dr.getFromDate(), is(equalTo("01-12-2017")));
+ dr.setToDate("21-12-2017");
+ assertThat(dr.getToDate(), is(equalTo("21-12-2017")));
+ DateRange[] drs = {dr};
+ dra.setDateRanges(drs);
+ Assert.assertTrue(dra.getDateRanges().length == 1);
+ Assert.assertNotNull(dra.toElasticSearch());
+ Assert.assertNotNull(dra.toString());
+ as.setDateRange(dra);
+ as.toString();
+
+ as.getNestedPath();
+
+ GroupByAggregation gba = new GroupByAggregation();
+ gba.setField("field-1");
+ gba.setMinThreshold(1);
+ Assert.assertNotNull(gba.toElasticSearch());
+ Assert.assertNotNull(gba.toString());
+ as.setGroupBy(gba);
+ Assert.assertNotNull(as.toString());
+
+ a.setStatement(as);
+ Assert.assertNotNull(a.toString());
+ return a;
+ }
+}
diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/TermQueryTest.java b/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/TermQueryTest.java
index 403ad6e..5a15913 100644
--- a/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/TermQueryTest.java
+++ b/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/TermQueryTest.java
@@ -29,11 +29,9 @@ public class TermQueryTest {
@Test
public void testAllMethods() throws IOException {
-
String field = "searchTags.nested";
String stringValue = "theValue.nested";
String termQueryWithStringValueJson = "{\"field\": \"" + field + "\", \"value\": \"" + stringValue + "\"}";
- String termQueryWithStringValueExpectedES = "{\"term\": {\"" + field + "\" : \"" + stringValue + "\"}}";
ObjectMapper mapper = new ObjectMapper();
TermQuery stringTermQuery = mapper.readValue(termQueryWithStringValueJson, TermQuery.class);