2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.generator;
23 import org.openecomp.sdc.generator.aai.model.Widget;
24 import org.openecomp.sdc.generator.aai.tosca.ToscaTemplate;
25 import org.openecomp.sdc.generator.aai.xml.Model;
26 import org.openecomp.sdc.generator.data.*;
27 import org.openecomp.sdc.generator.impl.ArtifactGenerationServiceImpl;
29 import junit.framework.TestCase;
30 import org.junit.Assert;
31 import org.junit.Test;
36 import static org.openecomp.sdc.generator.ArtifactGenerationServiceTest.*;
37 import static org.openecomp.sdc.generator.data.GeneratorConstants.*;
39 public class SampleJUnitTest extends TestCase {
41 public static final String aaiArtifactType = ArtifactType.AAI.name();
42 public static final String aaiArtifactGroupType = GroupType.DEPLOYMENT.name();
43 public static final String generatorConfig = "{\"artifactTypes\": [\"OTHER\",\"AAI\"]}";
44 public static final String ARTIFACTGENERATOR_CONFIG = "artifactgenerator.config";
45 public static final String CONFIG_PATH = "/qa-test-repo/jmeter3/apache-jmeter-3" +
47 //public static final String CONFIG_PATH ="C:\\Jmeter-Copy\\jmeter3\\apache-jmeter-3" +
49 public static final String GENERATOR_AAI_CONFIGLPROP_NOT_FOUND =
50 "Cannot generate artifacts. Widget configuration not found for %s";
51 public static final String GENERATOR_AAI_CONFIGFILE_NOT_FOUND =
52 "Cannot generate artifacts. Artifact Generator Configuration file not found at %s";
53 public static final String GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND =
54 "Cannot generate artifacts. artifactgenerator.config system property not configured";
55 public static final String INVALID_VALUE_INVARIANT =
56 "Invalid value for mandatory attribute <invariantUUID> in Artifact";
57 public static final String INVALID_VALUE_UUID =
58 "Invalid value for mandatory attribute <UUID> in Artifact:";
59 public static final Map<String, String> additionalParams = new HashMap<>();
62 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
65 private void loadConfig(Properties properties) throws IOException {
66 String configLocation = System.getProperty(ARTIFACTGENERATOR_CONFIG);
67 if (configLocation != null) {
68 File file = new File(configLocation);
70 properties.load(new FileInputStream(file));
74 public SampleJUnitTest(String name) throws Exception {
76 System.setProperty(ARTIFACTGENERATOR_CONFIG,CONFIG_PATH+"Artifact-Generator.properties");
77 loadConfig(ArtifactGenerationServiceTest.properties);
80 public SampleJUnitTest() {
82 System.setProperty(ARTIFACTGENERATOR_CONFIG,CONFIG_PATH+"Artifact-Generator.properties");
86 public void testArtifactGenerationSingleVFSingleVFModule() {
88 List<Artifact> inputArtifacts = new ArrayList();
89 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_SingleVFVFMod.yml");
90 readPayload(inputArtifacts, fis1, "vf_vmme_template_SingleVFVFMod.yml");
93 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_SingleVFVFMod.yml");
94 readPayload(inputArtifacts, fis2, "service_vmme_template_SingleVFVFMod.yml");
95 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
96 List<ToscaTemplate> toscas = new LinkedList();
98 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
100 for (Artifact inputArtifact : inputArtifacts) {
101 toscas.add(getToscaModel(inputArtifact));
103 List<Artifact> resultData = data.getResultData();
105 Map<String, Model> outputArtifactMap = new HashMap<>();
106 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
107 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
109 testResourceTosca(toscas.iterator(), outputArtifactMap);
111 Assert.assertEquals(5, data.getResultData().size());
113 removeMockArtifact(data.getResultData().iterator());
115 ArtifactGenerationServiceTest.validateName(data.getResultData());
118 } catch (Exception e) {
119 Assert.fail(e.getMessage());
124 public void testArtifactGenerationMissingVFInServiceTOSCA() {
126 List<Artifact> inputArtifacts = new ArrayList();
127 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_MissingVFInServiceTOSCA.yml");
128 readPayload(inputArtifacts, fis2, "service_vmme_template_MissingVFInServiceTOSCA.yml");
129 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
130 List<ToscaTemplate> toscas = new LinkedList();
132 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
134 for (Artifact inputArtifact : inputArtifacts) {
135 toscas.add(getToscaModel(inputArtifact));
137 List<Artifact> resultData = data.getResultData();
139 Map<String, Model> outputArtifactMap = new HashMap<>();
140 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
141 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
143 Assert.assertEquals(3, data.getResultData().size());
145 removeMockArtifact(data.getResultData().iterator());
147 ArtifactGenerationServiceTest.validateName(data.getResultData());
150 } catch (Exception e) {
151 Assert.fail(e.getMessage());
156 public void testArtifactGenerationVerifySameStaticWidgetsForAllServices() {
158 List<Artifact> inputArtifacts = new ArrayList();
159 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_SameWidgets1.yml");
160 readPayload(inputArtifacts, fis1, "vf_vmme_template_SameWidgets1.yml");
163 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_SameWidget1.yml");
164 readPayload(inputArtifacts, fis2, "service_vmme_template_SameWidget1.yml");
165 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
166 List<ToscaTemplate> toscas = new LinkedList();
168 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
170 for (Artifact inputArtifact : inputArtifacts) {
171 toscas.add(getToscaModel(inputArtifact));
173 List<Artifact> resultData = data.getResultData();
175 Map<String, Model> outputArtifactMap = new HashMap<>();
176 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
178 removeMockArtifact(data.getResultData().iterator());
181 List<Artifact> inputArtifacts2 = new ArrayList();
182 InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_SameWidgets2.yml");
183 readPayload(inputArtifacts2, fis3, "vf_vmme_template_SameWidgets2.yml");
185 InputStream fis4 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_SameWidget2.yml");
186 readPayload(inputArtifacts2, fis4, "service_vmme_template_SameWidget2.yml");
187 ArtifactGenerationServiceImpl obj2 = new ArtifactGenerationServiceImpl();
189 GenerationData data2 = obj2.generateArtifact(inputArtifacts2, generatorConfig,additionalParams);
190 List<Artifact> resultData2 = data2.getResultData();
192 List<ToscaTemplate> toscas2 = new LinkedList();
194 for (Artifact inputArtifact : inputArtifacts2) {
195 toscas2.add(getToscaModel(inputArtifact));
198 Map<String, Model> outputArtifactMap2 = new HashMap<>();
199 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap2, resultData2);
200 removeMockArtifact(data2.getResultData().iterator());
202 Map<String,String> map = new HashMap<>();
203 Iterator<Artifact> itr = data.getResultData().iterator();
204 while(itr.hasNext()){
205 Artifact artifact=itr.next();
206 if(artifact.getLabel().contains("AAI-widget")){
207 map.put(artifact.getName(),artifact.getChecksum());
210 Map<String,String> map2 = new HashMap<>();
211 Iterator<Artifact> itr2 = data2.getResultData().iterator();
212 while(itr2.hasNext()){
213 Artifact artifact=itr2.next();
214 if(artifact.getLabel().contains("AAI-widget")){
215 map2.put(artifact.getName(),artifact.getChecksum());
218 Assert.assertEquals(map.size(),map2.size());
219 for(String name : map.keySet()){
220 Assert.assertEquals(map.get(name),map2.get(name));
223 } catch (Exception e) {
224 Assert.fail(e.getMessage());
229 public void testArtifactGenerationMulVFModule() {
231 List<Artifact> inputArtifacts = new ArrayList();
232 String[] resourceFileList = {};
233 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_MulVFVFMod.yml");
234 readPayload(inputArtifacts,fis1, "vf_vmme_template_MulVFVFMod.yml");
237 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_MulVFVFMod.yml");
238 readPayload(inputArtifacts,fis2, "service_vmme_template_MulVFVFMod.yml");
240 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
241 List<ToscaTemplate> toscas = new LinkedList();
243 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
245 for (Artifact inputArtifact : inputArtifacts) {
246 toscas.add(getToscaModel(inputArtifact));
248 List<Artifact> resultData = data.getResultData();
250 Map<String, Model> outputArtifactMap = new HashMap<>();
251 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
252 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
253 testResourceTosca(toscas.iterator(), outputArtifactMap);
255 Assert.assertEquals(3,data.getResultData().size());
257 removeMockArtifact(data.getResultData().iterator());
259 ArtifactGenerationServiceTest.validateName(data.getResultData());
261 } catch (Exception e) {
262 Assert.fail(e.getMessage());
267 public void testArtifactGenerationMulVFs() {
269 List<Artifact> inputArtifacts = new ArrayList();
271 InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/CMAUI_VF.yaml");
272 readPayload(inputArtifacts,fis3, "CMAUI_VF.yaml");
274 InputStream fis4 = SampleJUnitTest.class.getResourceAsStream("/ECA_OAM_VF.yaml");
275 readPayload(inputArtifacts,fis4, "ECA_OAM_VF.yaml");
277 InputStream fis5 = SampleJUnitTest.class.getResourceAsStream("/MMSC_Sevice_07_25_16.yaml");
278 readPayload(inputArtifacts,fis5, "MMSC_Sevice_07_25_16.yaml");
280 InputStream fis6 = SampleJUnitTest.class.getResourceAsStream("/MMSC_VF.yaml");
281 readPayload(inputArtifacts,fis6, "MMSC_VF.yaml");
283 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
284 List<ToscaTemplate> toscas = new LinkedList();
286 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
288 for (Artifact inputArtifact : inputArtifacts) {
289 toscas.add(getToscaModel(inputArtifact));
291 List<Artifact> resultData = data.getResultData();
293 Map<String, Model> outputArtifactMap = new HashMap<>();
294 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
295 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
296 testResourceTosca(toscas.iterator(), outputArtifactMap);
298 Assert.assertEquals(8,data.getResultData().size());
300 removeMockArtifact(data.getResultData().iterator());
302 ArtifactGenerationServiceTest.validateName(data.getResultData());
304 } catch (Exception e) {
305 Assert.fail(e.getMessage());
310 public void testArtifactGenerationDupVFUUID() {
312 List<Artifact> inputArtifacts = new ArrayList();
313 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_DupVFUUID.yml");
314 readPayload(inputArtifacts,fis1, "vf_vmme_template_DupVFUUID.yml");
317 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_DupVFUUID.yml");
318 readPayload(inputArtifacts,fis2, "service_vmme_template_DupVFUUID.yml");
319 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
320 List<ToscaTemplate> toscas = new LinkedList();
322 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
324 for (Artifact inputArtifact : inputArtifacts) {
325 toscas.add(getToscaModel(inputArtifact));
327 List<Artifact> resultData = data.getResultData();
329 Map<String, Model> outputArtifactMap = new HashMap<>();
330 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
331 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
332 testResourceTosca(toscas.iterator(), outputArtifactMap);
334 Assert.assertEquals(5,data.getResultData().size());
336 removeMockArtifact(data.getResultData().iterator());
338 ArtifactGenerationServiceTest.validateName(data.getResultData());
340 } catch (Exception e) {
341 Assert.fail(e.getMessage());
346 public void testArtifactGenerationDupVFModUUID() {
348 List<Artifact> inputArtifacts = new ArrayList();
349 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_DupVFModUUID.yml");
350 readPayload(inputArtifacts,fis1, "vf_vmme_template_DupVFModUUID.yml");
353 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_DupVFModUUID.yml");
354 readPayload(inputArtifacts,fis2, "service_vmme_template_DupVFModUUID.yml");
355 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
356 List<ToscaTemplate> toscas = new LinkedList();
358 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
360 for (Artifact inputArtifact : inputArtifacts) {
361 toscas.add(getToscaModel(inputArtifact));
363 List<Artifact> resultData = data.getResultData();
365 Map<String, Model> outputArtifactMap = new HashMap<>();
366 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
367 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
368 testResourceTosca(toscas.iterator(), outputArtifactMap);
370 Assert.assertEquals(5,data.getResultData().size());
372 removeMockArtifact(data.getResultData().iterator());
374 ArtifactGenerationServiceTest.validateName(data.getResultData());
375 } catch (Exception e) {
376 Assert.fail(e.getMessage());
381 public void testArtifactGenerationVerifyVFModWithoutVNFC() {
383 List<Artifact> inputArtifacts = new ArrayList();
384 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyVFModWithoutVNFC.yml");
385 readPayload(inputArtifacts,fis1, "vf_vmme_template_VerifyVFModWithoutVNFC.yml");
388 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyVFModWithoutVNFC.yml");
389 readPayload(inputArtifacts,fis2, "service_vmme_template_VerifyVFModWithoutVNFC.yml");
390 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
391 List<ToscaTemplate> toscas = new LinkedList();
393 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
395 for (Artifact inputArtifact : inputArtifacts) {
396 toscas.add(getToscaModel(inputArtifact));
398 List<Artifact> resultData = data.getResultData();
400 Map<String, Model> outputArtifactMap = new HashMap<>();
401 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
402 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
403 testResourceTosca(toscas.iterator(), outputArtifactMap);
405 Assert.assertEquals(5,data.getResultData().size());
407 removeMockArtifact(data.getResultData().iterator());
409 ArtifactGenerationServiceTest.validateName(data.getResultData());
410 } catch (Exception e) {
411 Assert.fail(e.getMessage());
416 public void testArtifactGenerationVerifyVFModWithInvalidMember() {
418 List<Artifact> inputArtifacts = new ArrayList();
419 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyVFModWithInvalidNo.yml");
420 readPayload(inputArtifacts,fis1, "vf_vmme_template_VerifyVFModWithInvalidNo.yml");
423 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyVFModWithInvalidNo.yml");
424 readPayload(inputArtifacts,fis2, "service_vmme_template_VerifyVFModWithInvalidNo.yml");
425 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
426 List<ToscaTemplate> toscas = new LinkedList();
428 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
430 for (Artifact inputArtifact : inputArtifacts) {
431 toscas.add(getToscaModel(inputArtifact));
433 List<Artifact> resultData = data.getResultData();
435 Map<String, Model> outputArtifactMap = new HashMap<>();
436 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
437 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
438 testResourceTosca(toscas.iterator(), outputArtifactMap);
440 Assert.assertEquals(5,data.getResultData().size());
442 removeMockArtifact(data.getResultData().iterator());
444 ArtifactGenerationServiceTest.validateName(data.getResultData());
445 } catch (Exception e) {
446 Assert.fail(e.getMessage());
451 public void testArtifactGenerationNullFields() {
453 List<Artifact> inputArtifacts = new ArrayList();
454 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_NullFields.yml");
455 readPayload(inputArtifacts,fis1, "vf_vmme_template_NullFields.yml");
458 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_NullFields.yml");
459 readPayload(inputArtifacts,fis2, "service_vmme_template_NullFields.yml");
460 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
462 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
463 Assert.assertEquals(false,data.getErrorData().isEmpty());
465 Assert.assertEquals("Invalid Service/Resource definition mandatory attribute <UUID> missing in Artifact: <"+inputArtifacts.get(0).getName()+">",data.getErrorData().get("AAI").get(0));
467 Assert.assertEquals(2,data.getResultData().size());
469 } catch (Exception e) {
471 Assert.fail(e.getMessage());
476 public void testArtifactGenerationInCorrectYmlFormat() {
478 List<Artifact> inputArtifacts = new ArrayList();
480 InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/CMAUI_VFInvalidFormat.yaml");
481 readPayload(inputArtifacts,fis3, "CMAUI_VFInvalidFormat.yaml");
483 InputStream fis4 = SampleJUnitTest.class.getResourceAsStream("/ECA_OAM_VFInvalidFormat.yaml");
484 readPayload(inputArtifacts,fis4, "ECA_OAM_VFInvalidFormat.yaml");
486 InputStream fis5 = SampleJUnitTest.class.getResourceAsStream("/MMSC_Sevice_07_25_16InvalidFormat.yaml");
487 readPayload(inputArtifacts,fis5, "MMSC_Sevice_07_25_16InvalidFormat.yaml");
489 InputStream fis6 = SampleJUnitTest.class.getResourceAsStream("/MMSC_VFInvalidFormat.yaml");
490 readPayload(inputArtifacts,fis6, "MMSC_VFInvalidFormat.yaml");
492 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
494 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
495 Assert.assertEquals(false,data.getErrorData().isEmpty());
497 Assert.assertEquals("Invalid format for Tosca YML : "+inputArtifacts.get(1).getName(),data.getErrorData().get("AAI").get(0));
499 Assert.assertEquals(2,data.getResultData().size());
501 } catch (Exception e) {
502 Assert.fail(e.getMessage());
507 public void testArtifactGenerationMulComp() {
509 List<Artifact> inputArtifacts = new ArrayList();
510 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_MulComp.yml");
511 readPayload(inputArtifacts,fis1, "vf_vmme_template_MulComp.yml");
514 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_MulComp.yml");
515 readPayload(inputArtifacts,fis2, "service_vmme_template_MulComp.yml");
516 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
517 List<ToscaTemplate> toscas = new LinkedList();
519 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
521 for (Artifact inputArtifact : inputArtifacts) {
522 toscas.add(getToscaModel(inputArtifact));
524 List<Artifact> resultData = data.getResultData();
526 Map<String, Model> outputArtifactMap = new HashMap<>();
527 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
528 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
529 testResourceTosca(toscas.iterator(), outputArtifactMap);
531 Assert.assertEquals(5,data.getResultData().size());
533 removeMockArtifact(data.getResultData().iterator());
535 ArtifactGenerationServiceTest.validateName(data.getResultData());
536 } catch (Exception e) {
537 Assert.fail(e.getMessage());
542 public void testArtifactGenerationOrphan() {
544 List<Artifact> inputArtifacts = new ArrayList();
546 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_Orphan.yml");
547 readPayload(inputArtifacts,fis1, "vf_vmme_template_Orphan.yml");
550 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_Orphan.yml");
551 readPayload(inputArtifacts,fis2, "service_vmme_template_Orphan.yml");
553 InputStream fis4 = SampleJUnitTest.class.getResourceAsStream("/ECA_OAM_VFOrphan.yaml");
554 readPayload(inputArtifacts,fis4, "ECA_OAM_VFOrphan.yaml");
556 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
557 List<ToscaTemplate> toscas = new LinkedList();
559 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
561 for (Artifact inputArtifact : inputArtifacts) {
562 toscas.add(getToscaModel(inputArtifact));
564 List<Artifact> resultData = data.getResultData();
566 Map<String, Model> outputArtifactMap = new HashMap<>();
567 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
568 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
569 testResourceTosca(toscas.iterator(), outputArtifactMap);
571 Assert.assertEquals(5,data.getResultData().size());
573 removeMockArtifact(data.getResultData().iterator());
575 ArtifactGenerationServiceTest.validateName(data.getResultData());
576 } catch (Exception e) {
577 Assert.fail(e.getMessage());
582 public void testArtifactGenerationMissingVFTemplate() {
584 List<Artifact> inputArtifacts = new ArrayList();
586 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_MissingVFTemplate.yml");
587 readPayload(inputArtifacts,fis1, "service_vmme_template_MissingVFTemplate.yml");
591 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
592 List<ToscaTemplate> toscas = new LinkedList();
594 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
596 for (Artifact inputArtifact : inputArtifacts) {
597 toscas.add(getToscaModel(inputArtifact));
599 List<Artifact> resultData = data.getResultData();
601 Map<String, Model> outputArtifactMap = new HashMap<>();
602 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
603 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
606 Assert.assertEquals(3,data.getResultData().size());
608 removeMockArtifact(data.getResultData().iterator());
610 ArtifactGenerationServiceTest.validateName(data.getResultData());
611 } catch (Exception e) {
612 Assert.fail(e.getMessage());
617 public void testArtifactGenerationMissingVFModule() {
619 List<Artifact> inputArtifacts = new ArrayList();
621 InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/CMAUI_VFMissingVFModule.yaml");
622 readPayload(inputArtifacts,fis3, "CMAUI_VFMissingVFModule.yaml");
624 InputStream fis4 = SampleJUnitTest.class.getResourceAsStream("/ECA_OAM_VFMissingVFModule.yaml");
625 readPayload(inputArtifacts,fis4, "ECA_OAM_VFMissingVFModule.yaml");
627 InputStream fis5 = SampleJUnitTest.class.getResourceAsStream("/MMSC_Sevice_07_25_16MissingVFModule.yaml");
628 readPayload(inputArtifacts,fis5, "MMSC_Sevice_07_25_16MissingVFModule.yaml");
630 InputStream fis6 = SampleJUnitTest.class.getResourceAsStream("/MMSC_VFMissingVFModule.yaml");
631 readPayload(inputArtifacts,fis6, "MMSC_VFMissingVFModule.yaml");
633 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
634 List<ToscaTemplate> toscas = new LinkedList();
636 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
638 for (Artifact inputArtifact : inputArtifacts) {
639 toscas.add(getToscaModel(inputArtifact));
641 List<Artifact> resultData = data.getResultData();
643 Map<String, Model> outputArtifactMap = new HashMap<>();
644 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
645 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
646 testResourceTosca(toscas.iterator(), outputArtifactMap);
648 Assert.assertEquals(8,data.getResultData().size());
650 removeMockArtifact(data.getResultData().iterator());
652 ArtifactGenerationServiceTest.validateName(data.getResultData());
654 } catch (Exception e) {
656 Assert.fail(e.getMessage());
661 public void testArtifactGenerationEmptyArtifact() {
663 List<Artifact> inputArtifacts = new ArrayList();
665 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
667 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
668 Assert.assertEquals(false,data.getErrorData().isEmpty());
669 Assert.assertEquals("Service tosca missing from list of input artifacts",data.getErrorData().get("AAI").get(0));
671 Assert.assertEquals(2,data.getResultData().size());
673 } catch (Exception e) {
674 Assert.fail(e.getMessage());
679 public void testArtifactGenerationMissingConfigFile() {
681 List<Artifact> inputArtifacts = new ArrayList();
683 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_SingleVFVFMod.yml");
684 readPayload(inputArtifacts,fis1, "vf_vmme_template_SingleVFVFMod.yml");
687 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_SingleVFVFMod.yml");
688 readPayload(inputArtifacts,fis2, "service_vmme_template_SingleVFVFMod.yml");
689 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
691 GenerationData data = obj.generateArtifact(inputArtifacts, "",additionalParams);
692 Assert.assertEquals(false,data.getErrorData().isEmpty());
693 Assert.assertEquals("Invalid Client Configuration",data.getErrorData().get("ARTIFACT_GENERATOR_INVOCATION_ERROR").get(0));
695 Assert.assertEquals(0,data.getResultData().size());
697 } catch (Exception e) {
698 Assert.fail(e.getMessage());
704 public void testArtifactGenerationWithNodeTemplates() {
706 List<Artifact> inputArtifacts = new ArrayList();
708 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/ServiceWithNodetemplate.yml");
709 readPayload(inputArtifacts,fis1, "ServiceWithNodetemplate.yml");
712 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/Resource0-template.yml");
713 readPayload(inputArtifacts,fis2, "Resource0-template.yml");
715 InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/Resource1-template.yml");
716 readPayload(inputArtifacts,fis3, "Resource1-template.yml");
718 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
719 List<ToscaTemplate> toscas = new LinkedList();
721 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
723 for (Artifact inputArtifact : inputArtifacts) {
724 toscas.add(getToscaModel(inputArtifact));
726 List<Artifact> resultData = data.getResultData();
728 Map<String, Model> outputArtifactMap = new HashMap<>();
729 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
730 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
731 testResourceTosca(toscas.iterator(), outputArtifactMap);
733 Assert.assertEquals(5,data.getResultData().size());
735 removeMockArtifact(data.getResultData().iterator());
737 ArtifactGenerationServiceTest.validateName(data.getResultData());
740 } catch (Exception e) {
741 Assert.fail(e.getMessage());
746 public void testArtifactGenerationWithoutNodeTemplates() {
748 List<Artifact> inputArtifacts = new ArrayList();
750 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/Service0-template.yml");
751 readPayload(inputArtifacts,fis1, "Service0-template.yml");
755 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
756 List<ToscaTemplate> toscas = new LinkedList();
758 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
760 for (Artifact inputArtifact : inputArtifacts) {
761 toscas.add(getToscaModel(inputArtifact));
763 List<Artifact> resultData = data.getResultData();
765 Map<String, Model> outputArtifactMap = new HashMap<>();
766 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
767 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
770 Assert.assertEquals(3,data.getResultData().size());
772 removeMockArtifact(data.getResultData().iterator());
774 ArtifactGenerationServiceTest.validateName(data.getResultData());
777 } catch (Exception e) {
778 Assert.fail(e.getMessage());
783 public void testArtifactGenerationWithArtifactNameAndDescMoreThan256() {
785 List<Artifact> inputArtifacts = new ArrayList();
787 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/Service0-templateMoreThan256.yml");
788 readPayload(inputArtifacts,fis1, "Service0-templateMoreThan256.yml");
792 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
793 List<ToscaTemplate> toscas = new LinkedList();
795 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
797 for (Artifact inputArtifact : inputArtifacts) {
798 toscas.add(getToscaModel(inputArtifact));
800 List<Artifact> resultData = data.getResultData();
802 Map<String, Model> outputArtifactMap = new HashMap<>();
803 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
804 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
807 Assert.assertEquals(3,data.getResultData().size());
809 removeMockArtifact(data.getResultData().iterator());
811 for(Artifact artifact : data.getResultData()){
812 checkArtifactName(artifact.getName());
813 checkArtifactLabel(artifact.getLabel());
814 checkArtifactDescription(artifact.getDescription());
818 } catch (Exception e) {
819 Assert.fail(e.getMessage());
824 public void testArtifactGenerationWithDifferentVersionOfSameVF() {
826 List<Artifact> inputArtifacts = new ArrayList();
828 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_DiffVerOfSameVF.yml");
829 readPayload(inputArtifacts,fis1, "service_vmme_template_DiffVerOfSameVF.yml");
832 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_DiffVerOfSameVF_1.yml");
833 readPayload(inputArtifacts,fis2, "vf_vmme_template_DiffVerOfSameVF_1.yml");
836 InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_DiffVerOfSameVF_2.yml");
837 readPayload(inputArtifacts,fis3, "vf_vmme_template_DiffVerOfSameVF_2.yml");
840 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
841 List<ToscaTemplate> toscas = new LinkedList();
843 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
845 for (Artifact inputArtifact : inputArtifacts) {
846 toscas.add(getToscaModel(inputArtifact));
848 List<Artifact> resultData = data.getResultData();
850 Map<String, Model> outputArtifactMap = new HashMap<>();
851 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
852 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
853 testResourceTosca(toscas.iterator(), outputArtifactMap);
855 Assert.assertEquals(6,data.getResultData().size());
857 removeMockArtifact(data.getResultData().iterator());
859 ArtifactGenerationServiceTest.validateName(data.getResultData());
862 } catch (Exception e) {
863 Assert.fail(e.getMessage());
868 public void testArtifactGenerationWithDifferentVersionOfSameVFModWithSameInvId() {
870 List<Artifact> inputArtifacts = new ArrayList();
872 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_DiffVerOfSameVFModWithSameInvId.yml");
873 readPayload(inputArtifacts,fis1, "service_vmme_template_DiffVerOfSameVFModWithSameInvId.yml");
876 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_DiffVerOfSameVFModWithSameInvId.yml");
877 readPayload(inputArtifacts,fis2, "vf_vmme_template_DiffVerOfSameVFModWithSameInvId.yml");
880 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
881 List<ToscaTemplate> toscas = new LinkedList();
883 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
885 for (Artifact inputArtifact : inputArtifacts) {
886 toscas.add(getToscaModel(inputArtifact));
888 List<Artifact> resultData = data.getResultData();
890 Map<String, Model> outputArtifactMap = new HashMap<>();
891 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
892 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
893 testResourceTosca(toscas.iterator(), outputArtifactMap);
895 Assert.assertEquals(6,data.getResultData().size());
897 removeMockArtifact(data.getResultData().iterator());
899 ArtifactGenerationServiceTest.validateName(data.getResultData());
902 } catch (Exception e) {
903 Assert.fail(e.getMessage());
908 public void testArtifactGenerationWithServiceContainingL3Network() {
910 List<Artifact> inputArtifacts = new ArrayList();
912 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithL3Network.yml");
913 readPayload(inputArtifacts,fis1, "service_vmme_template_WithL3Network.yml");
916 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithL3Network.yml");
917 readPayload(inputArtifacts,fis2, "vf_vmme_template_WithL3Network.yml");
920 InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource-template_WithL3Network.yml");
921 readPayload(inputArtifacts,fis3, "resource-AllottedResource-template_WithL3Network.yml");
924 InputStream fis4 = SampleJUnitTest.class.getResourceAsStream
925 ("/resource-Extvl-template_WithL3Network.yml");
926 readPayload(inputArtifacts,fis4, "resource-Extvl-template_WithL3Network.yml");
929 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
930 List<ToscaTemplate> toscas = new LinkedList();
932 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
934 for (Artifact inputArtifact : inputArtifacts) {
935 toscas.add(getToscaModel(inputArtifact));
937 List<Artifact> resultData = data.getResultData();
939 Map<String, Model> outputArtifactMap = new HashMap<>();
940 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
941 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
942 testResourceTosca(toscas.iterator(), outputArtifactMap);
944 Assert.assertEquals(7,data.getResultData().size());
946 removeMockArtifact(data.getResultData().iterator());
948 ArtifactGenerationServiceTest.validateName(data.getResultData());
951 } catch (Exception e) {
952 Assert.fail(e.getMessage());
957 public void testArtifactGenerationWithServiceContainingDupL3Network() {
959 List<Artifact> inputArtifacts = new ArrayList();
961 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithDupL3Network.yml");
962 readPayload(inputArtifacts,fis1, "service_vmme_template_WithDupL3Network.yml");
965 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithDupL3Network.yml");
966 readPayload(inputArtifacts,fis2, "vf_vmme_template_WithDupL3Network.yml");
969 InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource-template_WithDupL3Network.yml");
970 readPayload(inputArtifacts,fis3, "resource-AllottedResource-template_WithDupL3Network.yml");
973 InputStream fis4 = SampleJUnitTest.class.getResourceAsStream
974 ("/resource-Extvl-template_WithDupL3Network.yml");
975 readPayload(inputArtifacts,fis4, "resource-Extvl-template_WithDupL3Network.yml");
978 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
979 List<ToscaTemplate> toscas = new LinkedList();
981 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
983 for (Artifact inputArtifact : inputArtifacts) {
984 toscas.add(getToscaModel(inputArtifact));
986 List<Artifact> resultData = data.getResultData();
988 Map<String, Model> outputArtifactMap = new HashMap<>();
989 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
990 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
991 testResourceTosca(toscas.iterator(), outputArtifactMap);
993 Assert.assertEquals(7,data.getResultData().size());
995 removeMockArtifact(data.getResultData().iterator());
997 ArtifactGenerationServiceTest.validateName(data.getResultData());
1000 } catch (Exception e) {
1001 Assert.fail(e.getMessage());
1006 public void testArtifactGenerationWithL3NetworkInVFMod() {
1008 List<Artifact> inputArtifacts = new ArrayList();
1010 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithL3NetworkInVFMod.yml");
1011 readPayload(inputArtifacts,fis1, "service_vmme_template_WithL3NetworkInVFMod.yml");
1014 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithL3NetworkInVFMod.yml");
1015 readPayload(inputArtifacts,fis2, "vf_vmme_template_WithL3NetworkInVFMod.yml");
1018 InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource-template_WithL3NetworkInVFMod.yml");
1019 readPayload(inputArtifacts,fis3, "resource-AllottedResource-template_WithL3NetworkInVFMod.yml");
1022 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1023 List<ToscaTemplate> toscas = new LinkedList();
1025 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1027 for (Artifact inputArtifact : inputArtifacts) {
1028 toscas.add(getToscaModel(inputArtifact));
1030 List<Artifact> resultData = data.getResultData();
1032 Map<String, Model> outputArtifactMap = new HashMap<>();
1033 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
1034 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
1035 testResourceTosca(toscas.iterator(), outputArtifactMap);
1037 Assert.assertEquals(6,data.getResultData().size());
1039 removeMockArtifact(data.getResultData().iterator());
1041 ArtifactGenerationServiceTest.validateName(data.getResultData());
1044 } catch (Exception e) {
1045 Assert.fail(e.getMessage());
1050 public void testArtifactGenerationWithDiffVersionOfSameL3Network() {
1052 List<Artifact> inputArtifacts = new ArrayList();
1054 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithDiffVersionOfSameL3Network.yml");
1055 readPayload(inputArtifacts,fis1, "service_vmme_template_WithDiffVersionOfSameL3Network.yml");
1058 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithDiffVersionOfSameL3Network.yml");
1059 readPayload(inputArtifacts,fis2, "vf_vmme_template_WithDiffVersionOfSameL3Network.yml");
1062 InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource-template_WithDiffVersionOfSameL3Network.yml");
1063 readPayload(inputArtifacts,fis3, "resource-AllottedResource-template_WithDiffVersionOfSameL3Network.yml");
1066 InputStream fis4 = SampleJUnitTest.class.getResourceAsStream
1067 ("/resource-Extvl-template_WithDiffVersionOfSameL3Network.yml");
1068 readPayload(inputArtifacts,fis4, "resource-Extvl-template_WithDiffVersionOfSameL3Network.yml");
1071 InputStream fis5 = SampleJUnitTest.class.getResourceAsStream
1072 ("/resource-Extvl-template_1_WithDiffVersionOfSameL3Network.yml");
1073 readPayload(inputArtifacts,fis5,
1074 "resource-Extvl-template_1_WithDiffVersionOfSameL3Network.yml");
1077 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1078 List<ToscaTemplate> toscas = new LinkedList();
1080 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1082 for (Artifact inputArtifact : inputArtifacts) {
1083 toscas.add(getToscaModel(inputArtifact));
1085 List<Artifact> resultData = data.getResultData();
1087 Map<String, Model> outputArtifactMap = new HashMap<>();
1088 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
1089 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
1090 testResourceTosca(toscas.iterator(), outputArtifactMap);
1092 Assert.assertEquals(8,data.getResultData().size());
1094 removeMockArtifact(data.getResultData().iterator());
1096 ArtifactGenerationServiceTest.validateName(data.getResultData());
1099 } catch (Exception e) {
1100 Assert.fail(e.getMessage());
1105 public void testArtifactGenerationWithInvIdGreaterThanSpecifiedLimit() {
1107 List<Artifact> inputArtifacts = new ArrayList();
1108 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithInvIdGreaterThanSpecifiedLimit.yml");
1109 readPayload(inputArtifacts,fis1, "vf_vmme_template_WithInvIdGreaterThanSpecifiedLimit" +
1113 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithInvIdGreaterThanSpecifiedLimit.yml");
1114 readPayload(inputArtifacts,fis2, "service_vmme_template_WithInvIdGreaterThanSpecifiedLimit.yml");
1115 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1118 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1119 Assert.assertEquals(false,data.getErrorData().isEmpty());
1121 Assert.assertEquals(INVALID_VALUE_INVARIANT + ": <" +inputArtifacts.get(1).getName()+">",data.getErrorData().get("AAI").get(0));
1123 Assert.assertEquals(2,data.getResultData().size());
1125 } catch (Exception e) {
1126 e.printStackTrace();
1127 Assert.fail(e.getMessage());
1132 public void testArtifactGenerationWithInvIdLesserThanSpecifiedLimit() {
1134 List<Artifact> inputArtifacts = new ArrayList();
1135 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithInvIdLesserThanSpecifiedLimit.yml");
1136 readPayload(inputArtifacts,fis1, "vf_vmme_template_WithInvIdLesserThanSpecifiedLimit" +
1140 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithInvIdLesserThanSpecifiedLimit.yml");
1141 readPayload(inputArtifacts,fis2, "service_vmme_template_WithInvIdLesserThanSpecifiedLimit.yml");
1142 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1145 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1146 Assert.assertEquals(false,data.getErrorData().isEmpty());
1148 Assert.assertEquals(INVALID_VALUE_UUID + " <"
1149 +inputArtifacts.get(1).getName()+">",data.getErrorData().get("AAI").get(0));
1151 Assert.assertEquals(2,data.getResultData().size());
1153 } catch (Exception e) {
1154 e.printStackTrace();
1155 Assert.fail(e.getMessage());
1161 public void testErrorWhenNoSystemPropConfigured() throws Exception {
1162 String configLoc = System.getProperty(ARTIFACTGENERATOR_CONFIG);
1164 List<Artifact> inputArtifacts = new ArrayList();
1165 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_NoSystemPropConfigured.yml");
1166 readPayload(inputArtifacts,fis1, "vf_vmme_template_NoSystemPropConfigured" +
1170 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_NoSystemPropConfigured.yml");
1171 readPayload(inputArtifacts,fis2, "service_vmme_template_NoSystemPropConfigured.yml");
1174 System.clearProperty(ARTIFACTGENERATOR_CONFIG);
1176 Map<String, Model> outputArtifactMap = new HashMap<>();
1177 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1178 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1179 Assert.assertEquals(false,data.getErrorData().isEmpty());
1180 Assert.assertEquals(data.getErrorData().
1181 get("AAI").get(0), GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND);
1182 } catch (Exception e) {
1183 Assert.fail(e.getMessage());
1186 System.setProperty(ARTIFACTGENERATOR_CONFIG,configLoc);
1191 public void testErrorWhenNoFileAtConfigLocation() throws Exception {
1192 String configLoc = System.getProperty(ARTIFACTGENERATOR_CONFIG);
1194 List<Artifact> inputArtifacts = new ArrayList();
1195 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_NoSystemPropConfigured.yml");
1196 readPayload(inputArtifacts,fis1, "vf_vmme_template_NoSystemPropConfigured" +
1200 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_NoSystemPropConfigured.yml");
1201 readPayload(inputArtifacts,fis2, "service_vmme_template_NoSystemPropConfigured.yml");
1204 System.setProperty(ARTIFACTGENERATOR_CONFIG,configLoc + File.separator + "testErrorWhenNoFileAtConfigLocation");
1205 Map<String, Model> outputArtifactMap = new HashMap<>();
1206 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1207 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1208 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1209 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format(
1210 GENERATOR_AAI_CONFIGFILE_NOT_FOUND,System.getProperty
1211 (ARTIFACTGENERATOR_CONFIG)));
1212 } catch (Exception e) {
1213 Assert.fail(e.getMessage());
1216 System.setProperty(ARTIFACTGENERATOR_CONFIG,configLoc);
1221 public void testErrorWhenNoWidgetInConfig() throws Exception {
1222 System.setProperty(ARTIFACTGENERATOR_CONFIG,CONFIG_PATH+"Artifact-Generator1.properties");
1223 loadConfig(ArtifactGenerationServiceTest.properties);
1225 List<Artifact> inputArtifacts = new ArrayList();
1226 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_NoSystemPropConfigured.yml");
1227 readPayload(inputArtifacts,fis1, "vf_vmme_template_NoSystemPropConfigured" +
1231 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_NoSystemPropConfigured.yml");
1232 readPayload(inputArtifacts,fis2, "service_vmme_template_NoSystemPropConfigured.yml");
1235 Map<String, Model> outputArtifactMap = new HashMap<>();
1236 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1237 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1239 String assertMsg = ArtifactType.AAI.name() + ".model-version-id." + Widget.getWidget
1240 (Widget.Type.SERVICE).getName();
1242 Assert.assertEquals(false,data.getErrorData().isEmpty());
1243 String errMsg = String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,assertMsg);
1244 Assert.assertEquals(data.getErrorData().get("AAI").get(0),errMsg);
1245 } catch (Exception e) {
1246 Assert.fail(e.getMessage());
1248 System.setProperty(ARTIFACTGENERATOR_CONFIG, CONFIG_PATH+"Artifact-Generator.properties");
1249 loadConfig(ArtifactGenerationServiceTest.properties);
1254 public void testArtifactGenerationWithUpdatedUUIDInConfig() throws Exception {
1256 List<Artifact> inputArtifacts = new ArrayList();
1257 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithUpdatedUUIDInConfig.yml");
1258 readPayload(inputArtifacts,fis1, "vf_vmme_template_WithUpdatedUUIDInConfig" +
1262 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithUpdatedUUIDInConfig.yml");
1263 readPayload(inputArtifacts,fis2, "service_vmme_template_WithUpdatedUUIDInConfig.yml");
1266 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1267 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1268 List<ToscaTemplate> toscas = new LinkedList();
1269 for (Artifact inputArtifact : inputArtifacts) {
1270 toscas.add(getToscaModel(inputArtifact));
1272 List<Artifact> resultData = data.getResultData();
1273 Map<String, Model> outputArtifactMap = new HashMap<>();
1274 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1275 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1276 testResourceTosca(toscas.iterator(), outputArtifactMap);
1278 System.setProperty(ARTIFACTGENERATOR_CONFIG,CONFIG_PATH+"Artifact-Generator2.properties");
1279 loadConfig(ArtifactGenerationServiceTest.properties);
1281 List<ToscaTemplate> toscas2 = new LinkedList();
1282 for (Artifact inputArtifact : inputArtifacts) {
1283 toscas2.add(getToscaModel(inputArtifact));
1285 GenerationData data2 = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1286 Map<String, Model> outputArtifactMap2 = new HashMap<>();
1287 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap2,
1288 data2.getResultData());
1289 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap2, toscas2);
1290 testResourceTosca(toscas2.iterator(), outputArtifactMap2);
1292 } catch (Exception e) {
1293 Assert.fail(e.getMessage());
1295 System.setProperty(ARTIFACTGENERATOR_CONFIG,CONFIG_PATH+"Artifact-Generator.properties");
1296 loadConfig(ArtifactGenerationServiceTest.properties);
1301 public void testArtifactGenerationVerifyMandatoryParameterServiceVersion() {
1303 List<Artifact> inputArtifacts = new ArrayList();
1304 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyMandatoryParameterServiceVersion.yml");
1305 readPayload(inputArtifacts, fis1, "vf_vmme_template_VerifyMandatoryParameterServiceVersion.yml");
1308 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyMandatoryParameterServiceVersion.yml");
1309 readPayload(inputArtifacts, fis2, "service_vmme_template_VerifyMandatoryParameterServiceVersion.yml");
1310 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1312 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, new HashMap<String, String>());
1313 List<Artifact> resultData = data.getResultData();
1315 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1316 Assert.assertEquals(data.getErrorData().get("AAI").get(0),GENERATOR_AAI_ERROR_MISSING_SERVICE_VERSION);
1317 } catch (Exception e) {
1318 Assert.fail(e.getMessage());
1323 public void testArtifactGenerationVerifyServiceVersionFormat() {
1325 List<Artifact> inputArtifacts = new ArrayList();
1326 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyServiceVersionFormat.yml");
1327 readPayload(inputArtifacts, fis1, "vf_vmme_template_VerifyServiceVersionFormat.yml");
1330 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyServiceVersionFormat.yml");
1331 readPayload(inputArtifacts, fis2, "service_vmme_template_VerifyServiceVersionFormat.yml");
1332 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1334 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1");
1335 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1336 List<Artifact> resultData = data.getResultData();
1337 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1338 Assert.assertEquals(data.getErrorData().get("AAI").get(0),GENERATOR_AAI_INVALID_SERVICE_VERSION);
1340 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.1");
1341 GenerationData data2 = obj.generateArtifact(inputArtifacts, generatorConfig,
1343 List<Artifact> resultData2 = data.getResultData();
1344 Assert.assertEquals(data2.getErrorData().isEmpty(),false);
1345 Assert.assertEquals(data2.getErrorData().get("AAI").get(0),
1346 GENERATOR_AAI_INVALID_SERVICE_VERSION);
1348 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.0");
1349 GenerationData data3 = obj.generateArtifact(inputArtifacts, generatorConfig,
1351 List<Artifact> resultData3 = data.getResultData();
1352 Assert.assertEquals(data3.getErrorData().isEmpty(),false);
1353 Assert.assertEquals(data3.getErrorData().get("AAI").get(0),
1354 GENERATOR_AAI_INVALID_SERVICE_VERSION);
1355 } catch (Exception e) {
1356 Assert.fail(e.getMessage());
1358 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
1363 public void testArtifactGenerationVerifyServiceVersion() {
1365 List<Artifact> inputArtifacts = new ArrayList();
1366 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyServiceVersion.yml");
1367 readPayload(inputArtifacts, fis1, "vf_vmme_template_VerifyServiceVersion.yml");
1370 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyServiceVersion.yml");
1371 readPayload(inputArtifacts, fis2, "service_vmme_template_VerifyServiceVersion.yml");
1372 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1373 List<ToscaTemplate> toscas = new LinkedList();
1375 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"9.0");
1376 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1378 for (Artifact inputArtifact : inputArtifacts) {
1379 toscas.add(getToscaModel(inputArtifact));
1381 List<Artifact> resultData = data.getResultData();
1383 Map<String, Model> outputArtifactMap = new HashMap<>();
1384 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1385 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1387 testResourceTosca(toscas.iterator(), outputArtifactMap);
1389 Assert.assertEquals(5, data.getResultData().size());
1391 removeMockArtifact(data.getResultData().iterator());
1393 ArtifactGenerationServiceTest.validateName(data.getResultData());
1396 } catch (Exception e) {
1397 Assert.fail(e.getMessage());
1399 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
1405 public void testArtifactGenerationVerifyResourceVersionFormat() {
1407 List<Artifact> inputArtifacts = new ArrayList();
1408 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyResourceVersionFormat.yml");
1409 readPayload(inputArtifacts, fis1, "vf_vmme_template_VerifyResourceVersionFormat.yml");
1412 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyResourceVersionFormat1.yml");
1413 readPayload(inputArtifacts, fis2, "service_vmme_template_VerifyResourceVersionFormat1.yml");
1414 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1417 List<ToscaTemplate> toscas = new LinkedList();
1418 for (Artifact inputArtifact : inputArtifacts) {
1419 toscas.add(getToscaModel(inputArtifact));
1422 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1423 List<Artifact> resultData = data.getResultData();
1424 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1425 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
1426 String.format(GENERATOR_AAI_ERROR_INVALID_RESOURCE_VERSION_IN_SERVICE_TOSCA,
1427 toscas.get(0).getMetadata().get("UUID")));
1429 inputArtifacts.remove(1);
1431 InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyResourceVersionFormat2.yml");
1432 readPayload(inputArtifacts, fis3, "service_vmme_template_VerifyResourceVersionFormat2.yml");
1434 GenerationData data2 = obj.generateArtifact(inputArtifacts, generatorConfig,
1436 List<Artifact> resultData2 = data2.getResultData();
1437 Assert.assertEquals(data2.getErrorData().isEmpty(),false);
1438 Assert.assertEquals(data2.getErrorData().get("AAI").get(0),
1439 String.format(GENERATOR_AAI_ERROR_INVALID_RESOURCE_VERSION_IN_SERVICE_TOSCA,
1440 toscas.get(0).getMetadata().get("UUID")));
1442 } catch (Exception e) {
1443 Assert.fail(e.getMessage());
1448 public void testArtifactGenerationVerifyMandatoryParameterResourceVersion() {
1450 List<Artifact> inputArtifacts = new ArrayList();
1451 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyMandatoryParameterResourceVersion.yml");
1452 readPayload(inputArtifacts, fis1, "vf_vmme_template_VerifyMandatoryParameterResourceVersion.yml");
1455 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyMandatoryParameterResourceVersion.yml");
1456 readPayload(inputArtifacts, fis2, "service_vmme_template_VerifyMandatoryParameterResourceVersion.yml");
1457 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1458 List<ToscaTemplate> toscas = new LinkedList();
1459 for (Artifact inputArtifact : inputArtifacts) {
1460 toscas.add(getToscaModel(inputArtifact));
1463 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1464 List<Artifact> resultData = data.getResultData();
1465 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1466 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format(GENERATOR_AAI_ERROR_NULL_RESOURCE_VERSION_IN_SERVICE_TOSCA,toscas.get(0).getMetadata().get("UUID")));
1467 } catch (Exception e) {
1468 Assert.fail(e.getMessage());
1473 public void testArtifactGenerationWithoutAllottedResource() {
1475 List<Artifact> inputArtifacts = new ArrayList();
1477 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service-ServiceWithAllottedResourceIpmux-template.yml");
1478 readPayload(inputArtifacts, fis1, "service-ServiceWithAllottedResourceIpmux-template.yml");
1481 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource-template_IpMux.yml");
1482 readPayload(inputArtifacts, fis2, "resource-AllottedResource-template_IpMux.yml");
1485 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1486 List<ToscaTemplate> toscas = new LinkedList();
1488 for (Artifact inputArtifact : inputArtifacts) {
1489 toscas.add(getToscaModel(inputArtifact));
1491 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1493 List<Artifact> resultData = data.getResultData();
1494 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1495 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format
1496 (GENERATOR_AAI_PROVIDING_SERVICE_MISSING, toscas.get(1).getModelId()));
1498 } catch (Exception e) {
1499 Assert.fail(e.getMessage());
1504 public void testArtifactGenerationAllottedResourceIpmuxWithGroups() {
1506 List<Artifact> inputArtifacts = new ArrayList();
1508 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream
1509 ("/service-ServiceWithAllottedResourceIpmux-template_WithGroups.yml");
1510 readPayload(inputArtifacts, fis1, "service-ServiceWithAllottedResourceIpmux-template_WithGroups.yml");
1513 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource-template_IpMux_WithGroups.yml");
1514 readPayload(inputArtifacts, fis2, "resource-AllottedResource-template_IpMux_WithGroups.yml");
1517 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1518 List<ToscaTemplate> toscas = new LinkedList();
1520 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1522 for (Artifact inputArtifact : inputArtifacts) {
1523 toscas.add(getToscaModel(inputArtifact));
1525 List<Artifact> resultData = data.getResultData();
1527 Map<String, Model> outputArtifactMap = new HashMap<>();
1528 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1529 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1530 testResourceTosca(toscas.iterator(), outputArtifactMap);
1532 Assert.assertEquals(5, data.getResultData().size());
1534 removeMockArtifact(data.getResultData().iterator());
1536 ArtifactGenerationServiceTest.validateName(data.getResultData());
1538 } catch (Exception e) {
1539 Assert.fail(e.getMessage());
1544 public void testArtifactGenerationAllottedResourceIpmuxSameInvariantDiffVersion() {
1546 List<Artifact> inputArtifacts = new ArrayList();
1548 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service-ServiceWithAllottedResourcesIpMuxSameInvariant-template.yml");
1549 readPayload(inputArtifacts, fis1, "service-ServiceWithAllottedResourcesIpMuxSameInvariant-template.yml");
1552 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource1SameInvariant-IpMux-template.yml");
1553 readPayload(inputArtifacts, fis2, "resource-AllottedResource1SameInvariant-IpMux-template.yml");
1556 InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource2SameInvariant-IpMux-template.yml");
1557 readPayload(inputArtifacts, fis3, "resource-AllottedResource2SameInvariant-IpMux-template.yml");
1560 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1561 List<ToscaTemplate> toscas = new LinkedList();
1563 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1565 for (Artifact inputArtifact : inputArtifacts) {
1566 toscas.add(getToscaModel(inputArtifact));
1568 List<Artifact> resultData = data.getResultData();
1570 Map<String, Model> outputArtifactMap = new HashMap<>();
1571 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1572 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1573 testResourceTosca(toscas.iterator(), outputArtifactMap);
1575 Assert.assertEquals(5, data.getResultData().size());
1577 removeMockArtifact(data.getResultData().iterator());
1579 ArtifactGenerationServiceTest.validateName(data.getResultData());
1582 } catch (Exception e) {
1583 Assert.fail(e.getMessage());
1588 public void testArtifactGenerationAllottedResourceIpmuxSameInvariantSameVersion() {
1590 List<Artifact> inputArtifacts = new ArrayList();
1592 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service-ServiceWithAllottedResourcesIpMuxSameInvariantSameVers-template.yml");
1593 readPayload(inputArtifacts, fis1, "service-ServiceWithAllottedResourcesIpMuxSameInvariantSameVers-template.yml");
1596 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResourceSameInvariantSameVers-IpMux-template.yml");
1597 readPayload(inputArtifacts, fis2, "resource-AllottedResourceSameInvariantSameVers-IpMux-template.yml");
1600 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1601 List<ToscaTemplate> toscas = new LinkedList();
1603 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1605 for (Artifact inputArtifact : inputArtifacts) {
1606 toscas.add(getToscaModel(inputArtifact));
1608 List<Artifact> resultData = data.getResultData();
1610 Map<String, Model> outputArtifactMap = new HashMap<>();
1611 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1612 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1613 testResourceTosca(toscas.iterator(), outputArtifactMap);
1615 Assert.assertEquals(4, data.getResultData().size());
1617 removeMockArtifact(data.getResultData().iterator());
1619 ArtifactGenerationServiceTest.validateName(data.getResultData());
1622 } catch (Exception e) {
1623 Assert.fail(e.getMessage());
1628 public void testArtifactGenerationAllottedResourceWithIpMuxAndTunnelXConn() {
1630 List<Artifact> inputArtifacts = new ArrayList();
1632 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service-Allottedipmux-template.yml");
1633 readPayload(inputArtifacts, fis2, "service-Allottedipmux-template.yml");
1635 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/resource-IpMuxDemux-template.yml");
1636 readPayload(inputArtifacts, fis1, "resource-IpMuxDemux-template.yml");
1638 InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-TunnelXconn-template.yml");
1639 readPayload(inputArtifacts, fis3, "resource-TunnelXconn-template.yml");
1641 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1642 List<ToscaTemplate> toscas = new LinkedList();
1644 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1646 for (Artifact inputArtifact : inputArtifacts) {
1647 toscas.add(getToscaModel(inputArtifact));
1649 List<Artifact> resultData = data.getResultData();
1651 Map<String, Model> outputArtifactMap = new HashMap<>();
1652 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1653 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1654 testResourceTosca(toscas.iterator(), outputArtifactMap);
1656 Assert.assertEquals(5, data.getResultData().size());
1658 removeMockArtifact(data.getResultData().iterator());
1660 ArtifactGenerationServiceTest.validateName(data.getResultData());
1662 } catch (Exception e) {
1663 Assert.fail(e.getMessage());
1668 public void testArtifactGenerationAllottedResourceWithOutProvidingServiceId() {
1670 List<Artifact> inputArtifacts = new ArrayList();
1672 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service-SdWan-template_WithOutDepSerId.yml");
1673 readPayload(inputArtifacts, fis2, "service-SdWan-template_WithOutDepSerId.yml");
1675 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/resource-VhnfNonHeat-template_WithOutDepSerId.yml");
1676 readPayload(inputArtifacts, fis1, "resource-VhnfNonHeat-template_WithOutDepSerId.yml");
1678 InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-TunnelXconn-template_WithOutDepSerId.yml");
1679 readPayload(inputArtifacts, fis3, "resource-TunnelXconn-template_WithOutDepSerId.yml");
1681 InputStream fis4 = SampleJUnitTest.class.getResourceAsStream
1682 ("/resource-ServiceAdmin-template_WithOutDepSerId.yml");
1683 readPayload(inputArtifacts, fis4, "resource-ServiceAdmin-template_WithOutDepSerId.yml");
1685 InputStream fis5 = SampleJUnitTest.class.getResourceAsStream
1686 ("/resource-IpMuxDemux-template_WithOutDepSerId.yml");
1687 readPayload(inputArtifacts, fis5, "resource-IpMuxDemux-template_WithOutDepSerId.yml");
1689 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1690 List<ToscaTemplate> toscas = new LinkedList();
1691 for (Artifact inputArtifact : inputArtifacts) {
1692 toscas.add(getToscaModel(inputArtifact));
1695 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1696 List<Artifact> resultData = data.getResultData();
1697 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1698 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format
1699 (GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING, toscas.get(2).getModelId()));
1700 } catch (Exception e) {
1701 Assert.fail(e.getMessage());
1706 public void testArtifactGenerationAllottedResourceWithVF() {
1708 List<Artifact> inputArtifacts = new ArrayList();
1710 InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service-SdWan-template_AllRes_VF.yml");
1711 readPayload(inputArtifacts, fis2, "service-SdWan-template_AllRes_VF.yml");
1713 InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/resource-VhnfNonHeat-template_AllRes_VF.yml");
1714 readPayload(inputArtifacts, fis1, "resource-VhnfNonHeat-template_AllRes_VF.yml");
1716 InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-TunnelXconn-template_AllRes_VF.yml");
1717 readPayload(inputArtifacts, fis3, "resource-TunnelXconn-template_AllRes_VF.yml");
1719 InputStream fis4 = SampleJUnitTest.class.getResourceAsStream
1720 ("/resource-ServiceAdmin-template_AllRes_VF.yml");
1721 readPayload(inputArtifacts, fis4, "resource-ServiceAdmin-template_AllRes_VF.yml");
1723 InputStream fis5 = SampleJUnitTest.class.getResourceAsStream
1724 ("/resource-IpMuxDemux-template_AllRes_VF.yml");
1725 readPayload(inputArtifacts, fis5, "resource-IpMuxDemux-template_AllRes_VF.yml");
1727 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1728 List<ToscaTemplate> toscas = new LinkedList();
1730 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
1731 for (Artifact inputArtifact : inputArtifacts) {
1732 toscas.add(getToscaModel(inputArtifact));
1734 List<Artifact> resultData = data.getResultData();
1736 Map<String, Model> outputArtifactMap = new HashMap<>();
1737 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1738 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1739 testResourceTosca(toscas.iterator(), outputArtifactMap);
1741 Assert.assertEquals(7, data.getResultData().size());
1743 removeMockArtifact(data.getResultData().iterator());
1745 ArtifactGenerationServiceTest.validateName(data.getResultData());
1746 } catch (Exception e) {
1747 Assert.fail(e.getMessage());
1751 public static void readPayload(List<Artifact> inputArtifacts,InputStream fis, String fileName) throws IOException {
1752 byte[] payload = new byte[fis.available()];
1754 String checksum = GeneratorUtil.checkSum(payload);
1755 byte[] encodedPayload = GeneratorUtil.encode(payload);
1756 Artifact artifact = new Artifact(aaiArtifactType, aaiArtifactGroupType, checksum, encodedPayload);
1757 artifact.setName(fileName);
1758 artifact.setLabel(fileName);
1759 artifact.setDescription(fileName);
1760 //artifact.setVersion("1.0");
1761 System.out.println(artifact.getName());
1762 inputArtifacts.add(artifact);
1767 * Get the tosca java model from the tosca input artifact
1769 * @param input Input tosca file and its metadata information as {@link Artifact} object
1770 * @return Translated {@link ToscaTemplate tosca} object
1771 * @throws SecurityException
1773 public static ToscaTemplate getToscaModel(Artifact input) throws SecurityException {
1774 byte[] decodedInput = GeneratorUtil.decoder(input.getPayload());
1775 String checksum = GeneratorUtil.checkSum(decodedInput);
1776 if (checksum.equals(input.getChecksum())) {
1778 return GeneratorUtil.translateTosca(new String(decodedInput), ToscaTemplate.class);
1779 } catch (Exception e) {
1780 e.printStackTrace();
1781 throw new IllegalArgumentException(String.format(GENERATOR_AAI_ERROR_INVALID_TOSCA, input.getName()));
1784 throw new SecurityException(String.format(GENERATOR_AAI_ERROR_CHECKSUM_MISMATCH, input.getName()));
1788 public static void removeMockArtifact(Iterator<Artifact> itr) {
1789 while (itr.hasNext()){
1790 if(itr.next().getType().equals("OTHER")){
1796 /*public static void testResourceTosca(Iterator<ToscaTemplate> itr, Map<String, Model> outputArtifactMap) {
1797 while(itr.hasNext()){
1798 ToscaTemplate toscaTemplate = itr.next();
1799 if("VF".equals(toscaTemplate.getMetadata().get("type"))){
1800 ArtifactGenerationServiceTest.testResourceTosca(outputArtifactMap, toscaTemplate);