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.onap.sdc.generator;
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;
35 import junit.framework.TestCase;
36 import org.junit.Assert;
37 import org.junit.Test;
42 import static org.onap.sdc.generator.ArtifactGenerationServiceTest.*;
44 public class SampleJUnitTest extends TestCase {
46 private static final String AAI_ARTIFACT_TYPE = ArtifactType.AAI.name();
47 private static final String AAI_ARTIFACT_GROUP_TYPE = GroupType.DEPLOYMENT.name();
48 private static final String GENERATOR_CONFIG = "{\"artifactTypes\": [\"OTHER\",\"AAI\"]}";
49 private static final String ARTIFACT_GENERATOR_CONFIG = "artifactgenerator.config";
50 private static final String CONFIG_PATH = "/qa-test-repo/jmeter3/apache-jmeter-3" +
52 private static final String GENERATOR_AAI_CONFIGLPROP_NOT_FOUND =
53 "Cannot generate artifacts. Widget configuration not found for %s";
54 private static final String GENERATOR_AAI_CONFIGFILE_NOT_FOUND =
55 "Cannot generate artifacts. Artifact Generator Configuration file not found at %s";
56 private static final String GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND =
57 "Cannot generate artifacts. artifactgenerator.config system property not configured";
58 private static final String INVALID_VALUE_INVARIANT =
59 "Invalid value for mandatory attribute <invariantUUID> in Artifact";
60 private static final String INVALID_VALUE_UUID =
61 "Invalid value for mandatory attribute <UUID> in Artifact:";
62 static final Map<String, String> additionalParams = new HashMap<>();
63 public static final String ARTIFACT_GENERATOR_PROPERTIES = "Artifact-Generator.properties";
64 public static final String VF_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML = "vf_vmme_template_NoSystemPropConfigured.yml";
65 public static final String SERVICE_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML = "service_vmme_template_NoSystemPropConfigured.yml";
68 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
71 public SampleJUnitTest(String name) throws IOException {
73 System.setProperty(ARTIFACT_GENERATOR_CONFIG,CONFIG_PATH + ARTIFACT_GENERATOR_PROPERTIES);
74 loadConfig(ArtifactGenerationServiceTest.properties);
77 private void loadConfig(Properties properties) throws IOException {
78 String configLocation = System.getProperty(ARTIFACT_GENERATOR_CONFIG);
79 if (configLocation != null) {
80 File file = new File(configLocation);
83 try (InputStream fis = new FileInputStream(file)) {
90 public SampleJUnitTest() {
92 System.setProperty(ARTIFACT_GENERATOR_CONFIG,CONFIG_PATH + ARTIFACT_GENERATOR_PROPERTIES);
96 public void testArtifactGenerationSingleVFSingleVFModule() {
98 List<Artifact> inputArtifacts = new ArrayList();
99 readPayloadFromResource(inputArtifacts, "vf_vmme_template_SingleVFVFMod.yml");
101 readPayloadFromResource(inputArtifacts, "service_vmme_template_SingleVFVFMod.yml");
102 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
103 List<ToscaTemplate> toscas = new LinkedList();
105 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
107 for (Artifact inputArtifact : inputArtifacts) {
108 toscas.add(getToscaModel(inputArtifact));
110 List<Artifact> resultData = data.getResultData();
112 Map<String, Model> outputArtifactMap = new HashMap<>();
113 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
114 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
116 testResourceTosca(toscas.iterator(), outputArtifactMap);
118 Assert.assertEquals(5, data.getResultData().size());
120 removeMockArtifact(data.getResultData().iterator());
122 ArtifactGenerationServiceTest.validateName(data.getResultData());
125 } catch (Exception e) {
126 Assert.fail(e.getMessage());
131 public void testArtifactGenerationMissingVFInServiceTOSCA() {
133 List<Artifact> inputArtifacts = new ArrayList();
134 readPayloadFromResource(inputArtifacts, "service_vmme_template_MissingVFInServiceTOSCA.yml");
135 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
136 List<ToscaTemplate> toscas = new LinkedList();
138 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
140 for (Artifact inputArtifact : inputArtifacts) {
141 toscas.add(getToscaModel(inputArtifact));
143 List<Artifact> resultData = data.getResultData();
145 Map<String, Model> outputArtifactMap = new HashMap<>();
146 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
147 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
149 Assert.assertEquals(3, data.getResultData().size());
151 removeMockArtifact(data.getResultData().iterator());
153 ArtifactGenerationServiceTest.validateName(data.getResultData());
156 } catch (Exception e) {
157 Assert.fail(e.getMessage());
162 public void testArtifactGenerationVerifySameStaticWidgetsForAllServices() {
164 List<Artifact> inputArtifacts = new ArrayList();
165 readPayloadFromResource(inputArtifacts, "vf_vmme_template_SameWidgets1.yml");
167 readPayloadFromResource(inputArtifacts, "service_vmme_template_SameWidget1.yml");
168 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
169 List<ToscaTemplate> toscas = new LinkedList();
171 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
173 for (Artifact inputArtifact : inputArtifacts) {
174 toscas.add(getToscaModel(inputArtifact));
176 List<Artifact> resultData = data.getResultData();
178 Map<String, Model> outputArtifactMap = new HashMap<>();
179 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
181 removeMockArtifact(data.getResultData().iterator());
184 List<Artifact> inputArtifacts2 = new ArrayList();
185 readPayloadFromResource(inputArtifacts2, "vf_vmme_template_SameWidgets2.yml");
187 readPayloadFromResource(inputArtifacts2, "service_vmme_template_SameWidget2.yml");
188 ArtifactGenerationServiceImpl obj2 = new ArtifactGenerationServiceImpl();
190 GenerationData data2 = obj2.generateArtifact(inputArtifacts2, GENERATOR_CONFIG,additionalParams);
191 List<Artifact> resultData2 = data2.getResultData();
193 List<ToscaTemplate> toscas2 = new LinkedList();
195 for (Artifact inputArtifact : inputArtifacts2) {
196 toscas2.add(getToscaModel(inputArtifact));
199 Map<String, Model> outputArtifactMap2 = new HashMap<>();
200 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap2, resultData2);
201 removeMockArtifact(data2.getResultData().iterator());
203 Map<String,String> map = new HashMap<>();
204 Iterator<Artifact> itr = data.getResultData().iterator();
205 while(itr.hasNext()){
206 Artifact artifact=itr.next();
207 if(artifact.getLabel().contains("AAI-widget")){
208 map.put(artifact.getName(),artifact.getChecksum());
211 Map<String,String> map2 = new HashMap<>();
212 Iterator<Artifact> itr2 = data2.getResultData().iterator();
213 while(itr2.hasNext()){
214 Artifact artifact=itr2.next();
215 if(artifact.getLabel().contains("AAI-widget")){
216 map2.put(artifact.getName(),artifact.getChecksum());
219 Assert.assertEquals(map.size(),map2.size());
220 for(Map.Entry<String, String> entry : map.entrySet()){
221 Assert.assertEquals(entry.getValue(), map2.get(entry.getKey()));
224 } catch (Exception e) {
225 Assert.fail(e.getMessage());
230 public void testArtifactGenerationMulVFModule() {
232 List<Artifact> inputArtifacts = new ArrayList();
233 readPayloadFromResource(inputArtifacts, "vf_vmme_template_MulVFVFMod.yml");
235 readPayloadFromResource(inputArtifacts, "service_vmme_template_MulVFVFMod.yml");
237 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
238 List<ToscaTemplate> toscas = new LinkedList();
240 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
242 for (Artifact inputArtifact : inputArtifacts) {
243 toscas.add(getToscaModel(inputArtifact));
245 List<Artifact> resultData = data.getResultData();
247 Map<String, Model> outputArtifactMap = new HashMap<>();
248 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
249 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
250 testResourceTosca(toscas.iterator(), outputArtifactMap);
252 Assert.assertEquals(3,data.getResultData().size());
254 removeMockArtifact(data.getResultData().iterator());
256 ArtifactGenerationServiceTest.validateName(data.getResultData());
258 } catch (Exception e) {
259 Assert.fail(e.getMessage());
264 public void testArtifactGenerationMulVFs() {
266 List<Artifact> inputArtifacts = new ArrayList();
268 readPayloadFromResource(inputArtifacts, "CMAUI_VF.yaml");
270 readPayloadFromResource(inputArtifacts, "ECA_OAM_VF.yaml");
272 readPayloadFromResource(inputArtifacts, "MMSC_Sevice_07_25_16.yaml");
274 readPayloadFromResource(inputArtifacts, "MMSC_VF.yaml");
276 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
277 List<ToscaTemplate> toscas = new LinkedList();
279 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
281 for (Artifact inputArtifact : inputArtifacts) {
282 toscas.add(getToscaModel(inputArtifact));
284 List<Artifact> resultData = data.getResultData();
286 Map<String, Model> outputArtifactMap = new HashMap<>();
287 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
288 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
289 testResourceTosca(toscas.iterator(), outputArtifactMap);
291 Assert.assertEquals(8,data.getResultData().size());
293 removeMockArtifact(data.getResultData().iterator());
295 ArtifactGenerationServiceTest.validateName(data.getResultData());
297 } catch (Exception e) {
298 Assert.fail(e.getMessage());
303 public void testArtifactGenerationDupVFUUID() {
305 List<Artifact> inputArtifacts = new ArrayList();
306 readPayloadFromResource(inputArtifacts, "vf_vmme_template_DupVFUUID.yml");
308 readPayloadFromResource(inputArtifacts, "service_vmme_template_DupVFUUID.yml");
309 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
310 List<ToscaTemplate> toscas = new LinkedList();
312 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
314 for (Artifact inputArtifact : inputArtifacts) {
315 toscas.add(getToscaModel(inputArtifact));
317 List<Artifact> resultData = data.getResultData();
319 Map<String, Model> outputArtifactMap = new HashMap<>();
320 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
321 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
322 testResourceTosca(toscas.iterator(), outputArtifactMap);
324 Assert.assertEquals(5,data.getResultData().size());
326 removeMockArtifact(data.getResultData().iterator());
328 ArtifactGenerationServiceTest.validateName(data.getResultData());
330 } catch (Exception e) {
331 Assert.fail(e.getMessage());
336 public void testArtifactGenerationDupVFModUUID() {
338 List<Artifact> inputArtifacts = new ArrayList();
339 readPayloadFromResource(inputArtifacts, "vf_vmme_template_DupVFModUUID.yml");
341 readPayloadFromResource(inputArtifacts, "service_vmme_template_DupVFModUUID.yml");
342 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
343 List<ToscaTemplate> toscas = new LinkedList();
345 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
347 for (Artifact inputArtifact : inputArtifacts) {
348 toscas.add(getToscaModel(inputArtifact));
350 List<Artifact> resultData = data.getResultData();
352 Map<String, Model> outputArtifactMap = new HashMap<>();
353 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
354 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
355 testResourceTosca(toscas.iterator(), outputArtifactMap);
357 Assert.assertEquals(5,data.getResultData().size());
359 removeMockArtifact(data.getResultData().iterator());
361 ArtifactGenerationServiceTest.validateName(data.getResultData());
362 } catch (Exception e) {
363 Assert.fail(e.getMessage());
368 public void testArtifactGenerationVerifyVFModWithoutVNFC() {
370 List<Artifact> inputArtifacts = new ArrayList();
371 readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyVFModWithoutVNFC.yml");
373 readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyVFModWithoutVNFC.yml");
374 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
375 List<ToscaTemplate> toscas = new LinkedList();
377 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
379 for (Artifact inputArtifact : inputArtifacts) {
380 toscas.add(getToscaModel(inputArtifact));
382 List<Artifact> resultData = data.getResultData();
384 Map<String, Model> outputArtifactMap = new HashMap<>();
385 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
386 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
387 testResourceTosca(toscas.iterator(), outputArtifactMap);
389 Assert.assertEquals(5,data.getResultData().size());
391 removeMockArtifact(data.getResultData().iterator());
393 ArtifactGenerationServiceTest.validateName(data.getResultData());
394 } catch (Exception e) {
395 Assert.fail(e.getMessage());
400 public void testArtifactGenerationVerifyVFModWithInvalidMember() {
402 List<Artifact> inputArtifacts = new ArrayList();
403 readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyVFModWithInvalidNo.yml");
405 readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyVFModWithInvalidNo.yml");
406 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
407 List<ToscaTemplate> toscas = new LinkedList();
409 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
411 for (Artifact inputArtifact : inputArtifacts) {
412 toscas.add(getToscaModel(inputArtifact));
414 List<Artifact> resultData = data.getResultData();
416 Map<String, Model> outputArtifactMap = new HashMap<>();
417 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
418 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
419 testResourceTosca(toscas.iterator(), outputArtifactMap);
421 Assert.assertEquals(5,data.getResultData().size());
423 removeMockArtifact(data.getResultData().iterator());
425 ArtifactGenerationServiceTest.validateName(data.getResultData());
426 } catch (Exception e) {
427 Assert.fail(e.getMessage());
432 public void testArtifactGenerationNullFields() {
434 List<Artifact> inputArtifacts = new ArrayList();
435 readPayloadFromResource(inputArtifacts, "vf_vmme_template_NullFields.yml");
437 readPayloadFromResource(inputArtifacts, "service_vmme_template_NullFields.yml");
438 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
440 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
441 Assert.assertEquals(false,data.getErrorData().isEmpty());
443 Assert.assertEquals("Invalid Service/Resource definition mandatory attribute <UUID> missing in Artifact: <"+inputArtifacts.get(0).getName()+">",data.getErrorData().get("AAI").get(0));
445 Assert.assertEquals(2,data.getResultData().size());
447 } catch (Exception e) {
448 Assert.fail(e.getMessage());
453 public void testArtifactGenerationInCorrectYmlFormat() {
455 List<Artifact> inputArtifacts = new ArrayList();
457 readPayloadFromResource(inputArtifacts, "CMAUI_VFInvalidFormat.yaml");
459 readPayloadFromResource(inputArtifacts, "ECA_OAM_VFInvalidFormat.yaml");
461 readPayloadFromResource(inputArtifacts, "MMSC_Sevice_07_25_16InvalidFormat.yaml");
463 readPayloadFromResource(inputArtifacts, "MMSC_VFInvalidFormat.yaml");
465 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
467 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
468 Assert.assertEquals(false,data.getErrorData().isEmpty());
470 Assert.assertEquals("Invalid format for Tosca YML : "+inputArtifacts.get(1).getName(),data.getErrorData().get("AAI").get(0));
472 Assert.assertEquals(2,data.getResultData().size());
474 } catch (Exception e) {
475 Assert.fail(e.getMessage());
480 public void testArtifactGenerationMulComp() {
482 List<Artifact> inputArtifacts = new ArrayList();
483 readPayloadFromResource(inputArtifacts, "vf_vmme_template_MulComp.yml");
485 readPayloadFromResource(inputArtifacts, "service_vmme_template_MulComp.yml");
486 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
487 List<ToscaTemplate> toscas = new LinkedList();
489 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
491 for (Artifact inputArtifact : inputArtifacts) {
492 toscas.add(getToscaModel(inputArtifact));
494 List<Artifact> resultData = data.getResultData();
496 Map<String, Model> outputArtifactMap = new HashMap<>();
497 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
498 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
499 testResourceTosca(toscas.iterator(), outputArtifactMap);
501 Assert.assertEquals(5,data.getResultData().size());
503 removeMockArtifact(data.getResultData().iterator());
505 ArtifactGenerationServiceTest.validateName(data.getResultData());
506 } catch (Exception e) {
507 Assert.fail(e.getMessage());
512 public void testArtifactGenerationOrphan() {
514 List<Artifact> inputArtifacts = new ArrayList();
516 readPayloadFromResource(inputArtifacts, "vf_vmme_template_Orphan.yml");
518 readPayloadFromResource(inputArtifacts, "service_vmme_template_Orphan.yml");
520 readPayloadFromResource(inputArtifacts, "ECA_OAM_VFOrphan.yaml");
522 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
523 List<ToscaTemplate> toscas = new LinkedList();
525 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
527 for (Artifact inputArtifact : inputArtifacts) {
528 toscas.add(getToscaModel(inputArtifact));
530 List<Artifact> resultData = data.getResultData();
532 Map<String, Model> outputArtifactMap = new HashMap<>();
533 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
534 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
535 testResourceTosca(toscas.iterator(), outputArtifactMap);
537 Assert.assertEquals(5,data.getResultData().size());
539 removeMockArtifact(data.getResultData().iterator());
541 ArtifactGenerationServiceTest.validateName(data.getResultData());
542 } catch (Exception e) {
543 Assert.fail(e.getMessage());
548 public void testArtifactGenerationMissingVFTemplate() {
550 List<Artifact> inputArtifacts = new ArrayList();
552 readPayloadFromResource(inputArtifacts, "service_vmme_template_MissingVFTemplate.yml");
554 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
555 List<ToscaTemplate> toscas = new LinkedList();
557 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
559 for (Artifact inputArtifact : inputArtifacts) {
560 toscas.add(getToscaModel(inputArtifact));
562 List<Artifact> resultData = data.getResultData();
564 Map<String, Model> outputArtifactMap = new HashMap<>();
565 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
566 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
569 Assert.assertEquals(3,data.getResultData().size());
571 removeMockArtifact(data.getResultData().iterator());
573 ArtifactGenerationServiceTest.validateName(data.getResultData());
574 } catch (Exception e) {
575 Assert.fail(e.getMessage());
580 public void testArtifactGenerationMissingVFModule() {
582 List<Artifact> inputArtifacts = new ArrayList();
584 readPayloadFromResource(inputArtifacts, "CMAUI_VFMissingVFModule.yaml");
586 readPayloadFromResource(inputArtifacts, "ECA_OAM_VFMissingVFModule.yaml");
588 readPayloadFromResource(inputArtifacts, "MMSC_Sevice_07_25_16MissingVFModule.yaml");
590 readPayloadFromResource(inputArtifacts, "MMSC_VFMissingVFModule.yaml");
592 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
593 List<ToscaTemplate> toscas = new LinkedList();
595 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
597 for (Artifact inputArtifact : inputArtifacts) {
598 toscas.add(getToscaModel(inputArtifact));
600 List<Artifact> resultData = data.getResultData();
602 Map<String, Model> outputArtifactMap = new HashMap<>();
603 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
604 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
605 testResourceTosca(toscas.iterator(), outputArtifactMap);
607 Assert.assertEquals(8,data.getResultData().size());
609 removeMockArtifact(data.getResultData().iterator());
611 ArtifactGenerationServiceTest.validateName(data.getResultData());
613 } catch (Exception e) {
614 Assert.fail(e.getMessage());
619 public void testArtifactGenerationEmptyArtifact() {
621 List<Artifact> inputArtifacts = new ArrayList();
623 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
625 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
626 Assert.assertEquals(false,data.getErrorData().isEmpty());
627 Assert.assertEquals("Service tosca missing from list of input artifacts",data.getErrorData().get("AAI").get(0));
629 Assert.assertEquals(2,data.getResultData().size());
631 } catch (Exception e) {
632 Assert.fail(e.getMessage());
637 public void testArtifactGenerationMissingConfigFile() {
639 List<Artifact> inputArtifacts = new ArrayList();
641 readPayloadFromResource(inputArtifacts, "vf_vmme_template_SingleVFVFMod.yml");
643 readPayloadFromResource(inputArtifacts, "service_vmme_template_SingleVFVFMod.yml");
644 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
646 GenerationData data = obj.generateArtifact(inputArtifacts, "",additionalParams);
647 Assert.assertEquals(false,data.getErrorData().isEmpty());
648 Assert.assertEquals("Invalid Client Configuration",data.getErrorData().get("ARTIFACT_GENERATOR_INVOCATION_ERROR").get(0));
650 Assert.assertEquals(0,data.getResultData().size());
652 } catch (Exception e) {
653 Assert.fail(e.getMessage());
659 public void testArtifactGenerationWithNodeTemplates() {
661 List<Artifact> inputArtifacts = new ArrayList();
663 readPayloadFromResource(inputArtifacts, "ServiceWithNodetemplate.yml");
665 readPayloadFromResource(inputArtifacts, "Resource0-template.yml");
667 readPayloadFromResource(inputArtifacts, "Resource1-template.yml");
669 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
670 List<ToscaTemplate> toscas = new LinkedList();
672 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
674 for (Artifact inputArtifact : inputArtifacts) {
675 toscas.add(getToscaModel(inputArtifact));
677 List<Artifact> resultData = data.getResultData();
679 Map<String, Model> outputArtifactMap = new HashMap<>();
680 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
681 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
682 testResourceTosca(toscas.iterator(), outputArtifactMap);
684 Assert.assertEquals(5,data.getResultData().size());
686 removeMockArtifact(data.getResultData().iterator());
688 ArtifactGenerationServiceTest.validateName(data.getResultData());
691 } catch (Exception e) {
692 Assert.fail(e.getMessage());
697 public void testArtifactGenerationWithoutNodeTemplates() {
699 List<Artifact> inputArtifacts = new ArrayList();
701 readPayloadFromResource(inputArtifacts, "Service0-template.yml");
703 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
704 List<ToscaTemplate> toscas = new LinkedList();
706 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
708 for (Artifact inputArtifact : inputArtifacts) {
709 toscas.add(getToscaModel(inputArtifact));
711 List<Artifact> resultData = data.getResultData();
713 Map<String, Model> outputArtifactMap = new HashMap<>();
714 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
715 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
718 Assert.assertEquals(3,data.getResultData().size());
720 removeMockArtifact(data.getResultData().iterator());
722 ArtifactGenerationServiceTest.validateName(data.getResultData());
725 } catch (Exception e) {
726 Assert.fail(e.getMessage());
731 public void testArtifactGenerationWithArtifactNameAndDescMoreThan256() {
733 List<Artifact> inputArtifacts = new ArrayList();
735 readPayloadFromResource(inputArtifacts, "Service0-templateMoreThan256.yml");
737 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
738 List<ToscaTemplate> toscas = new LinkedList();
740 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
742 for (Artifact inputArtifact : inputArtifacts) {
743 toscas.add(getToscaModel(inputArtifact));
745 List<Artifact> resultData = data.getResultData();
747 Map<String, Model> outputArtifactMap = new HashMap<>();
748 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
749 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
752 Assert.assertEquals(3,data.getResultData().size());
754 removeMockArtifact(data.getResultData().iterator());
756 for(Artifact artifact : data.getResultData()){
757 checkArtifactName(artifact.getName());
758 checkArtifactLabel(artifact.getLabel());
759 checkArtifactDescription(artifact.getDescription());
763 } catch (Exception e) {
764 Assert.fail(e.getMessage());
769 public void testArtifactGenerationWithDifferentVersionOfSameVF() {
771 List<Artifact> inputArtifacts = new ArrayList();
773 readPayloadFromResource(inputArtifacts, "service_vmme_template_DiffVerOfSameVF.yml");
775 readPayloadFromResource(inputArtifacts, "vf_vmme_template_DiffVerOfSameVF_1.yml");
777 readPayloadFromResource(inputArtifacts, "vf_vmme_template_DiffVerOfSameVF_2.yml");
779 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
780 List<ToscaTemplate> toscas = new LinkedList();
782 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
784 for (Artifact inputArtifact : inputArtifacts) {
785 toscas.add(getToscaModel(inputArtifact));
787 List<Artifact> resultData = data.getResultData();
789 Map<String, Model> outputArtifactMap = new HashMap<>();
790 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
791 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
792 testResourceTosca(toscas.iterator(), outputArtifactMap);
794 Assert.assertEquals(6,data.getResultData().size());
796 removeMockArtifact(data.getResultData().iterator());
798 ArtifactGenerationServiceTest.validateName(data.getResultData());
801 } catch (Exception e) {
802 Assert.fail(e.getMessage());
807 public void testArtifactGenerationWithDifferentVersionOfSameVFModWithSameInvId() {
809 List<Artifact> inputArtifacts = new ArrayList();
811 readPayloadFromResource(inputArtifacts, "service_vmme_template_DiffVerOfSameVFModWithSameInvId.yml");
813 readPayloadFromResource(inputArtifacts, "vf_vmme_template_DiffVerOfSameVFModWithSameInvId.yml");
815 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
816 List<ToscaTemplate> toscas = new LinkedList();
818 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
820 for (Artifact inputArtifact : inputArtifacts) {
821 toscas.add(getToscaModel(inputArtifact));
823 List<Artifact> resultData = data.getResultData();
825 Map<String, Model> outputArtifactMap = new HashMap<>();
826 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
827 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
828 testResourceTosca(toscas.iterator(), outputArtifactMap);
830 Assert.assertEquals(6,data.getResultData().size());
832 removeMockArtifact(data.getResultData().iterator());
834 ArtifactGenerationServiceTest.validateName(data.getResultData());
837 } catch (Exception e) {
838 Assert.fail(e.getMessage());
843 public void testArtifactGenerationWithServiceContainingL3Network() {
845 List<Artifact> inputArtifacts = new ArrayList();
847 readPayloadFromResource(inputArtifacts, "service_vmme_template_WithL3Network.yml");
849 readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithL3Network.yml");
851 readPayloadFromResource(inputArtifacts, "resource-AllottedResource-template_WithL3Network.yml");
853 readPayloadFromResource(inputArtifacts, "resource-Extvl-template_WithL3Network.yml");
855 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
856 List<ToscaTemplate> toscas = new LinkedList();
858 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
860 for (Artifact inputArtifact : inputArtifacts) {
861 toscas.add(getToscaModel(inputArtifact));
863 List<Artifact> resultData = data.getResultData();
865 Map<String, Model> outputArtifactMap = new HashMap<>();
866 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
867 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
868 testResourceTosca(toscas.iterator(), outputArtifactMap);
870 Assert.assertEquals(7,data.getResultData().size());
872 removeMockArtifact(data.getResultData().iterator());
874 ArtifactGenerationServiceTest.validateName(data.getResultData());
877 } catch (Exception e) {
878 Assert.fail(e.getMessage());
883 public void testArtifactGenerationWithServiceContainingDupL3Network() {
885 List<Artifact> inputArtifacts = new ArrayList();
887 readPayloadFromResource(inputArtifacts, "service_vmme_template_WithDupL3Network.yml");
889 readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithDupL3Network.yml");
891 readPayloadFromResource(inputArtifacts, "resource-AllottedResource-template_WithDupL3Network.yml");
893 readPayloadFromResource(inputArtifacts, "resource-Extvl-template_WithDupL3Network.yml");
895 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
896 List<ToscaTemplate> toscas = new LinkedList();
898 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
900 for (Artifact inputArtifact : inputArtifacts) {
901 toscas.add(getToscaModel(inputArtifact));
903 List<Artifact> resultData = data.getResultData();
905 Map<String, Model> outputArtifactMap = new HashMap<>();
906 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
907 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
908 testResourceTosca(toscas.iterator(), outputArtifactMap);
910 Assert.assertEquals(7,data.getResultData().size());
912 removeMockArtifact(data.getResultData().iterator());
914 ArtifactGenerationServiceTest.validateName(data.getResultData());
917 } catch (Exception e) {
918 Assert.fail(e.getMessage());
923 public void testArtifactGenerationWithL3NetworkInVFMod() {
925 List<Artifact> inputArtifacts = new ArrayList();
927 readPayloadFromResource(inputArtifacts, "service_vmme_template_WithL3NetworkInVFMod.yml");
929 readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithL3NetworkInVFMod.yml");
931 readPayloadFromResource(inputArtifacts, "resource-AllottedResource-template_WithL3NetworkInVFMod.yml");
933 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
934 List<ToscaTemplate> toscas = new LinkedList();
936 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
938 for (Artifact inputArtifact : inputArtifacts) {
939 toscas.add(getToscaModel(inputArtifact));
941 List<Artifact> resultData = data.getResultData();
943 Map<String, Model> outputArtifactMap = new HashMap<>();
944 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
945 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
946 testResourceTosca(toscas.iterator(), outputArtifactMap);
948 Assert.assertEquals(6,data.getResultData().size());
950 removeMockArtifact(data.getResultData().iterator());
952 ArtifactGenerationServiceTest.validateName(data.getResultData());
955 } catch (Exception e) {
956 Assert.fail(e.getMessage());
961 public void testArtifactGenerationWithDiffVersionOfSameL3Network() {
963 List<Artifact> inputArtifacts = new ArrayList();
965 readPayloadFromResource(inputArtifacts, "service_vmme_template_WithDiffVersionOfSameL3Network.yml");
967 readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithDiffVersionOfSameL3Network.yml");
969 readPayloadFromResource(inputArtifacts, "resource-AllottedResource-template_WithDiffVersionOfSameL3Network.yml");
971 readPayloadFromResource(inputArtifacts, "resource-Extvl-template_WithDiffVersionOfSameL3Network.yml");
973 readPayloadFromResource(inputArtifacts, "resource-Extvl-template_1_WithDiffVersionOfSameL3Network.yml");
975 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
976 List<ToscaTemplate> toscas = new LinkedList();
978 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
980 for (Artifact inputArtifact : inputArtifacts) {
981 toscas.add(getToscaModel(inputArtifact));
983 List<Artifact> resultData = data.getResultData();
985 Map<String, Model> outputArtifactMap = new HashMap<>();
986 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
987 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
988 testResourceTosca(toscas.iterator(), outputArtifactMap);
990 Assert.assertEquals(8,data.getResultData().size());
992 removeMockArtifact(data.getResultData().iterator());
994 ArtifactGenerationServiceTest.validateName(data.getResultData());
997 } catch (Exception e) {
998 Assert.fail(e.getMessage());
1003 public void testArtifactGenerationWithInvIdGreaterThanSpecifiedLimit() {
1005 List<Artifact> inputArtifacts = new ArrayList();
1006 readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithInvIdGreaterThanSpecifiedLimit.yml");
1008 readPayloadFromResource(inputArtifacts, "service_vmme_template_WithInvIdGreaterThanSpecifiedLimit.yml");
1009 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1011 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1012 Assert.assertEquals(false,data.getErrorData().isEmpty());
1014 Assert.assertEquals(INVALID_VALUE_INVARIANT + ": <" +inputArtifacts.get(1).getName()+">",data.getErrorData().get("AAI").get(0));
1016 Assert.assertEquals(2,data.getResultData().size());
1018 } catch (Exception e) {
1019 Assert.fail(e.getMessage());
1024 public void testArtifactGenerationWithInvIdLesserThanSpecifiedLimit() {
1026 List<Artifact> inputArtifacts = new ArrayList();
1027 readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithInvIdLesserThanSpecifiedLimit.yml");
1029 readPayloadFromResource(inputArtifacts, "service_vmme_template_WithInvIdLesserThanSpecifiedLimit.yml");
1030 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1032 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1033 Assert.assertEquals(false,data.getErrorData().isEmpty());
1035 Assert.assertEquals(INVALID_VALUE_UUID + " <"
1036 +inputArtifacts.get(1).getName()+">",data.getErrorData().get("AAI").get(0));
1038 Assert.assertEquals(2,data.getResultData().size());
1040 } catch (Exception e) {
1041 Assert.fail(e.getMessage());
1047 public void testErrorWhenNoSystemPropConfigured() {
1048 String configLoc = System.getProperty(ARTIFACT_GENERATOR_CONFIG);
1050 List<Artifact> inputArtifacts = new ArrayList();
1051 readPayloadFromResource(inputArtifacts, VF_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML);
1053 readPayloadFromResource(inputArtifacts, SERVICE_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML);
1055 System.clearProperty(ARTIFACT_GENERATOR_CONFIG);
1057 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1058 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1059 Assert.assertEquals(false,data.getErrorData().isEmpty());
1060 Assert.assertEquals(data.getErrorData().
1061 get("AAI").get(0), GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND);
1062 } catch (Exception e) {
1063 Assert.fail(e.getMessage());
1066 System.setProperty(ARTIFACT_GENERATOR_CONFIG,configLoc);
1071 public void testErrorWhenNoFileAtConfigLocation() {
1072 String configLoc = System.getProperty(ARTIFACT_GENERATOR_CONFIG);
1074 List<Artifact> inputArtifacts = new ArrayList();
1075 readPayloadFromResource(inputArtifacts, VF_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML);
1077 readPayloadFromResource(inputArtifacts, SERVICE_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML);
1079 System.setProperty(ARTIFACT_GENERATOR_CONFIG,configLoc + File.separator + "testErrorWhenNoFileAtConfigLocation");
1080 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1081 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1082 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1083 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format(
1084 GENERATOR_AAI_CONFIGFILE_NOT_FOUND,System.getProperty
1085 (ARTIFACT_GENERATOR_CONFIG)));
1086 } catch (Exception e) {
1087 Assert.fail(e.getMessage());
1090 System.setProperty(ARTIFACT_GENERATOR_CONFIG,configLoc);
1095 public void testErrorWhenNoWidgetInConfig() throws IOException {
1096 System.setProperty(ARTIFACT_GENERATOR_CONFIG,CONFIG_PATH+"Artifact-Generator1.properties");
1097 loadConfig(ArtifactGenerationServiceTest.properties);
1099 List<Artifact> inputArtifacts = new ArrayList();
1100 readPayloadFromResource(inputArtifacts, VF_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML);
1102 readPayloadFromResource(inputArtifacts, SERVICE_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML);
1104 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1105 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1107 String assertMsg = ArtifactType.AAI.name() + ".model-version-id." + Widget.getWidget
1108 (Widget.Type.SERVICE).getName();
1110 Assert.assertEquals(false,data.getErrorData().isEmpty());
1111 String errMsg = String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,assertMsg);
1112 Assert.assertEquals(data.getErrorData().get("AAI").get(0),errMsg);
1113 } catch (Exception e) {
1114 Assert.fail(e.getMessage());
1116 System.setProperty(ARTIFACT_GENERATOR_CONFIG, CONFIG_PATH + ARTIFACT_GENERATOR_PROPERTIES);
1117 loadConfig(ArtifactGenerationServiceTest.properties);
1122 public void testArtifactGenerationWithUpdatedUUIDInConfig() throws IOException {
1124 List<Artifact> inputArtifacts = new ArrayList();
1125 readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithUpdatedUUIDInConfig.yml");
1127 readPayloadFromResource(inputArtifacts, "service_vmme_template_WithUpdatedUUIDInConfig.yml");
1129 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1130 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1131 List<ToscaTemplate> toscas = new LinkedList();
1132 for (Artifact inputArtifact : inputArtifacts) {
1133 toscas.add(getToscaModel(inputArtifact));
1135 List<Artifact> resultData = data.getResultData();
1136 Map<String, Model> outputArtifactMap = new HashMap<>();
1137 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1138 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1139 testResourceTosca(toscas.iterator(), outputArtifactMap);
1141 System.setProperty(ARTIFACT_GENERATOR_CONFIG,CONFIG_PATH+"Artifact-Generator2.properties");
1142 loadConfig(ArtifactGenerationServiceTest.properties);
1144 List<ToscaTemplate> toscas2 = new LinkedList();
1145 for (Artifact inputArtifact : inputArtifacts) {
1146 toscas2.add(getToscaModel(inputArtifact));
1148 GenerationData data2 = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1149 Map<String, Model> outputArtifactMap2 = new HashMap<>();
1150 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap2,
1151 data2.getResultData());
1152 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap2, toscas2);
1153 testResourceTosca(toscas2.iterator(), outputArtifactMap2);
1155 } catch (Exception e) {
1156 Assert.fail(e.getMessage());
1158 System.setProperty(ARTIFACT_GENERATOR_CONFIG,CONFIG_PATH + ARTIFACT_GENERATOR_PROPERTIES);
1159 loadConfig(ArtifactGenerationServiceTest.properties);
1164 public void testArtifactGenerationVerifyMandatoryParameterServiceVersion() {
1166 List<Artifact> inputArtifacts = new ArrayList();
1167 readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyMandatoryParameterServiceVersion.yml");
1169 readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyMandatoryParameterServiceVersion.yml");
1170 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1172 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, new HashMap<String, String>());
1174 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1175 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
1176 GeneratorConstants.GENERATOR_AAI_ERROR_MISSING_SERVICE_VERSION);
1177 } catch (Exception e) {
1178 Assert.fail(e.getMessage());
1183 public void testArtifactGenerationVerifyServiceVersionFormat() {
1185 List<Artifact> inputArtifacts = new ArrayList();
1186 readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyServiceVersionFormat.yml");
1188 readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyServiceVersionFormat.yml");
1189 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1191 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1");
1192 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1193 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1194 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
1195 GeneratorConstants.GENERATOR_AAI_INVALID_SERVICE_VERSION);
1197 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.1");
1198 GenerationData data2 = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG,
1200 Assert.assertEquals(data2.getErrorData().isEmpty(),false);
1201 Assert.assertEquals(data2.getErrorData().get("AAI").get(0),
1202 GeneratorConstants.GENERATOR_AAI_INVALID_SERVICE_VERSION);
1204 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.0");
1205 GenerationData data3 = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG,
1207 Assert.assertEquals(data3.getErrorData().isEmpty(),false);
1208 Assert.assertEquals(data3.getErrorData().get("AAI").get(0),
1209 GeneratorConstants.GENERATOR_AAI_INVALID_SERVICE_VERSION);
1210 } catch (Exception e) {
1211 Assert.fail(e.getMessage());
1213 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
1218 public void testArtifactGenerationVerifyServiceVersion() {
1220 List<Artifact> inputArtifacts = new ArrayList();
1221 readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyServiceVersion.yml");
1223 readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyServiceVersion.yml");
1224 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1225 List<ToscaTemplate> toscas = new LinkedList();
1227 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"9.0");
1228 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1230 for (Artifact inputArtifact : inputArtifacts) {
1231 toscas.add(getToscaModel(inputArtifact));
1233 List<Artifact> resultData = data.getResultData();
1235 Map<String, Model> outputArtifactMap = new HashMap<>();
1236 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1237 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1239 testResourceTosca(toscas.iterator(), outputArtifactMap);
1241 Assert.assertEquals(5, data.getResultData().size());
1243 removeMockArtifact(data.getResultData().iterator());
1245 ArtifactGenerationServiceTest.validateName(data.getResultData());
1248 } catch (Exception e) {
1249 Assert.fail(e.getMessage());
1251 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
1257 public void testArtifactGenerationVerifyResourceVersionFormat() {
1259 List<Artifact> inputArtifacts = new ArrayList();
1260 readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyResourceVersionFormat.yml");
1262 readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyResourceVersionFormat1.yml");
1263 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1265 List<ToscaTemplate> toscas = new LinkedList();
1266 for (Artifact inputArtifact : inputArtifacts) {
1267 toscas.add(getToscaModel(inputArtifact));
1270 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1271 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1272 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
1274 GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_RESOURCE_VERSION_IN_SERVICE_TOSCA,
1275 toscas.get(0).getMetadata().get("UUID")));
1277 inputArtifacts.remove(1);
1279 readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyResourceVersionFormat2.yml");
1280 GenerationData data2 = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG,
1282 Assert.assertEquals(data2.getErrorData().isEmpty(),false);
1283 Assert.assertEquals(data2.getErrorData().get("AAI").get(0),
1285 GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_RESOURCE_VERSION_IN_SERVICE_TOSCA,
1286 toscas.get(0).getMetadata().get("UUID")));
1288 } catch (Exception e) {
1289 Assert.fail(e.getMessage());
1294 public void testArtifactGenerationVerifyMandatoryParameterResourceVersion() {
1296 List<Artifact> inputArtifacts = new ArrayList();
1297 readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyMandatoryParameterResourceVersion.yml");
1299 readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyMandatoryParameterResourceVersion.yml");
1300 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1301 List<ToscaTemplate> toscas = new LinkedList();
1302 for (Artifact inputArtifact : inputArtifacts) {
1303 toscas.add(getToscaModel(inputArtifact));
1306 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1307 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1308 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format(
1309 GeneratorConstants.GENERATOR_AAI_ERROR_NULL_RESOURCE_VERSION_IN_SERVICE_TOSCA,toscas.get(0).getMetadata().get("UUID")));
1310 } catch (Exception e) {
1311 Assert.fail(e.getMessage());
1316 public void testArtifactGenerationWithoutAllottedResource() {
1318 List<Artifact> inputArtifacts = new ArrayList();
1320 readPayloadFromResource(inputArtifacts, "service-ServiceWithAllottedResourceIpmux-template.yml");
1322 readPayloadFromResource(inputArtifacts, "resource-AllottedResource-template_IpMux.yml");
1324 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1325 List<ToscaTemplate> toscas = new LinkedList();
1327 for (Artifact inputArtifact : inputArtifacts) {
1328 toscas.add(getToscaModel(inputArtifact));
1330 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1332 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1333 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format
1334 (GeneratorConstants.GENERATOR_AAI_PROVIDING_SERVICE_MISSING, toscas.get(1).getModelId()));
1336 } catch (Exception e) {
1337 Assert.fail(e.getMessage());
1342 public void testArtifactGenerationAllottedResourceIpmuxWithGroups() {
1344 List<Artifact> inputArtifacts = new ArrayList();
1346 readPayloadFromResource(inputArtifacts, "service-ServiceWithAllottedResourceIpmux-template_WithGroups.yml");
1348 readPayloadFromResource(inputArtifacts, "resource-AllottedResource-template_IpMux_WithGroups.yml");
1350 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1351 List<ToscaTemplate> toscas = new LinkedList();
1353 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1355 for (Artifact inputArtifact : inputArtifacts) {
1356 toscas.add(getToscaModel(inputArtifact));
1358 List<Artifact> resultData = data.getResultData();
1360 Map<String, Model> outputArtifactMap = new HashMap<>();
1361 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1362 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1363 testResourceTosca(toscas.iterator(), outputArtifactMap);
1365 Assert.assertEquals(5, data.getResultData().size());
1367 removeMockArtifact(data.getResultData().iterator());
1369 ArtifactGenerationServiceTest.validateName(data.getResultData());
1371 } catch (Exception e) {
1372 Assert.fail(e.getMessage());
1377 public void testArtifactGenerationAllottedResourceIpmuxSameInvariantDiffVersion() {
1379 List<Artifact> inputArtifacts = new ArrayList();
1381 readPayloadFromResource(inputArtifacts, "service-ServiceWithAllottedResourcesIpMuxSameInvariant-template.yml");
1383 readPayloadFromResource(inputArtifacts, "resource-AllottedResource1SameInvariant-IpMux-template.yml");
1385 readPayloadFromResource(inputArtifacts, "resource-AllottedResource2SameInvariant-IpMux-template.yml");
1387 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1388 List<ToscaTemplate> toscas = new LinkedList();
1390 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1392 for (Artifact inputArtifact : inputArtifacts) {
1393 toscas.add(getToscaModel(inputArtifact));
1395 List<Artifact> resultData = data.getResultData();
1397 Map<String, Model> outputArtifactMap = new HashMap<>();
1398 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1399 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1400 testResourceTosca(toscas.iterator(), outputArtifactMap);
1402 Assert.assertEquals(5, data.getResultData().size());
1404 removeMockArtifact(data.getResultData().iterator());
1406 ArtifactGenerationServiceTest.validateName(data.getResultData());
1409 } catch (Exception e) {
1410 Assert.fail(e.getMessage());
1415 public void testArtifactGenerationAllottedResourceIpmuxSameInvariantSameVersion() {
1417 List<Artifact> inputArtifacts = new ArrayList();
1419 readPayloadFromResource(inputArtifacts, "service-ServiceWithAllottedResourcesIpMuxSameInvariantSameVers-template.yml");
1421 readPayloadFromResource(inputArtifacts, "resource-AllottedResourceSameInvariantSameVers-IpMux-template.yml");
1423 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1424 List<ToscaTemplate> toscas = new LinkedList();
1426 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1428 for (Artifact inputArtifact : inputArtifacts) {
1429 toscas.add(getToscaModel(inputArtifact));
1431 List<Artifact> resultData = data.getResultData();
1433 Map<String, Model> outputArtifactMap = new HashMap<>();
1434 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1435 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1436 testResourceTosca(toscas.iterator(), outputArtifactMap);
1438 Assert.assertEquals(4, data.getResultData().size());
1440 removeMockArtifact(data.getResultData().iterator());
1442 ArtifactGenerationServiceTest.validateName(data.getResultData());
1445 } catch (Exception e) {
1446 Assert.fail(e.getMessage());
1451 public void testArtifactGenerationAllottedResourceWithIpMuxAndTunnelXConn() {
1453 List<Artifact> inputArtifacts = new ArrayList();
1455 readPayloadFromResource(inputArtifacts, "service-Allottedipmux-template.yml");
1457 readPayloadFromResource(inputArtifacts, "resource-IpMuxDemux-template.yml");
1459 readPayloadFromResource(inputArtifacts, "resource-TunnelXconn-template.yml");
1461 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1462 List<ToscaTemplate> toscas = new LinkedList();
1464 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1466 for (Artifact inputArtifact : inputArtifacts) {
1467 toscas.add(getToscaModel(inputArtifact));
1469 List<Artifact> resultData = data.getResultData();
1471 Map<String, Model> outputArtifactMap = new HashMap<>();
1472 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1473 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1474 testResourceTosca(toscas.iterator(), outputArtifactMap);
1476 Assert.assertEquals(5, data.getResultData().size());
1478 removeMockArtifact(data.getResultData().iterator());
1480 ArtifactGenerationServiceTest.validateName(data.getResultData());
1482 } catch (Exception e) {
1483 Assert.fail(e.getMessage());
1488 public void testArtifactGenerationAllottedResourceWithOutProvidingServiceId() {
1490 List<Artifact> inputArtifacts = new ArrayList();
1492 readPayloadFromResource(inputArtifacts, "service-SdWan-template_WithOutDepSerId.yml");
1494 readPayloadFromResource(inputArtifacts, "resource-VhnfNonHeat-template_WithOutDepSerId.yml");
1496 readPayloadFromResource(inputArtifacts, "resource-TunnelXconn-template_WithOutDepSerId.yml");
1498 readPayloadFromResource(inputArtifacts, "resource-ServiceAdmin-template_WithOutDepSerId.yml");
1500 readPayloadFromResource(inputArtifacts, "resource-IpMuxDemux-template_WithOutDepSerId.yml");
1502 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1503 List<ToscaTemplate> toscas = new LinkedList();
1504 for (Artifact inputArtifact : inputArtifacts) {
1505 toscas.add(getToscaModel(inputArtifact));
1508 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1509 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1510 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format
1511 (GeneratorConstants.GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING, toscas.get(2).getModelId()));
1512 } catch (Exception e) {
1513 Assert.fail(e.getMessage());
1518 public void testArtifactGenerationAllottedResourceWithVF() {
1520 List<Artifact> inputArtifacts = new ArrayList();
1522 readPayloadFromResource(inputArtifacts, "service-SdWan-template_AllRes_VF.yml");
1524 readPayloadFromResource(inputArtifacts, "resource-VhnfNonHeat-template_AllRes_VF.yml");
1526 readPayloadFromResource(inputArtifacts, "resource-TunnelXconn-template_AllRes_VF.yml");
1528 readPayloadFromResource(inputArtifacts, "resource-ServiceAdmin-template_AllRes_VF.yml");
1530 readPayloadFromResource(inputArtifacts, "resource-IpMuxDemux-template_AllRes_VF.yml");
1532 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1533 List<ToscaTemplate> toscas = new LinkedList();
1535 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1536 for (Artifact inputArtifact : inputArtifacts) {
1537 toscas.add(getToscaModel(inputArtifact));
1539 List<Artifact> resultData = data.getResultData();
1541 Map<String, Model> outputArtifactMap = new HashMap<>();
1542 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1543 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1544 testResourceTosca(toscas.iterator(), outputArtifactMap);
1546 Assert.assertEquals(7, data.getResultData().size());
1548 removeMockArtifact(data.getResultData().iterator());
1550 ArtifactGenerationServiceTest.validateName(data.getResultData());
1551 } catch (Exception e) {
1552 Assert.fail(e.getMessage());
1556 public static void readPayload(List<Artifact> inputArtifacts,InputStream fis, String fileName) throws IOException {
1557 byte[] payload = new byte[fis.available()];
1559 String checksum = GeneratorUtil.checkSum(payload);
1560 byte[] encodedPayload = GeneratorUtil.encode(payload);
1561 Artifact artifact = new Artifact(AAI_ARTIFACT_TYPE, AAI_ARTIFACT_GROUP_TYPE, checksum, encodedPayload);
1562 artifact.setName(fileName);
1563 artifact.setLabel(fileName);
1564 artifact.setDescription(fileName);
1565 inputArtifacts.add(artifact);
1570 * Get the tosca java model from the tosca input artifact
1572 * @param input Input tosca file and its metadata information as {@link Artifact} object
1573 * @return Translated {@link ToscaTemplate tosca} object
1574 * @throws SecurityException
1576 public static ToscaTemplate getToscaModel(Artifact input) {
1577 byte[] decodedInput = GeneratorUtil.decoder(input.getPayload());
1578 String checksum = GeneratorUtil.checkSum(decodedInput);
1579 if (checksum.equals(input.getChecksum())) {
1581 return GeneratorUtil.translateTosca(new String(decodedInput), ToscaTemplate.class);
1582 } catch (Exception e) {
1583 throw new IllegalArgumentException(String.format(
1584 GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_TOSCA, input.getName()));
1587 throw new SecurityException(String.format(
1588 GeneratorConstants.GENERATOR_AAI_ERROR_CHECKSUM_MISMATCH, input.getName()));
1592 public static void removeMockArtifact(Iterator<Artifact> itr) {
1593 while (itr.hasNext()){
1594 if(itr.next().getType().equals("OTHER")){
1600 private void readPayloadFromResource(List<Artifact> inputArtifacts, String fileName) throws IOException {
1602 try (InputStream fis = SampleJUnitTest.class.getResourceAsStream("/" + fileName)) {
1603 readPayload(inputArtifacts, fis, fileName);