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