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.distribution;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertNotNull;
26 import java.io.ByteArrayInputStream;
27 import java.io.InputStream;
28 import java.util.HashMap;
29 import java.util.List;
31 import java.util.zip.ZipInputStream;
33 import org.apache.commons.codec.binary.Base64;
34 import org.junit.Rule;
35 import org.junit.rules.TestName;
36 import org.openecomp.sdc.be.datatypes.elements.ConsumerDataDefinition;
37 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
38 import org.openecomp.sdc.be.model.ArtifactDefinition;
39 import org.openecomp.sdc.be.model.Resource;
40 import org.openecomp.sdc.be.model.Service;
41 import org.openecomp.sdc.be.model.User;
42 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
43 import org.openecomp.sdc.ci.tests.api.Urls;
44 import org.openecomp.sdc.ci.tests.config.Config;
45 import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails;
46 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
47 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
48 import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
49 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
50 import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum;
51 import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
52 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
53 import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedDistDownloadAudit;
54 import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
55 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
56 import org.openecomp.sdc.ci.tests.utils.ArtifactUtils;
57 import org.openecomp.sdc.ci.tests.utils.Utils;
58 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
59 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
60 import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
61 import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
62 import org.openecomp.sdc.ci.tests.utils.rest.ConsumerRestUtils;
63 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
64 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
65 import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
66 import org.openecomp.sdc.ci.tests.utils.validation.AuditValidationUtils;
67 import org.openecomp.sdc.common.api.Constants;
68 import org.openecomp.sdc.common.util.GeneralUtility;
69 import org.openecomp.sdc.common.util.ValidationUtils;
70 import org.testng.AssertJUnit;
71 import org.testng.annotations.BeforeMethod;
72 import org.testng.annotations.Test;
74 public class DistributionDownloadArtifactTest extends ComponentBaseTest {
76 protected static ResourceReqDetails resourceDetails;
77 protected static User designerUser;
78 protected static User adminUser;
79 protected static String resourceBaseVersion;
80 // user ci password 123456
81 protected final String authorizationHeader = "Basic Y2k6MTIzNDU2";
82 protected ConsumerDataDefinition consumerDataDefinition;
85 public static TestName name = new TestName();
86 protected static String artifactInterfaceType;
87 protected static String artifactOperationName;
89 protected static ServiceReqDetails serviceDetails;
90 protected static String serviceBaseVersion;
91 protected static String serviceUniqueId;
92 protected final String USER = "ci";
93 protected final String PASSWORD = "123456";
94 protected final String SALT = "2a1f887d607d4515d4066fe0f5452a50";
95 protected final String HASHED_PASSWORD = "0a0dc557c3bf594b1a48030e3e99227580168b21f44e285c69740b8d5b13e33b";
97 public DistributionDownloadArtifactTest() {
98 super(name, DistributionDownloadArtifactTest.class.getName());
102 // public static void InitBeforeTest() throws Exception
106 // resourceBaseVersion = "0.1";
107 // serviceBaseVersion = "0.1";
108 // designerUser = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
109 // adminUser = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
111 // ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC,
112 // NormativeTypesEnum.ROOT, ResourceCategoryEnum.NETWORK_L2_3_ROUTERS,
114 // serviceDetails = ElementFactory.getDefaultService();
115 // serviceUniqueId = "svc_" + serviceDetails.getName().toLowerCase() + "." +
116 // serviceBaseVersion;
117 // artifactInterfaceType = "standard";
118 // artifactOperationName = "start";
122 public void setup() throws Exception {
124 resourceBaseVersion = "0.1";
125 serviceBaseVersion = "0.1";
126 designerUser = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
127 adminUser = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
128 resourceDetails = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC,
129 NormativeTypesEnum.ROOT, ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, adminUser);
130 serviceDetails = ElementFactory.getDefaultService();
131 serviceUniqueId = "svc_" + serviceDetails.getName().toLowerCase() + "." + serviceBaseVersion;
132 artifactInterfaceType = "standard";
133 artifactOperationName = "start";
134 consumerDataDefinition = createConsumer();
135 RestResponse deleteResponse = ConsumerRestUtils.deleteConsumer(consumerDataDefinition, adminUser);
136 BaseRestUtils.checkStatusCode(deleteResponse, "delete operation filed", false, 404, 200);
138 RestResponse createResponse = ConsumerRestUtils.createConsumer(consumerDataDefinition, adminUser);
139 BaseRestUtils.checkCreateResponse(createResponse);
143 public void downloadResourceArtifactSuccess() throws Exception {
145 RestResponse serviceResponse = ServiceRestUtils.createService(serviceDetails, designerUser);
146 AssertJUnit.assertEquals("Check response code after creating resource", 201,
147 serviceResponse.getErrorCode().intValue());
150 RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, designerUser);
151 AssertJUnit.assertEquals("Check response code after creating resource", 201,
152 createResource.getErrorCode().intValue());
153 Resource resource = ResponseParser.convertResourceResponseToJavaObject(createResource.getResponse());
155 ArtifactReqDetails artifactDetails = ElementFactory
156 .getDefaultDeploymentArtifactForType(ArtifactTypeEnum.HEAT.getType());
157 // Setting the name to be with space
158 artifactDetails.setArtifactName("test artifact file.yaml");
159 // artifactDetails.set(ArtifactRestUtils.calculateChecksum(artifactDetails));
161 RestResponse addArtifactResponse = ArtifactRestUtils.addInformationalArtifactToResource(artifactDetails,
162 designerUser, resource.getUniqueId(), ArtifactRestUtils.calculateChecksum(artifactDetails));
163 AssertJUnit.assertEquals("Check response code after adding interface artifact", 200,
164 addArtifactResponse.getErrorCode().intValue());
166 // Getting expected artifact checksum
167 ArtifactDefinition artifactResp = ResponseParser
168 .convertArtifactDefinitionResponseToJavaObject(addArtifactResponse.getResponse());
169 String expectedPayloadChecksum = artifactResp.getArtifactChecksum();
171 Config config = Utils.getConfig();
172 String relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_RESOURCE_ARTIFACT_RELATIVE_URL,
173 ValidationUtils.convertToSystemName(serviceDetails.getName()), serviceBaseVersion,
174 ValidationUtils.convertToSystemName(resource.getName()), resource.getVersion(),
175 artifactResp.getArtifactName()));
176 // String fullUrlFormatted =
177 // String.format(Urls.DOWNLOAD_RESOURCE_ARTIFACT_FULL_URL,
178 // config.getCatalogBeHost(),config.getCatalogBePort(), relativeUrl);
179 // String consumerId = "dummy.ecomp";
181 ResourceReqDetails resourceInfo = new ResourceReqDetails();
182 resourceInfo.setName(resource.getName());
183 resourceInfo.setVersion(resource.getVersion());
185 Map<String, String> authorizationHeaders = new HashMap<String, String>();
186 authorizationHeaders.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
187 RestResponse restResponse = ArtifactRestUtils.downloadResourceArtifact(serviceDetails, resourceInfo,
188 artifactDetails, designerUser, authorizationHeaders);
189 // RestResponse restResponse =
190 // artifactUtils.downloadResourceArtifact(designerUser,fullUrlFormatted,
192 AssertJUnit.assertEquals("Check response code after download resource", 200,
193 restResponse.getErrorCode().intValue());
195 // Validating headers
196 // content disposition
197 List<String> contDispHeaderList = restResponse.getHeaderFields().get(Constants.CONTENT_DISPOSITION_HEADER);
198 AssertJUnit.assertNotNull(contDispHeaderList);
201 "Check content disposition header", new StringBuilder().append("attachment; filename=\"")
202 .append(artifactResp.getArtifactName()).append("\"").toString(),
203 contDispHeaderList.get(0));
206 List<String> contTypeHeaderList = restResponse.getHeaderFields().get(Constants.CONTENT_TYPE_HEADER);
207 AssertJUnit.assertNotNull(contTypeHeaderList);
208 AssertJUnit.assertEquals("Check content type", "application/octet-stream", contTypeHeaderList.get(0));
210 String actualContents = restResponse.getResponse();
212 // Contents - comparing decoded content
213 AssertJUnit.assertEquals(artifactDetails.getPayload(), Base64.encodeBase64String(actualContents.getBytes()));
215 // validating checksum
216 String actualPayloadChecksum = GeneralUtility.calculateMD5Base64EncodedByByteArray(actualContents.getBytes());
217 AssertJUnit.assertEquals(expectedPayloadChecksum, actualPayloadChecksum);
220 String auditAction = "DArtifactDownload";
222 ExpectedDistDownloadAudit expectedDistDownloadAudit = new ExpectedDistDownloadAudit(auditAction,
223 BaseRestUtils.ecomp, relativeUrl, "200", "OK");
224 AuditValidationUtils.validateAudit(expectedDistDownloadAudit, auditAction);
227 protected void download_serviceNameNotFound_inner(String serviceName, String serviceVersion, String resourceName,
228 String resourceVersion) throws Exception {
229 Config config = Utils.getConfig();
230 String artifactName = "kuku";
231 ArtifactReqDetails artifact = new ArtifactReqDetails();
232 artifact.setArtifactName(artifactName);
234 Map<String, String> authorizationHeaders = new HashMap<String, String>();
235 authorizationHeaders.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
236 ServiceReqDetails serviceInfo = new ServiceReqDetails();
237 serviceInfo.setName(serviceName);
238 serviceInfo.setVersion(serviceVersion);
239 RestResponse restResponse = null;
240 if (resourceName != null) {
241 ResourceReqDetails resourceDetailes = new ResourceReqDetails();
242 resourceDetailes.setName(resourceName);
243 resourceDetailes.setVersion(resourceVersion);
244 relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_RESOURCE_ARTIFACT_RELATIVE_URL,
245 ValidationUtils.convertToSystemName(serviceName), serviceVersion,
246 ValidationUtils.convertToSystemName(resourceName), resourceVersion, artifactName));
247 restResponse = ArtifactRestUtils.downloadResourceArtifact(serviceInfo, resourceDetailes, artifact,
248 designerUser, authorizationHeaders);
250 relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_SERVICE_ARTIFACT_RELATIVE_URL,
251 ValidationUtils.convertToSystemName(serviceName), serviceVersion, artifactName));
252 restResponse = ArtifactRestUtils.downloadServiceArtifact(serviceInfo, artifact, designerUser,
253 authorizationHeaders);
256 // RestResponse restResponse =
257 // artifactUtils.downloadResourceArtifact(designerUser,fullUrlFormatted,
259 AssertJUnit.assertEquals("Check response code after download resource", 404,
260 restResponse.getErrorCode().intValue());
263 String auditAction = "DArtifactDownload";
265 ExpectedDistDownloadAudit expectedDistDownloadAudit = new ExpectedDistDownloadAudit(auditAction,
266 BaseRestUtils.ecomp, relativeUrl, "404", "SVC4503: Error: Requested '"
267 + ValidationUtils.convertToSystemName(serviceName) + "' service was not found.");
268 AuditValidationUtils.validateAudit(expectedDistDownloadAudit, auditAction);
271 protected void download_serviceVersionNotFound_inner(String serviceName, String serviceVersion, String resourceName,
272 String resourceVersion) throws Exception {
273 Config config = Utils.getConfig();
274 String artifactName = "kuku";
276 ArtifactReqDetails artifact = new ArtifactReqDetails();
277 artifact.setArtifactName(artifactName);
278 Map<String, String> authorizationHeaders = new HashMap<String, String>();
279 authorizationHeaders.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
280 ServiceReqDetails serviceInfo = new ServiceReqDetails();
281 serviceInfo.setName(serviceName);
282 serviceInfo.setVersion(serviceVersion);
283 RestResponse restResponse = null;
284 if (resourceName != null) {
285 ResourceReqDetails resourceDetailes = new ResourceReqDetails();
286 resourceDetailes.setName(resourceName);
287 resourceDetailes.setVersion(resourceVersion);
288 relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_RESOURCE_ARTIFACT_RELATIVE_URL,
289 ValidationUtils.convertToSystemName(serviceName), serviceVersion,
290 ValidationUtils.convertToSystemName(resourceName), resourceVersion, artifactName));
291 restResponse = ArtifactRestUtils.downloadResourceArtifact(serviceInfo, resourceDetailes, artifact,
292 designerUser, authorizationHeaders);
294 relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_SERVICE_ARTIFACT_RELATIVE_URL,
295 ValidationUtils.convertToSystemName(serviceName), serviceVersion, artifactName));
296 restResponse = ArtifactRestUtils.downloadServiceArtifact(serviceInfo, artifact, designerUser,
297 authorizationHeaders);
299 // String fullUrlFormatted =
300 // String.format(Urls.DOWNLOAD_RESOURCE_ARTIFACT_FULL_URL,
301 // config.getCatalogBeHost(),config.getCatalogBePort(), relativeUrl);
302 // String consumerId = "dummy.ecomp";
304 // RestResponse restResponse =
305 // artifactUtils.downloadResourceArtifact(designerUser,fullUrlFormatted,
307 AssertJUnit.assertEquals("Check response code after download resource", 404,
308 restResponse.getErrorCode().intValue());
311 String auditAction = "DArtifactDownload";
313 ExpectedDistDownloadAudit expectedDistDownloadAudit = new ExpectedDistDownloadAudit(auditAction,
314 BaseRestUtils.ecomp, relativeUrl, "404",
315 "SVC4504: Error: Service version " + serviceVersion + " was not found.");
316 AuditValidationUtils.validateAudit(expectedDistDownloadAudit, auditAction);
319 protected String encodeUrlForDownload(String url) {
320 return url.replaceAll(" ", "%20");
323 protected ConsumerDataDefinition createConsumer() {
324 ConsumerDataDefinition consumer = new ConsumerDataDefinition();
325 consumer.setConsumerName(USER);
326 consumer.setConsumerSalt(SALT);
327 consumer.setConsumerPassword(HASHED_PASSWORD);
332 @Test(enabled = false)
333 public void downloadServiceArtifactSuccess() throws Exception {
335 RestResponse serviceResponse = ServiceRestUtils.createService(serviceDetails, designerUser);
336 assertEquals("Check response code after creating resource", 201, serviceResponse.getErrorCode().intValue());
337 serviceUniqueId = ResponseParser.convertServiceResponseToJavaObject(serviceResponse.getResponse())
340 ArtifactReqDetails artifactDetails = ElementFactory.getDefaultDeploymentArtifactForType("MURANO_PKG");
342 RestResponse addArtifactResponse = ArtifactRestUtils.addInformationalArtifactToService(artifactDetails,
343 designerUser, serviceUniqueId, ArtifactRestUtils.calculateMD5Header(artifactDetails));
344 assertEquals("Check response code after adding interface artifact", 200,
345 addArtifactResponse.getErrorCode().intValue());
347 // Getting expected artifact checksum
349 // ArtifactResJavaObject artifactResp =
350 // artifactUtils.parseInformationalArtifactResp(addArtifactResponse);
351 String expectedPayloadChecksum = ResponseParser
352 .convertArtifactDefinitionResponseToJavaObject(addArtifactResponse.getResponse()).getArtifactChecksum();
354 String artifactName = ValidationUtils.normalizeFileName(artifactDetails.getArtifactName());
356 String relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_SERVICE_ARTIFACT_RELATIVE_URL,
357 ValidationUtils.convertToSystemName(serviceDetails.getName()), serviceBaseVersion, artifactName));
359 Map<String, String> authorizationHeaders = new HashMap<String, String>();
360 authorizationHeaders.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
361 RestResponse restResponse = ArtifactRestUtils.downloadServiceArtifact(serviceDetails, artifactDetails,
362 designerUser, authorizationHeaders);
363 assertEquals("Check response code after download resource", 200, restResponse.getErrorCode().intValue());
365 // Validating headers
366 // content disposition
367 List<String> contDispHeaderList = restResponse.getHeaderFields().get(Constants.CONTENT_DISPOSITION_HEADER);
368 assertNotNull(contDispHeaderList);
369 assertEquals("Check content disposition header",
370 new StringBuilder().append("attachment; filename=\"").append(artifactName).append("\"").toString(),
371 contDispHeaderList.get(0));
374 List<String> contTypeHeaderList = restResponse.getHeaderFields().get(Constants.CONTENT_TYPE_HEADER);
375 assertNotNull(contTypeHeaderList);
376 assertEquals("Check content type", "application/octet-stream", contTypeHeaderList.get(0));
378 String actualContents = restResponse.getResponse();
380 assertEquals(artifactDetails.getPayload(), Base64.encodeBase64String(actualContents.getBytes()));
382 // validating checksum
383 byte[] bytes = actualContents.getBytes();
384 String actualPayloadChecksum = GeneralUtility.calculateMD5Base64EncodedByByteArray(bytes);
385 assertEquals(expectedPayloadChecksum, actualPayloadChecksum);
387 // validating valid zip
388 InputStream is = new ByteArrayInputStream(bytes);
389 InputStream zis = new ZipInputStream(is);
393 String auditAction = "DArtifactDownload";
395 ExpectedDistDownloadAudit expectedDistDownloadAudit = new ExpectedDistDownloadAudit(auditAction,
396 ResourceRestUtils.ecomp, encodeUrlForDownload(relativeUrl), "200", "OK");
397 AuditValidationUtils.validateAudit(expectedDistDownloadAudit, auditAction);
401 public void downloadResourceArtifact_NoConsumerId() throws Exception {
403 String artifactName = "kuku";
404 ArtifactReqDetails artifact = new ArtifactReqDetails();
405 artifact.setArtifactName(artifactName);
406 ResourceReqDetails resource = new ResourceReqDetails();
407 resource.setName("notExisting");
408 resource.setVersion("0.1");
409 String relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_RESOURCE_ARTIFACT_RELATIVE_URL,
410 ValidationUtils.convertToSystemName(serviceDetails.getName()), serviceBaseVersion,
411 ValidationUtils.convertToSystemName(resource.getName()), resource.getVersion(), artifactName));
412 serviceDetails.setVersion("0.1");
413 Map<String, String> authorizationHeaders = new HashMap<String, String>();
414 authorizationHeaders.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
415 RestResponse restResponse = ArtifactRestUtils.downloadResourceArtifact(serviceDetails, resource, artifact,
416 designerUser, authorizationHeaders, false);
417 assertEquals("Check response code after download resource", 400, restResponse.getErrorCode().intValue());
420 String auditAction = "DArtifactDownload";
422 ExpectedDistDownloadAudit expectedDistDownloadAudit = new ExpectedDistDownloadAudit(auditAction, "",
423 relativeUrl, "400", "POL5001: Error: Missing 'X-ECOMP-InstanceID' HTTP header.");
424 AuditValidationUtils.validateAudit(expectedDistDownloadAudit, auditAction);
428 public void downloadResourceArtifact_ResourceNameNotFound() throws Exception {
430 String artifactName = "kuku";
431 ArtifactReqDetails artifact = new ArtifactReqDetails();
432 artifact.setArtifactName(artifactName);
433 ResourceReqDetails resource = new ResourceReqDetails();
434 resource.setName("notExisting");
435 resource.setVersion("0.1");
436 serviceDetails.setVersion("0.1");
437 String relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_RESOURCE_ARTIFACT_RELATIVE_URL,
438 ValidationUtils.convertToSystemName(serviceDetails.getName()), serviceDetails.getVersion(),
439 ValidationUtils.convertToSystemName(resource.getName()), resource.getVersion(), artifactName));
441 Map<String, String> authorizationHeaders = new HashMap<String, String>();
442 authorizationHeaders.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
443 RestResponse restResponse = ArtifactRestUtils.downloadResourceArtifact(serviceDetails, resource, artifact,
444 designerUser, authorizationHeaders);
446 assertEquals("Check response code after download resource", 404, restResponse.getErrorCode().intValue());
449 String auditAction = "DArtifactDownload";
451 ExpectedDistDownloadAudit expectedDistDownloadAudit = new ExpectedDistDownloadAudit(auditAction,
452 BaseRestUtils.ecomp, relativeUrl, "404",
453 "SVC4063: Error: Requested 'Notexisting' resource was not found.");
454 AuditValidationUtils.validateAudit(expectedDistDownloadAudit, auditAction);
458 public void downloadResourceArtifact_ResourceVersionNotFound() throws Exception {
459 RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, designerUser);
460 assertEquals("Check response code after creating resource", 201, createResource.getErrorCode().intValue());
462 Resource resource = ResponseParser.convertResourceResponseToJavaObject(createResource.getResponse());
463 ResourceReqDetails resourceDetailes = new ResourceReqDetails();
464 resourceDetailes.setName(resource.getName());
465 resourceDetailes.setVersion("0.2");
467 serviceDetails.setVersion("0.1");
469 String artifactName = "kuku";
470 ArtifactReqDetails artifact = new ArtifactReqDetails();
471 artifact.setArtifactName(artifactName);
473 String relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_RESOURCE_ARTIFACT_RELATIVE_URL,
474 ValidationUtils.convertToSystemName(serviceDetails.getName()), serviceBaseVersion,
475 ValidationUtils.convertToSystemName(resourceDetailes.getName()), resourceDetailes.getVersion(),
478 Map<String, String> authorizationHeaders = new HashMap<String, String>();
479 authorizationHeaders.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
480 RestResponse restResponse = ArtifactRestUtils.downloadResourceArtifact(serviceDetails, resourceDetailes,
481 artifact, designerUser, authorizationHeaders);
482 assertEquals("Check response code after download resource", 404, restResponse.getErrorCode().intValue());
485 String auditAction = "DArtifactDownload";
487 ExpectedDistDownloadAudit expectedDistDownloadAudit = new ExpectedDistDownloadAudit(auditAction,
488 BaseRestUtils.ecomp, relativeUrl, "404", "SVC4504: Error: Resource version 0.2 was not found.");
489 AuditValidationUtils.validateAudit(expectedDistDownloadAudit, auditAction);
493 public void downloadResourceArtifact_ServiceNameNotFound() throws Exception {
495 RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, designerUser);
496 assertEquals("Check response code after creating resource", 201, createResource.getErrorCode().intValue());
497 Resource resource = ResponseParser.convertResourceResponseToJavaObject(createResource.getResponse());
498 download_serviceNameNotFound_inner("notExistingServiceName", serviceBaseVersion, resource.getName(),
499 resource.getVersion());
504 public void downloadResourceArtifact_ServiceVersionNotFound() throws Exception {
506 RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, designerUser);
507 assertEquals("Check response code after creating resource", 201, createResource.getErrorCode().intValue());
508 Resource resource = ResponseParser.convertResourceResponseToJavaObject(createResource.getResponse());
511 RestResponse serviceResponse = ServiceRestUtils.createService(serviceDetails, designerUser);
512 assertEquals("Check response code after creating resource", 201, serviceResponse.getErrorCode().intValue());
513 serviceUniqueId = ResponseParser.convertServiceResponseToJavaObject(serviceResponse.getResponse())
516 download_serviceVersionNotFound_inner(serviceDetails.getName(), "0.3", resource.getName(),
517 resource.getVersion());
521 public void downloadServiceArtifact_ServiceNameNotFound() throws Exception {
522 download_serviceNameNotFound_inner("notExistingServiceName", serviceBaseVersion, null, null);
527 public void downloadServiceArtifact_ServiceVersionNotFound() throws Exception {
530 RestResponse serviceResponse = ServiceRestUtils.createService(serviceDetails, designerUser);
531 assertEquals("Check response code after creating resource", 201, serviceResponse.getErrorCode().intValue());
532 serviceUniqueId = ResponseParser.convertServiceResponseToJavaObject(serviceResponse.getResponse())
535 download_serviceVersionNotFound_inner(serviceDetails.getName(), "0.2", null, null);
539 public void downloadServiceToscaArtifactSuccess() throws Exception {
541 RestResponse serviceResponse = ServiceRestUtils.createService(serviceDetails, designerUser);
542 assertEquals("Check response code after creating resource", 201, serviceResponse.getErrorCode().intValue());
543 Service service = ResponseParser.convertServiceResponseToJavaObject(serviceResponse.getResponse());
544 service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
545 // Approves service distribution
546 RestResponse serviceDistributionApproveRes = ServiceRestUtils.approveServiceDistribution(service.getUniqueId(), UserRoleEnum.GOVERNOR.getUserId());
547 service = ResponseParser.convertServiceResponseToJavaObject(serviceDistributionApproveRes.getResponse());
548 // Distributes service
549 RestResponse serviceDistributionRes = AtomicOperationUtils.distributeService(service, true);
550 service = ResponseParser.convertServiceResponseToJavaObject(serviceDistributionRes.getResponse());
551 // Gets tosca template artifact from service
552 ArtifactDefinition toscaTemplateArtifact = service.getToscaArtifacts().get("assettoscatemplate");
553 String expectedPayloadChecksum = toscaTemplateArtifact.getArtifactChecksum();
554 String artifactName = toscaTemplateArtifact.getArtifactName();
555 ArtifactReqDetails artifactDetails = ArtifactUtils.convertArtifactDefinitionToArtifactReqDetails(toscaTemplateArtifact);
556 // Downloads tosca template artifact
557 Map<String, String> authorizationHeaders = new HashMap<String, String>();
558 authorizationHeaders.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
559 RestResponse restResponse = ArtifactRestUtils.downloadServiceArtifact(serviceDetails, artifactDetails,
560 designerUser, authorizationHeaders);
561 assertEquals("Check response code after download resource", 200, restResponse.getErrorCode().intValue());
563 // Validating headers
564 // content disposition
565 List<String> contDispHeaderList = restResponse.getHeaderFields().get(Constants.CONTENT_DISPOSITION_HEADER);
566 assertNotNull(contDispHeaderList);
567 assertEquals("Check content disposition header",
568 new StringBuilder().append("attachment; filename=\"").append(artifactName).append("\"").toString(),
569 contDispHeaderList.get(0));
572 List<String> contTypeHeaderList = restResponse.getHeaderFields().get(Constants.CONTENT_TYPE_HEADER);
573 assertNotNull(contTypeHeaderList);
574 assertEquals("Check content type", "application/octet-stream", contTypeHeaderList.get(0));
575 String actualContents = restResponse.getResponse();
577 // validating checksum
578 byte[] bytes = actualContents.getBytes();
579 String actualPayloadChecksum = GeneralUtility.calculateMD5Base64EncodedByByteArray(bytes);
580 AssertJUnit.assertEquals(expectedPayloadChecksum, actualPayloadChecksum);
582 // validating valid zip
583 InputStream is = new ByteArrayInputStream(bytes);
584 InputStream zis = new ZipInputStream(is);
588 String relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_SERVICE_ARTIFACT_RELATIVE_URL,
589 ValidationUtils.convertToSystemName(serviceDetails.getName()), serviceBaseVersion, artifactName));
590 String auditAction = "DArtifactDownload";
591 ExpectedDistDownloadAudit expectedDistDownloadAudit = new ExpectedDistDownloadAudit(auditAction,
592 ResourceRestUtils.ecomp, encodeUrlForDownload(relativeUrl), "200", "OK");
593 AuditValidationUtils.validateAudit(expectedDistDownloadAudit, auditAction);