2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.sa.rest;
25 import org.glassfish.jersey.server.ResourceConfig;
26 import org.glassfish.jersey.test.JerseyTest;
27 import org.junit.Test;
29 import javax.ws.rs.client.Entity;
30 import javax.ws.rs.core.Application;
31 import javax.ws.rs.core.Response;
32 import java.io.BufferedReader;
34 import java.io.FileReader;
35 import java.io.IOException;
37 import static org.junit.Assert.assertEquals;
41 * This suite of tests validates the behaviour of the bulk operations REST
44 public class BulkApiTest extends JerseyTest {
46 private final String TOP_URI = "/test/bulk/";
50 protected Application configure() {
52 // Make sure that our test endpoint is on the resource path
54 return new ResourceConfig(SearchServiceApiHarness.class);
59 * This test validates that the expected response codes are returned
60 * to the client in the event of an authentication failure.
63 public void authenticationFailureTest() {
65 // Send a request to the end point, with a special trigger in the
66 // payload that tells our test harness to force the authentication
68 Response result = target(TOP_URI).request().post(Entity.json(SearchServiceApiHarness.FAIL_AUTHENTICATION_TRIGGER), Response.class);
70 // Validate that a failure to authenticate results in the expected
71 // response code returned to the client.
72 assertEquals(Response.Status.FORBIDDEN.getStatusCode(), result.getStatus());
77 * This test validates that properly constructed json payloads are
78 * correctly validated and that improperly contructed payloads will
79 * be rejected with the appropriate response code returned to the
85 public void payloadValidationTest() throws IOException {
87 // Post a request to the bulk operations endpoint with a valid
88 // operations list payload.
89 File validBulkOpsFile = new File("src/test/resources/json/bulk-ops-valid.json");
90 String validPayloadStr = TestUtils.readFileToString(validBulkOpsFile);
91 Response validResult = target(TOP_URI).request().post(Entity.json(validPayloadStr), Response.class);
93 // Validate that the payload is accepted as expected.
94 assertEquals("Valid operations payload was rejected",
95 Response.Status.OK.getStatusCode(), validResult.getStatus());
97 // Post a request to the bulk operations endpoint with an invalid
98 // operations list payload.
99 File inValidBulkOpsFile = new File("src/test/resources/json/bulk-ops-invalid.json");
100 String inValidPayloadStr = TestUtils.readFileToString(inValidBulkOpsFile);
101 Response invalidResult = target(TOP_URI).request().post(Entity.json(inValidPayloadStr), Response.class);
103 // Validate that the payload is rejected as expected.
104 assertEquals("Invalid operations payload was not rejected",
105 Response.Status.BAD_REQUEST.getStatusCode(), invalidResult.getStatus());