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