2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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=========================================================
21 package org.openecomp.sdc.ci.tests.execute.category;
23 import org.json.simple.JSONArray;
24 import org.json.simple.JSONObject;
25 import org.json.simple.JSONValue;
26 import org.junit.Rule;
27 import org.junit.rules.TestName;
28 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
29 import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
30 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
31 import org.openecomp.sdc.ci.tests.utils.rest.CatalogRestUtils;
32 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
33 import org.testng.annotations.Test;
35 import java.util.HashMap;
38 import static org.testng.AssertJUnit.assertEquals;
39 import static org.testng.AssertJUnit.assertNotNull;
41 public class ElementsApiTest extends ComponentBaseTest {
44 public static TestName name = new TestName();
46 public ElementsApiTest() {
47 super(name, ElementsApiTest.class.getName());
52 public void getAllPropertyScopesSuccess() throws Exception {
53 RestResponse response = ResourceRestUtils.getAllPropertyScopesTowardsCatalogBe();
54 String action = "Get All Property Scopes";
55 int expectedCode = 200;
56 verifyErrorCode(response, action, expectedCode);
61 public void getAllArtifactTypes() throws Exception {
62 RestResponse response = ResourceRestUtils.getAllArtifactTypesTowardsCatalogBe();
63 String action = "Get All Artifact Types";
64 int expectedCode = 200;
65 verifyErrorCode(response, action, expectedCode);
70 public void getConfiguration() throws Exception {
71 RestResponse response = ResourceRestUtils.getConfigurationTowardsCatalogBe();
72 String action = "Get All Artifact Types";
73 int expectedCode = 200;
75 String json = response.getResponse();
76 JSONObject jsonResp = (JSONObject) JSONValue.parse(json);
78 HashMap<String, Object> artifacts = (HashMap<String, Object>) jsonResp.get("artifacts");
79 Long defaultHeatTimeout = (Long) jsonResp.get("defaultHeatTimeout");
81 if (defaultHeatTimeout == null) {
82 response.setErrorCode(500);
83 verifyErrorCode(response, action, expectedCode);
87 if (artifacts == null) {
88 response.setErrorCode(500);
89 verifyErrorCode(response, action, expectedCode);
93 JSONObject deploymentResources = (JSONObject) artifacts.get("deployment");
94 JSONArray otherResources = (JSONArray) artifacts.get("other");
95 if (deploymentResources == null || otherResources == null) {
96 response.setErrorCode(500);
97 verifyErrorCode(response, action, expectedCode);
101 JSONArray roles = (JSONArray) jsonResp.get("roles");
103 response.setErrorCode(500);
104 verifyErrorCode(response, action, expectedCode);
110 public void verifyErrorCode(RestResponse response, String action, int expectedCode) {
111 assertNotNull("check response object is not null after " + action, response);
112 assertNotNull("check error code exists in response after " + action, response.getErrorCode());
113 assertEquals("Check response code after + action" + action, expectedCode, response.getErrorCode().intValue());
116 @Test(enabled = false)
117 public void getAllCategoriesSuccess() throws Exception {
118 Map<String, String> headersMap = new HashMap<String, String>();
119 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "application/json");
120 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), "application/json");
121 RestResponse response = CatalogRestUtils.getAllCategoriesTowardsCatalogBe();
122 String action = "Get All Categories";
123 int expectedCode = 200;
124 verifyErrorCode(response, action, expectedCode);
127 @Test(enabled = false)
128 public void getAllTagSuccess() throws Exception {
129 Map<String, String> headersMap = new HashMap<String, String>();
130 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "application/json");
131 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), "application/json");
132 RestResponse response = ResourceRestUtils.getAllTagsTowardsCatalogBe();
133 String action = "Get All Categories";
134 int expectedCode = 200;
135 verifyErrorCode(response, action, expectedCode);