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