summaryrefslogtreecommitdiffstats
path: root/aai-core/src/test/java
diff options
context:
space:
mode:
authorDileep Ranganathan <dileep.ranganathan@intel.com>2018-03-08 10:38:25 -0800
committerDileep Ranganathan <dileep.ranganathan@intel.com>2018-03-13 05:25:28 -0700
commitd7df2dca953d55fbd808b49bff3278495a85c705 (patch)
tree66c8eca1d5c8d97cdbafff1ff04ea8be6bef24e1 /aai-core/src/test/java
parent9bfec028ce6f4b0e7e7d59f29bf970d9d8a8024b (diff)
Testing for HpaCapabilities object
Fixed Schema - mismatch in the java attributes and xml attributes Added dependentOn for HpaFeatureAtrributes Added unit test for HPASchema Added sample payload for HPACapabilities inside flavor Issue-ID: AAI-742 Change-Id: I3525376886f10bee99aa0ce3f0a6b2a5efbaa9b1 Signed-off-by: Dileep Ranganathan <dileep.ranganathan@intel.com>
Diffstat (limited to 'aai-core/src/test/java')
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/HPACapabilityTest.java162
1 files changed, 162 insertions, 0 deletions
diff --git a/aai-core/src/test/java/org/onap/aai/rest/HPACapabilityTest.java b/aai-core/src/test/java/org/onap/aai/rest/HPACapabilityTest.java
new file mode 100644
index 00000000..2a9b5106
--- /dev/null
+++ b/aai-core/src/test/java/org/onap/aai/rest/HPACapabilityTest.java
@@ -0,0 +1,162 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2018 Intel Corporation Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.rest;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.jayway.jsonpath.JsonPath;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.aai.AAIJunitRunner;
+import org.onap.aai.HttpTestUtil;
+import org.onap.aai.PayloadUtil;
+import org.onap.aai.introspection.*;
+import org.skyscreamer.jsonassert.JSONAssert;
+
+import javax.ws.rs.core.Response;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(AAIJunitRunner.class)
+public class HPACapabilityTest {
+
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(HPACapabilityTest.class);
+ private HttpTestUtil httpTestUtil;
+ private Map<String, String> templateValuesMap;
+
+ @Before
+ public void setup() {
+ httpTestUtil = new HttpTestUtil();
+ templateValuesMap = new HashMap<>();
+ }
+
+ @Test
+ public void testPutHPACapabilitiesInFlavorAndCheckIfDeleteIsSuccessful() throws Exception {
+
+ templateValuesMap.put("cloud-region-id", UUID.randomUUID().toString());
+ templateValuesMap.put("cloud-owner", UUID.randomUUID().toString());
+ templateValuesMap.put("tenant-id", UUID.randomUUID().toString());
+ templateValuesMap.put("vserver-id", UUID.randomUUID().toString());
+ templateValuesMap.put("flavor-id1", UUID.randomUUID().toString());
+ templateValuesMap.put("flavor-id2", UUID.randomUUID().toString());
+ templateValuesMap.put("hpa-capability-id1", UUID.randomUUID().toString());
+ templateValuesMap.put("hpa-capability-id2", UUID.randomUUID().toString());
+ templateValuesMap.put("hpa-capability-id3", UUID.randomUUID().toString());
+ templateValuesMap.put("hpa-capability-id4", UUID.randomUUID().toString());
+ templateValuesMap.put("hpa-capability-id5", UUID.randomUUID().toString());
+ templateValuesMap.put("hpa-capability-id6", UUID.randomUUID().toString());
+ templateValuesMap.put("hpa-capability-id7", UUID.randomUUID().toString());
+ templateValuesMap.put("hpa-capability-id8", UUID.randomUUID().toString());
+
+ String cloudRegionPayload = PayloadUtil.getTemplatePayload("hpa.json", templateValuesMap);
+ String cloudRegionUri = String.format("/aai/v13/cloud-infrastructure/cloud-regions/cloud-region/%s/%s",
+ templateValuesMap.get("cloud-owner"),
+ templateValuesMap.get("cloud-region-id")
+ );
+
+ Response response = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
+ assertEquals("Expected the cloud region to be created", 201, response.getStatus());
+
+ response = httpTestUtil.doGet(cloudRegionUri);
+ assertEquals("Expected the cloud region to be found", 200, response.getStatus());
+ String jsonResponse = response.getEntity().toString();
+ System.out.println("#########################jsonResponse#########################");
+ System.out.println(jsonResponse);
+ System.out.println("#########################jsonResponse#########################");
+
+ JSONAssert.assertEquals(cloudRegionPayload, jsonResponse, false);
+
+ deleteFlavor(cloudRegionUri, templateValuesMap.get("flavor-id1"));
+ deleteFlavor(cloudRegionUri, templateValuesMap.get("flavor-id2"));
+ deleteTenant(cloudRegionUri);
+ }
+
+ private void deleteTenant(String cloudRegionUri) throws Exception {
+ String tenantUri = cloudRegionUri + "/tenants/tenant/" + templateValuesMap.get("tenant-id");
+ deleteVserver(tenantUri);
+
+ Response tntResponse = httpTestUtil.doGet(tenantUri);
+ assertEquals("Expected to GET Tenant info from cloud-region", 200, tntResponse.getStatus());
+ String responseStr = tntResponse.getEntity().toString();
+
+ String resourceVersion = JsonPath.read(responseStr, "$.resource-version");
+
+ tntResponse = httpTestUtil.doDelete(tenantUri, resourceVersion);
+ assertEquals("Expected to DELETE Tenant info from cloud-region", 204, tntResponse.getStatus());
+ }
+
+ private void deleteVserver(String tenantUri) throws Exception {
+ String uri = tenantUri + "/vservers/vserver/" + templateValuesMap.get("vserver-id");
+
+ Response tntResponse = httpTestUtil.doGet(uri);
+ assertEquals("Expected to GET Vserver", 200, tntResponse.getStatus());
+ String responseStr = tntResponse.getEntity().toString();
+
+ String resourceVersion = JsonPath.read(responseStr, "$.resource-version");
+
+ tntResponse = httpTestUtil.doDelete(uri, resourceVersion);
+ assertEquals("Expected to DELETE Vserver", 204, tntResponse.getStatus());
+ }
+
+ private void deleteFlavor(String cloudRegionUri, String flavorId) throws Exception {
+ String flavorUri = cloudRegionUri + "/flavors/flavor/" + flavorId;
+
+ Response response = httpTestUtil.doGet(flavorUri);
+ assertEquals("Expected to GET Flavors info from cloud-region", 200, response.getStatus());
+ String jsonResponse = response.getEntity().toString();
+ System.out.println("#########################Flavor Response#########################");
+ System.out.println(jsonResponse);
+ System.out.println("#########################Flavor Response#########################");
+ String responseStr = response.getEntity().toString();
+
+ List<String> capabilityIds = JsonPath.read(responseStr,
+ "$.hpa-capabilities.hpa-capability[*].hpa-capability-id");
+ for(String capabilityId : capabilityIds) {
+ deleteHPACapability(flavorUri, capabilityId);
+ }
+
+ String resourceVersion = JsonPath.read(responseStr, "$.resource-version");
+ response = httpTestUtil.doDelete(flavorUri, resourceVersion);
+ assertEquals("Expected to DELETE Flavor info from cloud-region", 204, response.getStatus());
+ }
+
+ private void deleteHPACapability(String flavorUri, String capabilityId) throws Exception {
+ String uri = flavorUri + "/hpa-capabilities/hpa-capability/" + capabilityId;
+
+ Response response = httpTestUtil.doGet(uri);
+ assertEquals("Expected to GET HPA info from flavors", 200, response.getStatus());
+ String jsonResponse = response.getEntity().toString();
+ System.out.println("#########################HPA Response#########################");
+ System.out.println(jsonResponse);
+ System.out.println("#########################HPA Response#########################");
+ String responseStr = response.getEntity().toString();
+
+ String resourceVersion = JsonPath.read(responseStr, "$.resource-version");
+
+ response = httpTestUtil.doDelete(uri, resourceVersion);
+ assertEquals("Expected to DELETE HPA info from flavors", 204, response.getStatus());
+ }
+}