2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.aai.rest;
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;
32 import javax.ws.rs.core.Response;
33 import java.util.HashMap;
35 import java.util.UUID;
37 import static org.junit.Assert.assertEquals;
39 @RunWith(AAIJunitRunner.class)
40 public class TenantTest {
42 private HttpTestUtil httpTestUtil;
44 private Map<String, String> templateValuesMap;
48 httpTestUtil = new HttpTestUtil();
49 templateValuesMap = new HashMap<>();
52 @Ignore("Test is failing due to the deletion of node with children not correct will be fixed soon")
54 public void testCloudRegionTenantDeleteSuccessWithoutDeletingVserver() throws Exception {
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());
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")
67 String tenantUri = cloudRegionUri + "/tenants/tenant/" + templateValuesMap.get("tenant-id");
68 String tenantPayload = PayloadUtil.getTemplatePayload("tenant.json", templateValuesMap);
70 Response response = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
71 assertEquals("Expected the cloud region to be created", 201, response.getStatus());
73 response = httpTestUtil.doGet(tenantUri);
74 assertEquals("Expected the cloud region to be created", 200, response.getStatus());
75 String responseStr = response.getEntity().toString();
77 JSONAssert.assertEquals(tenantPayload, responseStr, false);
78 String resourceVersion = JsonPath.read(responseStr, "$.resource-version");
80 response = httpTestUtil.doDelete(tenantUri, resourceVersion);
81 assertEquals("Expected the cloud region to be created", 204, response.getStatus());
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");
88 response = httpTestUtil.doDelete(cloudRegionUri, resourceVersion);
89 assertEquals("Expected the cloud region to be created", 204, response.getStatus());