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.user;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertNotNull;
26 import static org.testng.AssertJUnit.assertTrue;
28 import java.io.IOException;
29 import java.util.List;
31 import org.json.simple.JSONArray;
32 import org.json.simple.JSONObject;
33 import org.junit.Rule;
34 import org.junit.rules.TestName;
35 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
36 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
37 import org.openecomp.sdc.be.model.DistributionStatusEnum;
38 import org.openecomp.sdc.be.model.Resource;
39 import org.openecomp.sdc.be.model.Service;
40 import org.openecomp.sdc.be.model.User;
41 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
42 import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails;
43 import org.openecomp.sdc.ci.tests.datatypes.ComponentInstanceReqDetails;
44 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
45 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
46 import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
47 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
48 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
49 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
50 import org.openecomp.sdc.ci.tests.execute.lifecycle.LCSbaseTest;
51 import org.openecomp.sdc.ci.tests.utils.DbUtils;
52 import org.openecomp.sdc.ci.tests.utils.Utils;
53 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
54 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
55 import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
56 import org.openecomp.sdc.ci.tests.utils.rest.ComponentInstanceRestUtils;
57 import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils;
58 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
59 import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
60 import org.openecomp.sdc.ci.tests.utils.validation.ServiceValidationUtils;
61 import org.slf4j.Logger;
62 import org.slf4j.LoggerFactory;
63 import org.testng.annotations.BeforeMethod;
64 import org.testng.annotations.Test;
66 public class GovernorWorkspaceApiTest extends ComponentBaseTest {
68 private static Logger logger = LoggerFactory.getLogger(GovernorWorkspaceApiTest.class.getName());
70 public static TestName name = new TestName();
72 public GovernorWorkspaceApiTest() {
73 super(name, GovernorWorkspaceApiTest.class.getName());
77 protected final User admin1 = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
78 protected final User governor = ElementFactory.getDefaultUser(UserRoleEnum.GOVERNOR);
79 protected final User sdncDesignerDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
80 protected ResourceReqDetails resourceDetails1;
81 protected ComponentInstanceReqDetails componentInstanceReqDetails;
82 protected ArtifactReqDetails heatArtifactDetails;
84 protected final String serviceVersion = "0.1";
85 protected final String servicesString = "services";
86 protected final String userRemarks = "commentTest";
88 protected ServiceReqDetails serviceDetails11 = null;
89 protected ServiceReqDetails serviceDetails22 = null;
90 protected ServiceReqDetails serviceDetails33 = null;
93 public void initBeforeTest() throws Exception {
94 DbUtils.deleteFromEsDbByPattern("_all");
95 Resource resourceObj = AtomicOperationUtils
96 .createResourceByType(ResourceTypeEnum.VFC, UserRoleEnum.DESIGNER, true).left().value();
97 resourceDetails1 = new ResourceReqDetails(resourceObj);
98 heatArtifactDetails = ElementFactory.getDefaultDeploymentArtifactForType(ArtifactTypeEnum.HEAT.getType());
99 createThreeServices(sdncDesignerDetails1);
102 protected void createThreeServices(User user) throws Exception {
104 String checkinComment = "good checkin";
105 String checkinComentJson = "{\"userRemarks\": \"" + checkinComment + "\"}";
107 RestResponse addInformationalArtifactToResource = ArtifactRestUtils.addInformationalArtifactToResource(
108 heatArtifactDetails, sdncDesignerDetails1, resourceDetails1.getUniqueId());
109 RestResponse certifyResource = LifecycleRestUtils.certifyResource(resourceDetails1);
110 componentInstanceReqDetails = ElementFactory.getDefaultComponentInstance("defaultInstance", resourceDetails1);
112 serviceDetails11 = ElementFactory.getDefaultService();
113 serviceDetails22 = ElementFactory.getDefaultService();
114 serviceDetails33 = ElementFactory.getDefaultService();
116 serviceDetails11.setName(serviceDetails11.getName() + "1");
117 List<String> tags = serviceDetails11.getTags();
118 tags.add(serviceDetails11.getName());
119 serviceDetails11.setTags(tags);
121 serviceDetails22.setName(serviceDetails11.getName() + "2");
122 tags = serviceDetails22.getTags();
123 tags.add(serviceDetails22.getName());
124 serviceDetails22.setTags(tags);
126 serviceDetails33.setName(serviceDetails11.getName() + "3");
127 tags = serviceDetails33.getTags();
128 tags.add(serviceDetails33.getName());
129 serviceDetails33.setTags(tags);
131 RestResponse createServiceResponse1 = createService(user, serviceDetails11);
132 RestResponse createServiceResponse2 = createService(user, serviceDetails22);
133 RestResponse createServiceResponse3 = createService(user, serviceDetails33);
136 protected RestResponse createService(User user, ServiceReqDetails serviceDetails) throws Exception, IOException {
137 RestResponse createServiceResponse1 = ServiceRestUtils.createService(serviceDetails, user);
138 assertNotNull("check response object is not null after creating service", createServiceResponse1);
139 assertNotNull("check if error code exists in response after creating service",
140 createServiceResponse1.getErrorCode());
141 assertEquals("Check response code after creating service", 201,
142 createServiceResponse1.getErrorCode().intValue());
143 Service convertServiceResponseToJavaObject = ResponseParser
144 .convertServiceResponseToJavaObject(createServiceResponse1.getResponse());
145 serviceDetails.setUniqueId(convertServiceResponseToJavaObject.getUniqueId());
146 logger.debug("Created service1 ={}", serviceDetails);
147 addResourceWithHeatArt(serviceDetails);
148 return createServiceResponse1;
151 protected void addResourceWithHeatArt(ServiceReqDetails serviceDetails) throws Exception {
153 RestResponse createResourceInstance = ComponentInstanceRestUtils.createComponentInstance(
154 componentInstanceReqDetails, sdncDesignerDetails1, serviceDetails.getUniqueId(),
155 ComponentTypeEnum.SERVICE);
156 // System.out.println("serviceUID --->" + serviceDetails.getUniqueId());
157 assertEquals("Check response code ", 201, createResourceInstance.getErrorCode().intValue());
160 protected void certifyAllServices() throws Exception {
161 LifecycleRestUtils.certifyService(serviceDetails11);
162 LifecycleRestUtils.certifyService(serviceDetails22);
163 LifecycleRestUtils.certifyService(serviceDetails33);
166 protected boolean isElementInArray(String elementId, JSONArray jsonArray) throws Exception {
167 for (int i = 0; i < jsonArray.size(); i++) {
168 JSONObject jobject = (JSONObject) jsonArray.get(i);
170 if (jobject.get("uniqueId").toString().equals(elementId)) {
177 protected void approveDistributionStatusOfCertifiedService(ServiceReqDetails serviceDetails, User user)
179 approveDistributionStatusOfService(serviceDetails, user, "1.0");
182 protected void approveDistributionStatusOfService(ServiceReqDetails serviceDetails, User user, String version)
184 RestResponse res = LifecycleRestUtils.sendApproveDistribution(user, serviceDetails.getUniqueId(), userRemarks);
185 assertEquals(200, res.getErrorCode().intValue());
186 ServiceValidationUtils.validateDistrubtionStatusValue(res, DistributionStatusEnum.DISTRIBUTION_APPROVED);
189 protected void rejectDistributionStatusOfService(ServiceReqDetails serviceDetails, User user) throws Exception {
190 rejectDistributionStatusOfService(serviceDetails, user, "1.0");
193 protected void rejectDistributionStatusOfService(ServiceReqDetails serviceDetails, User user, String version)
195 RestResponse res = LifecycleRestUtils.rejectDistribution(serviceDetails, version, user, userRemarks);
196 assertEquals(200, res.getErrorCode().intValue());
197 ServiceValidationUtils.validateDistrubtionStatusValue(res, DistributionStatusEnum.DISTRIBUTION_REJECTED);
200 protected JSONArray getFollowedListAsJsonArray(User user) throws Exception {
201 RestResponse getGovernorFollowed = ServiceRestUtils.getFollowed(user);
202 assertNotNull(getGovernorFollowed);
203 assertNotNull(getGovernorFollowed.getErrorCode());
204 assertEquals(200, getGovernorFollowed.getErrorCode().intValue());
206 JSONArray listArrayFromRestResponse = ServiceRestUtils.getListArrayFromRestResponse(getGovernorFollowed);
208 return listArrayFromRestResponse;
211 protected void changeDistributionStatusOfAllService(boolean approved, User user) throws Exception {
213 approveDistributionStatusOfCertifiedService(serviceDetails11, user);
214 approveDistributionStatusOfCertifiedService(serviceDetails22, user);
215 approveDistributionStatusOfCertifiedService(serviceDetails33, user);
217 rejectDistributionStatusOfService(serviceDetails11, user);
218 rejectDistributionStatusOfService(serviceDetails22, user);
219 rejectDistributionStatusOfService(serviceDetails33, user);
224 protected JSONArray checkFollowed(User user) throws Exception {
225 JSONArray getFollowedList = getFollowedListAsJsonArray(user);
226 assertFalse(getFollowedList.isEmpty());
227 assertTrue(isElementInArray(serviceDetails11.getUniqueId(), getFollowedList));
228 assertTrue(isElementInArray(serviceDetails22.getUniqueId(), getFollowedList));
229 assertTrue(isElementInArray(serviceDetails33.getUniqueId(), getFollowedList));
231 return getFollowedList;
234 // -------------------------------------T E S T
235 // S------------------------------------------------------//
238 public void governorList_AllCertifiedVersionsOfService() throws Exception {
239 certifyAllServices();
240 String serviceUniqueIdCertified1 = serviceDetails11.getUniqueId();
241 RestResponse res = LifecycleRestUtils.changeServiceState(serviceDetails11, sdncDesignerDetails1, "1.0",
242 LifeCycleStatesEnum.CHECKOUT);
243 assertEquals(200, res.getErrorCode().intValue());
245 JSONArray getFollowedList = getFollowedListAsJsonArray(governor);
246 assertFalse(getFollowedList.isEmpty());
247 assertFalse(isElementInArray(serviceDetails11.getUniqueId(), getFollowedList));
248 assertTrue(isElementInArray(serviceDetails22.getUniqueId(), getFollowedList));
249 assertTrue(isElementInArray(serviceDetails33.getUniqueId(), getFollowedList));
250 assertTrue(isElementInArray(serviceUniqueIdCertified1, getFollowedList));
251 assertEquals(3, getFollowedList.size());
253 // certifyService(serviceDetails11, "1.1");
254 LifecycleRestUtils.certifyService(serviceDetails11);
256 JSONArray governorFollowedList2 = checkFollowed(governor);
257 assertEquals(4, governorFollowedList2.size());
258 assertTrue(isElementInArray(serviceDetails11.getUniqueId(), governorFollowedList2));
259 assertTrue(isElementInArray(serviceUniqueIdCertified1, governorFollowedList2));
263 // -------------------------------------T E S T
264 // S------------------------------------------------------//
267 public void governorList_distributionNotApproved() throws Exception {
268 certifyAllServices();
270 JSONArray checkFollowed = checkFollowed(governor);
271 assertEquals(3, checkFollowed.size());
275 public void governorGetEmptyListTest_notCertifiedServices() throws Exception {
276 JSONArray governorFollowedList = getFollowedListAsJsonArray(governor);
278 assertTrue(governorFollowedList.isEmpty());
282 public void governorList_distributionApproved() throws Exception {
283 certifyAllServices();
284 boolean approved = true;
285 changeDistributionStatusOfAllService(approved, governor);
287 JSONArray checkFollowed = checkFollowed(governor);
288 assertEquals(3, checkFollowed.size());
291 @Test(enabled = false)
292 public void governorList_distributed() throws Exception {
293 certifyAllServices();
295 LifecycleRestUtils.changeDistributionStatus(serviceDetails11, "1.0", governor, userRemarks,
296 DistributionStatusEnum.DISTRIBUTED);
297 LifecycleRestUtils.changeDistributionStatus(serviceDetails22, "1.0", governor, userRemarks,
298 DistributionStatusEnum.DISTRIBUTED);
299 LifecycleRestUtils.changeDistributionStatus(serviceDetails33, "1.0", governor, userRemarks,
300 DistributionStatusEnum.DISTRIBUTED);
302 JSONArray governorFollowedList = getFollowedListAsJsonArray(governor);
303 assertFalse(governorFollowedList.isEmpty());
304 assertTrue(isElementInArray(serviceDetails11.getUniqueId(), governorFollowedList));
305 assertTrue(isElementInArray(serviceDetails22.getUniqueId(), governorFollowedList));
306 assertTrue(isElementInArray(serviceDetails33.getUniqueId(), governorFollowedList));
310 public void governorList_distributionRejected() throws Exception {
311 certifyAllServices();
312 boolean distributionRejected = false;
313 changeDistributionStatusOfAllService(distributionRejected, governor);
315 JSONArray checkFollowed = checkFollowed(governor);
316 assertEquals(3, checkFollowed.size());