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