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.lifecycle;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertNotNull;
25 import static org.testng.AssertJUnit.assertTrue;
27 import java.io.IOException;
29 import org.apache.log4j.lf5.util.ResourceUtils;
30 import org.junit.rules.TestName;
31 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
32 import org.openecomp.sdc.be.model.LifecycleStateEnum;
33 import org.openecomp.sdc.be.model.Resource;
34 import org.openecomp.sdc.be.model.User;
35 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
36 import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails;
37 import org.openecomp.sdc.ci.tests.datatypes.ComponentInstanceReqDetails;
38 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
39 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
40 import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
41 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
42 import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum;
43 import org.openecomp.sdc.ci.tests.datatypes.enums.ServiceCategoriesEnum;
44 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
45 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
46 import org.openecomp.sdc.ci.tests.utils.ArtifactUtils;
47 import org.openecomp.sdc.ci.tests.utils.DbUtils;
48 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
49 import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
50 import org.openecomp.sdc.ci.tests.utils.rest.ComponentInstanceRestUtils;
51 import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils;
52 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
53 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
54 import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
55 import org.testng.annotations.BeforeMethod;
61 * resourceDetails - create, Add Heat, certify resourceDetails1 - create
62 * resource, LCS - CheckOut serviceDetails - create, add RI from
63 * resourceDetails serviceDetails2 - create, add RI from resourceDetails
64 * serviceDetailsEmpty - create, LCS - CheckOut serviceDetailsEmpty2 -
65 * create, LCS - CheckOut
68 public abstract class LCSbaseTest extends ComponentBaseTest {
70 protected ResourceReqDetails resourceDetails;
71 protected ResourceReqDetails resourceDetails1;
72 protected ServiceReqDetails serviceDetails;
73 protected ServiceReqDetails serviceDetails2;
74 protected ServiceReqDetails serviceDetailsEmpty;
75 protected ServiceReqDetails serviceDetailsEmpty2;
76 protected ComponentInstanceReqDetails componentInstanceReqDetails;
77 protected ComponentInstanceReqDetails resourceInstanceReqDetails2;
78 protected User sdncDesignerDetails1;
79 protected User sdncDesignerDetails2;
80 protected static User sdncTesterDeatails1;
81 protected User sdncAdminDetails1;
82 protected ArtifactReqDetails heatArtifactDetails;
83 protected ArtifactReqDetails heatVolArtifactDetails;
84 protected ArtifactReqDetails heatNetArtifactDetails;
86 protected ArtifactReqDetails defaultArtifactDetails;
87 protected ResourceUtils resourceUtils;
88 protected ArtifactUtils artifactUtils;
90 // protected static ServiceUtils serviceUtils = new ServiceUtils();
91 public LCSbaseTest(TestName testName, String className) {
92 super(testName, className);
96 public void before() throws Exception {
104 public void initializeMembers() throws IOException, Exception {
105 resourceDetails = ElementFactory.getDefaultResource();
107 // ElementFactory.getDefaultResource("myNewResource1234567890",
108 // NormativeTypesEnum.ROOT, ResourceServiceCategoriesEnum.ROUTERS,
109 // UserRoleEnum.DESIGNER.getUserId());
110 resourceDetails1 = ElementFactory.getDefaultResource("secondResource", NormativeTypesEnum.ROOT);
111 serviceDetails = ElementFactory.getDefaultService();
112 serviceDetails2 = ElementFactory.getDefaultService("newTestService2", ServiceCategoriesEnum.MOBILITY, "al1976");
113 serviceDetailsEmpty = ElementFactory.getDefaultService("newEmptyService", ServiceCategoriesEnum.MOBILITY,
115 serviceDetailsEmpty2 = ElementFactory.getDefaultService("newEmptyService2", ServiceCategoriesEnum.MOBILITY,
117 sdncDesignerDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
118 sdncDesignerDetails2 = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER2);
119 sdncTesterDeatails1 = ElementFactory.getDefaultUser(UserRoleEnum.TESTER);
120 sdncAdminDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
121 heatArtifactDetails = ElementFactory.getDefaultDeploymentArtifactForType(ArtifactTypeEnum.HEAT.getType());
122 heatNetArtifactDetails = ElementFactory
123 .getDefaultDeploymentArtifactForType(ArtifactTypeEnum.HEAT_NET.getType());
124 heatVolArtifactDetails = ElementFactory
125 .getDefaultDeploymentArtifactForType(ArtifactTypeEnum.HEAT_VOL.getType());
126 componentInstanceReqDetails = ElementFactory.getDefaultComponentInstance();
127 resourceInstanceReqDetails2 = ElementFactory.getDefaultComponentInstance();
131 protected void createComponents() throws Exception {
133 RestResponse response = ResourceRestUtils.createResource(resourceDetails1, sdncDesignerDetails1);
134 assertTrue("create request returned status:" + response.getErrorCode(), response.getErrorCode() == 201);
135 assertNotNull("resource uniqueId is null:", resourceDetails1.getUniqueId());
137 response = ResourceRestUtils.createResource(resourceDetails, sdncDesignerDetails1);
138 assertTrue("create request returned status:" + response.getErrorCode(), response.getErrorCode() == 201);
139 assertNotNull("resource uniqueId is null:", resourceDetails.getUniqueId());
141 response = ServiceRestUtils.createService(serviceDetails, sdncDesignerDetails1);
142 assertTrue("create request returned status:" + response.getErrorCode(), response.getErrorCode() == 201);
143 assertNotNull("service uniqueId is null:", serviceDetails.getUniqueId());
145 ArtifactReqDetails heatArtifactDetails = ElementFactory
146 .getDefaultDeploymentArtifactForType(ArtifactTypeEnum.HEAT.getType());
147 response = ArtifactRestUtils.addInformationalArtifactToResource(heatArtifactDetails, sdncDesignerDetails1,
148 resourceDetails.getUniqueId());
149 assertTrue("add HEAT artifact to resource request returned status:" + response.getErrorCode(),
150 response.getErrorCode() == 200);
152 // certified resource
153 response = LCSbaseTest.certifyResource(resourceDetails, sdncDesignerDetails1);
154 assertTrue("certify resource request returned status:" + response.getErrorCode(),
155 response.getErrorCode() == 200);
157 // add resource instance with HEAT deployment artifact to the service
158 componentInstanceReqDetails.setComponentUid(resourceDetails.getUniqueId());
159 response = ComponentInstanceRestUtils.createComponentInstance(componentInstanceReqDetails, sdncDesignerDetails1,
160 serviceDetails.getUniqueId(), ComponentTypeEnum.SERVICE);
161 assertTrue("response code is not 201, returned: " + response.getErrorCode(), response.getErrorCode() == 201);
163 response = ServiceRestUtils.createService(serviceDetails2, sdncDesignerDetails1);
164 assertTrue("create request returned status:" + response.getErrorCode(), response.getErrorCode() == 201);
165 assertNotNull("service uniqueId is null:", serviceDetails2.getUniqueId());
167 componentInstanceReqDetails.setComponentUid(resourceDetails.getUniqueId());
168 response = ComponentInstanceRestUtils.createComponentInstance(componentInstanceReqDetails, sdncDesignerDetails1,
169 serviceDetails2.getUniqueId(), ComponentTypeEnum.SERVICE);
170 assertTrue("response code is not 201, returned: " + response.getErrorCode(), response.getErrorCode() == 201);
172 response = ServiceRestUtils.createService(serviceDetailsEmpty, sdncDesignerDetails1);
173 assertTrue("create request returned status:" + response.getErrorCode(), response.getErrorCode() == 201);
174 assertNotNull("service uniqueId is null:", serviceDetailsEmpty.getUniqueId());
176 response = ServiceRestUtils.createService(serviceDetailsEmpty2, sdncDesignerDetails1);
177 assertTrue("create request returned status:" + response.getErrorCode(), response.getErrorCode() == 201);
178 assertNotNull("service uniqueId is null:", serviceDetailsEmpty2.getUniqueId());
180 DbUtils.cleanAllAudits();
184 public static RestResponse certifyResource(ResourceReqDetails resourceDetails, User user) throws Exception {
185 RestResponse restResponseResource = LifecycleRestUtils.changeResourceState(resourceDetails, user.getUserId(),
186 LifeCycleStatesEnum.CHECKIN);
187 // if (restResponseResource.getErrorCode() == 200){
188 restResponseResource = LifecycleRestUtils.changeResourceState(resourceDetails, user.getUserId(),
189 LifeCycleStatesEnum.CERTIFICATIONREQUEST);
191 // return restResponseResource;
192 sdncTesterDeatails1 = ElementFactory.getDefaultUser(UserRoleEnum.TESTER);
193 if (restResponseResource.getErrorCode() == 200) {
194 restResponseResource = LifecycleRestUtils.changeResourceState(resourceDetails,
195 sdncTesterDeatails1.getUserId(), LifeCycleStatesEnum.STARTCERTIFICATION);
197 return restResponseResource;
198 if (restResponseResource.getErrorCode() == 200) {
199 restResponseResource = LifecycleRestUtils.changeResourceState(resourceDetails,
200 sdncTesterDeatails1.getUserId(), LifeCycleStatesEnum.CERTIFY);
202 return restResponseResource;
205 public static RestResponse certifyService(ServiceReqDetails serviceDetails, User user) throws Exception {
206 RestResponse restResponseService = LifecycleRestUtils.changeServiceState(serviceDetails, user,
207 LifeCycleStatesEnum.CHECKIN);
208 // if (restResponseService.getErrorCode() == 200){
209 restResponseService = LifecycleRestUtils.changeServiceState(serviceDetails, user,
210 LifeCycleStatesEnum.CERTIFICATIONREQUEST);
212 // return restResponseService;
214 sdncTesterDeatails1 = ElementFactory.getDefaultUser(UserRoleEnum.TESTER);
215 if (restResponseService.getErrorCode() == 200) {
216 restResponseService = LifecycleRestUtils.changeServiceState(serviceDetails, sdncTesterDeatails1,
217 LifeCycleStatesEnum.STARTCERTIFICATION);
219 return restResponseService;
220 if (restResponseService.getErrorCode() == 200) {
221 restResponseService = LifecycleRestUtils.changeServiceState(serviceDetails, sdncTesterDeatails1,
222 LifeCycleStatesEnum.CERTIFY);
224 return restResponseService;
227 protected static RestResponse raiseResourceToTargetVersion(ResourceReqDetails resourceDetails, String targetVersion,
228 User user) throws Exception {
229 return raiseResourceToTargetVersion(resourceDetails, targetVersion, null, user);
232 protected static RestResponse raiseResourceToTargetVersion(ResourceReqDetails resourceDetails, String targetVersion,
233 RestResponse prevResponse, User user) throws Exception {
235 String[] splitParts = targetVersion.split("\\.");
237 int version = Integer.parseInt(splitParts[1]);
238 String checkinComment = "good checkin";
239 String checkinComentJson = "{\"userRemarks\": \"" + checkinComment + "\"}";
241 if (prevResponse != null) {
242 Resource resourceRespJavaObject = ResponseParser
243 .convertResourceResponseToJavaObject(prevResponse.getResponse());
244 if (resourceRespJavaObject.getLifecycleState().equals(LifecycleStateEnum.CERTIFIED)) {
245 RestResponse restResponseResource = LifecycleRestUtils.changeResourceState(resourceDetails,
246 user.getUserId(), LifeCycleStatesEnum.CHECKOUT);
250 RestResponse restResponseResource = null;
251 for (int i = 0; i < (version - 1); i++) {
253 restResponseResource = LifecycleRestUtils.changeResourceState(resourceDetails, user, null,
254 LifeCycleStatesEnum.CHECKIN, checkinComentJson);
255 if (restResponseResource.getErrorCode() == 200) {
256 restResponseResource = LifecycleRestUtils.changeResourceState(resourceDetails, user.getUserId(),
257 LifeCycleStatesEnum.CHECKOUT);
258 if (restResponseResource.getErrorCode() == 200) {
268 restResponseResource = LifecycleRestUtils.changeResourceState(resourceDetails, user, null,
269 LifeCycleStatesEnum.CHECKIN, checkinComentJson);
270 assertEquals("Check response code ", 200, restResponseResource.getErrorCode().intValue());
271 return restResponseResource;