ActivitySpec - Correcting logger messages
[sdc.git] / common / openecomp-sdc-artifact-generator-lib / openecomp-sdc-artifact-generator-core / src / test / java / org / openecomp / sdc / generator / ArtifactGenerationServiceTest.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.generator;
22
23 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_CONFIGFILE_NOT_FOUND;
24 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND;
25 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_CONFIGLPROP_NOT_FOUND;
26 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING;
27 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_PROVIDING_SERVICE_MISSING;
28 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_ID;
29 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_ERROR_MISSING_SERVICE_VERSION;
30 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_INVALID_SERVICE_VERSION;
31
32 import org.apache.commons.io.FileUtils;
33 import org.openecomp.sdc.generator.aai.model.Resource;
34 import org.openecomp.sdc.generator.aai.model.Service;
35 import org.openecomp.sdc.generator.aai.model.Widget;
36 import org.openecomp.sdc.generator.aai.tosca.GroupDefinition;
37 import org.openecomp.sdc.generator.aai.tosca.NodeTemplate;
38 import org.openecomp.sdc.generator.aai.tosca.ToscaTemplate;
39 import org.openecomp.sdc.generator.data.AdditionalParams;
40 import org.openecomp.sdc.generator.aai.xml.Model;
41 import org.openecomp.sdc.generator.aai.xml.ModelElement;
42 import org.openecomp.sdc.generator.aai.xml.ModelElements;
43 import org.openecomp.sdc.generator.aai.xml.ModelVer;
44 import org.openecomp.sdc.generator.aai.xml.Relationship;
45 import org.openecomp.sdc.generator.aai.xml.RelationshipData;
46 import org.openecomp.sdc.generator.data.Artifact;
47 import org.openecomp.sdc.generator.data.ArtifactType;
48 import org.openecomp.sdc.generator.data.GenerationData;
49 import org.openecomp.sdc.generator.data.GeneratorConstants;
50 import org.openecomp.sdc.generator.data.GeneratorUtil;
51 import org.openecomp.sdc.generator.data.GroupType;
52 import org.openecomp.sdc.generator.impl.ArtifactGenerationServiceImpl;
53 import org.testng.Assert;
54 import org.testng.annotations.BeforeSuite;
55 import org.testng.annotations.Test;
56
57 import java.io.ByteArrayInputStream;
58 import java.io.File;
59 import java.io.FileInputStream;
60 import java.io.FileOutputStream;
61 import java.io.IOException;
62 import java.io.InputStream;
63 import java.io.OutputStream;
64 import java.net.URL;
65 import java.util.*;
66 import javax.xml.bind.JAXBContext;
67 import javax.xml.bind.JAXBException;
68 import javax.xml.bind.Unmarshaller;
69
70 @SuppressWarnings("Duplicates")
71 public class ArtifactGenerationServiceTest {
72
73   private static final String aaiArtifactType = ArtifactType.AAI.name();
74   private static final String aaiArtifactGroupType = GroupType.DEPLOYMENT.name();
75   private static final String generatorConfig = "{\"artifactTypes\": [\"OTHER\",\"AAI\"]}";
76   private final Properties properties = new Properties();
77   private final Map<String, String> additionalParams = new HashMap<>();
78   private final Map<String, String> resourcesVersion = new HashMap<>();
79
80   @BeforeSuite
81   public void loadProperties() throws Exception{
82     loadConfigFromClasspath(properties);
83     additionalParams.put(AdditionalParams.ServiceVersion.getName(), "1.0");
84   }
85
86   @Test
87   public void testArtifactGeneration() {
88     // Sunny day scenario service with VF anf vfmodule
89     try {
90
91       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
92       List<ToscaTemplate> toscas = new LinkedList<>();
93       String aaiResourceBasePaths = "aai/";
94       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
95       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
96       if (data.getErrorData().isEmpty()) {
97         for (Artifact inputArtifact : inputArtifacts) {
98           toscas.add(getToscaModel(inputArtifact));
99         }
100         List<Artifact> resultData = data.getResultData();
101
102         /*for( int i = 0 ; i < resultData.size() ; i++) {
103           Artifact artifact = resultData.get(i);
104           String fileName = artifact.getName();
105           while(fileName.contains(":")){
106             fileName = fileName.replace(":","");
107           }
108           File targetFile =new File("src/test/resources/"+fileName);
109           OutputStream outStream = new FileOutputStream(targetFile);
110           outStream.write(Base64.getDecoder().decode(artifact.getPayload()));
111         }*/
112
113         Assert.assertEquals(resultData.size(),5);  //  1-service,1-VF-resource,1-vfmodule and 2
114         // others
115         Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
116         testServiceTosca(toscas, outputArtifactMap);
117         testResourceTosca(toscas.iterator(), outputArtifactMap);
118       } else {
119         Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
120       }
121
122     } catch (Exception e) {
123       Assert.fail(e.getMessage());
124     }
125   }
126
127   @Test
128   public void testWidgetinServiceTosca() {
129     // Sunny day scenario service with VF and extra widget like CP anf vf has vfmodule without
130     // member
131     try {
132       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
133       List<ToscaTemplate> toscas = new LinkedList<>();
134       String aaiResourceBasePaths = "testWidgetinServiceTosca/";
135       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
136       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
137       if (data.getErrorData().isEmpty()) {
138         for (Artifact inputArtifact : inputArtifacts) {
139           toscas.add(getToscaModel(inputArtifact));
140         }
141         List<Artifact> resultData = data.getResultData();
142         Assert.assertEquals(resultData.size(),5);  //  1-service,1-VF-resource,1-vfmodule and 2
143         // others
144         Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
145         testServiceTosca(toscas, outputArtifactMap);
146         testResourceTosca(toscas.iterator(), outputArtifactMap);
147       } else {
148         Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
149       }
150
151     } catch (Exception e) {
152       Assert.fail(e.getMessage());
153     }
154   }
155
156   @Test
157   public void testSameVLdifferentVersion() {
158     // Sunny day scenario service with VF and extra widget like CP anf vf has vfmodule without
159     // member
160     try {
161       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
162       List<ToscaTemplate> toscas = new LinkedList<>();
163       String aaiResourceBasePaths = "testSameVLdifferentVersion/";
164       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
165       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
166       if (data.getErrorData().isEmpty()) {
167         for (Artifact inputArtifact : inputArtifacts) {
168           toscas.add(getToscaModel(inputArtifact));
169         }
170         List<Artifact> resultData = data.getResultData();
171         Assert.assertEquals(resultData.size(),8);
172         // others
173         Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
174         testServiceTosca(toscas, outputArtifactMap);
175         testResourceTosca(toscas.iterator(), outputArtifactMap);
176       } else {
177         Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
178       }
179
180     } catch (Exception e) {
181       Assert.fail(e.getMessage());
182     }
183   }
184
185   @Test
186   public void testArtifactGenerationAllottedResourceAndL3Network() {
187     // Sunny day scenario service with allotted resource and L3-network
188     try {
189       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
190       List<ToscaTemplate> toscas = new LinkedList<>();
191       String aaiResourceBasePaths = "aai2/";
192       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
193       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
194       if (data.getErrorData().isEmpty()) {
195         for (Artifact inputArtifact : inputArtifacts) {
196           toscas.add(getToscaModel(inputArtifact));
197         }
198         List<Artifact> resultData = data.getResultData();
199
200         Assert.assertEquals(resultData.size(),5);
201         // and 2
202         // others
203         Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
204         testServiceTosca(toscas, outputArtifactMap);
205         testResourceTosca(toscas.iterator(), outputArtifactMap);
206       } else {
207         Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
208       }
209
210     } catch (Exception e) {
211       Assert.fail(e.getMessage());
212     }
213   }
214
215   @Test(dependsOnMethods = {"testArtifactGeneration"})
216   public void testWhenMissingTosca() {
217     try {
218       //Missing Service tosca test case
219       String aaiResourceBasePaths = "testArtifactGeneration2/";
220       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
221       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
222       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
223       Assert.assertEquals(data.getErrorData().get("AAI").get(0),"Service tosca missing from list of input artifacts");
224     } catch (Exception e) {
225       Assert.fail(e.getMessage());
226     }
227   }
228
229   @Test(dependsOnMethods = {"testWhenMissingTosca"})
230   public void testWhenInvaildConfig() {
231     try {
232       //Invalid config test case
233       String generatorConfig1 = "{\"artifactTypes\": [\"ABC\"]}";
234       String aaiResourceBasePaths = "testArtifactGeneration2/";
235       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
236       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
237       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig1, additionalParams);
238       Assert.assertEquals(data.getErrorData().get("ARTIFACT_GENERATOR_INVOCATION_ERROR").get(0),"Invalid Client Configuration");
239     } catch (Exception e) {
240       Assert.fail(e.getMessage());
241     }
242   }
243
244   @Test(dependsOnMethods = {"testArtifactGeneration"})
245   public void testWhenOnlyServToscaNoResTosca() {
246     try {
247       //Testing only service tosca no resource Tosca
248       String aaiResourceBasePaths = "testArtifactGeneration4/";
249       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
250       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
251       List<ToscaTemplate> toscas = new LinkedList<>();
252       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
253       List<Artifact> resultData = data.getResultData();
254       if (data.getErrorData().isEmpty()) {
255         for (Artifact inputArtifact : inputArtifacts) {
256           toscas.add(getToscaModel(inputArtifact));
257         }
258       }
259       Assert.assertEquals(resultData.size(),3);  //  1-service and 2-Others
260       Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
261       testServiceTosca(toscas, outputArtifactMap);
262     } catch (Exception e) {
263       Assert.fail(e.getMessage());
264     }
265   }
266
267   @Test(dependsOnMethods = {"testArtifactGeneration"})
268   public void testWhenInvaildYaml() {
269     try {
270       //Invalid Yaml file test case
271       String aaiResourceBasePaths = "testArtifactGeneration5/";
272       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
273       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
274       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
275       Assert.assertEquals(data.getErrorData().get("AAI").get(0),"Invalid format for Tosca YML  : " + inputArtifacts.get(0).getName());
276     } catch (Exception e) {
277       Assert.fail(e.getMessage());
278     }
279   }
280
281   @Test(dependsOnMethods = {"testArtifactGeneration"})
282   public void testWhenExtraResToscaNotPartOfServ() {
283     try {
284       // Valid scenario with extra resource tosca which is not part of Service
285       String aaiResourceBasePaths = "testArtifactGeneration6/";
286       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
287       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
288       List<ToscaTemplate> toscas = new LinkedList<>();
289       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
290       List<Artifact> resultData = data.getResultData();
291       if (data.getErrorData().isEmpty()) {
292         for (Artifact inputArtifact : inputArtifacts) {
293           toscas.add(getToscaModel(inputArtifact));
294         }
295       }
296       Assert.assertEquals(resultData.size(),3);  //  1-service and 2 Others
297       Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
298       testServiceTosca(toscas, outputArtifactMap);
299     } catch (Exception e) {
300       Assert.fail(e.getMessage());
301     }
302   }
303
304
305   @Test
306   public void testWhenInvUuIdAttrMissing() {
307     try {
308       // mandatory attribute <invariantUUID> missing
309       String aaiResourceBasePaths = "testArtifactGeneration8/";
310       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
311       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
312       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
313       Assert.assertEquals(
314           data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <invariantUUID> missing in Artifact: <" +
315               inputArtifacts.get(0).getName() + ">");
316
317     } catch (Exception e) {
318       Assert.fail(e.getMessage());
319     }
320   }
321
322   @Test
323   public void testErrorWhenInvalidInvId() {
324     try {
325       //Invariant Id in service tosca of length not 36
326       String aaiResourceBasePaths = "testErrorWhenInvalidInvId/";
327       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
328       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
329       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
330       Assert.assertEquals(
331           data.getErrorData().get("AAI").get(0),String.format(GENERATOR_AAI_ERROR_INVALID_ID,
332               "invariantUUID",inputArtifacts.get(0).getName()));
333
334     } catch (Exception e) {
335       Assert.fail(e.getMessage());
336     }
337   }
338
339   @Test
340   public void testWhenUuIdAttrMissing() {
341     try {
342       //mandatory attribute <UUID> missing
343       String aaiResourceBasePaths = "testArtifactGeneration9/";
344       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
345       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
346       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
347       Assert.assertEquals(
348           data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <UUID> missing in Artifact: <" +
349               inputArtifacts.get(0).getName() + ">");
350
351     } catch (Exception e) {
352       Assert.fail(e.getMessage());
353     }
354   }
355
356   @Test
357   public void testErrorWhenInvalidUuId() {
358     try {
359       //UUID Id in service tosca of length not 36
360       String aaiResourceBasePaths = "testErrorWhenInvalidUuId/";
361       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
362       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
363       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
364       Assert.assertEquals(
365           data.getErrorData().get("AAI").get(0),String.format(GENERATOR_AAI_ERROR_INVALID_ID,
366               "UUID",inputArtifacts.get(0).getName()));
367
368     } catch (Exception e) {
369       Assert.fail(e.getMessage());
370     }
371   }
372
373   @Test
374   public void testWhenNameAttrMissing() {
375     try {
376       //mandatory attribute <name> missing
377       String aaiResourceBasePaths = "testArtifactGeneration10/";
378       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
379       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
380       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
381       Assert.assertEquals(
382           data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <name> missing in Artifact: <" +
383               inputArtifacts.get(0).getName() + ">");
384
385     } catch (Exception e) {
386       Assert.fail(e.getMessage());
387     }
388   }
389
390   @Test //(dependsOnMethods = {"testArtifactGeneration"})
391   public void testWhenVfModInvUuIdAttrMissing() {
392     try {
393       //mandatory attribute <vfModuleModelInvariantUUID> missing
394       List<Artifact> inputArtifacts = new ArrayList<>();
395       readPayloadFromResource(inputArtifacts, "service_vmme_template_ModInvUUID.yml");
396       readPayloadFromResource(inputArtifacts, "vf_vmme_template_ModInvUUID.yml");
397       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
398       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
399       Assert.assertEquals(
400           data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <vfModuleModelInvariantUUID> missing in Artifact: <" +
401               inputArtifacts.get(1).getName() + ">");
402
403     } catch (Exception e) {
404       Assert.fail(e.getMessage());
405     }
406   }
407
408   public static void readPayload(List<Artifact> inputArtifacts, InputStream fis, String fileName) throws
409       IOException {
410     byte[] payload = new byte[fis.available()];
411     fis.read(payload);
412     String checksum = GeneratorUtil.checkSum(payload);
413     byte[] encodedPayload = GeneratorUtil.encode(payload);
414     Artifact artifact = new Artifact(aaiArtifactType, aaiArtifactGroupType, checksum, encodedPayload);
415     artifact.setName(fileName);
416     artifact.setLabel(fileName);
417     artifact.setDescription(fileName);
418     artifact.setVersion("1.0");
419     System.out.println(artifact.getName());
420     inputArtifacts.add(artifact);
421   }
422
423   @Test
424   public void testWhenInvalidVfModInvUuIdAttr() {
425     try {
426       //invalid id since not of length 36 for  <vfModuleModelInvariantUUID>
427       List<Artifact> inputArtifacts = new ArrayList<>();
428       readPayloadFromResource(inputArtifacts, "service_vmme_template_InvalidVfModInvUuIdAttr.yml");
429
430       readPayloadFromResource(inputArtifacts, "vf_vmme_template_InvalidVfModInvUuIdAttr.yml");
431       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
432       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
433       Assert.assertEquals(
434           data.getErrorData().get("AAI").get(0),String.format(GENERATOR_AAI_ERROR_INVALID_ID,
435               "vfModuleModelInvariantUUID", inputArtifacts.get(1).getName() ));
436
437     } catch (Exception e) {
438       Assert.fail(e.getMessage());
439     }
440   }
441
442   @Test //(dependsOnMethods = {"testArtifactGeneration"})
443   public void testWhenVfModNameAttrMissing() {
444     try {
445       //mandatory attribute <vfModuleModelName> missing
446       List<Artifact> inputArtifacts = new ArrayList<>();
447       readPayloadFromResource(inputArtifacts, "service_vmme_template_ModelName.yml");
448
449       readPayloadFromResource(inputArtifacts, "vf_vmme_template_ModelName.yml");
450       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
451       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
452       Assert.assertEquals(
453           data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <vfModuleModelName> missing in Artifact: <" +
454               inputArtifacts.get(1).getName() + ">");
455
456     } catch (Exception e) {
457       Assert.fail(e.getMessage());
458     }
459   }
460
461   /*public static void readPayload(List<Artifact> inputArtifacts,InputStream fis, String fileName)
462       throws
463       IOException {
464     byte[] payload = new byte[fis.available()];
465     fis.read(payload);
466     String checksum = GeneratorUtil.checkSum(payload);
467     byte[] encodedPayload = GeneratorUtil.encode(payload);
468     Artifact artifact = new Artifact(aaiArtifactType, aaiArtifactGroupType, checksum, encodedPayload);
469     artifact.setName(fileName);
470     artifact.setLabel(fileName);
471     artifact.setDescription(fileName);
472     artifact.setVersion("1.0");
473     System.out.println(artifact.getName());
474     inputArtifacts.add(artifact);
475   }*/
476
477   @Test //(dependsOnMethods = {"testArtifactGeneration"})
478   public void testWhenVfModUuIdAttrMissing() {
479     try {
480       //mandatory attribute <vfModuleModelUUID> missing in Artifact
481       List<Artifact> inputArtifacts = new ArrayList<>();
482       readPayloadFromResource(inputArtifacts, "service_vmme_template_ModelUUID.yml");
483
484       readPayloadFromResource(inputArtifacts, "vf_vmme_template_ModelUUID.yml");
485       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
486       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
487       Assert.assertEquals(
488           data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory " +
489               "attribute <vfModuleModelUUID> missing in Artifact: <" +
490               inputArtifacts.get(1).getName() + ">");
491
492     } catch (Exception e) {
493       Assert.fail(e.getMessage());
494     }
495   }
496
497   @Test
498   public void testWhenInvalidVfModUuIdAttr() {
499     try {
500       //invalid id since not of length 36 for  <vfModuleModelUUID>
501       List<Artifact> inputArtifacts = new ArrayList<>();
502       readPayloadFromResource(inputArtifacts, "service_vmme_template_InvalidVfModUuIdAttr.yml");
503
504       readPayloadFromResource(inputArtifacts, "vf_vmme_template_InvalidVfModUuIdAttr.yml");
505       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
506       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
507       Assert.assertEquals(
508           data.getErrorData().get("AAI").get(0),String.format(GENERATOR_AAI_ERROR_INVALID_ID,
509               "vfModuleModelUUID", inputArtifacts.get(1).getName() ));
510
511     } catch (Exception e) {
512       Assert.fail(e.getMessage());
513     }
514   }
515
516   @Test //(dependsOnMethods = {"testArtifactGeneration"})
517   public void testWhenVfModVersionAttrMissing() {
518     try {
519       //mandatory attribute <vfModuleModelVersion> missing
520       List<Artifact> inputArtifacts = new ArrayList<>();
521       readPayloadFromResource(inputArtifacts, "service_vmme_template_ModelVersion.yml");
522
523       readPayloadFromResource(inputArtifacts, "vf_vmme_template_ModelVersion.yml");
524       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
525       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
526       Assert.assertEquals(
527           data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <vfModuleModelVersion> missing in Artifact: <" +
528               inputArtifacts.get(1).getName() + ">");
529
530     } catch (Exception e) {
531       Assert.fail(e.getMessage());
532     }
533   }
534
535   @Test
536   public void testErrorWhenNoSystemPropConfigured() throws Exception  {
537     String configLoc = System.getProperty("artifactgenerator.config");
538     try {
539       System.clearProperty("artifactgenerator.config");
540       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
541       String aaiResourceBasePaths = "aai/";
542       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
543       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
544       Assert.assertEquals(false,data.getErrorData().isEmpty());
545       Assert.assertEquals(data.getErrorData().
546           get("AAI").get(0),GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND);
547     } catch (Exception e) {
548       Assert.fail(e.getMessage());
549     }
550     finally{
551       System.setProperty("artifactgenerator.config",configLoc);
552     }
553   }
554
555   @Test
556   public void testErrorWhenNoWidgetInConfig() throws Exception  {
557     String configLoc = System.getProperty("artifactgenerator.config");
558     final File configFile = new File(configLoc);
559     String configDir = configLoc.substring(0, configLoc.lastIndexOf(File.separator));
560     final File tempFile = new File(configDir + File.separator + "temp.properties");
561     try {
562       //copy orignal Artifact-Generator.properties to temp.properties for backup
563       FileUtils.copyFile(configFile, tempFile);
564
565       String serviceWidgetName = ArtifactType.AAI.name()+".model-version-id."+Widget.getWidget
566           (Widget.Type.SERVICE)
567           .getName();
568       String assertMsg = ArtifactType.AAI.name() + ".model-version-id." +Widget.getWidget
569           (Widget.Type.SERVICE).getName();
570
571       //Remove property from Artifact-Generator.properties
572       properties.remove(serviceWidgetName);
573       try (OutputStream fos = new FileOutputStream(new File(configLoc))) {
574         properties.store(fos,null);
575       }
576
577       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
578       String aaiResourceBasePaths = "aai/";
579       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
580       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
581       Assert.assertEquals(false,data.getErrorData().isEmpty());
582       String errMsg = String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,assertMsg);
583       Assert.assertEquals(data.getErrorData().get("AAI").get(0),errMsg);
584     } catch (Exception e) {
585       Assert.fail(e.getMessage());
586     }
587     finally{
588       if(tempFile.exists()){
589         //Revert the changes
590         FileUtils.copyFile(tempFile, configFile);
591         loadConfigFromClasspath(properties);
592         tempFile.delete();
593       }
594     }
595   }
596
597   @Test
598   public void testErrorWhenNoFileAtConfigLocation() throws Exception  {
599     String configLoc = System.getProperty("artifactgenerator.config");
600     try {
601       System.setProperty("artifactgenerator.config",configLoc + File.separator + "testErrorWhenNoFileAtConfigLocation");
602       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
603       String aaiResourceBasePaths = "aai/";
604       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
605       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
606       Assert.assertEquals(data.getErrorData().isEmpty(),false);
607       Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format(GENERATOR_AAI_CONFIGFILE_NOT_FOUND,System.getProperty
608           ("artifactgenerator.config")));
609     } catch (Exception e) {
610       Assert.fail(e.getMessage());
611     }
612     finally{
613       System.setProperty("artifactgenerator.config",configLoc);
614     }
615   }
616
617   @Test
618   public void testErrorWhenNoServiceVersion() {
619     //  scenario service with VF anf vfmodule but no service version in additional parameter
620     try {
621       additionalParams.clear();
622       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
623       String aaiResourceBasePaths = "aai/";
624       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
625       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
626       Assert.assertEquals(data.getErrorData().isEmpty(),false);
627       Assert.assertEquals(data.getErrorData().get("AAI").get(0),
628           GENERATOR_AAI_ERROR_MISSING_SERVICE_VERSION);
629     } catch (Exception e) {
630       Assert.fail(e.getMessage());
631     }
632     finally{
633       additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
634     }
635   }
636
637   @Test
638   public void testArtifactGenerationWithServiceVersion() {
639     // Sunny day scenario service with VF anf vfmodule and service version as adiitional parameter
640     try {
641       additionalParams.put(AdditionalParams.ServiceVersion.getName(),"9.0");
642       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
643       List<ToscaTemplate> toscas = new LinkedList<>();
644       String aaiResourceBasePaths = "aai/";
645       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
646       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
647       if (data.getErrorData().isEmpty()) {
648         for (Artifact inputArtifact : inputArtifacts) {
649           toscas.add(getToscaModel(inputArtifact));
650         }
651         List<Artifact> resultData = data.getResultData();
652
653         /*for( int i = 0 ; i < resultData.size() ; i++) {
654           Artifact artifact = resultData.get(i);
655           String fileName = artifact.getName();
656           while(fileName.contains(":")){
657             fileName = fileName.replace(":","");
658           }
659           File targetFile =new File("src/test/resources/"+fileName);
660           OutputStream outStream = new FileOutputStream(targetFile);
661           outStream.write(Base64.getDecoder().decode(artifact.getPayload()));
662         }*/
663
664         Assert.assertEquals(resultData.size(),5);  //  1-service,1-VF-resource,1-vfmodule and 2
665         // others
666         Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
667         testServiceTosca(toscas, outputArtifactMap);
668         testResourceTosca(toscas.iterator(), outputArtifactMap);
669       } else {
670         Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
671       }
672
673     } catch (Exception e) {
674       Assert.fail(e.getMessage());
675     }
676     finally{
677       additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
678     }
679   }
680
681   @Test
682   public void testErrorWhenInvalidServiceVersion() {
683     //  scenario service with VF anf vfmodule but invalid service version in additional parameter
684     try {
685       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
686       String aaiResourceBasePaths = "aai/";
687       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
688
689       additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1");
690       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
691       Assert.assertEquals(data.getErrorData().isEmpty(),false);
692       Assert.assertEquals(data.getErrorData().get("AAI").get(0),
693           GENERATOR_AAI_INVALID_SERVICE_VERSION);
694
695       additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.1");
696       data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
697       Assert.assertEquals(data.getErrorData().isEmpty(),false);
698       Assert.assertEquals(data.getErrorData().get("AAI").get(0),
699           GENERATOR_AAI_INVALID_SERVICE_VERSION);
700
701       additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.0");
702       data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
703       Assert.assertEquals(data.getErrorData().isEmpty(),false);
704       Assert.assertEquals(data.getErrorData().get("AAI").get(0),
705           GENERATOR_AAI_INVALID_SERVICE_VERSION);
706
707     } catch (Exception e) {
708       Assert.fail(e.getMessage());
709     }
710     finally{
711       additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
712     }
713   }
714
715   @Test
716   public void testMissingResourceTosca() {
717     try {
718       //Service with resource but seperate resource tosca not coming as input.
719       String aaiResourceBasePaths = "missingResourceTosca/";
720       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
721       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
722       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
723       Assert.assertEquals(data.getErrorData().get("AAI").get(0),"Cannot generate artifacts. Resource Tosca missing for resource with UUID: <b020ed1e-4bc7-4fc0-ba7e-cc7af6da7ffc>");
724     } catch (Exception e) {
725       Assert.fail(e.getMessage());
726     }
727   }
728   @Test
729   public void testMissingVLTosca() {
730     try {
731       //Service with VL but seperate VL tosca not coming as input artifact.
732       String aaiResourceBasePaths = "missingVLTosca/";
733       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
734       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
735       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
736       Assert.assertEquals(data.getErrorData().get("AAI").get(0),"Cannot generate artifacts. Resource Tosca missing for resource with UUID: <3f8fa4d2-2b86-4b36-bbc8-ffb8f9f57468>");
737     } catch (Exception e) {
738       Assert.fail(e.getMessage());
739     }
740   }
741
742   @Test
743   public void testErrorWhenNoResourceVersion() {
744     //  scenario service with VF but missing resource version in service tosca
745     try {
746       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
747       String aaiResourceBasePaths = "testErrorWhenNoResourceVersion/";
748       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
749       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
750       Assert.assertEquals(data.getErrorData().isEmpty(),false);
751       Assert.assertEquals(data.getErrorData().get("AAI").get(0),
752           "Invalid Service definition mandatory attribute version missing for resource with UUID: <b020ed1e-4bc7-4fc0-ba7e-cc7af6da7ffc>");
753     } catch (Exception e) {
754       Assert.fail(e.getMessage());
755     }
756   }
757
758   @Test
759   public void testErrorWhenInvalidResourceVersion1() {
760     //  scenario service with VF but invalid resource version 0.0 in service tosca
761     try {
762       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
763       String aaiResourceBasePaths = "testErrorWhenInvalidResourceVersion1/";
764       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
765       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
766       Assert.assertEquals(data.getErrorData().isEmpty(),false);
767       Assert.assertEquals(data.getErrorData().get("AAI").get(0),
768           "Cannot generate artifacts. Invalid Resource version in Service tosca for resource with UUID: <b020ed1e-4bc7-4fc0-ba7e-cc7af6da7ffc>");
769     } catch (Exception e) {
770       Assert.fail(e.getMessage());
771     }
772   }
773
774   @Test
775   public void testErrorWhenInvalidResourceVersion2() {
776     //  scenario service with VF but invalid resource version 1 in service tosca
777     try {
778       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
779       String aaiResourceBasePaths = "testErrorWhenInvalidResourceVersion2/";
780       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
781       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
782       Assert.assertEquals(data.getErrorData().isEmpty(),false);
783       Assert.assertEquals(data.getErrorData().get("AAI").get(0),
784           "Cannot generate artifacts. Invalid Resource version in Service tosca for resource with UUID: <b020ed1e-4bc7-4fc0-ba7e-cc7af6da7ffc>");
785     } catch (Exception e) {
786       Assert.fail(e.getMessage());
787     }
788   }
789
790   @Test
791   public void testArtifactGenerationAllottedResourceWithIpMuxAndTunnelXConn() {
792     try {
793       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
794       List<ToscaTemplate> toscas = new LinkedList<>();
795       String aaiResourceBasePaths = "testArtifactGeneration15/";
796       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
797       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
798       if (data.getErrorData().isEmpty()) {
799         for (Artifact inputArtifact : inputArtifacts) {
800           toscas.add(getToscaModel(inputArtifact));
801         }
802         List<Artifact> resultData = data.getResultData();
803
804         Assert.assertEquals(resultData.size(),5);
805         Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
806         testServiceTosca(toscas, outputArtifactMap);
807         testResourceTosca(toscas.iterator(), outputArtifactMap);
808       } else {
809         Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
810       }
811
812     } catch (Exception e) {
813       Assert.fail(e.getMessage());
814     }
815   }
816
817 //  @Test
818   public void testErrorWhenAllottedResourceWithOutProvidingServiceId() {
819     try {
820       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
821       String aaiResourceBasePaths = "testErrorWhenAllottedResourceWithOutDependingServiceId/";
822       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
823       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
824       Assert.assertEquals(data.getErrorData().isEmpty(),false);
825       Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format
826               (GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING, "707b2850-e830-4b00-9902-879f44ac05a4"));
827     } catch (Exception e) {
828       Assert.fail(e.getMessage());
829     }
830   }
831
832   @Test
833   public void testArtifactGenerationWithoutAllottedResource() {
834     try {
835       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
836       String aaiResourceBasePaths = "testArtifactGeneration16/";
837       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
838       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
839       Assert.assertEquals(data.getErrorData().isEmpty(),false);
840       Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format
841           (GENERATOR_AAI_PROVIDING_SERVICE_MISSING, "a54a5235-b69d-4f8a-838b-d011e6783fa5"));
842     } catch (Exception e) {
843       Assert.fail(e.getMessage());
844     }
845   }
846
847   @Test
848   public void testArtifactGenerationAllottedResourceIpmuxSameInvariantDiffVersion() {
849     try {
850       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
851       List<ToscaTemplate> toscas = new LinkedList<>();
852       String aaiResourceBasePaths = "testArtifactGeneration17/";
853       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
854       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
855       if (data.getErrorData().isEmpty()) {
856         for (Artifact inputArtifact : inputArtifacts) {
857           toscas.add(getToscaModel(inputArtifact));
858         }
859         List<Artifact> resultData = data.getResultData();
860
861         Assert.assertEquals(resultData.size(),5);
862         Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
863         testServiceTosca(toscas, outputArtifactMap);
864         testResourceTosca(toscas.iterator(), outputArtifactMap);
865       } else {
866         Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
867       }
868
869     } catch (Exception e) {
870       Assert.fail(e.getMessage());
871     }
872   }
873
874   @Test
875   public void testArtifactGenerationAllottedResourceIpmuxSameInvariantSameVersion() {
876     try {
877       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
878       List<ToscaTemplate> toscas = new LinkedList<>();
879       String aaiResourceBasePaths = "testArtifactGeneration18/";
880       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
881       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
882       if (data.getErrorData().isEmpty()) {
883         for (Artifact inputArtifact : inputArtifacts) {
884           toscas.add(getToscaModel(inputArtifact));
885         }
886         List<Artifact> resultData = data.getResultData();
887
888
889         Assert.assertEquals(resultData.size(),4);
890         Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
891         testServiceTosca(toscas, outputArtifactMap);
892         testResourceTosca(toscas.iterator(), outputArtifactMap);
893       } else {
894         Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
895       }
896
897     } catch (Exception e) {
898       Assert.fail(e.getMessage());
899     }
900   }
901
902   @Test
903   public void testArtifactGenerationAllottedResourceIpmuxWithGroups() {
904     try {
905       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
906       List<ToscaTemplate> toscas = new LinkedList<>();
907       String aaiResourceBasePaths = "testAllotedResourceWithDependingSerWithGroups/";
908       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
909       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
910       if (data.getErrorData().isEmpty()) {
911         for (Artifact inputArtifact : inputArtifacts) {
912           toscas.add(getToscaModel(inputArtifact));
913         }
914         List<Artifact> resultData = data.getResultData();
915
916         Assert.assertEquals(resultData.size(),5);
917         Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
918         testServiceTosca(toscas, outputArtifactMap);
919         testResourceTosca(toscas.iterator(), outputArtifactMap);
920       } else {
921         Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
922       }
923
924     } catch (Exception e) {
925       Assert.fail(e.getMessage());
926     }
927   }
928
929   @Test
930   public void testArtifactGenerationAllottedResourceWithVF() {
931     try {
932       ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
933       List<ToscaTemplate> toscas = new LinkedList<>();
934       String aaiResourceBasePaths = "testArtifactGenerationAllottedResourceWithVF/";
935       List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
936       GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
937       if (data.getErrorData().isEmpty()) {
938         for (Artifact inputArtifact : inputArtifacts) {
939           toscas.add(getToscaModel(inputArtifact));
940         }
941         List<Artifact> resultData = data.getResultData();
942
943         Assert.assertEquals(resultData.size(),7);
944         Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
945         testServiceTosca(toscas, outputArtifactMap);
946         testResourceTosca(toscas.iterator(), outputArtifactMap);
947       } else {
948         Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
949       }
950
951     } catch (Exception e) {
952       Assert.fail(e.getMessage());
953     }
954   }
955
956
957   //@Test
958   public void testServiceTosca(List<ToscaTemplate> toscas, Map<String, Model> outputArtifactMap) {
959     try {
960       ToscaTemplate serviceTosca = getServiceTosca(toscas);
961       if (serviceTosca == null) {
962         Assert.fail("Service Tosca not found");
963       }
964       serviceTosca.getMetadata().put("version", "1.0");
965       Service service = new Service();
966       service.populateModelIdentificationInformation(serviceTosca.getMetadata());
967       String serviceNameVersionId = service.getModelNameVersionId();
968       Model serviceAAIModel = getAAIModelByNameVersionId(serviceNameVersionId, outputArtifactMap);
969       validateServiceModelMetadata(service, serviceAAIModel);
970       //Validate Service instance base widget
971       ModelVer modelVersion =  serviceAAIModel.getModelVers().getModelVer().get(0);
972
973       List<ModelElement> matchedServiceBaseWidgetElements =
974           getModelElementbyRelationshipValue( modelVersion.getModelElements(),
975               Widget.getWidget(Widget.Type.SERVICE).getId());
976       validateMatchedModelElementsInService(matchedServiceBaseWidgetElements,
977           Widget.getWidget(Widget.Type.SERVICE).getName());
978
979       validateWidgetIds(matchedServiceBaseWidgetElements, Widget.getWidget(Widget.Type.SERVICE).getName(),
980           Widget.getWidget(Widget.Type.SERVICE).getWidgetId());
981
982       ModelElements baseServiceWidgetModelElements =
983           matchedServiceBaseWidgetElements.get(0).getModelElements();
984
985
986       Map<String, String> nodeTemplateIdTypeStore = getNodeTemplateTypeStore(serviceTosca);
987       if (nodeTemplateIdTypeStore != null) {
988         for (String key : nodeTemplateIdTypeStore.keySet()) {
989           if (nodeTemplateIdTypeStore.get(key).contains("org.openecomp.resource.vf")) {
990             List<ModelElement> matchedResourceElements =
991                 getModelElementbyRelationshipValue(baseServiceWidgetModelElements, key);
992             if (nodeTemplateIdTypeStore.get(key).contains("org.openecomp.resource.vf.allottedResource")){
993               validateMatchedModelElementsInService(matchedResourceElements,
994                   Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getName());
995             }else {
996               validateMatchedModelElementsInService(matchedResourceElements,
997                   Widget.getWidget(Widget.Type.VF).getName());
998             }
999
1000             //Validate uuid and invariantuuid are populated in model-ver.model-version-id and model.model-invariant-id
1001             Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList()
1002                 .getRelationship().get(0)
1003                 .getRelationshipData().get(0).getRelationshipValue(),key);
1004
1005             Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList().getRelationship().get(0)
1006                 .getRelationshipData().get(1).getRelationshipValue(), nodeTemplateIdTypeStore
1007                 .get(key+"-INV_UID"));
1008           } else if(nodeTemplateIdTypeStore.get(key).contains("org.openecomp.resource.vl")){
1009             //validate l3-network in service tosca
1010             List<ModelElement> matchedResourceElements =
1011                 getModelElementbyRelationshipValue(baseServiceWidgetModelElements, key);
1012             validateMatchedModelElementsInService(matchedResourceElements,
1013                 Widget.getWidget(Widget.Type.L3_NET).getName());
1014             //Validate uuid and invariantuuid are populated in model-ver.model-version-id and model.model-invariant-id
1015             Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList()
1016                 .getRelationship().get(0)
1017                 .getRelationshipData().get(0).getRelationshipValue(),key);
1018
1019             Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList().getRelationship().get(0)
1020                 .getRelationshipData().get(1).getRelationshipValue(), nodeTemplateIdTypeStore
1021                 .get(key+"-INV_UID"));
1022           }
1023         }
1024
1025
1026       System.out.println();
1027
1028       }
1029     } catch (IllegalArgumentException e) {
1030       Assert.fail(e.getMessage());    //Can come while populating metadata
1031     }
1032   }
1033
1034   private void validateWidgetIds(List<ModelElement> matchedServiceBaseWidgetElements,
1035                                  String widgetName, String widgetInvUuId) {
1036     Assert.assertEquals(matchedServiceBaseWidgetElements.get(0).getRelationshipList().getRelationship().get(0)
1037         .getRelationshipData().get(0).getRelationshipValue(), properties.getProperty(ArtifactType.AAI.name()
1038         + ".model-version-id."+ widgetName));
1039
1040     Assert.assertEquals(matchedServiceBaseWidgetElements.get(0).getRelationshipList().getRelationship().get(0)
1041         .getRelationshipData().get(1).getRelationshipValue(), widgetInvUuId);
1042   }
1043
1044
1045   public void testL3NetworkResourceTosca(Map<String, Model> outputArtifactMap , ToscaTemplate
1046       resourceTosca) {
1047     try {
1048       if (resourceTosca != null) {
1049         Resource resource = new Resource();
1050         resource.populateModelIdentificationInformation(resourceTosca.getMetadata());
1051         String resourceNameVersionId = resource.getModelNameVersionId();
1052         Model resourceAAIModel =
1053             getAAIModelByNameVersionId(resourceNameVersionId, outputArtifactMap);
1054         if (resourceAAIModel != null) {
1055           validateResourceModelMetadata(resource, resourceAAIModel);
1056           //Validate Resource instance base widget
1057
1058           ModelVer modelVersion = resourceAAIModel.getModelVers().getModelVer().get(0);
1059
1060           List<ModelElement> matchedVFBaseWidgetElements =
1061               getModelElementbyRelationshipValue(modelVersion.getModelElements(),
1062                   Widget.getWidget(Widget.Type.L3_NET).getId());
1063           validateMatchedModelElementsInService(matchedVFBaseWidgetElements,
1064               Widget.getWidget(Widget.Type.L3_NET).getName());
1065
1066           validateWidgetIds(matchedVFBaseWidgetElements, Widget.getWidget(Widget.Type.L3_NET).getName(),
1067               Widget.getWidget(Widget.Type.L3_NET).getWidgetId());
1068
1069         }else {
1070           System.out.println("Resource mapping not found for " + resourceNameVersionId);
1071         }
1072       }
1073
1074     }catch (IllegalArgumentException e) {
1075       Assert.fail(e.getMessage());    //Can come while populating metadata
1076     }
1077
1078   }
1079
1080   public void testAllottedResourceTosca(Map<String, Model> outputArtifactMap , ToscaTemplate
1081       resourceTosca) {
1082     try {
1083       if (resourceTosca != null) {
1084         Resource resource = new Resource();
1085         resource.populateModelIdentificationInformation(resourceTosca.getMetadata());
1086         String resourceNameVersionId = resource.getModelNameVersionId();
1087         Model resourceAAIModel =
1088             getAAIModelByNameVersionId(resourceNameVersionId, outputArtifactMap);
1089         if (resourceAAIModel != null) {
1090           validateResourceModelMetadata(resource, resourceAAIModel);
1091           //Validate Resource instance base widget
1092
1093           ModelVer modelVersion = resourceAAIModel.getModelVers().getModelVer().get(0);
1094
1095           List<ModelElement> matchedVFBaseWidgetElements =
1096               getModelElementbyRelationshipValue(modelVersion.getModelElements(),
1097                   Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getId());
1098           validateMatchedModelElementsInService(matchedVFBaseWidgetElements,
1099               Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getName());
1100
1101           validateWidgetIds(matchedVFBaseWidgetElements, Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getName(),
1102               Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getWidgetId());
1103
1104           Map<String, Object> dependingServiceDetails = getProvidingServiceDetails(resourceTosca);
1105
1106           ModelElements containedModelElements = modelVersion.getModelElements().getModelElement().
1107                   get(0).getModelElements();
1108           Assert.assertEquals( containedModelElements.getModelElement().get(0).getRelationshipList()
1109                 .getRelationship().get(0).getRelationshipData().get(0).getRelationshipValue(),
1110                 dependingServiceDetails.get("providing_service_uuid"));
1111
1112           Assert.assertEquals(containedModelElements.getModelElement().get(0).getRelationshipList()
1113                 .getRelationship().get(0).getRelationshipData().get(1).getRelationshipValue(),
1114                 dependingServiceDetails.get("providing_service_invariant_uuid"));
1115
1116           if("Allotted Resource".equals(resourceTosca.getMetadata().get("category")) &&
1117                   "Tunnel XConnect".equals(resourceTosca.getMetadata().get("subcategory"))) {
1118
1119             List<ModelElement> matchedTunnelXConnectWidgetElements =
1120                     getModelElementbyRelationshipValue(containedModelElements,
1121                             Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getId());
1122             validateMatchedModelElementsInService(matchedTunnelXConnectWidgetElements,
1123                     Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getName());
1124
1125             validateWidgetIds(matchedTunnelXConnectWidgetElements, Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getName(),
1126                     Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getWidgetId());
1127           }
1128
1129         }else {
1130           System.out.println("Resource mapping not found for " + resourceNameVersionId);
1131         }
1132       }
1133
1134     }catch (IllegalArgumentException e) {
1135       Assert.fail(e.getMessage());    //Can come while populating metadata
1136     }
1137
1138   }
1139
1140   public Map<String, Object> getProvidingServiceDetails(ToscaTemplate resourceTemplate) {
1141 Set<String> keys = resourceTemplate.getTopology_template().getNode_templates().keySet();
1142
1143 Map<String, Object> nodeProperties =null;
1144 for(String key : keys) {
1145 NodeTemplate node = resourceTemplate.getTopology_template().getNode_templates().get(key);
1146 if(node.getType().equals("org.openecomp.resource.vfc.AllottedResource")) {
1147 nodeProperties = node.getProperties();
1148   }
1149 }
1150
1151   return nodeProperties;
1152   }
1153
1154   public void testVfTosca(Map<String, Model> outputArtifactMap , ToscaTemplate resourceTosca) {
1155     try {
1156       //ToscaTemplate resourceTosca = getResourceTosca(toscas);
1157       //resourceTosca.getTopology_template().getGroups().
1158       if (resourceTosca != null) {
1159         Resource resource = new Resource();
1160         resource.populateModelIdentificationInformation(resourceTosca.getMetadata());
1161         String resourceNameVersionId = resource.getModelNameVersionId();
1162         Model resourceAAIModel =
1163             getAAIModelByNameVersionId(resourceNameVersionId, outputArtifactMap);
1164         if (resourceAAIModel != null) {
1165           validateResourceModelMetadata(resource, resourceAAIModel);
1166           //Validate Resource instance base widget
1167
1168           ModelVer modelVersion = resourceAAIModel.getModelVers().getModelVer().get(0);
1169
1170           List<ModelElement> matchedVFBaseWidgetElements =
1171               getModelElementbyRelationshipValue(modelVersion.getModelElements(),
1172                   Widget.getWidget(Widget.Type.VF).getId());
1173           validateMatchedModelElementsInService(matchedVFBaseWidgetElements,
1174               Widget.getWidget(Widget.Type.VF).getName());
1175
1176           validateWidgetIds(matchedVFBaseWidgetElements, Widget.getWidget(Widget.Type.VF).getName(),
1177                 Widget.getWidget(Widget.Type.VF).getWidgetId());
1178
1179           ModelElements baseResourceWidgetModelElements =
1180               matchedVFBaseWidgetElements.get(0).getModelElements();
1181           if (resourceTosca.getTopology_template() != null) {
1182             Map<String, String> groupIdTypeStore = getGroupsTypeStore(resourceTosca);
1183
1184             if (baseResourceWidgetModelElements.getModelElement().size() !=
1185                 groupIdTypeStore.size()) {
1186               Assert.fail("Missing VFModule in VF model.xml");
1187             }
1188
1189             for (String key : groupIdTypeStore.keySet()) {
1190
1191               List<ModelElement> matchedResourceElements =
1192                   getModelElementbyRelationshipValue(baseResourceWidgetModelElements, key);
1193               validateMatchedModelElementsInService(matchedResourceElements,
1194                   Widget.getWidget(Widget.Type.VFMODULE).getName());
1195               Model resourceAAIVFModel = getAAIModelByNameVersionId(key, outputArtifactMap);
1196               Map<String, String> vfModuleModelMetadata =
1197                   getVFModuleMetadataTosca(resourceTosca, key);
1198               Map<String, Object> vfModuleMembers = getVFModuleMembersTosca(resourceTosca, key);
1199
1200               validateVFModelMetadata(vfModuleModelMetadata, resourceAAIVFModel);
1201
1202
1203               ModelVer modelVfVersion = resourceAAIVFModel.getModelVers().getModelVer().get(0);
1204
1205               List<ModelElement> matchedVFModuleBaseWidgetElements =
1206                   getModelElementbyRelationshipValue(modelVfVersion.getModelElements(),
1207                       Widget.getWidget(Widget.Type.VFMODULE).getId());
1208               validateMatchedModelElementsInService(matchedVFModuleBaseWidgetElements,
1209                   Widget.getWidget(Widget.Type.VFMODULE).getName());
1210               validateWidgetIds(matchedVFModuleBaseWidgetElements, Widget.getWidget(Widget.Type.VFMODULE)
1211                   .getName(), Widget.getWidget(Widget.Type.VFMODULE).getWidgetId());
1212
1213               ModelElements baseResourceVFModuleWidgetModelElements =
1214                   matchedVFModuleBaseWidgetElements.get(0).getModelElements();
1215              if (vfModuleMembers.containsKey("l3-network")) {
1216                 //Validate l3
1217                 List<ModelElement> matchedL3NetworkElements =
1218                     getModelElementbyRelationshipValue(baseResourceVFModuleWidgetModelElements,
1219                         Widget.getWidget(Widget.Type.L3_NET).getId());
1220                 validateMatchedModelElementsInService(matchedL3NetworkElements,
1221                     Widget.getWidget(Widget.Type.L3_NET).getName());
1222                 validateWidgetIds(matchedL3NetworkElements, Widget.getWidget(Widget.Type.L3_NET)
1223                     .getName(), Widget.getWidget(Widget.Type.L3_NET).getWidgetId());
1224               }
1225               if (vfModuleMembers.containsKey("vserver")) {
1226                 //Validate vserver
1227                 List<ModelElement> matchedVserverElements =
1228                     getModelElementbyRelationshipValue(baseResourceVFModuleWidgetModelElements,
1229                         Widget.getWidget(Widget.Type.VSERVER).getId());
1230                 validateMatchedModelElementsInService(matchedVserverElements,
1231                     Widget.getWidget(Widget.Type.VSERVER).getName());
1232                 ModelElements vserverWidgetModelElements =
1233                     matchedVserverElements.get(0).getModelElements();
1234
1235                 validateWidgetIds(matchedVserverElements, Widget.getWidget(Widget.Type.VSERVER)
1236                     .getName(), Widget.getWidget(Widget.Type.VSERVER).getWidgetId());
1237
1238
1239                 //Validate vserver->vfc
1240                 List<ModelElement> matchedVfcElements =
1241                     getModelElementbyRelationshipValue(vserverWidgetModelElements,
1242                         Widget.getWidget(Widget.Type.VFC).getId());
1243                 validateMatchedModelElementsInService(matchedVfcElements,
1244                     Widget.getWidget(Widget.Type.VFC).getName());
1245                 validateWidgetIds(matchedVfcElements, Widget.getWidget(Widget.Type.VFC).getName(),
1246                     Widget.getWidget(Widget.Type.VFC).getWidgetId());
1247
1248                 //Validate vserver->Image
1249                 List<ModelElement> matchedImageElements =
1250                     getModelElementbyRelationshipValue(vserverWidgetModelElements,
1251                         Widget.getWidget(Widget.Type.IMAGE).getId());
1252                 validateMatchedModelElementsInService(matchedImageElements,
1253                     Widget.getWidget(Widget.Type.IMAGE).getName());
1254                 validateWidgetIds(matchedImageElements, Widget.getWidget(Widget.Type.IMAGE)
1255                     .getName(), Widget.getWidget(Widget.Type.IMAGE).getWidgetId());
1256
1257
1258                 //Validate vserver->Flavor
1259                 List<ModelElement> matchedFlavorElements =
1260                     getModelElementbyRelationshipValue(vserverWidgetModelElements,
1261                         Widget.getWidget(Widget.Type.FLAVOR).getId());
1262                 validateMatchedModelElementsInService(matchedFlavorElements,
1263                     Widget.getWidget(Widget.Type.FLAVOR).getName());
1264                 validateWidgetIds(matchedFlavorElements, Widget.getWidget(Widget.Type.FLAVOR).getName(),
1265                     Widget.getWidget(Widget.Type.FLAVOR).getWidgetId());
1266
1267                 //Validate vserver->Tenant
1268                 List<ModelElement> matchedTenantElements =
1269                     getModelElementbyRelationshipValue(vserverWidgetModelElements,
1270                         Widget.getWidget(Widget.Type.TENANT).getId());
1271                 validateMatchedModelElementsInService(matchedTenantElements,
1272                     Widget.getWidget(Widget.Type.TENANT).getName());
1273                 validateWidgetIds(matchedTenantElements, Widget.getWidget(Widget.Type.TENANT).getName(),
1274                     Widget.getWidget(Widget.Type.TENANT).getWidgetId());
1275
1276                 //Validate vserver->l-interface
1277                 if (vfModuleMembers.containsKey("l-interface")) {
1278                   List<ModelElement> matchedLinterfaceElements =
1279                       getModelElementbyRelationshipValue(vserverWidgetModelElements,
1280                           Widget.getWidget(Widget.Type.LINT).getId());
1281                   validateMatchedModelElementsInService(matchedLinterfaceElements,
1282                       Widget.getWidget(Widget.Type.LINT).getName());
1283                   validateWidgetIds(matchedLinterfaceElements, Widget.getWidget(Widget.Type.LINT).getName(),
1284                       Widget.getWidget(Widget.Type.LINT).getWidgetId());
1285                 }
1286                 //Validate vserver->volume
1287                 if (vfModuleMembers.containsKey("volume")) {
1288                   List<ModelElement> matchedVolumeElements =
1289                       getModelElementbyRelationshipValue(vserverWidgetModelElements,
1290                           Widget.getWidget(Widget.Type.VOLUME).getId());
1291                   validateMatchedModelElementsInService(matchedVolumeElements,
1292                       Widget.getWidget(Widget.Type.VOLUME).getName());
1293                   validateWidgetIds(matchedVolumeElements, Widget.getWidget(Widget.Type.VOLUME).getName(),
1294                       Widget.getWidget(Widget.Type.VOLUME).getWidgetId());
1295                 }
1296               }
1297             }
1298           }
1299         } else {
1300           System.out.println("Resource mapping not found for " + resourceNameVersionId);
1301         }
1302       }
1303
1304     } catch (IllegalArgumentException e) {
1305       Assert.fail(e.getMessage());    //Can come while populating metadata
1306     }
1307
1308   }
1309
1310   private void validateMatchedModelElementsInService(List<ModelElement> matchedModelElements,
1311                                                      String modelType) {
1312     if (matchedModelElements.isEmpty()) {
1313       Assert.fail(modelType + " not present ");
1314     }
1315     if (matchedModelElements.size() > 1) {
1316       Assert.fail("More than one " + modelType + " present ");
1317     }
1318   }
1319
1320   private Map<String, String> getNodeTemplateTypeStore(ToscaTemplate toscaTemplate) {
1321     if (toscaTemplate.getTopology_template() != null) {
1322       Map<String, NodeTemplate> nodeTemplateMap =
1323           toscaTemplate.getTopology_template().getNode_templates();
1324       Map<String, String> nodeTemplateIdTypeStore = new LinkedHashMap<>();
1325       if (nodeTemplateMap != null) {
1326         for (Map.Entry<String, NodeTemplate> e : nodeTemplateMap.entrySet()) {
1327           String uuid = e.getValue().getMetadata().get("resourceUUID");
1328           if (GeneratorUtil.isEmpty(uuid)) {
1329             uuid = e.getValue().getMetadata().get("UUID");
1330             if (GeneratorUtil.isEmpty(uuid)) {
1331               Assert.fail("UUID Not found");
1332             }
1333           }
1334           if(e.getValue().getType().contains("org.openecomp.resource.vf.")&& (e.getValue()
1335               .getMetadata().get("category").equals("Allotted Resource")))
1336           {
1337             e.getValue().setType("org.openecomp.resource.vf.allottedResource");
1338           }
1339           nodeTemplateIdTypeStore.put(uuid, e.getValue().getType());
1340           resourcesVersion.put(uuid,e.getValue().getMetadata().get
1341               ("version"));
1342           //Populate invraintUuId for V9
1343           String invUuId = e.getValue().getMetadata().get("invariantUUID");
1344           nodeTemplateIdTypeStore.put(uuid+"-INV_UID" , invUuId);
1345         }
1346       }
1347       return nodeTemplateIdTypeStore;
1348     } else {
1349       return null;
1350     }
1351   }
1352
1353   private Map<String, String> getGroupsTypeStore(ToscaTemplate toscaTemplate) {
1354     if (toscaTemplate.getTopology_template() != null) {
1355       Map<String, GroupDefinition> groupDefinitionMap =
1356           toscaTemplate.getTopology_template().getGroups();
1357       Map<String, String> groupDefinitionIdTypeStore = new LinkedHashMap<>();
1358       if (groupDefinitionMap != null) {
1359         for (Map.Entry<String, GroupDefinition> e : groupDefinitionMap.entrySet()) {
1360           if (e.getValue().getType().contains("org.openecomp.groups.VfModule")) {
1361             String uuid = e.getValue().getMetadata().get("vfModuleModelUUID");
1362             if (GeneratorUtil.isEmpty(uuid)) {
1363               uuid = e.getValue().getMetadata().get("UUID");
1364               if (GeneratorUtil.isEmpty(uuid)) {
1365                 Assert.fail("UUID Not found");
1366               }
1367             }
1368             groupDefinitionIdTypeStore.put(uuid, e.getValue().getType());
1369           }
1370         }
1371       }
1372       return groupDefinitionIdTypeStore;
1373     } else {
1374       return null;
1375     }
1376
1377   }
1378
1379   private void validateServiceModelMetadata(Service serviceToscaModel, Model generatedAAIModel) {
1380     ModelVer modelVersion =  generatedAAIModel.getModelVers().getModelVer().get(0);
1381     Assert.assertEquals(serviceToscaModel.getModelNameVersionId(),
1382         modelVersion.getModelVersionId());
1383     Assert.assertEquals(serviceToscaModel.getModelId(), generatedAAIModel.getModelInvariantId());
1384     Assert.assertEquals(serviceToscaModel.getModelName(), modelVersion.getModelName());
1385     Assert.assertEquals(additionalParams.get(AdditionalParams.ServiceVersion.getName()), modelVersion
1386         .getModelVersion());
1387     Assert.assertEquals(serviceToscaModel.getModelDescription(),
1388         modelVersion.getModelDescription());
1389
1390   }
1391
1392   private void validateResourceModelMetadata(Resource resouerceToscaModel,
1393                                              Model generatedAAIModel) {
1394     ModelVer modelVersion =  generatedAAIModel.getModelVers().getModelVer().get(0);
1395     Assert.assertEquals(resouerceToscaModel.getModelNameVersionId(),
1396         modelVersion.getModelVersionId());
1397     Assert.assertEquals(resouerceToscaModel.getModelId(), generatedAAIModel.getModelInvariantId());
1398     Assert.assertEquals(resouerceToscaModel.getModelName(), modelVersion.getModelName());
1399     Assert
1400         .assertEquals(resouerceToscaModel.getModelVersion(), modelVersion.getModelVersion());
1401     Assert.assertEquals(resouerceToscaModel.getModelDescription(),
1402         modelVersion.getModelDescription());
1403
1404   }
1405
1406   private void validateVFModelMetadata(Map<String, String> vfModuleModelMetadata,
1407                                        Model generatedAAIModel) {
1408     ModelVer modelVersion =  generatedAAIModel.getModelVers().getModelVer().get(0);
1409     Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelUUID"),
1410         modelVersion.getModelVersionId());
1411     Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelInvariantUUID"),
1412         generatedAAIModel.getModelInvariantId());
1413     Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelName"),
1414         modelVersion.getModelName());
1415     Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelVersion"),
1416         modelVersion.getModelVersion());
1417     Assert.assertEquals(vfModuleModelMetadata.get("vf_module_description"),
1418         modelVersion.getModelDescription());
1419   }
1420
1421   private Model getAAIModelByNameVersionId(String nameVersionId,
1422                                            Map<String, Model> outputArtifactMap) {
1423     return outputArtifactMap.get(nameVersionId);
1424   }
1425
1426   private List<ModelElement> getModelElementbyRelationshipValue(ModelElements modelElements,
1427                                                                 String relationshipValue) {
1428     List<ModelElement> matchedModelElements = new ArrayList<>();
1429     if (modelElements != null) {
1430       List<ModelElement> modelElementList = modelElements.getModelElement();
1431       for (ModelElement element : modelElementList) {
1432         List<Relationship> relationshipList = element.getRelationshipList().getRelationship();
1433         for (Relationship r : relationshipList) {
1434           List<RelationshipData> relationshipDataList = r.getRelationshipData();
1435           for (RelationshipData relationshipData : relationshipDataList) {
1436             if (relationshipData.getRelationshipValue().equals(relationshipValue)) {
1437               matchedModelElements.add(element);
1438             }
1439           }
1440         }
1441       }
1442     }
1443     return matchedModelElements;
1444   }
1445
1446   private Map<String, Model> populateAAIGeneratedModelStore(List<Artifact> resultData) throws IOException {
1447     Map<String, Model> outputArtifactMap = new HashMap<>();
1448     for (Artifact outputArtifact : resultData) {
1449       if (outputArtifact.getType().equals(ArtifactType.MODEL_INVENTORY_PROFILE.name())) {
1450         byte[] decodedPayload = GeneratorUtil.decoder(outputArtifact.getPayload());
1451         Model aaiModel = getUnmarshalledArtifactModel(new String(decodedPayload));
1452         List<ModelVer> modelVersions =  aaiModel.getModelVers().getModelVer();
1453         outputArtifactMap.put(modelVersions.get(0).getModelVersionId(), aaiModel);
1454       }
1455     }
1456     return outputArtifactMap;
1457   }
1458
1459   private Model getUnmarshalledArtifactModel(String aaiModel) throws IOException {
1460
1461     try {
1462
1463       JAXBContext jaxbContext = JAXBContext.newInstance(Model.class);
1464       Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
1465
1466       try (InputStream aaiModelStream = new ByteArrayInputStream(aaiModel.getBytes())) {
1467         return (Model) unmarshaller.unmarshal(aaiModelStream);
1468       }
1469
1470     } catch (JAXBException e) {
1471       e.printStackTrace();
1472     }
1473
1474     return null;
1475   }
1476
1477   /**
1478    * Get the tosca java model from the tosca input artifact
1479    *
1480    * @param input Input tosca file and its metadata information as {@link Artifact} object
1481    * @return Translated {@link ToscaTemplate tosca} object
1482    */
1483   private ToscaTemplate getToscaModel(Artifact input) throws SecurityException {
1484     byte[] decodedInput = GeneratorUtil.decoder(input.getPayload());
1485     String checksum = GeneratorUtil.checkSum(decodedInput);
1486     if (checksum.equals(input.getChecksum())) {
1487       try {
1488         return GeneratorUtil.translateTosca(new String(decodedInput), ToscaTemplate.class);
1489       } catch (Exception e) {
1490         e.printStackTrace();
1491         throw new IllegalArgumentException(
1492             String.format(GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_TOSCA, input.getName()));
1493       }
1494     } else {
1495       throw new SecurityException(
1496           String.format(GeneratorConstants.GENERATOR_AAI_ERROR_CHECKSUM_MISMATCH, input.getName()));
1497     }
1498   }
1499
1500   /**
1501    * Identify the service tosca artifact from the list of translated tosca inputs
1502    *
1503    * @param input List of translated {@link ToscaTemplate tosca} object models
1504    * @return Identified service {@link ToscaTemplate tosca}
1505    */
1506   private ToscaTemplate getServiceTosca(List<ToscaTemplate> input) {
1507     Iterator<ToscaTemplate> iter = input.iterator();
1508     while (iter.hasNext()) {
1509       ToscaTemplate tosca = iter.next();
1510       if (tosca.isService()) {
1511         iter.remove();
1512         return tosca;
1513       }
1514     }
1515     return null;
1516   }
1517
1518   private Map<String, String> getVFModuleMetadataTosca(ToscaTemplate toscaTemplate,
1519                                                        String vfModuleModelUUID) {
1520     Map<String, GroupDefinition> groupDefinitionMap =
1521         toscaTemplate.getTopology_template().getGroups();
1522     Map<String, String> vfModuleModelMetadata = new LinkedHashMap<>();
1523     for (Map.Entry<String, GroupDefinition> e : groupDefinitionMap.entrySet()) {
1524       if (e.getValue().getType().contains("org.openecomp.groups.VfModule")) {
1525         String uuid = e.getValue().getMetadata().get("vfModuleModelUUID");
1526         if (Objects.equals(uuid, vfModuleModelUUID)) {
1527           vfModuleModelMetadata = e.getValue().getMetadata();
1528           vfModuleModelMetadata.put("vf_module_description",
1529               (String) e.getValue().getProperties().get("vf_module_description"));
1530         }
1531       }
1532     }
1533     return vfModuleModelMetadata;
1534   }
1535
1536   private Map<String, Object> getVFModuleMembersTosca(ToscaTemplate toscaTemplate,
1537                                                       String vfModuleModelUUID) {
1538     Map<String, GroupDefinition> groupDefinitionMap =
1539         toscaTemplate.getTopology_template().getGroups();
1540     Map<String, NodeTemplate> nodeTemplateMaps =
1541         toscaTemplate.getTopology_template().getNode_templates();
1542     Map<String, Object> vfModuleMembers = new LinkedHashMap<>();
1543     List<String> vfModuleModelMetadata;
1544     for (Map.Entry<String, GroupDefinition> e : groupDefinitionMap.entrySet()) {
1545       if (e.getValue().getType().contains("org.openecomp.groups.VfModule")) {
1546         String uuid = e.getValue().getMetadata().get("vfModuleModelUUID");
1547         if (Objects.equals(uuid, vfModuleModelUUID)) {
1548           vfModuleModelMetadata = e.getValue().getMembers();
1549           if (vfModuleModelMetadata !=null) {
1550             for (Object key : vfModuleModelMetadata) {
1551               NodeTemplate nodeTemplate = nodeTemplateMaps.get(key);
1552               String nodetype = null;
1553               if (nodeTemplate != null) {
1554                 nodetype = nodeTemplate.getType();
1555               }
1556               if (nodetype != null) {
1557                 String widgetType = membersType(nodetype);
1558                 if (widgetType != null) {
1559                   vfModuleMembers.put(widgetType, key);
1560                 }
1561               }
1562             }
1563           }
1564         }
1565       }
1566     }
1567
1568     return vfModuleMembers;
1569   }
1570
1571
1572   private String membersType(String toscaType) {
1573     String modelToBeReturned = null;
1574     while (toscaType != null && toscaType.lastIndexOf(".") != -1 && modelToBeReturned == null) {
1575
1576       switch (toscaType) {
1577         case "org.openecomp.resource.vf.allottedResource":
1578           modelToBeReturned = "allotted-resource";
1579           break;
1580         case "org.openecomp.resource.vfc":
1581           modelToBeReturned = "vserver";
1582           break;
1583         case "org.openecomp.resource.cp":
1584         case "org.openecomp.cp":
1585           modelToBeReturned = "l-interface";
1586           break;
1587         case "org.openecomp.resource.vl":
1588           modelToBeReturned = "l3-network";
1589           break;
1590         case "org.openecomp.resource.vf":
1591           modelToBeReturned = "generic-vnf";
1592           break;
1593         case "org.openecomp.groups.VfModule":
1594           modelToBeReturned = "vf-module";
1595           break;
1596         case "org.openecomp.resource.vfc.nodes.heat.cinder":
1597           modelToBeReturned = "volume";
1598           break;
1599         default:
1600           modelToBeReturned = null;
1601           break;
1602       }
1603
1604       toscaType = toscaType.substring(0, toscaType.lastIndexOf("."));
1605     }
1606     return modelToBeReturned;
1607   }
1608
1609   private List<Artifact> init(String aaiResourceBasePaths) {
1610     List<Artifact> inputArtifacts1 = new ArrayList<>();
1611     try {
1612
1613       String[] resourceFileList = {};
1614       URL resourceDirUrl = this.getClass().getClassLoader().getResource(aaiResourceBasePaths);
1615       if (resourceDirUrl != null && resourceDirUrl.getProtocol().equals("file")) {
1616         resourceFileList = new File(resourceDirUrl.toURI()).list();
1617       } else {
1618         Assert.fail("Invalid resource directory");
1619       }
1620
1621       for (String aResourceFileList : resourceFileList) {
1622         File resourceFile = new File(
1623                 this.getClass().getClassLoader().getResource(aaiResourceBasePaths + aResourceFileList)
1624                         .getPath());
1625
1626         //convert service tosca file into array of bytes
1627         byte[] payload = new byte[(int) resourceFile.length()];
1628         try (FileInputStream fileInputStream = new FileInputStream(resourceFile)) {
1629           fileInputStream.read(payload);
1630         }
1631
1632         String checksum = GeneratorUtil.checkSum(payload);
1633         byte[] encodedPayload = GeneratorUtil.encode(payload);
1634         Artifact artifact =
1635                 new Artifact(aaiArtifactType, aaiArtifactGroupType, checksum, encodedPayload);
1636         artifact.setName(aResourceFileList);
1637         artifact.setLabel(aResourceFileList);
1638         artifact.setDescription(aResourceFileList);
1639         artifact.setVersion("1.0");
1640         inputArtifacts1.add(artifact);
1641
1642       }
1643     } catch (Exception e) {
1644       //e.printStackTrace();
1645       Assert.fail(e.getMessage());
1646     }
1647     return inputArtifacts1;
1648   }
1649
1650   private void loadConfigFromClasspath(Properties properties) throws IOException {
1651     String configLocation = System.getProperty("artifactgenerator.config");
1652     if (configLocation != null) {
1653       File file = new File(configLocation);
1654       if (file.exists()) {
1655         properties.load(new FileInputStream(file));
1656       }
1657     }
1658   }
1659
1660   public  void testResourceTosca(Iterator<ToscaTemplate> itr, Map<String, Model>
1661       outputArtifactMap) {
1662     while(itr.hasNext()){
1663       ToscaTemplate toscaTemplate = itr.next();
1664       String resourceVersion=resourcesVersion.get(toscaTemplate.getMetadata().get("UUID"));
1665       toscaTemplate.getMetadata().put("version", resourceVersion);
1666       if("VF".equals(toscaTemplate.getMetadata().get("type")) && !("Allotted Resource".equals
1667           (toscaTemplate.getMetadata().get("category"))) ){
1668         testVfTosca(outputArtifactMap, toscaTemplate);
1669       } else if("VF".equals(toscaTemplate.getMetadata().get("type")) && ("Allotted Resource".equals
1670           (toscaTemplate.getMetadata().get("category"))) ){
1671         testAllottedResourceTosca(outputArtifactMap, toscaTemplate);
1672       } else if("VL".equals(toscaTemplate.getMetadata().get("type"))){
1673         testL3NetworkResourceTosca(outputArtifactMap, toscaTemplate);
1674       }
1675     }
1676   }
1677
1678   private void readPayloadFromResource(List<Artifact> inputArtifacts, String file) throws IOException {
1679     try (InputStream stream = ArtifactGenerationServiceTest.class.getResourceAsStream("/" + file)) {
1680       readPayload(inputArtifacts, stream, file);
1681     }
1682   }
1683 }