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=========================================================
21 package org.onap.aai.rest;
23 import static org.junit.Assert.assertEquals;
25 import com.jayway.jsonpath.JsonPath;
29 import javax.ws.rs.core.Response;
31 import org.junit.Before;
32 import org.junit.ClassRule;
33 import org.junit.Ignore;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.junit.runners.Parameterized;
38 import org.onap.aai.AAISetup;
39 import org.onap.aai.HttpTestUtil;
40 import org.onap.aai.PayloadUtil;
41 import org.onap.aai.serialization.engines.QueryStyle;
42 import org.skyscreamer.jsonassert.JSONAssert;
43 import org.springframework.test.context.junit4.rules.SpringClassRule;
44 import org.springframework.test.context.junit4.rules.SpringMethodRule;
46 @RunWith(value = Parameterized.class)
47 public class TenantTest extends AAISetup {
49 private HttpTestUtil httpTestUtil;
50 private Map<String, String> templateValuesMap;
52 public static final SpringClassRule SPRING_CLASS_RULE = new SpringClassRule();
55 public final SpringMethodRule springMethodRule = new SpringMethodRule();
57 @Parameterized.Parameter(value = 0)
58 public QueryStyle queryStyle;
60 @Parameterized.Parameters(name = "QueryStyle.{0}")
61 public static Collection<Object[]> data() {
62 return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
67 httpTestUtil = new HttpTestUtil(queryStyle);
68 templateValuesMap = new HashMap<>();
71 @Ignore("Test is failing due to the deletion of node with children not correct will be fixed soon")
73 public void testCloudRegionTenantDeleteSuccessWithoutDeletingVserver() throws Exception {
75 templateValuesMap.put("cloud-region-id", UUID.randomUUID().toString());
76 templateValuesMap.put("cloud-owner", UUID.randomUUID().toString());
77 templateValuesMap.put("tenant-id", UUID.randomUUID().toString());
78 templateValuesMap.put("vserver-id", UUID.randomUUID().toString());
80 String cloudRegionPayload = PayloadUtil.getTemplatePayload("cloud-region.json", templateValuesMap);
81 String cloudRegionUri = String.format("/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/%s/%s",
82 templateValuesMap.get("cloud-owner"), templateValuesMap.get("cloud-region-id"));
84 String tenantUri = cloudRegionUri + "/tenants/tenant/" + templateValuesMap.get("tenant-id");
85 String tenantPayload = PayloadUtil.getTemplatePayload("tenant.json", templateValuesMap);
87 Response response = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
88 assertEquals("Expected the cloud region to be created", 201, response.getStatus());
90 response = httpTestUtil.doGet(tenantUri);
91 assertEquals("Expected the cloud region to be created", 200, response.getStatus());
92 String responseStr = response.getEntity().toString();
94 JSONAssert.assertEquals(tenantPayload, responseStr, false);
95 String resourceVersion = JsonPath.read(responseStr, "$.resource-version");
97 response = httpTestUtil.doDelete(tenantUri, resourceVersion);
98 assertEquals("Expected the cloud region to be created", 204, response.getStatus());
100 response = httpTestUtil.doGet(cloudRegionUri);
101 assertEquals("Expected the cloud region to be created", 200, response.getStatus());
102 responseStr = response.getEntity().toString();
103 resourceVersion = JsonPath.read(responseStr, "$.resource-version");
105 response = httpTestUtil.doDelete(cloudRegionUri, resourceVersion);
106 assertEquals("Expected the cloud region to be created", 204, response.getStatus());