Merge "[AAI] Fix doc config files"
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / rest / VipAddressListTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.aai.rest;
22
23 import static org.junit.Assert.assertEquals;
24
25 import com.jayway.jsonpath.JsonPath;
26
27 import java.io.IOException;
28 import java.util.Arrays;
29 import java.util.Collection;
30
31 import javax.ws.rs.core.Response;
32
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.junit.runners.Parameterized;
37 import org.onap.aai.AAISetup;
38 import org.onap.aai.HttpTestUtil;
39 import org.onap.aai.PayloadUtil;
40 import org.onap.aai.exceptions.AAIException;
41 import org.onap.aai.serialization.engines.QueryStyle;
42 import org.skyscreamer.jsonassert.JSONAssert;
43
44 @RunWith(value = Parameterized.class)
45 public class VipAddressListTest extends AAISetup {
46
47     private HttpTestUtil httpTestUtil;
48
49     @Parameterized.Parameter(value = 0)
50     public QueryStyle queryStyle;
51
52     @Parameterized.Parameters(name = "QueryStyle.{0}")
53     public static Collection<Object[]> data() {
54         return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL_URI}});
55     }
56
57     @Before
58     public void setUp() {
59         httpTestUtil = new HttpTestUtil(queryStyle);
60     }
61
62     @Test
63     public void testPutWithAllCloudRegionChildrenNodesAndCheckIfDeleteIsSuccessful() throws IOException, AAIException {
64
65         String cloudRegionPayload = PayloadUtil.getResourcePayload("cloud-region.json");
66         String cloudRegionUri =
67                 "/aai/v14/cloud-infrastructure/cloud-regions/cloud-region/cloud-region-owner-with-vip-ipv4/cloud-region-id-with-vip-ipv4";
68
69         Response response = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
70         assertEquals("Expected the cloud region to be created", 201, response.getStatus());
71
72         response = httpTestUtil.doGet(cloudRegionUri);
73         assertEquals("Expected the cloud region to be found", 200, response.getStatus());
74         String jsonResponse = response.getEntity().toString();
75
76         JSONAssert.assertEquals(cloudRegionPayload, jsonResponse, false);
77
78         String vipIpv4Uri = cloudRegionUri + "/vip-ipv4-address-list/vip-ipv4-address-list-1";
79         String vipIpv4Payload = PayloadUtil.getResourcePayload("vip-ipv4-address-list.json");
80
81         response = httpTestUtil.doPut(vipIpv4Uri, vipIpv4Payload);
82         assertEquals("Expected the ipv4 address list to be created", 201, response.getStatus());
83
84         response = httpTestUtil.doGet(vipIpv4Uri);
85         assertEquals("Expected the ipv4 address list to be found", 200, response.getStatus());
86
87         jsonResponse = response.getEntity().toString();
88         String resourceVersion = JsonPath.read(jsonResponse, "$.resource-version");
89
90         response = httpTestUtil.doDelete(vipIpv4Uri, resourceVersion);
91         assertEquals("Expected the ipv4 address list to be deleted", 204, response.getStatus());
92
93         response = httpTestUtil.doGet(cloudRegionUri);
94         jsonResponse = response.getEntity().toString();
95         resourceVersion = JsonPath.read(jsonResponse, "$.resource-version");
96
97         response = httpTestUtil.doDelete(cloudRegionUri, resourceVersion);
98         assertEquals("Expected the cloud region to be deleted", 204, response.getStatus());
99     }
100 }