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