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.ClassRule;
25 import org.junit.Ignore;
26 import org.junit.Rule;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.junit.runners.Parameterized;
30 import org.onap.aai.AAISetup;
31 import org.onap.aai.HttpTestUtil;
32 import org.onap.aai.PayloadUtil;
33 import org.onap.aai.serialization.engines.QueryStyle;
34 import org.skyscreamer.jsonassert.JSONAssert;
35 import org.springframework.test.context.junit4.rules.SpringClassRule;
36 import org.springframework.test.context.junit4.rules.SpringMethodRule;
38 import javax.ws.rs.core.Response;
41 import static org.junit.Assert.assertEquals;
43 @RunWith(value = Parameterized.class)
44 public class TenantTest extends AAISetup {
46 private HttpTestUtil httpTestUtil;
47 private Map<String, String> templateValuesMap;
49 public static final SpringClassRule SPRING_CLASS_RULE = new SpringClassRule();
52 public final SpringMethodRule springMethodRule = new SpringMethodRule();
54 @Parameterized.Parameter(value = 0)
55 public QueryStyle queryStyle;
57 @Parameterized.Parameters(name = "QueryStyle.{0}")
58 public static Collection<Object[]> data() {
59 return Arrays.asList(new Object[][]{
60 {QueryStyle.TRAVERSAL},
61 {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"),
83 templateValuesMap.get("cloud-region-id")
86 String tenantUri = cloudRegionUri + "/tenants/tenant/" + templateValuesMap.get("tenant-id");
87 String tenantPayload = PayloadUtil.getTemplatePayload("tenant.json", templateValuesMap);
89 Response response = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
90 assertEquals("Expected the cloud region to be created", 201, response.getStatus());
92 response = httpTestUtil.doGet(tenantUri);
93 assertEquals("Expected the cloud region to be created", 200, response.getStatus());
94 String responseStr = response.getEntity().toString();
96 JSONAssert.assertEquals(tenantPayload, responseStr, false);
97 String resourceVersion = JsonPath.read(responseStr, "$.resource-version");
99 response = httpTestUtil.doDelete(tenantUri, resourceVersion);
100 assertEquals("Expected the cloud region to be created", 204, response.getStatus());
102 response = httpTestUtil.doGet(cloudRegionUri);
103 assertEquals("Expected the cloud region to be created", 200, response.getStatus());
104 responseStr = response.getEntity().toString();
105 resourceVersion = JsonPath.read(responseStr, "$.resource-version");
107 response = httpTestUtil.doDelete(cloudRegionUri, resourceVersion);
108 assertEquals("Expected the cloud region to be created", 204, response.getStatus());