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