2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.aai.rest;
22 import com.jayway.jsonpath.JsonPath;
23 import org.junit.After;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.Parameterized;
28 import org.onap.aai.AAISetup;
29 import org.onap.aai.HttpTestUtil;
30 import org.onap.aai.PayloadUtil;
31 import org.onap.aai.exceptions.AAIException;
32 import org.onap.aai.serialization.engines.QueryStyle;
33 import org.skyscreamer.jsonassert.JSONAssert;
34 import org.springframework.test.annotation.DirtiesContext;
36 import javax.ws.rs.core.Response;
37 import java.io.IOException;
38 import java.io.UnsupportedEncodingException;
39 import java.util.Arrays;
40 import java.util.Collection;
42 import static org.junit.Assert.assertEquals;
44 @RunWith(value = Parameterized.class)
45 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
46 public class EntitlementTest extends AAISetup {
48 private HttpTestUtil httpTestUtil;
50 @Parameterized.Parameter(value = 0)
51 public QueryStyle queryStyle;
53 private String vnfPayload;
55 private String vnfUri;
57 @Parameterized.Parameters(name = "QueryStyle.{0}")
58 public static Collection<Object[]> data() {
59 return Arrays.asList(new Object[][]{
60 {QueryStyle.TRAVERSAL_URI}
65 public void setUp() throws IOException {
66 httpTestUtil = new HttpTestUtil(queryStyle);
67 vnfPayload = PayloadUtil.getResourcePayload("vnf.json");
68 vnfUri = "/aai/v14/network/generic-vnfs/generic-vnf/vnf1";
72 public void testPutGenericVnfAndThenInsertEntitlement() throws IOException, AAIException {
73 String entitlementPayload = PayloadUtil.getResourcePayload("entitlement.json");
74 String entitlementUri = "/aai/v14/network/generic-vnfs/generic-vnf/vnf1/entitlements/entitlement/g1/r1";
75 Response response = httpTestUtil.doPut(vnfUri, vnfPayload);
76 assertEquals("Expected the Generic Vnf to be created", 201, response.getStatus());
78 response = httpTestUtil.doGet(vnfUri);
79 assertEquals("Expected the Generic Vnf to be found", 200, response.getStatus());
80 String jsonResponse = response.getEntity().toString();
81 JSONAssert.assertEquals(vnfPayload, jsonResponse, false);
83 response = httpTestUtil.doPut(entitlementUri, entitlementPayload);
84 assertEquals("Expected the Entitlement to be created", 201, response.getStatus());
88 public void tearDown() throws UnsupportedEncodingException, AAIException {
89 Response response = httpTestUtil.doGet(vnfUri);
90 assertEquals("Expected the Generic Vnf to be found", 200, response.getStatus());
91 String jsonResponse = response.getEntity().toString();
92 String resourceVersion = JsonPath.read(jsonResponse, "$.resource-version");
93 response = httpTestUtil.doDelete(vnfUri, resourceVersion);
94 assertEquals("Expected the cloud region to be deleted", 204, response.getStatus());