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