2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License ati
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
25 package org.openecomp.sa.rest;
27 import org.glassfish.jersey.server.ResourceConfig;
28 import org.glassfish.jersey.test.JerseyTest;
29 import org.junit.Test;
31 import javax.ws.rs.client.Entity;
32 import javax.ws.rs.core.Application;
33 import javax.ws.rs.core.Response;
34 import java.io.BufferedReader;
36 import java.io.FileReader;
37 import java.io.IOException;
39 import static org.junit.Assert.assertEquals;
43 * This suite of tests validates the behaviour of the bulk operations REST
46 public class BulkApiTest extends JerseyTest {
48 private final String TOP_URI = "/test/bulk/";
52 protected Application configure() {
54 // Make sure that our test endpoint is on the resource path
56 return new ResourceConfig(SearchServiceApiHarness.class);
61 * This test validates that the expected response codes are returned
62 * to the client in the event of an authentication failure.
65 public void authenticationFailureTest() {
67 // Send a request to the end point, with a special trigger in the
68 // payload that tells our test harness to force the authentication
70 Response result = target(TOP_URI).request().post(Entity.json(SearchServiceApiHarness.FAIL_AUTHENTICATION_TRIGGER), Response.class);
72 // Validate that a failure to authenticate results in the expected
73 // response code returned to the client.
74 assertEquals(Response.Status.FORBIDDEN.getStatusCode(), result.getStatus());
79 * This test validates that properly constructed json payloads are
80 * correctly validated and that improperly contructed payloads will
81 * be rejected with the appropriate response code returned to the
87 public void payloadValidationTest() throws IOException {
89 // Post a request to the bulk operations endpoint with a valid
90 // operations list payload.
91 File validBulkOpsFile = new File("src/test/resources/json/bulk-ops-valid.json");
92 String validPayloadStr = TestUtils.readFileToString(validBulkOpsFile);
93 Response validResult = target(TOP_URI).request().post(Entity.json(validPayloadStr), Response.class);
95 // Validate that the payload is accepted as expected.
96 assertEquals("Valid operations payload was rejected",
97 Response.Status.OK.getStatusCode(), validResult.getStatus());
99 // Post a request to the bulk operations endpoint with an invalid
100 // operations list payload.
101 File inValidBulkOpsFile = new File("src/test/resources/json/bulk-ops-invalid.json");
102 String inValidPayloadStr = TestUtils.readFileToString(inValidBulkOpsFile);
103 Response invalidResult = target(TOP_URI).request().post(Entity.json(inValidPayloadStr), Response.class);
105 // Validate that the payload is rejected as expected.
106 assertEquals("Invalid operations payload was not rejected",
107 Response.Status.BAD_REQUEST.getStatusCode(), invalidResult.getStatus());