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;
34 import org.onap.sdc.generator.data.*;
36 import junit.framework.TestCase;
37 import org.junit.Assert;
38 import org.junit.Test;
43 import static org.onap.sdc.generator.ArtifactGenerationServiceTest.*;
45 public class SampleJUnitTest extends TestCase {
47 private static final String AAI_ARTIFACT_TYPE = ArtifactType.AAI.name();
48 private static final String AAI_ARTIFACT_GROUP_TYPE = GroupType.DEPLOYMENT.name();
49 private static final String GENERATOR_CONFIG = "{\"artifactTypes\": [\"OTHER\",\"AAI\"]}";
50 private static final String ARTIFACT_GENERATOR_CONFIG = "artifactgenerator.config";
51 private static final String CONFIG_PATH = "/qa-test-repo/jmeter3/apache-jmeter-3" +
53 private static final String GENERATOR_AAI_CONFIGLPROP_NOT_FOUND =
54 "Cannot generate artifacts. Widget configuration not found for %s";
55 private static final String GENERATOR_AAI_CONFIGFILE_NOT_FOUND =
56 "Cannot generate artifacts. Artifact Generator Configuration file not found at %s";
57 private static final String GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND =
58 "Cannot generate artifacts. artifactgenerator.config system property not configured";
59 private static final String INVALID_VALUE_INVARIANT =
60 "Invalid value for mandatory attribute <invariantUUID> in Artifact";
61 private static final String INVALID_VALUE_UUID =
62 "Invalid value for mandatory attribute <UUID> in Artifact:";
63 static final Map<String, String> additionalParams = new HashMap<>();
64 public static final String ARTIFACT_GENERATOR_PROPERTIES = "Artifact-Generator.properties";
65 public static final String VF_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML = "vf_vmme_template_NoSystemPropConfigured.yml";
66 public static final String SERVICE_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML = "service_vmme_template_NoSystemPropConfigured.yml";
69 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
72 public SampleJUnitTest(String name) throws IOException {
74 System.setProperty(ARTIFACT_GENERATOR_CONFIG,CONFIG_PATH + ARTIFACT_GENERATOR_PROPERTIES);
75 loadConfig(ArtifactGenerationServiceTest.properties);
78 private void loadConfig(Properties properties) throws IOException {
79 String configLocation = System.getProperty(ARTIFACT_GENERATOR_CONFIG);
80 if (configLocation != null) {
81 File file = new File(configLocation);
84 try (InputStream fis = new FileInputStream(file)) {
91 public SampleJUnitTest() {
93 System.setProperty(ARTIFACT_GENERATOR_CONFIG,CONFIG_PATH + ARTIFACT_GENERATOR_PROPERTIES);
97 public void testArtifactGenerationSingleVFSingleVFModule() {
99 List<Artifact> inputArtifacts = new ArrayList();
100 readPayloadFromResource(inputArtifacts, "vf_vmme_template_SingleVFVFMod.yml");
102 readPayloadFromResource(inputArtifacts, "service_vmme_template_SingleVFVFMod.yml");
103 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
104 List<ToscaTemplate> toscas = new LinkedList();
106 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
108 for (Artifact inputArtifact : inputArtifacts) {
109 toscas.add(getToscaModel(inputArtifact));
111 List<Artifact> resultData = data.getResultData();
113 Map<String, Model> outputArtifactMap = new HashMap<>();
114 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
115 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
117 testResourceTosca(toscas.iterator(), outputArtifactMap);
119 Assert.assertEquals(5, data.getResultData().size());
121 removeMockArtifact(data.getResultData().iterator());
123 ArtifactGenerationServiceTest.validateName(data.getResultData());
126 } catch (Exception e) {
127 Assert.fail(e.getMessage());
132 public void testArtifactGenerationMissingVFInServiceTOSCA() {
134 List<Artifact> inputArtifacts = new ArrayList();
135 readPayloadFromResource(inputArtifacts, "service_vmme_template_MissingVFInServiceTOSCA.yml");
136 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
137 List<ToscaTemplate> toscas = new LinkedList();
139 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
141 for (Artifact inputArtifact : inputArtifacts) {
142 toscas.add(getToscaModel(inputArtifact));
144 List<Artifact> resultData = data.getResultData();
146 Map<String, Model> outputArtifactMap = new HashMap<>();
147 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
148 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
150 Assert.assertEquals(3, data.getResultData().size());
152 removeMockArtifact(data.getResultData().iterator());
154 ArtifactGenerationServiceTest.validateName(data.getResultData());
157 } catch (Exception e) {
158 Assert.fail(e.getMessage());
163 public void testArtifactGenerationVerifySameStaticWidgetsForAllServices() {
165 List<Artifact> inputArtifacts = new ArrayList();
166 readPayloadFromResource(inputArtifacts, "vf_vmme_template_SameWidgets1.yml");
168 readPayloadFromResource(inputArtifacts, "service_vmme_template_SameWidget1.yml");
169 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
170 List<ToscaTemplate> toscas = new LinkedList();
172 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
174 for (Artifact inputArtifact : inputArtifacts) {
175 toscas.add(getToscaModel(inputArtifact));
177 List<Artifact> resultData = data.getResultData();
179 Map<String, Model> outputArtifactMap = new HashMap<>();
180 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
182 removeMockArtifact(data.getResultData().iterator());
185 List<Artifact> inputArtifacts2 = new ArrayList();
186 readPayloadFromResource(inputArtifacts2, "vf_vmme_template_SameWidgets2.yml");
188 readPayloadFromResource(inputArtifacts2, "service_vmme_template_SameWidget2.yml");
189 ArtifactGenerationServiceImpl obj2 = new ArtifactGenerationServiceImpl();
191 GenerationData data2 = obj2.generateArtifact(inputArtifacts2, GENERATOR_CONFIG,additionalParams);
192 List<Artifact> resultData2 = data2.getResultData();
194 List<ToscaTemplate> toscas2 = new LinkedList();
196 for (Artifact inputArtifact : inputArtifacts2) {
197 toscas2.add(getToscaModel(inputArtifact));
200 Map<String, Model> outputArtifactMap2 = new HashMap<>();
201 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap2, resultData2);
202 removeMockArtifact(data2.getResultData().iterator());
204 Map<String,String> map = new HashMap<>();
205 Iterator<Artifact> itr = data.getResultData().iterator();
206 while(itr.hasNext()){
207 Artifact artifact=itr.next();
208 if(artifact.getLabel().contains("AAI-widget")){
209 map.put(artifact.getName(),artifact.getChecksum());
212 Map<String,String> map2 = new HashMap<>();
213 Iterator<Artifact> itr2 = data2.getResultData().iterator();
214 while(itr2.hasNext()){
215 Artifact artifact=itr2.next();
216 if(artifact.getLabel().contains("AAI-widget")){
217 map2.put(artifact.getName(),artifact.getChecksum());
220 Assert.assertEquals(map.size(),map2.size());
221 for(Map.Entry<String, String> entry : map.entrySet()){
222 Assert.assertEquals(entry.getValue(), map2.get(entry.getKey()));
225 } catch (Exception e) {
226 Assert.fail(e.getMessage());
231 public void testArtifactGenerationMulVFModule() {
233 List<Artifact> inputArtifacts = new ArrayList();
234 readPayloadFromResource(inputArtifacts, "vf_vmme_template_MulVFVFMod.yml");
236 readPayloadFromResource(inputArtifacts, "service_vmme_template_MulVFVFMod.yml");
238 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
239 List<ToscaTemplate> toscas = new LinkedList();
241 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
243 for (Artifact inputArtifact : inputArtifacts) {
244 toscas.add(getToscaModel(inputArtifact));
246 List<Artifact> resultData = data.getResultData();
248 Map<String, Model> outputArtifactMap = new HashMap<>();
249 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
250 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
251 testResourceTosca(toscas.iterator(), outputArtifactMap);
253 Assert.assertEquals(3,data.getResultData().size());
255 removeMockArtifact(data.getResultData().iterator());
257 ArtifactGenerationServiceTest.validateName(data.getResultData());
259 } catch (Exception e) {
260 Assert.fail(e.getMessage());
265 public void testArtifactGenerationMulVFs() {
267 List<Artifact> inputArtifacts = new ArrayList();
269 readPayloadFromResource(inputArtifacts, "CMAUI_VF.yaml");
271 readPayloadFromResource(inputArtifacts, "ECA_OAM_VF.yaml");
273 readPayloadFromResource(inputArtifacts, "MMSC_Sevice_07_25_16.yaml");
275 readPayloadFromResource(inputArtifacts, "MMSC_VF.yaml");
277 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
278 List<ToscaTemplate> toscas = new LinkedList();
280 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
282 for (Artifact inputArtifact : inputArtifacts) {
283 toscas.add(getToscaModel(inputArtifact));
285 List<Artifact> resultData = data.getResultData();
287 Map<String, Model> outputArtifactMap = new HashMap<>();
288 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
289 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
290 testResourceTosca(toscas.iterator(), outputArtifactMap);
292 Assert.assertEquals(8,data.getResultData().size());
294 removeMockArtifact(data.getResultData().iterator());
296 ArtifactGenerationServiceTest.validateName(data.getResultData());
298 } catch (Exception e) {
299 Assert.fail(e.getMessage());
304 public void testArtifactGenerationDupVFUUID() {
306 List<Artifact> inputArtifacts = new ArrayList();
307 readPayloadFromResource(inputArtifacts, "vf_vmme_template_DupVFUUID.yml");
309 readPayloadFromResource(inputArtifacts, "service_vmme_template_DupVFUUID.yml");
310 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
311 List<ToscaTemplate> toscas = new LinkedList();
313 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
315 for (Artifact inputArtifact : inputArtifacts) {
316 toscas.add(getToscaModel(inputArtifact));
318 List<Artifact> resultData = data.getResultData();
320 Map<String, Model> outputArtifactMap = new HashMap<>();
321 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
322 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
323 testResourceTosca(toscas.iterator(), outputArtifactMap);
325 Assert.assertEquals(5,data.getResultData().size());
327 removeMockArtifact(data.getResultData().iterator());
329 ArtifactGenerationServiceTest.validateName(data.getResultData());
331 } catch (Exception e) {
332 Assert.fail(e.getMessage());
337 public void testArtifactGenerationDupVFModUUID() {
339 List<Artifact> inputArtifacts = new ArrayList();
340 readPayloadFromResource(inputArtifacts, "vf_vmme_template_DupVFModUUID.yml");
342 readPayloadFromResource(inputArtifacts, "service_vmme_template_DupVFModUUID.yml");
343 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
344 List<ToscaTemplate> toscas = new LinkedList();
346 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
348 for (Artifact inputArtifact : inputArtifacts) {
349 toscas.add(getToscaModel(inputArtifact));
351 List<Artifact> resultData = data.getResultData();
353 Map<String, Model> outputArtifactMap = new HashMap<>();
354 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
355 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
356 testResourceTosca(toscas.iterator(), outputArtifactMap);
358 Assert.assertEquals(5,data.getResultData().size());
360 removeMockArtifact(data.getResultData().iterator());
362 ArtifactGenerationServiceTest.validateName(data.getResultData());
363 } catch (Exception e) {
364 Assert.fail(e.getMessage());
369 public void testArtifactGenerationVerifyVFModWithoutVNFC() {
371 List<Artifact> inputArtifacts = new ArrayList();
372 readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyVFModWithoutVNFC.yml");
374 readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyVFModWithoutVNFC.yml");
375 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
376 List<ToscaTemplate> toscas = new LinkedList();
378 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
380 for (Artifact inputArtifact : inputArtifacts) {
381 toscas.add(getToscaModel(inputArtifact));
383 List<Artifact> resultData = data.getResultData();
385 Map<String, Model> outputArtifactMap = new HashMap<>();
386 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
387 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
388 testResourceTosca(toscas.iterator(), outputArtifactMap);
390 Assert.assertEquals(5,data.getResultData().size());
392 removeMockArtifact(data.getResultData().iterator());
394 ArtifactGenerationServiceTest.validateName(data.getResultData());
395 } catch (Exception e) {
396 Assert.fail(e.getMessage());
401 public void testArtifactGenerationVerifyVFModWithInvalidMember() {
403 List<Artifact> inputArtifacts = new ArrayList();
404 readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyVFModWithInvalidNo.yml");
406 readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyVFModWithInvalidNo.yml");
407 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
408 List<ToscaTemplate> toscas = new LinkedList();
410 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
412 for (Artifact inputArtifact : inputArtifacts) {
413 toscas.add(getToscaModel(inputArtifact));
415 List<Artifact> resultData = data.getResultData();
417 Map<String, Model> outputArtifactMap = new HashMap<>();
418 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
419 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
420 testResourceTosca(toscas.iterator(), outputArtifactMap);
422 Assert.assertEquals(5,data.getResultData().size());
424 removeMockArtifact(data.getResultData().iterator());
426 ArtifactGenerationServiceTest.validateName(data.getResultData());
427 } catch (Exception e) {
428 Assert.fail(e.getMessage());
433 public void testArtifactGenerationNullFields() {
435 List<Artifact> inputArtifacts = new ArrayList();
436 readPayloadFromResource(inputArtifacts, "vf_vmme_template_NullFields.yml");
438 readPayloadFromResource(inputArtifacts, "service_vmme_template_NullFields.yml");
439 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
441 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
442 Assert.assertEquals(false,data.getErrorData().isEmpty());
444 Assert.assertEquals("Invalid Service/Resource definition mandatory attribute <UUID> missing in Artifact: <"+inputArtifacts.get(0).getName()+">",data.getErrorData().get("AAI").get(0));
446 Assert.assertEquals(2,data.getResultData().size());
448 } catch (Exception e) {
449 Assert.fail(e.getMessage());
454 public void testArtifactGenerationInCorrectYmlFormat() {
456 List<Artifact> inputArtifacts = new ArrayList();
458 readPayloadFromResource(inputArtifacts, "CMAUI_VFInvalidFormat.yaml");
460 readPayloadFromResource(inputArtifacts, "ECA_OAM_VFInvalidFormat.yaml");
462 readPayloadFromResource(inputArtifacts, "MMSC_Sevice_07_25_16InvalidFormat.yaml");
464 readPayloadFromResource(inputArtifacts, "MMSC_VFInvalidFormat.yaml");
466 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
468 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
469 Assert.assertEquals(false,data.getErrorData().isEmpty());
471 Assert.assertEquals("Invalid format for Tosca YML : "+inputArtifacts.get(1).getName(),data.getErrorData().get("AAI").get(0));
473 Assert.assertEquals(2,data.getResultData().size());
475 } catch (Exception e) {
476 Assert.fail(e.getMessage());
481 public void testArtifactGenerationMulComp() {
483 List<Artifact> inputArtifacts = new ArrayList();
484 readPayloadFromResource(inputArtifacts, "vf_vmme_template_MulComp.yml");
486 readPayloadFromResource(inputArtifacts, "service_vmme_template_MulComp.yml");
487 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
488 List<ToscaTemplate> toscas = new LinkedList();
490 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
492 for (Artifact inputArtifact : inputArtifacts) {
493 toscas.add(getToscaModel(inputArtifact));
495 List<Artifact> resultData = data.getResultData();
497 Map<String, Model> outputArtifactMap = new HashMap<>();
498 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
499 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
500 testResourceTosca(toscas.iterator(), outputArtifactMap);
502 Assert.assertEquals(5,data.getResultData().size());
504 removeMockArtifact(data.getResultData().iterator());
506 ArtifactGenerationServiceTest.validateName(data.getResultData());
507 } catch (Exception e) {
508 Assert.fail(e.getMessage());
513 public void testArtifactGenerationOrphan() {
515 List<Artifact> inputArtifacts = new ArrayList();
517 readPayloadFromResource(inputArtifacts, "vf_vmme_template_Orphan.yml");
519 readPayloadFromResource(inputArtifacts, "service_vmme_template_Orphan.yml");
521 readPayloadFromResource(inputArtifacts, "ECA_OAM_VFOrphan.yaml");
523 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
524 List<ToscaTemplate> toscas = new LinkedList();
526 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
528 for (Artifact inputArtifact : inputArtifacts) {
529 toscas.add(getToscaModel(inputArtifact));
531 List<Artifact> resultData = data.getResultData();
533 Map<String, Model> outputArtifactMap = new HashMap<>();
534 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
535 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
536 testResourceTosca(toscas.iterator(), outputArtifactMap);
538 Assert.assertEquals(5,data.getResultData().size());
540 removeMockArtifact(data.getResultData().iterator());
542 ArtifactGenerationServiceTest.validateName(data.getResultData());
543 } catch (Exception e) {
544 Assert.fail(e.getMessage());
549 public void testArtifactGenerationMissingVFTemplate() {
551 List<Artifact> inputArtifacts = new ArrayList();
553 readPayloadFromResource(inputArtifacts, "service_vmme_template_MissingVFTemplate.yml");
555 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
556 List<ToscaTemplate> toscas = new LinkedList();
558 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
560 for (Artifact inputArtifact : inputArtifacts) {
561 toscas.add(getToscaModel(inputArtifact));
563 List<Artifact> resultData = data.getResultData();
565 Map<String, Model> outputArtifactMap = new HashMap<>();
566 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
567 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
570 Assert.assertEquals(3,data.getResultData().size());
572 removeMockArtifact(data.getResultData().iterator());
574 ArtifactGenerationServiceTest.validateName(data.getResultData());
575 } catch (Exception e) {
576 Assert.fail(e.getMessage());
581 public void testArtifactGenerationMissingVFModule() {
583 List<Artifact> inputArtifacts = new ArrayList();
585 readPayloadFromResource(inputArtifacts, "CMAUI_VFMissingVFModule.yaml");
587 readPayloadFromResource(inputArtifacts, "ECA_OAM_VFMissingVFModule.yaml");
589 readPayloadFromResource(inputArtifacts, "MMSC_Sevice_07_25_16MissingVFModule.yaml");
591 readPayloadFromResource(inputArtifacts, "MMSC_VFMissingVFModule.yaml");
593 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
594 List<ToscaTemplate> toscas = new LinkedList();
596 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
598 for (Artifact inputArtifact : inputArtifacts) {
599 toscas.add(getToscaModel(inputArtifact));
601 List<Artifact> resultData = data.getResultData();
603 Map<String, Model> outputArtifactMap = new HashMap<>();
604 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
605 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
606 testResourceTosca(toscas.iterator(), outputArtifactMap);
608 Assert.assertEquals(8,data.getResultData().size());
610 removeMockArtifact(data.getResultData().iterator());
612 ArtifactGenerationServiceTest.validateName(data.getResultData());
614 } catch (Exception e) {
615 Assert.fail(e.getMessage());
620 public void testArtifactGenerationEmptyArtifact() {
622 List<Artifact> inputArtifacts = new ArrayList();
624 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
626 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
627 Assert.assertEquals(false,data.getErrorData().isEmpty());
628 Assert.assertEquals("Service tosca missing from list of input artifacts",data.getErrorData().get("AAI").get(0));
630 Assert.assertEquals(2,data.getResultData().size());
632 } catch (Exception e) {
633 Assert.fail(e.getMessage());
638 public void testArtifactGenerationMissingConfigFile() {
640 List<Artifact> inputArtifacts = new ArrayList();
642 readPayloadFromResource(inputArtifacts, "vf_vmme_template_SingleVFVFMod.yml");
644 readPayloadFromResource(inputArtifacts, "service_vmme_template_SingleVFVFMod.yml");
645 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
647 GenerationData data = obj.generateArtifact(inputArtifacts, "",additionalParams);
648 Assert.assertEquals(false,data.getErrorData().isEmpty());
649 Assert.assertEquals("Invalid Client Configuration",data.getErrorData().get("ARTIFACT_GENERATOR_INVOCATION_ERROR").get(0));
651 Assert.assertEquals(0,data.getResultData().size());
653 } catch (Exception e) {
654 Assert.fail(e.getMessage());
660 public void testArtifactGenerationWithNodeTemplates() {
662 List<Artifact> inputArtifacts = new ArrayList();
664 readPayloadFromResource(inputArtifacts, "ServiceWithNodetemplate.yml");
666 readPayloadFromResource(inputArtifacts, "Resource0-template.yml");
668 readPayloadFromResource(inputArtifacts, "Resource1-template.yml");
670 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
671 List<ToscaTemplate> toscas = new LinkedList();
673 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
675 for (Artifact inputArtifact : inputArtifacts) {
676 toscas.add(getToscaModel(inputArtifact));
678 List<Artifact> resultData = data.getResultData();
680 Map<String, Model> outputArtifactMap = new HashMap<>();
681 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
682 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
683 testResourceTosca(toscas.iterator(), outputArtifactMap);
685 Assert.assertEquals(5,data.getResultData().size());
687 removeMockArtifact(data.getResultData().iterator());
689 ArtifactGenerationServiceTest.validateName(data.getResultData());
692 } catch (Exception e) {
693 Assert.fail(e.getMessage());
698 public void testArtifactGenerationWithoutNodeTemplates() {
700 List<Artifact> inputArtifacts = new ArrayList();
702 readPayloadFromResource(inputArtifacts, "Service0-template.yml");
704 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
705 List<ToscaTemplate> toscas = new LinkedList();
707 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
709 for (Artifact inputArtifact : inputArtifacts) {
710 toscas.add(getToscaModel(inputArtifact));
712 List<Artifact> resultData = data.getResultData();
714 Map<String, Model> outputArtifactMap = new HashMap<>();
715 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
716 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
719 Assert.assertEquals(3,data.getResultData().size());
721 removeMockArtifact(data.getResultData().iterator());
723 ArtifactGenerationServiceTest.validateName(data.getResultData());
726 } catch (Exception e) {
727 Assert.fail(e.getMessage());
732 public void testArtifactGenerationWithArtifactNameAndDescMoreThan256() {
734 List<Artifact> inputArtifacts = new ArrayList();
736 readPayloadFromResource(inputArtifacts, "Service0-templateMoreThan256.yml");
738 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
739 List<ToscaTemplate> toscas = new LinkedList();
741 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
743 for (Artifact inputArtifact : inputArtifacts) {
744 toscas.add(getToscaModel(inputArtifact));
746 List<Artifact> resultData = data.getResultData();
748 Map<String, Model> outputArtifactMap = new HashMap<>();
749 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
750 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
753 Assert.assertEquals(3,data.getResultData().size());
755 removeMockArtifact(data.getResultData().iterator());
757 for(Artifact artifact : data.getResultData()){
758 checkArtifactName(artifact.getName());
759 checkArtifactLabel(artifact.getLabel());
760 checkArtifactDescription(artifact.getDescription());
764 } catch (Exception e) {
765 Assert.fail(e.getMessage());
770 public void testArtifactGenerationWithDifferentVersionOfSameVF() {
772 List<Artifact> inputArtifacts = new ArrayList();
774 readPayloadFromResource(inputArtifacts, "service_vmme_template_DiffVerOfSameVF.yml");
776 readPayloadFromResource(inputArtifacts, "vf_vmme_template_DiffVerOfSameVF_1.yml");
778 readPayloadFromResource(inputArtifacts, "vf_vmme_template_DiffVerOfSameVF_2.yml");
780 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
781 List<ToscaTemplate> toscas = new LinkedList();
783 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
785 for (Artifact inputArtifact : inputArtifacts) {
786 toscas.add(getToscaModel(inputArtifact));
788 List<Artifact> resultData = data.getResultData();
790 Map<String, Model> outputArtifactMap = new HashMap<>();
791 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
792 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
793 testResourceTosca(toscas.iterator(), outputArtifactMap);
795 Assert.assertEquals(6,data.getResultData().size());
797 removeMockArtifact(data.getResultData().iterator());
799 ArtifactGenerationServiceTest.validateName(data.getResultData());
802 } catch (Exception e) {
803 Assert.fail(e.getMessage());
808 public void testArtifactGenerationWithDifferentVersionOfSameVFModWithSameInvId() {
810 List<Artifact> inputArtifacts = new ArrayList();
812 readPayloadFromResource(inputArtifacts, "service_vmme_template_DiffVerOfSameVFModWithSameInvId.yml");
814 readPayloadFromResource(inputArtifacts, "vf_vmme_template_DiffVerOfSameVFModWithSameInvId.yml");
816 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
817 List<ToscaTemplate> toscas = new LinkedList();
819 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
821 for (Artifact inputArtifact : inputArtifacts) {
822 toscas.add(getToscaModel(inputArtifact));
824 List<Artifact> resultData = data.getResultData();
826 Map<String, Model> outputArtifactMap = new HashMap<>();
827 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
828 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
829 testResourceTosca(toscas.iterator(), outputArtifactMap);
831 Assert.assertEquals(6,data.getResultData().size());
833 removeMockArtifact(data.getResultData().iterator());
835 ArtifactGenerationServiceTest.validateName(data.getResultData());
838 } catch (Exception e) {
839 Assert.fail(e.getMessage());
844 public void testArtifactGenerationWithServiceContainingL3Network() {
846 List<Artifact> inputArtifacts = new ArrayList();
848 readPayloadFromResource(inputArtifacts, "service_vmme_template_WithL3Network.yml");
850 readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithL3Network.yml");
852 readPayloadFromResource(inputArtifacts, "resource-AllottedResource-template_WithL3Network.yml");
854 readPayloadFromResource(inputArtifacts, "resource-Extvl-template_WithL3Network.yml");
856 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
857 List<ToscaTemplate> toscas = new LinkedList();
859 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
861 for (Artifact inputArtifact : inputArtifacts) {
862 toscas.add(getToscaModel(inputArtifact));
864 List<Artifact> resultData = data.getResultData();
866 Map<String, Model> outputArtifactMap = new HashMap<>();
867 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
868 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
869 testResourceTosca(toscas.iterator(), outputArtifactMap);
871 Assert.assertEquals(7,data.getResultData().size());
873 removeMockArtifact(data.getResultData().iterator());
875 ArtifactGenerationServiceTest.validateName(data.getResultData());
878 } catch (Exception e) {
879 Assert.fail(e.getMessage());
884 public void testArtifactGenerationWithServiceContainingDupL3Network() {
886 List<Artifact> inputArtifacts = new ArrayList();
888 readPayloadFromResource(inputArtifacts, "service_vmme_template_WithDupL3Network.yml");
890 readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithDupL3Network.yml");
892 readPayloadFromResource(inputArtifacts, "resource-AllottedResource-template_WithDupL3Network.yml");
894 readPayloadFromResource(inputArtifacts, "resource-Extvl-template_WithDupL3Network.yml");
896 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
897 List<ToscaTemplate> toscas = new LinkedList();
899 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
901 for (Artifact inputArtifact : inputArtifacts) {
902 toscas.add(getToscaModel(inputArtifact));
904 List<Artifact> resultData = data.getResultData();
906 Map<String, Model> outputArtifactMap = new HashMap<>();
907 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
908 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
909 testResourceTosca(toscas.iterator(), outputArtifactMap);
911 Assert.assertEquals(7,data.getResultData().size());
913 removeMockArtifact(data.getResultData().iterator());
915 ArtifactGenerationServiceTest.validateName(data.getResultData());
918 } catch (Exception e) {
919 Assert.fail(e.getMessage());
924 public void testArtifactGenerationWithL3NetworkInVFMod() {
926 List<Artifact> inputArtifacts = new ArrayList();
928 readPayloadFromResource(inputArtifacts, "service_vmme_template_WithL3NetworkInVFMod.yml");
930 readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithL3NetworkInVFMod.yml");
932 readPayloadFromResource(inputArtifacts, "resource-AllottedResource-template_WithL3NetworkInVFMod.yml");
934 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
935 List<ToscaTemplate> toscas = new LinkedList();
937 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
939 for (Artifact inputArtifact : inputArtifacts) {
940 toscas.add(getToscaModel(inputArtifact));
942 List<Artifact> resultData = data.getResultData();
944 Map<String, Model> outputArtifactMap = new HashMap<>();
945 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
946 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
947 testResourceTosca(toscas.iterator(), outputArtifactMap);
949 Assert.assertEquals(6,data.getResultData().size());
951 removeMockArtifact(data.getResultData().iterator());
953 ArtifactGenerationServiceTest.validateName(data.getResultData());
956 } catch (Exception e) {
957 Assert.fail(e.getMessage());
962 public void testArtifactGenerationWithDiffVersionOfSameL3Network() {
964 List<Artifact> inputArtifacts = new ArrayList();
966 readPayloadFromResource(inputArtifacts, "service_vmme_template_WithDiffVersionOfSameL3Network.yml");
968 readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithDiffVersionOfSameL3Network.yml");
970 readPayloadFromResource(inputArtifacts, "resource-AllottedResource-template_WithDiffVersionOfSameL3Network.yml");
972 readPayloadFromResource(inputArtifacts, "resource-Extvl-template_WithDiffVersionOfSameL3Network.yml");
974 readPayloadFromResource(inputArtifacts, "resource-Extvl-template_1_WithDiffVersionOfSameL3Network.yml");
976 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
977 List<ToscaTemplate> toscas = new LinkedList();
979 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
981 for (Artifact inputArtifact : inputArtifacts) {
982 toscas.add(getToscaModel(inputArtifact));
984 List<Artifact> resultData = data.getResultData();
986 Map<String, Model> outputArtifactMap = new HashMap<>();
987 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData);
988 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas);
989 testResourceTosca(toscas.iterator(), outputArtifactMap);
991 Assert.assertEquals(8,data.getResultData().size());
993 removeMockArtifact(data.getResultData().iterator());
995 ArtifactGenerationServiceTest.validateName(data.getResultData());
998 } catch (Exception e) {
999 Assert.fail(e.getMessage());
1004 public void testArtifactGenerationWithInvIdGreaterThanSpecifiedLimit() {
1006 List<Artifact> inputArtifacts = new ArrayList();
1007 readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithInvIdGreaterThanSpecifiedLimit.yml");
1009 readPayloadFromResource(inputArtifacts, "service_vmme_template_WithInvIdGreaterThanSpecifiedLimit.yml");
1010 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1012 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1013 Assert.assertEquals(false,data.getErrorData().isEmpty());
1015 Assert.assertEquals(INVALID_VALUE_INVARIANT + ": <" +inputArtifacts.get(1).getName()+">",data.getErrorData().get("AAI").get(0));
1017 Assert.assertEquals(2,data.getResultData().size());
1019 } catch (Exception e) {
1020 Assert.fail(e.getMessage());
1025 public void testArtifactGenerationWithInvIdLesserThanSpecifiedLimit() {
1027 List<Artifact> inputArtifacts = new ArrayList();
1028 readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithInvIdLesserThanSpecifiedLimit.yml");
1030 readPayloadFromResource(inputArtifacts, "service_vmme_template_WithInvIdLesserThanSpecifiedLimit.yml");
1031 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1033 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1034 Assert.assertEquals(false,data.getErrorData().isEmpty());
1036 Assert.assertEquals(INVALID_VALUE_UUID + " <"
1037 +inputArtifacts.get(1).getName()+">",data.getErrorData().get("AAI").get(0));
1039 Assert.assertEquals(2,data.getResultData().size());
1041 } catch (Exception e) {
1042 Assert.fail(e.getMessage());
1048 public void testErrorWhenNoSystemPropConfigured() {
1049 String configLoc = System.getProperty(ARTIFACT_GENERATOR_CONFIG);
1051 List<Artifact> inputArtifacts = new ArrayList();
1052 readPayloadFromResource(inputArtifacts, VF_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML);
1054 readPayloadFromResource(inputArtifacts, SERVICE_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML);
1056 System.clearProperty(ARTIFACT_GENERATOR_CONFIG);
1058 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1059 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1060 Assert.assertEquals(false,data.getErrorData().isEmpty());
1061 Assert.assertEquals(data.getErrorData().
1062 get("AAI").get(0), GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND);
1063 } catch (Exception e) {
1064 Assert.fail(e.getMessage());
1067 System.setProperty(ARTIFACT_GENERATOR_CONFIG,configLoc);
1072 public void testErrorWhenNoFileAtConfigLocation() {
1073 String configLoc = System.getProperty(ARTIFACT_GENERATOR_CONFIG);
1075 List<Artifact> inputArtifacts = new ArrayList();
1076 readPayloadFromResource(inputArtifacts, VF_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML);
1078 readPayloadFromResource(inputArtifacts, SERVICE_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML);
1080 System.setProperty(ARTIFACT_GENERATOR_CONFIG,configLoc + File.separator + "testErrorWhenNoFileAtConfigLocation");
1081 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1082 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1083 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1084 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format(
1085 GENERATOR_AAI_CONFIGFILE_NOT_FOUND,System.getProperty
1086 (ARTIFACT_GENERATOR_CONFIG)));
1087 } catch (Exception e) {
1088 Assert.fail(e.getMessage());
1091 System.setProperty(ARTIFACT_GENERATOR_CONFIG,configLoc);
1096 public void testErrorWhenNoWidgetInConfig() throws IOException {
1097 System.setProperty(ARTIFACT_GENERATOR_CONFIG,CONFIG_PATH+"Artifact-Generator1.properties");
1098 loadConfig(ArtifactGenerationServiceTest.properties);
1100 List<Artifact> inputArtifacts = new ArrayList();
1101 readPayloadFromResource(inputArtifacts, VF_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML);
1103 readPayloadFromResource(inputArtifacts, SERVICE_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML);
1105 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1106 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1108 String assertMsg = ArtifactType.AAI.name() + ".model-version-id." + Widget.getWidget
1109 (Widget.Type.SERVICE).getName();
1111 Assert.assertEquals(false,data.getErrorData().isEmpty());
1112 String errMsg = String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,assertMsg);
1113 Assert.assertEquals(data.getErrorData().get("AAI").get(0),errMsg);
1114 } catch (Exception e) {
1115 Assert.fail(e.getMessage());
1117 System.setProperty(ARTIFACT_GENERATOR_CONFIG, CONFIG_PATH + ARTIFACT_GENERATOR_PROPERTIES);
1118 loadConfig(ArtifactGenerationServiceTest.properties);
1123 public void testArtifactGenerationWithUpdatedUUIDInConfig() throws IOException {
1125 List<Artifact> inputArtifacts = new ArrayList();
1126 readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithUpdatedUUIDInConfig.yml");
1128 readPayloadFromResource(inputArtifacts, "service_vmme_template_WithUpdatedUUIDInConfig.yml");
1130 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1131 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1132 List<ToscaTemplate> toscas = new LinkedList();
1133 for (Artifact inputArtifact : inputArtifacts) {
1134 toscas.add(getToscaModel(inputArtifact));
1136 List<Artifact> resultData = data.getResultData();
1137 Map<String, Model> outputArtifactMap = new HashMap<>();
1138 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1139 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1140 testResourceTosca(toscas.iterator(), outputArtifactMap);
1142 System.setProperty(ARTIFACT_GENERATOR_CONFIG,CONFIG_PATH+"Artifact-Generator2.properties");
1143 loadConfig(ArtifactGenerationServiceTest.properties);
1145 List<ToscaTemplate> toscas2 = new LinkedList();
1146 for (Artifact inputArtifact : inputArtifacts) {
1147 toscas2.add(getToscaModel(inputArtifact));
1149 GenerationData data2 = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1150 Map<String, Model> outputArtifactMap2 = new HashMap<>();
1151 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap2,
1152 data2.getResultData());
1153 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap2, toscas2);
1154 testResourceTosca(toscas2.iterator(), outputArtifactMap2);
1156 } catch (Exception e) {
1157 Assert.fail(e.getMessage());
1159 System.setProperty(ARTIFACT_GENERATOR_CONFIG,CONFIG_PATH + ARTIFACT_GENERATOR_PROPERTIES);
1160 loadConfig(ArtifactGenerationServiceTest.properties);
1165 public void testArtifactGenerationVerifyMandatoryParameterServiceVersion() {
1167 List<Artifact> inputArtifacts = new ArrayList();
1168 readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyMandatoryParameterServiceVersion.yml");
1170 readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyMandatoryParameterServiceVersion.yml");
1171 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1173 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, new HashMap<String, String>());
1175 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1176 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
1177 GeneratorConstants.GENERATOR_AAI_ERROR_MISSING_SERVICE_VERSION);
1178 } catch (Exception e) {
1179 Assert.fail(e.getMessage());
1184 public void testArtifactGenerationVerifyServiceVersionFormat() {
1186 List<Artifact> inputArtifacts = new ArrayList();
1187 readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyServiceVersionFormat.yml");
1189 readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyServiceVersionFormat.yml");
1190 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1192 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1");
1193 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1194 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1195 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
1196 GeneratorConstants.GENERATOR_AAI_INVALID_SERVICE_VERSION);
1198 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.1");
1199 GenerationData data2 = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG,
1201 Assert.assertEquals(data2.getErrorData().isEmpty(),false);
1202 Assert.assertEquals(data2.getErrorData().get("AAI").get(0),
1203 GeneratorConstants.GENERATOR_AAI_INVALID_SERVICE_VERSION);
1205 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.0");
1206 GenerationData data3 = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG,
1208 Assert.assertEquals(data3.getErrorData().isEmpty(),false);
1209 Assert.assertEquals(data3.getErrorData().get("AAI").get(0),
1210 GeneratorConstants.GENERATOR_AAI_INVALID_SERVICE_VERSION);
1211 } catch (Exception e) {
1212 Assert.fail(e.getMessage());
1214 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
1219 public void testArtifactGenerationVerifyServiceVersion() {
1221 List<Artifact> inputArtifacts = new ArrayList();
1222 readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyServiceVersion.yml");
1224 readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyServiceVersion.yml");
1225 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1226 List<ToscaTemplate> toscas = new LinkedList();
1228 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"9.0");
1229 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1231 for (Artifact inputArtifact : inputArtifacts) {
1232 toscas.add(getToscaModel(inputArtifact));
1234 List<Artifact> resultData = data.getResultData();
1236 Map<String, Model> outputArtifactMap = new HashMap<>();
1237 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1238 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1240 testResourceTosca(toscas.iterator(), outputArtifactMap);
1242 Assert.assertEquals(5, data.getResultData().size());
1244 removeMockArtifact(data.getResultData().iterator());
1246 ArtifactGenerationServiceTest.validateName(data.getResultData());
1249 } catch (Exception e) {
1250 Assert.fail(e.getMessage());
1252 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
1258 public void testArtifactGenerationVerifyResourceVersionFormat() {
1260 List<Artifact> inputArtifacts = new ArrayList();
1261 readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyResourceVersionFormat.yml");
1263 readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyResourceVersionFormat1.yml");
1264 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1266 List<ToscaTemplate> toscas = new LinkedList();
1267 for (Artifact inputArtifact : inputArtifacts) {
1268 toscas.add(getToscaModel(inputArtifact));
1271 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1272 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1273 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
1275 GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_RESOURCE_VERSION_IN_SERVICE_TOSCA,
1276 toscas.get(0).getMetadata().get("UUID")));
1278 inputArtifacts.remove(1);
1280 readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyResourceVersionFormat2.yml");
1281 GenerationData data2 = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG,
1283 Assert.assertEquals(data2.getErrorData().isEmpty(),false);
1284 Assert.assertEquals(data2.getErrorData().get("AAI").get(0),
1286 GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_RESOURCE_VERSION_IN_SERVICE_TOSCA,
1287 toscas.get(0).getMetadata().get("UUID")));
1289 } catch (Exception e) {
1290 Assert.fail(e.getMessage());
1295 public void testArtifactGenerationVerifyMandatoryParameterResourceVersion() {
1297 List<Artifact> inputArtifacts = new ArrayList();
1298 readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyMandatoryParameterResourceVersion.yml");
1300 readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyMandatoryParameterResourceVersion.yml");
1301 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1302 List<ToscaTemplate> toscas = new LinkedList();
1303 for (Artifact inputArtifact : inputArtifacts) {
1304 toscas.add(getToscaModel(inputArtifact));
1307 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1308 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1309 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format(
1310 GeneratorConstants.GENERATOR_AAI_ERROR_NULL_RESOURCE_VERSION_IN_SERVICE_TOSCA,toscas.get(0).getMetadata().get("UUID")));
1311 } catch (Exception e) {
1312 Assert.fail(e.getMessage());
1317 public void testArtifactGenerationWithoutAllottedResource() {
1319 List<Artifact> inputArtifacts = new ArrayList();
1321 readPayloadFromResource(inputArtifacts, "service-ServiceWithAllottedResourceIpmux-template.yml");
1323 readPayloadFromResource(inputArtifacts, "resource-AllottedResource-template_IpMux.yml");
1325 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1326 List<ToscaTemplate> toscas = new LinkedList();
1328 for (Artifact inputArtifact : inputArtifacts) {
1329 toscas.add(getToscaModel(inputArtifact));
1331 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1333 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1334 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format
1335 (GeneratorConstants.GENERATOR_AAI_PROVIDING_SERVICE_MISSING, toscas.get(1).getModelId()));
1337 } catch (Exception e) {
1338 Assert.fail(e.getMessage());
1343 public void testArtifactGenerationAllottedResourceIpmuxWithGroups() {
1345 List<Artifact> inputArtifacts = new ArrayList();
1347 readPayloadFromResource(inputArtifacts, "service-ServiceWithAllottedResourceIpmux-template_WithGroups.yml");
1349 readPayloadFromResource(inputArtifacts, "resource-AllottedResource-template_IpMux_WithGroups.yml");
1351 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1352 List<ToscaTemplate> toscas = new LinkedList();
1354 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1356 for (Artifact inputArtifact : inputArtifacts) {
1357 toscas.add(getToscaModel(inputArtifact));
1359 List<Artifact> resultData = data.getResultData();
1361 Map<String, Model> outputArtifactMap = new HashMap<>();
1362 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1363 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1364 testResourceTosca(toscas.iterator(), outputArtifactMap);
1366 Assert.assertEquals(5, data.getResultData().size());
1368 removeMockArtifact(data.getResultData().iterator());
1370 ArtifactGenerationServiceTest.validateName(data.getResultData());
1372 } catch (Exception e) {
1373 Assert.fail(e.getMessage());
1378 public void testArtifactGenerationAllottedResourceIpmuxSameInvariantDiffVersion() {
1380 List<Artifact> inputArtifacts = new ArrayList();
1382 readPayloadFromResource(inputArtifacts, "service-ServiceWithAllottedResourcesIpMuxSameInvariant-template.yml");
1384 readPayloadFromResource(inputArtifacts, "resource-AllottedResource1SameInvariant-IpMux-template.yml");
1386 readPayloadFromResource(inputArtifacts, "resource-AllottedResource2SameInvariant-IpMux-template.yml");
1388 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1389 List<ToscaTemplate> toscas = new LinkedList();
1391 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1393 for (Artifact inputArtifact : inputArtifacts) {
1394 toscas.add(getToscaModel(inputArtifact));
1396 List<Artifact> resultData = data.getResultData();
1398 Map<String, Model> outputArtifactMap = new HashMap<>();
1399 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1400 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1401 testResourceTosca(toscas.iterator(), outputArtifactMap);
1403 Assert.assertEquals(5, data.getResultData().size());
1405 removeMockArtifact(data.getResultData().iterator());
1407 ArtifactGenerationServiceTest.validateName(data.getResultData());
1410 } catch (Exception e) {
1411 Assert.fail(e.getMessage());
1416 public void testArtifactGenerationAllottedResourceIpmuxSameInvariantSameVersion() {
1418 List<Artifact> inputArtifacts = new ArrayList();
1420 readPayloadFromResource(inputArtifacts, "service-ServiceWithAllottedResourcesIpMuxSameInvariantSameVers-template.yml");
1422 readPayloadFromResource(inputArtifacts, "resource-AllottedResourceSameInvariantSameVers-IpMux-template.yml");
1424 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1425 List<ToscaTemplate> toscas = new LinkedList();
1427 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1429 for (Artifact inputArtifact : inputArtifacts) {
1430 toscas.add(getToscaModel(inputArtifact));
1432 List<Artifact> resultData = data.getResultData();
1434 Map<String, Model> outputArtifactMap = new HashMap<>();
1435 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1436 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1437 testResourceTosca(toscas.iterator(), outputArtifactMap);
1439 Assert.assertEquals(4, data.getResultData().size());
1441 removeMockArtifact(data.getResultData().iterator());
1443 ArtifactGenerationServiceTest.validateName(data.getResultData());
1446 } catch (Exception e) {
1447 Assert.fail(e.getMessage());
1452 public void testArtifactGenerationAllottedResourceWithIpMuxAndTunnelXConn() {
1454 List<Artifact> inputArtifacts = new ArrayList();
1456 readPayloadFromResource(inputArtifacts, "service-Allottedipmux-template.yml");
1458 readPayloadFromResource(inputArtifacts, "resource-IpMuxDemux-template.yml");
1460 readPayloadFromResource(inputArtifacts, "resource-TunnelXconn-template.yml");
1462 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1463 List<ToscaTemplate> toscas = new LinkedList();
1465 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1467 for (Artifact inputArtifact : inputArtifacts) {
1468 toscas.add(getToscaModel(inputArtifact));
1470 List<Artifact> resultData = data.getResultData();
1472 Map<String, Model> outputArtifactMap = new HashMap<>();
1473 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1474 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1475 testResourceTosca(toscas.iterator(), outputArtifactMap);
1477 Assert.assertEquals(5, data.getResultData().size());
1479 removeMockArtifact(data.getResultData().iterator());
1481 ArtifactGenerationServiceTest.validateName(data.getResultData());
1483 } catch (Exception e) {
1484 Assert.fail(e.getMessage());
1489 public void testArtifactGenerationAllottedResourceWithOutProvidingServiceId() {
1491 List<Artifact> inputArtifacts = new ArrayList();
1493 readPayloadFromResource(inputArtifacts, "service-SdWan-template_WithOutDepSerId.yml");
1495 readPayloadFromResource(inputArtifacts, "resource-VhnfNonHeat-template_WithOutDepSerId.yml");
1497 readPayloadFromResource(inputArtifacts, "resource-TunnelXconn-template_WithOutDepSerId.yml");
1499 readPayloadFromResource(inputArtifacts, "resource-ServiceAdmin-template_WithOutDepSerId.yml");
1501 readPayloadFromResource(inputArtifacts, "resource-IpMuxDemux-template_WithOutDepSerId.yml");
1503 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1504 List<ToscaTemplate> toscas = new LinkedList();
1505 for (Artifact inputArtifact : inputArtifacts) {
1506 toscas.add(getToscaModel(inputArtifact));
1509 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1510 Assert.assertEquals(data.getErrorData().isEmpty(),false);
1511 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format
1512 (GeneratorConstants.GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING, toscas.get(2).getModelId()));
1513 } catch (Exception e) {
1514 Assert.fail(e.getMessage());
1519 public void testArtifactGenerationAllottedResourceWithVF() {
1521 List<Artifact> inputArtifacts = new ArrayList();
1523 readPayloadFromResource(inputArtifacts, "service-SdWan-template_AllRes_VF.yml");
1525 readPayloadFromResource(inputArtifacts, "resource-VhnfNonHeat-template_AllRes_VF.yml");
1527 readPayloadFromResource(inputArtifacts, "resource-TunnelXconn-template_AllRes_VF.yml");
1529 readPayloadFromResource(inputArtifacts, "resource-ServiceAdmin-template_AllRes_VF.yml");
1531 readPayloadFromResource(inputArtifacts, "resource-IpMuxDemux-template_AllRes_VF.yml");
1533 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
1534 List<ToscaTemplate> toscas = new LinkedList();
1536 GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
1537 for (Artifact inputArtifact : inputArtifacts) {
1538 toscas.add(getToscaModel(inputArtifact));
1540 List<Artifact> resultData = data.getResultData();
1542 Map<String, Model> outputArtifactMap = new HashMap<>();
1543 ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData);
1544 ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas);
1545 testResourceTosca(toscas.iterator(), outputArtifactMap);
1547 Assert.assertEquals(7, data.getResultData().size());
1549 removeMockArtifact(data.getResultData().iterator());
1551 ArtifactGenerationServiceTest.validateName(data.getResultData());
1552 } catch (Exception e) {
1553 Assert.fail(e.getMessage());
1557 public static void readPayload(List<Artifact> inputArtifacts,InputStream fis, String fileName) throws IOException {
1558 byte[] payload = new byte[fis.available()];
1560 String checksum = GeneratorUtil.checkSum(payload);
1561 byte[] encodedPayload = GeneratorUtil.encode(payload);
1562 Artifact artifact = new Artifact(AAI_ARTIFACT_TYPE, AAI_ARTIFACT_GROUP_TYPE, checksum, encodedPayload);
1563 artifact.setName(fileName);
1564 artifact.setLabel(fileName);
1565 artifact.setDescription(fileName);
1566 inputArtifacts.add(artifact);
1571 * Get the tosca java model from the tosca input artifact
1573 * @param input Input tosca file and its metadata information as {@link Artifact} object
1574 * @return Translated {@link ToscaTemplate tosca} object
1575 * @throws SecurityException
1577 public static ToscaTemplate getToscaModel(Artifact input) {
1578 byte[] decodedInput = GeneratorUtil.decoder(input.getPayload());
1579 String checksum = GeneratorUtil.checkSum(decodedInput);
1580 if (checksum.equals(input.getChecksum())) {
1582 return GeneratorUtil.translateTosca(new String(decodedInput), ToscaTemplate.class);
1583 } catch (Exception e) {
1584 throw new IllegalArgumentException(String.format(
1585 GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_TOSCA, input.getName()));
1588 throw new SecurityException(String.format(
1589 GeneratorConstants.GENERATOR_AAI_ERROR_CHECKSUM_MISMATCH, input.getName()));
1593 public static void removeMockArtifact(Iterator<Artifact> itr) {
1594 while (itr.hasNext()){
1595 if(itr.next().getType().equals("OTHER")){
1601 private void readPayloadFromResource(List<Artifact> inputArtifacts, String fileName) throws IOException {
1603 try (InputStream fis = SampleJUnitTest.class.getResourceAsStream("/" + fileName)) {
1604 readPayload(inputArtifacts, fis, fileName);