aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/aai/sa/rest
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/onap/aai/sa/rest')
-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
8 files changed, 32 insertions, 61 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);