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.util.Arrays;
29 import java.util.Collection;
31 import javax.ws.rs.core.Response;
33 import org.junit.Before;
34 import org.junit.Ignore;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.junit.runners.Parameterized;
38 import org.onap.aai.AAISetup;
39 import org.onap.aai.HttpTestUtil;
40 import org.onap.aai.PayloadUtil;
41 import org.onap.aai.exceptions.AAIException;
42 import org.onap.aai.serialization.engines.QueryStyle;
43 import org.skyscreamer.jsonassert.JSONAssert;
45 @RunWith(value = Parameterized.class)
46 public class VipAddressListTest extends AAISetup {
48 private HttpTestUtil httpTestUtil;
50 @Parameterized.Parameter(value = 0)
51 public QueryStyle queryStyle;
53 @Parameterized.Parameters(name = "QueryStyle.{0}")
54 public static Collection<Object[]> data() {
55 return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL_URI}});
60 httpTestUtil = new HttpTestUtil(queryStyle);
64 public void testPutWithAllCloudRegionChildrenNodesAndCheckIfDeleteIsSuccessful() throws IOException, AAIException {
66 String cloudRegionPayload = PayloadUtil.getResourcePayload("cloud-region.json");
67 String cloudRegionUri =
68 "/aai/v14/cloud-infrastructure/cloud-regions/cloud-region/cloud-region-owner-with-vip-ipv4/cloud-region-id-with-vip-ipv4";
70 Response response = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
71 assertEquals("Expected the cloud region to be created", 201, response.getStatus());
73 response = httpTestUtil.doGet(cloudRegionUri);
74 assertEquals("Expected the cloud region to be found", 200, response.getStatus());
75 String jsonResponse = response.getEntity().toString();
77 JSONAssert.assertEquals(cloudRegionPayload, jsonResponse, false);
79 String vipIpv4Uri = cloudRegionUri + "/vip-ipv4-address-list/vip-ipv4-address-list-1";
80 String vipIpv4Payload = PayloadUtil.getResourcePayload("vip-ipv4-address-list.json");
82 response = httpTestUtil.doPut(vipIpv4Uri, vipIpv4Payload);
83 assertEquals("Expected the ipv4 address list to be created", 201, response.getStatus());
85 response = httpTestUtil.doGet(vipIpv4Uri);
86 assertEquals("Expected the ipv4 address list to be found", 200, response.getStatus());
88 jsonResponse = response.getEntity().toString();
89 String resourceVersion = JsonPath.read(jsonResponse, "$.resource-version");
91 response = httpTestUtil.doDelete(vipIpv4Uri, resourceVersion);
92 assertEquals("Expected the ipv4 address list to be deleted", 204, response.getStatus());
94 response = httpTestUtil.doGet(cloudRegionUri);
95 jsonResponse = response.getEntity().toString();
96 resourceVersion = JsonPath.read(jsonResponse, "$.resource-version");
98 response = httpTestUtil.doDelete(cloudRegionUri, resourceVersion);
99 assertEquals("Expected the cloud region to be deleted", 204, response.getStatus());