Improve the performance of resoures microservice
[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 package org.onap.aai.rest;
21
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;
34
35 import javax.ws.rs.core.Response;
36 import java.io.IOException;
37 import java.util.Arrays;
38 import java.util.Collection;
39
40 import static org.junit.Assert.assertEquals;
41
42 @RunWith(value = Parameterized.class)
43 public class VipAddressListTest extends AAISetup {
44
45     private HttpTestUtil httpTestUtil;
46
47     @Parameterized.Parameter(value = 0)
48     public QueryStyle queryStyle;
49
50     @Parameterized.Parameters(name = "QueryStyle.{0}")
51     public static Collection<Object[]> data() {
52         return Arrays.asList(new Object[][]{
53                 {QueryStyle.TRAVERSAL_URI}
54         });
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 = "/aai/v14/cloud-infrastructure/cloud-regions/cloud-region/cloud-region-owner-with-vip-ipv4/cloud-region-id-with-vip-ipv4";
67
68         Response response     = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
69         assertEquals("Expected the cloud region to be created", 201, response.getStatus());
70
71         response = httpTestUtil.doGet(cloudRegionUri);
72         assertEquals("Expected the cloud region to be found", 200, response.getStatus());
73         String jsonResponse = response.getEntity().toString();
74
75         JSONAssert.assertEquals(cloudRegionPayload, jsonResponse, false);
76
77         String vipIpv4Uri = cloudRegionUri + "/vip-ipv4-address-list/vip-ipv4-address-list-1";
78         String vipIpv4Payload = PayloadUtil.getResourcePayload("vip-ipv4-address-list.json");
79
80         response     = httpTestUtil.doPut(vipIpv4Uri, vipIpv4Payload);
81         assertEquals("Expected the ipv4 address list to be created", 201, response.getStatus());
82
83         response = httpTestUtil.doGet(vipIpv4Uri);
84         assertEquals("Expected the ipv4 address list to be found", 200, response.getStatus());
85
86         jsonResponse = response.getEntity().toString();
87         String resourceVersion = JsonPath.read(jsonResponse, "$.resource-version");
88
89         response = httpTestUtil.doDelete(vipIpv4Uri, resourceVersion);
90         assertEquals("Expected the ipv4 address list to be deleted", 204, response.getStatus());
91
92         response = httpTestUtil.doGet(cloudRegionUri);
93         jsonResponse = response.getEntity().toString();
94         resourceVersion = JsonPath.read(jsonResponse, "$.resource-version");
95
96         response = httpTestUtil.doDelete(cloudRegionUri, resourceVersion);
97         assertEquals("Expected the cloud region to be deleted", 204, response.getStatus());
98     }
99 }