* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 Amdocs
+ * 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.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.sa.rest;
-import org.glassfish.jersey.server.ResourceConfig;
-import org.glassfish.jersey.test.JerseyTest;
-import org.junit.Test;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.core.Application;
-import javax.ws.rs.core.Response;
-import java.io.BufferedReader;
import java.io.File;
-import java.io.FileReader;
import java.io.IOException;
-
-import static org.junit.Assert.assertEquals;
+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;
/**
- * This suite of tests validates the behaviour of the bulk operations REST
- * end point.
+ * 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);
+ this.mockMvc.perform(post(TOP_URI).contentType(MediaType.APPLICATION_JSON).content(inValidPayloadStr))
+ .andExpect(status().isBadRequest());
+ }
}