2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.aai.sa.rest;
23 import org.glassfish.jersey.server.ResourceConfig;
24 import org.glassfish.jersey.test.JerseyTest;
25 import org.junit.Test;
27 import javax.ws.rs.client.Entity;
28 import javax.ws.rs.core.Application;
29 import javax.ws.rs.core.Response;
30 import java.io.BufferedReader;
32 import java.io.FileReader;
33 import java.io.IOException;
35 import static org.junit.Assert.assertEquals;
39 * This suite of tests validates the behaviour of the bulk operations REST
42 public class BulkApiTest extends JerseyTest {
44 private final String TOP_URI = "/test/bulk/";
48 protected Application configure() {
50 // Make sure that our test endpoint is on the resource path
52 return new ResourceConfig(SearchServiceApiHarness.class);
57 * This test validates that the expected response codes are returned
58 * to the client in the event of an authentication failure.
61 public void authenticationFailureTest() {
63 // Send a request to the end point, with a special trigger in the
64 // payload that tells our test harness to force the authentication
66 Response result = target(TOP_URI).request().post(Entity.json(SearchServiceApiHarness.FAIL_AUTHENTICATION_TRIGGER), Response.class);
68 // Validate that a failure to authenticate results in the expected
69 // response code returned to the client.
70 assertEquals(Response.Status.FORBIDDEN.getStatusCode(), result.getStatus());
75 * This test validates that properly constructed json payloads are
76 * correctly validated and that improperly contructed payloads will
77 * be rejected with the appropriate response code returned to the
83 public void payloadValidationTest() throws IOException {
85 // Post a request to the bulk operations endpoint with a valid
86 // operations list payload.
87 File validBulkOpsFile = new File("src/test/resources/json/bulk-ops-valid.json");
88 String validPayloadStr = TestUtils.readFileToString(validBulkOpsFile);
89 Response validResult = target(TOP_URI).request().post(Entity.json(validPayloadStr), Response.class);
91 // Validate that the payload is accepted as expected.
92 assertEquals("Valid operations payload was rejected",
93 Response.Status.OK.getStatusCode(), validResult.getStatus());
95 // Post a request to the bulk operations endpoint with an invalid
96 // operations list payload.
97 File inValidBulkOpsFile = new File("src/test/resources/json/bulk-ops-invalid.json");
98 String inValidPayloadStr = TestUtils.readFileToString(inValidBulkOpsFile);
99 Response invalidResult = target(TOP_URI).request().post(Entity.json(inValidPayloadStr), Response.class);
101 // Validate that the payload is rejected as expected.
102 assertEquals("Invalid operations payload was not rejected",
103 Response.Status.BAD_REQUEST.getStatusCode(), invalidResult.getStatus());