[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / common / openecomp-sdc-artifact-generator-lib / openecomp-sdc-artifact-generator-test / src / main / java / org / openecomp / sdc / generator / SampleJUnitTest.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 org.openecomp.sdc.generator.aai.model.Widget;
24 import org.openecomp.sdc.generator.aai.tosca.ToscaTemplate;
25 import org.openecomp.sdc.generator.aai.xml.Model;
26 import org.openecomp.sdc.generator.data.*;
27 import org.openecomp.sdc.generator.impl.ArtifactGenerationServiceImpl;
28
29 import junit.framework.TestCase;
30 import org.junit.Assert;
31 import org.junit.Test;
32
33 import java.io.*;
34 import java.util.*;
35
36 import static org.openecomp.sdc.generator.ArtifactGenerationServiceTest.*;
37 import static org.openecomp.sdc.generator.data.GeneratorConstants.*;
38
39 public class SampleJUnitTest extends TestCase {
40
41     public static final String aaiArtifactType = ArtifactType.AAI.name();
42     public static final String aaiArtifactGroupType = GroupType.DEPLOYMENT.name();
43     public static final String generatorConfig = "{\"artifactTypes\": [\"OTHER\",\"AAI\"]}";
44     public static final String ARTIFACTGENERATOR_CONFIG = "artifactgenerator.config";
45     public static final String CONFIG_PATH = "/qa-test-repo/jmeter3/apache-jmeter-3" +
46         ".0/lib/junit/";
47     //public static final String CONFIG_PATH ="C:\\Jmeter-Copy\\jmeter3\\apache-jmeter-3" +
48         //".0\\lib\\junit\\";
49     public static final String GENERATOR_AAI_CONFIGLPROP_NOT_FOUND =
50         "Cannot generate artifacts. Widget configuration not found for %s";
51     public static final String GENERATOR_AAI_CONFIGFILE_NOT_FOUND =
52         "Cannot generate artifacts. Artifact Generator Configuration file not found at %s";
53     public static final String GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND =
54         "Cannot generate artifacts. artifactgenerator.config system property not configured";
55     public static final String INVALID_VALUE_INVARIANT =
56         "Invalid value for mandatory attribute <invariantUUID> in Artifact";
57     public static final String INVALID_VALUE_UUID =
58         "Invalid value for mandatory attribute <UUID> in Artifact:";
59     public static final Map<String, String> additionalParams = new HashMap<>();
60
61     static{
62         additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
63     }
64
65     private void loadConfig(Properties properties) throws IOException {
66         String configLocation = System.getProperty(ARTIFACTGENERATOR_CONFIG);
67         if (configLocation != null) {
68             File file = new File(configLocation);
69             if (file.exists()) {
70                 properties.load(new FileInputStream(file));
71             }
72         }
73     }
74     public SampleJUnitTest(String name) throws Exception {
75         super(name);
76         System.setProperty(ARTIFACTGENERATOR_CONFIG,CONFIG_PATH+"Artifact-Generator.properties");
77         loadConfig(ArtifactGenerationServiceTest.properties);
78     }
79
80     public SampleJUnitTest() {
81         super();
82         System.setProperty(ARTIFACTGENERATOR_CONFIG,CONFIG_PATH+"Artifact-Generator.properties");
83     }
84
85     @Test
86     public void testArtifactGenerationSingleVFSingleVFModule() {
87         try {
88             List<Artifact> inputArtifacts = new ArrayList();
89             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_SingleVFVFMod.yml");
90             readPayload(inputArtifacts, fis1, "vf_vmme_template_SingleVFVFMod.yml");
91
92             fis1.close();
93             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_SingleVFVFMod.yml");
94             readPayload(inputArtifacts, fis2, "service_vmme_template_SingleVFVFMod.yml");
95             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
96             List<ToscaTemplate> toscas = new LinkedList();
97
98             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
99
100             for (Artifact inputArtifact : inputArtifacts) {
101                 toscas.add(getToscaModel(inputArtifact));
102             }
103             List<Artifact> resultData = data.getResultData();
104
105             Map<String, Model> outputArtifactMap = new HashMap<>();
106             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
107             ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
108
109             testResourceTosca(toscas.iterator(), outputArtifactMap);
110
111             Assert.assertEquals(5, data.getResultData().size());
112
113             removeMockArtifact(data.getResultData().iterator());
114
115             ArtifactGenerationServiceTest.validateName(data.getResultData());
116
117
118         } catch (Exception e) {
119             Assert.fail(e.getMessage());
120         }
121     }
122
123     @Test
124     public void testArtifactGenerationMissingVFInServiceTOSCA() {
125         try {
126             List<Artifact> inputArtifacts = new ArrayList();
127             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_MissingVFInServiceTOSCA.yml");
128             readPayload(inputArtifacts, fis2, "service_vmme_template_MissingVFInServiceTOSCA.yml");
129             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
130             List<ToscaTemplate> toscas = new LinkedList();
131
132             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
133
134             for (Artifact inputArtifact : inputArtifacts) {
135                 toscas.add(getToscaModel(inputArtifact));
136             }
137             List<Artifact> resultData = data.getResultData();
138
139             Map<String, Model> outputArtifactMap = new HashMap<>();
140             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
141             ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
142
143             Assert.assertEquals(3, data.getResultData().size());
144
145             removeMockArtifact(data.getResultData().iterator());
146
147             ArtifactGenerationServiceTest.validateName(data.getResultData());
148
149
150         } catch (Exception e) {
151             Assert.fail(e.getMessage());
152         }
153     }
154
155     @Test
156     public void testArtifactGenerationVerifySameStaticWidgetsForAllServices() {
157         try {
158             List<Artifact> inputArtifacts = new ArrayList();
159             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_SameWidgets1.yml");
160             readPayload(inputArtifacts, fis1, "vf_vmme_template_SameWidgets1.yml");
161
162             fis1.close();
163             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_SameWidget1.yml");
164             readPayload(inputArtifacts, fis2, "service_vmme_template_SameWidget1.yml");
165             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
166             List<ToscaTemplate> toscas = new LinkedList();
167
168             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
169
170             for (Artifact inputArtifact : inputArtifacts) {
171                 toscas.add(getToscaModel(inputArtifact));
172             }
173             List<Artifact> resultData = data.getResultData();
174
175             Map<String, Model> outputArtifactMap = new HashMap<>();
176             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
177
178             removeMockArtifact(data.getResultData().iterator());
179
180
181             List<Artifact> inputArtifacts2 = new ArrayList();
182             InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_SameWidgets2.yml");
183             readPayload(inputArtifacts2, fis3, "vf_vmme_template_SameWidgets2.yml");
184
185             InputStream fis4 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_SameWidget2.yml");
186             readPayload(inputArtifacts2, fis4, "service_vmme_template_SameWidget2.yml");
187             ArtifactGenerationServiceImpl obj2 = new ArtifactGenerationServiceImpl();
188
189             GenerationData data2 = obj2.generateArtifact(inputArtifacts2, generatorConfig,additionalParams);
190             List<Artifact> resultData2 = data2.getResultData();
191
192             List<ToscaTemplate> toscas2 = new LinkedList();
193
194             for (Artifact inputArtifact : inputArtifacts2) {
195                 toscas2.add(getToscaModel(inputArtifact));
196             }
197
198             Map<String, Model> outputArtifactMap2 = new HashMap<>();
199             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap2, resultData2);
200             removeMockArtifact(data2.getResultData().iterator());
201
202             Map<String,String> map = new HashMap<>();
203             Iterator<Artifact> itr =  data.getResultData().iterator();
204                     while(itr.hasNext()){
205                         Artifact artifact=itr.next();
206                         if(artifact.getLabel().contains("AAI-widget")){
207                             map.put(artifact.getName(),artifact.getChecksum());
208                         }
209                     }
210             Map<String,String> map2 = new HashMap<>();
211             Iterator<Artifact> itr2 =  data2.getResultData().iterator();
212             while(itr2.hasNext()){
213                 Artifact artifact=itr2.next();
214                 if(artifact.getLabel().contains("AAI-widget")){
215                     map2.put(artifact.getName(),artifact.getChecksum());
216                 }
217             }
218             Assert.assertEquals(map.size(),map2.size());
219             for(String name : map.keySet()){
220                 Assert.assertEquals(map.get(name),map2.get(name));
221             }
222
223         } catch (Exception e) {
224             Assert.fail(e.getMessage());
225         }
226     }
227
228     @Test
229     public void testArtifactGenerationMulVFModule() {
230         try {
231             List<Artifact> inputArtifacts = new ArrayList();
232             String[] resourceFileList = {};
233             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_MulVFVFMod.yml");
234             readPayload(inputArtifacts,fis1, "vf_vmme_template_MulVFVFMod.yml");
235
236             fis1.close();
237             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_MulVFVFMod.yml");
238             readPayload(inputArtifacts,fis2, "service_vmme_template_MulVFVFMod.yml");
239
240             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
241             List<ToscaTemplate> toscas = new LinkedList();
242
243             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
244
245                 for (Artifact inputArtifact : inputArtifacts) {
246                     toscas.add(getToscaModel(inputArtifact));
247                 }
248                 List<Artifact> resultData = data.getResultData();
249
250                 Map<String, Model> outputArtifactMap = new HashMap<>();
251                 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
252                 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
253                 testResourceTosca(toscas.iterator(), outputArtifactMap);
254
255             Assert.assertEquals(3,data.getResultData().size());
256
257             removeMockArtifact(data.getResultData().iterator());
258
259             ArtifactGenerationServiceTest.validateName(data.getResultData());
260
261         } catch (Exception e) {
262             Assert.fail(e.getMessage());
263         }
264     }
265
266     @Test
267     public void testArtifactGenerationMulVFs() {
268         try {
269             List<Artifact> inputArtifacts = new ArrayList();
270
271             InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/CMAUI_VF.yaml");
272             readPayload(inputArtifacts,fis3, "CMAUI_VF.yaml");
273
274             InputStream fis4 = SampleJUnitTest.class.getResourceAsStream("/ECA_OAM_VF.yaml");
275             readPayload(inputArtifacts,fis4, "ECA_OAM_VF.yaml");
276
277             InputStream fis5 = SampleJUnitTest.class.getResourceAsStream("/MMSC_Sevice_07_25_16.yaml");
278             readPayload(inputArtifacts,fis5, "MMSC_Sevice_07_25_16.yaml");
279
280             InputStream fis6 = SampleJUnitTest.class.getResourceAsStream("/MMSC_VF.yaml");
281             readPayload(inputArtifacts,fis6, "MMSC_VF.yaml");
282
283             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
284             List<ToscaTemplate> toscas = new LinkedList();
285
286             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
287
288             for (Artifact inputArtifact : inputArtifacts) {
289                 toscas.add(getToscaModel(inputArtifact));
290             }
291             List<Artifact> resultData = data.getResultData();
292
293             Map<String, Model> outputArtifactMap = new HashMap<>();
294             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
295             ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
296             testResourceTosca(toscas.iterator(), outputArtifactMap);
297
298             Assert.assertEquals(8,data.getResultData().size());
299
300             removeMockArtifact(data.getResultData().iterator());
301
302             ArtifactGenerationServiceTest.validateName(data.getResultData());
303
304         } catch (Exception e) {
305             Assert.fail(e.getMessage());
306         }
307     }
308
309     @Test
310     public void testArtifactGenerationDupVFUUID() {
311         try {
312             List<Artifact> inputArtifacts = new ArrayList();
313             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_DupVFUUID.yml");
314             readPayload(inputArtifacts,fis1, "vf_vmme_template_DupVFUUID.yml");
315
316             fis1.close();
317             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_DupVFUUID.yml");
318             readPayload(inputArtifacts,fis2, "service_vmme_template_DupVFUUID.yml");
319             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
320             List<ToscaTemplate> toscas = new LinkedList();
321
322             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
323
324                 for (Artifact inputArtifact : inputArtifacts) {
325                     toscas.add(getToscaModel(inputArtifact));
326                 }
327                 List<Artifact> resultData = data.getResultData();
328
329                 Map<String, Model> outputArtifactMap = new HashMap<>();
330                 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
331                 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
332                 testResourceTosca(toscas.iterator(), outputArtifactMap);
333
334             Assert.assertEquals(5,data.getResultData().size());
335
336             removeMockArtifact(data.getResultData().iterator());
337
338             ArtifactGenerationServiceTest.validateName(data.getResultData());
339
340         } catch (Exception e) {
341             Assert.fail(e.getMessage());
342         }
343     }
344
345     @Test
346     public void testArtifactGenerationDupVFModUUID() {
347         try {
348             List<Artifact> inputArtifacts = new ArrayList();
349             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_DupVFModUUID.yml");
350             readPayload(inputArtifacts,fis1, "vf_vmme_template_DupVFModUUID.yml");
351
352             fis1.close();
353             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_DupVFModUUID.yml");
354             readPayload(inputArtifacts,fis2, "service_vmme_template_DupVFModUUID.yml");
355             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
356             List<ToscaTemplate> toscas = new LinkedList();
357
358             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
359
360                 for (Artifact inputArtifact : inputArtifacts) {
361                     toscas.add(getToscaModel(inputArtifact));
362                 }
363                 List<Artifact> resultData = data.getResultData();
364
365                 Map<String, Model> outputArtifactMap = new HashMap<>();
366                 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
367                 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
368                 testResourceTosca(toscas.iterator(), outputArtifactMap);
369
370             Assert.assertEquals(5,data.getResultData().size());
371
372             removeMockArtifact(data.getResultData().iterator());
373
374             ArtifactGenerationServiceTest.validateName(data.getResultData());
375         } catch (Exception e) {
376             Assert.fail(e.getMessage());
377         }
378     }
379
380     @Test
381     public void testArtifactGenerationVerifyVFModWithoutVNFC() {
382         try {
383             List<Artifact> inputArtifacts = new ArrayList();
384             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyVFModWithoutVNFC.yml");
385             readPayload(inputArtifacts,fis1, "vf_vmme_template_VerifyVFModWithoutVNFC.yml");
386
387             fis1.close();
388             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyVFModWithoutVNFC.yml");
389             readPayload(inputArtifacts,fis2, "service_vmme_template_VerifyVFModWithoutVNFC.yml");
390             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
391             List<ToscaTemplate> toscas = new LinkedList();
392
393             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
394
395                 for (Artifact inputArtifact : inputArtifacts) {
396                     toscas.add(getToscaModel(inputArtifact));
397                 }
398                 List<Artifact> resultData = data.getResultData();
399
400                 Map<String, Model> outputArtifactMap = new HashMap<>();
401                 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
402                 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
403                 testResourceTosca(toscas.iterator(), outputArtifactMap);
404
405             Assert.assertEquals(5,data.getResultData().size());
406
407             removeMockArtifact(data.getResultData().iterator());
408
409             ArtifactGenerationServiceTest.validateName(data.getResultData());
410         } catch (Exception e) {
411             Assert.fail(e.getMessage());
412         }
413     }
414
415     @Test
416     public void testArtifactGenerationVerifyVFModWithInvalidMember() {
417         try {
418             List<Artifact> inputArtifacts = new ArrayList();
419             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyVFModWithInvalidNo.yml");
420             readPayload(inputArtifacts,fis1, "vf_vmme_template_VerifyVFModWithInvalidNo.yml");
421
422             fis1.close();
423             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyVFModWithInvalidNo.yml");
424             readPayload(inputArtifacts,fis2, "service_vmme_template_VerifyVFModWithInvalidNo.yml");
425             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
426             List<ToscaTemplate> toscas = new LinkedList();
427
428             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
429
430                 for (Artifact inputArtifact : inputArtifacts) {
431                     toscas.add(getToscaModel(inputArtifact));
432                 }
433                 List<Artifact> resultData = data.getResultData();
434
435                 Map<String, Model> outputArtifactMap = new HashMap<>();
436                 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
437                 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
438                 testResourceTosca(toscas.iterator(), outputArtifactMap);
439
440             Assert.assertEquals(5,data.getResultData().size());
441
442             removeMockArtifact(data.getResultData().iterator());
443
444             ArtifactGenerationServiceTest.validateName(data.getResultData());
445         } catch (Exception e) {
446             Assert.fail(e.getMessage());
447         }
448     }
449
450     @Test
451     public void testArtifactGenerationNullFields() {
452         try {
453             List<Artifact> inputArtifacts = new ArrayList();
454             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_NullFields.yml");
455             readPayload(inputArtifacts,fis1, "vf_vmme_template_NullFields.yml");
456
457             fis1.close();
458             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_NullFields.yml");
459             readPayload(inputArtifacts,fis2, "service_vmme_template_NullFields.yml");
460             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
461
462             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
463             Assert.assertEquals(false,data.getErrorData().isEmpty());
464
465             Assert.assertEquals("Invalid Service/Resource definition mandatory attribute <UUID> missing in Artifact: <"+inputArtifacts.get(0).getName()+">",data.getErrorData().get("AAI").get(0));
466
467             Assert.assertEquals(2,data.getResultData().size());
468
469         } catch (Exception e) {
470             e.printStackTrace();
471             Assert.fail(e.getMessage());
472         }
473     }
474
475     @Test
476     public void testArtifactGenerationInCorrectYmlFormat() {
477         try {
478             List<Artifact> inputArtifacts = new ArrayList();
479
480             InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/CMAUI_VFInvalidFormat.yaml");
481             readPayload(inputArtifacts,fis3, "CMAUI_VFInvalidFormat.yaml");
482
483             InputStream fis4 = SampleJUnitTest.class.getResourceAsStream("/ECA_OAM_VFInvalidFormat.yaml");
484             readPayload(inputArtifacts,fis4, "ECA_OAM_VFInvalidFormat.yaml");
485
486             InputStream fis5 = SampleJUnitTest.class.getResourceAsStream("/MMSC_Sevice_07_25_16InvalidFormat.yaml");
487             readPayload(inputArtifacts,fis5, "MMSC_Sevice_07_25_16InvalidFormat.yaml");
488
489             InputStream fis6 = SampleJUnitTest.class.getResourceAsStream("/MMSC_VFInvalidFormat.yaml");
490             readPayload(inputArtifacts,fis6, "MMSC_VFInvalidFormat.yaml");
491
492             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
493
494             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
495             Assert.assertEquals(false,data.getErrorData().isEmpty());
496
497             Assert.assertEquals("Invalid format for Tosca YML  : "+inputArtifacts.get(1).getName(),data.getErrorData().get("AAI").get(0));
498
499             Assert.assertEquals(2,data.getResultData().size());
500
501         } catch (Exception e) {
502             Assert.fail(e.getMessage());
503         }
504     }
505
506     @Test
507     public void testArtifactGenerationMulComp() {
508         try {
509             List<Artifact> inputArtifacts = new ArrayList();
510             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_MulComp.yml");
511             readPayload(inputArtifacts,fis1, "vf_vmme_template_MulComp.yml");
512
513             fis1.close();
514             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_MulComp.yml");
515             readPayload(inputArtifacts,fis2, "service_vmme_template_MulComp.yml");
516             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
517             List<ToscaTemplate> toscas = new LinkedList();
518
519             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
520
521                 for (Artifact inputArtifact : inputArtifacts) {
522                     toscas.add(getToscaModel(inputArtifact));
523                 }
524                 List<Artifact> resultData = data.getResultData();
525
526                 Map<String, Model> outputArtifactMap = new HashMap<>();
527                 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
528                 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
529                 testResourceTosca(toscas.iterator(), outputArtifactMap);
530
531             Assert.assertEquals(5,data.getResultData().size());
532
533             removeMockArtifact(data.getResultData().iterator());
534
535             ArtifactGenerationServiceTest.validateName(data.getResultData());
536         } catch (Exception e) {
537             Assert.fail(e.getMessage());
538         }
539     }
540
541     @Test
542     public void testArtifactGenerationOrphan() {
543         try {
544             List<Artifact> inputArtifacts = new ArrayList();
545
546             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_Orphan.yml");
547             readPayload(inputArtifacts,fis1, "vf_vmme_template_Orphan.yml");
548
549             fis1.close();
550             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_Orphan.yml");
551             readPayload(inputArtifacts,fis2, "service_vmme_template_Orphan.yml");
552
553             InputStream fis4 = SampleJUnitTest.class.getResourceAsStream("/ECA_OAM_VFOrphan.yaml");
554             readPayload(inputArtifacts,fis4, "ECA_OAM_VFOrphan.yaml");
555
556             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
557             List<ToscaTemplate> toscas = new LinkedList();
558
559             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
560
561                 for (Artifact inputArtifact : inputArtifacts) {
562                     toscas.add(getToscaModel(inputArtifact));
563                 }
564                 List<Artifact> resultData = data.getResultData();
565
566                 Map<String, Model> outputArtifactMap = new HashMap<>();
567                 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
568                 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
569                 testResourceTosca(toscas.iterator(), outputArtifactMap);
570
571             Assert.assertEquals(5,data.getResultData().size());
572
573             removeMockArtifact(data.getResultData().iterator());
574
575             ArtifactGenerationServiceTest.validateName(data.getResultData());
576         } catch (Exception e) {
577             Assert.fail(e.getMessage());
578         }
579     }
580
581     @Test
582     public void testArtifactGenerationMissingVFTemplate() {
583         try {
584             List<Artifact> inputArtifacts = new ArrayList();
585
586             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_MissingVFTemplate.yml");
587             readPayload(inputArtifacts,fis1, "service_vmme_template_MissingVFTemplate.yml");
588
589             fis1.close();
590
591             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
592             List<ToscaTemplate> toscas = new LinkedList();
593
594             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
595
596                 for (Artifact inputArtifact : inputArtifacts) {
597                     toscas.add(getToscaModel(inputArtifact));
598                 }
599                 List<Artifact> resultData = data.getResultData();
600
601                 Map<String, Model> outputArtifactMap = new HashMap<>();
602                 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
603                 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
604
605
606             Assert.assertEquals(3,data.getResultData().size());
607
608             removeMockArtifact(data.getResultData().iterator());
609
610             ArtifactGenerationServiceTest.validateName(data.getResultData());
611         } catch (Exception e) {
612             Assert.fail(e.getMessage());
613         }
614     }
615
616     @Test
617     public void testArtifactGenerationMissingVFModule() {
618         try {
619             List<Artifact> inputArtifacts = new ArrayList();
620
621             InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/CMAUI_VFMissingVFModule.yaml");
622             readPayload(inputArtifacts,fis3, "CMAUI_VFMissingVFModule.yaml");
623
624             InputStream fis4 = SampleJUnitTest.class.getResourceAsStream("/ECA_OAM_VFMissingVFModule.yaml");
625             readPayload(inputArtifacts,fis4, "ECA_OAM_VFMissingVFModule.yaml");
626
627             InputStream fis5 = SampleJUnitTest.class.getResourceAsStream("/MMSC_Sevice_07_25_16MissingVFModule.yaml");
628             readPayload(inputArtifacts,fis5, "MMSC_Sevice_07_25_16MissingVFModule.yaml");
629
630             InputStream fis6 = SampleJUnitTest.class.getResourceAsStream("/MMSC_VFMissingVFModule.yaml");
631             readPayload(inputArtifacts,fis6, "MMSC_VFMissingVFModule.yaml");
632
633             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
634             List<ToscaTemplate> toscas = new LinkedList();
635
636             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
637
638                 for (Artifact inputArtifact : inputArtifacts) {
639                     toscas.add(getToscaModel(inputArtifact));
640                 }
641                 List<Artifact> resultData = data.getResultData();
642
643                 Map<String, Model> outputArtifactMap = new HashMap<>();
644                 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
645                 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
646                 testResourceTosca(toscas.iterator(), outputArtifactMap);
647
648             Assert.assertEquals(8,data.getResultData().size());
649
650             removeMockArtifact(data.getResultData().iterator());
651
652             ArtifactGenerationServiceTest.validateName(data.getResultData());
653
654         } catch (Exception e) {
655             e.printStackTrace();
656             Assert.fail(e.getMessage());
657         }
658     }
659
660     @Test
661     public void testArtifactGenerationEmptyArtifact() {
662         try {
663             List<Artifact> inputArtifacts = new ArrayList();
664
665             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
666
667             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
668             Assert.assertEquals(false,data.getErrorData().isEmpty());
669             Assert.assertEquals("Service tosca missing from list of input artifacts",data.getErrorData().get("AAI").get(0));
670
671             Assert.assertEquals(2,data.getResultData().size());
672
673         } catch (Exception e) {
674             Assert.fail(e.getMessage());
675         }
676     }
677
678     @Test
679     public void testArtifactGenerationMissingConfigFile() {
680         try {
681             List<Artifact> inputArtifacts = new ArrayList();
682
683             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_SingleVFVFMod.yml");
684             readPayload(inputArtifacts,fis1, "vf_vmme_template_SingleVFVFMod.yml");
685
686             fis1.close();
687             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_SingleVFVFMod.yml");
688             readPayload(inputArtifacts,fis2, "service_vmme_template_SingleVFVFMod.yml");
689             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
690
691             GenerationData data = obj.generateArtifact(inputArtifacts, "",additionalParams);
692             Assert.assertEquals(false,data.getErrorData().isEmpty());
693             Assert.assertEquals("Invalid Client Configuration",data.getErrorData().get("ARTIFACT_GENERATOR_INVOCATION_ERROR").get(0));
694
695             Assert.assertEquals(0,data.getResultData().size());
696
697         } catch (Exception e) {
698             Assert.fail(e.getMessage());
699         }
700     }
701
702
703     @Test
704     public void testArtifactGenerationWithNodeTemplates() {
705         try {
706             List<Artifact> inputArtifacts = new ArrayList();
707
708             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/ServiceWithNodetemplate.yml");
709             readPayload(inputArtifacts,fis1, "ServiceWithNodetemplate.yml");
710
711             fis1.close();
712             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/Resource0-template.yml");
713             readPayload(inputArtifacts,fis2, "Resource0-template.yml");
714
715             InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/Resource1-template.yml");
716             readPayload(inputArtifacts,fis3, "Resource1-template.yml");
717
718             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
719             List<ToscaTemplate> toscas = new LinkedList();
720
721             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
722
723             for (Artifact inputArtifact : inputArtifacts) {
724                 toscas.add(getToscaModel(inputArtifact));
725             }
726             List<Artifact> resultData = data.getResultData();
727
728             Map<String, Model> outputArtifactMap = new HashMap<>();
729             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
730             ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
731             testResourceTosca(toscas.iterator(), outputArtifactMap);
732
733             Assert.assertEquals(5,data.getResultData().size());
734
735             removeMockArtifact(data.getResultData().iterator());
736
737             ArtifactGenerationServiceTest.validateName(data.getResultData());
738
739
740         } catch (Exception e) {
741             Assert.fail(e.getMessage());
742         }
743     }
744
745     @Test
746     public void testArtifactGenerationWithoutNodeTemplates() {
747         try {
748             List<Artifact> inputArtifacts = new ArrayList();
749
750             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/Service0-template.yml");
751             readPayload(inputArtifacts,fis1, "Service0-template.yml");
752
753             fis1.close();
754
755             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
756             List<ToscaTemplate> toscas = new LinkedList();
757
758             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
759
760             for (Artifact inputArtifact : inputArtifacts) {
761                 toscas.add(getToscaModel(inputArtifact));
762             }
763             List<Artifact> resultData = data.getResultData();
764
765             Map<String, Model> outputArtifactMap = new HashMap<>();
766             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
767             ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
768
769
770             Assert.assertEquals(3,data.getResultData().size());
771
772             removeMockArtifact(data.getResultData().iterator());
773
774             ArtifactGenerationServiceTest.validateName(data.getResultData());
775
776
777         } catch (Exception e) {
778             Assert.fail(e.getMessage());
779         }
780     }
781
782     @Test
783     public void testArtifactGenerationWithArtifactNameAndDescMoreThan256() {
784         try {
785             List<Artifact> inputArtifacts = new ArrayList();
786
787             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/Service0-templateMoreThan256.yml");
788             readPayload(inputArtifacts,fis1, "Service0-templateMoreThan256.yml");
789
790             fis1.close();
791
792             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
793             List<ToscaTemplate> toscas = new LinkedList();
794
795             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
796
797             for (Artifact inputArtifact : inputArtifacts) {
798                 toscas.add(getToscaModel(inputArtifact));
799             }
800             List<Artifact> resultData = data.getResultData();
801
802             Map<String, Model> outputArtifactMap = new HashMap<>();
803             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
804             ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
805
806
807             Assert.assertEquals(3,data.getResultData().size());
808
809             removeMockArtifact(data.getResultData().iterator());
810
811             for(Artifact artifact : data.getResultData()){
812                 checkArtifactName(artifact.getName());
813                 checkArtifactLabel(artifact.getLabel());
814                 checkArtifactDescription(artifact.getDescription());
815
816             }
817
818         } catch (Exception e) {
819             Assert.fail(e.getMessage());
820         }
821     }
822
823     @Test
824     public void testArtifactGenerationWithDifferentVersionOfSameVF() {
825         try {
826             List<Artifact> inputArtifacts = new ArrayList();
827
828             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_DiffVerOfSameVF.yml");
829             readPayload(inputArtifacts,fis1, "service_vmme_template_DiffVerOfSameVF.yml");
830             fis1.close();
831
832             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_DiffVerOfSameVF_1.yml");
833             readPayload(inputArtifacts,fis2, "vf_vmme_template_DiffVerOfSameVF_1.yml");
834             fis2.close();
835
836             InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_DiffVerOfSameVF_2.yml");
837             readPayload(inputArtifacts,fis3, "vf_vmme_template_DiffVerOfSameVF_2.yml");
838             fis3.close();
839
840             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
841             List<ToscaTemplate> toscas = new LinkedList();
842
843             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
844
845             for (Artifact inputArtifact : inputArtifacts) {
846                 toscas.add(getToscaModel(inputArtifact));
847             }
848             List<Artifact> resultData = data.getResultData();
849
850             Map<String, Model> outputArtifactMap = new HashMap<>();
851             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
852             ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
853             testResourceTosca(toscas.iterator(), outputArtifactMap);
854
855             Assert.assertEquals(6,data.getResultData().size());
856
857             removeMockArtifact(data.getResultData().iterator());
858
859             ArtifactGenerationServiceTest.validateName(data.getResultData());
860
861
862         } catch (Exception e) {
863             Assert.fail(e.getMessage());
864         }
865     }
866
867     @Test
868     public void testArtifactGenerationWithDifferentVersionOfSameVFModWithSameInvId() {
869         try {
870             List<Artifact> inputArtifacts = new ArrayList();
871
872             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_DiffVerOfSameVFModWithSameInvId.yml");
873             readPayload(inputArtifacts,fis1, "service_vmme_template_DiffVerOfSameVFModWithSameInvId.yml");
874             fis1.close();
875
876             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_DiffVerOfSameVFModWithSameInvId.yml");
877             readPayload(inputArtifacts,fis2, "vf_vmme_template_DiffVerOfSameVFModWithSameInvId.yml");
878             fis2.close();
879
880             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
881             List<ToscaTemplate> toscas = new LinkedList();
882
883             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
884
885             for (Artifact inputArtifact : inputArtifacts) {
886                 toscas.add(getToscaModel(inputArtifact));
887             }
888             List<Artifact> resultData = data.getResultData();
889
890             Map<String, Model> outputArtifactMap = new HashMap<>();
891             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
892             ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
893             testResourceTosca(toscas.iterator(), outputArtifactMap);
894
895             Assert.assertEquals(6,data.getResultData().size());
896
897             removeMockArtifact(data.getResultData().iterator());
898
899             ArtifactGenerationServiceTest.validateName(data.getResultData());
900
901
902         } catch (Exception e) {
903             Assert.fail(e.getMessage());
904         }
905     }
906
907     @Test
908     public void testArtifactGenerationWithServiceContainingL3Network() {
909         try {
910             List<Artifact> inputArtifacts = new ArrayList();
911
912             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithL3Network.yml");
913             readPayload(inputArtifacts,fis1, "service_vmme_template_WithL3Network.yml");
914             fis1.close();
915
916             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithL3Network.yml");
917             readPayload(inputArtifacts,fis2, "vf_vmme_template_WithL3Network.yml");
918             fis2.close();
919
920             InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource-template_WithL3Network.yml");
921             readPayload(inputArtifacts,fis3, "resource-AllottedResource-template_WithL3Network.yml");
922             fis3.close();
923
924             InputStream fis4 = SampleJUnitTest.class.getResourceAsStream
925                 ("/resource-Extvl-template_WithL3Network.yml");
926             readPayload(inputArtifacts,fis4, "resource-Extvl-template_WithL3Network.yml");
927             fis4.close();
928
929             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
930             List<ToscaTemplate> toscas = new LinkedList();
931
932             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
933
934             for (Artifact inputArtifact : inputArtifacts) {
935                 toscas.add(getToscaModel(inputArtifact));
936             }
937             List<Artifact> resultData = data.getResultData();
938
939             Map<String, Model> outputArtifactMap = new HashMap<>();
940             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
941             ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
942             testResourceTosca(toscas.iterator(), outputArtifactMap);
943
944             Assert.assertEquals(7,data.getResultData().size());
945
946             removeMockArtifact(data.getResultData().iterator());
947
948             ArtifactGenerationServiceTest.validateName(data.getResultData());
949
950
951         } catch (Exception e) {
952             Assert.fail(e.getMessage());
953         }
954     }
955
956     @Test
957     public void testArtifactGenerationWithServiceContainingDupL3Network() {
958         try {
959             List<Artifact> inputArtifacts = new ArrayList();
960
961             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithDupL3Network.yml");
962             readPayload(inputArtifacts,fis1, "service_vmme_template_WithDupL3Network.yml");
963             fis1.close();
964
965             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithDupL3Network.yml");
966             readPayload(inputArtifacts,fis2, "vf_vmme_template_WithDupL3Network.yml");
967             fis2.close();
968
969             InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource-template_WithDupL3Network.yml");
970             readPayload(inputArtifacts,fis3, "resource-AllottedResource-template_WithDupL3Network.yml");
971             fis3.close();
972
973             InputStream fis4 = SampleJUnitTest.class.getResourceAsStream
974                 ("/resource-Extvl-template_WithDupL3Network.yml");
975             readPayload(inputArtifacts,fis4, "resource-Extvl-template_WithDupL3Network.yml");
976             fis4.close();
977
978             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
979             List<ToscaTemplate> toscas = new LinkedList();
980
981             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
982
983             for (Artifact inputArtifact : inputArtifacts) {
984                 toscas.add(getToscaModel(inputArtifact));
985             }
986             List<Artifact> resultData = data.getResultData();
987
988             Map<String, Model> outputArtifactMap = new HashMap<>();
989             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
990             ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
991             testResourceTosca(toscas.iterator(), outputArtifactMap);
992
993             Assert.assertEquals(7,data.getResultData().size());
994
995             removeMockArtifact(data.getResultData().iterator());
996
997             ArtifactGenerationServiceTest.validateName(data.getResultData());
998
999
1000         } catch (Exception e) {
1001             Assert.fail(e.getMessage());
1002         }
1003     }
1004
1005     @Test
1006     public void testArtifactGenerationWithL3NetworkInVFMod() {
1007         try {
1008             List<Artifact> inputArtifacts = new ArrayList();
1009
1010             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithL3NetworkInVFMod.yml");
1011             readPayload(inputArtifacts,fis1, "service_vmme_template_WithL3NetworkInVFMod.yml");
1012             fis1.close();
1013
1014             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithL3NetworkInVFMod.yml");
1015             readPayload(inputArtifacts,fis2, "vf_vmme_template_WithL3NetworkInVFMod.yml");
1016             fis2.close();
1017
1018             InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource-template_WithL3NetworkInVFMod.yml");
1019             readPayload(inputArtifacts,fis3, "resource-AllottedResource-template_WithL3NetworkInVFMod.yml");
1020             fis3.close();
1021
1022             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1023             List<ToscaTemplate> toscas = new LinkedList();
1024
1025             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1026
1027             for (Artifact inputArtifact : inputArtifacts) {
1028                 toscas.add(getToscaModel(inputArtifact));
1029             }
1030             List<Artifact> resultData = data.getResultData();
1031
1032             Map<String, Model> outputArtifactMap = new HashMap<>();
1033             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
1034             ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
1035             testResourceTosca(toscas.iterator(), outputArtifactMap);
1036
1037             Assert.assertEquals(6,data.getResultData().size());
1038
1039             removeMockArtifact(data.getResultData().iterator());
1040
1041             ArtifactGenerationServiceTest.validateName(data.getResultData());
1042
1043
1044         } catch (Exception e) {
1045             Assert.fail(e.getMessage());
1046         }
1047     }
1048
1049     @Test
1050     public void testArtifactGenerationWithDiffVersionOfSameL3Network() {
1051         try {
1052             List<Artifact> inputArtifacts = new ArrayList();
1053
1054             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithDiffVersionOfSameL3Network.yml");
1055             readPayload(inputArtifacts,fis1, "service_vmme_template_WithDiffVersionOfSameL3Network.yml");
1056             fis1.close();
1057
1058             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithDiffVersionOfSameL3Network.yml");
1059             readPayload(inputArtifacts,fis2, "vf_vmme_template_WithDiffVersionOfSameL3Network.yml");
1060             fis2.close();
1061
1062             InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource-template_WithDiffVersionOfSameL3Network.yml");
1063             readPayload(inputArtifacts,fis3, "resource-AllottedResource-template_WithDiffVersionOfSameL3Network.yml");
1064             fis3.close();
1065
1066             InputStream fis4 = SampleJUnitTest.class.getResourceAsStream
1067                 ("/resource-Extvl-template_WithDiffVersionOfSameL3Network.yml");
1068             readPayload(inputArtifacts,fis4, "resource-Extvl-template_WithDiffVersionOfSameL3Network.yml");
1069             fis4.close();
1070
1071             InputStream fis5 = SampleJUnitTest.class.getResourceAsStream
1072                 ("/resource-Extvl-template_1_WithDiffVersionOfSameL3Network.yml");
1073             readPayload(inputArtifacts,fis5,
1074                 "resource-Extvl-template_1_WithDiffVersionOfSameL3Network.yml");
1075             fis5.close();
1076
1077             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1078             List<ToscaTemplate> toscas = new LinkedList();
1079
1080             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1081
1082             for (Artifact inputArtifact : inputArtifacts) {
1083                 toscas.add(getToscaModel(inputArtifact));
1084             }
1085             List<Artifact> resultData = data.getResultData();
1086
1087             Map<String, Model> outputArtifactMap = new HashMap<>();
1088             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
1089             ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
1090             testResourceTosca(toscas.iterator(), outputArtifactMap);
1091
1092             Assert.assertEquals(8,data.getResultData().size());
1093
1094             removeMockArtifact(data.getResultData().iterator());
1095
1096             ArtifactGenerationServiceTest.validateName(data.getResultData());
1097
1098
1099         } catch (Exception e) {
1100             Assert.fail(e.getMessage());
1101         }
1102     }
1103
1104     @Test
1105     public void testArtifactGenerationWithInvIdGreaterThanSpecifiedLimit() {
1106         try {
1107             List<Artifact> inputArtifacts = new ArrayList();
1108             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithInvIdGreaterThanSpecifiedLimit.yml");
1109             readPayload(inputArtifacts,fis1, "vf_vmme_template_WithInvIdGreaterThanSpecifiedLimit" +
1110                 ".yml");
1111             fis1.close();
1112
1113             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithInvIdGreaterThanSpecifiedLimit.yml");
1114             readPayload(inputArtifacts,fis2, "service_vmme_template_WithInvIdGreaterThanSpecifiedLimit.yml");
1115             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1116             fis2.close();
1117
1118             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1119             Assert.assertEquals(false,data.getErrorData().isEmpty());
1120
1121             Assert.assertEquals(INVALID_VALUE_INVARIANT + ": <" +inputArtifacts.get(1).getName()+">",data.getErrorData().get("AAI").get(0));
1122
1123             Assert.assertEquals(2,data.getResultData().size());
1124
1125         } catch (Exception e) {
1126             e.printStackTrace();
1127             Assert.fail(e.getMessage());
1128         }
1129     }
1130
1131     @Test
1132     public void testArtifactGenerationWithInvIdLesserThanSpecifiedLimit() {
1133         try {
1134             List<Artifact> inputArtifacts = new ArrayList();
1135             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithInvIdLesserThanSpecifiedLimit.yml");
1136             readPayload(inputArtifacts,fis1, "vf_vmme_template_WithInvIdLesserThanSpecifiedLimit" +
1137                 ".yml");
1138             fis1.close();
1139
1140             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithInvIdLesserThanSpecifiedLimit.yml");
1141             readPayload(inputArtifacts,fis2, "service_vmme_template_WithInvIdLesserThanSpecifiedLimit.yml");
1142             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1143             fis2.close();
1144
1145             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1146             Assert.assertEquals(false,data.getErrorData().isEmpty());
1147
1148             Assert.assertEquals(INVALID_VALUE_UUID + " <"
1149                 +inputArtifacts.get(1).getName()+">",data.getErrorData().get("AAI").get(0));
1150
1151             Assert.assertEquals(2,data.getResultData().size());
1152
1153         } catch (Exception e) {
1154             e.printStackTrace();
1155             Assert.fail(e.getMessage());
1156         }
1157     }
1158
1159
1160     @Test
1161     public void testErrorWhenNoSystemPropConfigured() throws Exception  {
1162         String configLoc = System.getProperty(ARTIFACTGENERATOR_CONFIG);
1163         try {
1164             List<Artifact> inputArtifacts = new ArrayList();
1165             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_NoSystemPropConfigured.yml");
1166             readPayload(inputArtifacts,fis1, "vf_vmme_template_NoSystemPropConfigured" +
1167                 ".yml");
1168             fis1.close();
1169
1170             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_NoSystemPropConfigured.yml");
1171             readPayload(inputArtifacts,fis2, "service_vmme_template_NoSystemPropConfigured.yml");
1172             fis2.close();
1173
1174             System.clearProperty(ARTIFACTGENERATOR_CONFIG);
1175
1176             Map<String, Model> outputArtifactMap = new HashMap<>();
1177             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1178             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1179             Assert.assertEquals(false,data.getErrorData().isEmpty());
1180             Assert.assertEquals(data.getErrorData().
1181                 get("AAI").get(0), GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND);
1182         } catch (Exception e) {
1183             Assert.fail(e.getMessage());
1184         }
1185         finally{
1186             System.setProperty(ARTIFACTGENERATOR_CONFIG,configLoc);
1187         }
1188     }
1189
1190     @Test
1191     public void testErrorWhenNoFileAtConfigLocation() throws Exception  {
1192         String configLoc = System.getProperty(ARTIFACTGENERATOR_CONFIG);
1193         try {
1194             List<Artifact> inputArtifacts = new ArrayList();
1195             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_NoSystemPropConfigured.yml");
1196             readPayload(inputArtifacts,fis1, "vf_vmme_template_NoSystemPropConfigured" +
1197                 ".yml");
1198             fis1.close();
1199
1200             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_NoSystemPropConfigured.yml");
1201             readPayload(inputArtifacts,fis2, "service_vmme_template_NoSystemPropConfigured.yml");
1202             fis2.close();
1203
1204             System.setProperty(ARTIFACTGENERATOR_CONFIG,configLoc + File.separator + "testErrorWhenNoFileAtConfigLocation");
1205             Map<String, Model> outputArtifactMap = new HashMap<>();
1206             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1207             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1208             Assert.assertEquals(data.getErrorData().isEmpty(),false);
1209             Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format(
1210                 GENERATOR_AAI_CONFIGFILE_NOT_FOUND,System.getProperty
1211                 (ARTIFACTGENERATOR_CONFIG)));
1212         } catch (Exception e) {
1213             Assert.fail(e.getMessage());
1214         }
1215         finally{
1216             System.setProperty(ARTIFACTGENERATOR_CONFIG,configLoc);
1217         }
1218     }
1219
1220     @Test
1221     public void testErrorWhenNoWidgetInConfig() throws Exception  {
1222         System.setProperty(ARTIFACTGENERATOR_CONFIG,CONFIG_PATH+"Artifact-Generator1.properties");
1223         loadConfig(ArtifactGenerationServiceTest.properties);
1224         try {
1225             List<Artifact> inputArtifacts = new ArrayList();
1226             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_NoSystemPropConfigured.yml");
1227             readPayload(inputArtifacts,fis1, "vf_vmme_template_NoSystemPropConfigured" +
1228                 ".yml");
1229             fis1.close();
1230
1231             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_NoSystemPropConfigured.yml");
1232             readPayload(inputArtifacts,fis2, "service_vmme_template_NoSystemPropConfigured.yml");
1233             fis2.close();
1234
1235             Map<String, Model> outputArtifactMap = new HashMap<>();
1236             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1237             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1238
1239             String assertMsg = ArtifactType.AAI.name() + ".model-version-id." + Widget.getWidget
1240                 (Widget.Type.SERVICE).getName();
1241
1242             Assert.assertEquals(false,data.getErrorData().isEmpty());
1243             String errMsg = String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,assertMsg);
1244             Assert.assertEquals(data.getErrorData().get("AAI").get(0),errMsg);
1245         } catch (Exception e) {
1246             Assert.fail(e.getMessage());
1247         } finally {
1248             System.setProperty(ARTIFACTGENERATOR_CONFIG, CONFIG_PATH+"Artifact-Generator.properties");
1249             loadConfig(ArtifactGenerationServiceTest.properties);
1250         }
1251     }
1252
1253     @Test
1254     public void testArtifactGenerationWithUpdatedUUIDInConfig() throws Exception  {
1255         try {
1256             List<Artifact> inputArtifacts = new ArrayList();
1257             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithUpdatedUUIDInConfig.yml");
1258             readPayload(inputArtifacts,fis1, "vf_vmme_template_WithUpdatedUUIDInConfig" +
1259                 ".yml");
1260             fis1.close();
1261
1262             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithUpdatedUUIDInConfig.yml");
1263             readPayload(inputArtifacts,fis2, "service_vmme_template_WithUpdatedUUIDInConfig.yml");
1264             fis2.close();
1265
1266             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1267             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1268             List<ToscaTemplate> toscas = new LinkedList();
1269             for (Artifact inputArtifact : inputArtifacts) {
1270                 toscas.add(getToscaModel(inputArtifact));
1271             }
1272             List<Artifact> resultData = data.getResultData();
1273             Map<String, Model> outputArtifactMap = new HashMap<>();
1274             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1275             ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1276             testResourceTosca(toscas.iterator(), outputArtifactMap);
1277
1278             System.setProperty(ARTIFACTGENERATOR_CONFIG,CONFIG_PATH+"Artifact-Generator2.properties");
1279             loadConfig(ArtifactGenerationServiceTest.properties);
1280
1281             List<ToscaTemplate> toscas2 = new LinkedList();
1282             for (Artifact inputArtifact : inputArtifacts) {
1283                 toscas2.add(getToscaModel(inputArtifact));
1284             }
1285             GenerationData data2 = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1286             Map<String, Model> outputArtifactMap2 = new HashMap<>();
1287             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap2,
1288                 data2.getResultData());
1289             ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap2, toscas2);
1290             testResourceTosca(toscas2.iterator(), outputArtifactMap2);
1291
1292         } catch (Exception e) {
1293             Assert.fail(e.getMessage());
1294         } finally {
1295             System.setProperty(ARTIFACTGENERATOR_CONFIG,CONFIG_PATH+"Artifact-Generator.properties");
1296             loadConfig(ArtifactGenerationServiceTest.properties);
1297         }
1298     }
1299
1300     @Test
1301     public void testArtifactGenerationVerifyMandatoryParameterServiceVersion() {
1302         try {
1303             List<Artifact> inputArtifacts = new ArrayList();
1304             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyMandatoryParameterServiceVersion.yml");
1305             readPayload(inputArtifacts, fis1, "vf_vmme_template_VerifyMandatoryParameterServiceVersion.yml");
1306
1307             fis1.close();
1308             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyMandatoryParameterServiceVersion.yml");
1309             readPayload(inputArtifacts, fis2, "service_vmme_template_VerifyMandatoryParameterServiceVersion.yml");
1310             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1311
1312             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, new HashMap<String, String>());
1313             List<Artifact> resultData = data.getResultData();
1314
1315             Assert.assertEquals(data.getErrorData().isEmpty(),false);
1316             Assert.assertEquals(data.getErrorData().get("AAI").get(0),GENERATOR_AAI_ERROR_MISSING_SERVICE_VERSION);
1317         } catch (Exception e) {
1318             Assert.fail(e.getMessage());
1319         }
1320     }
1321
1322     @Test
1323     public void testArtifactGenerationVerifyServiceVersionFormat() {
1324         try {
1325             List<Artifact> inputArtifacts = new ArrayList();
1326             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyServiceVersionFormat.yml");
1327             readPayload(inputArtifacts, fis1, "vf_vmme_template_VerifyServiceVersionFormat.yml");
1328
1329             fis1.close();
1330             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyServiceVersionFormat.yml");
1331             readPayload(inputArtifacts, fis2, "service_vmme_template_VerifyServiceVersionFormat.yml");
1332             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1333
1334             additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1");
1335             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1336             List<Artifact> resultData = data.getResultData();
1337             Assert.assertEquals(data.getErrorData().isEmpty(),false);
1338             Assert.assertEquals(data.getErrorData().get("AAI").get(0),GENERATOR_AAI_INVALID_SERVICE_VERSION);
1339
1340             additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.1");
1341             GenerationData data2 = obj.generateArtifact(inputArtifacts, generatorConfig,
1342                 additionalParams);
1343             List<Artifact> resultData2 = data.getResultData();
1344             Assert.assertEquals(data2.getErrorData().isEmpty(),false);
1345             Assert.assertEquals(data2.getErrorData().get("AAI").get(0),
1346                 GENERATOR_AAI_INVALID_SERVICE_VERSION);
1347
1348             additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.0");
1349             GenerationData data3 = obj.generateArtifact(inputArtifacts, generatorConfig,
1350                 additionalParams);
1351             List<Artifact> resultData3 = data.getResultData();
1352             Assert.assertEquals(data3.getErrorData().isEmpty(),false);
1353             Assert.assertEquals(data3.getErrorData().get("AAI").get(0),
1354                 GENERATOR_AAI_INVALID_SERVICE_VERSION);
1355         } catch (Exception e) {
1356             Assert.fail(e.getMessage());
1357         } finally{
1358             additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
1359         }
1360     }
1361
1362     @Test
1363     public void testArtifactGenerationVerifyServiceVersion() {
1364         try {
1365             List<Artifact> inputArtifacts = new ArrayList();
1366             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyServiceVersion.yml");
1367             readPayload(inputArtifacts, fis1, "vf_vmme_template_VerifyServiceVersion.yml");
1368
1369             fis1.close();
1370             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyServiceVersion.yml");
1371             readPayload(inputArtifacts, fis2, "service_vmme_template_VerifyServiceVersion.yml");
1372             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1373             List<ToscaTemplate> toscas = new LinkedList();
1374
1375             additionalParams.put(AdditionalParams.ServiceVersion.getName(),"9.0");
1376             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1377
1378             for (Artifact inputArtifact : inputArtifacts) {
1379                 toscas.add(getToscaModel(inputArtifact));
1380             }
1381             List<Artifact> resultData = data.getResultData();
1382
1383             Map<String, Model> outputArtifactMap = new HashMap<>();
1384             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1385             ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1386
1387             testResourceTosca(toscas.iterator(), outputArtifactMap);
1388
1389             Assert.assertEquals(5, data.getResultData().size());
1390
1391             removeMockArtifact(data.getResultData().iterator());
1392
1393             ArtifactGenerationServiceTest.validateName(data.getResultData());
1394
1395
1396         } catch (Exception e) {
1397             Assert.fail(e.getMessage());
1398         } finally{
1399             additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
1400         }
1401     }
1402
1403
1404     @Test
1405     public void testArtifactGenerationVerifyResourceVersionFormat() {
1406         try {
1407             List<Artifact> inputArtifacts = new ArrayList();
1408             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyResourceVersionFormat.yml");
1409             readPayload(inputArtifacts, fis1, "vf_vmme_template_VerifyResourceVersionFormat.yml");
1410             fis1.close();
1411
1412             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyResourceVersionFormat1.yml");
1413             readPayload(inputArtifacts, fis2, "service_vmme_template_VerifyResourceVersionFormat1.yml");
1414             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1415             fis2.close();
1416
1417             List<ToscaTemplate> toscas = new LinkedList();
1418             for (Artifact inputArtifact : inputArtifacts) {
1419                 toscas.add(getToscaModel(inputArtifact));
1420             }
1421
1422             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1423             List<Artifact> resultData = data.getResultData();
1424             Assert.assertEquals(data.getErrorData().isEmpty(),false);
1425             Assert.assertEquals(data.getErrorData().get("AAI").get(0),
1426                 String.format(GENERATOR_AAI_ERROR_INVALID_RESOURCE_VERSION_IN_SERVICE_TOSCA,
1427                     toscas.get(0).getMetadata().get("UUID")));
1428
1429             inputArtifacts.remove(1);
1430
1431             InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyResourceVersionFormat2.yml");
1432             readPayload(inputArtifacts, fis3, "service_vmme_template_VerifyResourceVersionFormat2.yml");
1433             fis3.close();
1434             GenerationData data2 = obj.generateArtifact(inputArtifacts, generatorConfig,
1435                 additionalParams);
1436             List<Artifact> resultData2 = data2.getResultData();
1437             Assert.assertEquals(data2.getErrorData().isEmpty(),false);
1438             Assert.assertEquals(data2.getErrorData().get("AAI").get(0),
1439                 String.format(GENERATOR_AAI_ERROR_INVALID_RESOURCE_VERSION_IN_SERVICE_TOSCA,
1440                     toscas.get(0).getMetadata().get("UUID")));
1441
1442         } catch (Exception e) {
1443             Assert.fail(e.getMessage());
1444         }
1445     }
1446
1447     @Test
1448     public void testArtifactGenerationVerifyMandatoryParameterResourceVersion() {
1449         try {
1450             List<Artifact> inputArtifacts = new ArrayList();
1451             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyMandatoryParameterResourceVersion.yml");
1452             readPayload(inputArtifacts, fis1, "vf_vmme_template_VerifyMandatoryParameterResourceVersion.yml");
1453
1454             fis1.close();
1455             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyMandatoryParameterResourceVersion.yml");
1456             readPayload(inputArtifacts, fis2, "service_vmme_template_VerifyMandatoryParameterResourceVersion.yml");
1457             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1458             List<ToscaTemplate> toscas = new LinkedList();
1459             for (Artifact inputArtifact : inputArtifacts) {
1460                 toscas.add(getToscaModel(inputArtifact));
1461             }
1462
1463             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1464             List<Artifact> resultData = data.getResultData();
1465             Assert.assertEquals(data.getErrorData().isEmpty(),false);
1466             Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format(GENERATOR_AAI_ERROR_NULL_RESOURCE_VERSION_IN_SERVICE_TOSCA,toscas.get(0).getMetadata().get("UUID")));
1467         } catch (Exception e) {
1468             Assert.fail(e.getMessage());
1469         }
1470     }
1471
1472     @Test
1473     public void testArtifactGenerationWithoutAllottedResource() {
1474         try {
1475             List<Artifact> inputArtifacts = new ArrayList();
1476
1477             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service-ServiceWithAllottedResourceIpmux-template.yml");
1478             readPayload(inputArtifacts, fis1, "service-ServiceWithAllottedResourceIpmux-template.yml");
1479             fis1.close();
1480
1481             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource-template_IpMux.yml");
1482             readPayload(inputArtifacts, fis2, "resource-AllottedResource-template_IpMux.yml");
1483             fis2.close();
1484
1485             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1486             List<ToscaTemplate> toscas = new LinkedList();
1487
1488             for (Artifact inputArtifact : inputArtifacts) {
1489                 toscas.add(getToscaModel(inputArtifact));
1490             }
1491             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1492
1493             List<Artifact> resultData = data.getResultData();
1494             Assert.assertEquals(data.getErrorData().isEmpty(),false);
1495             Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format
1496                 (GENERATOR_AAI_PROVIDING_SERVICE_MISSING, toscas.get(1).getModelId()));
1497
1498         } catch (Exception e) {
1499             Assert.fail(e.getMessage());
1500         }
1501     }
1502
1503     @Test
1504     public void testArtifactGenerationAllottedResourceIpmuxWithGroups() {
1505         try {
1506             List<Artifact> inputArtifacts = new ArrayList();
1507
1508             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream
1509                 ("/service-ServiceWithAllottedResourceIpmux-template_WithGroups.yml");
1510             readPayload(inputArtifacts, fis1, "service-ServiceWithAllottedResourceIpmux-template_WithGroups.yml");
1511             fis1.close();
1512
1513             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource-template_IpMux_WithGroups.yml");
1514             readPayload(inputArtifacts, fis2, "resource-AllottedResource-template_IpMux_WithGroups.yml");
1515             fis2.close();
1516
1517             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1518             List<ToscaTemplate> toscas = new LinkedList();
1519
1520             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1521
1522             for (Artifact inputArtifact : inputArtifacts) {
1523                 toscas.add(getToscaModel(inputArtifact));
1524             }
1525             List<Artifact> resultData = data.getResultData();
1526
1527             Map<String, Model> outputArtifactMap = new HashMap<>();
1528             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1529             ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1530             testResourceTosca(toscas.iterator(), outputArtifactMap);
1531
1532             Assert.assertEquals(5, data.getResultData().size());
1533
1534             removeMockArtifact(data.getResultData().iterator());
1535
1536             ArtifactGenerationServiceTest.validateName(data.getResultData());
1537
1538         } catch (Exception e) {
1539             Assert.fail(e.getMessage());
1540         }
1541     }
1542
1543     @Test
1544     public void testArtifactGenerationAllottedResourceIpmuxSameInvariantDiffVersion() {
1545         try {
1546             List<Artifact> inputArtifacts = new ArrayList();
1547
1548             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service-ServiceWithAllottedResourcesIpMuxSameInvariant-template.yml");
1549             readPayload(inputArtifacts, fis1, "service-ServiceWithAllottedResourcesIpMuxSameInvariant-template.yml");
1550             fis1.close();
1551
1552             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource1SameInvariant-IpMux-template.yml");
1553             readPayload(inputArtifacts, fis2, "resource-AllottedResource1SameInvariant-IpMux-template.yml");
1554             fis2.close();
1555
1556             InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource2SameInvariant-IpMux-template.yml");
1557             readPayload(inputArtifacts, fis3, "resource-AllottedResource2SameInvariant-IpMux-template.yml");
1558             fis3.close();
1559
1560             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1561             List<ToscaTemplate> toscas = new LinkedList();
1562
1563             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1564
1565             for (Artifact inputArtifact : inputArtifacts) {
1566                 toscas.add(getToscaModel(inputArtifact));
1567             }
1568             List<Artifact> resultData = data.getResultData();
1569
1570             Map<String, Model> outputArtifactMap = new HashMap<>();
1571             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1572             ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1573             testResourceTosca(toscas.iterator(), outputArtifactMap);
1574
1575             Assert.assertEquals(5, data.getResultData().size());
1576
1577             removeMockArtifact(data.getResultData().iterator());
1578
1579             ArtifactGenerationServiceTest.validateName(data.getResultData());
1580
1581
1582         } catch (Exception e) {
1583             Assert.fail(e.getMessage());
1584         }
1585     }
1586
1587     @Test
1588     public void testArtifactGenerationAllottedResourceIpmuxSameInvariantSameVersion() {
1589         try {
1590             List<Artifact> inputArtifacts = new ArrayList();
1591
1592             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service-ServiceWithAllottedResourcesIpMuxSameInvariantSameVers-template.yml");
1593             readPayload(inputArtifacts, fis1, "service-ServiceWithAllottedResourcesIpMuxSameInvariantSameVers-template.yml");
1594             fis1.close();
1595
1596             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResourceSameInvariantSameVers-IpMux-template.yml");
1597             readPayload(inputArtifacts, fis2, "resource-AllottedResourceSameInvariantSameVers-IpMux-template.yml");
1598             fis2.close();
1599
1600             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1601             List<ToscaTemplate> toscas = new LinkedList();
1602
1603             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1604
1605             for (Artifact inputArtifact : inputArtifacts) {
1606                 toscas.add(getToscaModel(inputArtifact));
1607             }
1608             List<Artifact> resultData = data.getResultData();
1609
1610             Map<String, Model> outputArtifactMap = new HashMap<>();
1611             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1612             ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1613             testResourceTosca(toscas.iterator(), outputArtifactMap);
1614
1615             Assert.assertEquals(4, data.getResultData().size());
1616
1617             removeMockArtifact(data.getResultData().iterator());
1618
1619             ArtifactGenerationServiceTest.validateName(data.getResultData());
1620
1621
1622         } catch (Exception e) {
1623             Assert.fail(e.getMessage());
1624         }
1625     }
1626
1627     @Test
1628     public void testArtifactGenerationAllottedResourceWithIpMuxAndTunnelXConn() {
1629         try {
1630             List<Artifact> inputArtifacts = new ArrayList();
1631
1632             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service-Allottedipmux-template.yml");
1633             readPayload(inputArtifacts, fis2, "service-Allottedipmux-template.yml");
1634
1635             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/resource-IpMuxDemux-template.yml");
1636             readPayload(inputArtifacts, fis1, "resource-IpMuxDemux-template.yml");
1637
1638             InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-TunnelXconn-template.yml");
1639             readPayload(inputArtifacts, fis3, "resource-TunnelXconn-template.yml");
1640
1641             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1642             List<ToscaTemplate> toscas = new LinkedList();
1643
1644             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1645
1646             for (Artifact inputArtifact : inputArtifacts) {
1647                 toscas.add(getToscaModel(inputArtifact));
1648             }
1649             List<Artifact> resultData = data.getResultData();
1650
1651             Map<String, Model> outputArtifactMap = new HashMap<>();
1652             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1653             ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1654             testResourceTosca(toscas.iterator(), outputArtifactMap);
1655
1656             Assert.assertEquals(5, data.getResultData().size());
1657
1658             removeMockArtifact(data.getResultData().iterator());
1659
1660             ArtifactGenerationServiceTest.validateName(data.getResultData());
1661
1662         } catch (Exception e) {
1663             Assert.fail(e.getMessage());
1664         }
1665     }
1666
1667     @Test
1668     public void testArtifactGenerationAllottedResourceWithOutProvidingServiceId() {
1669         try {
1670             List<Artifact> inputArtifacts = new ArrayList();
1671
1672             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service-SdWan-template_WithOutDepSerId.yml");
1673             readPayload(inputArtifacts, fis2, "service-SdWan-template_WithOutDepSerId.yml");
1674
1675             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/resource-VhnfNonHeat-template_WithOutDepSerId.yml");
1676             readPayload(inputArtifacts, fis1, "resource-VhnfNonHeat-template_WithOutDepSerId.yml");
1677
1678             InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-TunnelXconn-template_WithOutDepSerId.yml");
1679             readPayload(inputArtifacts, fis3, "resource-TunnelXconn-template_WithOutDepSerId.yml");
1680
1681             InputStream fis4 = SampleJUnitTest.class.getResourceAsStream
1682                 ("/resource-ServiceAdmin-template_WithOutDepSerId.yml");
1683             readPayload(inputArtifacts, fis4, "resource-ServiceAdmin-template_WithOutDepSerId.yml");
1684
1685             InputStream fis5 = SampleJUnitTest.class.getResourceAsStream
1686                 ("/resource-IpMuxDemux-template_WithOutDepSerId.yml");
1687             readPayload(inputArtifacts, fis5, "resource-IpMuxDemux-template_WithOutDepSerId.yml");
1688
1689             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1690             List<ToscaTemplate> toscas = new LinkedList();
1691             for (Artifact inputArtifact : inputArtifacts) {
1692                 toscas.add(getToscaModel(inputArtifact));
1693             }
1694
1695             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1696             List<Artifact> resultData = data.getResultData();
1697             Assert.assertEquals(data.getErrorData().isEmpty(),false);
1698             Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format
1699                 (GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING, toscas.get(2).getModelId()));
1700         } catch (Exception e) {
1701             Assert.fail(e.getMessage());
1702         }
1703     }
1704
1705     @Test
1706     public void testArtifactGenerationAllottedResourceWithVF() {
1707         try {
1708             List<Artifact> inputArtifacts = new ArrayList();
1709
1710             InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service-SdWan-template_AllRes_VF.yml");
1711             readPayload(inputArtifacts, fis2, "service-SdWan-template_AllRes_VF.yml");
1712
1713             InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/resource-VhnfNonHeat-template_AllRes_VF.yml");
1714             readPayload(inputArtifacts, fis1, "resource-VhnfNonHeat-template_AllRes_VF.yml");
1715
1716             InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-TunnelXconn-template_AllRes_VF.yml");
1717             readPayload(inputArtifacts, fis3, "resource-TunnelXconn-template_AllRes_VF.yml");
1718
1719             InputStream fis4 = SampleJUnitTest.class.getResourceAsStream
1720                 ("/resource-ServiceAdmin-template_AllRes_VF.yml");
1721             readPayload(inputArtifacts, fis4, "resource-ServiceAdmin-template_AllRes_VF.yml");
1722
1723             InputStream fis5 = SampleJUnitTest.class.getResourceAsStream
1724                 ("/resource-IpMuxDemux-template_AllRes_VF.yml");
1725             readPayload(inputArtifacts, fis5, "resource-IpMuxDemux-template_AllRes_VF.yml");
1726
1727             ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1728             List<ToscaTemplate> toscas = new LinkedList();
1729
1730             GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1731             for (Artifact inputArtifact : inputArtifacts) {
1732                 toscas.add(getToscaModel(inputArtifact));
1733             }
1734             List<Artifact> resultData = data.getResultData();
1735
1736             Map<String, Model> outputArtifactMap = new HashMap<>();
1737             ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1738             ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1739             testResourceTosca(toscas.iterator(), outputArtifactMap);
1740
1741             Assert.assertEquals(7, data.getResultData().size());
1742
1743             removeMockArtifact(data.getResultData().iterator());
1744
1745             ArtifactGenerationServiceTest.validateName(data.getResultData());
1746         } catch (Exception e) {
1747             Assert.fail(e.getMessage());
1748         }
1749     }
1750
1751     public static void readPayload(List<Artifact> inputArtifacts,InputStream fis, String fileName) throws IOException {
1752         byte[] payload = new byte[fis.available()];
1753         fis.read(payload);
1754         String checksum = GeneratorUtil.checkSum(payload);
1755         byte[] encodedPayload = GeneratorUtil.encode(payload);
1756         Artifact artifact = new Artifact(aaiArtifactType, aaiArtifactGroupType, checksum, encodedPayload);
1757         artifact.setName(fileName);
1758         artifact.setLabel(fileName);
1759         artifact.setDescription(fileName);
1760         //artifact.setVersion("1.0");
1761         System.out.println(artifact.getName());
1762         inputArtifacts.add(artifact);
1763     }
1764
1765
1766     /**
1767      * Get the tosca java model from the tosca input artifact
1768      *
1769      * @param input Input tosca file and its metadata information as {@link Artifact} object
1770      * @return Translated {@link ToscaTemplate tosca} object
1771      * @throws SecurityException
1772      */
1773     public static ToscaTemplate getToscaModel(Artifact input) throws SecurityException {
1774         byte[] decodedInput = GeneratorUtil.decoder(input.getPayload());
1775         String checksum = GeneratorUtil.checkSum(decodedInput);
1776         if (checksum.equals(input.getChecksum())) {
1777             try {
1778                 return GeneratorUtil.translateTosca(new String(decodedInput), ToscaTemplate.class);
1779             } catch (Exception e) {
1780                 e.printStackTrace();
1781                 throw new IllegalArgumentException(String.format(GENERATOR_AAI_ERROR_INVALID_TOSCA, input.getName()));
1782             }
1783         } else {
1784             throw new SecurityException(String.format(GENERATOR_AAI_ERROR_CHECKSUM_MISMATCH, input.getName()));
1785         }
1786     }
1787
1788     public static void removeMockArtifact(Iterator<Artifact> itr) {
1789         while (itr.hasNext()){
1790             if(itr.next().getType().equals("OTHER")){
1791                 itr.remove();
1792             }
1793         }
1794     }
1795
1796     /*public static void testResourceTosca(Iterator<ToscaTemplate> itr, Map<String, Model> outputArtifactMap) {
1797         while(itr.hasNext()){
1798             ToscaTemplate toscaTemplate = itr.next();
1799             if("VF".equals(toscaTemplate.getMetadata().get("type"))){
1800                 ArtifactGenerationServiceTest.testResourceTosca(outputArtifactMap, toscaTemplate);
1801             }
1802         }
1803     }*/
1804
1805 }