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