2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.onap.sdc.frontend.ci.tests.execute.sanity;
22 import static org.hamcrest.MatcherAssert.assertThat;
23 import static org.hamcrest.Matchers.anEmptyMap;
24 import static org.hamcrest.Matchers.empty;
25 import static org.hamcrest.Matchers.emptyString;
26 import static org.hamcrest.Matchers.hasSize;
27 import static org.hamcrest.Matchers.is;
28 import static org.hamcrest.Matchers.not;
29 import static org.hamcrest.Matchers.notNullValue;
30 import static org.junit.jupiter.api.Assertions.assertEquals;
31 import static org.junit.jupiter.api.Assertions.assertNotNull;
32 import static org.junit.jupiter.api.Assertions.assertTrue;
33 import static org.junit.jupiter.api.Assertions.fail;
35 import com.aventstack.extentreports.Status;
36 import java.io.IOException;
37 import java.util.ArrayList;
38 import java.util.Arrays;
39 import java.util.List;
41 import java.util.Map.Entry;
42 import java.util.Optional;
43 import java.util.stream.Collectors;
44 import org.onap.sdc.backend.ci.tests.config.Config;
45 import org.onap.sdc.backend.ci.tests.data.providers.OnboardingDataProviders;
46 import org.onap.sdc.backend.ci.tests.datatypes.enums.ComponentType;
47 import org.onap.sdc.backend.ci.tests.datatypes.enums.ResourceCategoryEnum;
48 import org.onap.sdc.backend.ci.tests.utils.general.ElementFactory;
49 import org.onap.sdc.frontend.ci.tests.datatypes.ComponentData;
50 import org.onap.sdc.frontend.ci.tests.datatypes.ResourceCreateData;
51 import org.onap.sdc.frontend.ci.tests.datatypes.composition.RelationshipInformation;
52 import org.onap.sdc.frontend.ci.tests.exception.UnzipException;
53 import org.onap.sdc.frontend.ci.tests.execute.setup.DriverFactory;
54 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
55 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
56 import org.onap.sdc.frontend.ci.tests.flow.AddNodeToCompositionFlow;
57 import org.onap.sdc.frontend.ci.tests.flow.CreateVfFlow;
58 import org.onap.sdc.frontend.ci.tests.flow.CreateVfcFlow;
59 import org.onap.sdc.frontend.ci.tests.flow.DownloadCsarArtifactFlow;
60 import org.onap.sdc.frontend.ci.tests.flow.composition.CreateRelationshipFlow;
61 import org.onap.sdc.frontend.ci.tests.flow.exception.UiTestFlowRuntimeException;
62 import org.onap.sdc.frontend.ci.tests.pages.AttributesOutputsPage;
63 import org.onap.sdc.frontend.ci.tests.pages.ComponentPage;
64 import org.onap.sdc.frontend.ci.tests.pages.ResourceCreatePage;
65 import org.onap.sdc.frontend.ci.tests.pages.TopNavComponent;
66 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionPage;
67 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.ToscaArtifactsPage;
68 import org.onap.sdc.frontend.ci.tests.pages.home.HomePage;
69 import org.onap.sdc.frontend.ci.tests.utilities.FileHandling;
70 import org.openecomp.sdc.be.model.ComponentInstance;
71 import org.openqa.selenium.WebDriver;
72 import org.slf4j.Logger;
73 import org.slf4j.LoggerFactory;
74 import org.testng.annotations.BeforeClass;
75 import org.testng.annotations.BeforeMethod;
76 import org.testng.annotations.Test;
77 import org.yaml.snakeyaml.Yaml;
79 public class ServiceTemplateDesignUiTests extends SetupCDTest {
81 private static final Logger LOGGER = LoggerFactory.getLogger(ServiceTemplateDesignUiTests.class);
83 private WebDriver webDriver;
84 private TopNavComponent topNavComponent;
85 private HomePage homePage;
86 private List<ResourceCreateData> vfcs = new ArrayList<>();
87 private ResourceCreateData vfResourceCreateData;
88 private ComponentInstance networkFunctionInstance;
89 private ComponentInstance networkServiceInstance;
90 private AddNodeToCompositionFlow addNodeToCompositionFlow;
94 webDriver = DriverFactory.getDriver();
95 topNavComponent = new TopNavComponent(webDriver);
96 homePage = new HomePage(webDriver);
99 @Test(dataProviderClass = OnboardingDataProviders.class, dataProvider = "vfcList")
100 public void importAndCertifyVfc(final String rootFolder, final String vfcFilename) {
102 final String resourceName = ElementFactory.addRandomSuffixToName(ElementFactory.getResourcePrefix());
103 final CreateVfcFlow createVfcFlow = createVFC(rootFolder + vfcFilename, resourceName);
104 vfcs.stream().filter(vfc -> vfc.getName().startsWith(resourceName)).findFirst().orElseThrow(
105 () -> new UiTestFlowRuntimeException(String.format("VFCs List should contain a VFC with the expected name %s", resourceName)));
106 final ResourceCreatePage vfcResourceCreatePage = createVfcFlow.getLandedPage()
107 .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected ResourceCreatePage"));
108 vfcResourceCreatePage.isLoaded();
109 vfcResourceCreatePage.certifyComponent();
110 ExtentTestActions.takeScreenshot(Status.INFO, "vfc-certified",
111 String.format("VFC '%s' was certified", resourceName));
114 @Test(dependsOnMethods = "importAndCertifyVfc")
115 public void runServiceDesign() throws UnzipException {
116 final CreateVfFlow createVfFlow = createVF();
117 addNodeToCompositionFlow = addNodeToCompositionAndCreateRelationship(createVfFlow);
118 final CompositionPage compositionPage = addNodeToCompositionFlow.getLandedPage()
119 .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected return CompositionPage"));
120 compositionPage.isLoaded();
121 final ComponentPage componentPage = compositionPage.goToGeneral();
122 componentPage.isLoaded();
123 downloadAndVerifyCsarPackage(componentPage);
126 @Test(dependsOnMethods = "runServiceDesign")
127 public void addOutputsToVF_test() throws UnzipException, IOException {
129 final ComponentPage resourceCreatePage = (ComponentPage) homePage.clickOnComponent(vfResourceCreateData.getName());
130 resourceCreatePage.isLoaded();
132 final AttributesOutputsPage attributesOutputsPage = resourceCreatePage.goToAttributesOutputs();
133 attributesOutputsPage.isLoaded();
135 final ComponentInstance createdComponentInstance = addNodeToCompositionFlow.getCreatedComponentInstance()
136 .orElseThrow(() -> new UiTestFlowRuntimeException("Expecting a ComponentInstance"));
138 attributesOutputsPage.clickOnAttributeNavigation(createdComponentInstance.getName());
139 assertTrue(attributesOutputsPage.isAttributePresent("attr_1"));
140 attributesOutputsPage.declareOutput("attr_1");
141 attributesOutputsPage.clickOnOutputsTab();
142 assertTrue(attributesOutputsPage.isOutputPresent("attr_1"));
144 attributesOutputsPage.clickOnAttributesTab();
145 assertTrue(attributesOutputsPage.isAttributePresent("attr_2"));
146 attributesOutputsPage.declareOutput("attr_2");
147 attributesOutputsPage.clickOnOutputsTab();
148 assertTrue(attributesOutputsPage.isOutputPresent("attr_2"));
150 attributesOutputsPage.clickOnAttributesTab();
151 assertTrue(attributesOutputsPage.isAttributePresent("attr_3"));
152 attributesOutputsPage.declareOutput("attr_3");
153 attributesOutputsPage.clickOnOutputsTab();
154 assertTrue(attributesOutputsPage.isOutputPresent("attr_3"));
156 attributesOutputsPage.deleteOutput(createdComponentInstance.getName() + "_attr_2");
157 attributesOutputsPage.clickOnAttributesTab();
158 assertTrue(attributesOutputsPage.isAttributePresent("attr_2"));
159 attributesOutputsPage.clickOnOutputsTab();
160 assertTrue(attributesOutputsPage.isOutputDeleted("attr_2"));
162 attributesOutputsPage.clickOnAttributesTab();
163 ExtentTestActions.addScreenshot(Status.INFO, "AttributesTab", "The Attribute's list : ");
165 attributesOutputsPage.clickOnOutputsTab();
166 ExtentTestActions.addScreenshot(Status.INFO, "OutputsTab", "The Output's list : ");
168 attributesOutputsPage.certifyComponent();
169 attributesOutputsPage.isLoaded();
171 Map<String, Object> yamlObject = downloadToscaArtifact(attributesOutputsPage);
172 checkMetadata(yamlObject, vfResourceCreateData);
173 checkTopologyTemplate(yamlObject);
177 private void checkMetadata(final Map<String, Object> map, final ResourceCreateData createdData) {
178 final Map<String, Object> metadata = getMapEntry(map, "metadata");
180 assertEquals(createdData.getName(), metadata.get("name"));
181 assertEquals(createdData.getDescription(), metadata.get("description"));
182 assertEquals("Generic", metadata.get("category"));
183 assertThat((String) metadata.get("type"), not(emptyString()));
184 assertEquals(createdData.getCategory(), metadata.get("subcategory"));
185 assertEquals(createdData.getVendorName(), metadata.get("resourceVendor"));
186 assertEquals(createdData.getVendorRelease(), metadata.get("resourceVendorRelease"));
187 assertEquals(createdData.getVendorModelNumber(), metadata.get("reourceVendorModelNumber"));
190 private void checkTopologyTemplate(final Map<String, Object> map) {
191 final Map<String, Object> mapEntry = getMapEntry(map, "topology_template");
192 assertNotNull(mapEntry);
194 final Map<String, Object> inputs = getMapEntry(mapEntry, "inputs");
195 assertThat(inputs, not(anEmptyMap()));
197 final Map<String, Object> outputs = getMapEntry(mapEntry, "outputs");
198 assertThat(outputs, not(anEmptyMap()));
199 assertEquals(2, outputs.keySet().stream().filter(s -> (s.contains("_attr_1") || s.contains("_attr_3")) && !s.contains("_attr_2")).count());
201 final Map<String, Object> nodeTemplates = getMapEntry(mapEntry, "node_templates");
202 assertThat(nodeTemplates, not(anEmptyMap()));
204 final Map<String, Object> substitutionMappings = getMapEntry(mapEntry, "substitution_mappings");
205 assertThat(substitutionMappings, not(anEmptyMap()));
207 final Map<String, Object> attributes = getMapEntry(substitutionMappings, "attributes");
208 assertThat(attributes, not(anEmptyMap()));
209 assertEquals(2, attributes.keySet().stream().filter(s -> (s.contains("_attr_1") || s.contains("_attr_3")) && !s.contains("_attr_2")).count());
213 private Map<String, Object> downloadToscaArtifact(final ComponentPage resourceCreatePage) throws UnzipException {
214 final DownloadCsarArtifactFlow downloadCsarArtifactFlow = downloadToscaCsar(resourceCreatePage);
215 final ToscaArtifactsPage toscaArtifactsPage = downloadCsarArtifactFlow.getLandedPage()
216 .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected ToscaArtifactsPage"));
218 assertThat("No artifact download was found", toscaArtifactsPage.getDownloadedArtifactList(), not(empty()));
219 final String downloadedCsarName = toscaArtifactsPage.getDownloadedArtifactList().get(0);
220 final String downloadFolderPath = getConfig().getDownloadAutomationFolder();
221 final Map<String, byte[]> filesFromZip = FileHandling.getFilesFromZip(downloadFolderPath, downloadedCsarName);
222 final Optional<String> resourceEntryOpt = filesFromZip.keySet().stream()
223 .filter(s -> s.equals("Definitions/" + downloadedCsarName.replace("-csar.csar", "-template.yml")))
225 if (resourceEntryOpt.isEmpty()) {
226 fail("Could not find the resource package in Definitions");
228 return loadYamlObject(filesFromZip.get(resourceEntryOpt.get()));
231 private CreateVfFlow createVF() {
232 final ResourceCreateData vfCreateData = createVfFormData();
233 final CreateVfFlow createVfFlow = new CreateVfFlow(webDriver, vfCreateData);
234 createVfFlow.run(homePage);
238 private ResourceCreateData createVfFormData() {
239 vfResourceCreateData = new ResourceCreateData();
240 vfResourceCreateData.setRandomName(ElementFactory.getResourcePrefix() + "-VF");
241 vfResourceCreateData.setCategory(ResourceCategoryEnum.GENERIC_ABSTRACT.getSubCategory());
242 vfResourceCreateData.setTagList(Arrays.asList(vfResourceCreateData.getName(), "createVF"));
243 vfResourceCreateData.setDescription("aDescription");
244 vfResourceCreateData.setVendorName("EST");
245 vfResourceCreateData.setVendorRelease("4.1.1");
246 vfResourceCreateData.setVendorModelNumber("0001");
247 return vfResourceCreateData;
250 private CreateVfcFlow createVFC(final String vfcFullFilename, final String resourceName) {
251 final ResourceCreateData vfcCreateData = createVfcFormData(resourceName);
252 final CreateVfcFlow createVfcFlow = new CreateVfcFlow(webDriver, vfcCreateData, vfcFullFilename);
253 createVfcFlow.run(homePage);
254 ExtentTestActions.takeScreenshot(Status.INFO, "vfc-created", String.format("VFC '%s' was created", resourceName));
255 assertThat(vfcs, notNullValue());
256 vfcs.add(vfcCreateData);
257 return createVfcFlow;
260 private ResourceCreateData createVfcFormData(final String resourceName) {
261 final ResourceCreateData vfcCreateData = new ResourceCreateData();
262 vfcCreateData.setRandomName(resourceName);
263 vfcCreateData.setCategory(ResourceCategoryEnum.GENERIC_NETWORK_ELEMENTS.getSubCategory());
264 vfcCreateData.setTagList(Arrays.asList(vfcCreateData.getName(), "importVFC"));
265 vfcCreateData.setDescription("aDescription");
266 vfcCreateData.setVendorName("EST");
267 vfcCreateData.setVendorRelease("4.1.1");
268 vfcCreateData.setVendorModelNumber("0001");
269 return vfcCreateData;
272 private AddNodeToCompositionFlow addNodeToCompositionAndCreateRelationship(final CreateVfFlow createVfFlow) {
273 final ResourceCreatePage resourceCreatePage = createVfFlow.getLandedPage()
274 .orElseThrow(() -> new UiTestFlowRuntimeException("Expecting a ResourceCreatePage"));
275 resourceCreatePage.isLoaded();
276 assertThat(vfcs, hasSize(2));
277 final ComponentData parentComponent = new ComponentData();
278 parentComponent.setName(vfResourceCreateData.getName());
279 parentComponent.setVersion("0.1");
280 parentComponent.setComponentType(ComponentType.RESOURCE);
282 // Adds networkFunction to VF composition
283 final ComponentData networkFunction = new ComponentData();
284 networkFunction.setName(vfcs.get(0).getName());
285 networkFunction.setVersion("1.0");
286 networkFunction.setComponentType(ComponentType.RESOURCE);
287 CompositionPage compositionPage = resourceCreatePage.goToComposition();
288 compositionPage.isLoaded();
289 AddNodeToCompositionFlow addNodeToCompositionFlow = addNodeToComposition(parentComponent, networkFunction, compositionPage);
290 networkFunctionInstance = addNodeToCompositionFlow.getCreatedComponentInstance()
291 .orElseThrow(() -> new UiTestFlowRuntimeException("Could not get the created component instance"));
293 // Adds networkService to VF composition
294 final ComponentData networkService = new ComponentData();
295 networkService.setName(vfcs.get(1).getName());
296 networkService.setVersion("1.0");
297 networkService.setComponentType(ComponentType.RESOURCE);
298 addNodeToCompositionFlow = addNodeToComposition(parentComponent, networkService, compositionPage);
299 networkServiceInstance = addNodeToCompositionFlow.getCreatedComponentInstance()
300 .orElseThrow(() -> new UiTestFlowRuntimeException("Could not get the created component instance"));
302 // Creates a dependsOn relationship from networkServiceInstance to networkFunctionInstance
303 createRelationship(compositionPage, networkFunctionInstance.getName(), "tosca.capabilities.Node",
304 networkServiceInstance.getName(), "tosca.capabilities.Node");
306 return addNodeToCompositionFlow;
309 public AddNodeToCompositionFlow addNodeToComposition(final ComponentData parentComponent,
310 final ComponentData resourceToAdd,
311 CompositionPage compositionPage) {
312 final AddNodeToCompositionFlow addNodeToCompositionFlow = new AddNodeToCompositionFlow(webDriver, parentComponent, resourceToAdd);
313 compositionPage = (CompositionPage) addNodeToCompositionFlow.run(compositionPage)
314 .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected CompositionPage"));
315 compositionPage.isLoaded();
316 ExtentTestActions.takeScreenshot(Status.INFO, "node-added-to-composition",
317 String.format("Resource '%s' was added to composition", resourceToAdd.getName()));
318 return addNodeToCompositionFlow;
322 * Creates a DependsOn relationship between the imported VFCs
324 * @param compositionPage Composition Page
325 * @param fromComponentInstanceName VFC - Network Function
326 * @param fromCapability Node Capability
327 * @param toComponentInstanceName VFC - Network Service
328 * @param toRequirement Node Requirement
330 private void createRelationship(final CompositionPage compositionPage, final String fromComponentInstanceName,
331 final String fromCapability, final String toComponentInstanceName, final String toRequirement) {
332 final RelationshipInformation relationshipInformation =
333 new RelationshipInformation(fromComponentInstanceName, fromCapability, toComponentInstanceName, toRequirement);
334 CreateRelationshipFlow createRelationshipFlow = new CreateRelationshipFlow(webDriver, relationshipInformation);
335 createRelationshipFlow.run(compositionPage).orElseThrow(() -> new UiTestFlowRuntimeException("Expecting a CompositionPage instance"));
336 ExtentTestActions.takeScreenshot(Status.INFO, "relationship",
337 String.format("Relationship from networkFunctionInstance '%s' to networkServiceInstanceResource '%s' was created",
338 fromComponentInstanceName, toComponentInstanceName));
341 private void downloadAndVerifyCsarPackage(final ComponentPage componentPage) throws UnzipException {
342 final DownloadCsarArtifactFlow downloadToscaCsarFlow = downloadToscaCsar(componentPage);
343 final ToscaArtifactsPage toscaArtifactsPage = downloadToscaCsarFlow.getLandedPage()
344 .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected ToscaArtifactsPage"));
345 assertThat("No artifact download was found", toscaArtifactsPage.getDownloadedArtifactList(), not(empty()));
346 final String downloadedCsarName = toscaArtifactsPage.getDownloadedArtifactList().get(0);
347 checkCsarPackage(vfResourceCreateData.getName(), downloadedCsarName);
351 * Download the generated package
353 * @return DownloadCsarArtifactFlow
355 private DownloadCsarArtifactFlow downloadToscaCsar(final ComponentPage componentPage) {
356 final DownloadCsarArtifactFlow downloadToscaCsarFlow = new DownloadCsarArtifactFlow(webDriver);
357 downloadToscaCsarFlow.setWaitBeforeGetTheFile(5);
358 downloadToscaCsarFlow.run(componentPage);
359 return downloadToscaCsarFlow;
363 * Checks if the downloaded Tosca csar includes the node templates for the added VFCs,
364 * the generated service template declared “tosca_simple_yaml_1_3” as its Tosca version,
365 * the generated csar contains the node type definitions for the added VFCs in the Definitions directory,
366 * the interface template contains the relationship declaration
367 * @param vfResourceName VF created
368 * @param downloadedCsarName download Tosca CSAR filename
369 * @throws UnzipException
371 private void checkCsarPackage(final String vfResourceName, final String downloadedCsarName) throws UnzipException {
372 final String downloadFolderPath = getConfig().getDownloadAutomationFolder();
373 final Map<String, byte[]> filesFromZip = FileHandling.getFilesFromZip(downloadFolderPath, downloadedCsarName);
374 final String virtualFunctionName = vfResourceName.replace("-", "").toLowerCase();
375 final List<String> expectedDefinitionFolderFileList = getExpectedDefinitionFolderFileList(virtualFunctionName);
376 final Map<String, byte[]> expectedFilesFromZipMap = filesFromZip.entrySet().parallelStream()
377 .filter(key -> expectedDefinitionFolderFileList.stream()
378 .anyMatch(filename -> filename.equalsIgnoreCase(key.getKey()))).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
379 final String vfResourceTemplateFile = "Definitions/resource-" + virtualFunctionName + "-template.yml";
380 final String generatedTemplateFile = expectedFilesFromZipMap.keySet().stream()
381 .filter(filename -> filename.equalsIgnoreCase(vfResourceTemplateFile)).findFirst()
382 .orElseThrow(() -> new UiTestFlowRuntimeException(String.format("Resource template file not found %s", vfResourceTemplateFile)));
383 final byte[] toscaTemplateGenerated = filesFromZip.get(generatedTemplateFile);
384 assertThat(toscaTemplateGenerated, is(notNullValue()));
385 verifyGeneratedTemplate(toscaTemplateGenerated, generatedTemplateFile);
386 verifyNodesRelationship(expectedFilesFromZipMap, virtualFunctionName, filesFromZip);
389 private void verifyGeneratedTemplate(final byte[] generatedTemplateData, final String generatedTemplateFile) {
390 final Map<String, Object> templateYamlMap = loadYamlObject(generatedTemplateData);
391 final boolean hasToscaDefinitionVersionEntry = templateYamlMap.containsKey("tosca_definitions_version");
392 assertThat(String.format("'%s' should contain tosca_definitions_version entry", generatedTemplateFile), hasToscaDefinitionVersionEntry,
394 final String toscaVersion = (String) templateYamlMap.get("tosca_definitions_version");
395 assertThat(String.format("'%s' tosca_definitions_version entry should have tosca_simple_yaml_1_3 value", generatedTemplateFile),
396 toscaVersion.equalsIgnoreCase("tosca_simple_yaml_1_3"));
397 final Map<String, Object> topologyTemplateTosca = getMapEntry(templateYamlMap, "topology_template");
398 assertThat(String.format("'%s' should contain a topology_template entry", generatedTemplateFile), topologyTemplateTosca, is(notNullValue()));
399 final Map<String, Object> nodeTemplatesTosca = getMapEntry(topologyTemplateTosca, "node_templates");
400 assertThat(String.format("'%s' should contain a node_templates entry", generatedTemplateFile), nodeTemplatesTosca, is(notNullValue()));
401 final List<String> nodeTemplateFound = nodeTemplatesTosca.keySet().parallelStream().filter(s -> vfcs.stream()
402 .anyMatch(vfc -> s.startsWith(vfc.getName()))).collect(Collectors.toList());
403 assertThat(String.format("'%s' should contain the node type definitions for the added VFCs '%s'", nodeTemplatesTosca, vfcs),
404 nodeTemplateFound, hasSize(vfcs.size()));
407 private void verifyNodesRelationship(final Map<String, byte[]> expectedFilesFromZipMap, final String virtualFunctionName,
408 final Map<String, byte[]> filesFromZip) {
409 final String vfResourceTemplateFile = "Definitions/resource-" + virtualFunctionName + "-template-interface.yml";
410 final String interfaceTemplateFile = expectedFilesFromZipMap.keySet().stream()
411 .filter(filename -> filename.equalsIgnoreCase(vfResourceTemplateFile)).findFirst()
412 .orElseThrow(() -> new UiTestFlowRuntimeException(String.format("Resource template file not found %s", vfResourceTemplateFile)));
413 final byte[] toscaInterfaceTemplateGenerated = filesFromZip.get(interfaceTemplateFile);
414 assertThat(toscaInterfaceTemplateGenerated, is(notNullValue()));
415 final Map<String, Object> interfaceTemplateYamlMap = loadYamlObject(toscaInterfaceTemplateGenerated);
416 final Map<String, Object> nodeTypesYamlMap = getMapEntry(interfaceTemplateYamlMap, "node_types");
417 assertThat(String.format("'%s' should contain a node_types entry", interfaceTemplateYamlMap), nodeTypesYamlMap, is(notNullValue()));
418 final String result = Arrays.asList(nodeTypesYamlMap.values()).toString();
419 assertThat(String.format("'%s' should contain a capabilities entry", nodeTypesYamlMap), result.contains("capabilities"), is(true));
420 assertThat(String.format("'%s' should contain a requirements entry", nodeTypesYamlMap), result.contains("requirements"), is(true));
421 assertThat(String.format("'%s' should contain a relationship entry", nodeTypesYamlMap), result.contains("relationship"), is(true));
422 assertThat(String.format("'%s' should contain a DependsOn relationship value", nodeTypesYamlMap),
423 result.contains("tosca.relationships.DependsOn"), is(true));
426 private List<String> getExpectedDefinitionFolderFileList(final String vfResourceName) {
427 final List<String> expectedDefinitionFolderFileList = new ArrayList<>();
428 vfcs.forEach(vfc -> expectedDefinitionFolderFileList.add("Definitions/resource-" + vfc.getName() + "-template.yml"));
429 expectedDefinitionFolderFileList.add("Definitions/resource-" + vfResourceName + "-template.yml");
430 expectedDefinitionFolderFileList.add("Definitions/resource-" + vfResourceName + "-template-interface.yml");
431 return expectedDefinitionFolderFileList;
434 private Map<String, Object> getMapEntry(final Map<String, Object> yamlObj, final String entryName) {
436 return (Map<String, Object>) yamlObj.get(entryName);
437 } catch (final Exception e) {
438 final String errorMsg = String.format("Could not get the '%s' entry.", entryName);
439 LOGGER.error(errorMsg, e);
440 fail(errorMsg + "Error message: " + e.getMessage());
445 private Map<String, Object> loadYamlObject(final byte[] definitionYamlFile) {
446 return new Yaml().load(new String(definitionYamlFile));