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