01645006136a5eee7bd806d89b49fcc576ad2630
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.ci.tests.execute.distribution;
22
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.ConsumerDataDefinition;
27 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
28 import org.openecomp.sdc.be.model.ArtifactDefinition;
29 import org.openecomp.sdc.be.model.Resource;
30 import org.openecomp.sdc.be.model.User;
31 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
32 import org.openecomp.sdc.ci.tests.api.Urls;
33 import org.openecomp.sdc.ci.tests.config.Config;
34 import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails;
35 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
36 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
37 import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
38 import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum;
39 import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
40 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
41 import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedDistDownloadAudit;
42 import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
43 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
44 import org.openecomp.sdc.ci.tests.utils.Utils;
45 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
46 import org.openecomp.sdc.ci.tests.utils.rest.*;
47 import org.openecomp.sdc.ci.tests.utils.validation.AuditValidationUtils;
48 import org.openecomp.sdc.common.api.Constants;
49 import org.openecomp.sdc.common.util.GeneralUtility;
50 import org.openecomp.sdc.common.util.ValidationUtils;
51 import org.testng.AssertJUnit;
52 import org.testng.annotations.BeforeMethod;
53 import org.testng.annotations.Test;
54
55 import java.io.ByteArrayInputStream;
56 import java.io.InputStream;
57 import java.util.HashMap;
58 import java.util.List;
59 import java.util.Map;
60 import java.util.zip.ZipInputStream;
61
62 import static org.testng.AssertJUnit.assertEquals;
63 import static org.testng.AssertJUnit.assertNotNull;
64
65 public class DistributionDownloadArtifactTest extends ComponentBaseTest {
66
67         protected static ResourceReqDetails resourceDetails;
68         protected static User designerUser;
69         protected static User adminUser;
70         protected static String resourceBaseVersion;
71         // user ci password 123456
72         protected final String authorizationHeader = "Basic Y2k6MTIzNDU2";
73         protected ConsumerDataDefinition consumerDataDefinition;
74
75         @Rule
76         public static TestName name = new TestName();
77         protected static String artifactInterfaceType;
78         protected static String artifactOperationName;
79
80         protected static ServiceReqDetails serviceDetails;
81         protected static String serviceBaseVersion;
82         protected static String serviceUniqueId;
83         protected final String USER = "ci";
84         protected final String PASSWORD = "123456";
85         protected final String SALT = "2a1f887d607d4515d4066fe0f5452a50";
86         protected final String HASHED_PASSWORD = "0a0dc557c3bf594b1a48030e3e99227580168b21f44e285c69740b8d5b13e33b";
87
88         // @BeforeClass
89         // public static void InitBeforeTest() throws Exception
90         // {
91         //
92         //
93         // resourceBaseVersion = "0.1";
94         // serviceBaseVersion = "0.1";
95         // designerUser = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
96         // adminUser = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
97         // resourceDetails =
98         // ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC,
99         // NormativeTypesEnum.ROOT, ResourceCategoryEnum.NETWORK_L2_3_ROUTERS,
100         // adminUser);
101         // serviceDetails = ElementFactory.getDefaultService();
102         // serviceUniqueId = "svc_" + serviceDetails.getName().toLowerCase() + "." +
103         // serviceBaseVersion;
104         // artifactInterfaceType = "standard";
105         // artifactOperationName = "start";
106         // }
107
108         @BeforeMethod
109         public void setup() throws Exception {
110
111                 resourceBaseVersion = "0.1";
112                 serviceBaseVersion = "0.1";
113                 designerUser = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
114                 adminUser = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN);
115                 resourceDetails = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(ResourceTypeEnum.VFC,
116                                 NormativeTypesEnum.ROOT, ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, adminUser);
117                 serviceDetails = ElementFactory.getDefaultService();
118                 serviceUniqueId = "svc_" + serviceDetails.getName().toLowerCase() + "." + serviceBaseVersion;
119                 artifactInterfaceType = "standard";
120                 artifactOperationName = "start";
121                 consumerDataDefinition = createConsumer();
122                 RestResponse deleteResponse = ConsumerRestUtils.deleteConsumer(consumerDataDefinition, adminUser);
123                 BaseRestUtils.checkStatusCode(deleteResponse, "delete operation filed", false, 404, 200);
124
125                 RestResponse createResponse = ConsumerRestUtils.createConsumer(consumerDataDefinition, adminUser);
126                 BaseRestUtils.checkCreateResponse(createResponse);
127         }
128
129         @Test
130         public void downloadResourceArtifactSuccess() throws Exception {
131                 // Create service
132                 RestResponse serviceResponse = ServiceRestUtils.createService(serviceDetails, designerUser);
133                 AssertJUnit.assertEquals("Check response code after creating resource", 201,
134                                 serviceResponse.getErrorCode().intValue());
135
136                 // Create resource
137                 RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, designerUser);
138                 AssertJUnit.assertEquals("Check response code after creating resource", 201,
139                                 createResource.getErrorCode().intValue());
140                 Resource resource = ResponseParser.convertResourceResponseToJavaObject(createResource.getResponse());
141
142                 ArtifactReqDetails artifactDetails = ElementFactory
143                                 .getDefaultDeploymentArtifactForType(ArtifactTypeEnum.HEAT.getType());
144                 // Setting the name to be with space
145                 artifactDetails.setArtifactName("test artifact file.yaml");
146                 // artifactDetails.set(ArtifactRestUtils.calculateChecksum(artifactDetails));
147
148                 RestResponse addArtifactResponse = ArtifactRestUtils.addInformationalArtifactToResource(artifactDetails,
149                                 designerUser, resource.getUniqueId(), ArtifactRestUtils.calculateChecksum(artifactDetails));
150                 AssertJUnit.assertEquals("Check response code after adding interface artifact", 200,
151                                 addArtifactResponse.getErrorCode().intValue());
152
153                 // Getting expected artifact checksum
154                 ArtifactDefinition artifactResp = ResponseParser
155                                 .convertArtifactDefinitionResponseToJavaObject(addArtifactResponse.getResponse());
156                 String expectedPayloadChecksum = artifactResp.getArtifactChecksum();
157
158                 Config config = Utils.getConfig();
159                 String relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_RESOURCE_ARTIFACT_RELATIVE_URL,
160                                 ValidationUtils.convertToSystemName(serviceDetails.getName()), serviceBaseVersion,
161                                 ValidationUtils.convertToSystemName(resource.getName()), resource.getVersion(),
162                                 artifactResp.getArtifactName()));
163                 // String fullUrlFormatted =
164                 // String.format(Urls.DOWNLOAD_RESOURCE_ARTIFACT_FULL_URL,
165                 // config.getCatalogBeHost(),config.getCatalogBePort(), relativeUrl);
166                 // String consumerId = "dummy.ecomp";
167
168                 ResourceReqDetails resourceInfo = new ResourceReqDetails();
169                 resourceInfo.setName(resource.getName());
170                 resourceInfo.setVersion(resource.getVersion());
171
172                 Map<String, String> authorizationHeaders = new HashMap<String, String>();
173                 authorizationHeaders.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
174                 RestResponse restResponse = ArtifactRestUtils.downloadResourceArtifact(serviceDetails, resourceInfo,
175                                 artifactDetails, designerUser, authorizationHeaders);
176                 // RestResponse restResponse =
177                 // artifactUtils.downloadResourceArtifact(designerUser,fullUrlFormatted,
178                 // consumerId,true);
179                 AssertJUnit.assertEquals("Check response code after download resource", 200,
180                                 restResponse.getErrorCode().intValue());
181
182                 // Validating headers
183                 // content disposition
184                 List<String> contDispHeaderList = restResponse.getHeaderFields().get(Constants.CONTENT_DISPOSITION_HEADER);
185                 AssertJUnit.assertNotNull(contDispHeaderList);
186                 AssertJUnit
187                                 .assertEquals(
188                                                 "Check content disposition header", new StringBuilder().append("attachment; filename=\"")
189                                                                 .append(artifactResp.getArtifactName()).append("\"").toString(),
190                                                 contDispHeaderList.get(0));
191
192                 // content type
193                 List<String> contTypeHeaderList = restResponse.getHeaderFields().get(Constants.CONTENT_TYPE_HEADER);
194                 AssertJUnit.assertNotNull(contTypeHeaderList);
195                 AssertJUnit.assertEquals("Check content type", "application/octet-stream", contTypeHeaderList.get(0));
196
197                 String actualContents = restResponse.getResponse();
198
199                 // Contents - comparing decoded content
200                 AssertJUnit.assertEquals(artifactDetails.getPayload(), Base64.encodeBase64String(actualContents.getBytes()));
201
202                 // validating checksum
203                 String actualPayloadChecksum = GeneralUtility.calculateMD5Base64EncodedByByteArray(actualContents.getBytes());
204                 AssertJUnit.assertEquals(expectedPayloadChecksum, actualPayloadChecksum);
205
206                 // validate audit
207                 String auditAction = "DArtifactDownload";
208
209                 ExpectedDistDownloadAudit expectedDistDownloadAudit = new ExpectedDistDownloadAudit(auditAction,
210                                 BaseRestUtils.ecomp, relativeUrl, "200", "OK");
211                 AuditValidationUtils.validateAudit(expectedDistDownloadAudit, auditAction);
212         }
213
214         protected void download_serviceNameNotFound_inner(String serviceName, String serviceVersion, String resourceName,
215                         String resourceVersion) throws Exception {
216                 Config config = Utils.getConfig();
217                 String artifactName = "kuku";
218                 ArtifactReqDetails artifact = new ArtifactReqDetails();
219                 artifact.setArtifactName(artifactName);
220                 String relativeUrl;
221                 Map<String, String> authorizationHeaders = new HashMap<String, String>();
222                 authorizationHeaders.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
223                 ServiceReqDetails serviceInfo = new ServiceReqDetails();
224                 serviceInfo.setName(serviceName);
225                 serviceInfo.setVersion(serviceVersion);
226                 RestResponse restResponse = null;
227                 if (resourceName != null) {
228                         ResourceReqDetails resourceDetailes = new ResourceReqDetails();
229                         resourceDetailes.setName(resourceName);
230                         resourceDetailes.setVersion(resourceVersion);
231                         relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_RESOURCE_ARTIFACT_RELATIVE_URL,
232                                         ValidationUtils.convertToSystemName(serviceName), serviceVersion,
233                                         ValidationUtils.convertToSystemName(resourceName), resourceVersion, artifactName));
234                         restResponse = ArtifactRestUtils.downloadResourceArtifact(serviceInfo, resourceDetailes, artifact,
235                                         designerUser, authorizationHeaders);
236                 } else {
237                         relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_SERVICE_ARTIFACT_RELATIVE_URL,
238                                         ValidationUtils.convertToSystemName(serviceName), serviceVersion, artifactName));
239                         restResponse = ArtifactRestUtils.downloadServiceArtifact(serviceInfo, artifact, designerUser,
240                                         authorizationHeaders);
241                 }
242
243                 // RestResponse restResponse =
244                 // artifactUtils.downloadResourceArtifact(designerUser,fullUrlFormatted,
245                 // consumerId,true);
246                 AssertJUnit.assertEquals("Check response code after download resource", 404,
247                                 restResponse.getErrorCode().intValue());
248
249                 // validate audit
250                 String auditAction = "DArtifactDownload";
251
252                 ExpectedDistDownloadAudit expectedDistDownloadAudit = new ExpectedDistDownloadAudit(auditAction,
253                                 BaseRestUtils.ecomp, relativeUrl, "404", "SVC4503: Error: Requested '"
254                                                 + ValidationUtils.convertToSystemName(serviceName) + "' service was not found.");
255                 AuditValidationUtils.validateAudit(expectedDistDownloadAudit, auditAction);
256         }
257
258         protected void download_serviceVersionNotFound_inner(String serviceName, String serviceVersion, String resourceName,
259                         String resourceVersion) throws Exception {
260                 Config config = Utils.getConfig();
261                 String artifactName = "kuku";
262                 String relativeUrl;
263                 ArtifactReqDetails artifact = new ArtifactReqDetails();
264                 artifact.setArtifactName(artifactName);
265                 Map<String, String> authorizationHeaders = new HashMap<String, String>();
266                 authorizationHeaders.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
267                 ServiceReqDetails serviceInfo = new ServiceReqDetails();
268                 serviceInfo.setName(serviceName);
269                 serviceInfo.setVersion(serviceVersion);
270                 RestResponse restResponse = null;
271                 if (resourceName != null) {
272                         ResourceReqDetails resourceDetailes = new ResourceReqDetails();
273                         resourceDetailes.setName(resourceName);
274                         resourceDetailes.setVersion(resourceVersion);
275                         relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_RESOURCE_ARTIFACT_RELATIVE_URL,
276                                         ValidationUtils.convertToSystemName(serviceName), serviceVersion,
277                                         ValidationUtils.convertToSystemName(resourceName), resourceVersion, artifactName));
278                         restResponse = ArtifactRestUtils.downloadResourceArtifact(serviceInfo, resourceDetailes, artifact,
279                                         designerUser, authorizationHeaders);
280                 } else {
281                         relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_SERVICE_ARTIFACT_RELATIVE_URL,
282                                         ValidationUtils.convertToSystemName(serviceName), serviceVersion, artifactName));
283                         restResponse = ArtifactRestUtils.downloadServiceArtifact(serviceInfo, artifact, designerUser,
284                                         authorizationHeaders);
285                 }
286                 // String fullUrlFormatted =
287                 // String.format(Urls.DOWNLOAD_RESOURCE_ARTIFACT_FULL_URL,
288                 // config.getCatalogBeHost(),config.getCatalogBePort(), relativeUrl);
289                 // String consumerId = "dummy.ecomp";
290
291                 // RestResponse restResponse =
292                 // artifactUtils.downloadResourceArtifact(designerUser,fullUrlFormatted,
293                 // consumerId,true);
294                 AssertJUnit.assertEquals("Check response code after download resource", 404,
295                                 restResponse.getErrorCode().intValue());
296
297                 // validate audit
298                 String auditAction = "DArtifactDownload";
299
300                 ExpectedDistDownloadAudit expectedDistDownloadAudit = new ExpectedDistDownloadAudit(auditAction,
301                                 BaseRestUtils.ecomp, relativeUrl, "404",
302                                 "SVC4504: Error: Service version " + serviceVersion + " was not found.");
303                 AuditValidationUtils.validateAudit(expectedDistDownloadAudit, auditAction);
304         }
305
306         protected String encodeUrlForDownload(String url) {
307                 return url.replaceAll(" ", "%20");
308         }
309
310         protected ConsumerDataDefinition createConsumer() {
311                 ConsumerDataDefinition consumer = new ConsumerDataDefinition();
312                 consumer.setConsumerName(USER);
313                 consumer.setConsumerSalt(SALT);
314                 consumer.setConsumerPassword(HASHED_PASSWORD);
315                 return consumer;
316
317         }
318
319         @Test(enabled = true)
320         public void downloadServiceArtifactSuccess() throws Exception {
321                 // Create service
322                 RestResponse serviceResponse = ServiceRestUtils.createService(serviceDetails, designerUser);
323                 assertEquals("Check response code after creating resource", 201, serviceResponse.getErrorCode().intValue());
324                 serviceUniqueId = ResponseParser.convertServiceResponseToJavaObject(serviceResponse.getResponse())
325                                 .getUniqueId();
326
327                 ArtifactReqDetails artifactDetails = ElementFactory.getDefaultDeploymentArtifactForType("MURANO_PKG");
328
329                 RestResponse addArtifactResponse = ArtifactRestUtils.addInformationalArtifactToService(artifactDetails,
330                                 designerUser, serviceUniqueId, ArtifactRestUtils.calculateMD5Header(artifactDetails));
331                 assertEquals("Check response code after adding interface artifact", 200,
332                                 addArtifactResponse.getErrorCode().intValue());
333
334                 // Getting expected artifact checksum
335
336                 // ArtifactResJavaObject artifactResp =
337                 // artifactUtils.parseInformationalArtifactResp(addArtifactResponse);
338                 String expectedPayloadChecksum = ResponseParser
339                                 .convertArtifactDefinitionResponseToJavaObject(addArtifactResponse.getResponse()).getArtifactChecksum();
340
341                 String artifactName = ValidationUtils.normalizeFileName(artifactDetails.getArtifactName());
342
343                 String relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_SERVICE_ARTIFACT_RELATIVE_URL,
344                                 ValidationUtils.convertToSystemName(serviceDetails.getName()), serviceBaseVersion, artifactName));
345
346                 Map<String, String> authorizationHeaders = new HashMap<String, String>();
347                 authorizationHeaders.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
348                 RestResponse restResponse = ArtifactRestUtils.downloadServiceArtifact(serviceDetails, artifactDetails,
349                                 designerUser, authorizationHeaders);
350                 assertEquals("Check response code after download resource", 200, restResponse.getErrorCode().intValue());
351
352                 // Validating headers
353                 // content disposition
354                 List<String> contDispHeaderList = restResponse.getHeaderFields().get(Constants.CONTENT_DISPOSITION_HEADER);
355                 assertNotNull(contDispHeaderList);
356                 assertEquals("Check content disposition header",
357                                 new StringBuilder().append("attachment; filename=\"").append(artifactName).append("\"").toString(),
358                                 contDispHeaderList.get(0));
359
360                 // content type
361                 List<String> contTypeHeaderList = restResponse.getHeaderFields().get(Constants.CONTENT_TYPE_HEADER);
362                 assertNotNull(contTypeHeaderList);
363                 assertEquals("Check content type", "application/octet-stream", contTypeHeaderList.get(0));
364
365                 String actualContents = restResponse.getResponse();
366
367                 assertEquals(artifactDetails.getPayload(), Base64.encodeBase64String(actualContents.getBytes()));
368
369                 // validating checksum
370                 byte[] bytes = actualContents.getBytes();
371                 String actualPayloadChecksum = GeneralUtility.calculateMD5Base64EncodedByByteArray(bytes);
372                 assertEquals(expectedPayloadChecksum, actualPayloadChecksum);
373
374                 // validating valid zip
375                 InputStream is = new ByteArrayInputStream(bytes);
376                 InputStream zis = new ZipInputStream(is);
377                 zis.close();
378
379                 // validate audit
380                 String auditAction = "DArtifactDownload";
381
382                 ExpectedDistDownloadAudit expectedDistDownloadAudit = new ExpectedDistDownloadAudit(auditAction,
383                                 ResourceRestUtils.ecomp, encodeUrlForDownload(relativeUrl), "200", "OK");
384                 AuditValidationUtils.validateAudit(expectedDistDownloadAudit, auditAction);
385         }
386
387         @Test
388         public void downloadResourceArtifact_NoConsumerId() throws Exception {
389
390                 String artifactName = "kuku";
391                 ArtifactReqDetails artifact = new ArtifactReqDetails();
392                 artifact.setArtifactName(artifactName);
393                 ResourceReqDetails resource = new ResourceReqDetails();
394                 resource.setName("notExisting");
395                 resource.setVersion("0.1");
396                 String relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_RESOURCE_ARTIFACT_RELATIVE_URL,
397                                 ValidationUtils.convertToSystemName(serviceDetails.getName()), serviceBaseVersion,
398                                 ValidationUtils.convertToSystemName(resource.getName()), resource.getVersion(), artifactName));
399                 serviceDetails.setVersion("0.1");
400                 Map<String, String> authorizationHeaders = new HashMap<String, String>();
401                 authorizationHeaders.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
402                 RestResponse restResponse = ArtifactRestUtils.downloadResourceArtifact(serviceDetails, resource, artifact,
403                                 designerUser, authorizationHeaders, false);
404                 assertEquals("Check response code after download resource", 400, restResponse.getErrorCode().intValue());
405
406                 // validate audit
407                 String auditAction = "DArtifactDownload";
408
409                 ExpectedDistDownloadAudit expectedDistDownloadAudit = new ExpectedDistDownloadAudit(auditAction, "",
410                                 relativeUrl, "400", "POL5001: Error: Missing 'X-ECOMP-InstanceID' HTTP header.");
411                 AuditValidationUtils.validateAudit(expectedDistDownloadAudit, auditAction);
412         }
413
414         @Test
415         public void downloadResourceArtifact_ResourceNameNotFound() throws Exception {
416
417                 String artifactName = "kuku";
418                 ArtifactReqDetails artifact = new ArtifactReqDetails();
419                 artifact.setArtifactName(artifactName);
420                 ResourceReqDetails resource = new ResourceReqDetails();
421                 resource.setName("notExisting");
422                 resource.setVersion("0.1");
423                 serviceDetails.setVersion("0.1");
424                 String relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_RESOURCE_ARTIFACT_RELATIVE_URL,
425                                 ValidationUtils.convertToSystemName(serviceDetails.getName()), serviceDetails.getVersion(),
426                                 ValidationUtils.convertToSystemName(resource.getName()), resource.getVersion(), artifactName));
427
428                 Map<String, String> authorizationHeaders = new HashMap<String, String>();
429                 authorizationHeaders.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
430                 RestResponse restResponse = ArtifactRestUtils.downloadResourceArtifact(serviceDetails, resource, artifact,
431                                 designerUser, authorizationHeaders);
432
433                 assertEquals("Check response code after download resource", 404, restResponse.getErrorCode().intValue());
434
435                 // validate audit
436                 String auditAction = "DArtifactDownload";
437
438                 ExpectedDistDownloadAudit expectedDistDownloadAudit = new ExpectedDistDownloadAudit(auditAction,
439                                 BaseRestUtils.ecomp, relativeUrl, "404",
440                                 "SVC4063: Error: Requested 'Notexisting' resource was not found.");
441                 AuditValidationUtils.validateAudit(expectedDistDownloadAudit, auditAction);
442         }
443
444         @Test
445         public void downloadResourceArtifact_ResourceVersionNotFound() throws Exception {
446                 RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, designerUser);
447                 assertEquals("Check response code after creating resource", 201, createResource.getErrorCode().intValue());
448
449                 Resource resource = ResponseParser.convertResourceResponseToJavaObject(createResource.getResponse());
450                 ResourceReqDetails resourceDetailes = new ResourceReqDetails();
451                 resourceDetailes.setName(resource.getName());
452                 resourceDetailes.setVersion("0.2");
453
454                 serviceDetails.setVersion("0.1");
455
456                 String artifactName = "kuku";
457                 ArtifactReqDetails artifact = new ArtifactReqDetails();
458                 artifact.setArtifactName(artifactName);
459
460                 String relativeUrl = encodeUrlForDownload(String.format(Urls.DISTRIB_DOWNLOAD_RESOURCE_ARTIFACT_RELATIVE_URL,
461                                 ValidationUtils.convertToSystemName(serviceDetails.getName()), serviceBaseVersion,
462                                 ValidationUtils.convertToSystemName(resourceDetailes.getName()), resourceDetailes.getVersion(),
463                                 artifactName));
464
465                 Map<String, String> authorizationHeaders = new HashMap<String, String>();
466                 authorizationHeaders.put(HttpHeaderEnum.AUTHORIZATION.getValue(), authorizationHeader);
467                 RestResponse restResponse = ArtifactRestUtils.downloadResourceArtifact(serviceDetails, resourceDetailes,
468                                 artifact, designerUser, authorizationHeaders);
469                 assertEquals("Check response code after download resource", 404, restResponse.getErrorCode().intValue());
470
471                 // validate audit
472                 String auditAction = "DArtifactDownload";
473
474                 ExpectedDistDownloadAudit expectedDistDownloadAudit = new ExpectedDistDownloadAudit(auditAction,
475                                 BaseRestUtils.ecomp, relativeUrl, "404", "SVC4504: Error: Resource version 0.2 was not found.");
476                 AuditValidationUtils.validateAudit(expectedDistDownloadAudit, auditAction);
477         }
478
479         @Test
480         public void downloadResourceArtifact_ServiceNameNotFound() throws Exception {
481                 // Create resource
482                 RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, designerUser);
483                 assertEquals("Check response code after creating resource", 201, createResource.getErrorCode().intValue());
484                 Resource resource = ResponseParser.convertResourceResponseToJavaObject(createResource.getResponse());
485                 download_serviceNameNotFound_inner("notExistingServiceName", serviceBaseVersion, resource.getName(),
486                                 resource.getVersion());
487
488         }
489
490         @Test
491         public void downloadResourceArtifact_ServiceVersionNotFound() throws Exception {
492                 // Create resource
493                 RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, designerUser);
494                 assertEquals("Check response code after creating resource", 201, createResource.getErrorCode().intValue());
495                 Resource resource = ResponseParser.convertResourceResponseToJavaObject(createResource.getResponse());
496
497                 // Create service
498                 RestResponse serviceResponse = ServiceRestUtils.createService(serviceDetails, designerUser);
499                 assertEquals("Check response code after creating resource", 201, serviceResponse.getErrorCode().intValue());
500                 serviceUniqueId = ResponseParser.convertServiceResponseToJavaObject(serviceResponse.getResponse())
501                                 .getUniqueId();
502
503                 download_serviceVersionNotFound_inner(serviceDetails.getName(), "0.3", resource.getName(),
504                                 resource.getVersion());
505         }
506
507         @Test
508         public void downloadServiceArtifact_ServiceNameNotFound() throws Exception {
509                 download_serviceNameNotFound_inner("notExistingServiceName", serviceBaseVersion, null, null);
510
511         }
512
513         @Test
514         public void downloadServiceArtifact_ServiceVersionNotFound() throws Exception {
515
516                 // Create service
517                 RestResponse serviceResponse = ServiceRestUtils.createService(serviceDetails, designerUser);
518                 assertEquals("Check response code after creating resource", 201, serviceResponse.getErrorCode().intValue());
519                 serviceUniqueId = ResponseParser.convertServiceResponseToJavaObject(serviceResponse.getResponse())
520                                 .getUniqueId();
521
522                 download_serviceVersionNotFound_inner(serviceDetails.getName(), "0.2", null, null);
523         }
524
525 }