Sync the latest code changes
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / rest / TenantTest.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.skyscreamer.jsonassert.JSONAssert;
33
34 import javax.ws.rs.core.Response;
35 import java.util.HashMap;
36 import java.util.Map;
37 import java.util.UUID;
38
39 import static org.junit.Assert.assertEquals;
40
41 @RunWith(AAIJunitRunner.class)
42 public class TenantTest {
43
44     private HttpTestUtil httpTestUtil;
45
46     private Map<String, String> templateValuesMap;
47
48     @Before
49     public void setup(){
50         httpTestUtil      = new HttpTestUtil();
51         templateValuesMap = new HashMap<>();
52     }
53
54     @Ignore("Test is failing due to the deletion of node with children not correct will be fixed soon")
55     @Test
56     public void testCloudRegionTenantDeleteSuccessWithoutDeletingVserver() throws Exception {
57
58         templateValuesMap.put("cloud-region-id", UUID.randomUUID().toString());
59         templateValuesMap.put("cloud-owner", UUID.randomUUID().toString());
60         templateValuesMap.put("tenant-id", UUID.randomUUID().toString());
61         templateValuesMap.put("vserver-id", UUID.randomUUID().toString());
62
63         String cloudRegionPayload = PayloadUtil.getTemplatePayload("cloud-region.json", templateValuesMap);
64         String cloudRegionUri = String.format("/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/%s/%s",
65                 templateValuesMap.get("cloud-owner"),
66                 templateValuesMap.get("cloud-region-id")
67         );
68
69         String tenantUri = cloudRegionUri + "/tenants/tenant/" + templateValuesMap.get("tenant-id");
70         String tenantPayload = PayloadUtil.getTemplatePayload("tenant.json", templateValuesMap);
71
72         Response response     = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
73         assertEquals("Expected the cloud region to be created", 201, response.getStatus());
74
75         response     = httpTestUtil.doGet(tenantUri);
76         assertEquals("Expected the cloud region to be created", 200, response.getStatus());
77         String responseStr = response.getEntity().toString();
78
79         JSONAssert.assertEquals(tenantPayload, responseStr, false);
80         String resourceVersion = JsonPath.read(responseStr, "$.resource-version");
81
82         response     = httpTestUtil.doDelete(tenantUri, resourceVersion);
83         assertEquals("Expected the cloud region to be created", 204, response.getStatus());
84
85         response     = httpTestUtil.doGet(cloudRegionUri);
86         assertEquals("Expected the cloud region to be created", 200, response.getStatus());
87         responseStr = response.getEntity().toString();
88         resourceVersion = JsonPath.read(responseStr, "$.resource-version");
89
90         response     = httpTestUtil.doDelete(cloudRegionUri, resourceVersion);
91         assertEquals("Expected the cloud region to be created", 204, response.getStatus());
92     }
93 }