2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.generator;
23 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_CONFIGFILE_NOT_FOUND;
24 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND;
25 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_CONFIGLPROP_NOT_FOUND;
26 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING;
27 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_PROVIDING_SERVICE_MISSING;
28 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_ID;
29 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_ERROR_MISSING_SERVICE_VERSION;
30 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_INVALID_SERVICE_VERSION;
32 import org.apache.commons.io.FileUtils;
33 import org.openecomp.sdc.generator.aai.model.Resource;
34 import org.openecomp.sdc.generator.aai.model.Service;
35 import org.openecomp.sdc.generator.aai.model.Widget;
36 import org.openecomp.sdc.generator.aai.tosca.GroupDefinition;
37 import org.openecomp.sdc.generator.aai.tosca.NodeTemplate;
38 import org.openecomp.sdc.generator.aai.tosca.ToscaTemplate;
39 import org.openecomp.sdc.generator.data.AdditionalParams;
40 import org.openecomp.sdc.generator.aai.xml.Model;
41 import org.openecomp.sdc.generator.aai.xml.ModelElement;
42 import org.openecomp.sdc.generator.aai.xml.ModelElements;
43 import org.openecomp.sdc.generator.aai.xml.ModelVer;
44 import org.openecomp.sdc.generator.aai.xml.Relationship;
45 import org.openecomp.sdc.generator.aai.xml.RelationshipData;
46 import org.openecomp.sdc.generator.data.Artifact;
47 import org.openecomp.sdc.generator.data.ArtifactType;
48 import org.openecomp.sdc.generator.data.GenerationData;
49 import org.openecomp.sdc.generator.data.GeneratorConstants;
50 import org.openecomp.sdc.generator.data.GeneratorUtil;
51 import org.openecomp.sdc.generator.data.GroupType;
52 import org.openecomp.sdc.generator.impl.ArtifactGenerationServiceImpl;
53 import org.testng.Assert;
54 import org.testng.annotations.BeforeSuite;
55 import org.testng.annotations.Test;
57 import java.io.ByteArrayInputStream;
59 import java.io.FileInputStream;
60 import java.io.FileOutputStream;
61 import java.io.IOException;
62 import java.io.InputStream;
63 import java.io.OutputStream;
66 import javax.xml.bind.JAXBContext;
67 import javax.xml.bind.JAXBException;
68 import javax.xml.bind.Unmarshaller;
70 @SuppressWarnings("Duplicates")
71 public class ArtifactGenerationServiceTest {
73 private static final String aaiArtifactType = ArtifactType.AAI.name();
74 private static final String aaiArtifactGroupType = GroupType.DEPLOYMENT.name();
75 private static final String generatorConfig = "{\"artifactTypes\": [\"OTHER\",\"AAI\"]}";
76 private final Properties properties = new Properties();
77 private final Map<String, String> additionalParams = new HashMap<>();
78 private final Map<String, String> resourcesVersion = new HashMap<>();
81 public void loadProperties() throws Exception{
82 loadConfigFromClasspath(properties);
83 additionalParams.put(AdditionalParams.ServiceVersion.getName(), "1.0");
87 public void testArtifactGeneration() {
88 // Sunny day scenario service with VF anf vfmodule
91 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
92 List<ToscaTemplate> toscas = new LinkedList<>();
93 String aaiResourceBasePaths = "aai/";
94 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
95 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
96 if (data.getErrorData().isEmpty()) {
97 for (Artifact inputArtifact : inputArtifacts) {
98 toscas.add(getToscaModel(inputArtifact));
100 List<Artifact> resultData = data.getResultData();
102 /*for( int i = 0 ; i < resultData.size() ; i++) {
103 Artifact artifact = resultData.get(i);
104 String fileName = artifact.getName();
105 while(fileName.contains(":")){
106 fileName = fileName.replace(":","");
108 File targetFile =new File("src/test/resources/"+fileName);
109 OutputStream outStream = new FileOutputStream(targetFile);
110 outStream.write(Base64.getDecoder().decode(artifact.getPayload()));
113 Assert.assertEquals(resultData.size(),5); // 1-service,1-VF-resource,1-vfmodule and 2
115 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
116 testServiceTosca(toscas, outputArtifactMap);
117 testResourceTosca(toscas.iterator(), outputArtifactMap);
119 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
122 } catch (Exception e) {
123 Assert.fail(e.getMessage());
128 public void testWidgetinServiceTosca() {
129 // Sunny day scenario service with VF and extra widget like CP anf vf has vfmodule without
132 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
133 List<ToscaTemplate> toscas = new LinkedList<>();
134 String aaiResourceBasePaths = "testWidgetinServiceTosca/";
135 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
136 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
137 if (data.getErrorData().isEmpty()) {
138 for (Artifact inputArtifact : inputArtifacts) {
139 toscas.add(getToscaModel(inputArtifact));
141 List<Artifact> resultData = data.getResultData();
142 Assert.assertEquals(resultData.size(),5); // 1-service,1-VF-resource,1-vfmodule and 2
144 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
145 testServiceTosca(toscas, outputArtifactMap);
146 testResourceTosca(toscas.iterator(), outputArtifactMap);
148 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
151 } catch (Exception e) {
152 Assert.fail(e.getMessage());
157 public void testSameVLdifferentVersion() {
158 // Sunny day scenario service with VF and extra widget like CP anf vf has vfmodule without
161 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
162 List<ToscaTemplate> toscas = new LinkedList<>();
163 String aaiResourceBasePaths = "testSameVLdifferentVersion/";
164 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
165 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
166 if (data.getErrorData().isEmpty()) {
167 for (Artifact inputArtifact : inputArtifacts) {
168 toscas.add(getToscaModel(inputArtifact));
170 List<Artifact> resultData = data.getResultData();
171 Assert.assertEquals(resultData.size(),8);
173 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
174 testServiceTosca(toscas, outputArtifactMap);
175 testResourceTosca(toscas.iterator(), outputArtifactMap);
177 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
180 } catch (Exception e) {
181 Assert.fail(e.getMessage());
186 public void testArtifactGenerationAllottedResourceAndL3Network() {
187 // Sunny day scenario service with allotted resource and L3-network
189 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
190 List<ToscaTemplate> toscas = new LinkedList<>();
191 String aaiResourceBasePaths = "aai2/";
192 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
193 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
194 if (data.getErrorData().isEmpty()) {
195 for (Artifact inputArtifact : inputArtifacts) {
196 toscas.add(getToscaModel(inputArtifact));
198 List<Artifact> resultData = data.getResultData();
200 Assert.assertEquals(resultData.size(),5);
203 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
204 testServiceTosca(toscas, outputArtifactMap);
205 testResourceTosca(toscas.iterator(), outputArtifactMap);
207 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
210 } catch (Exception e) {
211 Assert.fail(e.getMessage());
215 @Test(dependsOnMethods = {"testArtifactGeneration"})
216 public void testWhenMissingTosca() {
218 //Missing Service tosca test case
219 String aaiResourceBasePaths = "testArtifactGeneration2/";
220 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
221 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
222 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
223 Assert.assertEquals(data.getErrorData().get("AAI").get(0),"Service tosca missing from list of input artifacts");
224 } catch (Exception e) {
225 Assert.fail(e.getMessage());
229 @Test(dependsOnMethods = {"testWhenMissingTosca"})
230 public void testWhenInvaildConfig() {
232 //Invalid config test case
233 String generatorConfig1 = "{\"artifactTypes\": [\"ABC\"]}";
234 String aaiResourceBasePaths = "testArtifactGeneration2/";
235 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
236 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
237 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig1, additionalParams);
238 Assert.assertEquals(data.getErrorData().get("ARTIFACT_GENERATOR_INVOCATION_ERROR").get(0),"Invalid Client Configuration");
239 } catch (Exception e) {
240 Assert.fail(e.getMessage());
244 @Test(dependsOnMethods = {"testArtifactGeneration"})
245 public void testWhenOnlyServToscaNoResTosca() {
247 //Testing only service tosca no resource Tosca
248 String aaiResourceBasePaths = "testArtifactGeneration4/";
249 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
250 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
251 List<ToscaTemplate> toscas = new LinkedList<>();
252 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
253 List<Artifact> resultData = data.getResultData();
254 if (data.getErrorData().isEmpty()) {
255 for (Artifact inputArtifact : inputArtifacts) {
256 toscas.add(getToscaModel(inputArtifact));
259 Assert.assertEquals(resultData.size(),3); // 1-service and 2-Others
260 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
261 testServiceTosca(toscas, outputArtifactMap);
262 } catch (Exception e) {
263 Assert.fail(e.getMessage());
267 @Test(dependsOnMethods = {"testArtifactGeneration"})
268 public void testWhenInvaildYaml() {
270 //Invalid Yaml file test case
271 String aaiResourceBasePaths = "testArtifactGeneration5/";
272 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
273 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
274 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
275 Assert.assertEquals(data.getErrorData().get("AAI").get(0),"Invalid format for Tosca YML : " + inputArtifacts.get(0).getName());
276 } catch (Exception e) {
277 Assert.fail(e.getMessage());
281 @Test(dependsOnMethods = {"testArtifactGeneration"})
282 public void testWhenExtraResToscaNotPartOfServ() {
284 // Valid scenario with extra resource tosca which is not part of Service
285 String aaiResourceBasePaths = "testArtifactGeneration6/";
286 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
287 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
288 List<ToscaTemplate> toscas = new LinkedList<>();
289 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
290 List<Artifact> resultData = data.getResultData();
291 if (data.getErrorData().isEmpty()) {
292 for (Artifact inputArtifact : inputArtifacts) {
293 toscas.add(getToscaModel(inputArtifact));
296 Assert.assertEquals(resultData.size(),3); // 1-service and 2 Others
297 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
298 testServiceTosca(toscas, outputArtifactMap);
299 } catch (Exception e) {
300 Assert.fail(e.getMessage());
306 public void testWhenInvUuIdAttrMissing() {
308 // mandatory attribute <invariantUUID> missing
309 String aaiResourceBasePaths = "testArtifactGeneration8/";
310 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
311 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
312 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
314 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <invariantUUID> missing in Artifact: <" +
315 inputArtifacts.get(0).getName() + ">");
317 } catch (Exception e) {
318 Assert.fail(e.getMessage());
323 public void testErrorWhenInvalidInvId() {
325 //Invariant Id in service tosca of length not 36
326 String aaiResourceBasePaths = "testErrorWhenInvalidInvId/";
327 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
328 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
329 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
331 data.getErrorData().get("AAI").get(0),String.format(GENERATOR_AAI_ERROR_INVALID_ID,
332 "invariantUUID",inputArtifacts.get(0).getName()));
334 } catch (Exception e) {
335 Assert.fail(e.getMessage());
340 public void testWhenUuIdAttrMissing() {
342 //mandatory attribute <UUID> missing
343 String aaiResourceBasePaths = "testArtifactGeneration9/";
344 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
345 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
346 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
348 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <UUID> missing in Artifact: <" +
349 inputArtifacts.get(0).getName() + ">");
351 } catch (Exception e) {
352 Assert.fail(e.getMessage());
357 public void testErrorWhenInvalidUuId() {
359 //UUID Id in service tosca of length not 36
360 String aaiResourceBasePaths = "testErrorWhenInvalidUuId/";
361 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
362 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
363 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
365 data.getErrorData().get("AAI").get(0),String.format(GENERATOR_AAI_ERROR_INVALID_ID,
366 "UUID",inputArtifacts.get(0).getName()));
368 } catch (Exception e) {
369 Assert.fail(e.getMessage());
374 public void testWhenNameAttrMissing() {
376 //mandatory attribute <name> missing
377 String aaiResourceBasePaths = "testArtifactGeneration10/";
378 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
379 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
380 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
382 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <name> missing in Artifact: <" +
383 inputArtifacts.get(0).getName() + ">");
385 } catch (Exception e) {
386 Assert.fail(e.getMessage());
390 @Test //(dependsOnMethods = {"testArtifactGeneration"})
391 public void testWhenVfModInvUuIdAttrMissing() {
393 //mandatory attribute <vfModuleModelInvariantUUID> missing
394 List<Artifact> inputArtifacts = new ArrayList<>();
395 readPayloadFromResource(inputArtifacts, "service_vmme_template_ModInvUUID.yml");
396 readPayloadFromResource(inputArtifacts, "vf_vmme_template_ModInvUUID.yml");
397 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
398 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
400 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <vfModuleModelInvariantUUID> missing in Artifact: <" +
401 inputArtifacts.get(1).getName() + ">");
403 } catch (Exception e) {
404 Assert.fail(e.getMessage());
408 public static void readPayload(List<Artifact> inputArtifacts, InputStream fis, String fileName) throws
410 byte[] payload = new byte[fis.available()];
412 String checksum = GeneratorUtil.checkSum(payload);
413 byte[] encodedPayload = GeneratorUtil.encode(payload);
414 Artifact artifact = new Artifact(aaiArtifactType, aaiArtifactGroupType, checksum, encodedPayload);
415 artifact.setName(fileName);
416 artifact.setLabel(fileName);
417 artifact.setDescription(fileName);
418 artifact.setVersion("1.0");
419 System.out.println(artifact.getName());
420 inputArtifacts.add(artifact);
424 public void testWhenInvalidVfModInvUuIdAttr() {
426 //invalid id since not of length 36 for <vfModuleModelInvariantUUID>
427 List<Artifact> inputArtifacts = new ArrayList<>();
428 readPayloadFromResource(inputArtifacts, "service_vmme_template_InvalidVfModInvUuIdAttr.yml");
430 readPayloadFromResource(inputArtifacts, "vf_vmme_template_InvalidVfModInvUuIdAttr.yml");
431 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
432 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
434 data.getErrorData().get("AAI").get(0),String.format(GENERATOR_AAI_ERROR_INVALID_ID,
435 "vfModuleModelInvariantUUID", inputArtifacts.get(1).getName() ));
437 } catch (Exception e) {
438 Assert.fail(e.getMessage());
442 @Test //(dependsOnMethods = {"testArtifactGeneration"})
443 public void testWhenVfModNameAttrMissing() {
445 //mandatory attribute <vfModuleModelName> missing
446 List<Artifact> inputArtifacts = new ArrayList<>();
447 readPayloadFromResource(inputArtifacts, "service_vmme_template_ModelName.yml");
449 readPayloadFromResource(inputArtifacts, "vf_vmme_template_ModelName.yml");
450 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
451 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
453 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <vfModuleModelName> missing in Artifact: <" +
454 inputArtifacts.get(1).getName() + ">");
456 } catch (Exception e) {
457 Assert.fail(e.getMessage());
461 /*public static void readPayload(List<Artifact> inputArtifacts,InputStream fis, String fileName)
464 byte[] payload = new byte[fis.available()];
466 String checksum = GeneratorUtil.checkSum(payload);
467 byte[] encodedPayload = GeneratorUtil.encode(payload);
468 Artifact artifact = new Artifact(aaiArtifactType, aaiArtifactGroupType, checksum, encodedPayload);
469 artifact.setName(fileName);
470 artifact.setLabel(fileName);
471 artifact.setDescription(fileName);
472 artifact.setVersion("1.0");
473 System.out.println(artifact.getName());
474 inputArtifacts.add(artifact);
477 @Test //(dependsOnMethods = {"testArtifactGeneration"})
478 public void testWhenVfModUuIdAttrMissing() {
480 //mandatory attribute <vfModuleModelUUID> missing in Artifact
481 List<Artifact> inputArtifacts = new ArrayList<>();
482 readPayloadFromResource(inputArtifacts, "service_vmme_template_ModelUUID.yml");
484 readPayloadFromResource(inputArtifacts, "vf_vmme_template_ModelUUID.yml");
485 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
486 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
488 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory " +
489 "attribute <vfModuleModelUUID> missing in Artifact: <" +
490 inputArtifacts.get(1).getName() + ">");
492 } catch (Exception e) {
493 Assert.fail(e.getMessage());
498 public void testWhenInvalidVfModUuIdAttr() {
500 //invalid id since not of length 36 for <vfModuleModelUUID>
501 List<Artifact> inputArtifacts = new ArrayList<>();
502 readPayloadFromResource(inputArtifacts, "service_vmme_template_InvalidVfModUuIdAttr.yml");
504 readPayloadFromResource(inputArtifacts, "vf_vmme_template_InvalidVfModUuIdAttr.yml");
505 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
506 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
508 data.getErrorData().get("AAI").get(0),String.format(GENERATOR_AAI_ERROR_INVALID_ID,
509 "vfModuleModelUUID", inputArtifacts.get(1).getName() ));
511 } catch (Exception e) {
512 Assert.fail(e.getMessage());
516 @Test //(dependsOnMethods = {"testArtifactGeneration"})
517 public void testWhenVfModVersionAttrMissing() {
519 //mandatory attribute <vfModuleModelVersion> missing
520 List<Artifact> inputArtifacts = new ArrayList<>();
521 readPayloadFromResource(inputArtifacts, "service_vmme_template_ModelVersion.yml");
523 readPayloadFromResource(inputArtifacts, "vf_vmme_template_ModelVersion.yml");
524 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
525 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
527 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <vfModuleModelVersion> missing in Artifact: <" +
528 inputArtifacts.get(1).getName() + ">");
530 } catch (Exception e) {
531 Assert.fail(e.getMessage());
536 public void testErrorWhenNoSystemPropConfigured() throws Exception {
537 String configLoc = System.getProperty("artifactgenerator.config");
539 System.clearProperty("artifactgenerator.config");
540 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
541 String aaiResourceBasePaths = "aai/";
542 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
543 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
544 Assert.assertEquals(false,data.getErrorData().isEmpty());
545 Assert.assertEquals(data.getErrorData().
546 get("AAI").get(0),GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND);
547 } catch (Exception e) {
548 Assert.fail(e.getMessage());
551 System.setProperty("artifactgenerator.config",configLoc);
556 public void testErrorWhenNoWidgetInConfig() throws Exception {
557 String configLoc = System.getProperty("artifactgenerator.config");
558 final File configFile = new File(configLoc);
559 String configDir = configLoc.substring(0, configLoc.lastIndexOf(File.separator));
560 final File tempFile = new File(configDir + File.separator + "temp.properties");
562 //copy orignal Artifact-Generator.properties to temp.properties for backup
563 FileUtils.copyFile(configFile, tempFile);
565 String serviceWidgetName = ArtifactType.AAI.name()+".model-version-id."+Widget.getWidget
566 (Widget.Type.SERVICE)
568 String assertMsg = ArtifactType.AAI.name() + ".model-version-id." +Widget.getWidget
569 (Widget.Type.SERVICE).getName();
571 //Remove property from Artifact-Generator.properties
572 properties.remove(serviceWidgetName);
573 try (OutputStream fos = new FileOutputStream(new File(configLoc))) {
574 properties.store(fos,null);
577 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
578 String aaiResourceBasePaths = "aai/";
579 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
580 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
581 Assert.assertEquals(false,data.getErrorData().isEmpty());
582 String errMsg = String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,assertMsg);
583 Assert.assertEquals(data.getErrorData().get("AAI").get(0),errMsg);
584 } catch (Exception e) {
585 Assert.fail(e.getMessage());
588 if(tempFile.exists()){
590 FileUtils.copyFile(tempFile, configFile);
591 loadConfigFromClasspath(properties);
598 public void testErrorWhenNoFileAtConfigLocation() throws Exception {
599 String configLoc = System.getProperty("artifactgenerator.config");
601 System.setProperty("artifactgenerator.config",configLoc + File.separator + "testErrorWhenNoFileAtConfigLocation");
602 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
603 String aaiResourceBasePaths = "aai/";
604 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
605 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
606 Assert.assertEquals(data.getErrorData().isEmpty(),false);
607 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format(GENERATOR_AAI_CONFIGFILE_NOT_FOUND,System.getProperty
608 ("artifactgenerator.config")));
609 } catch (Exception e) {
610 Assert.fail(e.getMessage());
613 System.setProperty("artifactgenerator.config",configLoc);
618 public void testErrorWhenNoServiceVersion() {
619 // scenario service with VF anf vfmodule but no service version in additional parameter
621 additionalParams.clear();
622 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
623 String aaiResourceBasePaths = "aai/";
624 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
625 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
626 Assert.assertEquals(data.getErrorData().isEmpty(),false);
627 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
628 GENERATOR_AAI_ERROR_MISSING_SERVICE_VERSION);
629 } catch (Exception e) {
630 Assert.fail(e.getMessage());
633 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
638 public void testArtifactGenerationWithServiceVersion() {
639 // Sunny day scenario service with VF anf vfmodule and service version as adiitional parameter
641 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"9.0");
642 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
643 List<ToscaTemplate> toscas = new LinkedList<>();
644 String aaiResourceBasePaths = "aai/";
645 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
646 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
647 if (data.getErrorData().isEmpty()) {
648 for (Artifact inputArtifact : inputArtifacts) {
649 toscas.add(getToscaModel(inputArtifact));
651 List<Artifact> resultData = data.getResultData();
653 /*for( int i = 0 ; i < resultData.size() ; i++) {
654 Artifact artifact = resultData.get(i);
655 String fileName = artifact.getName();
656 while(fileName.contains(":")){
657 fileName = fileName.replace(":","");
659 File targetFile =new File("src/test/resources/"+fileName);
660 OutputStream outStream = new FileOutputStream(targetFile);
661 outStream.write(Base64.getDecoder().decode(artifact.getPayload()));
664 Assert.assertEquals(resultData.size(),5); // 1-service,1-VF-resource,1-vfmodule and 2
666 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
667 testServiceTosca(toscas, outputArtifactMap);
668 testResourceTosca(toscas.iterator(), outputArtifactMap);
670 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
673 } catch (Exception e) {
674 Assert.fail(e.getMessage());
677 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
682 public void testErrorWhenInvalidServiceVersion() {
683 // scenario service with VF anf vfmodule but invalid service version in additional parameter
685 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
686 String aaiResourceBasePaths = "aai/";
687 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
689 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1");
690 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
691 Assert.assertEquals(data.getErrorData().isEmpty(),false);
692 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
693 GENERATOR_AAI_INVALID_SERVICE_VERSION);
695 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.1");
696 data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
697 Assert.assertEquals(data.getErrorData().isEmpty(),false);
698 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
699 GENERATOR_AAI_INVALID_SERVICE_VERSION);
701 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.0");
702 data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
703 Assert.assertEquals(data.getErrorData().isEmpty(),false);
704 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
705 GENERATOR_AAI_INVALID_SERVICE_VERSION);
707 } catch (Exception e) {
708 Assert.fail(e.getMessage());
711 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
716 public void testMissingResourceTosca() {
718 //Service with resource but seperate resource tosca not coming as input.
719 String aaiResourceBasePaths = "missingResourceTosca/";
720 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
721 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
722 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
723 Assert.assertEquals(data.getErrorData().get("AAI").get(0),"Cannot generate artifacts. Resource Tosca missing for resource with UUID: <b020ed1e-4bc7-4fc0-ba7e-cc7af6da7ffc>");
724 } catch (Exception e) {
725 Assert.fail(e.getMessage());
729 public void testMissingVLTosca() {
731 //Service with VL but seperate VL tosca not coming as input artifact.
732 String aaiResourceBasePaths = "missingVLTosca/";
733 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
734 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
735 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
736 Assert.assertEquals(data.getErrorData().get("AAI").get(0),"Cannot generate artifacts. Resource Tosca missing for resource with UUID: <3f8fa4d2-2b86-4b36-bbc8-ffb8f9f57468>");
737 } catch (Exception e) {
738 Assert.fail(e.getMessage());
743 public void testErrorWhenNoResourceVersion() {
744 // scenario service with VF but missing resource version in service tosca
746 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
747 String aaiResourceBasePaths = "testErrorWhenNoResourceVersion/";
748 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
749 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
750 Assert.assertEquals(data.getErrorData().isEmpty(),false);
751 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
752 "Invalid Service definition mandatory attribute version missing for resource with UUID: <b020ed1e-4bc7-4fc0-ba7e-cc7af6da7ffc>");
753 } catch (Exception e) {
754 Assert.fail(e.getMessage());
759 public void testErrorWhenInvalidResourceVersion1() {
760 // scenario service with VF but invalid resource version 0.0 in service tosca
762 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
763 String aaiResourceBasePaths = "testErrorWhenInvalidResourceVersion1/";
764 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
765 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
766 Assert.assertEquals(data.getErrorData().isEmpty(),false);
767 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
768 "Cannot generate artifacts. Invalid Resource version in Service tosca for resource with UUID: <b020ed1e-4bc7-4fc0-ba7e-cc7af6da7ffc>");
769 } catch (Exception e) {
770 Assert.fail(e.getMessage());
775 public void testErrorWhenInvalidResourceVersion2() {
776 // scenario service with VF but invalid resource version 1 in service tosca
778 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
779 String aaiResourceBasePaths = "testErrorWhenInvalidResourceVersion2/";
780 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
781 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
782 Assert.assertEquals(data.getErrorData().isEmpty(),false);
783 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
784 "Cannot generate artifacts. Invalid Resource version in Service tosca for resource with UUID: <b020ed1e-4bc7-4fc0-ba7e-cc7af6da7ffc>");
785 } catch (Exception e) {
786 Assert.fail(e.getMessage());
791 public void testArtifactGenerationAllottedResourceWithIpMuxAndTunnelXConn() {
793 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
794 List<ToscaTemplate> toscas = new LinkedList<>();
795 String aaiResourceBasePaths = "testArtifactGeneration15/";
796 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
797 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
798 if (data.getErrorData().isEmpty()) {
799 for (Artifact inputArtifact : inputArtifacts) {
800 toscas.add(getToscaModel(inputArtifact));
802 List<Artifact> resultData = data.getResultData();
804 Assert.assertEquals(resultData.size(),5);
805 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
806 testServiceTosca(toscas, outputArtifactMap);
807 testResourceTosca(toscas.iterator(), outputArtifactMap);
809 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
812 } catch (Exception e) {
813 Assert.fail(e.getMessage());
818 public void testErrorWhenAllottedResourceWithOutProvidingServiceId() {
820 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
821 String aaiResourceBasePaths = "testErrorWhenAllottedResourceWithOutDependingServiceId/";
822 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
823 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
824 Assert.assertEquals(data.getErrorData().isEmpty(),false);
825 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format
826 (GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING, "707b2850-e830-4b00-9902-879f44ac05a4"));
827 } catch (Exception e) {
828 Assert.fail(e.getMessage());
833 public void testArtifactGenerationWithoutAllottedResource() {
835 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
836 String aaiResourceBasePaths = "testArtifactGeneration16/";
837 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
838 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
839 Assert.assertEquals(data.getErrorData().isEmpty(),false);
840 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format
841 (GENERATOR_AAI_PROVIDING_SERVICE_MISSING, "a54a5235-b69d-4f8a-838b-d011e6783fa5"));
842 } catch (Exception e) {
843 Assert.fail(e.getMessage());
848 public void testArtifactGenerationAllottedResourceIpmuxSameInvariantDiffVersion() {
850 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
851 List<ToscaTemplate> toscas = new LinkedList<>();
852 String aaiResourceBasePaths = "testArtifactGeneration17/";
853 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
854 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
855 if (data.getErrorData().isEmpty()) {
856 for (Artifact inputArtifact : inputArtifacts) {
857 toscas.add(getToscaModel(inputArtifact));
859 List<Artifact> resultData = data.getResultData();
861 Assert.assertEquals(resultData.size(),5);
862 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
863 testServiceTosca(toscas, outputArtifactMap);
864 testResourceTosca(toscas.iterator(), outputArtifactMap);
866 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
869 } catch (Exception e) {
870 Assert.fail(e.getMessage());
875 public void testArtifactGenerationAllottedResourceIpmuxSameInvariantSameVersion() {
877 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
878 List<ToscaTemplate> toscas = new LinkedList<>();
879 String aaiResourceBasePaths = "testArtifactGeneration18/";
880 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
881 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
882 if (data.getErrorData().isEmpty()) {
883 for (Artifact inputArtifact : inputArtifacts) {
884 toscas.add(getToscaModel(inputArtifact));
886 List<Artifact> resultData = data.getResultData();
889 Assert.assertEquals(resultData.size(),4);
890 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
891 testServiceTosca(toscas, outputArtifactMap);
892 testResourceTosca(toscas.iterator(), outputArtifactMap);
894 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
897 } catch (Exception e) {
898 Assert.fail(e.getMessage());
903 public void testArtifactGenerationAllottedResourceIpmuxWithGroups() {
905 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
906 List<ToscaTemplate> toscas = new LinkedList<>();
907 String aaiResourceBasePaths = "testAllotedResourceWithDependingSerWithGroups/";
908 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
909 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
910 if (data.getErrorData().isEmpty()) {
911 for (Artifact inputArtifact : inputArtifacts) {
912 toscas.add(getToscaModel(inputArtifact));
914 List<Artifact> resultData = data.getResultData();
916 Assert.assertEquals(resultData.size(),5);
917 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
918 testServiceTosca(toscas, outputArtifactMap);
919 testResourceTosca(toscas.iterator(), outputArtifactMap);
921 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
924 } catch (Exception e) {
925 Assert.fail(e.getMessage());
930 public void testArtifactGenerationAllottedResourceWithVF() {
932 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
933 List<ToscaTemplate> toscas = new LinkedList<>();
934 String aaiResourceBasePaths = "testArtifactGenerationAllottedResourceWithVF/";
935 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
936 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
937 if (data.getErrorData().isEmpty()) {
938 for (Artifact inputArtifact : inputArtifacts) {
939 toscas.add(getToscaModel(inputArtifact));
941 List<Artifact> resultData = data.getResultData();
943 Assert.assertEquals(resultData.size(),7);
944 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
945 testServiceTosca(toscas, outputArtifactMap);
946 testResourceTosca(toscas.iterator(), outputArtifactMap);
948 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
951 } catch (Exception e) {
952 Assert.fail(e.getMessage());
958 public void testServiceTosca(List<ToscaTemplate> toscas, Map<String, Model> outputArtifactMap) {
960 ToscaTemplate serviceTosca = getServiceTosca(toscas);
961 if (serviceTosca == null) {
962 Assert.fail("Service Tosca not found");
964 serviceTosca.getMetadata().put("version", "1.0");
965 Service service = new Service();
966 service.populateModelIdentificationInformation(serviceTosca.getMetadata());
967 String serviceNameVersionId = service.getModelNameVersionId();
968 Model serviceAAIModel = getAAIModelByNameVersionId(serviceNameVersionId, outputArtifactMap);
969 validateServiceModelMetadata(service, serviceAAIModel);
970 //Validate Service instance base widget
971 ModelVer modelVersion = serviceAAIModel.getModelVers().getModelVer().get(0);
973 List<ModelElement> matchedServiceBaseWidgetElements =
974 getModelElementbyRelationshipValue( modelVersion.getModelElements(),
975 Widget.getWidget(Widget.Type.SERVICE).getId());
976 validateMatchedModelElementsInService(matchedServiceBaseWidgetElements,
977 Widget.getWidget(Widget.Type.SERVICE).getName());
979 validateWidgetIds(matchedServiceBaseWidgetElements, Widget.getWidget(Widget.Type.SERVICE).getName(),
980 Widget.getWidget(Widget.Type.SERVICE).getWidgetId());
982 ModelElements baseServiceWidgetModelElements =
983 matchedServiceBaseWidgetElements.get(0).getModelElements();
986 Map<String, String> nodeTemplateIdTypeStore = getNodeTemplateTypeStore(serviceTosca);
987 if (nodeTemplateIdTypeStore != null) {
988 for (String key : nodeTemplateIdTypeStore.keySet()) {
989 if (nodeTemplateIdTypeStore.get(key).contains("org.openecomp.resource.vf")) {
990 List<ModelElement> matchedResourceElements =
991 getModelElementbyRelationshipValue(baseServiceWidgetModelElements, key);
992 if (nodeTemplateIdTypeStore.get(key).contains("org.openecomp.resource.vf.allottedResource")){
993 validateMatchedModelElementsInService(matchedResourceElements,
994 Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getName());
996 validateMatchedModelElementsInService(matchedResourceElements,
997 Widget.getWidget(Widget.Type.VF).getName());
1000 //Validate uuid and invariantuuid are populated in model-ver.model-version-id and model.model-invariant-id
1001 Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList()
1002 .getRelationship().get(0)
1003 .getRelationshipData().get(0).getRelationshipValue(),key);
1005 Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList().getRelationship().get(0)
1006 .getRelationshipData().get(1).getRelationshipValue(), nodeTemplateIdTypeStore
1007 .get(key+"-INV_UID"));
1008 } else if(nodeTemplateIdTypeStore.get(key).contains("org.openecomp.resource.vl")){
1009 //validate l3-network in service tosca
1010 List<ModelElement> matchedResourceElements =
1011 getModelElementbyRelationshipValue(baseServiceWidgetModelElements, key);
1012 validateMatchedModelElementsInService(matchedResourceElements,
1013 Widget.getWidget(Widget.Type.L3_NET).getName());
1014 //Validate uuid and invariantuuid are populated in model-ver.model-version-id and model.model-invariant-id
1015 Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList()
1016 .getRelationship().get(0)
1017 .getRelationshipData().get(0).getRelationshipValue(),key);
1019 Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList().getRelationship().get(0)
1020 .getRelationshipData().get(1).getRelationshipValue(), nodeTemplateIdTypeStore
1021 .get(key+"-INV_UID"));
1026 System.out.println();
1029 } catch (IllegalArgumentException e) {
1030 Assert.fail(e.getMessage()); //Can come while populating metadata
1034 private void validateWidgetIds(List<ModelElement> matchedServiceBaseWidgetElements,
1035 String widgetName, String widgetInvUuId) {
1036 Assert.assertEquals(matchedServiceBaseWidgetElements.get(0).getRelationshipList().getRelationship().get(0)
1037 .getRelationshipData().get(0).getRelationshipValue(), properties.getProperty(ArtifactType.AAI.name()
1038 + ".model-version-id."+ widgetName));
1040 Assert.assertEquals(matchedServiceBaseWidgetElements.get(0).getRelationshipList().getRelationship().get(0)
1041 .getRelationshipData().get(1).getRelationshipValue(), widgetInvUuId);
1045 public void testL3NetworkResourceTosca(Map<String, Model> outputArtifactMap , ToscaTemplate
1048 if (resourceTosca != null) {
1049 Resource resource = new Resource();
1050 resource.populateModelIdentificationInformation(resourceTosca.getMetadata());
1051 String resourceNameVersionId = resource.getModelNameVersionId();
1052 Model resourceAAIModel =
1053 getAAIModelByNameVersionId(resourceNameVersionId, outputArtifactMap);
1054 if (resourceAAIModel != null) {
1055 validateResourceModelMetadata(resource, resourceAAIModel);
1056 //Validate Resource instance base widget
1058 ModelVer modelVersion = resourceAAIModel.getModelVers().getModelVer().get(0);
1060 List<ModelElement> matchedVFBaseWidgetElements =
1061 getModelElementbyRelationshipValue(modelVersion.getModelElements(),
1062 Widget.getWidget(Widget.Type.L3_NET).getId());
1063 validateMatchedModelElementsInService(matchedVFBaseWidgetElements,
1064 Widget.getWidget(Widget.Type.L3_NET).getName());
1066 validateWidgetIds(matchedVFBaseWidgetElements, Widget.getWidget(Widget.Type.L3_NET).getName(),
1067 Widget.getWidget(Widget.Type.L3_NET).getWidgetId());
1070 System.out.println("Resource mapping not found for " + resourceNameVersionId);
1074 }catch (IllegalArgumentException e) {
1075 Assert.fail(e.getMessage()); //Can come while populating metadata
1080 public void testAllottedResourceTosca(Map<String, Model> outputArtifactMap , ToscaTemplate
1083 if (resourceTosca != null) {
1084 Resource resource = new Resource();
1085 resource.populateModelIdentificationInformation(resourceTosca.getMetadata());
1086 String resourceNameVersionId = resource.getModelNameVersionId();
1087 Model resourceAAIModel =
1088 getAAIModelByNameVersionId(resourceNameVersionId, outputArtifactMap);
1089 if (resourceAAIModel != null) {
1090 validateResourceModelMetadata(resource, resourceAAIModel);
1091 //Validate Resource instance base widget
1093 ModelVer modelVersion = resourceAAIModel.getModelVers().getModelVer().get(0);
1095 List<ModelElement> matchedVFBaseWidgetElements =
1096 getModelElementbyRelationshipValue(modelVersion.getModelElements(),
1097 Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getId());
1098 validateMatchedModelElementsInService(matchedVFBaseWidgetElements,
1099 Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getName());
1101 validateWidgetIds(matchedVFBaseWidgetElements, Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getName(),
1102 Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getWidgetId());
1104 Map<String, Object> dependingServiceDetails = getProvidingServiceDetails(resourceTosca);
1106 ModelElements containedModelElements = modelVersion.getModelElements().getModelElement().
1107 get(0).getModelElements();
1108 Assert.assertEquals( containedModelElements.getModelElement().get(0).getRelationshipList()
1109 .getRelationship().get(0).getRelationshipData().get(0).getRelationshipValue(),
1110 dependingServiceDetails.get("providing_service_uuid"));
1112 Assert.assertEquals(containedModelElements.getModelElement().get(0).getRelationshipList()
1113 .getRelationship().get(0).getRelationshipData().get(1).getRelationshipValue(),
1114 dependingServiceDetails.get("providing_service_invariant_uuid"));
1116 if("Allotted Resource".equals(resourceTosca.getMetadata().get("category")) &&
1117 "Tunnel XConnect".equals(resourceTosca.getMetadata().get("subcategory"))) {
1119 List<ModelElement> matchedTunnelXConnectWidgetElements =
1120 getModelElementbyRelationshipValue(containedModelElements,
1121 Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getId());
1122 validateMatchedModelElementsInService(matchedTunnelXConnectWidgetElements,
1123 Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getName());
1125 validateWidgetIds(matchedTunnelXConnectWidgetElements, Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getName(),
1126 Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getWidgetId());
1130 System.out.println("Resource mapping not found for " + resourceNameVersionId);
1134 }catch (IllegalArgumentException e) {
1135 Assert.fail(e.getMessage()); //Can come while populating metadata
1140 public Map<String, Object> getProvidingServiceDetails(ToscaTemplate resourceTemplate) {
1141 Set<String> keys = resourceTemplate.getTopology_template().getNode_templates().keySet();
1143 Map<String, Object> nodeProperties =null;
1144 for(String key : keys) {
1145 NodeTemplate node = resourceTemplate.getTopology_template().getNode_templates().get(key);
1146 if(node.getType().equals("org.openecomp.resource.vfc.AllottedResource")) {
1147 nodeProperties = node.getProperties();
1151 return nodeProperties;
1154 public void testVfTosca(Map<String, Model> outputArtifactMap , ToscaTemplate resourceTosca) {
1156 //ToscaTemplate resourceTosca = getResourceTosca(toscas);
1157 //resourceTosca.getTopology_template().getGroups().
1158 if (resourceTosca != null) {
1159 Resource resource = new Resource();
1160 resource.populateModelIdentificationInformation(resourceTosca.getMetadata());
1161 String resourceNameVersionId = resource.getModelNameVersionId();
1162 Model resourceAAIModel =
1163 getAAIModelByNameVersionId(resourceNameVersionId, outputArtifactMap);
1164 if (resourceAAIModel != null) {
1165 validateResourceModelMetadata(resource, resourceAAIModel);
1166 //Validate Resource instance base widget
1168 ModelVer modelVersion = resourceAAIModel.getModelVers().getModelVer().get(0);
1170 List<ModelElement> matchedVFBaseWidgetElements =
1171 getModelElementbyRelationshipValue(modelVersion.getModelElements(),
1172 Widget.getWidget(Widget.Type.VF).getId());
1173 validateMatchedModelElementsInService(matchedVFBaseWidgetElements,
1174 Widget.getWidget(Widget.Type.VF).getName());
1176 validateWidgetIds(matchedVFBaseWidgetElements, Widget.getWidget(Widget.Type.VF).getName(),
1177 Widget.getWidget(Widget.Type.VF).getWidgetId());
1179 ModelElements baseResourceWidgetModelElements =
1180 matchedVFBaseWidgetElements.get(0).getModelElements();
1181 if (resourceTosca.getTopology_template() != null) {
1182 Map<String, String> groupIdTypeStore = getGroupsTypeStore(resourceTosca);
1184 if (baseResourceWidgetModelElements.getModelElement().size() !=
1185 groupIdTypeStore.size()) {
1186 Assert.fail("Missing VFModule in VF model.xml");
1189 for (String key : groupIdTypeStore.keySet()) {
1191 List<ModelElement> matchedResourceElements =
1192 getModelElementbyRelationshipValue(baseResourceWidgetModelElements, key);
1193 validateMatchedModelElementsInService(matchedResourceElements,
1194 Widget.getWidget(Widget.Type.VFMODULE).getName());
1195 Model resourceAAIVFModel = getAAIModelByNameVersionId(key, outputArtifactMap);
1196 Map<String, String> vfModuleModelMetadata =
1197 getVFModuleMetadataTosca(resourceTosca, key);
1198 Map<String, Object> vfModuleMembers = getVFModuleMembersTosca(resourceTosca, key);
1200 validateVFModelMetadata(vfModuleModelMetadata, resourceAAIVFModel);
1203 ModelVer modelVfVersion = resourceAAIVFModel.getModelVers().getModelVer().get(0);
1205 List<ModelElement> matchedVFModuleBaseWidgetElements =
1206 getModelElementbyRelationshipValue(modelVfVersion.getModelElements(),
1207 Widget.getWidget(Widget.Type.VFMODULE).getId());
1208 validateMatchedModelElementsInService(matchedVFModuleBaseWidgetElements,
1209 Widget.getWidget(Widget.Type.VFMODULE).getName());
1210 validateWidgetIds(matchedVFModuleBaseWidgetElements, Widget.getWidget(Widget.Type.VFMODULE)
1211 .getName(), Widget.getWidget(Widget.Type.VFMODULE).getWidgetId());
1213 ModelElements baseResourceVFModuleWidgetModelElements =
1214 matchedVFModuleBaseWidgetElements.get(0).getModelElements();
1215 if (vfModuleMembers.containsKey("l3-network")) {
1217 List<ModelElement> matchedL3NetworkElements =
1218 getModelElementbyRelationshipValue(baseResourceVFModuleWidgetModelElements,
1219 Widget.getWidget(Widget.Type.L3_NET).getId());
1220 validateMatchedModelElementsInService(matchedL3NetworkElements,
1221 Widget.getWidget(Widget.Type.L3_NET).getName());
1222 validateWidgetIds(matchedL3NetworkElements, Widget.getWidget(Widget.Type.L3_NET)
1223 .getName(), Widget.getWidget(Widget.Type.L3_NET).getWidgetId());
1225 if (vfModuleMembers.containsKey("vserver")) {
1227 List<ModelElement> matchedVserverElements =
1228 getModelElementbyRelationshipValue(baseResourceVFModuleWidgetModelElements,
1229 Widget.getWidget(Widget.Type.VSERVER).getId());
1230 validateMatchedModelElementsInService(matchedVserverElements,
1231 Widget.getWidget(Widget.Type.VSERVER).getName());
1232 ModelElements vserverWidgetModelElements =
1233 matchedVserverElements.get(0).getModelElements();
1235 validateWidgetIds(matchedVserverElements, Widget.getWidget(Widget.Type.VSERVER)
1236 .getName(), Widget.getWidget(Widget.Type.VSERVER).getWidgetId());
1239 //Validate vserver->vfc
1240 List<ModelElement> matchedVfcElements =
1241 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1242 Widget.getWidget(Widget.Type.VFC).getId());
1243 validateMatchedModelElementsInService(matchedVfcElements,
1244 Widget.getWidget(Widget.Type.VFC).getName());
1245 validateWidgetIds(matchedVfcElements, Widget.getWidget(Widget.Type.VFC).getName(),
1246 Widget.getWidget(Widget.Type.VFC).getWidgetId());
1248 //Validate vserver->Image
1249 List<ModelElement> matchedImageElements =
1250 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1251 Widget.getWidget(Widget.Type.IMAGE).getId());
1252 validateMatchedModelElementsInService(matchedImageElements,
1253 Widget.getWidget(Widget.Type.IMAGE).getName());
1254 validateWidgetIds(matchedImageElements, Widget.getWidget(Widget.Type.IMAGE)
1255 .getName(), Widget.getWidget(Widget.Type.IMAGE).getWidgetId());
1258 //Validate vserver->Flavor
1259 List<ModelElement> matchedFlavorElements =
1260 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1261 Widget.getWidget(Widget.Type.FLAVOR).getId());
1262 validateMatchedModelElementsInService(matchedFlavorElements,
1263 Widget.getWidget(Widget.Type.FLAVOR).getName());
1264 validateWidgetIds(matchedFlavorElements, Widget.getWidget(Widget.Type.FLAVOR).getName(),
1265 Widget.getWidget(Widget.Type.FLAVOR).getWidgetId());
1267 //Validate vserver->Tenant
1268 List<ModelElement> matchedTenantElements =
1269 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1270 Widget.getWidget(Widget.Type.TENANT).getId());
1271 validateMatchedModelElementsInService(matchedTenantElements,
1272 Widget.getWidget(Widget.Type.TENANT).getName());
1273 validateWidgetIds(matchedTenantElements, Widget.getWidget(Widget.Type.TENANT).getName(),
1274 Widget.getWidget(Widget.Type.TENANT).getWidgetId());
1276 //Validate vserver->l-interface
1277 if (vfModuleMembers.containsKey("l-interface")) {
1278 List<ModelElement> matchedLinterfaceElements =
1279 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1280 Widget.getWidget(Widget.Type.LINT).getId());
1281 validateMatchedModelElementsInService(matchedLinterfaceElements,
1282 Widget.getWidget(Widget.Type.LINT).getName());
1283 validateWidgetIds(matchedLinterfaceElements, Widget.getWidget(Widget.Type.LINT).getName(),
1284 Widget.getWidget(Widget.Type.LINT).getWidgetId());
1286 //Validate vserver->volume
1287 if (vfModuleMembers.containsKey("volume")) {
1288 List<ModelElement> matchedVolumeElements =
1289 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1290 Widget.getWidget(Widget.Type.VOLUME).getId());
1291 validateMatchedModelElementsInService(matchedVolumeElements,
1292 Widget.getWidget(Widget.Type.VOLUME).getName());
1293 validateWidgetIds(matchedVolumeElements, Widget.getWidget(Widget.Type.VOLUME).getName(),
1294 Widget.getWidget(Widget.Type.VOLUME).getWidgetId());
1300 System.out.println("Resource mapping not found for " + resourceNameVersionId);
1304 } catch (IllegalArgumentException e) {
1305 Assert.fail(e.getMessage()); //Can come while populating metadata
1310 private void validateMatchedModelElementsInService(List<ModelElement> matchedModelElements,
1312 if (matchedModelElements.isEmpty()) {
1313 Assert.fail(modelType + " not present ");
1315 if (matchedModelElements.size() > 1) {
1316 Assert.fail("More than one " + modelType + " present ");
1320 private Map<String, String> getNodeTemplateTypeStore(ToscaTemplate toscaTemplate) {
1321 if (toscaTemplate.getTopology_template() != null) {
1322 Map<String, NodeTemplate> nodeTemplateMap =
1323 toscaTemplate.getTopology_template().getNode_templates();
1324 Map<String, String> nodeTemplateIdTypeStore = new LinkedHashMap<>();
1325 if (nodeTemplateMap != null) {
1326 for (Map.Entry<String, NodeTemplate> e : nodeTemplateMap.entrySet()) {
1327 String uuid = e.getValue().getMetadata().get("resourceUUID");
1328 if (GeneratorUtil.isEmpty(uuid)) {
1329 uuid = e.getValue().getMetadata().get("UUID");
1330 if (GeneratorUtil.isEmpty(uuid)) {
1331 Assert.fail("UUID Not found");
1334 if(e.getValue().getType().contains("org.openecomp.resource.vf.")&& (e.getValue()
1335 .getMetadata().get("category").equals("Allotted Resource")))
1337 e.getValue().setType("org.openecomp.resource.vf.allottedResource");
1339 nodeTemplateIdTypeStore.put(uuid, e.getValue().getType());
1340 resourcesVersion.put(uuid,e.getValue().getMetadata().get
1342 //Populate invraintUuId for V9
1343 String invUuId = e.getValue().getMetadata().get("invariantUUID");
1344 nodeTemplateIdTypeStore.put(uuid+"-INV_UID" , invUuId);
1347 return nodeTemplateIdTypeStore;
1353 private Map<String, String> getGroupsTypeStore(ToscaTemplate toscaTemplate) {
1354 if (toscaTemplate.getTopology_template() != null) {
1355 Map<String, GroupDefinition> groupDefinitionMap =
1356 toscaTemplate.getTopology_template().getGroups();
1357 Map<String, String> groupDefinitionIdTypeStore = new LinkedHashMap<>();
1358 if (groupDefinitionMap != null) {
1359 for (Map.Entry<String, GroupDefinition> e : groupDefinitionMap.entrySet()) {
1360 if (e.getValue().getType().contains("org.openecomp.groups.VfModule")) {
1361 String uuid = e.getValue().getMetadata().get("vfModuleModelUUID");
1362 if (GeneratorUtil.isEmpty(uuid)) {
1363 uuid = e.getValue().getMetadata().get("UUID");
1364 if (GeneratorUtil.isEmpty(uuid)) {
1365 Assert.fail("UUID Not found");
1368 groupDefinitionIdTypeStore.put(uuid, e.getValue().getType());
1372 return groupDefinitionIdTypeStore;
1379 private void validateServiceModelMetadata(Service serviceToscaModel, Model generatedAAIModel) {
1380 ModelVer modelVersion = generatedAAIModel.getModelVers().getModelVer().get(0);
1381 Assert.assertEquals(serviceToscaModel.getModelNameVersionId(),
1382 modelVersion.getModelVersionId());
1383 Assert.assertEquals(serviceToscaModel.getModelId(), generatedAAIModel.getModelInvariantId());
1384 Assert.assertEquals(serviceToscaModel.getModelName(), modelVersion.getModelName());
1385 Assert.assertEquals(additionalParams.get(AdditionalParams.ServiceVersion.getName()), modelVersion
1386 .getModelVersion());
1387 Assert.assertEquals(serviceToscaModel.getModelDescription(),
1388 modelVersion.getModelDescription());
1392 private void validateResourceModelMetadata(Resource resouerceToscaModel,
1393 Model generatedAAIModel) {
1394 ModelVer modelVersion = generatedAAIModel.getModelVers().getModelVer().get(0);
1395 Assert.assertEquals(resouerceToscaModel.getModelNameVersionId(),
1396 modelVersion.getModelVersionId());
1397 Assert.assertEquals(resouerceToscaModel.getModelId(), generatedAAIModel.getModelInvariantId());
1398 Assert.assertEquals(resouerceToscaModel.getModelName(), modelVersion.getModelName());
1400 .assertEquals(resouerceToscaModel.getModelVersion(), modelVersion.getModelVersion());
1401 Assert.assertEquals(resouerceToscaModel.getModelDescription(),
1402 modelVersion.getModelDescription());
1406 private void validateVFModelMetadata(Map<String, String> vfModuleModelMetadata,
1407 Model generatedAAIModel) {
1408 ModelVer modelVersion = generatedAAIModel.getModelVers().getModelVer().get(0);
1409 Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelUUID"),
1410 modelVersion.getModelVersionId());
1411 Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelInvariantUUID"),
1412 generatedAAIModel.getModelInvariantId());
1413 Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelName"),
1414 modelVersion.getModelName());
1415 Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelVersion"),
1416 modelVersion.getModelVersion());
1417 Assert.assertEquals(vfModuleModelMetadata.get("vf_module_description"),
1418 modelVersion.getModelDescription());
1421 private Model getAAIModelByNameVersionId(String nameVersionId,
1422 Map<String, Model> outputArtifactMap) {
1423 return outputArtifactMap.get(nameVersionId);
1426 private List<ModelElement> getModelElementbyRelationshipValue(ModelElements modelElements,
1427 String relationshipValue) {
1428 List<ModelElement> matchedModelElements = new ArrayList<>();
1429 if (modelElements != null) {
1430 List<ModelElement> modelElementList = modelElements.getModelElement();
1431 for (ModelElement element : modelElementList) {
1432 List<Relationship> relationshipList = element.getRelationshipList().getRelationship();
1433 for (Relationship r : relationshipList) {
1434 List<RelationshipData> relationshipDataList = r.getRelationshipData();
1435 for (RelationshipData relationshipData : relationshipDataList) {
1436 if (relationshipData.getRelationshipValue().equals(relationshipValue)) {
1437 matchedModelElements.add(element);
1443 return matchedModelElements;
1446 private Map<String, Model> populateAAIGeneratedModelStore(List<Artifact> resultData) throws IOException {
1447 Map<String, Model> outputArtifactMap = new HashMap<>();
1448 for (Artifact outputArtifact : resultData) {
1449 if (outputArtifact.getType().equals(ArtifactType.MODEL_INVENTORY_PROFILE.name())) {
1450 byte[] decodedPayload = GeneratorUtil.decoder(outputArtifact.getPayload());
1451 Model aaiModel = getUnmarshalledArtifactModel(new String(decodedPayload));
1452 List<ModelVer> modelVersions = aaiModel.getModelVers().getModelVer();
1453 outputArtifactMap.put(modelVersions.get(0).getModelVersionId(), aaiModel);
1456 return outputArtifactMap;
1459 private Model getUnmarshalledArtifactModel(String aaiModel) throws IOException {
1463 JAXBContext jaxbContext = JAXBContext.newInstance(Model.class);
1464 Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
1466 try (InputStream aaiModelStream = new ByteArrayInputStream(aaiModel.getBytes())) {
1467 return (Model) unmarshaller.unmarshal(aaiModelStream);
1470 } catch (JAXBException e) {
1471 e.printStackTrace();
1478 * Get the tosca java model from the tosca input artifact
1480 * @param input Input tosca file and its metadata information as {@link Artifact} object
1481 * @return Translated {@link ToscaTemplate tosca} object
1483 private ToscaTemplate getToscaModel(Artifact input) throws SecurityException {
1484 byte[] decodedInput = GeneratorUtil.decoder(input.getPayload());
1485 String checksum = GeneratorUtil.checkSum(decodedInput);
1486 if (checksum.equals(input.getChecksum())) {
1488 return GeneratorUtil.translateTosca(new String(decodedInput), ToscaTemplate.class);
1489 } catch (Exception e) {
1490 e.printStackTrace();
1491 throw new IllegalArgumentException(
1492 String.format(GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_TOSCA, input.getName()));
1495 throw new SecurityException(
1496 String.format(GeneratorConstants.GENERATOR_AAI_ERROR_CHECKSUM_MISMATCH, input.getName()));
1501 * Identify the service tosca artifact from the list of translated tosca inputs
1503 * @param input List of translated {@link ToscaTemplate tosca} object models
1504 * @return Identified service {@link ToscaTemplate tosca}
1506 private ToscaTemplate getServiceTosca(List<ToscaTemplate> input) {
1507 Iterator<ToscaTemplate> iter = input.iterator();
1508 while (iter.hasNext()) {
1509 ToscaTemplate tosca = iter.next();
1510 if (tosca.isService()) {
1518 private Map<String, String> getVFModuleMetadataTosca(ToscaTemplate toscaTemplate,
1519 String vfModuleModelUUID) {
1520 Map<String, GroupDefinition> groupDefinitionMap =
1521 toscaTemplate.getTopology_template().getGroups();
1522 Map<String, String> vfModuleModelMetadata = new LinkedHashMap<>();
1523 for (Map.Entry<String, GroupDefinition> e : groupDefinitionMap.entrySet()) {
1524 if (e.getValue().getType().contains("org.openecomp.groups.VfModule")) {
1525 String uuid = e.getValue().getMetadata().get("vfModuleModelUUID");
1526 if (Objects.equals(uuid, vfModuleModelUUID)) {
1527 vfModuleModelMetadata = e.getValue().getMetadata();
1528 vfModuleModelMetadata.put("vf_module_description",
1529 (String) e.getValue().getProperties().get("vf_module_description"));
1533 return vfModuleModelMetadata;
1536 private Map<String, Object> getVFModuleMembersTosca(ToscaTemplate toscaTemplate,
1537 String vfModuleModelUUID) {
1538 Map<String, GroupDefinition> groupDefinitionMap =
1539 toscaTemplate.getTopology_template().getGroups();
1540 Map<String, NodeTemplate> nodeTemplateMaps =
1541 toscaTemplate.getTopology_template().getNode_templates();
1542 Map<String, Object> vfModuleMembers = new LinkedHashMap<>();
1543 List<String> vfModuleModelMetadata;
1544 for (Map.Entry<String, GroupDefinition> e : groupDefinitionMap.entrySet()) {
1545 if (e.getValue().getType().contains("org.openecomp.groups.VfModule")) {
1546 String uuid = e.getValue().getMetadata().get("vfModuleModelUUID");
1547 if (Objects.equals(uuid, vfModuleModelUUID)) {
1548 vfModuleModelMetadata = e.getValue().getMembers();
1549 if (vfModuleModelMetadata !=null) {
1550 for (Object key : vfModuleModelMetadata) {
1551 NodeTemplate nodeTemplate = nodeTemplateMaps.get(key);
1552 String nodetype = null;
1553 if (nodeTemplate != null) {
1554 nodetype = nodeTemplate.getType();
1556 if (nodetype != null) {
1557 String widgetType = membersType(nodetype);
1558 if (widgetType != null) {
1559 vfModuleMembers.put(widgetType, key);
1568 return vfModuleMembers;
1572 private String membersType(String toscaType) {
1573 String modelToBeReturned = null;
1574 while (toscaType != null && toscaType.lastIndexOf(".") != -1 && modelToBeReturned == null) {
1576 switch (toscaType) {
1577 case "org.openecomp.resource.vf.allottedResource":
1578 modelToBeReturned = "allotted-resource";
1580 case "org.openecomp.resource.vfc":
1581 modelToBeReturned = "vserver";
1583 case "org.openecomp.resource.cp":
1584 case "org.openecomp.cp":
1585 modelToBeReturned = "l-interface";
1587 case "org.openecomp.resource.vl":
1588 modelToBeReturned = "l3-network";
1590 case "org.openecomp.resource.vf":
1591 modelToBeReturned = "generic-vnf";
1593 case "org.openecomp.groups.VfModule":
1594 modelToBeReturned = "vf-module";
1596 case "org.openecomp.resource.vfc.nodes.heat.cinder":
1597 modelToBeReturned = "volume";
1600 modelToBeReturned = null;
1604 toscaType = toscaType.substring(0, toscaType.lastIndexOf("."));
1606 return modelToBeReturned;
1609 private List<Artifact> init(String aaiResourceBasePaths) {
1610 List<Artifact> inputArtifacts1 = new ArrayList<>();
1613 String[] resourceFileList = {};
1614 URL resourceDirUrl = this.getClass().getClassLoader().getResource(aaiResourceBasePaths);
1615 if (resourceDirUrl != null && resourceDirUrl.getProtocol().equals("file")) {
1616 resourceFileList = new File(resourceDirUrl.toURI()).list();
1618 Assert.fail("Invalid resource directory");
1621 for (String aResourceFileList : resourceFileList) {
1622 File resourceFile = new File(
1623 this.getClass().getClassLoader().getResource(aaiResourceBasePaths + aResourceFileList)
1626 //convert service tosca file into array of bytes
1627 byte[] payload = new byte[(int) resourceFile.length()];
1628 try (FileInputStream fileInputStream = new FileInputStream(resourceFile)) {
1629 fileInputStream.read(payload);
1632 String checksum = GeneratorUtil.checkSum(payload);
1633 byte[] encodedPayload = GeneratorUtil.encode(payload);
1635 new Artifact(aaiArtifactType, aaiArtifactGroupType, checksum, encodedPayload);
1636 artifact.setName(aResourceFileList);
1637 artifact.setLabel(aResourceFileList);
1638 artifact.setDescription(aResourceFileList);
1639 artifact.setVersion("1.0");
1640 inputArtifacts1.add(artifact);
1643 } catch (Exception e) {
1644 //e.printStackTrace();
1645 Assert.fail(e.getMessage());
1647 return inputArtifacts1;
1650 private void loadConfigFromClasspath(Properties properties) throws IOException {
1651 String configLocation = System.getProperty("artifactgenerator.config");
1652 if (configLocation != null) {
1653 File file = new File(configLocation);
1654 if (file.exists()) {
1655 properties.load(new FileInputStream(file));
1660 public void testResourceTosca(Iterator<ToscaTemplate> itr, Map<String, Model>
1661 outputArtifactMap) {
1662 while(itr.hasNext()){
1663 ToscaTemplate toscaTemplate = itr.next();
1664 String resourceVersion=resourcesVersion.get(toscaTemplate.getMetadata().get("UUID"));
1665 toscaTemplate.getMetadata().put("version", resourceVersion);
1666 if("VF".equals(toscaTemplate.getMetadata().get("type")) && !("Allotted Resource".equals
1667 (toscaTemplate.getMetadata().get("category"))) ){
1668 testVfTosca(outputArtifactMap, toscaTemplate);
1669 } else if("VF".equals(toscaTemplate.getMetadata().get("type")) && ("Allotted Resource".equals
1670 (toscaTemplate.getMetadata().get("category"))) ){
1671 testAllottedResourceTosca(outputArtifactMap, toscaTemplate);
1672 } else if("VL".equals(toscaTemplate.getMetadata().get("type"))){
1673 testL3NetworkResourceTosca(outputArtifactMap, toscaTemplate);
1678 private void readPayloadFromResource(List<Artifact> inputArtifacts, String file) throws IOException {
1679 try (InputStream stream = ArtifactGenerationServiceTest.class.getResourceAsStream("/" + file)) {
1680 readPayload(inputArtifacts, stream, file);