2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.generator;
23 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_CONFIGFILE_NOT_FOUND;
24 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND;
25 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_CONFIGLPROP_NOT_FOUND;
26 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING;
27 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_PROVIDING_SERVICE_MISSING;
28 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_ID;
29 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_ERROR_MISSING_SERVICE_VERSION;
30 import static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_INVALID_SERVICE_VERSION;
32 import org.apache.commons.io.FileUtils;
33 import org.openecomp.sdc.generator.aai.model.Resource;
34 import org.openecomp.sdc.generator.aai.model.Service;
35 import org.openecomp.sdc.generator.aai.model.Widget;
36 import org.openecomp.sdc.generator.aai.tosca.GroupDefinition;
37 import org.openecomp.sdc.generator.aai.tosca.NodeTemplate;
38 import org.openecomp.sdc.generator.aai.tosca.ToscaTemplate;
39 import org.openecomp.sdc.generator.data.AdditionalParams;
40 import org.openecomp.sdc.generator.aai.xml.Model;
41 import org.openecomp.sdc.generator.aai.xml.ModelElement;
42 import org.openecomp.sdc.generator.aai.xml.ModelElements;
43 import org.openecomp.sdc.generator.aai.xml.ModelVer;
44 import org.openecomp.sdc.generator.aai.xml.Relationship;
45 import org.openecomp.sdc.generator.aai.xml.RelationshipData;
46 import org.openecomp.sdc.generator.data.Artifact;
47 import org.openecomp.sdc.generator.data.ArtifactType;
48 import org.openecomp.sdc.generator.data.GenerationData;
49 import org.openecomp.sdc.generator.data.GeneratorConstants;
50 import org.openecomp.sdc.generator.data.GeneratorUtil;
51 import org.openecomp.sdc.generator.data.GroupType;
52 import org.openecomp.sdc.generator.impl.ArtifactGenerationServiceImpl;
53 import org.testng.Assert;
54 import org.testng.annotations.BeforeSuite;
55 import org.testng.annotations.Test;
57 import java.io.ByteArrayInputStream;
59 import java.io.FileInputStream;
60 import java.io.FileOutputStream;
61 import java.io.IOException;
62 import java.io.InputStream;
63 import java.io.OutputStream;
66 import javax.xml.bind.JAXBContext;
67 import javax.xml.bind.JAXBException;
68 import javax.xml.bind.Unmarshaller;
70 @SuppressWarnings("Duplicates")
71 public class ArtifactGenerationServiceTest {
73 private static final String aaiArtifactType = ArtifactType.AAI.name();
74 private static final String aaiArtifactGroupType = GroupType.DEPLOYMENT.name();
75 private static final String generatorConfig = "{\"artifactTypes\": [\"OTHER\",\"AAI\"]}";
76 Properties properties = new Properties();
77 Map<String, String> additionalParams = new HashMap();
78 Map<String, String> resourcesVersion = new HashMap<>();
81 public void loadProperties() throws Exception{
82 loadConfigFromClasspath(properties);
83 additionalParams.put(AdditionalParams.ServiceVersion.getName(), "1.0");
87 public void testArtifactGeneration() {
88 // Sunny day scenario service with VF anf vfmodule
90 Map<String, Model> outputArtifactMap = new HashMap<>();
91 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
92 List<ToscaTemplate> toscas = new LinkedList<>();
93 String aaiResourceBasePaths = "aai/";
94 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
95 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
96 if (data.getErrorData().isEmpty()) {
97 for (Artifact inputArtifact : inputArtifacts) {
98 toscas.add(getToscaModel(inputArtifact));
100 List<Artifact> resultData = data.getResultData();
102 /*for( int i = 0 ; i < resultData.size() ; i++) {
103 Artifact artifact = resultData.get(i);
104 String fileName = artifact.getName();
105 while(fileName.contains(":")){
106 fileName = fileName.replace(":","");
108 File targetFile =new File("src/test/resources/"+fileName);
109 OutputStream outStream = new FileOutputStream(targetFile);
110 outStream.write(Base64.getDecoder().decode(artifact.getPayload()));
113 Assert.assertEquals(resultData.size(),5); // 1-service,1-VF-resource,1-vfmodule and 2
115 outputArtifactMap = populateAAIGeneratedModelStore(resultData);
116 testServiceTosca(toscas, outputArtifactMap);
117 testResourceTosca(toscas.iterator(), outputArtifactMap);
119 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
122 } catch (Exception e) {
123 Assert.fail(e.getMessage());
128 public void testWidgetinServiceTosca() {
129 // Sunny day scenario service with VF and extra widget like CP anf vf has vfmodule without
132 Map<String, Model> outputArtifactMap = new HashMap<>();
133 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
134 List<ToscaTemplate> toscas = new LinkedList<>();
135 String aaiResourceBasePaths = "testWidgetinServiceTosca/";
136 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
137 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
138 if (data.getErrorData().isEmpty()) {
139 for (Artifact inputArtifact : inputArtifacts) {
140 toscas.add(getToscaModel(inputArtifact));
142 List<Artifact> resultData = data.getResultData();
143 Assert.assertEquals(resultData.size(),5); // 1-service,1-VF-resource,1-vfmodule and 2
145 outputArtifactMap = populateAAIGeneratedModelStore(resultData);
146 testServiceTosca(toscas, outputArtifactMap);
147 testResourceTosca(toscas.iterator(), outputArtifactMap);
149 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
152 } catch (Exception e) {
153 Assert.fail(e.getMessage());
158 public void testSameVLdifferentVersion() {
159 // Sunny day scenario service with VF and extra widget like CP anf vf has vfmodule without
162 Map<String, Model> outputArtifactMap = new HashMap<>();
163 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
164 List<ToscaTemplate> toscas = new LinkedList<>();
165 String aaiResourceBasePaths = "testSameVLdifferentVersion/";
166 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
167 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
168 if (data.getErrorData().isEmpty()) {
169 for (Artifact inputArtifact : inputArtifacts) {
170 toscas.add(getToscaModel(inputArtifact));
172 List<Artifact> resultData = data.getResultData();
173 Assert.assertEquals(resultData.size(),8);
175 outputArtifactMap = populateAAIGeneratedModelStore(resultData);
176 testServiceTosca(toscas, outputArtifactMap);
177 testResourceTosca(toscas.iterator(), outputArtifactMap);
179 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
182 } catch (Exception e) {
183 Assert.fail(e.getMessage());
188 public void testArtifactGenerationAllottedResourceAndL3Network() {
189 // Sunny day scenario service with allotted resource and L3-network
191 Map<String, Model> outputArtifactMap = new HashMap<>();
192 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
193 List<ToscaTemplate> toscas = new LinkedList<>();
194 String aaiResourceBasePaths = "aai2/";
195 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
196 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
197 if (data.getErrorData().isEmpty()) {
198 for (Artifact inputArtifact : inputArtifacts) {
199 toscas.add(getToscaModel(inputArtifact));
201 List<Artifact> resultData = data.getResultData();
203 Assert.assertEquals(resultData.size(),5);
206 outputArtifactMap = populateAAIGeneratedModelStore(resultData);
207 testServiceTosca(toscas, outputArtifactMap);
208 testResourceTosca(toscas.iterator(), outputArtifactMap);
210 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
213 } catch (Exception e) {
214 Assert.fail(e.getMessage());
218 @Test(dependsOnMethods = {"testArtifactGeneration"})
219 public void testWhenMissingTosca() {
221 //Missing Service tosca test case
222 String aaiResourceBasePaths = "testArtifactGeneration2/";
223 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
224 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
225 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
226 Assert.assertEquals(data.getErrorData().get("AAI").get(0),"Service tosca missing from list of input artifacts");
227 } catch (Exception e) {
228 Assert.fail(e.getMessage());
232 @Test(dependsOnMethods = {"testWhenMissingTosca"})
233 public void testWhenInvaildConfig() {
235 //Invalid config test case
236 String generatorConfig1 = "{\"artifactTypes\": [\"ABC\"]}";
237 String aaiResourceBasePaths = "testArtifactGeneration2/";
238 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
239 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
240 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig1, additionalParams);
241 Assert.assertEquals(data.getErrorData().get("ARTIFACT_GENERATOR_INVOCATION_ERROR").get(0),"Invalid Client Configuration");
242 } catch (Exception e) {
243 Assert.fail(e.getMessage());
247 @Test(dependsOnMethods = {"testArtifactGeneration"})
248 public void testWhenOnlyServToscaNoResTosca() {
250 //Testing only service tosca no resource Tosca
251 Map<String, Model> outputArtifactMap = new HashMap<>();
252 String aaiResourceBasePaths = "testArtifactGeneration4/";
253 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
254 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
255 List<ToscaTemplate> toscas = new LinkedList<>();
256 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
257 List<Artifact> resultData = data.getResultData();
258 if (data.getErrorData().isEmpty()) {
259 for (Artifact inputArtifact : inputArtifacts) {
260 toscas.add(getToscaModel(inputArtifact));
263 Assert.assertEquals(resultData.size(),3); // 1-service and 2-Others
264 outputArtifactMap = populateAAIGeneratedModelStore(resultData);
265 testServiceTosca(toscas, outputArtifactMap);
266 } catch (Exception e) {
267 Assert.fail(e.getMessage());
271 @Test(dependsOnMethods = {"testArtifactGeneration"})
272 public void testWhenInvaildYaml() {
274 //Invalid Yaml file test case
275 String aaiResourceBasePaths = "testArtifactGeneration5/";
276 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
277 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
278 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
279 Assert.assertEquals(data.getErrorData().get("AAI").get(0),"Invalid format for Tosca YML : " + inputArtifacts.get(0).getName());
280 } catch (Exception e) {
281 Assert.fail(e.getMessage());
285 @Test(dependsOnMethods = {"testArtifactGeneration"})
286 public void testWhenExtraResToscaNotPartOfServ() {
288 // Valid scenario with extra resource tosca which is not part of Service
289 Map<String, Model> outputArtifactMap = new HashMap<>();
290 String aaiResourceBasePaths = "testArtifactGeneration6/";
291 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
292 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
293 List<ToscaTemplate> toscas = new LinkedList<>();
294 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
295 List<Artifact> resultData = data.getResultData();
296 if (data.getErrorData().isEmpty()) {
297 for (Artifact inputArtifact : inputArtifacts) {
298 toscas.add(getToscaModel(inputArtifact));
301 Assert.assertEquals(resultData.size(),3); // 1-service and 2 Others
302 outputArtifactMap = populateAAIGeneratedModelStore(resultData);
303 testServiceTosca(toscas, outputArtifactMap);
304 } catch (Exception e) {
305 Assert.fail(e.getMessage());
311 public void testWhenInvUuIdAttrMissing() {
313 // mandatory attribute <invariantUUID> missing
314 String aaiResourceBasePaths = "testArtifactGeneration8/";
315 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
316 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
317 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
319 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <invariantUUID> missing in Artifact: <" +
320 inputArtifacts.get(0).getName() + ">");
322 } catch (Exception e) {
323 Assert.fail(e.getMessage());
328 public void testErrorWhenInvalidInvId() {
330 //Invariant Id in service tosca of length not 36
331 String aaiResourceBasePaths = "testErrorWhenInvalidInvId/";
332 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
333 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
334 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
336 data.getErrorData().get("AAI").get(0),String.format(GENERATOR_AAI_ERROR_INVALID_ID,
337 "invariantUUID",inputArtifacts.get(0).getName()));
339 } catch (Exception e) {
340 Assert.fail(e.getMessage());
345 public void testWhenUuIdAttrMissing() {
347 //mandatory attribute <UUID> missing
348 String aaiResourceBasePaths = "testArtifactGeneration9/";
349 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
350 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
351 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
353 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <UUID> missing in Artifact: <" +
354 inputArtifacts.get(0).getName() + ">");
356 } catch (Exception e) {
357 Assert.fail(e.getMessage());
362 public void testErrorWhenInvalidUuId() {
364 //UUID Id in service tosca of length not 36
365 String aaiResourceBasePaths = "testErrorWhenInvalidUuId/";
366 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
367 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
368 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
370 data.getErrorData().get("AAI").get(0),String.format(GENERATOR_AAI_ERROR_INVALID_ID,
371 "UUID",inputArtifacts.get(0).getName()));
373 } catch (Exception e) {
374 Assert.fail(e.getMessage());
379 public void testWhenNameAttrMissing() {
381 //mandatory attribute <name> missing
382 String aaiResourceBasePaths = "testArtifactGeneration10/";
383 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
384 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
385 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
387 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <name> missing in Artifact: <" +
388 inputArtifacts.get(0).getName() + ">");
390 } catch (Exception e) {
391 Assert.fail(e.getMessage());
395 @Test //(dependsOnMethods = {"testArtifactGeneration"})
396 public void testWhenVfModInvUuIdAttrMissing() {
398 //mandatory attribute <vfModuleModelInvariantUUID> missing
399 List<Artifact> inputArtifacts = new ArrayList<>();
400 InputStream fis1 = ArtifactGenerationServiceTest.class.getResourceAsStream("/service_vmme_template_ModInvUUID.yml");
401 readPayload(inputArtifacts,fis1, "service_vmme_template_ModInvUUID.yml");
404 InputStream fis2 = ArtifactGenerationServiceTest.class.getResourceAsStream("/vf_vmme_template_ModInvUUID.yml");
405 readPayload(inputArtifacts,fis2, "vf_vmme_template_ModInvUUID.yml");
407 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
408 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
410 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <vfModuleModelInvariantUUID> missing in Artifact: <" +
411 inputArtifacts.get(1).getName() + ">");
413 } catch (Exception e) {
414 Assert.fail(e.getMessage());
418 public static void readPayload(List<Artifact> inputArtifacts,InputStream fis, String fileName) throws
420 byte[] payload = new byte[fis.available()];
422 String checksum = GeneratorUtil.checkSum(payload);
423 byte[] encodedPayload = GeneratorUtil.encode(payload);
424 Artifact artifact = new Artifact(aaiArtifactType, aaiArtifactGroupType, checksum, encodedPayload);
425 artifact.setName(fileName);
426 artifact.setLabel(fileName);
427 artifact.setDescription(fileName);
428 artifact.setVersion("1.0");
429 System.out.println(artifact.getName());
430 inputArtifacts.add(artifact);
434 public void testWhenInvalidVfModInvUuIdAttr() {
436 //invalid id since not of length 36 for <vfModuleModelInvariantUUID>
437 List<Artifact> inputArtifacts = new ArrayList<>();
438 InputStream fis1 = ArtifactGenerationServiceTest.class.getResourceAsStream("/service_vmme_template_InvalidVfModInvUuIdAttr.yml");
439 readPayload(inputArtifacts,fis1, "service_vmme_template_InvalidVfModInvUuIdAttr.yml");
442 InputStream fis2 = ArtifactGenerationServiceTest.class.getResourceAsStream("/vf_vmme_template_InvalidVfModInvUuIdAttr.yml");
443 readPayload(inputArtifacts,fis2, "vf_vmme_template_InvalidVfModInvUuIdAttr.yml");
445 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
446 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
448 data.getErrorData().get("AAI").get(0),String.format(GENERATOR_AAI_ERROR_INVALID_ID,
449 "vfModuleModelInvariantUUID", inputArtifacts.get(1).getName() ));
451 } catch (Exception e) {
452 Assert.fail(e.getMessage());
456 @Test //(dependsOnMethods = {"testArtifactGeneration"})
457 public void testWhenVfModNameAttrMissing() {
459 //mandatory attribute <vfModuleModelName> missing
460 List<Artifact> inputArtifacts = new ArrayList<>();
461 InputStream fis1 = ArtifactGenerationServiceTest.class.getResourceAsStream("/service_vmme_template_ModelName.yml");
462 readPayload(inputArtifacts,fis1, "service_vmme_template_ModelName.yml");
465 InputStream fis2 = ArtifactGenerationServiceTest.class.getResourceAsStream("/vf_vmme_template_ModelName.yml");
466 readPayload(inputArtifacts,fis2, "vf_vmme_template_ModelName.yml");
468 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
469 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
471 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <vfModuleModelName> missing in Artifact: <" +
472 inputArtifacts.get(1).getName() + ">");
474 } catch (Exception e) {
475 Assert.fail(e.getMessage());
479 /*public static void readPayload(List<Artifact> inputArtifacts,InputStream fis, String fileName)
482 byte[] payload = new byte[fis.available()];
484 String checksum = GeneratorUtil.checkSum(payload);
485 byte[] encodedPayload = GeneratorUtil.encode(payload);
486 Artifact artifact = new Artifact(aaiArtifactType, aaiArtifactGroupType, checksum, encodedPayload);
487 artifact.setName(fileName);
488 artifact.setLabel(fileName);
489 artifact.setDescription(fileName);
490 artifact.setVersion("1.0");
491 System.out.println(artifact.getName());
492 inputArtifacts.add(artifact);
495 @Test //(dependsOnMethods = {"testArtifactGeneration"})
496 public void testWhenVfModUuIdAttrMissing() {
498 //mandatory attribute <vfModuleModelUUID> missing in Artifact
499 List<Artifact> inputArtifacts = new ArrayList<>();
500 InputStream fis1 = ArtifactGenerationServiceTest.class.getResourceAsStream("/service_vmme_template_ModelUUID.yml");
501 readPayload(inputArtifacts,fis1, "service_vmme_template_ModelUUID.yml");
504 InputStream fis2 = ArtifactGenerationServiceTest.class.getResourceAsStream("/vf_vmme_template_ModelUUID.yml");
505 readPayload(inputArtifacts,fis2, "vf_vmme_template_ModelUUID.yml");
507 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
508 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
510 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory " +
511 "attribute <vfModuleModelUUID> missing in Artifact: <" +
512 inputArtifacts.get(1).getName() + ">");
514 } catch (Exception e) {
515 Assert.fail(e.getMessage());
520 public void testWhenInvalidVfModUuIdAttr() {
522 //invalid id since not of length 36 for <vfModuleModelUUID>
523 List<Artifact> inputArtifacts = new ArrayList<>();
524 InputStream fis1 = ArtifactGenerationServiceTest.class.getResourceAsStream("/service_vmme_template_InvalidVfModUuIdAttr.yml");
525 readPayload(inputArtifacts,fis1, "service_vmme_template_InvalidVfModUuIdAttr.yml");
528 InputStream fis2 = ArtifactGenerationServiceTest.class.getResourceAsStream("/vf_vmme_template_InvalidVfModUuIdAttr.yml");
529 readPayload(inputArtifacts,fis2, "vf_vmme_template_InvalidVfModUuIdAttr.yml");
531 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
532 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
534 data.getErrorData().get("AAI").get(0),String.format(GENERATOR_AAI_ERROR_INVALID_ID,
535 "vfModuleModelUUID", inputArtifacts.get(1).getName() ));
537 } catch (Exception e) {
538 Assert.fail(e.getMessage());
542 @Test //(dependsOnMethods = {"testArtifactGeneration"})
543 public void testWhenVfModVersionAttrMissing() {
545 //mandatory attribute <vfModuleModelVersion> missing
546 List<Artifact> inputArtifacts = new ArrayList<>();
547 InputStream fis1 = ArtifactGenerationServiceTest.class.getResourceAsStream("/service_vmme_template_ModelVersion.yml");
548 readPayload(inputArtifacts,fis1, "service_vmme_template_ModelVersion.yml");
551 InputStream fis2 = ArtifactGenerationServiceTest.class.getResourceAsStream("/vf_vmme_template_ModelVersion.yml");
552 readPayload(inputArtifacts,fis2, "vf_vmme_template_ModelVersion.yml");
554 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
555 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
557 data.getErrorData().get("AAI").get(0),"Invalid Service/Resource definition mandatory attribute <vfModuleModelVersion> missing in Artifact: <" +
558 inputArtifacts.get(1).getName() + ">");
560 } catch (Exception e) {
561 Assert.fail(e.getMessage());
566 public void testErrorWhenNoSystemPropConfigured() throws Exception {
567 String configLoc = System.getProperty("artifactgenerator.config");
569 System.clearProperty("artifactgenerator.config");
570 Map<String, Model> outputArtifactMap = new HashMap<>();
571 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
572 List<ToscaTemplate> toscas = new LinkedList<>();
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 Assert.assertEquals(data.getErrorData().
578 get("AAI").get(0),GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND);
579 } catch (Exception e) {
580 Assert.fail(e.getMessage());
583 System.setProperty("artifactgenerator.config",configLoc);
588 public void testErrorWhenNoWidgetInConfig() throws Exception {
589 String configLoc = System.getProperty("artifactgenerator.config");
590 final File configFile = new File(configLoc);
591 String configDir = configLoc.substring(0, configLoc.lastIndexOf(File.separator));
592 final File tempFile = new File(configDir + File.separator + "temp.properties");
594 //copy orignal Artifact-Generator.properties to temp.properties for backup
595 FileUtils.copyFile(configFile, tempFile);
597 String serviceWidgetName = ArtifactType.AAI.name()+".model-version-id."+Widget.getWidget
598 (Widget.Type.SERVICE)
600 String assertMsg = ArtifactType.AAI.name() + ".model-version-id." +Widget.getWidget
601 (Widget.Type.SERVICE).getName();
602 OutputStream fos = new FileOutputStream(new File(configLoc));
603 String serviceWidgetId = properties.getProperty(serviceWidgetName);
605 //Remove property from Artifact-Generator.properties
606 properties.remove(serviceWidgetName);
607 properties.store(fos,null);
610 Map<String, Model> outputArtifactMap = new HashMap<>();
611 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
612 List<ToscaTemplate> toscas = new LinkedList<>();
613 String aaiResourceBasePaths = "aai/";
614 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
615 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
616 Assert.assertEquals(false,data.getErrorData().isEmpty());
617 String errMsg = String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,assertMsg);
618 Assert.assertEquals(data.getErrorData().get("AAI").get(0),errMsg);
619 } catch (Exception e) {
620 Assert.fail(e.getMessage());
623 if(tempFile.exists()){
625 FileUtils.copyFile(tempFile, configFile);
626 loadConfigFromClasspath(properties);
633 public void testErrorWhenNoFileAtConfigLocation() throws Exception {
634 String configLoc = System.getProperty("artifactgenerator.config");
636 System.setProperty("artifactgenerator.config",configLoc + File.separator + "testErrorWhenNoFileAtConfigLocation");
637 Map<String, Model> outputArtifactMap = new HashMap<>();
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 Assert.assertEquals(data.getErrorData().isEmpty(),false);
644 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format(GENERATOR_AAI_CONFIGFILE_NOT_FOUND,System.getProperty
645 ("artifactgenerator.config")));
646 } catch (Exception e) {
647 Assert.fail(e.getMessage());
650 System.setProperty("artifactgenerator.config",configLoc);
655 public void testErrorWhenNoServiceVersion() {
656 // scenario service with VF anf vfmodule but no service version in additional parameter
658 additionalParams.clear();
659 Map<String, Model> outputArtifactMap = new HashMap<>();
660 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
661 List<ToscaTemplate> toscas = new LinkedList<>();
662 String aaiResourceBasePaths = "aai/";
663 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
664 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
665 Assert.assertEquals(data.getErrorData().isEmpty(),false);
666 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
667 GENERATOR_AAI_ERROR_MISSING_SERVICE_VERSION);
668 } catch (Exception e) {
669 Assert.fail(e.getMessage());
672 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
677 public void testArtifactGenerationWithServiceVersion() {
678 // Sunny day scenario service with VF anf vfmodule and service version as adiitional parameter
680 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"9.0");
681 Map<String, Model> outputArtifactMap = new HashMap<>();
682 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
683 List<ToscaTemplate> toscas = new LinkedList<>();
684 String aaiResourceBasePaths = "aai/";
685 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
686 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
687 if (data.getErrorData().isEmpty()) {
688 for (Artifact inputArtifact : inputArtifacts) {
689 toscas.add(getToscaModel(inputArtifact));
691 List<Artifact> resultData = data.getResultData();
693 /*for( int i = 0 ; i < resultData.size() ; i++) {
694 Artifact artifact = resultData.get(i);
695 String fileName = artifact.getName();
696 while(fileName.contains(":")){
697 fileName = fileName.replace(":","");
699 File targetFile =new File("src/test/resources/"+fileName);
700 OutputStream outStream = new FileOutputStream(targetFile);
701 outStream.write(Base64.getDecoder().decode(artifact.getPayload()));
704 Assert.assertEquals(resultData.size(),5); // 1-service,1-VF-resource,1-vfmodule and 2
706 outputArtifactMap = populateAAIGeneratedModelStore(resultData);
707 testServiceTosca(toscas, outputArtifactMap);
708 testResourceTosca(toscas.iterator(), outputArtifactMap);
710 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
713 } catch (Exception e) {
714 Assert.fail(e.getMessage());
717 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
722 public void testErrorWhenInvalidServiceVersion() {
723 // scenario service with VF anf vfmodule but invalid service version in additional parameter
725 Map<String, Model> outputArtifactMap = new HashMap<>();
726 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
727 List<ToscaTemplate> toscas = new LinkedList<>();
728 String aaiResourceBasePaths = "aai/";
729 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
731 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1");
732 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
733 Assert.assertEquals(data.getErrorData().isEmpty(),false);
734 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
735 GENERATOR_AAI_INVALID_SERVICE_VERSION);
737 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.1");
738 data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
739 Assert.assertEquals(data.getErrorData().isEmpty(),false);
740 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
741 GENERATOR_AAI_INVALID_SERVICE_VERSION);
743 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.0");
744 data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
745 Assert.assertEquals(data.getErrorData().isEmpty(),false);
746 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
747 GENERATOR_AAI_INVALID_SERVICE_VERSION);
749 } catch (Exception e) {
750 Assert.fail(e.getMessage());
753 additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
758 public void testMissingResourceTosca() {
760 //Service with resource but seperate resource tosca not coming as input.
761 String aaiResourceBasePaths = "missingResourceTosca/";
762 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
763 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
764 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
765 Assert.assertEquals(data.getErrorData().get("AAI").get(0),"Cannot generate artifacts. Resource Tosca missing for resource with UUID: <b020ed1e-4bc7-4fc0-ba7e-cc7af6da7ffc>");
766 } catch (Exception e) {
767 Assert.fail(e.getMessage());
771 public void testMissingVLTosca() {
773 //Service with VL but seperate VL tosca not coming as input artifact.
774 String aaiResourceBasePaths = "missingVLTosca/";
775 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
776 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
777 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
778 Assert.assertEquals(data.getErrorData().get("AAI").get(0),"Cannot generate artifacts. Resource Tosca missing for resource with UUID: <3f8fa4d2-2b86-4b36-bbc8-ffb8f9f57468>");
779 } catch (Exception e) {
780 Assert.fail(e.getMessage());
785 public void testErrorWhenNoResourceVersion() {
786 // scenario service with VF but missing resource version in service tosca
788 Map<String, Model> outputArtifactMap = new HashMap<>();
789 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
790 List<ToscaTemplate> toscas = new LinkedList<>();
791 String aaiResourceBasePaths = "testErrorWhenNoResourceVersion/";
792 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
793 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
794 Assert.assertEquals(data.getErrorData().isEmpty(),false);
795 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
796 "Invalid Service definition mandatory attribute version missing for resource with UUID: <b020ed1e-4bc7-4fc0-ba7e-cc7af6da7ffc>");
797 } catch (Exception e) {
798 Assert.fail(e.getMessage());
803 public void testErrorWhenInvalidResourceVersion1() {
804 // scenario service with VF but invalid resource version 0.0 in service tosca
806 Map<String, Model> outputArtifactMap = new HashMap<>();
807 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
808 List<ToscaTemplate> toscas = new LinkedList<>();
809 String aaiResourceBasePaths = "testErrorWhenInvalidResourceVersion1/";
810 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
811 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
812 Assert.assertEquals(data.getErrorData().isEmpty(),false);
813 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
814 "Cannot generate artifacts. Invalid Resource version in Service tosca for resource with UUID: <b020ed1e-4bc7-4fc0-ba7e-cc7af6da7ffc>");
815 } catch (Exception e) {
816 Assert.fail(e.getMessage());
821 public void testErrorWhenInvalidResourceVersion2() {
822 // scenario service with VF but invalid resource version 1 in service tosca
824 Map<String, Model> outputArtifactMap = new HashMap<>();
825 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
826 List<ToscaTemplate> toscas = new LinkedList<>();
827 String aaiResourceBasePaths = "testErrorWhenInvalidResourceVersion2/";
828 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
829 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
830 Assert.assertEquals(data.getErrorData().isEmpty(),false);
831 Assert.assertEquals(data.getErrorData().get("AAI").get(0),
832 "Cannot generate artifacts. Invalid Resource version in Service tosca for resource with UUID: <b020ed1e-4bc7-4fc0-ba7e-cc7af6da7ffc>");
833 } catch (Exception e) {
834 Assert.fail(e.getMessage());
839 public void testArtifactGenerationAllottedResourceWithIpMuxAndTunnelXConn() {
841 Map<String, Model> outputArtifactMap = new HashMap<>();
842 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
843 List<ToscaTemplate> toscas = new LinkedList<>();
844 String aaiResourceBasePaths = "testArtifactGeneration15/";
845 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
846 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
847 if (data.getErrorData().isEmpty()) {
848 for (Artifact inputArtifact : inputArtifacts) {
849 toscas.add(getToscaModel(inputArtifact));
851 List<Artifact> resultData = data.getResultData();
853 Assert.assertEquals(resultData.size(),5);
854 outputArtifactMap = populateAAIGeneratedModelStore(resultData);
855 testServiceTosca(toscas, outputArtifactMap);
856 testResourceTosca(toscas.iterator(), outputArtifactMap);
858 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
861 } catch (Exception e) {
862 Assert.fail(e.getMessage());
867 public void testErrorWhenAllottedResourceWithOutProvidingServiceId() {
869 Map<String, Model> outputArtifactMap = new HashMap<>();
870 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
871 List<ToscaTemplate> toscas = new LinkedList<>();
872 String aaiResourceBasePaths = "testErrorWhenAllottedResourceWithOutDependingServiceId/";
873 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
874 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
875 Assert.assertEquals(data.getErrorData().isEmpty(),false);
876 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format
877 (GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING, "707b2850-e830-4b00-9902-879f44ac05a4"));
878 } catch (Exception e) {
879 Assert.fail(e.getMessage());
884 public void testArtifactGenerationWithoutAllottedResource() {
886 Map<String, Model> outputArtifactMap = new HashMap<>();
887 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
888 List<ToscaTemplate> toscas = new LinkedList<>();
889 String aaiResourceBasePaths = "testArtifactGeneration16/";
890 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
891 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
892 Assert.assertEquals(data.getErrorData().isEmpty(),false);
893 Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format
894 (GENERATOR_AAI_PROVIDING_SERVICE_MISSING, "a54a5235-b69d-4f8a-838b-d011e6783fa5"));
895 } catch (Exception e) {
896 Assert.fail(e.getMessage());
901 public void testArtifactGenerationAllottedResourceIpmuxSameInvariantDiffVersion() {
903 Map<String, Model> outputArtifactMap = new HashMap<>();
904 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
905 List<ToscaTemplate> toscas = new LinkedList<>();
906 String aaiResourceBasePaths = "testArtifactGeneration17/";
907 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
908 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
909 if (data.getErrorData().isEmpty()) {
910 for (Artifact inputArtifact : inputArtifacts) {
911 toscas.add(getToscaModel(inputArtifact));
913 List<Artifact> resultData = data.getResultData();
915 Assert.assertEquals(resultData.size(),5);
916 outputArtifactMap = populateAAIGeneratedModelStore(resultData);
917 testServiceTosca(toscas, outputArtifactMap);
918 testResourceTosca(toscas.iterator(), outputArtifactMap);
920 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
923 } catch (Exception e) {
924 Assert.fail(e.getMessage());
929 public void testArtifactGenerationAllottedResourceIpmuxSameInvariantSameVersion() {
931 Map<String, Model> outputArtifactMap = new HashMap<>();
932 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
933 List<ToscaTemplate> toscas = new LinkedList<>();
934 String aaiResourceBasePaths = "testArtifactGeneration18/";
935 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
936 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
937 if (data.getErrorData().isEmpty()) {
938 for (Artifact inputArtifact : inputArtifacts) {
939 toscas.add(getToscaModel(inputArtifact));
941 List<Artifact> resultData = data.getResultData();
944 Assert.assertEquals(resultData.size(),4);
945 outputArtifactMap = populateAAIGeneratedModelStore(resultData);
946 testServiceTosca(toscas, outputArtifactMap);
947 testResourceTosca(toscas.iterator(), outputArtifactMap);
949 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
952 } catch (Exception e) {
953 Assert.fail(e.getMessage());
958 public void testArtifactGenerationAllottedResourceIpmuxWithGroups() {
960 Map<String, Model> outputArtifactMap = new HashMap<>();
961 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
962 List<ToscaTemplate> toscas = new LinkedList<>();
963 String aaiResourceBasePaths = "testAllotedResourceWithDependingSerWithGroups/";
964 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
965 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
966 if (data.getErrorData().isEmpty()) {
967 for (Artifact inputArtifact : inputArtifacts) {
968 toscas.add(getToscaModel(inputArtifact));
970 List<Artifact> resultData = data.getResultData();
972 Assert.assertEquals(resultData.size(),5);
973 outputArtifactMap = populateAAIGeneratedModelStore(resultData);
974 testServiceTosca(toscas, outputArtifactMap);
975 testResourceTosca(toscas.iterator(), outputArtifactMap);
977 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
980 } catch (Exception e) {
981 Assert.fail(e.getMessage());
986 public void testArtifactGenerationAllottedResourceWithVF() {
988 Map<String, Model> outputArtifactMap = new HashMap<>();
989 ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
990 List<ToscaTemplate> toscas = new LinkedList<>();
991 String aaiResourceBasePaths = "testArtifactGenerationAllottedResourceWithVF/";
992 List<Artifact> inputArtifacts = init(aaiResourceBasePaths);
993 GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams);
994 if (data.getErrorData().isEmpty()) {
995 for (Artifact inputArtifact : inputArtifacts) {
996 toscas.add(getToscaModel(inputArtifact));
998 List<Artifact> resultData = data.getResultData();
1000 Assert.assertEquals(resultData.size(),7);
1001 outputArtifactMap = populateAAIGeneratedModelStore(resultData);
1002 testServiceTosca(toscas, outputArtifactMap);
1003 testResourceTosca(toscas.iterator(), outputArtifactMap);
1005 Assert.fail("error encountered : " + data.getErrorData().get("AAI"));
1008 } catch (Exception e) {
1009 Assert.fail(e.getMessage());
1015 public void testServiceTosca(List<ToscaTemplate> toscas, Map<String, Model> outputArtifactMap) {
1017 ToscaTemplate serviceTosca = getServiceTosca(toscas);
1018 if (serviceTosca == null) {
1019 Assert.fail("Service Tosca not found");
1021 serviceTosca.getMetadata().put("version", "1.0");
1022 Service service = new Service();
1023 service.populateModelIdentificationInformation(serviceTosca.getMetadata());
1024 String serviceNameVersionId = service.getModelNameVersionId();
1025 Model serviceAAIModel = getAAIModelByNameVersionId(serviceNameVersionId, outputArtifactMap);
1026 validateServiceModelMetadata(service, serviceAAIModel);
1027 //Validate Service instance base widget
1028 ModelVer modelVersion = serviceAAIModel.getModelVers().getModelVer().get(0);
1030 List<ModelElement> matchedServiceBaseWidgetElements =
1031 getModelElementbyRelationshipValue( modelVersion.getModelElements(),
1032 Widget.getWidget(Widget.Type.SERVICE).getId());
1033 validateMatchedModelElementsInService(matchedServiceBaseWidgetElements,
1034 Widget.getWidget(Widget.Type.SERVICE).getName());
1036 validateWidgetIds(matchedServiceBaseWidgetElements, Widget.getWidget(Widget.Type.SERVICE).getName(),
1037 Widget.getWidget(Widget.Type.SERVICE).getWidgetId());
1039 ModelElements baseServiceWidgetModelElements =
1040 matchedServiceBaseWidgetElements.get(0).getModelElements();
1043 Map<String, String> nodeTemplateIdTypeStore = getNodeTemplateTypeStore(serviceTosca);
1044 if (nodeTemplateIdTypeStore != null) {
1045 for (String key : nodeTemplateIdTypeStore.keySet()) {
1046 if (nodeTemplateIdTypeStore.get(key).contains("org.openecomp.resource.vf")) {
1047 List<ModelElement> matchedResourceElements =
1048 getModelElementbyRelationshipValue(baseServiceWidgetModelElements, key);
1049 if (nodeTemplateIdTypeStore.get(key).contains("org.openecomp.resource.vf.allottedResource")){
1050 validateMatchedModelElementsInService(matchedResourceElements,
1051 Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getName());
1053 validateMatchedModelElementsInService(matchedResourceElements,
1054 Widget.getWidget(Widget.Type.VF).getName());
1057 //Validate uuid and invariantuuid are populated in model-ver.model-version-id and model.model-invariant-id
1058 Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList()
1059 .getRelationship().get(0)
1060 .getRelationshipData().get(0).getRelationshipValue(),key);
1062 Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList().getRelationship().get(0)
1063 .getRelationshipData().get(1).getRelationshipValue(), nodeTemplateIdTypeStore
1064 .get(key+"-INV_UID"));
1065 } else if(nodeTemplateIdTypeStore.get(key).contains("org.openecomp.resource.vl")){
1066 //validate l3-network in service tosca
1067 List<ModelElement> matchedResourceElements =
1068 getModelElementbyRelationshipValue(baseServiceWidgetModelElements, key);
1069 validateMatchedModelElementsInService(matchedResourceElements,
1070 Widget.getWidget(Widget.Type.L3_NET).getName());
1071 //Validate uuid and invariantuuid are populated in model-ver.model-version-id and model.model-invariant-id
1072 Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList()
1073 .getRelationship().get(0)
1074 .getRelationshipData().get(0).getRelationshipValue(),key);
1076 Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList().getRelationship().get(0)
1077 .getRelationshipData().get(1).getRelationshipValue(), nodeTemplateIdTypeStore
1078 .get(key+"-INV_UID"));
1083 System.out.println();
1086 } catch (IllegalArgumentException e) {
1087 Assert.fail(e.getMessage()); //Can come while populating metadata
1091 private void validateWidgetIds(List<ModelElement> matchedServiceBaseWidgetElements,
1092 String widgetName, String widgetInvUuId) {
1093 Assert.assertEquals(matchedServiceBaseWidgetElements.get(0).getRelationshipList().getRelationship().get(0)
1094 .getRelationshipData().get(0).getRelationshipValue(), properties.getProperty(ArtifactType.AAI.name()
1095 + ".model-version-id."+ widgetName));
1097 Assert.assertEquals(matchedServiceBaseWidgetElements.get(0).getRelationshipList().getRelationship().get(0)
1098 .getRelationshipData().get(1).getRelationshipValue(), widgetInvUuId);
1102 public void testL3NetworkResourceTosca(Map<String, Model> outputArtifactMap , ToscaTemplate
1105 if (resourceTosca != null) {
1106 Resource resource = new Resource();
1107 resource.populateModelIdentificationInformation(resourceTosca.getMetadata());
1108 String resourceNameVersionId = resource.getModelNameVersionId();
1109 Model resourceAAIModel =
1110 getAAIModelByNameVersionId(resourceNameVersionId, outputArtifactMap);
1111 if (resourceAAIModel != null) {
1112 validateResourceModelMetadata(resource, resourceAAIModel);
1113 //Validate Resource instance base widget
1115 ModelVer modelVersion = resourceAAIModel.getModelVers().getModelVer().get(0);
1117 List<ModelElement> matchedVFBaseWidgetElements =
1118 getModelElementbyRelationshipValue(modelVersion.getModelElements(),
1119 Widget.getWidget(Widget.Type.L3_NET).getId());
1120 validateMatchedModelElementsInService(matchedVFBaseWidgetElements,
1121 Widget.getWidget(Widget.Type.L3_NET).getName());
1123 validateWidgetIds(matchedVFBaseWidgetElements, Widget.getWidget(Widget.Type.L3_NET).getName(),
1124 Widget.getWidget(Widget.Type.L3_NET).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 void testAllottedResourceTosca(Map<String, Model> outputArtifactMap , ToscaTemplate
1140 if (resourceTosca != null) {
1141 Resource resource = new Resource();
1142 resource.populateModelIdentificationInformation(resourceTosca.getMetadata());
1143 String resourceNameVersionId = resource.getModelNameVersionId();
1144 Model resourceAAIModel =
1145 getAAIModelByNameVersionId(resourceNameVersionId, outputArtifactMap);
1146 if (resourceAAIModel != null) {
1147 validateResourceModelMetadata(resource, resourceAAIModel);
1148 //Validate Resource instance base widget
1150 ModelVer modelVersion = resourceAAIModel.getModelVers().getModelVer().get(0);
1152 List<ModelElement> matchedVFBaseWidgetElements =
1153 getModelElementbyRelationshipValue(modelVersion.getModelElements(),
1154 Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getId());
1155 validateMatchedModelElementsInService(matchedVFBaseWidgetElements,
1156 Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getName());
1158 validateWidgetIds(matchedVFBaseWidgetElements, Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getName(),
1159 Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getWidgetId());
1161 Map<String, Object> dependingServiceDetails = getProvidingServiceDetails(resourceTosca);
1163 ModelElements containedModelElements = modelVersion.getModelElements().getModelElement().
1164 get(0).getModelElements();
1165 Assert.assertEquals( containedModelElements.getModelElement().get(0).getRelationshipList()
1166 .getRelationship().get(0).getRelationshipData().get(0).getRelationshipValue(),
1167 dependingServiceDetails.get("providing_service_uuid"));
1169 Assert.assertEquals(containedModelElements.getModelElement().get(0).getRelationshipList()
1170 .getRelationship().get(0).getRelationshipData().get(1).getRelationshipValue(),
1171 dependingServiceDetails.get("providing_service_invariant_uuid"));
1173 if("Allotted Resource".equals(resourceTosca.getMetadata().get("category")) &&
1174 "Tunnel XConnect".equals(resourceTosca.getMetadata().get("subcategory"))) {
1176 List<ModelElement> matchedTunnelXConnectWidgetElements =
1177 getModelElementbyRelationshipValue(containedModelElements,
1178 Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getId());
1179 validateMatchedModelElementsInService(matchedTunnelXConnectWidgetElements,
1180 Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getName());
1182 validateWidgetIds(matchedTunnelXConnectWidgetElements, Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getName(),
1183 Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getWidgetId());
1187 System.out.println("Resource mapping not found for " + resourceNameVersionId);
1191 }catch (IllegalArgumentException e) {
1192 Assert.fail(e.getMessage()); //Can come while populating metadata
1197 public Map<String, Object> getProvidingServiceDetails(ToscaTemplate resourceTemplate) {
1198 Set<String> keys = resourceTemplate.getTopology_template().getNode_templates().keySet();
1200 Map<String, Object> nodeProperties =null;
1201 for(String key : keys) {
1202 NodeTemplate node = resourceTemplate.getTopology_template().getNode_templates().get(key);
1203 if(node.getType().equals("org.openecomp.resource.vfc.AllottedResource")) {
1204 nodeProperties = node.getProperties();
1208 return nodeProperties;
1211 public void testVfTosca(Map<String, Model> outputArtifactMap , ToscaTemplate resourceTosca) {
1213 //ToscaTemplate resourceTosca = getResourceTosca(toscas);
1214 //resourceTosca.getTopology_template().getGroups().
1215 if (resourceTosca != null) {
1216 Resource resource = new Resource();
1217 resource.populateModelIdentificationInformation(resourceTosca.getMetadata());
1218 String resourceNameVersionId = resource.getModelNameVersionId();
1219 Model resourceAAIModel =
1220 getAAIModelByNameVersionId(resourceNameVersionId, outputArtifactMap);
1221 if (resourceAAIModel != null) {
1222 validateResourceModelMetadata(resource, resourceAAIModel);
1223 //Validate Resource instance base widget
1225 ModelVer modelVersion = resourceAAIModel.getModelVers().getModelVer().get(0);
1227 List<ModelElement> matchedVFBaseWidgetElements =
1228 getModelElementbyRelationshipValue(modelVersion.getModelElements(),
1229 Widget.getWidget(Widget.Type.VF).getId());
1230 validateMatchedModelElementsInService(matchedVFBaseWidgetElements,
1231 Widget.getWidget(Widget.Type.VF).getName());
1233 validateWidgetIds(matchedVFBaseWidgetElements, Widget.getWidget(Widget.Type.VF).getName(),
1234 Widget.getWidget(Widget.Type.VF).getWidgetId());
1236 ModelElements baseResourceWidgetModelElements =
1237 matchedVFBaseWidgetElements.get(0).getModelElements();
1238 if (resourceTosca.getTopology_template() != null) {
1239 Map<String, String> groupIdTypeStore = getGroupsTypeStore(resourceTosca);
1241 if (baseResourceWidgetModelElements.getModelElement().size() !=
1242 groupIdTypeStore.size()) {
1243 Assert.fail("Missing VFModule in VF model.xml");
1246 for (String key : groupIdTypeStore.keySet()) {
1248 List<ModelElement> matchedResourceElements =
1249 getModelElementbyRelationshipValue(baseResourceWidgetModelElements, key);
1250 validateMatchedModelElementsInService(matchedResourceElements,
1251 Widget.getWidget(Widget.Type.VFMODULE).getName());
1252 Model resourceAAIVFModel = getAAIModelByNameVersionId(key, outputArtifactMap);
1253 Map<String, String> vfModuleModelMetadata =
1254 getVFModuleMetadataTosca(resourceTosca, key);
1255 Map<String, Object> vfModuleMembers = getVFModuleMembersTosca(resourceTosca, key);
1257 validateVFModelMetadata(vfModuleModelMetadata, resourceAAIVFModel);
1260 ModelVer modelVfVersion = resourceAAIVFModel.getModelVers().getModelVer().get(0);
1262 List<ModelElement> matchedVFModuleBaseWidgetElements =
1263 getModelElementbyRelationshipValue(modelVfVersion.getModelElements(),
1264 Widget.getWidget(Widget.Type.VFMODULE).getId());
1265 validateMatchedModelElementsInService(matchedVFModuleBaseWidgetElements,
1266 Widget.getWidget(Widget.Type.VFMODULE).getName());
1267 validateWidgetIds(matchedVFModuleBaseWidgetElements, Widget.getWidget(Widget.Type.VFMODULE)
1268 .getName(), Widget.getWidget(Widget.Type.VFMODULE).getWidgetId());
1270 ModelElements baseResourceVFModuleWidgetModelElements =
1271 matchedVFModuleBaseWidgetElements.get(0).getModelElements();
1272 if (vfModuleMembers.containsKey("l3-network")) {
1274 List<ModelElement> matchedL3NetworkElements =
1275 getModelElementbyRelationshipValue(baseResourceVFModuleWidgetModelElements,
1276 Widget.getWidget(Widget.Type.L3_NET).getId());
1277 validateMatchedModelElementsInService(matchedL3NetworkElements,
1278 Widget.getWidget(Widget.Type.L3_NET).getName());
1279 validateWidgetIds(matchedL3NetworkElements, Widget.getWidget(Widget.Type.L3_NET)
1280 .getName(), Widget.getWidget(Widget.Type.L3_NET).getWidgetId());
1282 if (vfModuleMembers.containsKey("vserver")) {
1284 List<ModelElement> matchedVserverElements =
1285 getModelElementbyRelationshipValue(baseResourceVFModuleWidgetModelElements,
1286 Widget.getWidget(Widget.Type.VSERVER).getId());
1287 validateMatchedModelElementsInService(matchedVserverElements,
1288 Widget.getWidget(Widget.Type.VSERVER).getName());
1289 ModelElements vserverWidgetModelElements =
1290 matchedVserverElements.get(0).getModelElements();
1292 validateWidgetIds(matchedVserverElements, Widget.getWidget(Widget.Type.VSERVER)
1293 .getName(), Widget.getWidget(Widget.Type.VSERVER).getWidgetId());
1296 //Validate vserver->vfc
1297 List<ModelElement> matchedVfcElements =
1298 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1299 Widget.getWidget(Widget.Type.VFC).getId());
1300 validateMatchedModelElementsInService(matchedVfcElements,
1301 Widget.getWidget(Widget.Type.VFC).getName());
1302 validateWidgetIds(matchedVfcElements, Widget.getWidget(Widget.Type.VFC).getName(),
1303 Widget.getWidget(Widget.Type.VFC).getWidgetId());
1305 //Validate vserver->Image
1306 List<ModelElement> matchedImageElements =
1307 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1308 Widget.getWidget(Widget.Type.IMAGE).getId());
1309 validateMatchedModelElementsInService(matchedImageElements,
1310 Widget.getWidget(Widget.Type.IMAGE).getName());
1311 validateWidgetIds(matchedImageElements, Widget.getWidget(Widget.Type.IMAGE)
1312 .getName(), Widget.getWidget(Widget.Type.IMAGE).getWidgetId());
1315 //Validate vserver->Flavor
1316 List<ModelElement> matchedFlavorElements =
1317 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1318 Widget.getWidget(Widget.Type.FLAVOR).getId());
1319 validateMatchedModelElementsInService(matchedFlavorElements,
1320 Widget.getWidget(Widget.Type.FLAVOR).getName());
1321 validateWidgetIds(matchedFlavorElements, Widget.getWidget(Widget.Type.FLAVOR).getName(),
1322 Widget.getWidget(Widget.Type.FLAVOR).getWidgetId());
1324 //Validate vserver->Tenant
1325 List<ModelElement> matchedTenantElements =
1326 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1327 Widget.getWidget(Widget.Type.TENANT).getId());
1328 validateMatchedModelElementsInService(matchedTenantElements,
1329 Widget.getWidget(Widget.Type.TENANT).getName());
1330 validateWidgetIds(matchedTenantElements, Widget.getWidget(Widget.Type.TENANT).getName(),
1331 Widget.getWidget(Widget.Type.TENANT).getWidgetId());
1333 //Validate vserver->l-interface
1334 if (vfModuleMembers.containsKey("l-interface")) {
1335 List<ModelElement> matchedLinterfaceElements =
1336 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1337 Widget.getWidget(Widget.Type.LINT).getId());
1338 validateMatchedModelElementsInService(matchedLinterfaceElements,
1339 Widget.getWidget(Widget.Type.LINT).getName());
1340 validateWidgetIds(matchedLinterfaceElements, Widget.getWidget(Widget.Type.LINT).getName(),
1341 Widget.getWidget(Widget.Type.LINT).getWidgetId());
1343 //Validate vserver->volume
1344 if (vfModuleMembers.containsKey("volume")) {
1345 List<ModelElement> matchedVolumeElements =
1346 getModelElementbyRelationshipValue(vserverWidgetModelElements,
1347 Widget.getWidget(Widget.Type.VOLUME).getId());
1348 validateMatchedModelElementsInService(matchedVolumeElements,
1349 Widget.getWidget(Widget.Type.VOLUME).getName());
1350 validateWidgetIds(matchedVolumeElements, Widget.getWidget(Widget.Type.VOLUME).getName(),
1351 Widget.getWidget(Widget.Type.VOLUME).getWidgetId());
1357 System.out.println("Resource mapping not found for " + resourceNameVersionId);
1361 } catch (IllegalArgumentException e) {
1362 Assert.fail(e.getMessage()); //Can come while populating metadata
1367 private void validateMatchedModelElementsInService(List<ModelElement> matchedModelElements,
1369 if (matchedModelElements.isEmpty()) {
1370 Assert.fail(modelType + " not present ");
1372 if (matchedModelElements.size() > 1) {
1373 Assert.fail("More than one " + modelType + " present ");
1377 private Map<String, String> getNodeTemplateTypeStore(ToscaTemplate toscaTemplate) {
1378 if (toscaTemplate.getTopology_template() != null) {
1379 Map<String, NodeTemplate> nodeTemplateMap =
1380 toscaTemplate.getTopology_template().getNode_templates();
1381 Map<String, String> nodeTemplateIdTypeStore = new LinkedHashMap<>();
1382 if (nodeTemplateMap != null) {
1383 for (Map.Entry<String, NodeTemplate> e : nodeTemplateMap.entrySet()) {
1384 String uuid = e.getValue().getMetadata().get("resourceUUID");
1385 if (GeneratorUtil.isEmpty(uuid)) {
1386 uuid = e.getValue().getMetadata().get("UUID");
1387 if (GeneratorUtil.isEmpty(uuid)) {
1388 Assert.fail("UUID Not found");
1391 if(e.getValue().getType().contains("org.openecomp.resource.vf.")&& (e.getValue()
1392 .getMetadata().get("category").equals("Allotted Resource")))
1394 e.getValue().setType("org.openecomp.resource.vf.allottedResource");
1396 nodeTemplateIdTypeStore.put(uuid, e.getValue().getType());
1397 resourcesVersion.put(uuid,e.getValue().getMetadata().get
1399 //Populate invraintUuId for V9
1400 String invUuId = e.getValue().getMetadata().get("invariantUUID");
1401 nodeTemplateIdTypeStore.put(uuid+"-INV_UID" , invUuId);
1404 return nodeTemplateIdTypeStore;
1410 private Map<String, String> getGroupsTypeStore(ToscaTemplate toscaTemplate) {
1411 if (toscaTemplate.getTopology_template() != null) {
1412 Map<String, GroupDefinition> groupDefinitionMap =
1413 toscaTemplate.getTopology_template().getGroups();
1414 Map<String, String> groupDefinitionIdTypeStore = new LinkedHashMap<>();
1415 if (groupDefinitionMap != null) {
1416 for (Map.Entry<String, GroupDefinition> e : groupDefinitionMap.entrySet()) {
1417 if (e.getValue().getType().contains("org.openecomp.groups.VfModule")) {
1418 String uuid = e.getValue().getMetadata().get("vfModuleModelUUID");
1419 if (GeneratorUtil.isEmpty(uuid)) {
1420 uuid = e.getValue().getMetadata().get("UUID");
1421 if (GeneratorUtil.isEmpty(uuid)) {
1422 Assert.fail("UUID Not found");
1425 groupDefinitionIdTypeStore.put(uuid, e.getValue().getType());
1429 return groupDefinitionIdTypeStore;
1436 private void validateServiceModelMetadata(Service serviceToscaModel, Model generatedAAIModel) {
1437 ModelVer modelVersion = generatedAAIModel.getModelVers().getModelVer().get(0);
1438 Assert.assertEquals(serviceToscaModel.getModelNameVersionId(),
1439 modelVersion.getModelVersionId());
1440 Assert.assertEquals(serviceToscaModel.getModelId(), generatedAAIModel.getModelInvariantId());
1441 Assert.assertEquals(serviceToscaModel.getModelName(), modelVersion.getModelName());
1442 Assert.assertEquals(additionalParams.get(AdditionalParams.ServiceVersion.getName()), modelVersion
1443 .getModelVersion());
1444 Assert.assertEquals(serviceToscaModel.getModelDescription(),
1445 modelVersion.getModelDescription());
1449 private void validateResourceModelMetadata(Resource resouerceToscaModel,
1450 Model generatedAAIModel) {
1451 ModelVer modelVersion = generatedAAIModel.getModelVers().getModelVer().get(0);
1452 Assert.assertEquals(resouerceToscaModel.getModelNameVersionId(),
1453 modelVersion.getModelVersionId());
1454 Assert.assertEquals(resouerceToscaModel.getModelId(), generatedAAIModel.getModelInvariantId());
1455 Assert.assertEquals(resouerceToscaModel.getModelName(), modelVersion.getModelName());
1457 .assertEquals(resouerceToscaModel.getModelVersion(), modelVersion.getModelVersion());
1458 Assert.assertEquals(resouerceToscaModel.getModelDescription(),
1459 modelVersion.getModelDescription());
1463 private void validateVFModelMetadata(Map<String, String> vfModuleModelMetadata,
1464 Model generatedAAIModel) {
1465 ModelVer modelVersion = generatedAAIModel.getModelVers().getModelVer().get(0);
1466 Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelUUID"),
1467 modelVersion.getModelVersionId());
1468 Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelInvariantUUID"),
1469 generatedAAIModel.getModelInvariantId());
1470 Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelName"),
1471 modelVersion.getModelName());
1472 Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelVersion"),
1473 modelVersion.getModelVersion());
1474 Assert.assertEquals(vfModuleModelMetadata.get("vf_module_description"),
1475 modelVersion.getModelDescription());
1478 private Model getAAIModelByNameVersionId(String nameVersionId,
1479 Map<String, Model> outputArtifactMap) {
1480 return outputArtifactMap.get(nameVersionId);
1483 private List<ModelElement> getModelElementbyRelationshipValue(ModelElements modelElements,
1484 String relationshipValue) {
1485 List<ModelElement> matchedModelElements = new ArrayList<>();
1486 if (modelElements != null) {
1487 List<ModelElement> modelElementList = modelElements.getModelElement();
1488 for (ModelElement element : modelElementList) {
1489 List<Relationship> relationshipList = element.getRelationshipList().getRelationship();
1490 for (Relationship r : relationshipList) {
1491 List<RelationshipData> relationshipDataList = r.getRelationshipData();
1492 for (RelationshipData relationshipData : relationshipDataList) {
1493 if (relationshipData.getRelationshipValue().equals(relationshipValue)) {
1494 matchedModelElements.add(element);
1500 return matchedModelElements;
1503 private Map<String, Model> populateAAIGeneratedModelStore(List<Artifact> resultData) {
1504 Map<String, Model> outputArtifactMap = new HashMap<>();
1505 for (Artifact outputArtifact : resultData) {
1506 if (outputArtifact.getType().equals(ArtifactType.MODEL_INVENTORY_PROFILE.name())) {
1507 byte[] decodedPayload = GeneratorUtil.decoder(outputArtifact.getPayload());
1508 Model aaiModel = getUnmarshalledArtifactModel(new String(decodedPayload));
1509 List<ModelVer> modelVersions = aaiModel.getModelVers().getModelVer();
1510 outputArtifactMap.put(modelVersions.get(0).getModelVersionId(), aaiModel);
1513 return outputArtifactMap;
1516 private Model getUnmarshalledArtifactModel(String aaiModel) {
1517 JAXBContext jaxbContext;
1519 jaxbContext = JAXBContext.newInstance(Model.class);
1520 Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
1521 InputStream aaiModelStream = new ByteArrayInputStream(aaiModel.getBytes());
1522 return (Model) unmarshaller.unmarshal(aaiModelStream);
1523 } catch (JAXBException e) {
1524 e.printStackTrace();
1530 * Get the tosca java model from the tosca input artifact
1532 * @param input Input tosca file and its metadata information as {@link Artifact} object
1533 * @return Translated {@link ToscaTemplate tosca} object
1535 private ToscaTemplate getToscaModel(Artifact input) throws SecurityException {
1536 byte[] decodedInput = GeneratorUtil.decoder(input.getPayload());
1537 String checksum = GeneratorUtil.checkSum(decodedInput);
1538 if (checksum.equals(input.getChecksum())) {
1540 return GeneratorUtil.translateTosca(new String(decodedInput), ToscaTemplate.class);
1541 } catch (Exception e) {
1542 e.printStackTrace();
1543 throw new IllegalArgumentException(
1544 String.format(GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_TOSCA, input.getName()));
1547 throw new SecurityException(
1548 String.format(GeneratorConstants.GENERATOR_AAI_ERROR_CHECKSUM_MISMATCH, input.getName()));
1553 * Identify the service tosca artifact from the list of translated tosca inputs
1555 * @param input List of translated {@link ToscaTemplate tosca} object models
1556 * @return Identified service {@link ToscaTemplate tosca}
1558 private ToscaTemplate getServiceTosca(List<ToscaTemplate> input) {
1559 Iterator<ToscaTemplate> iter = input.iterator();
1560 while (iter.hasNext()) {
1561 ToscaTemplate tosca = iter.next();
1562 if (tosca.isService()) {
1571 private ToscaTemplate getResourceTosca(List<ToscaTemplate> input) {
1572 Iterator<ToscaTemplate> iter = input.iterator();
1573 while (iter.hasNext()) {
1574 ToscaTemplate tosca = iter.next();
1575 if (!tosca.isService()) {
1584 private Map<String, String> getVFModuleMetadataTosca(ToscaTemplate toscaTemplate,
1585 String vfModuleModelUUID) {
1586 Map<String, GroupDefinition> groupDefinitionMap =
1587 toscaTemplate.getTopology_template().getGroups();
1588 Map<String, String> vfModuleModelMetadata = new LinkedHashMap<>();
1589 for (Map.Entry<String, GroupDefinition> e : groupDefinitionMap.entrySet()) {
1590 if (e.getValue().getType().contains("org.openecomp.groups.VfModule")) {
1591 String uuid = e.getValue().getMetadata().get("vfModuleModelUUID");
1592 if (uuid == vfModuleModelUUID) {
1593 vfModuleModelMetadata = e.getValue().getMetadata();
1594 vfModuleModelMetadata.put("vf_module_description",
1595 (String) e.getValue().getProperties().get("vf_module_description"));
1599 return vfModuleModelMetadata;
1602 private Map<String, Object> getVFModuleMembersTosca(ToscaTemplate toscaTemplate,
1603 String vfModuleModelUUID) {
1604 Map<String, GroupDefinition> groupDefinitionMap =
1605 toscaTemplate.getTopology_template().getGroups();
1606 Map<String, NodeTemplate> nodeTemplateMaps =
1607 toscaTemplate.getTopology_template().getNode_templates();
1608 Map<String, Object> vfModuleMembers = new LinkedHashMap<>();
1609 List<String> vfModuleModelMetadata = new ArrayList<>();
1610 for (Map.Entry<String, GroupDefinition> e : groupDefinitionMap.entrySet()) {
1611 if (e.getValue().getType().contains("org.openecomp.groups.VfModule")) {
1612 String uuid = e.getValue().getMetadata().get("vfModuleModelUUID");
1613 if (uuid == vfModuleModelUUID) {
1614 vfModuleModelMetadata = e.getValue().getMembers();
1615 if (vfModuleModelMetadata !=null) {
1616 Iterator itr = vfModuleModelMetadata.iterator();
1617 while (itr.hasNext()) {
1618 Object obj = itr.next();
1619 NodeTemplate nodeTemplate = nodeTemplateMaps.get(obj);
1620 String nodetype = null;
1621 if (nodeTemplate != null) {
1622 nodetype = nodeTemplate.getType();
1624 if (nodetype != null) {
1625 String widgetType = membersType(nodetype);
1626 if (widgetType != null) {
1627 vfModuleMembers.put(widgetType, obj);
1636 return vfModuleMembers;
1640 private String membersType(String toscaType) {
1641 String modelToBeReturned = null;
1642 while (toscaType != null && toscaType.lastIndexOf(".") != -1 && modelToBeReturned == null) {
1644 switch (toscaType) {
1645 case "org.openecomp.resource.vf.allottedResource":
1646 modelToBeReturned = "allotted-resource";
1648 case "org.openecomp.resource.vfc":
1649 modelToBeReturned = "vserver";
1651 case "org.openecomp.resource.cp":
1652 case "org.openecomp.cp":
1653 modelToBeReturned = "l-interface";
1655 case "org.openecomp.resource.vl":
1656 modelToBeReturned = "l3-network";
1658 case "org.openecomp.resource.vf":
1659 modelToBeReturned = "generic-vnf";
1661 case "org.openecomp.groups.VfModule":
1662 modelToBeReturned = "vf-module";
1664 case "org.openecomp.resource.vfc.nodes.heat.cinder":
1665 modelToBeReturned = "volume";
1668 modelToBeReturned = null;
1672 toscaType = toscaType.substring(0, toscaType.lastIndexOf("."));
1674 return modelToBeReturned;
1677 private List<Artifact> init(String aaiResourceBasePaths) {
1678 List<Artifact> inputArtifacts1 = new ArrayList<>();
1681 String[] resourceFileList = {};
1682 URL resourceDirUrl = this.getClass().getClassLoader().getResource(aaiResourceBasePaths);
1683 if (resourceDirUrl != null && resourceDirUrl.getProtocol().equals("file")) {
1684 resourceFileList = new File(resourceDirUrl.toURI()).list();
1686 Assert.fail("Invalid resource directory");
1689 for (int i = 0; i < resourceFileList.length; i++) {
1690 byte[] payload = null;
1691 File resourceFile = new File(
1692 this.getClass().getClassLoader().getResource(aaiResourceBasePaths + resourceFileList[i])
1694 FileInputStream fileInputStream;
1695 //convert service tosca file into array of bytes
1696 payload = new byte[(int) resourceFile.length()];
1697 fileInputStream = new FileInputStream(resourceFile);
1698 fileInputStream.read(payload);
1699 fileInputStream.close();
1700 String checksum = GeneratorUtil.checkSum(payload);
1701 byte[] encodedPayload = GeneratorUtil.encode(payload);
1703 new Artifact(aaiArtifactType, aaiArtifactGroupType, checksum, encodedPayload);
1704 artifact.setName(resourceFileList[i]);
1705 artifact.setLabel(resourceFileList[i]);
1706 artifact.setDescription(resourceFileList[i]);
1707 artifact.setVersion("1.0");
1708 inputArtifacts1.add(artifact);
1711 } catch (Exception e) {
1712 //e.printStackTrace();
1713 Assert.fail(e.getMessage());
1715 return inputArtifacts1;
1718 private void loadConfigFromClasspath(Properties properties) throws IOException {
1719 String configLocation = System.getProperty("artifactgenerator.config");
1720 if (configLocation != null) {
1721 File file = new File(configLocation);
1722 if (file.exists()) {
1723 properties.load(new FileInputStream(file));
1728 public void testResourceTosca(Iterator<ToscaTemplate> itr, Map<String, Model>
1729 outputArtifactMap) {
1730 while(itr.hasNext()){
1731 ToscaTemplate toscaTemplate = itr.next();
1732 String resourceVersion=resourcesVersion.get(toscaTemplate.getMetadata().get("UUID"));
1733 toscaTemplate.getMetadata().put("version", resourceVersion);
1734 if("VF".equals(toscaTemplate.getMetadata().get("type")) && !("Allotted Resource".equals
1735 (toscaTemplate.getMetadata().get("category"))) ){
1736 testVfTosca(outputArtifactMap, toscaTemplate);
1737 } else if("VF".equals(toscaTemplate.getMetadata().get("type")) && ("Allotted Resource".equals
1738 (toscaTemplate.getMetadata().get("category"))) ){
1739 testAllottedResourceTosca(outputArtifactMap, toscaTemplate);
1740 } else if("VL".equals(toscaTemplate.getMetadata().get("type"))){
1741 testL3NetworkResourceTosca(outputArtifactMap, toscaTemplate);