diff options
Diffstat (limited to 'integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/EtsiModelUiTests.java')
-rw-r--r-- | integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/EtsiModelUiTests.java | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/EtsiModelUiTests.java b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/EtsiModelUiTests.java new file mode 100644 index 0000000000..ce3254f296 --- /dev/null +++ b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/EtsiModelUiTests.java @@ -0,0 +1,195 @@ +/* + * - + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.frontend.ci.tests.execute.sanity; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasKey; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.fail; + +import com.aventstack.extentreports.Status; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import org.onap.sdc.backend.ci.tests.datatypes.enums.PackageTypeEnum; +import org.onap.sdc.backend.ci.tests.utils.general.ElementFactory; +import org.onap.sdc.frontend.ci.tests.datatypes.CategorySelect; +import org.onap.sdc.frontend.ci.tests.datatypes.ComponentProperty; +import org.onap.sdc.frontend.ci.tests.datatypes.ModelName; +import org.onap.sdc.frontend.ci.tests.datatypes.VspCreateData; +import org.onap.sdc.frontend.ci.tests.datatypes.VspOnboardingProcedure; +import org.onap.sdc.frontend.ci.tests.exception.UnzipException; +import org.onap.sdc.frontend.ci.tests.execute.setup.DriverFactory; +import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest; +import org.onap.sdc.frontend.ci.tests.flow.CheckComponentPropertiesFlow; +import org.onap.sdc.frontend.ci.tests.flow.CreateResourceFromVspFlow; +import org.onap.sdc.frontend.ci.tests.flow.CreateVlmFlow; +import org.onap.sdc.frontend.ci.tests.flow.CreateVspFlow; +import org.onap.sdc.frontend.ci.tests.flow.DownloadCsarArtifactFlow; +import org.onap.sdc.frontend.ci.tests.flow.ImportVspFlow; +import org.onap.sdc.frontend.ci.tests.flow.exception.UiTestFlowRuntimeException; +import org.onap.sdc.frontend.ci.tests.pages.ComponentPage; +import org.onap.sdc.frontend.ci.tests.pages.ResourceCreatePage; +import org.onap.sdc.frontend.ci.tests.pages.ResourcePropertiesAssignmentPage; +import org.onap.sdc.frontend.ci.tests.pages.TopNavComponent; +import org.onap.sdc.frontend.ci.tests.pages.component.workspace.ToscaArtifactsPage; +import org.onap.sdc.frontend.ci.tests.utilities.FileHandling; +import org.openqa.selenium.WebDriver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.Test; +import org.yaml.snakeyaml.Yaml; + +public class EtsiModelUiTests extends SetupCDTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(EtsiModelUiTests.class); + + private WebDriver webDriver; + + @Test + public void etsiNetworkServiceTest() throws UnzipException { + webDriver = DriverFactory.getDriver(); + + createVlm(); + final String resourceName = createVsp(); + ResourceCreatePage resourceCreatePage = importVsp(resourceName); + resourceCreatePage = createVf(resourceName, resourceCreatePage); + resourceCreatePage.isLoaded(); + final ResourcePropertiesAssignmentPage resourcePropertiesAssignmentPage = checkVfProperties(resourceCreatePage); + resourcePropertiesAssignmentPage.isLoaded(); + final DownloadCsarArtifactFlow downloadCsarArtifactFlow = downloadCsarArtifact(resourcePropertiesAssignmentPage); + final ToscaArtifactsPage toscaArtifactsPage = downloadCsarArtifactFlow.getLandedPage() + .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected ToscaArtifactsPage")); + toscaArtifactsPage.isLoaded(); + final String downloadedCsarName = toscaArtifactsPage.getDownloadedArtifactList().get(0); + checkCsarPackage(resourceName, downloadedCsarName); + toscaArtifactsPage.goToHomePage(); + } + + private ResourcePropertiesAssignmentPage checkVfProperties(final ComponentPage componentPage) { + final Set<ComponentProperty<?>> componentPropertySet = Set.of( + new ComponentProperty<>("descriptor_id", "descriptor_id"), + new ComponentProperty<>("descriptor_version", "v1.0.1"), + new ComponentProperty<>("flavour_description", "flavour_description"), + new ComponentProperty<>("flavour_id", "flavour_id"), + new ComponentProperty<>("product_name", "product_name"), + new ComponentProperty<>("provider", "provider"), + new ComponentProperty<>("software_version", "v1.0.1"), + new ComponentProperty<>("vnfm_info", List.of("etsivnfm:v1.0.1")) + ); + + final CheckComponentPropertiesFlow checkComponentPropertiesFlow = new CheckComponentPropertiesFlow(componentPropertySet, webDriver); + final Optional<ResourcePropertiesAssignmentPage> run = checkComponentPropertiesFlow.run(componentPage); + return run.orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected return ResourceCreatePage")); + } + + private ResourceCreatePage createVf(final String resourceName, final ResourceCreatePage resourceCreatePage) { + final CreateResourceFromVspFlow createResourceFlow = new CreateResourceFromVspFlow(webDriver, resourceName); + final ResourceCreatePage resourceCreatePage1 = createResourceFlow.run(resourceCreatePage) + .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected return ResourceCreatePage")); + resourceCreatePage1.isLoaded(); + return resourceCreatePage1; + } + + private ResourceCreatePage importVsp(final String resourceName) { + final ImportVspFlow importVspFlow = new ImportVspFlow(webDriver, resourceName); + return importVspFlow.run() + .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected return ResourceCreatePage")); + } + + private String createVsp() { + final String resourceName = ElementFactory.addRandomSuffixToName(ElementFactory.getResourcePrefix()); + final String virtualLinkableVnf = "Vnf-ETSI-SOL001-2.5.1.csar"; + final String rootFolder = org.onap.sdc.backend.ci.tests.utils.general.FileHandling.getPackageRepositoryPath(PackageTypeEnum.ETSI); + var vspCreateData = new VspCreateData(); + vspCreateData.setName(resourceName); + vspCreateData.setCategory(CategorySelect.COMMON_NETWORK_RESOURCES); + vspCreateData.setDescription("description"); + vspCreateData.setOnboardingProcedure(VspOnboardingProcedure.NETWORK_PACKAGE); + vspCreateData.setModel(ModelName.ETSI_SOL001_v2_5_1.getName()); + final CreateVspFlow createVspFlow = new CreateVspFlow(webDriver, vspCreateData, virtualLinkableVnf, rootFolder); + createVspFlow.run(new TopNavComponent(webDriver)); + return resourceName; + } + + private void createVlm() { + getExtendTest().log(Status.INFO, "Creating a VLM"); + final CreateVlmFlow createVlmFlow = new CreateVlmFlow(webDriver); + createVlmFlow.run(); + } + + private DownloadCsarArtifactFlow downloadCsarArtifact(final ComponentPage componentPage) { + final DownloadCsarArtifactFlow downloadCsarArtifactFlow = new DownloadCsarArtifactFlow(webDriver); + downloadCsarArtifactFlow.run(componentPage); + return downloadCsarArtifactFlow; + } + + private void checkCsarPackage(final String serviceName, final String downloadedCsarName) throws UnzipException { + final String downloadFolderPath = getConfig().getDownloadAutomationFolder(); + final Map<String, byte[]> filesFromZip = FileHandling.getFilesFromZip(downloadFolderPath, downloadedCsarName); + final String mainDefinitionFileName = String.format("resource-%s-template.yml", serviceName.substring(0, 1).toUpperCase() + serviceName.substring(1).toLowerCase()); + final Path mainDefinitionFilePath = Path.of("Definitions", mainDefinitionFileName); + final byte[] mainDefinitionFile = filesFromZip.get(mainDefinitionFilePath.toString()); + final Map<String, Object> mainDefinitionYamlMap = loadYamlObject(mainDefinitionFile); + final Map<String, Object> topologyTemplateTosca = getMapEntry(mainDefinitionYamlMap, "topology_template"); + assertThat(String.format("'%s' should contain a topology_template entry", mainDefinitionFilePath), topologyTemplateTosca, notNullValue()); + final Map<String, Object> substitutionMappingsTosca = getMapEntry(topologyTemplateTosca, "substitution_mappings"); + assertThat(String.format("'%s' should contain a substitution_mappings entry", mainDefinitionFilePath), substitutionMappingsTosca, notNullValue()); + final var nodeType = (String) substitutionMappingsTosca.get("node_type"); + assertThat("substitution_mappings->node_type should be as expected", nodeType, is("org.openecomp.resource.EtsiDummyVnf")); + + final Map<String, Object> nodeTemplatesTosca = getMapEntry(topologyTemplateTosca, "node_templates"); + assertThat(String.format("'%s' should contain a node_templates entry", mainDefinitionFilePath), nodeTemplatesTosca, notNullValue()); + final var expectedNode1 = "external_connection_point"; + assertThat(String.format("'%s' should contain a node_template %s entry", mainDefinitionFilePath, expectedNode1), + nodeTemplatesTosca, hasKey(expectedNode1)); + final var expectedNode2 = "vnf_virtual_link"; + assertThat(String.format("'%s' should contain a node_template %s entry", mainDefinitionFilePath, expectedNode2), + nodeTemplatesTosca, hasKey(expectedNode2)); + final var notExpectedNode1 = "etsi_dummy_vnf"; + assertThat(String.format("'%s' should not contain a node_template %s entry, as it represents the substitutable node", + mainDefinitionFilePath, notExpectedNode1), + nodeTemplatesTosca, not(hasKey(notExpectedNode1)) + ); + } + + private Map<String, Object> getMapEntry(final Map<String, Object> yamlObj, final String entryName) { + try { + return (Map<String, Object>) yamlObj.get(entryName); + } catch (final Exception e) { + final String errorMsg = String.format("Could not get the '%s' entry.", entryName); + LOGGER.error(errorMsg, e); + fail(errorMsg + "Error message: " + e.getMessage()); + } + return null; + } + + private Map<String, Object> loadYamlObject(final byte[] mainDefinitionFileBytes) { + return new Yaml().load(new String(mainDefinitionFileBytes)); + } + +} + |