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;
58 import javax.xml.bind.JAXBContext;
59 import javax.xml.bind.JAXBException;
60 import javax.xml.bind.Unmarshaller;
62 @SuppressWarnings("Duplicates")
63 public class ArtifactGenerationServiceTest {
65 private static final String aaiArtifactType = ArtifactType.AAI.name();
66 private static final String aaiArtifactGroupType = GroupType.DEPLOYMENT.name();
67 private static final String generatorConfig = "{\"artifactTypes\": [\"OTHER\",\"AAI\"]}";
68 private final Properties properties = new Properties();
69 private final Map<String, String> additionalParams = new HashMap<>();
70 private final Map<String, String> resourcesVersion = new HashMap<>();
73 public void loadProperties() throws Exception{
74 loadConfigFromClasspath(properties);
75 additionalParams.put(AdditionalParams.ServiceVersion.getName(), "1.0");
79 public void testArtifactGeneration() {
80 // Sunny day scenario service with VF anf vfmodule
83 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
84 List<ToscaTemplate> toscas = new LinkedList<>();
85 String aaiResourceBasePaths = "aai/";
86 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
87 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
88 if (data.getErrorData().isEmpty()) {
89 for (Artifact inputArtifact : inputArtifacts) {
90 toscas.add(getToscaModel(inputArtifact));
92 List<Artifact> resultData = data.getResultData();
94 /*for( int i = 0 ; i < resultData.size() ; i++) {
95 Artifact artifact = resultData.get(i);
96 String fileName = artifact.getName();
97 while(fileName.contains(":")){
98 fileName = fileName.replace(":","");
100 File targetFile =new File("src/test/resources/"+fileName);
101 OutputStream outStream = new FileOutputStream(targetFile);
102 outStream.write(Base64.getDecoder().decode(artifact.getPayload()));
105 Assert.assertEquals(resultData.size(),5); // 1-service,1-VF-resource,1-vfmodule and 2
107 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
108 testServiceTosca(toscas, outputArtifactMap);
109 testResourceTosca(toscas.iterator(), outputArtifactMap);
111 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
114 } catch (Exception e) {
115 Assert.fail(e.getMessage());
120 public void testWidgetinServiceTosca() {
121 // Sunny day scenario service with VF and extra widget like CP anf vf has vfmodule without
124 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
125 List<ToscaTemplate> toscas = new LinkedList<>();
126 String aaiResourceBasePaths = "testWidgetinServiceTosca/";
127 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
128 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
129 if (data.getErrorData().isEmpty()) {
130 for (Artifact inputArtifact : inputArtifacts) {
131 toscas.add(getToscaModel(inputArtifact));
133 List<Artifact> resultData = data.getResultData();
134 Assert.assertEquals(resultData.size(),5); // 1-service,1-VF-resource,1-vfmodule and 2
136 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
137 testServiceTosca(toscas, outputArtifactMap);
138 testResourceTosca(toscas.iterator(), outputArtifactMap);
140 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
143 } catch (Exception e) {
144 Assert.fail(e.getMessage());
149 public void testSameVLdifferentVersion() {
150 // Sunny day scenario service with VF and extra widget like CP anf vf has vfmodule without
153 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
154 List<ToscaTemplate> toscas = new LinkedList<>();
155 String aaiResourceBasePaths = "testSameVLdifferentVersion/";
156 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
157 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
158 if (data.getErrorData().isEmpty()) {
159 for (Artifact inputArtifact : inputArtifacts) {
160 toscas.add(getToscaModel(inputArtifact));
162 List<Artifact> resultData = data.getResultData();
163 Assert.assertEquals(resultData.size(),8);
165 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
166 testServiceTosca(toscas, outputArtifactMap);
167 testResourceTosca(toscas.iterator(), outputArtifactMap);
169 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
172 } catch (Exception e) {
173 Assert.fail(e.getMessage());
178 public void testArtifactGenerationAllottedResourceAndL3Network() {
179 // Sunny day scenario service with allotted resource and L3-network
181 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
182 List<ToscaTemplate> toscas = new LinkedList<>();
183 String aaiResourceBasePaths = "aai2/";
184 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
185 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
186 if (data.getErrorData().isEmpty()) {
187 for (Artifact inputArtifact : inputArtifacts) {
188 toscas.add(getToscaModel(inputArtifact));
190 List<Artifact> resultData = data.getResultData();
192 Assert.assertEquals(resultData.size(),5);
195 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
196 testServiceTosca(toscas, outputArtifactMap);
197 testResourceTosca(toscas.iterator(), outputArtifactMap);
199 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
202 } catch (Exception e) {
203 Assert.fail(e.getMessage());
207 @Test(dependsOnMethods = {"testArtifactGeneration"})
208 public void testWhenMissingTosca() {
210 //Missing Service tosca test case
211 String aaiResourceBasePaths = "testArtifactGeneration2/";
212 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
213 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
214 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
215 Assert.assertEquals(data.getErrorData().get("AAI").get(0),"Service tosca missing from list of input artifacts");
216 } catch (Exception e) {
217 Assert.fail(e.getMessage());
221 @Test(dependsOnMethods = {"testWhenMissingTosca"})
222 public void testWhenInvaildConfig() {
224 //Invalid config test case
225 String generatorConfig1 = "{\"artifactTypes\": [\"ABC\"]}";
226 String aaiResourceBasePaths = "testArtifactGeneration2/";
227 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
228 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
229 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig1, additionalParams);
230 Assert.assertEquals(data.getErrorData().get("ARTIFACT_GENERATOR_INVOCATION_ERROR").get(0),"Invalid Client Configuration");
231 } catch (Exception e) {
232 Assert.fail(e.getMessage());
236 @Test(dependsOnMethods = {"testArtifactGeneration"})
237 public void testWhenOnlyServToscaNoResTosca() {
239 //Testing only service tosca no resource Tosca
240 String aaiResourceBasePaths = "testArtifactGeneration4/";
241 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
242 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
243 List<ToscaTemplate> toscas = new LinkedList<>();
244 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
245 List<Artifact> resultData = data.getResultData();
246 if (data.getErrorData().isEmpty()) {
247 for (Artifact inputArtifact : inputArtifacts) {
248 toscas.add(getToscaModel(inputArtifact));
251 Assert.assertEquals(resultData.size(),3); // 1-service and 2-Others
252 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
253 testServiceTosca(toscas, outputArtifactMap);
254 } catch (Exception e) {
255 Assert.fail(e.getMessage());
259 @Test(dependsOnMethods = {"testArtifactGeneration"})
260 public void testWhenInvaildYaml() {
262 //Invalid Yaml file test case
263 String aaiResourceBasePaths = "testArtifactGeneration5/";
264 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
265 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
266 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
267 Assert.assertEquals(data.getErrorData().get("AAI").get(0),"Invalid format for Tosca YML : " + inputArtifacts.get(0).getName());
268 } catch (Exception e) {
269 Assert.fail(e.getMessage());
273 @Test(dependsOnMethods = {"testArtifactGeneration"})
274 public void testWhenExtraResToscaNotPartOfServ() {
276 // Valid scenario with extra resource tosca which is not part of Service
277 String aaiResourceBasePaths = "testArtifactGeneration6/";
278 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
279 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
280 List<ToscaTemplate> toscas = new LinkedList<>();
281 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
282 List<Artifact> resultData = data.getResultData();
283 if (data.getErrorData().isEmpty()) {
284 for (Artifact inputArtifact : inputArtifacts) {
285 toscas.add(getToscaModel(inputArtifact));
288 Assert.assertEquals(resultData.size(),3); // 1-service and 2 Others
289 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
290 testServiceTosca(toscas, outputArtifactMap);
291 } catch (Exception e) {
292 Assert.fail(e.getMessage());
298 public void testWhenInvUuIdAttrMissing() {
300 // mandatory attribute <invariantUUID> missing
301 String aaiResourceBasePaths = "testArtifactGeneration8/";
302 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
303 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
304 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
306 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <invariantUUID> missing in Artifact: <" +
307 inputArtifacts.get(0).getName() + ">");
309 } catch (Exception e) {
310 Assert.fail(e.getMessage());
315 public void testErrorWhenInvalidInvId() {
317 //Invariant Id in service tosca of length not 36
318 String aaiResourceBasePaths = "testErrorWhenInvalidInvId/";
319 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
320 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
321 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
323 data.getErrorData().get("AAI").get(0),String.format(
324 GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_ID,
325 "invariantUUID",inputArtifacts.get(0).getName()));
327 } catch (Exception e) {
328 Assert.fail(e.getMessage());
333 public void testWhenUuIdAttrMissing() {
335 //mandatory attribute <UUID> missing
336 String aaiResourceBasePaths = "testArtifactGeneration9/";
337 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
338 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
339 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
341 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <UUID> missing in Artifact: <" +
342 inputArtifacts.get(0).getName() + ">");
344 } catch (Exception e) {
345 Assert.fail(e.getMessage());
350 public void testErrorWhenInvalidUuId() {
352 //UUID Id in service tosca of length not 36
353 String aaiResourceBasePaths = "testErrorWhenInvalidUuId/";
354 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
355 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
356 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
358 data.getErrorData().get("AAI").get(0),String.format(
359 GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_ID,
360 "UUID",inputArtifacts.get(0).getName()));
362 } catch (Exception e) {
363 Assert.fail(e.getMessage());
368 public void testWhenNameAttrMissing() {
370 //mandatory attribute <name> missing
371 String aaiResourceBasePaths = "testArtifactGeneration10/";
372 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
373 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
374 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
376 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <name> missing in Artifact: <" +
377 inputArtifacts.get(0).getName() + ">");
379 } catch (Exception e) {
380 Assert.fail(e.getMessage());
384 @Test //(dependsOnMethods = {"testArtifactGeneration"})
385 public void testWhenVfModInvUuIdAttrMissing() {
387 //mandatory attribute <vfModuleModelInvariantUUID> missing
388 List<Artifact> inputArtifacts = new ArrayList<>();
389 readPayloadFromResource(inputArtifacts, "service_vmme_template_ModInvUUID.yml");
390 readPayloadFromResource(inputArtifacts, "vf_vmme_template_ModInvUUID.yml");
391 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
392 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
394 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <vfModuleModelInvariantUUID> missing in Artifact: <" +
395 inputArtifacts.get(1).getName() + ">");
397 } catch (Exception e) {
398 Assert.fail(e.getMessage());
402 public static void readPayload(List<Artifact> inputArtifacts, InputStream fis, String fileName) throws
404 byte[] payload = new byte[fis.available()];
406 String checksum = GeneratorUtil.checkSum(payload);
407 byte[] encodedPayload = GeneratorUtil.encode(payload);
408 Artifact artifact = new Artifact(aaiArtifactType, aaiArtifactGroupType, checksum, encodedPayload);
409 artifact.setName(fileName);
410 artifact.setLabel(fileName);
411 artifact.setDescription(fileName);
412 artifact.setVersion("1.0");
413 System.out.println(artifact.getName());
414 inputArtifacts.add(artifact);
418 public void testWhenInvalidVfModInvUuIdAttr() {
420 //invalid id since not of length 36 for <vfModuleModelInvariantUUID>
421 List<Artifact> inputArtifacts = new ArrayList<>();
422 readPayloadFromResource(inputArtifacts, "service_vmme_template_InvalidVfModInvUuIdAttr.yml");
424 readPayloadFromResource(inputArtifacts, "vf_vmme_template_InvalidVfModInvUuIdAttr.yml");
425 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
426 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
428 data.getErrorData().get("AAI").get(0),String.format(
429 GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_ID,
430 "vfModuleModelInvariantUUID", inputArtifacts.get(1).getName() ));
432 } catch (Exception e) {
433 Assert.fail(e.getMessage());
437 @Test //(dependsOnMethods = {"testArtifactGeneration"})
438 public void testWhenVfModNameAttrMissing() {
440 //mandatory attribute <vfModuleModelName> missing
441 List<Artifact> inputArtifacts = new ArrayList<>();
442 readPayloadFromResource(inputArtifacts, "service_vmme_template_ModelName.yml");
444 readPayloadFromResource(inputArtifacts, "vf_vmme_template_ModelName.yml");
445 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
446 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
448 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <vfModuleModelName> missing in Artifact: <" +
449 inputArtifacts.get(1).getName() + ">");
451 } catch (Exception e) {
452 Assert.fail(e.getMessage());
456 /*public static void readPayload(List<Artifact> inputArtifacts,InputStream fis, String fileName)
459 byte[] payload = new byte[fis.available()];
461 String checksum = GeneratorUtil.checkSum(payload);
462 byte[] encodedPayload = GeneratorUtil.encode(payload);
463 Artifact artifact = new Artifact(aaiArtifactType, aaiArtifactGroupType, checksum, encodedPayload);
464 artifact.setName(fileName);
465 artifact.setLabel(fileName);
466 artifact.setDescription(fileName);
467 artifact.setVersion("1.0");
468 System.out.println(artifact.getName());
469 inputArtifacts.add(artifact);
472 @Test //(dependsOnMethods = {"testArtifactGeneration"})
473 public void testWhenVfModUuIdAttrMissing() {
475 //mandatory attribute <vfModuleModelUUID> missing in Artifact
476 List<Artifact> inputArtifacts = new ArrayList<>();
477 readPayloadFromResource(inputArtifacts, "service_vmme_template_ModelUUID.yml");
479 readPayloadFromResource(inputArtifacts, "vf_vmme_template_ModelUUID.yml");
480 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
481 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
483 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory " +
484 "attribute <vfModuleModelUUID> missing in Artifact: <" +
485 inputArtifacts.get(1).getName() + ">");
487 } catch (Exception e) {
488 Assert.fail(e.getMessage());
493 public void testWhenInvalidVfModUuIdAttr() {
495 //invalid id since not of length 36 for <vfModuleModelUUID>
496 List<Artifact> inputArtifacts = new ArrayList<>();
497 readPayloadFromResource(inputArtifacts, "service_vmme_template_InvalidVfModUuIdAttr.yml");
499 readPayloadFromResource(inputArtifacts, "vf_vmme_template_InvalidVfModUuIdAttr.yml");
500 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
501 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
503 data.getErrorData().get("AAI").get(0),String.format(
504 GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_ID,
505 "vfModuleModelUUID", inputArtifacts.get(1).getName() ));
507 } catch (Exception e) {
508 Assert.fail(e.getMessage());
512 @Test //(dependsOnMethods = {"testArtifactGeneration"})
513 public void testWhenVfModVersionAttrMissing() {
515 //mandatory attribute <vfModuleModelVersion> missing
516 List<Artifact> inputArtifacts = new ArrayList<>();
517 readPayloadFromResource(inputArtifacts, "service_vmme_template_ModelVersion.yml");
519 readPayloadFromResource(inputArtifacts, "vf_vmme_template_ModelVersion.yml");
520 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
521 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
523 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <vfModuleModelVersion> missing in Artifact: <" +
524 inputArtifacts.get(1).getName() + ">");
526 } catch (Exception e) {
527 Assert.fail(e.getMessage());
532 public void testErrorWhenNoSystemPropConfigured() throws Exception {
533 String configLoc = System.getProperty("artifactgenerator.config");
535 System.clearProperty("artifactgenerator.config");
536 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
537 String aaiResourceBasePaths = "aai/";
538 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
539 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
540 Assert.assertEquals(false,data.getErrorData().isEmpty());
541 Assert.assertEquals(data.getErrorData().
542 get("AAI").get(0), GeneratorConstants.GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND);
543 } catch (Exception e) {
544 Assert.fail(e.getMessage());
547 System.setProperty("artifactgenerator.config",configLoc);
552 public void testErrorWhenNoWidgetInConfig() throws Exception {
553 String configLoc = System.getProperty("artifactgenerator.config");
554 final File configFile = new File(configLoc);
555 String configDir = configLoc.substring(0, configLoc.lastIndexOf(File.separator));
556 final File tempFile = new File(configDir + File.separator + "temp.properties");
558 //copy orignal Artifact-Generator.properties to temp.properties for backup
559 FileUtils.copyFile(configFile, tempFile);
561 String serviceWidgetName = ArtifactType.AAI.name()+".model-version-id."+Widget.getWidget
562 (Widget.Type.SERVICE)
564 String assertMsg = ArtifactType.AAI.name() + ".model-version-id." +Widget.getWidget
565 (Widget.Type.SERVICE).getName();
567 //Remove property from Artifact-Generator.properties
568 properties.remove(serviceWidgetName);
569 try (OutputStream fos = new FileOutputStream(new File(configLoc))) {
570 properties.store(fos,null);
573 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
574 String aaiResourceBasePaths = "aai/";
575 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
576 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
577 Assert.assertEquals(false,data.getErrorData().isEmpty());
578 String errMsg = String.format(GeneratorConstants.GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,assertMsg);
579 Assert.assertEquals(data.getErrorData().get("AAI").get(0),errMsg);
580 } catch (Exception e) {
581 Assert.fail(e.getMessage());
584 if(tempFile.exists()){
586 FileUtils.copyFile(tempFile, configFile);
587 loadConfigFromClasspath(properties);
594 public void testErrorWhenNoFileAtConfigLocation() throws Exception {
595 String configLoc = System.getProperty("artifactgenerator.config");
597 System.setProperty("artifactgenerator.config",configLoc + File.separator + "testErrorWhenNoFileAtConfigLocation");
598 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
599 String aaiResourceBasePaths = "aai/";
600 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
601 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
602 Assert.assertEquals(data.getErrorData().isEmpty(),false);
603 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format(
604 GeneratorConstants.GENERATOR_AAI_CONFIGFILE_NOT_FOUND,System.getProperty
605 ("artifactgenerator.config")));
606 } catch (Exception e) {
607 Assert.fail(e.getMessage());
610 System.setProperty("artifactgenerator.config",configLoc);
615 public void testErrorWhenNoServiceVersion() {
616 // scenario service with VF anf vfmodule but no service version in additional parameter
618 additionalParams.clear();
619 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
620 String aaiResourceBasePaths = "aai/";
621 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
622 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
623 Assert.assertEquals(data.getErrorData().isEmpty(),false);
624 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
625 GeneratorConstants.GENERATOR_AAI_ERROR_MISSING_SERVICE_VERSION);
626 } catch (Exception e) {
627 Assert.fail(e.getMessage());
630 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
635 public void testArtifactGenerationWithServiceVersion() {
636 // Sunny day scenario service with VF anf vfmodule and service version as adiitional parameter
638 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"9.0");
639 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
640 List<ToscaTemplate> toscas = new LinkedList<>();
641 String aaiResourceBasePaths = "aai/";
642 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
643 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
644 if (data.getErrorData().isEmpty()) {
645 for (Artifact inputArtifact : inputArtifacts) {
646 toscas.add(getToscaModel(inputArtifact));
648 List<Artifact> resultData = data.getResultData();
650 /*for( int i = 0 ; i < resultData.size() ; i++) {
651 Artifact artifact = resultData.get(i);
652 String fileName = artifact.getName();
653 while(fileName.contains(":")){
654 fileName = fileName.replace(":","");
656 File targetFile =new File("src/test/resources/"+fileName);
657 OutputStream outStream = new FileOutputStream(targetFile);
658 outStream.write(Base64.getDecoder().decode(artifact.getPayload()));
661 Assert.assertEquals(resultData.size(),5); // 1-service,1-VF-resource,1-vfmodule and 2
663 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
664 testServiceTosca(toscas, outputArtifactMap);
665 testResourceTosca(toscas.iterator(), outputArtifactMap);
667 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
670 } catch (Exception e) {
671 Assert.fail(e.getMessage());
674 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
679 public void testErrorWhenInvalidServiceVersion() {
680 // scenario service with VF anf vfmodule but invalid service version in additional parameter
682 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
683 String aaiResourceBasePaths = "aai/";
684 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
686 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1");
687 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
688 Assert.assertEquals(data.getErrorData().isEmpty(),false);
689 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
690 GeneratorConstants.GENERATOR_AAI_INVALID_SERVICE_VERSION);
692 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.1");
693 data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
694 Assert.assertEquals(data.getErrorData().isEmpty(),false);
695 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
696 GeneratorConstants.GENERATOR_AAI_INVALID_SERVICE_VERSION);
698 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.0");
699 data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
700 Assert.assertEquals(data.getErrorData().isEmpty(),false);
701 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
702 GeneratorConstants.GENERATOR_AAI_INVALID_SERVICE_VERSION);
704 } catch (Exception e) {
705 Assert.fail(e.getMessage());
708 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
713 public void testMissingResourceTosca() {
715 //Service with resource but seperate resource tosca not coming as input.
716 String aaiResourceBasePaths = "missingResourceTosca/";
717 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
718 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
719 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
720 Assert.assertEquals(data.getErrorData().get("AAI").get(0),"Cannot generate artifacts. Resource Tosca missing for resource with UUID: <b020ed1e-4bc7-4fc0-ba7e-cc7af6da7ffc>");
721 } catch (Exception e) {
722 Assert.fail(e.getMessage());
726 public void testMissingVLTosca() {
728 //Service with VL but seperate VL tosca not coming as input artifact.
729 String aaiResourceBasePaths = "missingVLTosca/";
730 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
731 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
732 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
733 Assert.assertEquals(data.getErrorData().get("AAI").get(0),"Cannot generate artifacts. Resource Tosca missing for resource with UUID: <3f8fa4d2-2b86-4b36-bbc8-ffb8f9f57468>");
734 } catch (Exception e) {
735 Assert.fail(e.getMessage());
740 public void testErrorWhenNoResourceVersion() {
741 // scenario service with VF but missing resource version in service tosca
743 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
744 String aaiResourceBasePaths = "testErrorWhenNoResourceVersion/";
745 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
746 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
747 Assert.assertEquals(data.getErrorData().isEmpty(),false);
748 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
749 "Invalid Service definition mandatory attribute version missing for resource with UUID: <b020ed1e-4bc7-4fc0-ba7e-cc7af6da7ffc>");
750 } catch (Exception e) {
751 Assert.fail(e.getMessage());
756 public void testErrorWhenInvalidResourceVersion1() {
757 // scenario service with VF but invalid resource version 0.0 in service tosca
759 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
760 String aaiResourceBasePaths = "testErrorWhenInvalidResourceVersion1/";
761 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
762 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
763 Assert.assertEquals(data.getErrorData().isEmpty(),false);
764 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
765 "Cannot generate artifacts. Invalid Resource version in Service tosca for resource with UUID: <b020ed1e-4bc7-4fc0-ba7e-cc7af6da7ffc>");
766 } catch (Exception e) {
767 Assert.fail(e.getMessage());
772 public void testErrorWhenInvalidResourceVersion2() {
773 // scenario service with VF but invalid resource version 1 in service tosca
775 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
776 String aaiResourceBasePaths = "testErrorWhenInvalidResourceVersion2/";
777 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
778 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
779 Assert.assertEquals(data.getErrorData().isEmpty(),false);
780 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
781 "Cannot generate artifacts. Invalid Resource version in Service tosca for resource with UUID: <b020ed1e-4bc7-4fc0-ba7e-cc7af6da7ffc>");
782 } catch (Exception e) {
783 Assert.fail(e.getMessage());
788 public void testArtifactGenerationAllottedResourceWithIpMuxAndTunnelXConn() {
790 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
791 List<ToscaTemplate> toscas = new LinkedList<>();
792 String aaiResourceBasePaths = "testArtifactGeneration15/";
793 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
794 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
795 if (data.getErrorData().isEmpty()) {
796 for (Artifact inputArtifact : inputArtifacts) {
797 toscas.add(getToscaModel(inputArtifact));
799 List<Artifact> resultData = data.getResultData();
801 Assert.assertEquals(resultData.size(),5);
802 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
803 testServiceTosca(toscas, outputArtifactMap);
804 testResourceTosca(toscas.iterator(), outputArtifactMap);
806 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
809 } catch (Exception e) {
810 Assert.fail(e.getMessage());
815 public void testErrorWhenAllottedResourceWithOutProvidingServiceId() {
817 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
818 String aaiResourceBasePaths = "testErrorWhenAllottedResourceWithOutDependingServiceId/";
819 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
820 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
821 Assert.assertEquals(data.getErrorData().isEmpty(),false);
822 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format
823 (GeneratorConstants.GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING, "707b2850-e830-4b00-9902-879f44ac05a4"));
824 } catch (Exception e) {
825 Assert.fail(e.getMessage());
830 public void testArtifactGenerationWithoutAllottedResource() {
832 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
833 String aaiResourceBasePaths = "testArtifactGeneration16/";
834 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
835 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
836 Assert.assertEquals(data.getErrorData().isEmpty(),false);
837 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format
838 (GeneratorConstants.GENERATOR_AAI_PROVIDING_SERVICE_MISSING, "a54a5235-b69d-4f8a-838b-d011e6783fa5"));
839 } catch (Exception e) {
840 Assert.fail(e.getMessage());
845 public void testArtifactGenerationAllottedResourceIpmuxSameInvariantDiffVersion() {
847 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
848 List<ToscaTemplate> toscas = new LinkedList<>();
849 String aaiResourceBasePaths = "testArtifactGeneration17/";
850 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
851 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
852 if (data.getErrorData().isEmpty()) {
853 for (Artifact inputArtifact : inputArtifacts) {
854 toscas.add(getToscaModel(inputArtifact));
856 List<Artifact> resultData = data.getResultData();
858 Assert.assertEquals(resultData.size(),5);
859 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
860 testServiceTosca(toscas, outputArtifactMap);
861 testResourceTosca(toscas.iterator(), outputArtifactMap);
863 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
866 } catch (Exception e) {
867 Assert.fail(e.getMessage());
872 public void testArtifactGenerationAllottedResourceIpmuxSameInvariantSameVersion() {
874 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
875 List<ToscaTemplate> toscas = new LinkedList<>();
876 String aaiResourceBasePaths = "testArtifactGeneration18/";
877 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
878 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
879 if (data.getErrorData().isEmpty()) {
880 for (Artifact inputArtifact : inputArtifacts) {
881 toscas.add(getToscaModel(inputArtifact));
883 List<Artifact> resultData = data.getResultData();
886 Assert.assertEquals(resultData.size(),4);
887 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
888 testServiceTosca(toscas, outputArtifactMap);
889 testResourceTosca(toscas.iterator(), outputArtifactMap);
891 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
894 } catch (Exception e) {
895 Assert.fail(e.getMessage());
900 public void testArtifactGenerationAllottedResourceIpmuxWithGroups() {
902 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
903 List<ToscaTemplate> toscas = new LinkedList<>();
904 String aaiResourceBasePaths = "testAllotedResourceWithDependingSerWithGroups/";
905 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
906 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
907 if (data.getErrorData().isEmpty()) {
908 for (Artifact inputArtifact : inputArtifacts) {
909 toscas.add(getToscaModel(inputArtifact));
911 List<Artifact> resultData = data.getResultData();
913 Assert.assertEquals(resultData.size(),5);
914 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
915 testServiceTosca(toscas, outputArtifactMap);
916 testResourceTosca(toscas.iterator(), outputArtifactMap);
918 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
921 } catch (Exception e) {
922 Assert.fail(e.getMessage());
927 public void testArtifactGenerationAllottedResourceWithVF() {
929 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
930 List<ToscaTemplate> toscas = new LinkedList<>();
931 String aaiResourceBasePaths = "testArtifactGenerationAllottedResourceWithVF/";
932 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
933 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
934 if (data.getErrorData().isEmpty()) {
935 for (Artifact inputArtifact : inputArtifacts) {
936 toscas.add(getToscaModel(inputArtifact));
938 List<Artifact> resultData = data.getResultData();
940 Assert.assertEquals(resultData.size(),7);
941 Map<String, Model> outputArtifactMap = populateAAIGeneratedModelStore(resultData);
942 testServiceTosca(toscas, outputArtifactMap);
943 testResourceTosca(toscas.iterator(), outputArtifactMap);
945 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
948 } catch (Exception e) {
949 Assert.fail(e.getMessage());
955 public void testServiceTosca(List<ToscaTemplate> toscas, Map<String, Model> outputArtifactMap) {
957 ToscaTemplate serviceTosca = getServiceTosca(toscas);
958 if (serviceTosca == null) {
959 Assert.fail("Service Tosca not found");
961 serviceTosca.getMetadata().put("version", "1.0");
962 Service service = new Service();
963 service.populateModelIdentificationInformation(serviceTosca.getMetadata());
964 String serviceNameVersionId = service.getModelNameVersionId();
965 Model serviceAAIModel = getAAIModelByNameVersionId(serviceNameVersionId, outputArtifactMap);
966 validateServiceModelMetadata(service, serviceAAIModel);
967 //Validate Service instance base widget
968 ModelVer modelVersion = serviceAAIModel.getModelVers().getModelVer().get(0);
970 List<ModelElement> matchedServiceBaseWidgetElements =
971 getModelElementbyRelationshipValue( modelVersion.getModelElements(),
972 Widget.getWidget(Widget.Type.SERVICE).getId());
973 validateMatchedModelElementsInService(matchedServiceBaseWidgetElements,
974 Widget.getWidget(Widget.Type.SERVICE).getName());
976 validateWidgetIds(matchedServiceBaseWidgetElements, Widget.getWidget(Widget.Type.SERVICE).getName(),
977 Widget.getWidget(Widget.Type.SERVICE).getWidgetId());
979 ModelElements baseServiceWidgetModelElements =
980 matchedServiceBaseWidgetElements.get(0).getModelElements();
983 Map<String, String> nodeTemplateIdTypeStore = getNodeTemplateTypeStore(serviceTosca);
984 if (nodeTemplateIdTypeStore != null) {
985 for (String key : nodeTemplateIdTypeStore.keySet()) {
986 if (nodeTemplateIdTypeStore.get(key).contains("org.openecomp.resource.vf")) {
987 List<ModelElement> matchedResourceElements =
988 getModelElementbyRelationshipValue(baseServiceWidgetModelElements, key);
989 if (nodeTemplateIdTypeStore.get(key).contains("org.openecomp.resource.vf.allottedResource")){
990 validateMatchedModelElementsInService(matchedResourceElements,
991 Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getName());
993 validateMatchedModelElementsInService(matchedResourceElements,
994 Widget.getWidget(Widget.Type.VF).getName());
997 //Validate uuid and invariantuuid are populated in model-ver.model-version-id and model.model-invariant-id
998 Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList()
999 .getRelationship().get(0)
1000 .getRelationshipData().get(0).getRelationshipValue(),key);
1002 Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList().getRelationship().get(0)
1003 .getRelationshipData().get(1).getRelationshipValue(), nodeTemplateIdTypeStore
1004 .get(key+"-INV_UID"));
1005 } else if(nodeTemplateIdTypeStore.get(key).contains("org.openecomp.resource.vl")){
1006 //validate l3-network in service tosca
1007 List<ModelElement> matchedResourceElements =
1008 getModelElementbyRelationshipValue(baseServiceWidgetModelElements, key);
1009 validateMatchedModelElementsInService(matchedResourceElements,
1010 Widget.getWidget(Widget.Type.L3_NET).getName());
1011 //Validate uuid and invariantuuid are populated in model-ver.model-version-id and model.model-invariant-id
1012 Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList()
1013 .getRelationship().get(0)
1014 .getRelationshipData().get(0).getRelationshipValue(),key);
1016 Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList().getRelationship().get(0)
1017 .getRelationshipData().get(1).getRelationshipValue(), nodeTemplateIdTypeStore
1018 .get(key+"-INV_UID"));
1023 System.out.println();
1026 } catch (IllegalArgumentException e) {
1027 Assert.fail(e.getMessage()); //Can come while populating metadata
1031 private void validateWidgetIds(List<ModelElement> matchedServiceBaseWidgetElements,
1032 String widgetName, String widgetInvUuId) {
1033 Assert.assertEquals(matchedServiceBaseWidgetElements.get(0).getRelationshipList().getRelationship().get(0)
1034 .getRelationshipData().get(0).getRelationshipValue(), properties.getProperty(ArtifactType.AAI.name()
1035 + ".model-version-id."+ widgetName));
1037 Assert.assertEquals(matchedServiceBaseWidgetElements.get(0).getRelationshipList().getRelationship().get(0)
1038 .getRelationshipData().get(1).getRelationshipValue(), widgetInvUuId);
1042 public void testL3NetworkResourceTosca(Map<String, Model> outputArtifactMap , ToscaTemplate
1045 if (resourceTosca != null) {
1046 Resource resource = new Resource();
1047 resource.populateModelIdentificationInformation(resourceTosca.getMetadata());
1048 String resourceNameVersionId = resource.getModelNameVersionId();
1049 Model resourceAAIModel =
1050 getAAIModelByNameVersionId(resourceNameVersionId, outputArtifactMap);
1051 if (resourceAAIModel != null) {
1052 validateResourceModelMetadata(resource, resourceAAIModel);
1053 //Validate Resource instance base widget
1055 ModelVer modelVersion = resourceAAIModel.getModelVers().getModelVer().get(0);
1057 List<ModelElement> matchedVFBaseWidgetElements =
1058 getModelElementbyRelationshipValue(modelVersion.getModelElements(),
1059 Widget.getWidget(Widget.Type.L3_NET).getId());
1060 validateMatchedModelElementsInService(matchedVFBaseWidgetElements,
1061 Widget.getWidget(Widget.Type.L3_NET).getName());
1063 validateWidgetIds(matchedVFBaseWidgetElements, Widget.getWidget(Widget.Type.L3_NET).getName(),
1064 Widget.getWidget(Widget.Type.L3_NET).getWidgetId());
1067 System.out.println("Resource mapping not found for " + resourceNameVersionId);
1071 }catch (IllegalArgumentException e) {
1072 Assert.fail(e.getMessage()); //Can come while populating metadata
1077 public void testAllottedResourceTosca(Map<String, Model> outputArtifactMap , ToscaTemplate
1080 if (resourceTosca != null) {
1081 Resource resource = new Resource();
1082 resource.populateModelIdentificationInformation(resourceTosca.getMetadata());
1083 String resourceNameVersionId = resource.getModelNameVersionId();
1084 Model resourceAAIModel =
1085 getAAIModelByNameVersionId(resourceNameVersionId, outputArtifactMap);
1086 if (resourceAAIModel != null) {
1087 validateResourceModelMetadata(resource, resourceAAIModel);
1088 //Validate Resource instance base widget
1090 ModelVer modelVersion = resourceAAIModel.getModelVers().getModelVer().get(0);
1092 List<ModelElement> matchedVFBaseWidgetElements =
1093 getModelElementbyRelationshipValue(modelVersion.getModelElements(),
1094 Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getId());
1095 validateMatchedModelElementsInService(matchedVFBaseWidgetElements,
1096 Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getName());
1098 validateWidgetIds(matchedVFBaseWidgetElements, Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getName(),
1099 Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getWidgetId());
1101 Map<String, Object> dependingServiceDetails = getProvidingServiceDetails(resourceTosca);
1103 ModelElements containedModelElements = modelVersion.getModelElements().getModelElement().
1104 get(0).getModelElements();
1105 Assert.assertEquals( containedModelElements.getModelElement().get(0).getRelationshipList()
1106 .getRelationship().get(0).getRelationshipData().get(0).getRelationshipValue(),
1107 dependingServiceDetails.get("providing_service_uuid"));
1109 Assert.assertEquals(containedModelElements.getModelElement().get(0).getRelationshipList()
1110 .getRelationship().get(0).getRelationshipData().get(1).getRelationshipValue(),
1111 dependingServiceDetails.get("providing_service_invariant_uuid"));
1113 if("Allotted Resource".equals(resourceTosca.getMetadata().get("category")) &&
1114 "Tunnel XConnect".equals(resourceTosca.getMetadata().get("subcategory"))) {
1116 List<ModelElement> matchedTunnelXConnectWidgetElements =
1117 getModelElementbyRelationshipValue(containedModelElements,
1118 Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getId());
1119 validateMatchedModelElementsInService(matchedTunnelXConnectWidgetElements,
1120 Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getName());
1122 validateWidgetIds(matchedTunnelXConnectWidgetElements, Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getName(),
1123 Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getWidgetId());
1127 System.out.println("Resource mapping not found for " + resourceNameVersionId);
1131 }catch (IllegalArgumentException e) {
1132 Assert.fail(e.getMessage()); //Can come while populating metadata
1137 public Map<String, Object> getProvidingServiceDetails(ToscaTemplate resourceTemplate) {
1138 Set<String> keys = resourceTemplate.getTopology_template().getNode_templates().keySet();
1140 Map<String, Object> nodeProperties =null;
1141 for(String key : keys) {
1142 NodeTemplate node = resourceTemplate.getTopology_template().getNode_templates().get(key);
1143 if(node.getType().equals("org.openecomp.resource.vfc.AllottedResource")) {
1144 nodeProperties = node.getProperties();
1148 return nodeProperties;
1151 public void testVfTosca(Map<String, Model> outputArtifactMap , ToscaTemplate resourceTosca) {
1153 //ToscaTemplate resourceTosca = getResourceTosca(toscas);
1154 //resourceTosca.getTopology_template().getGroups().
1155 if (resourceTosca != null) {
1156 Resource resource = new Resource();
1157 resource.populateModelIdentificationInformation(resourceTosca.getMetadata());
1158 String resourceNameVersionId = resource.getModelNameVersionId();
1159 Model resourceAAIModel =
1160 getAAIModelByNameVersionId(resourceNameVersionId, outputArtifactMap);
1161 if (resourceAAIModel != null) {
1162 validateResourceModelMetadata(resource, resourceAAIModel);
1163 //Validate Resource instance base widget
1165 ModelVer modelVersion = resourceAAIModel.getModelVers().getModelVer().get(0);
1167 List<ModelElement> matchedVFBaseWidgetElements =
1168 getModelElementbyRelationshipValue(modelVersion.getModelElements(),
1169 Widget.getWidget(Widget.Type.VF).getId());
1170 validateMatchedModelElementsInService(matchedVFBaseWidgetElements,
1171 Widget.getWidget(Widget.Type.VF).getName());
1173 validateWidgetIds(matchedVFBaseWidgetElements, Widget.getWidget(Widget.Type.VF).getName(),
1174 Widget.getWidget(Widget.Type.VF).getWidgetId());
1176 ModelElements baseResourceWidgetModelElements =
1177 matchedVFBaseWidgetElements.get(0).getModelElements();
1178 if (resourceTosca.getTopology_template() != null) {
1179 Map<String, String> groupIdTypeStore = getGroupsTypeStore(resourceTosca);
1181 if (baseResourceWidgetModelElements.getModelElement().size() !=
1182 groupIdTypeStore.size()) {
1183 Assert.fail("Missing VFModule in VF model.xml");
1186 for (String key : groupIdTypeStore.keySet()) {
1188 List<ModelElement> matchedResourceElements =
1189 getModelElementbyRelationshipValue(baseResourceWidgetModelElements, key);
1190 validateMatchedModelElementsInService(matchedResourceElements,
1191 Widget.getWidget(Widget.Type.VFMODULE).getName());
1192 Model resourceAAIVFModel = getAAIModelByNameVersionId(key, outputArtifactMap);
1193 Map<String, String> vfModuleModelMetadata =
1194 getVFModuleMetadataTosca(resourceTosca, key);
1195 Map<String, Object> vfModuleMembers = getVFModuleMembersTosca(resourceTosca, key);
1197 validateVFModelMetadata(vfModuleModelMetadata, resourceAAIVFModel);
1200 ModelVer modelVfVersion = resourceAAIVFModel.getModelVers().getModelVer().get(0);
1202 List<ModelElement> matchedVFModuleBaseWidgetElements =
1203 getModelElementbyRelationshipValue(modelVfVersion.getModelElements(),
1204 Widget.getWidget(Widget.Type.VFMODULE).getId());
1205 validateMatchedModelElementsInService(matchedVFModuleBaseWidgetElements,
1206 Widget.getWidget(Widget.Type.VFMODULE).getName());
1207 validateWidgetIds(matchedVFModuleBaseWidgetElements, Widget.getWidget(Widget.Type.VFMODULE)
1208 .getName(), Widget.getWidget(Widget.Type.VFMODULE).getWidgetId());
1210 ModelElements baseResourceVFModuleWidgetModelElements =
1211 matchedVFModuleBaseWidgetElements.get(0).getModelElements();
1212 if (vfModuleMembers.containsKey("l3-network")) {
1214 List<ModelElement> matchedL3NetworkElements =
1215 getModelElementbyRelationshipValue(baseResourceVFModuleWidgetModelElements,
1216 Widget.getWidget(Widget.Type.L3_NET).getId());
1217 validateMatchedModelElementsInService(matchedL3NetworkElements,
1218 Widget.getWidget(Widget.Type.L3_NET).getName());
1219 validateWidgetIds(matchedL3NetworkElements, Widget.getWidget(Widget.Type.L3_NET)
1220 .getName(), Widget.getWidget(Widget.Type.L3_NET).getWidgetId());
1222 if (vfModuleMembers.containsKey("vserver")) {
1224 List<ModelElement> matchedVserverElements =
1225 getModelElementbyRelationshipValue(baseResourceVFModuleWidgetModelElements,
1226 Widget.getWidget(Widget.Type.VSERVER).getId());
1227 validateMatchedModelElementsInService(matchedVserverElements,
1228 Widget.getWidget(Widget.Type.VSERVER).getName());
1229 ModelElements vserverWidgetModelElements =
1230 matchedVserverElements.get(0).getModelElements();
1232 validateWidgetIds(matchedVserverElements, Widget.getWidget(Widget.Type.VSERVER)
1233 .getName(), Widget.getWidget(Widget.Type.VSERVER).getWidgetId());
1236 //Validate vserver->vfc
1237 List<ModelElement> matchedVfcElements =
1238 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1239 Widget.getWidget(Widget.Type.VFC).getId());
1240 validateMatchedModelElementsInService(matchedVfcElements,
1241 Widget.getWidget(Widget.Type.VFC).getName());
1242 validateWidgetIds(matchedVfcElements, Widget.getWidget(Widget.Type.VFC).getName(),
1243 Widget.getWidget(Widget.Type.VFC).getWidgetId());
1245 //Validate vserver->Image
1246 List<ModelElement> matchedImageElements =
1247 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1248 Widget.getWidget(Widget.Type.IMAGE).getId());
1249 validateMatchedModelElementsInService(matchedImageElements,
1250 Widget.getWidget(Widget.Type.IMAGE).getName());
1251 validateWidgetIds(matchedImageElements, Widget.getWidget(Widget.Type.IMAGE)
1252 .getName(), Widget.getWidget(Widget.Type.IMAGE).getWidgetId());
1255 //Validate vserver->Flavor
1256 List<ModelElement> matchedFlavorElements =
1257 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1258 Widget.getWidget(Widget.Type.FLAVOR).getId());
1259 validateMatchedModelElementsInService(matchedFlavorElements,
1260 Widget.getWidget(Widget.Type.FLAVOR).getName());
1261 validateWidgetIds(matchedFlavorElements, Widget.getWidget(Widget.Type.FLAVOR).getName(),
1262 Widget.getWidget(Widget.Type.FLAVOR).getWidgetId());
1264 //Validate vserver->Tenant
1265 List<ModelElement> matchedTenantElements =
1266 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1267 Widget.getWidget(Widget.Type.TENANT).getId());
1268 validateMatchedModelElementsInService(matchedTenantElements,
1269 Widget.getWidget(Widget.Type.TENANT).getName());
1270 validateWidgetIds(matchedTenantElements, Widget.getWidget(Widget.Type.TENANT).getName(),
1271 Widget.getWidget(Widget.Type.TENANT).getWidgetId());
1273 //Validate vserver->l-interface
1274 if (vfModuleMembers.containsKey("l-interface")) {
1275 List<ModelElement> matchedLinterfaceElements =
1276 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1277 Widget.getWidget(Widget.Type.LINT).getId());
1278 validateMatchedModelElementsInService(matchedLinterfaceElements,
1279 Widget.getWidget(Widget.Type.LINT).getName());
1280 validateWidgetIds(matchedLinterfaceElements, Widget.getWidget(Widget.Type.LINT).getName(),
1281 Widget.getWidget(Widget.Type.LINT).getWidgetId());
1283 //Validate vserver->volume
1284 if (vfModuleMembers.containsKey("volume")) {
1285 List<ModelElement> matchedVolumeElements =
1286 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1287 Widget.getWidget(Widget.Type.VOLUME).getId());
1288 validateMatchedModelElementsInService(matchedVolumeElements,
1289 Widget.getWidget(Widget.Type.VOLUME).getName());
1290 validateWidgetIds(matchedVolumeElements, Widget.getWidget(Widget.Type.VOLUME).getName(),
1291 Widget.getWidget(Widget.Type.VOLUME).getWidgetId());
1297 System.out.println("Resource mapping not found for " + resourceNameVersionId);
1301 } catch (IllegalArgumentException e) {
1302 Assert.fail(e.getMessage()); //Can come while populating metadata
1307 private void validateMatchedModelElementsInService(List<ModelElement> matchedModelElements,
1309 if (matchedModelElements.isEmpty()) {
1310 Assert.fail(modelType + " not present ");
1312 if (matchedModelElements.size() > 1) {
1313 Assert.fail("More than one " + modelType + " present ");
1317 private Map<String, String> getNodeTemplateTypeStore(ToscaTemplate toscaTemplate) {
1318 if (toscaTemplate.getTopology_template() != null) {
1319 Map<String, NodeTemplate> nodeTemplateMap =
1320 toscaTemplate.getTopology_template().getNode_templates();
1321 Map<String, String> nodeTemplateIdTypeStore = new LinkedHashMap<>();
1322 if (nodeTemplateMap != null) {
1323 for (Map.Entry<String, NodeTemplate> e : nodeTemplateMap.entrySet()) {
1324 String uuid = e.getValue().getMetadata().get("resourceUUID");
1325 if (GeneratorUtil.isEmpty(uuid)) {
1326 uuid = e.getValue().getMetadata().get("UUID");
1327 if (GeneratorUtil.isEmpty(uuid)) {
1328 Assert.fail("UUID Not found");
1331 if(e.getValue().getType().contains("org.openecomp.resource.vf.")&& (e.getValue()
1332 .getMetadata().get("category").equals("Allotted Resource")))
1334 e.getValue().setType("org.openecomp.resource.vf.allottedResource");
1336 nodeTemplateIdTypeStore.put(uuid, e.getValue().getType());
1337 resourcesVersion.put(uuid,e.getValue().getMetadata().get
1339 //Populate invraintUuId for V9
1340 String invUuId = e.getValue().getMetadata().get("invariantUUID");
1341 nodeTemplateIdTypeStore.put(uuid+"-INV_UID" , invUuId);
1344 return nodeTemplateIdTypeStore;
1350 private Map<String, String> getGroupsTypeStore(ToscaTemplate toscaTemplate) {
1351 if (toscaTemplate.getTopology_template() != null) {
1352 Map<String, GroupDefinition> groupDefinitionMap =
1353 toscaTemplate.getTopology_template().getGroups();
1354 Map<String, String> groupDefinitionIdTypeStore = new LinkedHashMap<>();
1355 if (groupDefinitionMap != null) {
1356 for (Map.Entry<String, GroupDefinition> e : groupDefinitionMap.entrySet()) {
1357 if (e.getValue().getType().contains("org.openecomp.groups.VfModule")) {
1358 String uuid = e.getValue().getMetadata().get("vfModuleModelUUID");
1359 if (GeneratorUtil.isEmpty(uuid)) {
1360 uuid = e.getValue().getMetadata().get("UUID");
1361 if (GeneratorUtil.isEmpty(uuid)) {
1362 Assert.fail("UUID Not found");
1365 groupDefinitionIdTypeStore.put(uuid, e.getValue().getType());
1369 return groupDefinitionIdTypeStore;
1376 private void validateServiceModelMetadata(Service serviceToscaModel, Model generatedAAIModel) {
1377 ModelVer modelVersion = generatedAAIModel.getModelVers().getModelVer().get(0);
1378 Assert.assertEquals(serviceToscaModel.getModelNameVersionId(),
1379 modelVersion.getModelVersionId());
1380 Assert.assertEquals(serviceToscaModel.getModelId(), generatedAAIModel.getModelInvariantId());
1381 Assert.assertEquals(serviceToscaModel.getModelName(), modelVersion.getModelName());
1382 Assert.assertEquals(additionalParams.get(AdditionalParams.ServiceVersion.getName()), modelVersion
1383 .getModelVersion());
1384 Assert.assertEquals(serviceToscaModel.getModelDescription(),
1385 modelVersion.getModelDescription());
1389 private void validateResourceModelMetadata(Resource resouerceToscaModel,
1390 Model generatedAAIModel) {
1391 ModelVer modelVersion = generatedAAIModel.getModelVers().getModelVer().get(0);
1392 Assert.assertEquals(resouerceToscaModel.getModelNameVersionId(),
1393 modelVersion.getModelVersionId());
1394 Assert.assertEquals(resouerceToscaModel.getModelId(), generatedAAIModel.getModelInvariantId());
1395 Assert.assertEquals(resouerceToscaModel.getModelName(), modelVersion.getModelName());
1397 .assertEquals(resouerceToscaModel.getModelVersion(), modelVersion.getModelVersion());
1398 Assert.assertEquals(resouerceToscaModel.getModelDescription(),
1399 modelVersion.getModelDescription());
1403 private void validateVFModelMetadata(Map<String, String> vfModuleModelMetadata,
1404 Model generatedAAIModel) {
1405 ModelVer modelVersion = generatedAAIModel.getModelVers().getModelVer().get(0);
1406 Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelUUID"),
1407 modelVersion.getModelVersionId());
1408 Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelInvariantUUID"),
1409 generatedAAIModel.getModelInvariantId());
1410 Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelName"),
1411 modelVersion.getModelName());
1412 Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelVersion"),
1413 modelVersion.getModelVersion());
1414 Assert.assertEquals(vfModuleModelMetadata.get("vf_module_description"),
1415 modelVersion.getModelDescription());
1418 private Model getAAIModelByNameVersionId(String nameVersionId,
1419 Map<String, Model> outputArtifactMap) {
1420 return outputArtifactMap.get(nameVersionId);
1423 private List<ModelElement> getModelElementbyRelationshipValue(ModelElements modelElements,
1424 String relationshipValue) {
1425 List<ModelElement> matchedModelElements = new ArrayList<>();
1426 if (modelElements != null) {
1427 List<ModelElement> modelElementList = modelElements.getModelElement();
1428 for (ModelElement element : modelElementList) {
1429 List<Relationship> relationshipList = element.getRelationshipList().getRelationship();
1430 for (Relationship r : relationshipList) {
1431 List<RelationshipData> relationshipDataList = r.getRelationshipData();
1432 for (RelationshipData relationshipData : relationshipDataList) {
1433 if (relationshipData.getRelationshipValue().equals(relationshipValue)) {
1434 matchedModelElements.add(element);
1440 return matchedModelElements;
1443 private Map<String, Model> populateAAIGeneratedModelStore(List<Artifact> resultData) throws IOException {
1444 Map<String, Model> outputArtifactMap = new HashMap<>();
1445 for (Artifact outputArtifact : resultData) {
1446 if (outputArtifact.getType().equals(ArtifactType.MODEL_INVENTORY_PROFILE.name())) {
1447 byte[] decodedPayload = GeneratorUtil.decoder(outputArtifact.getPayload());
1448 Model aaiModel = getUnmarshalledArtifactModel(new String(decodedPayload));
1449 List<ModelVer> modelVersions = aaiModel.getModelVers().getModelVer();
1450 outputArtifactMap.put(modelVersions.get(0).getModelVersionId(), aaiModel);
1453 return outputArtifactMap;
1456 private Model getUnmarshalledArtifactModel(String aaiModel) throws IOException {
1460 JAXBContext jaxbContext = JAXBContext.newInstance(Model.class);
1461 Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
1463 try (InputStream aaiModelStream = new ByteArrayInputStream(aaiModel.getBytes())) {
1464 return (Model) unmarshaller.unmarshal(aaiModelStream);
1467 } catch (JAXBException e) {
1468 e.printStackTrace();
1475 * Get the tosca java model from the tosca input artifact
1477 * @param input Input tosca file and its metadata information as {@link Artifact} object
1478 * @return Translated {@link ToscaTemplate tosca} object
1480 private ToscaTemplate getToscaModel(Artifact input) throws SecurityException {
1481 byte[] decodedInput = GeneratorUtil.decoder(input.getPayload());
1482 String checksum = GeneratorUtil.checkSum(decodedInput);
1483 if (checksum.equals(input.getChecksum())) {
1485 return GeneratorUtil.translateTosca(new String(decodedInput), ToscaTemplate.class);
1486 } catch (Exception e) {
1487 e.printStackTrace();
1488 throw new IllegalArgumentException(
1489 String.format(GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_TOSCA, input.getName()));
1492 throw new SecurityException(
1493 String.format(GeneratorConstants.GENERATOR_AAI_ERROR_CHECKSUM_MISMATCH, input.getName()));
1498 * Identify the service tosca artifact from the list of translated tosca inputs
1500 * @param input List of translated {@link ToscaTemplate tosca} object models
1501 * @return Identified service {@link ToscaTemplate tosca}
1503 private ToscaTemplate getServiceTosca(List<ToscaTemplate> input) {
1504 Iterator<ToscaTemplate> iter = input.iterator();
1505 while (iter.hasNext()) {
1506 ToscaTemplate tosca = iter.next();
1507 if (tosca.isService()) {
1515 private Map<String, String> getVFModuleMetadataTosca(ToscaTemplate toscaTemplate,
1516 String vfModuleModelUUID) {
1517 Map<String, GroupDefinition> groupDefinitionMap =
1518 toscaTemplate.getTopology_template().getGroups();
1519 Map<String, String> vfModuleModelMetadata = new LinkedHashMap<>();
1520 for (Map.Entry<String, GroupDefinition> e : groupDefinitionMap.entrySet()) {
1521 if (e.getValue().getType().contains("org.openecomp.groups.VfModule")) {
1522 String uuid = e.getValue().getMetadata().get("vfModuleModelUUID");
1523 if (Objects.equals(uuid, vfModuleModelUUID)) {
1524 vfModuleModelMetadata = e.getValue().getMetadata();
1525 vfModuleModelMetadata.put("vf_module_description",
1526 (String) e.getValue().getProperties().get("vf_module_description"));
1530 return vfModuleModelMetadata;
1533 private Map<String, Object> getVFModuleMembersTosca(ToscaTemplate toscaTemplate,
1534 String vfModuleModelUUID) {
1535 Map<String, GroupDefinition> groupDefinitionMap =
1536 toscaTemplate.getTopology_template().getGroups();
1537 Map<String, NodeTemplate> nodeTemplateMaps =
1538 toscaTemplate.getTopology_template().getNode_templates();
1539 Map<String, Object> vfModuleMembers = new LinkedHashMap<>();
1540 List<String> vfModuleModelMetadata;
1541 for (Map.Entry<String, GroupDefinition> e : groupDefinitionMap.entrySet()) {
1542 if (e.getValue().getType().contains("org.openecomp.groups.VfModule")) {
1543 String uuid = e.getValue().getMetadata().get("vfModuleModelUUID");
1544 if (Objects.equals(uuid, vfModuleModelUUID)) {
1545 vfModuleModelMetadata = e.getValue().getMembers();
1546 if (vfModuleModelMetadata !=null) {
1547 for (Object key : vfModuleModelMetadata) {
1548 NodeTemplate nodeTemplate = nodeTemplateMaps.get(key);
1549 String nodetype = null;
1550 if (nodeTemplate != null) {
1551 nodetype = nodeTemplate.getType();
1553 if (nodetype != null) {
1554 String widgetType = membersType(nodetype);
1555 if (widgetType != null) {
1556 vfModuleMembers.put(widgetType, key);
1565 return vfModuleMembers;
1569 private String membersType(String toscaType) {
1570 String modelToBeReturned = null;
1571 while (toscaType != null && toscaType.lastIndexOf(".") != -1 && modelToBeReturned == null) {
1573 switch (toscaType) {
1574 case "org.openecomp.resource.vf.allottedResource":
1575 modelToBeReturned = "allotted-resource";
1577 case "org.openecomp.resource.vfc":
1578 modelToBeReturned = "vserver";
1580 case "org.openecomp.resource.cp":
1581 case "org.openecomp.cp":
1582 modelToBeReturned = "l-interface";
1584 case "org.openecomp.resource.vl":
1585 modelToBeReturned = "l3-network";
1587 case "org.openecomp.resource.vf":
1588 modelToBeReturned = "generic-vnf";
1590 case "org.openecomp.groups.VfModule":
1591 modelToBeReturned = "vf-module";
1593 case "org.openecomp.resource.vfc.nodes.heat.cinder":
1594 modelToBeReturned = "volume";
1597 modelToBeReturned = null;
1601 toscaType = toscaType.substring(0, toscaType.lastIndexOf("."));
1603 return modelToBeReturned;
1606 private List<Artifact> init(String aaiResourceBasePaths) {
1607 List<Artifact> inputArtifacts1 = new ArrayList<>();
1610 String[] resourceFileList = {};
1611 URL resourceDirUrl = this.getClass().getClassLoader().getResource(aaiResourceBasePaths);
1612 if (resourceDirUrl != null && resourceDirUrl.getProtocol().equals("file")) {
1613 resourceFileList = new File(resourceDirUrl.toURI()).list();
1615 Assert.fail("Invalid resource directory");
1618 for (String aResourceFileList : resourceFileList) {
1619 File resourceFile = new File(
1620 this.getClass().getClassLoader().getResource(aaiResourceBasePaths + aResourceFileList)
1623 //convert service tosca file into array of bytes
1624 byte[] payload = new byte[(int) resourceFile.length()];
1625 try (FileInputStream fileInputStream = new FileInputStream(resourceFile)) {
1626 fileInputStream.read(payload);
1629 String checksum = GeneratorUtil.checkSum(payload);
1630 byte[] encodedPayload = GeneratorUtil.encode(payload);
1632 new Artifact(aaiArtifactType, aaiArtifactGroupType, checksum, encodedPayload);
1633 artifact.setName(aResourceFileList);
1634 artifact.setLabel(aResourceFileList);
1635 artifact.setDescription(aResourceFileList);
1636 artifact.setVersion("1.0");
1637 inputArtifacts1.add(artifact);
1640 } catch (Exception e) {
1641 //e.printStackTrace();
1642 Assert.fail(e.getMessage());
1644 return inputArtifacts1;
1647 private void loadConfigFromClasspath(Properties properties) throws IOException {
1648 String configLocation = System.getProperty("artifactgenerator.config");
1649 if (configLocation != null) {
1650 File file = new File(configLocation);
1651 if (file.exists()) {
1652 properties.load(new FileInputStream(file));
1657 public void testResourceTosca(Iterator<ToscaTemplate> itr, Map<String, Model>
1658 outputArtifactMap) {
1659 while(itr.hasNext()){
1660 ToscaTemplate toscaTemplate = itr.next();
1661 String resourceVersion=resourcesVersion.get(toscaTemplate.getMetadata().get("UUID"));
1662 toscaTemplate.getMetadata().put("version", resourceVersion);
1663 if("VF".equals(toscaTemplate.getMetadata().get("type")) && !("Allotted Resource".equals
1664 (toscaTemplate.getMetadata().get("category"))) ){
1665 testVfTosca(outputArtifactMap, toscaTemplate);
1666 } else if("VF".equals(toscaTemplate.getMetadata().get("type")) && ("Allotted Resource".equals
1667 (toscaTemplate.getMetadata().get("category"))) ){
1668 testAllottedResourceTosca(outputArtifactMap, toscaTemplate);
1669 } else if("VL".equals(toscaTemplate.getMetadata().get("type"))){
1670 testL3NetworkResourceTosca(outputArtifactMap, toscaTemplate);
1675 private void readPayloadFromResource(List<Artifact> inputArtifacts, String file) throws IOException {
1676 try (InputStream stream = ArtifactGenerationServiceTest.class.getResourceAsStream("/" + file)) {
1677 readPayload(inputArtifacts, stream, file);