aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/aai/sa/rest/BulkApiTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/onap/aai/sa/rest/BulkApiTest.java')
-rw-r--r--src/test/java/org/onap/aai/sa/rest/BulkApiTest.java131
1 files changed, 58 insertions, 73 deletions
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 ebd9337..c7e9702 100644
--- a/src/test/java/org/onap/aai/sa/rest/BulkApiTest.java
+++ b/src/test/java/org/onap/aai/sa/rest/BulkApiTest.java
@@ -20,86 +20,71 @@
*/
package org.onap.aai.sa.rest;
-import org.glassfish.jersey.server.ResourceConfig;
-import org.glassfish.jersey.test.JerseyTest;
-import org.junit.Test;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.core.Application;
-import javax.ws.rs.core.Response;
-import java.io.BufferedReader;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+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;
import java.io.File;
-import java.io.FileReader;
import java.io.IOException;
-import static org.junit.Assert.assertEquals;
-
/**
* This suite of tests validates the behaviour of the bulk operations REST
* end point.
*/
-public class BulkApiTest extends JerseyTest {
-
- private final String TOP_URI = "/test/bulk/";
-
-
- @Override
- protected Application configure() {
-
- // Make sure that our test endpoint is on the resource path
- // for Jersey Test.
- return new ResourceConfig(SearchServiceApiHarness.class);
- }
-
-
- /**
- * This test validates that the expected response codes are returned
- * to the client in the event of an authentication failure.
- */
- @Test
- public void authenticationFailureTest() {
-
- // Send a request to the end point, with a special trigger in the
- // payload that tells our test harness to force the authentication
- // to fail.
- Response result = target(TOP_URI).request().post(Entity.json(SearchServiceApiHarness.FAIL_AUTHENTICATION_TRIGGER), Response.class);
-
- // Validate that a failure to authenticate results in the expected
- // response code returned to the client.
- assertEquals(Response.Status.FORBIDDEN.getStatusCode(), result.getStatus());
- }
-
-
- /**
- * This test validates that properly constructed json payloads are
- * correctly validated and that improperly contructed payloads will
- * be rejected with the appropriate response code returned to the
- * client.
- *
- * @throws IOException
- */
- @Test
- public void payloadValidationTest() throws IOException {
-
- // Post a request to the bulk operations endpoint with a valid
- // operations list payload.
- File validBulkOpsFile = new File("src/test/resources/json/bulk-ops-valid.json");
- String validPayloadStr = TestUtils.readFileToString(validBulkOpsFile);
- Response validResult = target(TOP_URI).request().post(Entity.json(validPayloadStr), Response.class);
-
- // Validate that the payload is accepted as expected.
- assertEquals("Valid operations payload was rejected",
- Response.Status.OK.getStatusCode(), validResult.getStatus());
-
- // 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);
- Response invalidResult = target(TOP_URI).request().post(Entity.json(inValidPayloadStr), Response.class);
-
- // Validate that the payload is rejected as expected.
- assertEquals("Invalid operations payload was not rejected",
- Response.Status.BAD_REQUEST.getStatusCode(), invalidResult.getStatus());
- }
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = org.onap.aai.sa.Application.class)
+@AutoConfigureMockMvc
+public class BulkApiTest {
+
+ private final String TOP_URI = "/test/bulk";
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @Test
+ public void authenticationFailureTest() throws Exception {
+
+ this.mockMvc.perform ( post ( TOP_URI) .contentType( MediaType.APPLICATION_JSON)
+ .content ( SearchServiceApiHarness.FAIL_AUTHENTICATION_TRIGGER )).andExpect ( status ().isForbidden () );
+ }
+
+
+ /**
+ * This test validates that properly constructed json payloads are
+ * correctly validated and that improperly contructed payloads will
+ * be rejected with the appropriate response code returned to the
+ * client.
+ *
+ * @throws IOException
+ */
+ @Test
+ public void payloadValidationTest() throws Exception {
+
+ // Post a request to the bulk operations endpoint with a valid
+ // operations list payload.
+ File validBulkOpsFile = new File ("src/test/resources/json/bulk-ops-valid.json");
+ String validPayloadStr = TestUtils.readFileToString(validBulkOpsFile);
+
+ // Validate that the payload is accepted as expected.
+ 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 ());
+ }
}