Fix for radio buttons
[sdc.git] / asdc-tests / src / main / java / org / openecomp / sdc / ci / tests / execute / category / ElementsApiTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.ci.tests.execute.category;
22
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertNotNull;
25
26 import java.util.HashMap;
27 import java.util.Map;
28
29 import org.json.simple.JSONArray;
30 import org.json.simple.JSONObject;
31 import org.json.simple.JSONValue;
32 import org.junit.Rule;
33 import org.junit.rules.TestName;
34 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
35 import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
36 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
37 import org.openecomp.sdc.ci.tests.utils.rest.CatalogRestUtils;
38 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
39 import org.testng.annotations.Test;
40
41 public class ElementsApiTest extends ComponentBaseTest {
42
43         @Rule
44         public static TestName name = new TestName();
45
46         public ElementsApiTest() {
47                 super(name, ElementsApiTest.class.getName());
48         }
49
50         // public LCSbaseTest(TestName testName, String className) {
51         // super(testName, className);
52         // }
53
54         // public ElementsApiTest(TestName name, String name2) {
55         //// super(name, name2);
56         // // TODO Auto-generated constructor stub
57         // }
58
59         // Expected 200 Keep
60         @Test
61         public void getAllPropertyScopesSuccess() throws Exception {
62                 RestResponse response = ResourceRestUtils.getAllPropertyScopesTowardsCatalogBe();
63                 String action = "Get All Property Scopes";
64                 int expectedCode = 200;
65                 verifyErrorCode(response, action, expectedCode);
66         }
67
68         // Expected 200 Keep
69         @Test
70         public void getAllArtifactTypes() throws Exception {
71                 RestResponse response = ResourceRestUtils.getAllArtifactTypesTowardsCatalogBe();
72                 String action = "Get All Artifact Types";
73                 int expectedCode = 200;
74                 verifyErrorCode(response, action, expectedCode);
75         }
76
77         // Expected 200 Keep
78         @Test
79         public void getConfiguration() throws Exception {
80                 RestResponse response = ResourceRestUtils.getConfigurationTowardsCatalogBe();
81                 String action = "Get All Artifact Types";
82                 int expectedCode = 200;
83
84                 String json = response.getResponse();
85                 JSONObject jsonResp = (JSONObject) JSONValue.parse(json);
86
87                 HashMap<String, Object> artifacts = (HashMap<String, Object>) jsonResp.get("artifacts");
88                 Long defaultHeatTimeout = (Long) jsonResp.get("defaultHeatTimeout");
89
90                 if (defaultHeatTimeout == null) {
91                         response.setErrorCode(500);
92                         verifyErrorCode(response, action, expectedCode);
93                         return;
94                 }
95
96                 if (artifacts == null) {
97                         response.setErrorCode(500);
98                         verifyErrorCode(response, action, expectedCode);
99                         return;
100                 }
101
102                 JSONObject deploymentResources = (JSONObject) artifacts.get("deployment");
103                 JSONArray otherResources = (JSONArray) artifacts.get("other");
104                 if (deploymentResources == null || otherResources == null) {
105                         response.setErrorCode(500);
106                         verifyErrorCode(response, action, expectedCode);
107                         return;
108                 }
109
110                 JSONArray roles = (JSONArray) jsonResp.get("roles");
111                 if (roles == null) {
112                         response.setErrorCode(500);
113                         verifyErrorCode(response, action, expectedCode);
114                         return;
115                 }
116
117         }
118
119         public void verifyErrorCode(RestResponse response, String action, int expectedCode) {
120                 assertNotNull("check response object is not null after " + action, response);
121                 assertNotNull("check error code exists in response after " + action, response.getErrorCode());
122                 assertEquals("Check response code after  + action" + action, expectedCode, response.getErrorCode().intValue());
123         }
124
125         @Test(enabled = false)
126         public void getAllCategoriesSuccess() throws Exception {
127                 Map<String, String> headersMap = new HashMap<String, String>();
128                 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "application/json");
129                 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), "application/json");
130                 RestResponse response = CatalogRestUtils.getAllCategoriesTowardsCatalogBe();
131                 String action = "Get All Categories";
132                 int expectedCode = 200;
133                 verifyErrorCode(response, action, expectedCode);
134         }
135
136         @Test(enabled = false)
137         public void getAllTagSuccess() throws Exception {
138                 Map<String, String> headersMap = new HashMap<String, String>();
139                 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "application/json");
140                 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), "application/json");
141                 RestResponse response = ResourceRestUtils.getAllTagsTowardsCatalogBe();
142                 String action = "Get All Categories";
143                 int expectedCode = 200;
144                 verifyErrorCode(response, action, expectedCode);
145         }
146
147 }