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