2 * ============LICENSE_START=======================================================
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
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.rest;
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;
34 import javax.ws.rs.core.Response;
35 import java.util.HashMap;
37 import java.util.UUID;
39 import static org.junit.Assert.assertEquals;
41 @RunWith(AAIJunitRunner.class)
42 public class TenantTest {
44 private HttpTestUtil httpTestUtil;
46 private Map<String, String> templateValuesMap;
50 httpTestUtil = new HttpTestUtil();
51 templateValuesMap = new HashMap<>();
54 @Ignore("Test is failing due to the deletion of node with children not correct will be fixed soon")
56 public void testCloudRegionTenantDeleteSuccessWithoutDeletingVserver() throws Exception {
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());
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")
69 String tenantUri = cloudRegionUri + "/tenants/tenant/" + templateValuesMap.get("tenant-id");
70 String tenantPayload = PayloadUtil.getTemplatePayload("tenant.json", templateValuesMap);
72 Response response = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
73 assertEquals("Expected the cloud region to be created", 201, response.getStatus());
75 response = httpTestUtil.doGet(tenantUri);
76 assertEquals("Expected the cloud region to be created", 200, response.getStatus());
77 String responseStr = response.getEntity().toString();
79 JSONAssert.assertEquals(tenantPayload, responseStr, false);
80 String resourceVersion = JsonPath.read(responseStr, "$.resource-version");
82 response = httpTestUtil.doDelete(tenantUri, resourceVersion);
83 assertEquals("Expected the cloud region to be created", 204, response.getStatus());
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");
90 response = httpTestUtil.doDelete(cloudRegionUri, resourceVersion);
91 assertEquals("Expected the cloud region to be created", 204, response.getStatus());