Catalog alignment
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / US / VfModule.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.sdc.ci.tests.US;
22
23 import com.aventstack.extentreports.Status;
24 import org.openecomp.sdc.be.model.Service;
25 import org.openecomp.sdc.ci.tests.data.providers.OnboardingDataProviders;
26 import org.openecomp.sdc.ci.tests.datatypes.CanvasElement;
27 import org.openecomp.sdc.ci.tests.datatypes.CanvasManager;
28 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.ToscaArtifactsScreenEnum;
29 import org.openecomp.sdc.ci.tests.datatypes.HeatMetaFirstLevelDefinition;
30 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
31 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
32 import org.openecomp.sdc.ci.tests.datatypes.TypeHeatMetaDefinition;
33 import org.openecomp.sdc.ci.tests.datatypes.VendorLicenseModel;
34 import org.openecomp.sdc.ci.tests.datatypes.VendorSoftwareProductObject;
35 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
36 import org.openecomp.sdc.ci.tests.execute.devCI.ArtifactFromCsar;
37 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
38 import org.openecomp.sdc.ci.tests.pages.CompositionPage;
39 import org.openecomp.sdc.ci.tests.pages.DeploymentArtifactPage;
40 import org.openecomp.sdc.ci.tests.pages.HomePage;
41 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
42 import org.openecomp.sdc.ci.tests.pages.ServiceGeneralPage;
43 import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaDefinition;
44 import org.openecomp.sdc.ci.tests.utilities.ArtifactUIUtils;
45 import org.openecomp.sdc.ci.tests.utilities.DownloadManager;
46 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
47 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
48 import org.openecomp.sdc.ci.tests.utilities.OnboardingUiUtils;
49 import org.openecomp.sdc.ci.tests.utilities.ServiceUIUtils;
50 import org.openecomp.sdc.ci.tests.utils.CsarParserUtils;
51 import org.openecomp.sdc.ci.tests.utils.ToscaParserUtils;
52 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
53 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
54 import org.openecomp.sdc.ci.tests.utils.general.OnboardingUtils;
55 import org.openecomp.sdc.ci.tests.utils.general.VendorLicenseModelRestUtils;
56 import org.openecomp.sdc.ci.tests.utils.general.VendorSoftwareProductRestUtils;
57 import org.openecomp.sdc.ci.tests.verificator.ServiceVerificator;
58 import org.openecomp.sdc.ci.tests.verificator.VfModuleVerificator;
59 import org.testng.annotations.Test;
60
61 import java.awt.*;
62 import java.io.File;
63 import java.util.LinkedList;
64 import java.util.List;
65 import java.util.Map;
66
67 import static org.testng.AssertJUnit.assertNotNull;
68
69 /**
70  * @author al714h
71  */
72
73 public class VfModule extends SetupCDTest {
74
75
76     @Test
77     public void checkVfModulesCountAndStructure() throws Exception, AWTException {
78
79 //              String filePath = "src\\main\\resources\\Files\\VNFs";
80         String filepath = FileHandling.getVnfRepositoryPath();
81 //              String vnfFile = "LDSA.zip";
82 //              String vnfFile = "FDNT.zip";
83         List<String> fileNamesFromFolder = OnboardingUtils.getVnfNamesFileListExcludeToscaParserFailure();
84         List<String> newRandomFileNamesFromFolder = OnboardingDataProviders.getRandomElements(1, fileNamesFromFolder);
85         String filePath = org.openecomp.sdc.ci.tests.utils.general.FileHandling.getVnfRepositoryPath();
86         String vnfFile = newRandomFileNamesFromFolder.get(0);
87         getExtendTest().log(Status.INFO, String.format("Going to onboard the VNF %s......", vnfFile));
88         System.out.println(String.format("Going to onboard the VNF %s......", vnfFile));
89
90         VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(getUser());
91         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource(); //getResourceReqDetails(ComponentConfigurationTypeEnum.DEFAULT);
92         VendorSoftwareProductObject createVendorSoftwareProduct = VendorSoftwareProductRestUtils.createVendorSoftwareProduct(resourceReqDetails, vnfFile, filepath, getUser(),
93             vendorLicenseModel);
94         String vspName = createVendorSoftwareProduct.getName();
95         //
96         DownloadManager.downloadCsarByNameFromVSPRepository(vspName, createVendorSoftwareProduct.getVspId());
97         File latestFilefromDir = FileHandling.getLastModifiedFileNameFromDir();
98         List<TypeHeatMetaDefinition> listTypeHeatMetaDefinition = CsarParserUtils.getListTypeHeatMetaDefinition(latestFilefromDir);
99         //
100         getExtendTest().log(Status.INFO, String.format("Searching for onboarded %s", vnfFile));
101         HomePage.showVspRepository();
102         getExtendTest().log(Status.INFO, String.format("Going to import %s......", vnfFile.substring(0, vnfFile.indexOf("."))));
103
104         OnboardingUiUtils.importVSP(createVendorSoftwareProduct);
105
106         ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
107
108         // Verify deployment artifacts
109         Map<String, Object> combinedMap = ArtifactFromCsar.combineHeatArtifacstWithFolderArtifacsToMap(latestFilefromDir.getAbsolutePath());
110         LinkedList<HeatMetaFirstLevelDefinition> deploymentArtifacts = ((LinkedList<HeatMetaFirstLevelDefinition>) combinedMap.get("Deployment"));
111         for (HeatMetaFirstLevelDefinition deploymentArtifact : deploymentArtifacts) {
112             if (deploymentArtifact.getType().equals("HEAT_ENV")) {
113                 continue;
114             }
115             System.out.println("--------------");
116             System.out.println(deploymentArtifact.getFileName());
117             System.out.println(deploymentArtifact.getType());
118 //                      System.out.println(deploymentArtifact.getFileName().trim().substring(0, deploymentArtifact.getFileName().lastIndexOf(".")));
119             if (deploymentArtifact.getFileName().contains(".")) {
120                 ArtifactUIUtils.validateArtifactNameVersionType(deploymentArtifact.getFileName().trim().substring(0, deploymentArtifact.getFileName().lastIndexOf(".")), "1", deploymentArtifact.getType());
121             } else {
122                 ArtifactUIUtils.validateArtifactNameVersionType(deploymentArtifact.getFileName().trim(), "1", deploymentArtifact.getType());
123             }
124
125         }
126
127         DeploymentArtifactPage.verifyArtifactsExistInTable(filepath, vnfFile);
128 //TODO Andrey should click on certify button
129         DeploymentArtifactPage.clickCertifyButton(vspName);
130
131         // create service
132         ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
133         ServiceUIUtils.createService(serviceMetadata);
134
135         ServiceGeneralPage.getLeftMenu().moveToCompositionScreen();
136         CompositionPage.searchForElement(vspName);
137         CanvasManager serviceCanvasManager = CanvasManager.getCanvasManager();
138         CanvasElement vfElement = serviceCanvasManager.createElementOnCanvas(vspName);
139         assertNotNull(vfElement);
140         ServiceVerificator.verifyNumOfComponentInstances(serviceMetadata, "0.1", 1, getUser());
141
142         GeneralUIUtils.clickOnElementByTestId("breadcrumbs-button-1");
143         ResourceGeneralPage.getLeftMenu().moveToToscaArtifactsScreen();
144         GeneralUIUtils.clickOnElementByTestId(ToscaArtifactsScreenEnum.TOSCA_TEMPLATE.getValue());
145         latestFilefromDir = FileHandling.getLastModifiedFileNameFromDir();
146
147 //              verification
148         Service service = AtomicOperationUtils.getServiceObjectByNameAndVersion(UserRoleEnum.DESIGNER, serviceMetadata.getName(), serviceMetadata.getVersion());
149         ToscaDefinition toscaDefinition = ToscaParserUtils.parseToscaYamlToJavaObject(latestFilefromDir);
150
151 //              compare number of vf modules defined in HEAT.meta file vs Service TOSCA yaml
152         VfModuleVerificator.compareNumberOfVfModules(listTypeHeatMetaDefinition, toscaDefinition);
153         VfModuleVerificator.verifyGroupMetadata(toscaDefinition, service);
154
155         getExtendTest().log(Status.INFO, String.format("Onboarding %s test is passed ! ", vnfFile));
156
157     }
158
159
160     @Override
161     protected UserRoleEnum getRole() {
162         return UserRoleEnum.DESIGNER;
163     }
164
165 }