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.artifacts;
23 import org.apache.commons.codec.binary.Base64;
24 import org.junit.Rule;
25 import org.junit.rules.TestName;
26 import org.openecomp.sdc.be.datatypes.elements.HeatParameterDataDefinition;
27 import org.openecomp.sdc.be.model.*;
28 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
29 import org.openecomp.sdc.ci.tests.datatypes.ComponentInstanceReqDetails;
30 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
31 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
32 import org.openecomp.sdc.ci.tests.datatypes.enums.ServiceCategoriesEnum;
33 import org.openecomp.sdc.ci.tests.datatypes.enums.ServiceInstantiationType;
34 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
35 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
36 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
37 import org.openecomp.sdc.ci.tests.utils.rest.*;
38 import org.testng.annotations.Test;
39 import org.yaml.snakeyaml.Yaml;
41 import java.io.ByteArrayInputStream;
42 import java.io.InputStream;
43 import java.util.List;
46 import static org.junit.Assert.assertEquals;
47 import static org.junit.Assert.assertNotNull;
49 public class HeatEnvArtifact extends ComponentBaseTest {
52 public static TestName name = new TestName();
54 public HeatEnvArtifact() {
55 super(name, HeatEnvArtifact.class.getName());
59 public void heatEnvOnResourceFormatTest() throws Exception {
61 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
63 Resource createdResource = createVfFromCSAR(sdncModifierDetails, "csarHeatEnv.csar");
64 assertNotNull(createdResource);
66 RestResponse certifyState = LifecycleRestUtils.changeComponentState(createdResource, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
67 BaseRestUtils.checkSuccess(certifyState);
69 Resource certifiedResource = ResponseParser.parseToObjectUsingMapper(certifyState.getResponse(), Resource.class);
71 ServiceReqDetails serviceDetails = ElementFactory.getDefaultService(
72 "ciNewtestservice1", ServiceCategoriesEnum.MOBILITY, sdncModifierDetails.getUserId(),
73 ServiceInstantiationType.A_LA_CARTE.getValue());
76 RestResponse createServiceResponse = ServiceRestUtils.createService(serviceDetails, sdncModifierDetails);
77 ResourceRestUtils.checkCreateResponse(createServiceResponse);
78 Service service = ResponseParser.parseToObjectUsingMapper(createServiceResponse.getResponse(), Service.class);
80 // 3 create vf instance in service
81 ComponentInstanceReqDetails componentInstanceDetails = ElementFactory.getComponentInstance(certifiedResource);
82 RestResponse createComponentInstance = ComponentInstanceRestUtils.createComponentInstance(componentInstanceDetails, sdncModifierDetails, service);
83 ResourceRestUtils.checkCreateResponse(createComponentInstance);
85 RestResponse getService = ServiceRestUtils.getService(service.getUniqueId());
86 BaseRestUtils.checkSuccess(getService);
87 service = ResponseParser.parseToObjectUsingMapper(getService.getResponse(), Service.class);
89 List<ComponentInstance> componentInstances = service.getComponentInstances();
90 assertNotNull(componentInstances);
91 assertEquals(1, componentInstances.size());
93 ComponentInstance vfi = componentInstances.get(0);
94 Map<String, ArtifactDefinition> deploymentArtifacts = vfi.getDeploymentArtifacts();
95 assertNotNull(deploymentArtifacts);
96 assertEquals(4, deploymentArtifacts.size());
97 ArtifactDefinition heatEnv = deploymentArtifacts.get("heat0env");
98 assertNotNull(heatEnv);
100 Map<String, Object> yaml = downloadComponentInstanceYamlFile(service.getUniqueId(), vfi.getUniqueId(), sdncModifierDetails, heatEnv.getUniqueId());
102 Map<String, Object> paramters = (Map<String, Object>)yaml.get("parameters");
103 assertNotNull(paramters);
104 assertEquals(8, paramters.size());
105 assertEquals(null, paramters.get("param8"));
106 List<HeatParameterDataDefinition> heatParameters = heatEnv.getHeatParameters();
107 heatParameters.forEach(p -> {
108 assertEquals(p.getCurrentValue(), paramters.get(p.getName()));
111 @Test(enabled = true)
112 public void noHeatEnvOnResourceFormatTest() throws Exception {
113 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
115 Resource createdResource = createVfFromCSAR(sdncModifierDetails, "csarHeatNoEnv.csar");
116 assertNotNull(createdResource);
118 RestResponse certifyState = LifecycleRestUtils.changeComponentState(createdResource, sdncModifierDetails, LifeCycleStatesEnum.CHECKIN);
119 BaseRestUtils.checkSuccess(certifyState);
121 Resource certifiedResource = ResponseParser.parseToObjectUsingMapper(certifyState.getResponse(), Resource.class);
123 ServiceReqDetails serviceDetails = ElementFactory.getDefaultService(
124 "ciNewtestservice1", ServiceCategoriesEnum.MOBILITY, sdncModifierDetails.getUserId(),
125 ServiceInstantiationType.A_LA_CARTE.getValue());
128 RestResponse createServiceResponse = ServiceRestUtils.createService(serviceDetails, sdncModifierDetails);
129 ResourceRestUtils.checkCreateResponse(createServiceResponse);
130 Service service = ResponseParser.parseToObjectUsingMapper(createServiceResponse.getResponse(), Service.class);
132 // 3 create vf instance in service
133 ComponentInstanceReqDetails componentInstanceDetails = ElementFactory.getComponentInstance(certifiedResource);
134 RestResponse createComponentInstance = ComponentInstanceRestUtils.createComponentInstance(componentInstanceDetails, sdncModifierDetails, service);
135 ResourceRestUtils.checkCreateResponse(createComponentInstance);
137 RestResponse getService = ServiceRestUtils.getService(service.getUniqueId());
138 BaseRestUtils.checkSuccess(getService);
139 service = ResponseParser.parseToObjectUsingMapper(getService.getResponse(), Service.class);
141 List<ComponentInstance> componentInstances = service.getComponentInstances();
142 assertNotNull(componentInstances);
143 assertEquals(1, componentInstances.size());
145 ComponentInstance vfi = componentInstances.get(0);
146 Map<String, ArtifactDefinition> deploymentArtifacts = vfi.getDeploymentArtifacts();
147 assertNotNull(deploymentArtifacts);
148 assertEquals(4, deploymentArtifacts.size());
149 ArtifactDefinition heatEnv = deploymentArtifacts.get("heat0env");
150 assertNotNull(heatEnv);
152 Map<String, Object> yaml = downloadComponentInstanceYamlFile(service.getUniqueId(), vfi.getUniqueId(), sdncModifierDetails, heatEnv.getUniqueId());
154 Map<String, Object> paramters = (Map<String, Object>)yaml.get("parameters");
155 assertNotNull(paramters);
156 assertEquals(8, paramters.size());
157 assertEquals(null, paramters.get("param1"));
158 assertEquals(null, paramters.get("param2"));
159 assertEquals(null, paramters.get("param4"));
160 assertEquals(null, paramters.get("param5"));
161 assertEquals(null, paramters.get("param7"));
162 assertEquals(null, paramters.get("param8"));
163 List<HeatParameterDataDefinition> heatParameters = heatEnv.getHeatParameters();
164 heatParameters.forEach(p -> {
165 assertEquals(p.getCurrentValue(), paramters.get(p.getName()));
169 //****************************************
170 private Map<String, Object> downloadComponentInstanceYamlFile(String serviceUniqueId, String resourceInstanceId, User user, String artifactUniqeId) throws Exception {
171 RestResponse heatEnvDownloadResponse = ArtifactRestUtils.downloadResourceInstanceArtifact(serviceUniqueId, resourceInstanceId, user, artifactUniqeId);
172 BaseRestUtils.checkSuccess(heatEnvDownloadResponse);
174 ArtifactUiDownloadData artifactUiDownloadData = ResponseParser.parseToObject(heatEnvDownloadResponse.getResponse(), ArtifactUiDownloadData.class);
175 byte[] fromUiDownload = artifactUiDownloadData.getBase64Contents().getBytes();
176 byte[] decodeBase64 = Base64.decodeBase64(fromUiDownload);
177 Yaml yaml = new Yaml();
179 InputStream inputStream = new ByteArrayInputStream(decodeBase64);
181 Map<String, Object> load = (Map<String, Object>) yaml.load(inputStream);