2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.ci.tests.execute.imports;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
27 import java.io.ByteArrayInputStream;
28 import java.io.IOException;
29 import java.io.InputStream;
31 import java.util.zip.ZipEntry;
32 import java.util.zip.ZipInputStream;
34 import org.apache.commons.codec.binary.Base64;
35 import org.junit.Rule;
36 import org.junit.rules.TestName;
37 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
38 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
39 import org.openecomp.sdc.be.model.ArtifactDefinition;
40 import org.openecomp.sdc.be.model.ArtifactUiDownloadData;
41 import org.openecomp.sdc.be.model.Component;
42 import org.openecomp.sdc.be.model.Resource;
43 import org.openecomp.sdc.be.model.Service;
44 import org.openecomp.sdc.be.model.User;
45 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
46 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
47 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
48 import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
49 import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum;
50 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
51 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
52 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
53 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
54 import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils;
55 import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
56 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
57 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
58 import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils;
59 import org.openecomp.sdc.common.util.YamlToObjectConverter;
60 import org.testng.annotations.Test;
61 import org.yaml.snakeyaml.Yaml;
63 public class CsarUtilsTest extends ComponentBaseTest {
65 public static final String ASSET_TOSCA_TEMPLATE = "assettoscatemplate";
68 public static TestName name = new TestName();
70 public CsarUtilsTest() {
71 super(name, CsarUtilsTest.class.getName());
75 public void createServiceCsarBasicTest() throws Exception {
77 Service service = AtomicOperationUtils.createDefaultService(UserRoleEnum.DESIGNER, true).left().value();
79 Resource resourceVF = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
81 AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.VENDOR_LICENSE, resourceVF, UserRoleEnum.DESIGNER,
83 resourceVF = (Resource) AtomicOperationUtils
84 .changeComponentState(resourceVF, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
86 AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceVF, service, UserRoleEnum.DESIGNER, true);
88 service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
90 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
92 byte[] downloadCSAR = downloadCSAR(sdncModifierDetails, service);
94 csarBasicValidation(service, downloadCSAR);
98 public void createResourceCsarBasicTest() throws Exception {
100 Resource resourceVF = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
101 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
103 resourceVF = (Resource) AtomicOperationUtils
104 .changeComponentState(resourceVF, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
106 byte[] downloadCSAR = downloadCSAR(sdncModifierDetails, resourceVF);
108 csarBasicValidation(resourceVF, downloadCSAR);
110 validateVFCsar(resourceVF, downloadCSAR, 1, 0, 0, 0, 0, 0, 0);
115 @Test(enabled = true)
116 public void createServiceCsarInclDeploymentArtTest() throws Exception {
118 Service service = AtomicOperationUtils.createDefaultService(UserRoleEnum.DESIGNER, true).left().value();
120 Resource resourceVF1 = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
121 Resource resourceVF2 = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
123 resourceVF1 = (Resource) AtomicOperationUtils
124 .changeComponentState(resourceVF1, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
126 resourceVF2 = (Resource) AtomicOperationUtils
127 .changeComponentState(resourceVF2, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
129 AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceVF1, service, UserRoleEnum.DESIGNER, true);
130 AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceVF2, service, UserRoleEnum.DESIGNER, true);
132 AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.YANG_XML, service, UserRoleEnum.DESIGNER, true, true);
134 service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
136 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
138 byte[] downloadCSAR = downloadCSAR(sdncModifierDetails, service);
140 csarBasicValidation(service, downloadCSAR);
142 validateServiceCsar(resourceVF1, resourceVF2, service, downloadCSAR, 3, 3, 1, 0);
145 @Test(enabled = true)
146 public void createResourceCsarInclDeploymentArtTest() throws Exception {
148 Resource resourceVF1 = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
151 AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.YANG_XML, resourceVF1, UserRoleEnum.DESIGNER, true, true);
152 AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.HEAT_ARTIFACT, resourceVF1, UserRoleEnum.DESIGNER, true, true);
154 resourceVF1 = (Resource) AtomicOperationUtils
155 .changeComponentState(resourceVF1, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
157 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
159 byte[] downloadCSAR = downloadCSAR(sdncModifierDetails, resourceVF1);
161 csarBasicValidation(resourceVF1, downloadCSAR);
163 validateVFCsar(resourceVF1, downloadCSAR, 1, 0, 1, 1, 0, 0, 0);
166 @Test(enabled = true)
167 public void createResourceCsarInclInformationalArtTest() throws Exception {
169 Resource resourceVF1 = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
171 AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.YANG_XML, resourceVF1, UserRoleEnum.DESIGNER, false, true);
172 AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.HEAT, resourceVF1, UserRoleEnum.DESIGNER, false, true);
174 resourceVF1 = (Resource) AtomicOperationUtils
175 .changeComponentState(resourceVF1, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
177 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
179 byte[] downloadCSAR = downloadCSAR(sdncModifierDetails, resourceVF1);
181 csarBasicValidation(resourceVF1, downloadCSAR);
183 validateVFCsar(resourceVF1, downloadCSAR, 1, 0, 0, 0, 1, 1, 0);
186 @Test(enabled = true)
187 public void createServiceCsarNotMandatoryMetadataFieldsTest() throws Exception {
189 Service service = AtomicOperationUtils.createDefaultService(UserRoleEnum.DESIGNER, true).left().value();
190 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
192 service.setServiceType("serviceTypeTest");
193 service.setServiceRole("serviceRoleTest");
194 ServiceRestUtils.updateService(new ServiceReqDetails(service), sdncModifierDetails);
196 Resource resourceVF1 = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
197 Resource resourceVF2 = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
199 resourceVF1 = (Resource) AtomicOperationUtils
200 .changeComponentState(resourceVF1, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
202 resourceVF2 = (Resource) AtomicOperationUtils
203 .changeComponentState(resourceVF2, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
205 AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceVF1, service, UserRoleEnum.DESIGNER, true);
206 AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceVF2, service, UserRoleEnum.DESIGNER, true);
208 service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
210 byte[] downloadCSAR = downloadCSAR(sdncModifierDetails, service);
212 csarBasicValidation(service, downloadCSAR);
214 validateServiceCsar(resourceVF1, resourceVF2, service, downloadCSAR, 3, 3, 0, 0);
217 @Test(enabled = true)
218 public void createResourceCsarNotMandatoryMetadataFieldsTest() throws Exception {
220 Resource resourceVF = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
221 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
223 resourceVF.setResourceVendorModelNumber("modelNumberTest");
224 ResourceRestUtils.updateResourceMetadata(new ResourceReqDetails(resourceVF), sdncModifierDetails, resourceVF.getUniqueId());
226 resourceVF = (Resource) AtomicOperationUtils
227 .changeComponentState(resourceVF, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
229 byte[] downloadCSAR = downloadCSAR(sdncModifierDetails, resourceVF);
231 csarBasicValidation(resourceVF, downloadCSAR);
233 validateVFCsar(resourceVF, downloadCSAR, 1, 0, 0, 0, 0, 0, 0);
239 private void csarBasicValidation(Component mainComponent, byte[] downloadCSAR) {
240 try (ByteArrayInputStream ins = new ByteArrayInputStream(downloadCSAR);
241 ZipInputStream zip = new ZipInputStream(ins);) {
243 String resourceYaml = null;
244 byte[] buffer = new byte[1024];
245 ZipEntry nextEntry = zip.getNextEntry();
246 StringBuffer sb = new StringBuffer();
249 while ((len = zip.read(buffer)) > 0) {
250 sb.append(new String(buffer, 0, len));
252 assertTrue(nextEntry.getName().equals("csar.meta"));
254 readNextEntry(sb, len, buffer, zip);
256 nextEntry = zip.getNextEntry();
257 assertTrue(nextEntry.getName().equals("TOSCA-Metadata/TOSCA.meta"));
259 readNextEntry(sb, len, buffer, zip);
260 nextEntry = zip.getNextEntry();
261 resourceYaml = sb.toString();
263 YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
264 ArtifactDefinition artifactDefinition = mainComponent.getToscaArtifacts().get(ASSET_TOSCA_TEMPLATE);
265 String fileName = artifactDefinition.getArtifactName();
266 assertEquals("Tosca-Template file name: ", "Definitions/" + fileName, nextEntry.getName());
267 assertTrue("Tosca template Yaml validation: ", yamlToObjectConverter.isValidYaml(resourceYaml.getBytes()));
271 } catch (IOException e) {
276 private void validateServiceCsar(Component certifiedVFC1, Component certifiedVFC2, Service fetchedService,
277 byte[] resultByte, int toscaEntryIndexToPass, int generatorEntryIndexToPass,
278 int deploymentArtifactIndexToPass, int informationalArtifactIndexToPass) {
280 // TODO Test to validate everything is right (comment out after testing)
282 FileUtils.writeByteArrayToFile(new File("c:/TestCSAR/" + fetchedService.getName() + ".zip"), resultByte);
283 } catch (IOException e) {
284 // Auto-generated catch block
288 try (ByteArrayInputStream ins = new ByteArrayInputStream(resultByte);
289 ZipInputStream zip = new ZipInputStream(ins);) {
291 String resourceYaml = null;
292 byte[] buffer = new byte[1024];
293 ZipEntry nextEntry = zip.getNextEntry();
294 StringBuffer sb = new StringBuffer();
297 while ((len = zip.read(buffer)) > 0) {
298 sb.append(new String(buffer, 0, len));
300 assertTrue(nextEntry.getName().equals("csar.meta"));
301 readNextEntry(sb, len, buffer, zip);
302 nextEntry = zip.getNextEntry();
303 assertTrue(nextEntry.getName().equals("TOSCA-Metadata/TOSCA.meta"));
304 readNextEntry(sb, len, buffer, zip);
307 YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
309 int toscaEntryIndex = 0;
310 int generatorEntryIndex = 0;
311 int deploymentArtifactIndex = 0;
312 int informationalArtifactIndex = 0;
313 String fileName = null;
314 ArtifactDefinition artifactDefinition;
315 Component componentToValidate = null;
317 artifactDefinition = fetchedService.getToscaArtifacts().get(ASSET_TOSCA_TEMPLATE);
318 String serviceFileName = artifactDefinition.getArtifactName();
319 artifactDefinition = certifiedVFC1.getToscaArtifacts().get(ASSET_TOSCA_TEMPLATE);
320 String vfc1FileName = artifactDefinition.getArtifactName();
321 artifactDefinition = certifiedVFC2.getToscaArtifacts().get(ASSET_TOSCA_TEMPLATE);
322 String vfc2FileName = artifactDefinition.getArtifactName();
324 while ((nextEntry = zip.getNextEntry()) != null) {
327 while ((len = zip.read(buffer)) > 0) {
328 sb.append(new String(buffer, 0, len));
331 String entryName = nextEntry.getName();
333 resourceYaml = sb.toString();
334 if (entryName.contains(serviceFileName)) {
335 componentToValidate = fetchedService;
336 fileName = "Definitions/" + serviceFileName;
338 assertEquals("Validate entry Name", (fileName), nextEntry.getName());
339 assertTrue(yamlToObjectConverter.isValidYaml(resourceYaml.getBytes()));
340 validateContent(resourceYaml, componentToValidate);
345 if (entryName.contains(vfc1FileName)) {
346 componentToValidate = certifiedVFC1;
347 fileName = "Definitions/" + vfc1FileName;
349 assertEquals("Validate entry Name", (fileName), nextEntry.getName());
350 assertTrue(yamlToObjectConverter.isValidYaml(resourceYaml.getBytes()));
351 validateContent(resourceYaml, componentToValidate);
355 if (entryName.contains(vfc2FileName)) {
356 componentToValidate = certifiedVFC2;
357 fileName = "Definitions/" + vfc2FileName;
359 assertEquals("Validate entry Name", (fileName), nextEntry.getName());
360 assertTrue(yamlToObjectConverter.isValidYaml(resourceYaml.getBytes()));
361 validateContent(resourceYaml, componentToValidate);
366 if (entryName.startsWith("Artifacts/Deployment/MODEL_INVENTORY_PROFILE") && entryName.contains("AAI")) {
367 ++generatorEntryIndex;
371 if (entryName.contains(".xml") && entryName.startsWith("Artifacts/Deployment/") && !entryName.contains("AAI")) {
372 ++deploymentArtifactIndex;
376 if (entryName.contains(".xml") && entryName.startsWith("Artifacts/Informational/") && !entryName.contains("AAI")) {
377 ++informationalArtifactIndex;
381 assertTrue("Unexpected entry: " + entryName, true);
383 assertEquals("Validate amount of entries", toscaEntryIndexToPass, toscaEntryIndex);
384 assertEquals("Validate amount of generated AAI artifacts", generatorEntryIndexToPass, generatorEntryIndex);
385 assertEquals("Validate amount of Deployment artifacts entries", deploymentArtifactIndexToPass,
386 deploymentArtifactIndex);
387 assertEquals("Validate amount of Informational artifacts entries", informationalArtifactIndexToPass,
388 informationalArtifactIndex);
392 } catch (IOException e) {
397 private void validateVFCsar(Component certifiedVF, byte[] resultByte, int toscaEntryIndexToPass,
398 int ymlDeploymentArtifactIndexToPass, int xmlDeploymentArtifactIndexToPass, int heatDeploymentArtifactIndexToPass,
399 int ymlInformationalArtifactIndexToPass, int xmlInformationalArtifactIndexToPass, int heatInformationalArtifactIndexToPass) {
401 // TODO Test to validate everything is right (comment out after testing)
403 FileUtils.writeByteArrayToFile(new File("c:/TestCSAR/" + fetchedService.getName() + ".zip"), resultByte);
404 } catch (IOException e) {
405 // Auto-generated catch block
409 try (ByteArrayInputStream ins = new ByteArrayInputStream(resultByte);
410 ZipInputStream zip = new ZipInputStream(ins);) {
412 String resourceYaml = null;
413 byte[] buffer = new byte[1024];
414 ZipEntry nextEntry = zip.getNextEntry();
415 StringBuffer sb = new StringBuffer();
418 while ((len = zip.read(buffer)) > 0) {
419 sb.append(new String(buffer, 0, len));
422 assertTrue(nextEntry.getName().equals("csar.meta"));
424 readNextEntry(sb, len, buffer, zip);
425 nextEntry = zip.getNextEntry();
426 assertTrue(nextEntry.getName().equals("TOSCA-Metadata/TOSCA.meta"));
428 readNextEntry(sb, len, buffer, zip);
430 YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
432 int toscaEntryIndex = 0;
433 int ymlDeploymentArtifactsIndex = 0;
434 int xmlDeploymentArtifactsIndex = 0;
435 int heatDeploymentArtifactIndex = 0;
436 int ymlInformationalArtifactsIndex = 0;
437 int xmlInformationalArtifactsIndex = 0;
438 int heatInformationalArtifactIndex = 0;
439 String fileName = null;
440 ArtifactDefinition artifactDefinition;
441 Component componentToValidate = null;
443 artifactDefinition = certifiedVF.getToscaArtifacts().get(ASSET_TOSCA_TEMPLATE);
444 String vfFileName = artifactDefinition.getArtifactName();
446 while ((nextEntry = zip.getNextEntry()) != null) {
448 readNextEntry(sb, len, buffer, zip);
450 String entryName = nextEntry.getName();
452 resourceYaml = sb.toString();
453 if (entryName.contains(vfFileName)) {
454 componentToValidate = certifiedVF;
455 fileName = "Definitions/" + vfFileName;
457 assertEquals("Validate entry Name", (fileName), nextEntry.getName());
458 assertTrue(yamlToObjectConverter.isValidYaml(resourceYaml.getBytes()));
459 validateContent(resourceYaml, componentToValidate);
464 if (entryName.contains(".xml") && entryName.contains("YANG_XML")) {
465 if(entryName.startsWith("Artifacts/Deployment")){
466 ++xmlDeploymentArtifactsIndex;
468 }else if(entryName.startsWith("Artifacts/Informational")){
469 ++xmlInformationalArtifactsIndex;
474 if (entryName.contains(".sh") && entryName.contains("HEAT_ARTIFACT")) {
475 if(entryName.startsWith("Artifacts/Deployment")){
476 ++heatDeploymentArtifactIndex;
478 }else if(entryName.startsWith("Artifacts/Informational")){
479 ++heatInformationalArtifactIndex;
484 if ((entryName.contains(".yml") || entryName.contains(".yaml")) && entryName.contains("HEAT")) {
485 if(entryName.startsWith("Artifacts/Deployment")){
486 ++ymlDeploymentArtifactsIndex;
488 }else if(entryName.startsWith("Artifacts/Informational")){
489 ++ymlInformationalArtifactsIndex;
494 if(entryName.contains("Definitions/") && entryName.contains("template-interface.yml")){
495 validateInterfaceContent(resourceYaml, certifiedVF);
498 if(entryName.contains("Definitions/")) {
499 if(isImportsFileValidation(entryName))
503 assertTrue("Unexpected entry: " + entryName, false);
507 assertEquals("Validate amount of entries", toscaEntryIndexToPass, toscaEntryIndex);
510 assertEquals("Validate amount of YAML Deployment artifacts", ymlDeploymentArtifactIndexToPass, ymlDeploymentArtifactsIndex);
511 assertEquals("Validate amount of XML Deployment artifacts", xmlDeploymentArtifactIndexToPass,
512 xmlDeploymentArtifactsIndex);
513 assertEquals("Validate amount of HEAT Deployment artifacts", heatDeploymentArtifactIndexToPass,
514 heatDeploymentArtifactIndex);
516 //Informational folder
517 assertEquals("Validate amount of YAML Informational artifacts", ymlInformationalArtifactIndexToPass, ymlInformationalArtifactsIndex);
518 assertEquals("Validate amount of XML Informational artifacts", xmlInformationalArtifactIndexToPass,
519 xmlInformationalArtifactsIndex);
520 assertEquals("Validate amount of HEAT Informational artifacts", heatInformationalArtifactIndexToPass,
521 heatInformationalArtifactIndex);
525 } catch (IOException e) {
530 private void validateContent(String content, Component component) {
531 Yaml yaml = new Yaml();
533 InputStream inputStream = new ByteArrayInputStream(content.getBytes());
534 @SuppressWarnings("unchecked")
535 Map<String, Object> load = (Map<String, Object>) yaml.load(inputStream);
536 @SuppressWarnings("unchecked")
537 Map<String, Object> metadata = (Map<String, Object>) load.get("metadata");
538 assertNotNull(metadata);
540 String name = (String) metadata.get("name");
542 assertEquals("Validate component name", component.getName(), name);
544 String invariantUUID = (String) metadata.get("invariantUUID");
545 assertNotNull(invariantUUID);
546 assertEquals("Validate component invariantUUID", component.getInvariantUUID(), invariantUUID);
548 String UUID = (String) metadata.get("UUID");
550 assertEquals("Validate component UUID", component.getUUID(), UUID);
552 String type = (String) metadata.get("type");
554 if (component.getComponentType().equals(ComponentTypeEnum.SERVICE)) {
555 assertEquals("Validate component type", component.getComponentType().getValue(), type);
556 String serviceType = (String) metadata.get("serviceType");
557 assertNotNull(serviceType);
558 assertEquals("Validate service type", ((Service )component).getServiceType(), serviceType);
559 String serviceRole = (String) metadata.get("serviceRole");
560 assertNotNull(serviceRole);
561 assertEquals("Validate service role", ((Service )component).getServiceRole(), serviceRole);
563 assertEquals("Validate component type", ((Resource) component).getResourceType(),
564 ResourceTypeEnum.valueOf(type));
565 String resourceVendorModelNumber = (String) metadata.get("resourceVendorModelNumber");
566 assertNotNull(resourceVendorModelNumber);
567 assertEquals("Validate resource vendor model number", ((Resource )component).getResourceVendorModelNumber(), resourceVendorModelNumber);
571 private byte[] downloadCSAR(User sdncModifierDetails, Component createdComponent) throws Exception {
573 String artifactUniqeId = createdComponent.getToscaArtifacts().get("assettoscacsar").getUniqueId();
574 RestResponse getCsarResponse = null;
576 switch (createdComponent.getComponentType()) {
578 getCsarResponse = ArtifactRestUtils.downloadResourceArtifactInternalApi(createdComponent.getUniqueId(),
579 sdncModifierDetails, artifactUniqeId);
582 getCsarResponse = ArtifactRestUtils.downloadServiceArtifactInternalApi(createdComponent.getUniqueId(),
583 sdncModifierDetails, artifactUniqeId);
589 assertNotNull(getCsarResponse);
590 BaseRestUtils.checkSuccess(getCsarResponse);
592 ArtifactUiDownloadData artifactUiDownloadData = ResponseParser.parseToObject(getCsarResponse.getResponse(),
593 ArtifactUiDownloadData.class);
595 assertNotNull(artifactUiDownloadData);
597 byte[] fromUiDownload = artifactUiDownloadData.getBase64Contents().getBytes();
598 byte[] decodeBase64 = Base64.decodeBase64(fromUiDownload);
603 private void validateInterfaceContent(String content, Component component) {
604 Yaml yaml = new Yaml();
606 InputStream inputStream = new ByteArrayInputStream(content.getBytes());
607 @SuppressWarnings("unchecked")
608 Map<String, Object> load = (Map<String, Object>) yaml.load(inputStream);
609 @SuppressWarnings("unchecked")
610 Map<String, Object> node_types = (Map<String, Object>) load.get("node_types");
611 assertNotNull(node_types);
613 String toscaInterfaceName = node_types.keySet().stream().filter(p -> p.startsWith("org.openecomp.")).findAny().get();
614 Map<String, Object> toscaInterface = (Map<String, Object>) node_types.get(toscaInterfaceName);
615 assertNotNull(toscaInterface);
616 String derived_from = (String) toscaInterface.get("derived_from");
617 assertNotNull(derived_from);
618 assertEquals("Validate derived from generic", component.getDerivedFromGenericType(), derived_from);
622 private void readNextEntry(StringBuffer sb, int len, byte[] buffer, ZipInputStream zip) throws IOException {
625 while ((len = zip.read(buffer)) > 0) {
626 sb.append(new String(buffer, 0, len));
630 private boolean isImportsFileValidation(String fileName) {
633 case "Definitions/artifacts.yml":
634 case "Definitions/capabilities.yml":
635 case "Definitions/data.yml":
636 case "Definitions/groups.yml":
637 case "Definitions/interfaces.yml":
638 case "Definitions/nodes.yml":
639 case "Definitions/policies.yml":
640 case "Definitions/relationships.yml":