[SDC] rebase 1710 code
[sdc.git] / asdc-tests / src / main / java / org / openecomp / sdc / ci / tests / execute / imports / CsarUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.ci.tests.execute.imports;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26
27 import java.io.ByteArrayInputStream;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.util.Map;
31 import java.util.zip.ZipEntry;
32 import java.util.zip.ZipInputStream;
33
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;
62
63 public class CsarUtilsTest extends ComponentBaseTest {
64         
65         public static final String ASSET_TOSCA_TEMPLATE = "assettoscatemplate";
66         
67         @Rule
68         public static TestName name = new TestName();
69         
70         public CsarUtilsTest() {
71                 super(name, CsarUtilsTest.class.getName());
72         }
73         
74         @Test(enabled = true)
75         public void createServiceCsarBasicTest() throws Exception {
76                 
77                 Service service = AtomicOperationUtils.createDefaultService(UserRoleEnum.DESIGNER, true).left().value();
78
79                 Resource resourceVF = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
80                 
81                 AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.VENDOR_LICENSE, resourceVF, UserRoleEnum.DESIGNER,
82                                 true, true);
83                 resourceVF = (Resource) AtomicOperationUtils
84                                 .changeComponentState(resourceVF, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
85                 
86                 AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceVF, service, UserRoleEnum.DESIGNER, true);
87                 
88                 service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
89                 
90                 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
91                 
92                 byte[] downloadCSAR = downloadCSAR(sdncModifierDetails, service);
93                 
94                 csarBasicValidation(service, downloadCSAR);
95         }
96         
97         @Test(enabled = true)
98         public void createResourceCsarBasicTest() throws Exception {
99
100                 Resource resourceVF = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
101                 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
102                                 
103                 resourceVF = (Resource) AtomicOperationUtils
104                                 .changeComponentState(resourceVF, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
105                 
106                 byte[] downloadCSAR = downloadCSAR(sdncModifierDetails, resourceVF);
107                 
108                 csarBasicValidation(resourceVF, downloadCSAR);
109                 
110                 validateVFCsar(resourceVF, downloadCSAR, 1, 0, 0, 0, 0, 0, 0);
111
112                 
113         }
114         
115         @Test(enabled = true)
116         public void createServiceCsarInclDeploymentArtTest() throws Exception {
117                 
118                 Service service = AtomicOperationUtils.createDefaultService(UserRoleEnum.DESIGNER, true).left().value();
119
120                 Resource resourceVF1 = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
121                 Resource resourceVF2 = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
122                 
123                 resourceVF1 = (Resource) AtomicOperationUtils
124                                 .changeComponentState(resourceVF1, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
125                 
126                 resourceVF2 = (Resource) AtomicOperationUtils
127                                 .changeComponentState(resourceVF2, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
128                 
129                 AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceVF1, service, UserRoleEnum.DESIGNER, true);
130                 AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceVF2, service, UserRoleEnum.DESIGNER, true);
131                 
132                 AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.YANG_XML, service, UserRoleEnum.DESIGNER, true, true);
133                 
134                 service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
135                 
136                 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
137                 
138                 byte[] downloadCSAR = downloadCSAR(sdncModifierDetails, service);
139                 
140                 csarBasicValidation(service, downloadCSAR);
141                 
142                 validateServiceCsar(resourceVF1, resourceVF2, service, downloadCSAR, 3, 3, 1, 0);
143         }
144         
145         @Test(enabled = true)
146         public void createResourceCsarInclDeploymentArtTest() throws Exception {
147
148                 Resource resourceVF1 = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
149                 
150                 
151                 AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.YANG_XML, resourceVF1, UserRoleEnum.DESIGNER, true, true);
152                 AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.HEAT_ARTIFACT, resourceVF1, UserRoleEnum.DESIGNER, true, true);
153                 
154                 resourceVF1 = (Resource) AtomicOperationUtils
155                                 .changeComponentState(resourceVF1, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
156
157                 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
158                 
159                 byte[] downloadCSAR = downloadCSAR(sdncModifierDetails, resourceVF1);
160                 
161                 csarBasicValidation(resourceVF1, downloadCSAR);
162                 
163                 validateVFCsar(resourceVF1, downloadCSAR, 1, 0, 1, 1, 0, 0, 0);
164         }
165         
166         @Test(enabled = true)
167         public void createResourceCsarInclInformationalArtTest() throws Exception {
168
169                 Resource resourceVF1 = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
170
171                 AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.YANG_XML, resourceVF1, UserRoleEnum.DESIGNER, false, true);
172                 AtomicOperationUtils.uploadArtifactByType(ArtifactTypeEnum.HEAT, resourceVF1, UserRoleEnum.DESIGNER, false, true);
173                 
174                 resourceVF1 = (Resource) AtomicOperationUtils
175                                 .changeComponentState(resourceVF1, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
176
177                 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
178                 
179                 byte[] downloadCSAR = downloadCSAR(sdncModifierDetails, resourceVF1);
180                 
181                 csarBasicValidation(resourceVF1, downloadCSAR);
182                 
183                 validateVFCsar(resourceVF1, downloadCSAR, 1, 0, 0, 0, 1, 1, 0);
184         }
185         
186         @Test(enabled = true)
187         public void createServiceCsarNotMandatoryMetadataFieldsTest() throws Exception {
188                 
189                 Service service = AtomicOperationUtils.createDefaultService(UserRoleEnum.DESIGNER, true).left().value();
190                 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
191
192                 service.setServiceType("serviceTypeTest");
193                 service.setServiceRole("serviceRoleTest");
194                 ServiceRestUtils.updateService(new ServiceReqDetails(service), sdncModifierDetails);
195
196                 Resource resourceVF1 = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
197                 Resource resourceVF2 = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
198                 
199                 resourceVF1 = (Resource) AtomicOperationUtils
200                                 .changeComponentState(resourceVF1, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
201                 
202                 resourceVF2 = (Resource) AtomicOperationUtils
203                                 .changeComponentState(resourceVF2, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
204                 
205                 AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceVF1, service, UserRoleEnum.DESIGNER, true);
206                 AtomicOperationUtils.addComponentInstanceToComponentContainer(resourceVF2, service, UserRoleEnum.DESIGNER, true);
207                                 
208                 service = (Service) AtomicOperationUtils.changeComponentState(service, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
209                                 
210                 byte[] downloadCSAR = downloadCSAR(sdncModifierDetails, service);
211                 
212                 csarBasicValidation(service, downloadCSAR);
213                 
214                 validateServiceCsar(resourceVF1, resourceVF2, service, downloadCSAR, 3, 3, 0, 0);
215         }
216
217         @Test(enabled = true)
218         public void createResourceCsarNotMandatoryMetadataFieldsTest() throws Exception {
219
220                 Resource resourceVF = AtomicOperationUtils.createResourceByType(ResourceTypeEnum.VF, UserRoleEnum.DESIGNER, true).left().value();
221                 User sdncModifierDetails = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
222                 
223                 resourceVF.setResourceVendorModelNumber("modelNumberTest");
224                 ResourceRestUtils.updateResourceMetadata(new ResourceReqDetails(resourceVF), sdncModifierDetails, resourceVF.getUniqueId());
225                 
226                 resourceVF = (Resource) AtomicOperationUtils
227                                 .changeComponentState(resourceVF, UserRoleEnum.DESIGNER, LifeCycleStatesEnum.CERTIFY, true).getLeft();
228                 
229                 byte[] downloadCSAR = downloadCSAR(sdncModifierDetails, resourceVF);
230                 
231                 csarBasicValidation(resourceVF, downloadCSAR);
232                 
233                 validateVFCsar(resourceVF, downloadCSAR, 1, 0, 0, 0, 0, 0, 0);
234
235                 
236         }
237
238         
239         private void csarBasicValidation(Component mainComponent, byte[] downloadCSAR) {
240                 try (ByteArrayInputStream ins = new ByteArrayInputStream(downloadCSAR);
241                                 ZipInputStream zip = new ZipInputStream(ins);) {
242
243                         String resourceYaml = null;
244                         byte[] buffer = new byte[1024];
245                         ZipEntry nextEntry = zip.getNextEntry();
246                         StringBuffer sb = new StringBuffer();
247                         int len;
248
249                         while ((len = zip.read(buffer)) > 0) {
250                                 sb.append(new String(buffer, 0, len));
251                         }
252                         assertTrue(nextEntry.getName().equals("csar.meta"));
253
254                         readNextEntry(sb, len, buffer, zip);
255
256                         nextEntry = zip.getNextEntry();
257                         assertTrue(nextEntry.getName().equals("TOSCA-Metadata/TOSCA.meta"));
258                         
259                         readNextEntry(sb, len, buffer, zip);
260                         nextEntry = zip.getNextEntry();
261                         resourceYaml = sb.toString();
262
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()));
268
269                         ins.close();
270                         zip.close();
271                 } catch (IOException e) {
272                         e.printStackTrace();
273                 }
274         }
275         
276         private void validateServiceCsar(Component certifiedVFC1, Component certifiedVFC2, Service fetchedService,
277                         byte[] resultByte, int toscaEntryIndexToPass, int generatorEntryIndexToPass,
278                         int deploymentArtifactIndexToPass, int informationalArtifactIndexToPass) {
279                 
280                 // TODO Test to validate everything is right (comment out after testing)
281                 /*try {
282                         FileUtils.writeByteArrayToFile(new File("c:/TestCSAR/" + fetchedService.getName() + ".zip"), resultByte);
283                 } catch (IOException e) {
284                         // Auto-generated catch block
285                         e.printStackTrace();
286                 }*/
287
288                 try (ByteArrayInputStream ins = new ByteArrayInputStream(resultByte);
289                                 ZipInputStream zip = new ZipInputStream(ins);) {
290                         
291                         String resourceYaml = null;
292                         byte[] buffer = new byte[1024];
293                         ZipEntry nextEntry = zip.getNextEntry();
294                         StringBuffer sb = new StringBuffer();
295                         int len;
296
297                         while ((len = zip.read(buffer)) > 0) {
298                                 sb.append(new String(buffer, 0, len));
299                         }
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);
305
306
307                         YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
308
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;
316
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();
323
324                         while ((nextEntry = zip.getNextEntry()) != null) {
325                                 sb.setLength(0);
326
327                                 while ((len = zip.read(buffer)) > 0) {
328                                         sb.append(new String(buffer, 0, len));
329                                 }
330
331                                 String entryName = nextEntry.getName();
332
333                                 resourceYaml = sb.toString();
334                                 if (entryName.contains(serviceFileName)) {
335                                         componentToValidate = fetchedService;
336                                         fileName = "Definitions/" + serviceFileName;
337                                         
338                                         assertEquals("Validate entry Name", (fileName), nextEntry.getName());
339                                         assertTrue(yamlToObjectConverter.isValidYaml(resourceYaml.getBytes()));
340                                         validateContent(resourceYaml, componentToValidate);
341                                         ++toscaEntryIndex;
342                                         continue;
343                                 }
344                                 
345                                 if (entryName.contains(vfc1FileName)) {
346                                         componentToValidate = certifiedVFC1;
347                                         fileName = "Definitions/" + vfc1FileName;
348                                         
349                                         assertEquals("Validate entry Name", (fileName), nextEntry.getName());
350                                         assertTrue(yamlToObjectConverter.isValidYaml(resourceYaml.getBytes()));
351                                         validateContent(resourceYaml, componentToValidate);
352                                         ++toscaEntryIndex;
353                                         continue;
354                                 }
355                                 if (entryName.contains(vfc2FileName)) {
356                                         componentToValidate = certifiedVFC2;
357                                         fileName = "Definitions/" + vfc2FileName;
358                                         
359                                         assertEquals("Validate entry Name", (fileName), nextEntry.getName());
360                                         assertTrue(yamlToObjectConverter.isValidYaml(resourceYaml.getBytes()));
361                                         validateContent(resourceYaml, componentToValidate);
362                                         ++toscaEntryIndex;
363                                         continue;
364                                 }
365
366                                 if (entryName.startsWith("Artifacts/Deployment/MODEL_INVENTORY_PROFILE") && entryName.contains("AAI")) {
367                                         ++generatorEntryIndex;
368                                         continue;
369                                 }
370                                 
371                                 if (entryName.contains(".xml") && entryName.startsWith("Artifacts/Deployment/") && !entryName.contains("AAI")) {
372                                         ++deploymentArtifactIndex;
373                                         continue;
374                                 }
375                                 
376                                 if (entryName.contains(".xml") && entryName.startsWith("Artifacts/Informational/") && !entryName.contains("AAI")) {
377                                         ++informationalArtifactIndex;
378                                         continue;
379                                 }
380                                 
381                                 assertTrue("Unexpected entry: " + entryName, true);
382                         }
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);
389                         
390                         ins.close();
391                         zip.close();
392                 } catch (IOException e) {
393                         e.printStackTrace();
394                 }
395         }
396         
397         private void validateVFCsar(Component certifiedVF, byte[] resultByte, int toscaEntryIndexToPass, 
398                         int ymlDeploymentArtifactIndexToPass, int xmlDeploymentArtifactIndexToPass, int heatDeploymentArtifactIndexToPass,
399                         int ymlInformationalArtifactIndexToPass, int xmlInformationalArtifactIndexToPass, int heatInformationalArtifactIndexToPass) {
400                 
401                 // TODO Test to validate everything is right (comment out after testing)
402                 /*try {
403                         FileUtils.writeByteArrayToFile(new File("c:/TestCSAR/" + fetchedService.getName() + ".zip"), resultByte);
404                 } catch (IOException e) {
405                         // Auto-generated catch block
406                         e.printStackTrace();
407                 }*/
408
409                 try (ByteArrayInputStream ins = new ByteArrayInputStream(resultByte);
410                                 ZipInputStream zip = new ZipInputStream(ins);) {
411                         
412                         String resourceYaml = null;
413                         byte[] buffer = new byte[1024];
414                         ZipEntry nextEntry = zip.getNextEntry();
415                         StringBuffer sb = new StringBuffer();
416                         int len;
417
418                         while ((len = zip.read(buffer)) > 0) {
419                                 sb.append(new String(buffer, 0, len));
420                         }
421
422                         assertTrue(nextEntry.getName().equals("csar.meta"));
423
424                         readNextEntry(sb, len, buffer, zip);
425                         nextEntry = zip.getNextEntry();
426                         assertTrue(nextEntry.getName().equals("TOSCA-Metadata/TOSCA.meta"));
427                         
428                         readNextEntry(sb, len, buffer, zip);
429                 
430                         YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
431
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;
442
443                         artifactDefinition = certifiedVF.getToscaArtifacts().get(ASSET_TOSCA_TEMPLATE);
444                         String vfFileName = artifactDefinition.getArtifactName();
445
446                         while ((nextEntry = zip.getNextEntry()) != null) {
447                                 
448                                 readNextEntry(sb, len, buffer, zip);
449
450                                 String entryName = nextEntry.getName();
451
452                                 resourceYaml = sb.toString();
453                                 if (entryName.contains(vfFileName)) {
454                                         componentToValidate = certifiedVF;
455                                         fileName = "Definitions/" + vfFileName;
456                                         
457                                         assertEquals("Validate entry Name", (fileName), nextEntry.getName());
458                                         assertTrue(yamlToObjectConverter.isValidYaml(resourceYaml.getBytes()));
459                                         validateContent(resourceYaml, componentToValidate);
460                                         ++toscaEntryIndex;
461                                         continue;
462                                 }
463
464                                 if (entryName.contains(".xml") && entryName.contains("YANG_XML")) {
465                                         if(entryName.startsWith("Artifacts/Deployment")){
466                                                 ++xmlDeploymentArtifactsIndex;
467                                                 continue;                                               
468                                         }else if(entryName.startsWith("Artifacts/Informational")){
469                                                 ++xmlInformationalArtifactsIndex;
470                                                 continue;
471                                         }
472                                 }
473
474                                 if (entryName.contains(".sh") && entryName.contains("HEAT_ARTIFACT")) {
475                                         if(entryName.startsWith("Artifacts/Deployment")){
476                                                 ++heatDeploymentArtifactIndex;
477                                                 continue;                                       
478                                         }else if(entryName.startsWith("Artifacts/Informational")){
479                                                 ++heatInformationalArtifactIndex;
480                                                 continue;
481                                         }
482                                 }
483                                 
484                                 if ((entryName.contains(".yml") || entryName.contains(".yaml")) && entryName.contains("HEAT")) {
485                                         if(entryName.startsWith("Artifacts/Deployment")){
486                                                 ++ymlDeploymentArtifactsIndex;
487                                                 continue;                                               
488                                         }else if(entryName.startsWith("Artifacts/Informational")){
489                                                 ++ymlInformationalArtifactsIndex;
490                                                 continue;
491                                         }
492                                 }
493                                 
494                                 if(entryName.contains("Definitions/") && entryName.contains("template-interface.yml")){
495                                         validateInterfaceContent(resourceYaml, certifiedVF);
496                                         continue;
497                                 }
498                                 if(entryName.contains("Definitions/")) {
499                                         if(isImportsFileValidation(entryName))
500                                         continue;
501                                 }
502                                 
503                                 assertTrue("Unexpected entry: " + entryName, false);
504                         }
505                         
506                         //Definitions folder
507                         assertEquals("Validate amount of entries", toscaEntryIndexToPass, toscaEntryIndex);
508                         
509                         //Deployment folder
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);
515                         
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);
522                         
523                         ins.close();
524                         zip.close();
525                 } catch (IOException e) {
526                         e.printStackTrace();
527                 }
528         }
529         
530         private void validateContent(String content, Component component) {
531                 Yaml yaml = new Yaml();
532
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);
539
540                 String name = (String) metadata.get("name");
541                 assertNotNull(name);
542                 assertEquals("Validate component name", component.getName(), name);
543
544                 String invariantUUID = (String) metadata.get("invariantUUID");
545                 assertNotNull(invariantUUID);
546                 assertEquals("Validate component invariantUUID", component.getInvariantUUID(), invariantUUID);
547
548                 String UUID = (String) metadata.get("UUID");
549                 assertNotNull(UUID);
550                 assertEquals("Validate component UUID", component.getUUID(), UUID);
551
552                 String type = (String) metadata.get("type");
553                 assertNotNull(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);
562                 } else {
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);
568                 }
569         }
570         
571         private byte[] downloadCSAR(User sdncModifierDetails, Component createdComponent) throws Exception {
572
573                 String artifactUniqeId = createdComponent.getToscaArtifacts().get("assettoscacsar").getUniqueId();
574                 RestResponse getCsarResponse = null;
575                 
576                 switch (createdComponent.getComponentType()) {
577                 case RESOURCE:
578                         getCsarResponse = ArtifactRestUtils.downloadResourceArtifactInternalApi(createdComponent.getUniqueId(),
579                                         sdncModifierDetails, artifactUniqeId);
580                         break;                  
581                 case SERVICE:
582                         getCsarResponse = ArtifactRestUtils.downloadServiceArtifactInternalApi(createdComponent.getUniqueId(),
583                                         sdncModifierDetails, artifactUniqeId);
584                         break;
585                 default:
586                         break;
587                 }
588                 
589                 assertNotNull(getCsarResponse);
590                 BaseRestUtils.checkSuccess(getCsarResponse);
591
592                 ArtifactUiDownloadData artifactUiDownloadData = ResponseParser.parseToObject(getCsarResponse.getResponse(),
593                                 ArtifactUiDownloadData.class);
594
595                 assertNotNull(artifactUiDownloadData);
596
597                 byte[] fromUiDownload = artifactUiDownloadData.getBase64Contents().getBytes();
598                 byte[] decodeBase64 = Base64.decodeBase64(fromUiDownload);
599
600                 return decodeBase64;
601         }
602         
603         private void validateInterfaceContent(String content, Component component) {
604                 Yaml yaml = new Yaml();
605
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);
612
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);
619
620         }
621         
622         private void readNextEntry(StringBuffer sb, int len, byte[] buffer, ZipInputStream zip) throws IOException {
623                 sb.setLength(0);
624
625                 while ((len = zip.read(buffer)) > 0) {
626                         sb.append(new String(buffer, 0, len));
627                 }
628         }
629         
630         private boolean isImportsFileValidation(String fileName) {
631         
632                 switch(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":
641                                 return true;
642                                 
643                 }
644                 return false;
645         }
646 }