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.resource;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
28 import java.util.ArrayList;
29 import java.util.List;
32 import org.junit.Rule;
33 import org.junit.rules.TestName;
34 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
35 import org.openecomp.sdc.be.model.ArtifactDefinition;
36 import org.openecomp.sdc.be.model.CapabilityDefinition;
37 import org.openecomp.sdc.be.model.ComponentInstance;
38 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
39 import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
40 import org.openecomp.sdc.be.model.RequirementDefinition;
41 import org.openecomp.sdc.be.model.Resource;
42 import org.openecomp.sdc.be.model.Service;
43 import org.openecomp.sdc.be.model.User;
44 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
45 import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails;
46 import org.openecomp.sdc.ci.tests.datatypes.ComponentInstanceReqDetails;
47 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
48 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
49 import org.openecomp.sdc.ci.tests.datatypes.enums.ServiceCategoriesEnum;
50 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
51 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
52 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
53 import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
54 import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
55 import org.openecomp.sdc.ci.tests.utils.rest.ComponentInstanceRestUtils;
56 import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils;
57 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
58 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
59 import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
60 import org.testng.annotations.Test;
62 public class CustomizationUUIDTest extends ComponentBaseTest {
65 public static TestName name = new TestName();
67 public CustomizationUUIDTest() {
68 super(name, CustomizationUUIDTest.class.getName());
72 public void resourceCustomUUIDTestUpdateMeta() throws Exception {
73 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
75 // create resource in checkin status
76 Resource resource1 = createVfFromCSAR(sdncModifierDetails, "csar_1");
78 RestResponse checkinState = LifecycleRestUtils.changeComponentState(resource1, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
79 BaseRestUtils.checkSuccess(checkinState);
82 ServiceReqDetails serviceDetails = ElementFactory.getDefaultService("ciNewtestservice1", ServiceCategoriesEnum.MOBILITY, sdncModifierDetails.getUserId());
83 RestResponse createServiceResponse = ServiceRestUtils.createService(serviceDetails, sdncModifierDetails);
84 ResourceRestUtils.checkCreateResponse(createServiceResponse);
85 Service service = ResponseParser.parseToObjectUsingMapper(createServiceResponse.getResponse(), Service.class);
88 ComponentInstanceReqDetails componentInstanceDetails = ElementFactory.getComponentInstance(resource1);
89 RestResponse createComponentInstance = ComponentInstanceRestUtils.createComponentInstance(componentInstanceDetails, sdncModifierDetails, service);
90 ResourceRestUtils.checkCreateResponse(createComponentInstance);
92 ComponentInstance ci1 = ResponseParser.parseToObjectUsingMapper(createComponentInstance.getResponse(), ComponentInstance.class);
93 assertNotNull(ci1.getCustomizationUUID());
94 String ci1CustUUID = ci1.getCustomizationUUID();
96 // get service with 1 instance
97 RestResponse getService = ServiceRestUtils.getService(service.getUniqueId());
98 BaseRestUtils.checkSuccess(getService);
99 service = ResponseParser.parseToObjectUsingMapper(getService.getResponse(), Service.class);
100 List<ComponentInstance> componentInstances = service.getComponentInstances();
101 assertNotNull(componentInstances);
102 assertEquals(1, componentInstances.size());
104 // change name of instance 1 and check custom UUID
105 String newCi1Name = "newCi1Name";
106 ci1.setName(newCi1Name);
107 RestResponse updateComponentInstance = ComponentInstanceRestUtils.updateComponentInstance(ci1, sdncModifierDetails, service.getUniqueId(), ComponentTypeEnum.SERVICE);
108 ResourceRestUtils.checkSuccess(updateComponentInstance);
109 ComponentInstance ci1AfterChange = ResponseParser.parseToObjectUsingMapper(updateComponentInstance.getResponse(), ComponentInstance.class);
112 assertFalse(ci1.getCustomizationUUID().equals(ci1AfterChange.getCustomizationUUID()));
114 // change position of instance 1 and check UUID
117 updateComponentInstance = ComponentInstanceRestUtils.updateComponentInstance(ci1, sdncModifierDetails, service.getUniqueId(), ComponentTypeEnum.SERVICE);
118 ResourceRestUtils.checkSuccess(updateComponentInstance);
119 ci1AfterChange = ResponseParser.parseToObjectUsingMapper(updateComponentInstance.getResponse(), ComponentInstance.class);
121 assertTrue(ci1.getCustomizationUUID().equals(ci1AfterChange.getCustomizationUUID()));
124 @Test(enabled = true)
125 public void resourceCustomUUIDPropertyTest() throws Exception {
126 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
129 Resource resource1 = createVfFromCSAR(sdncModifierDetails, "csar_1");
131 RestResponse checkinState = LifecycleRestUtils.changeComponentState(resource1, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
132 BaseRestUtils.checkSuccess(checkinState);
135 ServiceReqDetails serviceDetails = ElementFactory.getDefaultService("ciNewtestservice1", ServiceCategoriesEnum.MOBILITY, sdncModifierDetails.getUserId());
136 RestResponse createServiceResponse = ServiceRestUtils.createService(serviceDetails, sdncModifierDetails);
137 ResourceRestUtils.checkCreateResponse(createServiceResponse);
138 Service service = ResponseParser.parseToObjectUsingMapper(createServiceResponse.getResponse(), Service.class);
141 ComponentInstanceReqDetails componentInstanceDetails = ElementFactory.getComponentInstance(resource1);
142 RestResponse createComponentInstance = ComponentInstanceRestUtils.createComponentInstance(componentInstanceDetails, sdncModifierDetails, service);
143 ResourceRestUtils.checkCreateResponse(createComponentInstance);
145 ComponentInstance ci1 = ResponseParser.parseToObjectUsingMapper(createComponentInstance.getResponse(), ComponentInstance.class);
146 assertNotNull(ci1.getCustomizationUUID());
147 String ci1CustUUID = ci1.getCustomizationUUID();
149 // get service with 1 instance
150 RestResponse getService = ServiceRestUtils.getService(service.getUniqueId());
151 BaseRestUtils.checkSuccess(getService);
152 service = ResponseParser.parseToObjectUsingMapper(getService.getResponse(), Service.class);
153 List<ComponentInstance> componentInstances = service.getComponentInstances();
154 assertNotNull(componentInstances);
155 assertEquals(1, componentInstances.size());
157 // instance property values
158 Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = service.getComponentInstancesProperties();
159 assertNotNull(componentInstancesProperties);
160 List<ComponentInstanceProperty> listProps = componentInstancesProperties.get(ci1.getUniqueId());
161 assertNotNull(listProps);
163 ComponentInstanceProperty updatedInstanceProperty = null;
164 for (ComponentInstanceProperty cip : listProps) {
165 if (cip.getType().equals("string")) {
166 updatedInstanceProperty = cip;
170 assertNotNull(updatedInstanceProperty);
171 updatedInstanceProperty.setValue("newValue");
173 RestResponse updatePropRes = ComponentInstanceRestUtils.updatePropertyValueOnResourceInstance(service, ci1, sdncModifierDetails, updatedInstanceProperty);
174 BaseRestUtils.checkSuccess(updatePropRes);
176 getService = ServiceRestUtils.getService(service.getUniqueId());
177 BaseRestUtils.checkSuccess(getService);
178 service = ResponseParser.parseToObjectUsingMapper(getService.getResponse(), Service.class);
179 componentInstances = service.getComponentInstances();
180 assertNotNull(componentInstances);
181 ComponentInstance ciAfterUpdateProp = componentInstances.get(0);
183 assertFalse(ci1.getCustomizationUUID().equals(ciAfterUpdateProp.getCustomizationUUID()));
186 @Test(enabled = true)
187 public void resourceCustomUUIDChangeVersionTest() throws Exception {
188 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
190 // create resource in checkin status
191 Resource resource1 = createVfFromCSAR(sdncModifierDetails, "csar_1");
193 RestResponse checkinState = LifecycleRestUtils.changeComponentState(resource1, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
194 BaseRestUtils.checkSuccess(checkinState);
197 ServiceReqDetails serviceDetails = ElementFactory.getDefaultService("ciNewtestservice1", ServiceCategoriesEnum.MOBILITY, sdncModifierDetails.getUserId());
198 RestResponse createServiceResponse = ServiceRestUtils.createService(serviceDetails, sdncModifierDetails);
199 ResourceRestUtils.checkCreateResponse(createServiceResponse);
200 Service service = ResponseParser.parseToObjectUsingMapper(createServiceResponse.getResponse(), Service.class);
203 ComponentInstanceReqDetails componentInstanceDetails = ElementFactory.getComponentInstance(resource1);
204 RestResponse createComponentInstance = ComponentInstanceRestUtils.createComponentInstance(componentInstanceDetails, sdncModifierDetails, service);
205 ResourceRestUtils.checkCreateResponse(createComponentInstance);
207 ComponentInstance ci1 = ResponseParser.parseToObjectUsingMapper(createComponentInstance.getResponse(), ComponentInstance.class);
208 assertNotNull(ci1.getCustomizationUUID());
209 String ci1CustUUID = ci1.getCustomizationUUID();
211 // create 0.2 version of resource( check out and check in)
212 RestResponse checkoutState = LifecycleRestUtils.changeComponentState(resource1, sdncModifierDetails, LifeCycleStatesEnum.CHECKOUT);
213 BaseRestUtils.checkSuccess(checkoutState);
214 resource1 = ResponseParser.parseToObjectUsingMapper(checkoutState.getResponse(), Resource.class);
215 assertNotNull(resource1);
217 checkinState = LifecycleRestUtils.changeComponentState(resource1, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
218 BaseRestUtils.checkSuccess(checkinState);
220 // change version of instance
221 RestResponse changeComponentInstanceVersion = ComponentInstanceRestUtils.changeComponentInstanceVersion(service, ci1, resource1, sdncModifierDetails);
222 BaseRestUtils.checkSuccess(changeComponentInstanceVersion);
223 RestResponse getService = ServiceRestUtils.getService(service.getUniqueId());
224 BaseRestUtils.checkSuccess(getService);
225 service = ResponseParser.parseToObjectUsingMapper(getService.getResponse(), Service.class);
226 List<ComponentInstance> componentInstances = service.getComponentInstances();
227 assertNotNull(componentInstances);
228 assertEquals(1, componentInstances.size());
229 assertFalse(ci1CustUUID.equals(componentInstances.get(0).getCustomizationUUID()));
233 @Test(enabled = true)
234 public void resourceCustomUUIDChangeArtifactsTest() throws Exception {
235 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
237 // create resource in checkin status
238 Resource resource1 = createVfFromCSAR(sdncModifierDetails, "csar_1");
240 RestResponse checkinState = LifecycleRestUtils.changeComponentState(resource1, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
241 BaseRestUtils.checkSuccess(checkinState);
244 ServiceReqDetails serviceDetails = ElementFactory.getDefaultService("ciNewtestservice1", ServiceCategoriesEnum.MOBILITY, sdncModifierDetails.getUserId());
245 RestResponse createServiceResponse = ServiceRestUtils.createService(serviceDetails, sdncModifierDetails);
246 ResourceRestUtils.checkCreateResponse(createServiceResponse);
247 Service service = ResponseParser.parseToObjectUsingMapper(createServiceResponse.getResponse(), Service.class);
250 ComponentInstanceReqDetails componentInstanceDetails = ElementFactory.getComponentInstance(resource1);
251 RestResponse createComponentInstance = ComponentInstanceRestUtils.createComponentInstance(componentInstanceDetails, sdncModifierDetails, service);
252 ResourceRestUtils.checkCreateResponse(createComponentInstance);
254 ComponentInstance ci1 = ResponseParser.parseToObjectUsingMapper(createComponentInstance.getResponse(), ComponentInstance.class);
255 assertNotNull(ci1.getCustomizationUUID());
256 String lastUUID = ci1.getCustomizationUUID();
258 RestResponse getService = ServiceRestUtils.getService(service.getUniqueId());
259 BaseRestUtils.checkSuccess(getService);
260 service = ResponseParser.parseToObjectUsingMapper(getService.getResponse(), Service.class);
262 List<ComponentInstance> componentInstances = service.getComponentInstances();
263 assertNotNull(componentInstances);
264 assertEquals(1, componentInstances.size());
265 ComponentInstance ci = componentInstances.get(0);
266 Map<String, ArtifactDefinition> deploymentArtifacts = ci.getDeploymentArtifacts();
267 assertNotNull(deploymentArtifacts);
268 // find artifact for update
269 ArtifactDefinition artifactForUpdate = null;
270 for (ArtifactDefinition ad : deploymentArtifacts.values()) {
271 if (ad.getArtifactType().equals("HEAT_ENV")) {
272 artifactForUpdate = ad;
277 assertNotNull(artifactForUpdate);
278 // update heat env on instance
279 RestResponse updateArtifact = ArtifactRestUtils.updateDeploymentArtifactToRI(artifactForUpdate, sdncModifierDetails, ci.getUniqueId(), service.getUniqueId());
280 BaseRestUtils.checkSuccess(updateArtifact);
281 getService = ServiceRestUtils.getService(service.getUniqueId());
282 BaseRestUtils.checkSuccess(getService);
283 service = ResponseParser.parseToObjectUsingMapper(getService.getResponse(), Service.class);
284 componentInstances = service.getComponentInstances();
285 assertNotNull(componentInstances);
286 assertFalse(lastUUID.equals(componentInstances.get(0).getCustomizationUUID()));
287 lastUUID = componentInstances.get(0).getCustomizationUUID();
289 // add artifact to instance
290 ArtifactReqDetails artifactDetails = ElementFactory.getDefaultArtifact();
291 RestResponse addArtifactToResourceInstance = ArtifactRestUtils.addArtifactToResourceInstance(artifactDetails, sdncModifierDetails, ci.getUniqueId(), service.getUniqueId());
292 BaseRestUtils.checkSuccess(addArtifactToResourceInstance);
293 ArtifactDefinition artifactDef = ResponseParser.parseToObjectUsingMapper(addArtifactToResourceInstance.getResponse(), ArtifactDefinition.class);
294 assertNotNull(artifactDef);
296 getService = ServiceRestUtils.getService(service.getUniqueId());
297 BaseRestUtils.checkSuccess(getService);
298 service = ResponseParser.parseToObjectUsingMapper(getService.getResponse(), Service.class);
300 componentInstances = service.getComponentInstances();
301 assertNotNull(componentInstances);
302 assertFalse(lastUUID.equals(componentInstances.get(0).getCustomizationUUID()));
303 lastUUID = componentInstances.get(0).getCustomizationUUID();
306 //not supported now!!!!!
307 // artifactDef.setDescription("new description");
308 // RestResponse updateArtifactRes = ArtifactRestUtils.updateArtifactToResourceInstance(artifactDef, sdncModifierDetails, ci.getUniqueId(), service.getUniqueId());
309 // BaseRestUtils.checkSuccess(updateArtifactRes);
310 // artifactDef = ResponseParser.parseToObjectUsingMapper(addArtifactToResourceInstance.getResponse(), ArtifactDefinition.class);
311 // assertNotNull(artifactDef);
313 // getService = ServiceRestUtils.getService(service.getUniqueId());
314 // BaseRestUtils.checkSuccess(getService);
315 // service = ResponseParser.parseToObjectUsingMapper(getService.getResponse(), Service.class);
317 // componentInstances = service.getComponentInstances();
318 // assertNotNull(componentInstances);
319 // assertFalse(lastUUID.equals(componentInstances.get(0).getCustomizationUUID()));
320 // lastUUID = componentInstances.get(0).getCustomizationUUID();
323 // RestResponse deleteArtifactRes = ArtifactRestUtils.deleteArtifactFromResourceInstance (artifactDef, sdncModifierDetails, ci.getUniqueId(), service.getUniqueId());
324 // BaseRestUtils.checkSuccess(deleteArtifactRes);
325 // getService = ServiceRestUtils.getService(service.getUniqueId());
326 // BaseRestUtils.checkSuccess(getService);
327 // service = ResponseParser.parseToObjectUsingMapper(getService.getResponse(), Service.class);
329 // componentInstances = service.getComponentInstances();
330 // assertNotNull(componentInstances);
331 // assertFalse(lastUUID.equals(componentInstances.get(0).getCustomizationUUID()));
334 @Test(enabled = true)
335 public void resourceCustomUUIDRelationTest() throws Exception {
336 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
338 // create resource in checkin status
339 Resource resource = createVfFromCSAR(sdncModifierDetails, "csar_1");
341 RestResponse checkinState = LifecycleRestUtils.changeComponentState(resource, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
342 BaseRestUtils.checkSuccess(checkinState);
345 ServiceReqDetails serviceDetails = ElementFactory.getDefaultService("ciNewtestservice1", ServiceCategoriesEnum.MOBILITY, sdncModifierDetails.getUserId());
346 RestResponse createServiceResponse = ServiceRestUtils.createService(serviceDetails, sdncModifierDetails);
347 ResourceRestUtils.checkCreateResponse(createServiceResponse);
348 Service service = ResponseParser.parseToObjectUsingMapper(createServiceResponse.getResponse(), Service.class);
351 ComponentInstanceReqDetails componentInstanceDetails = ElementFactory.getComponentInstance(resource);
352 RestResponse createComponentInstance = ComponentInstanceRestUtils.createComponentInstance(componentInstanceDetails, sdncModifierDetails, service);
353 ResourceRestUtils.checkCreateResponse(createComponentInstance);
355 ComponentInstance ci1 = ResponseParser.parseToObjectUsingMapper(createComponentInstance.getResponse(), ComponentInstance.class);
356 assertNotNull(ci1.getCustomizationUUID());
357 String ci1LastUUID = ci1.getCustomizationUUID();
360 createComponentInstance = ComponentInstanceRestUtils.createComponentInstance(componentInstanceDetails, sdncModifierDetails, service);
361 ResourceRestUtils.checkCreateResponse(createComponentInstance);
363 ComponentInstance ci2 = ResponseParser.parseToObjectUsingMapper(createComponentInstance.getResponse(), ComponentInstance.class);
364 assertNotNull(ci2.getCustomizationUUID());
365 String ci2LastUUID = ci2.getCustomizationUUID();
367 // get service with 2 instances
368 RestResponse getService = ServiceRestUtils.getService(service.getUniqueId());
369 BaseRestUtils.checkSuccess(getService);
370 service = ResponseParser.parseToObjectUsingMapper(getService.getResponse(), Service.class);
371 List<ComponentInstance> componentInstances = service.getComponentInstances();
372 assertNotNull(componentInstances);
373 assertEquals(2, componentInstances.size());
375 ComponentInstance ciFrom = componentInstances.get(0);
376 ComponentInstance ciTo = componentInstances.get(1);
378 Map<String, List<RequirementDefinition>> requirements = ciFrom.getRequirements();
379 assertNotNull(requirements);
380 List<RequirementDefinition> listReq = requirements.get("tosca.capabilities.network.Bindable");
381 assertNotNull(listReq);
382 RequirementDefinition req = listReq.get(0);
385 Map<String, List<CapabilityDefinition>> capabilities = ciTo.getCapabilities();
386 assertNotNull(capabilities);
387 List<CapabilityDefinition> listCap = capabilities.get("tosca.capabilities.network.Bindable");
388 assertNotNull(listCap);
389 CapabilityDefinition cap = listCap.get(0);
391 List<CapabilityDefinition> capList = new ArrayList<>();
393 List<RequirementDefinition> reqList = new ArrayList<>();
396 RequirementCapabilityRelDef relation = ElementFactory.getReqCapRelation(ciFrom.getUniqueId(),ciTo.getUniqueId(), req.getOwnerId(), cap.getOwnerId(), cap.getType(), req.getName(), capList, reqList );
398 RestResponse associateInstances = ComponentInstanceRestUtils.associateInstances(relation, sdncModifierDetails,service.getUniqueId(), ComponentTypeEnum.SERVICE);
399 ResourceRestUtils.checkSuccess(associateInstances);
401 getService = ServiceRestUtils.getService(service.getUniqueId());
402 BaseRestUtils.checkSuccess(getService);
403 service = ResponseParser.parseToObjectUsingMapper(getService.getResponse(), Service.class);
404 componentInstances = service.getComponentInstances();
405 assertNotNull(componentInstances);
407 for ( ComponentInstance ci : componentInstances){
408 if ( ci.getUniqueId().equals(ci1.getUniqueId()) ){
409 assertFalse( ci1LastUUID.equals(ci.getCustomizationUUID()) );
410 ci1LastUUID = ci.getCustomizationUUID();
412 assertFalse( ci2LastUUID.equals(ci.getCustomizationUUID()) );
413 ci2LastUUID = ci.getCustomizationUUID();
416 associateInstances = ComponentInstanceRestUtils.dissociateInstances(relation, sdncModifierDetails,service.getUniqueId(), ComponentTypeEnum.SERVICE);
417 ResourceRestUtils.checkSuccess(associateInstances);
419 getService = ServiceRestUtils.getService(service.getUniqueId());
420 BaseRestUtils.checkSuccess(getService);
421 service = ResponseParser.parseToObjectUsingMapper(getService.getResponse(), Service.class);
422 componentInstances = service.getComponentInstances();
423 assertNotNull(componentInstances);
425 for ( ComponentInstance ci : componentInstances){
426 if ( ci.getUniqueId().equals(ci1.getUniqueId()) ){
427 assertFalse( ci1LastUUID.equals(ci.getCustomizationUUID()) );
429 assertFalse( ci2LastUUID.equals(ci.getCustomizationUUID()) );