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.Before;
24 import org.junit.Ignore;
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;
35 import javax.ws.rs.core.Response;
36 import java.io.IOException;
37 import java.util.Arrays;
38 import java.util.Collection;
40 import static org.junit.Assert.assertEquals;
42 @RunWith(value = Parameterized.class)
43 public class VipAddressListTest extends AAISetup {
45 private HttpTestUtil httpTestUtil;
47 @Parameterized.Parameter(value = 0)
48 public QueryStyle queryStyle;
50 @Parameterized.Parameters(name = "QueryStyle.{0}")
51 public static Collection<Object[]> data() {
52 return Arrays.asList(new Object[][]{
53 {QueryStyle.TRAVERSAL_URI}
59 httpTestUtil = new HttpTestUtil(queryStyle);
63 public void testPutWithAllCloudRegionChildrenNodesAndCheckIfDeleteIsSuccessful() throws IOException, AAIException {
65 String cloudRegionPayload = PayloadUtil.getResourcePayload("cloud-region.json");
66 String cloudRegionUri = "/aai/v14/cloud-infrastructure/cloud-regions/cloud-region/cloud-region-owner-with-vip-ipv4/cloud-region-id-with-vip-ipv4";
68 Response response = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
69 assertEquals("Expected the cloud region to be created", 201, response.getStatus());
71 response = httpTestUtil.doGet(cloudRegionUri);
72 assertEquals("Expected the cloud region to be found", 200, response.getStatus());
73 String jsonResponse = response.getEntity().toString();
75 JSONAssert.assertEquals(cloudRegionPayload, jsonResponse, false);
77 String vipIpv4Uri = cloudRegionUri + "/vip-ipv4-address-list/vip-ipv4-address-list-1";
78 String vipIpv4Payload = PayloadUtil.getResourcePayload("vip-ipv4-address-list.json");
80 response = httpTestUtil.doPut(vipIpv4Uri, vipIpv4Payload);
81 assertEquals("Expected the ipv4 address list to be created", 201, response.getStatus());
83 response = httpTestUtil.doGet(vipIpv4Uri);
84 assertEquals("Expected the ipv4 address list to be found", 200, response.getStatus());
86 jsonResponse = response.getEntity().toString();
87 String resourceVersion = JsonPath.read(jsonResponse, "$.resource-version");
89 response = httpTestUtil.doDelete(vipIpv4Uri, resourceVersion);
90 assertEquals("Expected the ipv4 address list to be deleted", 204, response.getStatus());
92 response = httpTestUtil.doGet(cloudRegionUri);
93 jsonResponse = response.getEntity().toString();
94 resourceVersion = JsonPath.read(jsonResponse, "$.resource-version");
96 response = httpTestUtil.doDelete(cloudRegionUri, resourceVersion);
97 assertEquals("Expected the cloud region to be deleted", 204, response.getStatus());