55fdd53d0990f5ba64315e7d2211e66321ac0136
[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 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22 package org.onap.aai.rest;
23
24 import com.jayway.jsonpath.JsonPath;
25 import org.junit.Before;
26 import org.junit.Ignore;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.onap.aai.AAIJunitRunner;
30 import org.onap.aai.HttpTestUtil;
31 import org.onap.aai.PayloadUtil;
32 import org.onap.aai.exceptions.AAIException;
33 import org.skyscreamer.jsonassert.JSONAssert;
34
35 import javax.ws.rs.core.Response;
36 import java.io.IOException;
37
38 import static org.junit.Assert.assertEquals;
39
40 /**
41  * <b>CloudRegionTest</b> is testing if you put a cloud region with all
42  * children nodes associated to it then you should be able to
43  * remove the cloud region without removing the individual child nodes first
44  */
45 @RunWith(AAIJunitRunner.class)
46 public class CloudRegionTest {
47
48     private HttpTestUtil httpTestUtil;
49
50     @Before
51     public void setUp(){
52         httpTestUtil = new HttpTestUtil();
53     }
54
55     @Ignore("Test is failing due to the deletion of node with children not correct will be fixed soon")
56     @Test
57     public void testPutWithAllCloudRegionChildrenNodesAndCheckIfDeleteIsSuccessful() throws IOException, AAIException {
58
59         String cloudRegionPayload = PayloadUtil.getResourcePayload("cloud-region-with-all-children.json");
60         String cloudRegionUri = "/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/junit-cloud-owner/junit-cloud-region";
61
62         Response response     = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
63         assertEquals("Expected the cloud region to be created", 201, response.getStatus());
64
65         response = httpTestUtil.doGet(cloudRegionUri);
66         assertEquals("Expected the cloud region to be found", 200, response.getStatus());
67         String jsonResponse = response.getEntity().toString();
68
69         JSONAssert.assertEquals(cloudRegionPayload, jsonResponse, false);
70         String resourceVersion = JsonPath.read(jsonResponse, "$.resource-version");
71
72         response = httpTestUtil.doDelete(cloudRegionUri, resourceVersion);
73         assertEquals("Expected the cloud region to be deleted", 204, response.getStatus());
74     }
75
76 }