AAI-1523 Batch reformat aai-core
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / rest / CloudRegionTest.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.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;
44
45 /**
46  * <b>CloudRegionTest</b> is testing if you put a cloud region with all
47  * children nodes associated to it then you should be able to
48  * remove the cloud region without removing the individual child nodes first
49  */
50 @RunWith(value = Parameterized.class)
51 public class CloudRegionTest extends AAISetup {
52
53     private HttpTestUtil httpTestUtil;
54
55     @Parameterized.Parameter(value = 0)
56     public QueryStyle queryStyle;
57
58     @Parameterized.Parameters(name = "QueryStyle.{0}")
59     public static Collection<Object[]> data() {
60         return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
61     }
62
63     @Before
64     public void setUp() {
65         httpTestUtil = new HttpTestUtil(queryStyle);
66     }
67
68     @Ignore("Test is failing due to the deletion of node with children not correct will be fixed soon")
69     @Test
70     public void testPutWithAllCloudRegionChildrenNodesAndCheckIfDeleteIsSuccessful() throws IOException, AAIException {
71
72         String cloudRegionPayload = PayloadUtil.getResourcePayload("cloud-region-with-all-children.json");
73         String cloudRegionUri =
74                 "/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/junit-cloud-owner/junit-cloud-region";
75
76         Response response = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
77         assertEquals("Expected the cloud region to be created", 201, response.getStatus());
78
79         response = httpTestUtil.doGet(cloudRegionUri);
80         assertEquals("Expected the cloud region to be found", 200, response.getStatus());
81         String jsonResponse = response.getEntity().toString();
82
83         JSONAssert.assertEquals(cloudRegionPayload, jsonResponse, false);
84         String resourceVersion = JsonPath.read(jsonResponse, "$.resource-version");
85
86         response = httpTestUtil.doDelete(cloudRegionUri, resourceVersion);
87         assertEquals("Expected the cloud region to be deleted", 204, response.getStatus());
88     }
89 }