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.apache.commons.io.FileUtils;
24 import org.onap.sdc.generator.aai.tosca.GroupDefinition;
25 import org.onap.sdc.generator.data.AdditionalParams;
26 import org.onap.sdc.generator.data.GenerationData;
27 import org.onap.sdc.generator.data.GeneratorConstants;
28 import org.onap.sdc.generator.impl.ArtifactGenerationServiceImpl;
29 import org.onap.sdc.generator.aai.model.Resource;
30 import org.onap.sdc.generator.aai.model.Service;
31 import org.onap.sdc.generator.aai.model.Widget;
32 import org.onap.sdc.generator.aai.tosca.NodeTemplate;
33 import org.onap.sdc.generator.aai.tosca.ToscaTemplate;
34 import org.onap.sdc.generator.aai.xml.Model;
35 import org.onap.sdc.generator.aai.xml.ModelElement;
36 import org.onap.sdc.generator.aai.xml.ModelElements;
37 import org.onap.sdc.generator.aai.xml.ModelVer;
38 import org.onap.sdc.generator.aai.xml.Relationship;
39 import org.onap.sdc.generator.aai.xml.RelationshipData;
40 import org.onap.sdc.generator.data.Artifact;
41 import org.onap.sdc.generator.data.ArtifactType;
42 import org.onap.sdc.generator.data.GeneratorUtil;
43 import org.onap.sdc.generator.data.GroupType;
44 import org.testng.Assert;
45 import org.testng.annotations.BeforeSuite;
46 import org.testng.annotations.Test;
48 import java.io.ByteArrayInputStream;
50 import java.io.FileInputStream;
51 import java.io.FileOutputStream;
52 import java.io.IOException;
53 import java.io.InputStream;
54 import java.io.OutputStream;
57 import javax.xml.bind.JAXBContext;
58 import javax.xml.bind.JAXBException;
59 import javax.xml.bind.Unmarshaller;
61 @SuppressWarnings("Duplicates")
62 public class ArtifactGenerationServiceTest {
64 private static final String aaiArtifactType = ArtifactType.AAI.name();
65 private static final String aaiArtifactGroupType = GroupType.DEPLOYMENT.name();
66 private static final String generatorConfig = "{\"artifactTypes\": [\"OTHER\",\"AAI\"]}";
67 private final Properties properties = new Properties();
68 private final Map<String, String> additionalParams = new HashMap<>();
69 private final Map<String, String> resourcesVersion = new HashMap<>();
72 public void loadProperties() throws Exception{
73 loadConfigFromClasspath(properties);
74 additionalParams.put(AdditionalParams.ServiceVersion.getName(), "1.0");
78 public void testArtifactGeneration() {
79 // Sunny day scenario service with VF anf vfmodule
82 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
83 List<ToscaTemplate> toscas = new LinkedList<>();
84 String aaiResourceBasePaths = "aai/";
85 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
86 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
87 if (data.getErrorData().isEmpty()) {
88 for (Artifact inputArtifact : inputArtifacts) {
89 toscas.add(getToscaModel(inputArtifact));
91 List<Artifact> resultData = data.getResultData();
93 /*for( int i = 0 ; i < resultData.size() ; i++) {
94 Artifact artifact = resultData.get(i);
95 String fileName = artifact.getName();
96 while(fileName.contains(":")){
97 fileName = fileName.replace(":","");
99 File targetFile =new File("src/test/resources/"+fileName);
100 OutputStream outStream = new FileOutputStream(targetFile);
101 outStream.write(Base64.getDecoder().decode(artifact.getPayload()));
104 Assert.assertEquals(resultData.size(),5); // 1-service,1-VF-resource,1-vfmodule and 2
106 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
107 testServiceTosca(toscas, outputArtifactMap);
108 testResourceTosca(toscas.iterator(), outputArtifactMap);
110 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
113 } catch (Exception e) {
114 Assert.fail(e.getMessage());
119 public void testWidgetinServiceTosca() {
120 // Sunny day scenario service with VF and extra widget like CP anf vf has vfmodule without
123 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
124 List<ToscaTemplate> toscas = new LinkedList<>();
125 String aaiResourceBasePaths = "testWidgetinServiceTosca/";
126 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
127 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
128 if (data.getErrorData().isEmpty()) {
129 for (Artifact inputArtifact : inputArtifacts) {
130 toscas.add(getToscaModel(inputArtifact));
132 List<Artifact> resultData = data.getResultData();
133 Assert.assertEquals(resultData.size(),5); // 1-service,1-VF-resource,1-vfmodule and 2
135 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
136 testServiceTosca(toscas, outputArtifactMap);
137 testResourceTosca(toscas.iterator(), outputArtifactMap);
139 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
142 } catch (Exception e) {
143 Assert.fail(e.getMessage());
148 public void testSameVLdifferentVersion() {
149 // Sunny day scenario service with VF and extra widget like CP anf vf has vfmodule without
152 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
153 List<ToscaTemplate> toscas = new LinkedList<>();
154 String aaiResourceBasePaths = "testSameVLdifferentVersion/";
155 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
156 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
157 if (data.getErrorData().isEmpty()) {
158 for (Artifact inputArtifact : inputArtifacts) {
159 toscas.add(getToscaModel(inputArtifact));
161 List<Artifact> resultData = data.getResultData();
162 Assert.assertEquals(resultData.size(),8);
164 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
165 testServiceTosca(toscas, outputArtifactMap);
166 testResourceTosca(toscas.iterator(), outputArtifactMap);
168 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
171 } catch (Exception e) {
172 Assert.fail(e.getMessage());
177 public void testArtifactGenerationAllottedResourceAndL3Network() {
178 // Sunny day scenario service with allotted resource and L3-network
180 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
181 List<ToscaTemplate> toscas = new LinkedList<>();
182 String aaiResourceBasePaths = "aai2/";
183 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
184 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
185 if (data.getErrorData().isEmpty()) {
186 for (Artifact inputArtifact : inputArtifacts) {
187 toscas.add(getToscaModel(inputArtifact));
189 List<Artifact> resultData = data.getResultData();
191 Assert.assertEquals(resultData.size(),5);
194 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
195 testServiceTosca(toscas, outputArtifactMap);
196 testResourceTosca(toscas.iterator(), outputArtifactMap);
198 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
201 } catch (Exception e) {
202 Assert.fail(e.getMessage());
206 @Test(dependsOnMethods = {"testArtifactGeneration"})
207 public void testWhenMissingTosca() {
209 //Missing Service tosca test case
210 String aaiResourceBasePaths = "testArtifactGeneration2/";
211 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
212 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
213 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
214 Assert.assertEquals(data.getErrorData().get("AAI").get(0),"Service tosca missing from list of input artifacts");
215 } catch (Exception e) {
216 Assert.fail(e.getMessage());
220 @Test(dependsOnMethods = {"testWhenMissingTosca"})
221 public void testWhenInvaildConfig() {
223 //Invalid config test case
224 String generatorConfig1 = "{\"artifactTypes\": [\"ABC\"]}";
225 String aaiResourceBasePaths = "testArtifactGeneration2/";
226 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
227 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
228 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig1, additionalParams);
229 Assert.assertEquals(data.getErrorData().get("ARTIFACT_GENERATOR_INVOCATION_ERROR").get(0),"Invalid Client Configuration");
230 } catch (Exception e) {
231 Assert.fail(e.getMessage());
235 @Test(dependsOnMethods = {"testArtifactGeneration"})
236 public void testWhenOnlyServToscaNoResTosca() {
238 //Testing only service tosca no resource Tosca
239 String aaiResourceBasePaths = "testArtifactGeneration4/";
240 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
241 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
242 List<ToscaTemplate> toscas = new LinkedList<>();
243 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
244 List<Artifact> resultData = data.getResultData();
245 if (data.getErrorData().isEmpty()) {
246 for (Artifact inputArtifact : inputArtifacts) {
247 toscas.add(getToscaModel(inputArtifact));
250 Assert.assertEquals(resultData.size(),3); // 1-service and 2-Others
251 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
252 testServiceTosca(toscas, outputArtifactMap);
253 } catch (Exception e) {
254 Assert.fail(e.getMessage());
258 @Test(dependsOnMethods = {"testArtifactGeneration"})
259 public void testWhenInvaildYaml() {
261 //Invalid Yaml file test case
262 String aaiResourceBasePaths = "testArtifactGeneration5/";
263 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
264 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
265 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
266 Assert.assertEquals(data.getErrorData().get("AAI").get(0),"Invalid format for Tosca YML : " + inputArtifacts.get(0).getName());
267 } catch (Exception e) {
268 Assert.fail(e.getMessage());
272 @Test(dependsOnMethods = {"testArtifactGeneration"})
273 public void testWhenExtraResToscaNotPartOfServ() {
275 // Valid scenario with extra resource tosca which is not part of Service
276 String aaiResourceBasePaths = "testArtifactGeneration6/";
277 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
278 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
279 List<ToscaTemplate> toscas = new LinkedList<>();
280 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
281 List<Artifact> resultData = data.getResultData();
282 if (data.getErrorData().isEmpty()) {
283 for (Artifact inputArtifact : inputArtifacts) {
284 toscas.add(getToscaModel(inputArtifact));
287 Assert.assertEquals(resultData.size(),3); // 1-service and 2 Others
288 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
289 testServiceTosca(toscas, outputArtifactMap);
290 } catch (Exception e) {
291 Assert.fail(e.getMessage());
297 public void testWhenInvUuIdAttrMissing() {
299 // mandatory attribute <invariantUUID> missing
300 String aaiResourceBasePaths = "testArtifactGeneration8/";
301 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
302 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
303 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
305 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <invariantUUID> missing in Artifact: <" +
306 inputArtifacts.get(0).getName() + ">");
308 } catch (Exception e) {
309 Assert.fail(e.getMessage());
314 public void testErrorWhenInvalidInvId() {
316 //Invariant Id in service tosca of length not 36
317 String aaiResourceBasePaths = "testErrorWhenInvalidInvId/";
318 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
319 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
320 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
322 data.getErrorData().get("AAI").get(0),String.format(
323 GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_ID,
324 "invariantUUID",inputArtifacts.get(0).getName()));
326 } catch (Exception e) {
327 Assert.fail(e.getMessage());
332 public void testWhenUuIdAttrMissing() {
334 //mandatory attribute <UUID> missing
335 String aaiResourceBasePaths = "testArtifactGeneration9/";
336 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
337 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
338 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
340 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <UUID> missing in Artifact: <" +
341 inputArtifacts.get(0).getName() + ">");
343 } catch (Exception e) {
344 Assert.fail(e.getMessage());
349 public void testErrorWhenInvalidUuId() {
351 //UUID Id in service tosca of length not 36
352 String aaiResourceBasePaths = "testErrorWhenInvalidUuId/";
353 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
354 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
355 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
357 data.getErrorData().get("AAI").get(0),String.format(
358 GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_ID,
359 "UUID",inputArtifacts.get(0).getName()));
361 } catch (Exception e) {
362 Assert.fail(e.getMessage());
367 public void testWhenNameAttrMissing() {
369 //mandatory attribute <name> missing
370 String aaiResourceBasePaths = "testArtifactGeneration10/";
371 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
372 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
373 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
375 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <name> missing in Artifact: <" +
376 inputArtifacts.get(0).getName() + ">");
378 } catch (Exception e) {
379 Assert.fail(e.getMessage());
383 @Test //(dependsOnMethods = {"testArtifactGeneration"})
384 public void testWhenVfModInvUuIdAttrMissing() {
386 //mandatory attribute <vfModuleModelInvariantUUID> missing
387 List<Artifact> inputArtifacts = new ArrayList<>();
388 readPayloadFromResource(inputArtifacts, "service_vmme_template_ModInvUUID.yml");
389 readPayloadFromResource(inputArtifacts, "vf_vmme_template_ModInvUUID.yml");
390 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
391 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
393 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <vfModuleModelInvariantUUID> missing in Artifact: <" +
394 inputArtifacts.get(1).getName() + ">");
396 } catch (Exception e) {
397 Assert.fail(e.getMessage());
401 public static void readPayload(List<Artifact> inputArtifacts, InputStream fis, String fileName) throws
403 byte[] payload = new byte[fis.available()];
405 String checksum = GeneratorUtil.checkSum(payload);
406 byte[] encodedPayload = GeneratorUtil.encode(payload);
407 Artifact artifact = new Artifact(aaiArtifactType, aaiArtifactGroupType, checksum, encodedPayload);
408 artifact.setName(fileName);
409 artifact.setLabel(fileName);
410 artifact.setDescription(fileName);
411 artifact.setVersion("1.0");
412 System.out.println(artifact.getName());
413 inputArtifacts.add(artifact);
417 public void testWhenInvalidVfModInvUuIdAttr() {
419 //invalid id since not of length 36 for <vfModuleModelInvariantUUID>
420 List<Artifact> inputArtifacts = new ArrayList<>();
421 readPayloadFromResource(inputArtifacts, "service_vmme_template_InvalidVfModInvUuIdAttr.yml");
423 readPayloadFromResource(inputArtifacts, "vf_vmme_template_InvalidVfModInvUuIdAttr.yml");
424 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
425 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
427 data.getErrorData().get("AAI").get(0),String.format(
428 GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_ID,
429 "vfModuleModelInvariantUUID", inputArtifacts.get(1).getName() ));
431 } catch (Exception e) {
432 Assert.fail(e.getMessage());
436 @Test //(dependsOnMethods = {"testArtifactGeneration"})
437 public void testWhenVfModNameAttrMissing() {
439 //mandatory attribute <vfModuleModelName> missing
440 List<Artifact> inputArtifacts = new ArrayList<>();
441 readPayloadFromResource(inputArtifacts, "service_vmme_template_ModelName.yml");
443 readPayloadFromResource(inputArtifacts, "vf_vmme_template_ModelName.yml");
444 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
445 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
447 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <vfModuleModelName> missing in Artifact: <" +
448 inputArtifacts.get(1).getName() + ">");
450 } catch (Exception e) {
451 Assert.fail(e.getMessage());
455 /*public static void readPayload(List<Artifact> inputArtifacts,InputStream fis, String fileName)
458 byte[] payload = new byte[fis.available()];
460 String checksum = GeneratorUtil.checkSum(payload);
461 byte[] encodedPayload = GeneratorUtil.encode(payload);
462 Artifact artifact = new Artifact(aaiArtifactType, aaiArtifactGroupType, checksum, encodedPayload);
463 artifact.setName(fileName);
464 artifact.setLabel(fileName);
465 artifact.setDescription(fileName);
466 artifact.setVersion("1.0");
467 System.out.println(artifact.getName());
468 inputArtifacts.add(artifact);
471 @Test //(dependsOnMethods = {"testArtifactGeneration"})
472 public void testWhenVfModUuIdAttrMissing() {
474 //mandatory attribute <vfModuleModelUUID> missing in Artifact
475 List<Artifact> inputArtifacts = new ArrayList<>();
476 readPayloadFromResource(inputArtifacts, "service_vmme_template_ModelUUID.yml");
478 readPayloadFromResource(inputArtifacts, "vf_vmme_template_ModelUUID.yml");
479 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
480 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
482 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory " +
483 "attribute <vfModuleModelUUID> missing in Artifact: <" +
484 inputArtifacts.get(1).getName() + ">");
486 } catch (Exception e) {
487 Assert.fail(e.getMessage());
492 public void testWhenInvalidVfModUuIdAttr() {
494 //invalid id since not of length 36 for <vfModuleModelUUID>
495 List<Artifact> inputArtifacts = new ArrayList<>();
496 readPayloadFromResource(inputArtifacts, "service_vmme_template_InvalidVfModUuIdAttr.yml");
498 readPayloadFromResource(inputArtifacts, "vf_vmme_template_InvalidVfModUuIdAttr.yml");
499 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
500 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
502 data.getErrorData().get("AAI").get(0),String.format(
503 GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_ID,
504 "vfModuleModelUUID", inputArtifacts.get(1).getName() ));
506 } catch (Exception e) {
507 Assert.fail(e.getMessage());
511 @Test //(dependsOnMethods = {"testArtifactGeneration"})
512 public void testWhenVfModVersionAttrMissing() {
514 //mandatory attribute <vfModuleModelVersion> missing
515 List<Artifact> inputArtifacts = new ArrayList<>();
516 readPayloadFromResource(inputArtifacts, "service_vmme_template_ModelVersion.yml");
518 readPayloadFromResource(inputArtifacts, "vf_vmme_template_ModelVersion.yml");
519 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
520 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
522 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <vfModuleModelVersion> missing in Artifact: <" +
523 inputArtifacts.get(1).getName() + ">");
525 } catch (Exception e) {
526 Assert.fail(e.getMessage());
531 public void testErrorWhenNoSystemPropConfigured() throws Exception {
532 String configLoc = System.getProperty("artifactgenerator.config");
534 System.clearProperty("artifactgenerator.config");
535 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
536 String aaiResourceBasePaths = "aai/";
537 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
538 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
539 Assert.assertEquals(false,data.getErrorData().isEmpty());
540 Assert.assertEquals(data.getErrorData().
541 get("AAI").get(0), GeneratorConstants.GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND);
542 } catch (Exception e) {
543 Assert.fail(e.getMessage());
546 System.setProperty("artifactgenerator.config",configLoc);
551 public void testErrorWhenNoWidgetInConfig() throws Exception {
552 String configLoc = System.getProperty("artifactgenerator.config");
553 final File configFile = new File(configLoc);
554 String configDir = configLoc.substring(0, configLoc.lastIndexOf(File.separator));
555 final File tempFile = new File(configDir + File.separator + "temp.properties");
557 //copy orignal Artifact-Generator.properties to temp.properties for backup
558 FileUtils.copyFile(configFile, tempFile);
560 String serviceWidgetName = ArtifactType.AAI.name()+".model-version-id."+Widget.getWidget
561 (Widget.Type.SERVICE)
563 String assertMsg = ArtifactType.AAI.name() + ".model-version-id." +Widget.getWidget
564 (Widget.Type.SERVICE).getName();
566 //Remove property from Artifact-Generator.properties
567 properties.remove(serviceWidgetName);
568 try (OutputStream fos = new FileOutputStream(new File(configLoc))) {
569 properties.store(fos,null);
572 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
573 String aaiResourceBasePaths = "aai/";
574 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
575 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
576 Assert.assertEquals(false,data.getErrorData().isEmpty());
577 String errMsg = String.format(GeneratorConstants.GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,assertMsg);
578 Assert.assertEquals(data.getErrorData().get("AAI").get(0),errMsg);
579 } catch (Exception e) {
580 Assert.fail(e.getMessage());
583 if(tempFile.exists()){
585 FileUtils.copyFile(tempFile, configFile);
586 loadConfigFromClasspath(properties);
593 public void testErrorWhenNoFileAtConfigLocation() throws Exception {
594 String configLoc = System.getProperty("artifactgenerator.config");
596 System.setProperty("artifactgenerator.config",configLoc + File.separator + "testErrorWhenNoFileAtConfigLocation");
597 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
598 String aaiResourceBasePaths = "aai/";
599 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
600 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
601 Assert.assertEquals(data.getErrorData().isEmpty(),false);
602 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format(
603 GeneratorConstants.GENERATOR_AAI_CONFIGFILE_NOT_FOUND,System.getProperty
604 ("artifactgenerator.config")));
605 } catch (Exception e) {
606 Assert.fail(e.getMessage());
609 System.setProperty("artifactgenerator.config",configLoc);
614 public void testErrorWhenNoServiceVersion() {
615 // scenario service with VF anf vfmodule but no service version in additional parameter
617 additionalParams.clear();
618 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
619 String aaiResourceBasePaths = "aai/";
620 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
621 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
622 Assert.assertEquals(data.getErrorData().isEmpty(),false);
623 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
624 GeneratorConstants.GENERATOR_AAI_ERROR_MISSING_SERVICE_VERSION);
625 } catch (Exception e) {
626 Assert.fail(e.getMessage());
629 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
634 public void testArtifactGenerationWithServiceVersion() {
635 // Sunny day scenario service with VF anf vfmodule and service version as adiitional parameter
637 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"9.0");
638 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
639 List<ToscaTemplate> toscas = new LinkedList<>();
640 String aaiResourceBasePaths = "aai/";
641 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
642 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
643 if (data.getErrorData().isEmpty()) {
644 for (Artifact inputArtifact : inputArtifacts) {
645 toscas.add(getToscaModel(inputArtifact));
647 List<Artifact> resultData = data.getResultData();
649 /*for( int i = 0 ; i < resultData.size() ; i++) {
650 Artifact artifact = resultData.get(i);
651 String fileName = artifact.getName();
652 while(fileName.contains(":")){
653 fileName = fileName.replace(":","");
655 File targetFile =new File("src/test/resources/"+fileName);
656 OutputStream outStream = new FileOutputStream(targetFile);
657 outStream.write(Base64.getDecoder().decode(artifact.getPayload()));
660 Assert.assertEquals(resultData.size(),5); // 1-service,1-VF-resource,1-vfmodule and 2
662 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
663 testServiceTosca(toscas, outputArtifactMap);
664 testResourceTosca(toscas.iterator(), outputArtifactMap);
666 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
669 } catch (Exception e) {
670 Assert.fail(e.getMessage());
673 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
678 public void testErrorWhenInvalidServiceVersion() {
679 // scenario service with VF anf vfmodule but invalid service version in additional parameter
681 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
682 String aaiResourceBasePaths = "aai/";
683 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
685 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1");
686 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
687 Assert.assertEquals(data.getErrorData().isEmpty(),false);
688 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
689 GeneratorConstants.GENERATOR_AAI_INVALID_SERVICE_VERSION);
691 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.1");
692 data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
693 Assert.assertEquals(data.getErrorData().isEmpty(),false);
694 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
695 GeneratorConstants.GENERATOR_AAI_INVALID_SERVICE_VERSION);
697 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.0");
698 data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
699 Assert.assertEquals(data.getErrorData().isEmpty(),false);
700 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
701 GeneratorConstants.GENERATOR_AAI_INVALID_SERVICE_VERSION);
703 } catch (Exception e) {
704 Assert.fail(e.getMessage());
707 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
712 public void testMissingResourceTosca() {
714 //Service with resource but seperate resource tosca not coming as input.
715 String aaiResourceBasePaths = "missingResourceTosca/";
716 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
717 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
718 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
719 Assert.assertEquals(data.getErrorData().get("AAI").get(0),"Cannot generate artifacts. Resource Tosca missing for resource with UUID: <b020ed1e-4bc7-4fc0-ba7e-cc7af6da7ffc>");
720 } catch (Exception e) {
721 Assert.fail(e.getMessage());
725 public void testMissingVLTosca() {
727 //Service with VL but seperate VL tosca not coming as input artifact.
728 String aaiResourceBasePaths = "missingVLTosca/";
729 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
730 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
731 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
732 Assert.assertEquals(data.getErrorData().get("AAI").get(0),"Cannot generate artifacts. Resource Tosca missing for resource with UUID: <3f8fa4d2-2b86-4b36-bbc8-ffb8f9f57468>");
733 } catch (Exception e) {
734 Assert.fail(e.getMessage());
739 public void testErrorWhenNoResourceVersion() {
740 // scenario service with VF but missing resource version in service tosca
742 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
743 String aaiResourceBasePaths = "testErrorWhenNoResourceVersion/";
744 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
745 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
746 Assert.assertEquals(data.getErrorData().isEmpty(),false);
747 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
748 "Invalid Service definition mandatory attribute version missing for resource with UUID: <b020ed1e-4bc7-4fc0-ba7e-cc7af6da7ffc>");
749 } catch (Exception e) {
750 Assert.fail(e.getMessage());
755 public void testErrorWhenInvalidResourceVersion1() {
756 // scenario service with VF but invalid resource version 0.0 in service tosca
758 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
759 String aaiResourceBasePaths = "testErrorWhenInvalidResourceVersion1/";
760 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
761 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
762 Assert.assertEquals(data.getErrorData().isEmpty(),false);
763 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
764 "Cannot generate artifacts. Invalid Resource version in Service tosca for resource with UUID: <b020ed1e-4bc7-4fc0-ba7e-cc7af6da7ffc>");
765 } catch (Exception e) {
766 Assert.fail(e.getMessage());
771 public void testErrorWhenInvalidResourceVersion2() {
772 // scenario service with VF but invalid resource version 1 in service tosca
774 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
775 String aaiResourceBasePaths = "testErrorWhenInvalidResourceVersion2/";
776 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
777 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
778 Assert.assertEquals(data.getErrorData().isEmpty(),false);
779 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
780 "Cannot generate artifacts. Invalid Resource version in Service tosca for resource with UUID: <b020ed1e-4bc7-4fc0-ba7e-cc7af6da7ffc>");
781 } catch (Exception e) {
782 Assert.fail(e.getMessage());
787 public void testArtifactGenerationAllottedResourceWithIpMuxAndTunnelXConn() {
789 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
790 List<ToscaTemplate> toscas = new LinkedList<>();
791 String aaiResourceBasePaths = "testArtifactGeneration15/";
792 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
793 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
794 if (data.getErrorData().isEmpty()) {
795 for (Artifact inputArtifact : inputArtifacts) {
796 toscas.add(getToscaModel(inputArtifact));
798 List<Artifact> resultData = data.getResultData();
800 Assert.assertEquals(resultData.size(),5);
801 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
802 testServiceTosca(toscas, outputArtifactMap);
803 testResourceTosca(toscas.iterator(), outputArtifactMap);
805 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
808 } catch (Exception e) {
809 Assert.fail(e.getMessage());
814 public void testErrorWhenAllottedResourceWithOutProvidingServiceId() {
816 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
817 String aaiResourceBasePaths = "testErrorWhenAllottedResourceWithOutDependingServiceId/";
818 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
819 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
820 Assert.assertEquals(data.getErrorData().isEmpty(),false);
821 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format
822 (GeneratorConstants.GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING, "707b2850-e830-4b00-9902-879f44ac05a4"));
823 } catch (Exception e) {
824 Assert.fail(e.getMessage());
829 public void testArtifactGenerationWithoutAllottedResource() {
831 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
832 String aaiResourceBasePaths = "testArtifactGeneration16/";
833 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
834 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
835 Assert.assertEquals(data.getErrorData().isEmpty(),false);
836 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format
837 (GeneratorConstants.GENERATOR_AAI_PROVIDING_SERVICE_MISSING, "a54a5235-b69d-4f8a-838b-d011e6783fa5"));
838 } catch (Exception e) {
839 Assert.fail(e.getMessage());
844 public void testArtifactGenerationAllottedResourceIpmuxSameInvariantDiffVersion() {
846 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
847 List<ToscaTemplate> toscas = new LinkedList<>();
848 String aaiResourceBasePaths = "testArtifactGeneration17/";
849 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
850 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
851 if (data.getErrorData().isEmpty()) {
852 for (Artifact inputArtifact : inputArtifacts) {
853 toscas.add(getToscaModel(inputArtifact));
855 List<Artifact> resultData = data.getResultData();
857 Assert.assertEquals(resultData.size(),5);
858 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
859 testServiceTosca(toscas, outputArtifactMap);
860 testResourceTosca(toscas.iterator(), outputArtifactMap);
862 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
865 } catch (Exception e) {
866 Assert.fail(e.getMessage());
871 public void testArtifactGenerationAllottedResourceIpmuxSameInvariantSameVersion() {
873 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
874 List<ToscaTemplate> toscas = new LinkedList<>();
875 String aaiResourceBasePaths = "testArtifactGeneration18/";
876 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
877 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
878 if (data.getErrorData().isEmpty()) {
879 for (Artifact inputArtifact : inputArtifacts) {
880 toscas.add(getToscaModel(inputArtifact));
882 List<Artifact> resultData = data.getResultData();
885 Assert.assertEquals(resultData.size(),4);
886 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
887 testServiceTosca(toscas, outputArtifactMap);
888 testResourceTosca(toscas.iterator(), outputArtifactMap);
890 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
893 } catch (Exception e) {
894 Assert.fail(e.getMessage());
899 public void testArtifactGenerationAllottedResourceIpmuxWithGroups() {
901 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
902 List<ToscaTemplate> toscas = new LinkedList<>();
903 String aaiResourceBasePaths = "testAllotedResourceWithDependingSerWithGroups/";
904 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
905 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
906 if (data.getErrorData().isEmpty()) {
907 for (Artifact inputArtifact : inputArtifacts) {
908 toscas.add(getToscaModel(inputArtifact));
910 List<Artifact> resultData = data.getResultData();
912 Assert.assertEquals(resultData.size(),5);
913 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
914 testServiceTosca(toscas, outputArtifactMap);
915 testResourceTosca(toscas.iterator(), outputArtifactMap);
917 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
920 } catch (Exception e) {
921 Assert.fail(e.getMessage());
926 public void testArtifactGenerationAllottedResourceWithVF() {
928 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
929 List<ToscaTemplate> toscas = new LinkedList<>();
930 String aaiResourceBasePaths = "testArtifactGenerationAllottedResourceWithVF/";
931 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
932 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
933 if (data.getErrorData().isEmpty()) {
934 for (Artifact inputArtifact : inputArtifacts) {
935 toscas.add(getToscaModel(inputArtifact));
937 List<Artifact> resultData = data.getResultData();
939 Assert.assertEquals(resultData.size(),7);
940 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
941 testServiceTosca(toscas, outputArtifactMap);
942 testResourceTosca(toscas.iterator(), outputArtifactMap);
944 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
947 } catch (Exception e) {
948 Assert.fail(e.getMessage());
954 public void testServiceTosca(List<ToscaTemplate> toscas, Map<String, Model> outputArtifactMap) {
956 ToscaTemplate serviceTosca = getServiceTosca(toscas);
957 if (serviceTosca == null) {
958 Assert.fail("Service Tosca not found");
960 serviceTosca.getMetadata().put("version", "1.0");
961 Service service = new Service();
962 service.populateModelIdentificationInformation(serviceTosca.getMetadata());
963 String serviceNameVersionId = service.getModelNameVersionId();
964 Model serviceAAIModel = getAAIModelByNameVersionId(serviceNameVersionId, outputArtifactMap);
965 validateServiceModelMetadata(service, serviceAAIModel);
966 //Validate Service instance base widget
967 ModelVer modelVersion = serviceAAIModel.getModelVers().getModelVer().get(0);
969 List<ModelElement> matchedServiceBaseWidgetElements =
970 getModelElementbyRelationshipValue( modelVersion.getModelElements(),
971 Widget.getWidget(Widget.Type.SERVICE).getId());
972 validateMatchedModelElementsInService(matchedServiceBaseWidgetElements,
973 Widget.getWidget(Widget.Type.SERVICE).getName());
975 validateWidgetIds(matchedServiceBaseWidgetElements, Widget.getWidget(Widget.Type.SERVICE).getName(),
976 Widget.getWidget(Widget.Type.SERVICE).getWidgetId());
978 ModelElements baseServiceWidgetModelElements =
979 matchedServiceBaseWidgetElements.get(0).getModelElements();
982 Map<String, String> nodeTemplateIdTypeStore = getNodeTemplateTypeStore(serviceTosca);
983 if (nodeTemplateIdTypeStore != null) {
984 for (String key : nodeTemplateIdTypeStore.keySet()) {
985 if (nodeTemplateIdTypeStore.get(key).contains("org.openecomp.resource.vf")) {
986 List<ModelElement> matchedResourceElements =
987 getModelElementbyRelationshipValue(baseServiceWidgetModelElements, key);
988 if (nodeTemplateIdTypeStore.get(key).contains("org.openecomp.resource.vf.allottedResource")){
989 validateMatchedModelElementsInService(matchedResourceElements,
990 Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getName());
992 validateMatchedModelElementsInService(matchedResourceElements,
993 Widget.getWidget(Widget.Type.VF).getName());
996 //Validate uuid and invariantuuid are populated in model-ver.model-version-id and model.model-invariant-id
997 Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList()
998 .getRelationship().get(0)
999 .getRelationshipData().get(0).getRelationshipValue(),key);
1001 Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList().getRelationship().get(0)
1002 .getRelationshipData().get(1).getRelationshipValue(), nodeTemplateIdTypeStore
1003 .get(key+"-INV_UID"));
1004 } else if(nodeTemplateIdTypeStore.get(key).contains("org.openecomp.resource.vl")){
1005 //validate l3-network in service tosca
1006 List<ModelElement> matchedResourceElements =
1007 getModelElementbyRelationshipValue(baseServiceWidgetModelElements, key);
1008 validateMatchedModelElementsInService(matchedResourceElements,
1009 Widget.getWidget(Widget.Type.L3_NET).getName());
1010 //Validate uuid and invariantuuid are populated in model-ver.model-version-id and model.model-invariant-id
1011 Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList()
1012 .getRelationship().get(0)
1013 .getRelationshipData().get(0).getRelationshipValue(),key);
1015 Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList().getRelationship().get(0)
1016 .getRelationshipData().get(1).getRelationshipValue(), nodeTemplateIdTypeStore
1017 .get(key+"-INV_UID"));
1022 System.out.println();
1025 } catch (IllegalArgumentException e) {
1026 Assert.fail(e.getMessage()); //Can come while populating metadata
1030 private void validateWidgetIds(List<ModelElement> matchedServiceBaseWidgetElements,
1031 String widgetName, String widgetInvUuId) {
1032 Assert.assertEquals(matchedServiceBaseWidgetElements.get(0).getRelationshipList().getRelationship().get(0)
1033 .getRelationshipData().get(0).getRelationshipValue(), properties.getProperty(ArtifactType.AAI.name()
1034 + ".model-version-id."+ widgetName));
1036 Assert.assertEquals(matchedServiceBaseWidgetElements.get(0).getRelationshipList().getRelationship().get(0)
1037 .getRelationshipData().get(1).getRelationshipValue(), widgetInvUuId);
1041 public void testL3NetworkResourceTosca(Map<String, Model> outputArtifactMap , ToscaTemplate
1044 if (resourceTosca != null) {
1045 Resource resource = new Resource();
1046 resource.populateModelIdentificationInformation(resourceTosca.getMetadata());
1047 String resourceNameVersionId = resource.getModelNameVersionId();
1048 Model resourceAAIModel =
1049 getAAIModelByNameVersionId(resourceNameVersionId, outputArtifactMap);
1050 if (resourceAAIModel != null) {
1051 validateResourceModelMetadata(resource, resourceAAIModel);
1052 //Validate Resource instance base widget
1054 ModelVer modelVersion = resourceAAIModel.getModelVers().getModelVer().get(0);
1056 List<ModelElement> matchedVFBaseWidgetElements =
1057 getModelElementbyRelationshipValue(modelVersion.getModelElements(),
1058 Widget.getWidget(Widget.Type.L3_NET).getId());
1059 validateMatchedModelElementsInService(matchedVFBaseWidgetElements,
1060 Widget.getWidget(Widget.Type.L3_NET).getName());
1062 validateWidgetIds(matchedVFBaseWidgetElements, Widget.getWidget(Widget.Type.L3_NET).getName(),
1063 Widget.getWidget(Widget.Type.L3_NET).getWidgetId());
1066 System.out.println("Resource mapping not found for " + resourceNameVersionId);
1070 }catch (IllegalArgumentException e) {
1071 Assert.fail(e.getMessage()); //Can come while populating metadata
1076 public void testAllottedResourceTosca(Map<String, Model> outputArtifactMap , ToscaTemplate
1079 if (resourceTosca != null) {
1080 Resource resource = new Resource();
1081 resource.populateModelIdentificationInformation(resourceTosca.getMetadata());
1082 String resourceNameVersionId = resource.getModelNameVersionId();
1083 Model resourceAAIModel =
1084 getAAIModelByNameVersionId(resourceNameVersionId, outputArtifactMap);
1085 if (resourceAAIModel != null) {
1086 validateResourceModelMetadata(resource, resourceAAIModel);
1087 //Validate Resource instance base widget
1089 ModelVer modelVersion = resourceAAIModel.getModelVers().getModelVer().get(0);
1091 List<ModelElement> matchedVFBaseWidgetElements =
1092 getModelElementbyRelationshipValue(modelVersion.getModelElements(),
1093 Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getId());
1094 validateMatchedModelElementsInService(matchedVFBaseWidgetElements,
1095 Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getName());
1097 validateWidgetIds(matchedVFBaseWidgetElements, Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getName(),
1098 Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getWidgetId());
1100 Map<String, Object> dependingServiceDetails = getProvidingServiceDetails(resourceTosca);
1102 ModelElements containedModelElements = modelVersion.getModelElements().getModelElement().
1103 get(0).getModelElements();
1104 Assert.assertEquals( containedModelElements.getModelElement().get(0).getRelationshipList()
1105 .getRelationship().get(0).getRelationshipData().get(0).getRelationshipValue(),
1106 dependingServiceDetails.get("providing_service_uuid"));
1108 Assert.assertEquals(containedModelElements.getModelElement().get(0).getRelationshipList()
1109 .getRelationship().get(0).getRelationshipData().get(1).getRelationshipValue(),
1110 dependingServiceDetails.get("providing_service_invariant_uuid"));
1112 if("Allotted Resource".equals(resourceTosca.getMetadata().get("category")) &&
1113 "Tunnel XConnect".equals(resourceTosca.getMetadata().get("subcategory"))) {
1115 List<ModelElement> matchedTunnelXConnectWidgetElements =
1116 getModelElementbyRelationshipValue(containedModelElements,
1117 Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getId());
1118 validateMatchedModelElementsInService(matchedTunnelXConnectWidgetElements,
1119 Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getName());
1121 validateWidgetIds(matchedTunnelXConnectWidgetElements, Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getName(),
1122 Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getWidgetId());
1126 System.out.println("Resource mapping not found for " + resourceNameVersionId);
1130 }catch (IllegalArgumentException e) {
1131 Assert.fail(e.getMessage()); //Can come while populating metadata
1136 public Map<String, Object> getProvidingServiceDetails(ToscaTemplate resourceTemplate) {
1137 Set<String> keys = resourceTemplate.getTopology_template().getNode_templates().keySet();
1139 Map<String, Object> nodeProperties =null;
1140 for(String key : keys) {
1141 NodeTemplate node = resourceTemplate.getTopology_template().getNode_templates().get(key);
1142 if(node.getType().equals("org.openecomp.resource.vfc.AllottedResource")) {
1143 nodeProperties = node.getProperties();
1147 return nodeProperties;
1150 public void testVfTosca(Map<String, Model> outputArtifactMap , ToscaTemplate resourceTosca) {
1152 //ToscaTemplate resourceTosca = getResourceTosca(toscas);
1153 //resourceTosca.getTopology_template().getGroups().
1154 if (resourceTosca != null) {
1155 Resource resource = new Resource();
1156 resource.populateModelIdentificationInformation(resourceTosca.getMetadata());
1157 String resourceNameVersionId = resource.getModelNameVersionId();
1158 Model resourceAAIModel =
1159 getAAIModelByNameVersionId(resourceNameVersionId, outputArtifactMap);
1160 if (resourceAAIModel != null) {
1161 validateResourceModelMetadata(resource, resourceAAIModel);
1162 //Validate Resource instance base widget
1164 ModelVer modelVersion = resourceAAIModel.getModelVers().getModelVer().get(0);
1166 List<ModelElement> matchedVFBaseWidgetElements =
1167 getModelElementbyRelationshipValue(modelVersion.getModelElements(),
1168 Widget.getWidget(Widget.Type.VF).getId());
1169 validateMatchedModelElementsInService(matchedVFBaseWidgetElements,
1170 Widget.getWidget(Widget.Type.VF).getName());
1172 validateWidgetIds(matchedVFBaseWidgetElements, Widget.getWidget(Widget.Type.VF).getName(),
1173 Widget.getWidget(Widget.Type.VF).getWidgetId());
1175 ModelElements baseResourceWidgetModelElements =
1176 matchedVFBaseWidgetElements.get(0).getModelElements();
1177 if (resourceTosca.getTopology_template() != null) {
1178 Map<String, String> groupIdTypeStore = getGroupsTypeStore(resourceTosca);
1180 if (baseResourceWidgetModelElements.getModelElement().size() !=
1181 groupIdTypeStore.size()) {
1182 Assert.fail("Missing VFModule in VF model.xml");
1185 for (String key : groupIdTypeStore.keySet()) {
1187 List<ModelElement> matchedResourceElements =
1188 getModelElementbyRelationshipValue(baseResourceWidgetModelElements, key);
1189 validateMatchedModelElementsInService(matchedResourceElements,
1190 Widget.getWidget(Widget.Type.VFMODULE).getName());
1191 Model resourceAAIVFModel = getAAIModelByNameVersionId(key, outputArtifactMap);
1192 Map<String, String> vfModuleModelMetadata =
1193 getVFModuleMetadataTosca(resourceTosca, key);
1194 Map<String, Object> vfModuleMembers = getVFModuleMembersTosca(resourceTosca, key);
1196 validateVFModelMetadata(vfModuleModelMetadata, resourceAAIVFModel);
1199 ModelVer modelVfVersion = resourceAAIVFModel.getModelVers().getModelVer().get(0);
1201 List<ModelElement> matchedVFModuleBaseWidgetElements =
1202 getModelElementbyRelationshipValue(modelVfVersion.getModelElements(),
1203 Widget.getWidget(Widget.Type.VFMODULE).getId());
1204 validateMatchedModelElementsInService(matchedVFModuleBaseWidgetElements,
1205 Widget.getWidget(Widget.Type.VFMODULE).getName());
1206 validateWidgetIds(matchedVFModuleBaseWidgetElements, Widget.getWidget(Widget.Type.VFMODULE)
1207 .getName(), Widget.getWidget(Widget.Type.VFMODULE).getWidgetId());
1209 ModelElements baseResourceVFModuleWidgetModelElements =
1210 matchedVFModuleBaseWidgetElements.get(0).getModelElements();
1211 if (vfModuleMembers.containsKey("l3-network")) {
1213 List<ModelElement> matchedL3NetworkElements =
1214 getModelElementbyRelationshipValue(baseResourceVFModuleWidgetModelElements,
1215 Widget.getWidget(Widget.Type.L3_NET).getId());
1216 validateMatchedModelElementsInService(matchedL3NetworkElements,
1217 Widget.getWidget(Widget.Type.L3_NET).getName());
1218 validateWidgetIds(matchedL3NetworkElements, Widget.getWidget(Widget.Type.L3_NET)
1219 .getName(), Widget.getWidget(Widget.Type.L3_NET).getWidgetId());
1221 if (vfModuleMembers.containsKey("vserver")) {
1223 List<ModelElement> matchedVserverElements =
1224 getModelElementbyRelationshipValue(baseResourceVFModuleWidgetModelElements,
1225 Widget.getWidget(Widget.Type.VSERVER).getId());
1226 validateMatchedModelElementsInService(matchedVserverElements,
1227 Widget.getWidget(Widget.Type.VSERVER).getName());
1228 ModelElements vserverWidgetModelElements =
1229 matchedVserverElements.get(0).getModelElements();
1231 validateWidgetIds(matchedVserverElements, Widget.getWidget(Widget.Type.VSERVER)
1232 .getName(), Widget.getWidget(Widget.Type.VSERVER).getWidgetId());
1235 //Validate vserver->vfc
1236 List<ModelElement> matchedVfcElements =
1237 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1238 Widget.getWidget(Widget.Type.VFC).getId());
1239 validateMatchedModelElementsInService(matchedVfcElements,
1240 Widget.getWidget(Widget.Type.VFC).getName());
1241 validateWidgetIds(matchedVfcElements, Widget.getWidget(Widget.Type.VFC).getName(),
1242 Widget.getWidget(Widget.Type.VFC).getWidgetId());
1244 //Validate vserver->Image
1245 List<ModelElement> matchedImageElements =
1246 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1247 Widget.getWidget(Widget.Type.IMAGE).getId());
1248 validateMatchedModelElementsInService(matchedImageElements,
1249 Widget.getWidget(Widget.Type.IMAGE).getName());
1250 validateWidgetIds(matchedImageElements, Widget.getWidget(Widget.Type.IMAGE)
1251 .getName(), Widget.getWidget(Widget.Type.IMAGE).getWidgetId());
1254 //Validate vserver->Flavor
1255 List<ModelElement> matchedFlavorElements =
1256 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1257 Widget.getWidget(Widget.Type.FLAVOR).getId());
1258 validateMatchedModelElementsInService(matchedFlavorElements,
1259 Widget.getWidget(Widget.Type.FLAVOR).getName());
1260 validateWidgetIds(matchedFlavorElements, Widget.getWidget(Widget.Type.FLAVOR).getName(),
1261 Widget.getWidget(Widget.Type.FLAVOR).getWidgetId());
1263 //Validate vserver->Tenant
1264 List<ModelElement> matchedTenantElements =
1265 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1266 Widget.getWidget(Widget.Type.TENANT).getId());
1267 validateMatchedModelElementsInService(matchedTenantElements,
1268 Widget.getWidget(Widget.Type.TENANT).getName());
1269 validateWidgetIds(matchedTenantElements, Widget.getWidget(Widget.Type.TENANT).getName(),
1270 Widget.getWidget(Widget.Type.TENANT).getWidgetId());
1272 //Validate vserver->l-interface
1273 if (vfModuleMembers.containsKey("l-interface")) {
1274 List<ModelElement> matchedLinterfaceElements =
1275 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1276 Widget.getWidget(Widget.Type.LINT).getId());
1277 validateMatchedModelElementsInService(matchedLinterfaceElements,
1278 Widget.getWidget(Widget.Type.LINT).getName());
1279 validateWidgetIds(matchedLinterfaceElements, Widget.getWidget(Widget.Type.LINT).getName(),
1280 Widget.getWidget(Widget.Type.LINT).getWidgetId());
1282 //Validate vserver->volume
1283 if (vfModuleMembers.containsKey("volume")) {
1284 List<ModelElement> matchedVolumeElements =
1285 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1286 Widget.getWidget(Widget.Type.VOLUME).getId());
1287 validateMatchedModelElementsInService(matchedVolumeElements,
1288 Widget.getWidget(Widget.Type.VOLUME).getName());
1289 validateWidgetIds(matchedVolumeElements, Widget.getWidget(Widget.Type.VOLUME).getName(),
1290 Widget.getWidget(Widget.Type.VOLUME).getWidgetId());
1296 System.out.println("Resource mapping not found for " + resourceNameVersionId);
1300 } catch (IllegalArgumentException e) {
1301 Assert.fail(e.getMessage()); //Can come while populating metadata
1306 private void validateMatchedModelElementsInService(List<ModelElement> matchedModelElements,
1308 if (matchedModelElements.isEmpty()) {
1309 Assert.fail(modelType + " not present ");
1311 if (matchedModelElements.size() > 1) {
1312 Assert.fail("More than one " + modelType + " present ");
1316 private Map<String, String> getNodeTemplateTypeStore(ToscaTemplate toscaTemplate) {
1317 if (toscaTemplate.getTopology_template() != null) {
1318 Map<String, NodeTemplate> nodeTemplateMap =
1319 toscaTemplate.getTopology_template().getNode_templates();
1320 Map<String, String> nodeTemplateIdTypeStore = new LinkedHashMap<>();
1321 if (nodeTemplateMap != null) {
1322 for (Map.Entry<String, NodeTemplate> e : nodeTemplateMap.entrySet()) {
1323 String uuid = e.getValue().getMetadata().get("resourceUUID");
1324 if (GeneratorUtil.isEmpty(uuid)) {
1325 uuid = e.getValue().getMetadata().get("UUID");
1326 if (GeneratorUtil.isEmpty(uuid)) {
1327 Assert.fail("UUID Not found");
1330 if(e.getValue().getType().contains("org.openecomp.resource.vf.")&& (e.getValue()
1331 .getMetadata().get("category").equals("Allotted Resource")))
1333 e.getValue().setType("org.openecomp.resource.vf.allottedResource");
1335 nodeTemplateIdTypeStore.put(uuid, e.getValue().getType());
1336 resourcesVersion.put(uuid,e.getValue().getMetadata().get
1338 //Populate invraintUuId for V9
1339 String invUuId = e.getValue().getMetadata().get("invariantUUID");
1340 nodeTemplateIdTypeStore.put(uuid+"-INV_UID" , invUuId);
1343 return nodeTemplateIdTypeStore;
1349 private Map<String, String> getGroupsTypeStore(ToscaTemplate toscaTemplate) {
1350 if (toscaTemplate.getTopology_template() != null) {
1351 Map<String, GroupDefinition> groupDefinitionMap =
1352 toscaTemplate.getTopology_template().getGroups();
1353 Map<String, String> groupDefinitionIdTypeStore = new LinkedHashMap<>();
1354 if (groupDefinitionMap != null) {
1355 for (Map.Entry<String, GroupDefinition> e : groupDefinitionMap.entrySet()) {
1356 if (e.getValue().getType().contains("org.openecomp.groups.VfModule")) {
1357 String uuid = e.getValue().getMetadata().get("vfModuleModelUUID");
1358 if (GeneratorUtil.isEmpty(uuid)) {
1359 uuid = e.getValue().getMetadata().get("UUID");
1360 if (GeneratorUtil.isEmpty(uuid)) {
1361 Assert.fail("UUID Not found");
1364 groupDefinitionIdTypeStore.put(uuid, e.getValue().getType());
1368 return groupDefinitionIdTypeStore;
1375 private void validateServiceModelMetadata(Service serviceToscaModel, Model generatedAAIModel) {
1376 ModelVer modelVersion = generatedAAIModel.getModelVers().getModelVer().get(0);
1377 Assert.assertEquals(serviceToscaModel.getModelNameVersionId(),
1378 modelVersion.getModelVersionId());
1379 Assert.assertEquals(serviceToscaModel.getModelId(), generatedAAIModel.getModelInvariantId());
1380 Assert.assertEquals(serviceToscaModel.getModelName(), modelVersion.getModelName());
1381 Assert.assertEquals(additionalParams.get(AdditionalParams.ServiceVersion.getName()), modelVersion
1382 .getModelVersion());
1383 Assert.assertEquals(serviceToscaModel.getModelDescription(),
1384 modelVersion.getModelDescription());
1388 private void validateResourceModelMetadata(Resource resouerceToscaModel,
1389 Model generatedAAIModel) {
1390 ModelVer modelVersion = generatedAAIModel.getModelVers().getModelVer().get(0);
1391 Assert.assertEquals(resouerceToscaModel.getModelNameVersionId(),
1392 modelVersion.getModelVersionId());
1393 Assert.assertEquals(resouerceToscaModel.getModelId(), generatedAAIModel.getModelInvariantId());
1394 Assert.assertEquals(resouerceToscaModel.getModelName(), modelVersion.getModelName());
1396 .assertEquals(resouerceToscaModel.getModelVersion(), modelVersion.getModelVersion());
1397 Assert.assertEquals(resouerceToscaModel.getModelDescription(),
1398 modelVersion.getModelDescription());
1402 private void validateVFModelMetadata(Map<String, String> vfModuleModelMetadata,
1403 Model generatedAAIModel) {
1404 ModelVer modelVersion = generatedAAIModel.getModelVers().getModelVer().get(0);
1405 Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelUUID"),
1406 modelVersion.getModelVersionId());
1407 Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelInvariantUUID"),
1408 generatedAAIModel.getModelInvariantId());
1409 Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelName"),
1410 modelVersion.getModelName());
1411 Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelVersion"),
1412 modelVersion.getModelVersion());
1413 Assert.assertEquals(vfModuleModelMetadata.get("vf_module_description"),
1414 modelVersion.getModelDescription());
1417 private Model getAAIModelByNameVersionId(String nameVersionId,
1418 Map<String, Model> outputArtifactMap) {
1419 return outputArtifactMap.get(nameVersionId);
1422 private List<ModelElement> getModelElementbyRelationshipValue(ModelElements modelElements,
1423 String relationshipValue) {
1424 List<ModelElement> matchedModelElements = new ArrayList<>();
1425 if (modelElements != null) {
1426 List<ModelElement> modelElementList = modelElements.getModelElement();
1427 for (ModelElement element : modelElementList) {
1428 List<Relationship> relationshipList = element.getRelationshipList().getRelationship();
1429 for (Relationship r : relationshipList) {
1430 List<RelationshipData> relationshipDataList = r.getRelationshipData();
1431 for (RelationshipData relationshipData : relationshipDataList) {
1432 if (relationshipData.getRelationshipValue().equals(relationshipValue)) {
1433 matchedModelElements.add(element);
1439 return matchedModelElements;
1442 private Map<String, Model> populateAAIGeneratedModelStore(List<Artifact> resultData) throws IOException {
1443 Map<String, Model> outputArtifactMap = new HashMap<>();
1444 for (Artifact outputArtifact : resultData) {
1445 if (outputArtifact.getType().equals(ArtifactType.MODEL_INVENTORY_PROFILE.name())) {
1446 byte[] decodedPayload = GeneratorUtil.decoder(outputArtifact.getPayload());
1447 Model aaiModel = getUnmarshalledArtifactModel(new String(decodedPayload));
1448 List<ModelVer> modelVersions = aaiModel.getModelVers().getModelVer();
1449 outputArtifactMap.put(modelVersions.get(0).getModelVersionId(), aaiModel);
1452 return outputArtifactMap;
1455 private Model getUnmarshalledArtifactModel(String aaiModel) throws IOException {
1459 JAXBContext jaxbContext = JAXBContext.newInstance(Model.class);
1460 Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
1462 try (InputStream aaiModelStream = new ByteArrayInputStream(aaiModel.getBytes())) {
1463 return (Model) unmarshaller.unmarshal(aaiModelStream);
1466 } catch (JAXBException e) {
1467 e.printStackTrace();
1474 * Get the tosca java model from the tosca input artifact
1476 * @param input Input tosca file and its metadata information as {@link Artifact} object
1477 * @return Translated {@link ToscaTemplate tosca} object
1479 private ToscaTemplate getToscaModel(Artifact input) throws SecurityException {
1480 byte[] decodedInput = GeneratorUtil.decoder(input.getPayload());
1481 String checksum = GeneratorUtil.checkSum(decodedInput);
1482 if (checksum.equals(input.getChecksum())) {
1484 return GeneratorUtil.translateTosca(new String(decodedInput), ToscaTemplate.class);
1485 } catch (Exception e) {
1486 e.printStackTrace();
1487 throw new IllegalArgumentException(
1488 String.format(GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_TOSCA, input.getName()));
1491 throw new SecurityException(
1492 String.format(GeneratorConstants.GENERATOR_AAI_ERROR_CHECKSUM_MISMATCH, input.getName()));
1497 * Identify the service tosca artifact from the list of translated tosca inputs
1499 * @param input List of translated {@link ToscaTemplate tosca} object models
1500 * @return Identified service {@link ToscaTemplate tosca}
1502 private ToscaTemplate getServiceTosca(List<ToscaTemplate> input) {
1503 Iterator<ToscaTemplate> iter = input.iterator();
1504 while (iter.hasNext()) {
1505 ToscaTemplate tosca = iter.next();
1506 if (tosca.isService()) {
1514 private Map<String, String> getVFModuleMetadataTosca(ToscaTemplate toscaTemplate,
1515 String vfModuleModelUUID) {
1516 Map<String, GroupDefinition> groupDefinitionMap =
1517 toscaTemplate.getTopology_template().getGroups();
1518 Map<String, String> vfModuleModelMetadata = new LinkedHashMap<>();
1519 for (Map.Entry<String, GroupDefinition> e : groupDefinitionMap.entrySet()) {
1520 if (e.getValue().getType().contains("org.openecomp.groups.VfModule")) {
1521 String uuid = e.getValue().getMetadata().get("vfModuleModelUUID");
1522 if (Objects.equals(uuid, vfModuleModelUUID)) {
1523 vfModuleModelMetadata = e.getValue().getMetadata();
1524 vfModuleModelMetadata.put("vf_module_description",
1525 (String) e.getValue().getProperties().get("vf_module_description"));
1529 return vfModuleModelMetadata;
1532 private Map<String, Object> getVFModuleMembersTosca(ToscaTemplate toscaTemplate,
1533 String vfModuleModelUUID) {
1534 Map<String, GroupDefinition> groupDefinitionMap =
1535 toscaTemplate.getTopology_template().getGroups();
1536 Map<String, NodeTemplate> nodeTemplateMaps =
1537 toscaTemplate.getTopology_template().getNode_templates();
1538 Map<String, Object> vfModuleMembers = new LinkedHashMap<>();
1539 List<String> vfModuleModelMetadata;
1540 for (Map.Entry<String, GroupDefinition> e : groupDefinitionMap.entrySet()) {
1541 if (e.getValue().getType().contains("org.openecomp.groups.VfModule")) {
1542 String uuid = e.getValue().getMetadata().get("vfModuleModelUUID");
1543 if (Objects.equals(uuid, vfModuleModelUUID)) {
1544 vfModuleModelMetadata = e.getValue().getMembers();
1545 if (vfModuleModelMetadata !=null) {
1546 for (Object key : vfModuleModelMetadata) {
1547 NodeTemplate nodeTemplate = nodeTemplateMaps.get(key);
1548 String nodetype = null;
1549 if (nodeTemplate != null) {
1550 nodetype = nodeTemplate.getType();
1552 if (nodetype != null) {
1553 String widgetType = membersType(nodetype);
1554 if (widgetType != null) {
1555 vfModuleMembers.put(widgetType, key);
1564 return vfModuleMembers;
1568 private String membersType(String toscaType) {
1569 String modelToBeReturned = null;
1570 while (toscaType != null && toscaType.lastIndexOf(".") != -1 && modelToBeReturned == null) {
1572 switch (toscaType) {
1573 case "org.openecomp.resource.vf.allottedResource":
1574 modelToBeReturned = "allotted-resource";
1576 case "org.openecomp.resource.vfc":
1577 modelToBeReturned = "vserver";
1579 case "org.openecomp.resource.cp":
1580 case "org.openecomp.cp":
1581 modelToBeReturned = "l-interface";
1583 case "org.openecomp.resource.vl":
1584 modelToBeReturned = "l3-network";
1586 case "org.openecomp.resource.vf":
1587 modelToBeReturned = "generic-vnf";
1589 case "org.openecomp.groups.VfModule":
1590 modelToBeReturned = "vf-module";
1592 case "org.openecomp.resource.vfc.nodes.heat.cinder":
1593 modelToBeReturned = "volume";
1596 modelToBeReturned = null;
1600 toscaType = toscaType.substring(0, toscaType.lastIndexOf("."));
1602 return modelToBeReturned;
1605 private List<Artifact> init(String aaiResourceBasePaths) {
1606 List<Artifact> inputArtifacts1 = new ArrayList<>();
1609 String[] resourceFileList = {};
1610 URL resourceDirUrl = this.getClass().getClassLoader().getResource(aaiResourceBasePaths);
1611 if (resourceDirUrl != null && resourceDirUrl.getProtocol().equals("file")) {
1612 resourceFileList = new File(resourceDirUrl.toURI()).list();
1614 Assert.fail("Invalid resource directory");
1617 for (String aResourceFileList : resourceFileList) {
1618 File resourceFile = new File(
1619 this.getClass().getClassLoader().getResource(aaiResourceBasePaths + aResourceFileList)
1622 //convert service tosca file into array of bytes
1623 byte[] payload = new byte[(int) resourceFile.length()];
1624 try (FileInputStream fileInputStream = new FileInputStream(resourceFile)) {
1625 fileInputStream.read(payload);
1628 String checksum = GeneratorUtil.checkSum(payload);
1629 byte[] encodedPayload = GeneratorUtil.encode(payload);
1631 new Artifact(aaiArtifactType, aaiArtifactGroupType, checksum, encodedPayload);
1632 artifact.setName(aResourceFileList);
1633 artifact.setLabel(aResourceFileList);
1634 artifact.setDescription(aResourceFileList);
1635 artifact.setVersion("1.0");
1636 inputArtifacts1.add(artifact);
1639 } catch (Exception e) {
1640 //e.printStackTrace();
1641 Assert.fail(e.getMessage());
1643 return inputArtifacts1;
1646 private void loadConfigFromClasspath(Properties properties) throws IOException {
1647 String configLocation = System.getProperty("artifactgenerator.config");
1648 if (configLocation != null) {
1649 File file = new File(configLocation);
1650 if (file.exists()) {
1651 properties.load(new FileInputStream(file));
1656 public void testResourceTosca(Iterator<ToscaTemplate> itr, Map<String, Model>
1657 outputArtifactMap) {
1658 while(itr.hasNext()){
1659 ToscaTemplate toscaTemplate = itr.next();
1660 String resourceVersion=resourcesVersion.get(toscaTemplate.getMetadata().get("UUID"));
1661 toscaTemplate.getMetadata().put("version", resourceVersion);
1662 if("VF".equals(toscaTemplate.getMetadata().get("type")) && !("Allotted Resource".equals
1663 (toscaTemplate.getMetadata().get("category"))) ){
1664 testVfTosca(outputArtifactMap, toscaTemplate);
1665 } else if("VF".equals(toscaTemplate.getMetadata().get("type")) && ("Allotted Resource".equals
1666 (toscaTemplate.getMetadata().get("category"))) ){
1667 testAllottedResourceTosca(outputArtifactMap, toscaTemplate);
1668 } else if("VL".equals(toscaTemplate.getMetadata().get("type"))){
1669 testL3NetworkResourceTosca(outputArtifactMap, toscaTemplate);
1674 private void readPayloadFromResource(List<Artifact> inputArtifacts, String file) throws IOException {
1675 try (InputStream stream = ArtifactGenerationServiceTest.class.getResourceAsStream("/" + file)) {
1676 readPayload(inputArtifacts, stream, file);