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=========================================================
21 package org.onap.aai.rest;
23 import static org.junit.Assert.assertEquals;
25 import com.jayway.jsonpath.JsonPath;
27 import java.io.IOException;
28 import java.io.UnsupportedEncodingException;
29 import java.util.Arrays;
30 import java.util.Collection;
32 import javax.ws.rs.core.Response;
34 import org.junit.After;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.junit.runners.Parameterized;
39 import org.onap.aai.AAISetup;
40 import org.onap.aai.HttpTestUtil;
41 import org.onap.aai.PayloadUtil;
42 import org.onap.aai.exceptions.AAIException;
43 import org.onap.aai.serialization.engines.QueryStyle;
44 import org.skyscreamer.jsonassert.JSONAssert;
45 import org.springframework.test.annotation.DirtiesContext;
47 @RunWith(value = Parameterized.class)
48 @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
49 public class EntitlementTest extends AAISetup {
51 private HttpTestUtil httpTestUtil;
53 @Parameterized.Parameter(value = 0)
54 public QueryStyle queryStyle;
56 private String vnfPayload;
58 private String vnfUri;
60 @Parameterized.Parameters(name = "QueryStyle.{0}")
61 public static Collection<Object[]> data() {
62 return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL_URI}});
66 public void setUp() throws IOException {
67 httpTestUtil = new HttpTestUtil(queryStyle);
68 vnfPayload = PayloadUtil.getResourcePayload("vnf.json");
69 vnfUri = "/aai/v14/network/generic-vnfs/generic-vnf/vnf1";
73 public void testPutGenericVnfAndThenInsertEntitlement() throws IOException, AAIException {
74 String entitlementPayload = PayloadUtil.getResourcePayload("entitlement.json");
75 String entitlementUri = "/aai/v14/network/generic-vnfs/generic-vnf/vnf1/entitlements/entitlement/g1/r1";
76 Response response = httpTestUtil.doPut(vnfUri, vnfPayload);
77 assertEquals("Expected the Generic Vnf to be created", 201, response.getStatus());
79 response = httpTestUtil.doGet(vnfUri);
80 assertEquals("Expected the Generic Vnf to be found", 200, response.getStatus());
81 String jsonResponse = response.getEntity().toString();
82 JSONAssert.assertEquals(vnfPayload, jsonResponse, false);
84 response = httpTestUtil.doPut(entitlementUri, entitlementPayload);
85 assertEquals("Expected the Entitlement to be created", 201, response.getStatus());
89 public void tearDown() throws UnsupportedEncodingException, AAIException {
90 Response response = httpTestUtil.doGet(vnfUri);
91 assertEquals("Expected the Generic Vnf to be found", 200, response.getStatus());
92 String jsonResponse = response.getEntity().toString();
93 String resourceVersion = JsonPath.read(jsonResponse, "$.resource-version");
94 response = httpTestUtil.doDelete(vnfUri, resourceVersion);
95 assertEquals("Expected the cloud region to be deleted", 204, response.getStatus());