re base code
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / AmdocsComplexService / CreatePath.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.execute.AmdocsComplexService;
22
23 import com.aventstack.extentreports.Status;
24 import com.clearspring.analytics.util.Pair;
25 import org.openecomp.sdc.ci.tests.datatypes.*;
26 import org.openecomp.sdc.ci.tests.datatypes.enums.CircleSize;
27 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
28 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
29 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
30 import org.openecomp.sdc.ci.tests.pages.*;
31 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
32 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
33 import org.openecomp.sdc.ci.tests.utilities.OnboardingUiUtils;
34 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
35 import org.testng.annotations.BeforeMethod;
36 import org.testng.annotations.Optional;
37 import org.testng.annotations.Parameters;
38 import org.testng.annotations.Test;
39
40 import java.util.ArrayList;
41 import java.util.List;
42
43
44 public class CreatePath extends SetupCDTest {
45
46     protected static String filePath = FileHandling.getFilePath("ComplexService");
47     private static String fullCompositionFile = "fullComposition.zip";
48     private static String fullCompositionFile2 = "fullCompositionNew.zip";
49     private static String HSSFile = "HSS.zip";
50     private static String VMMEFile = "VMME.zip";
51     private static String makeDistributionValue;
52
53     @Parameters({"makeDistribution"})
54     @BeforeMethod
55     public void beforeTestReadParams(@Optional("true") String makeDistributionReadValue) {
56         makeDistributionValue = makeDistributionReadValue;
57     }
58
59     //------------------------------------------Tests-----------------------------------------------------
60
61
62     // Test#1 Jira issue 5610
63     @Test
64     public void AssertPathButtons() throws Exception {
65         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
66         getToPathFlow(resourceReqDetails, filePath, fullCompositionFile);
67         reloginWithNewRole(UserRoleEnum.DESIGNER);
68         PathUtilities.createService(getUser());
69         PathUtilities.openCreatePath();
70         PathValidations.AssertCreatePath();
71         PathValidations.AssertExtendPath();
72     }
73
74     // Test#2 Jira issue 5441
75     @Test
76     public void CreatePathTestSanity() throws Exception {
77         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
78         Pair<String, ServiceReqDetails> pair = getToPathFlow(resourceReqDetails, filePath, fullCompositionFile);
79         String vspName = pair.left;
80         String serviceName = pair.right.getName();
81         String pathName = "Test1";
82         PathUtilities.createPath(pathName, vspName);
83         PathValidations.validateServicePath(serviceName, pathName);
84     }
85
86     // Test#3 Jira issue 5611
87     @Test
88     public void CreatePathCheckIO() throws Exception {
89         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
90         String vspName = onboardAndCertify(resourceReqDetails, filePath, fullCompositionFile);
91         reloginWithNewRole(UserRoleEnum.DESIGNER);
92         String  serviceName = PathUtilities.createService(getUser()).getName();
93         String pathName = PathUtilities.createPath("Test3", vspName);
94
95         // @@ check in @@
96         ResourceGeneralPage.clickCheckinButton(serviceName);
97         GeneralUIUtils.findComponentAndClick(serviceName);
98         ServiceGeneralPage.getLeftMenu().moveToCompositionScreen();
99         PathValidations.AssertCreatedPathExistInCompositionPage(pathName);
100
101         // @@ check out @@
102         ResourceGeneralPage.clickCheckoutButton();
103         PathValidations.AssertCreatedPathExistInCompositionPage(pathName);
104     }
105
106     // Test#4 Jira issue 5441
107     @Test
108     public void CreateMultiplePaths() throws Exception {
109         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
110         Pair<String, ServiceReqDetails> pair = getToPathFlow(resourceReqDetails, filePath, HSSFile);
111         String vspName = pair.left;
112         PathUtilities.createPath("Test4_path1", vspName);
113         PathUtilities.createPath("Test4_path2", vspName);
114         PathValidations.createPathNumOfRows(7);
115         PathValidations.createPathNumOfRows(6);
116         SetupCDTest.getExtendTest().log(Status.INFO, "multiple paths have been created");
117     }
118
119     // Test#5 Jira issue 5506
120     @Test
121     public void CreatePathWithComplex() throws Exception {
122         List<String> vnfFiles = new ArrayList<>();
123         vnfFiles.add(HSSFile);
124         vnfFiles.add(VMMEFile);
125         Pair<String, String> complex = CreatePathComplexServiceFlow(filePath, vnfFiles);
126         String serviceName = complex.left;
127         String pathName = complex.right;
128         PathValidations.validateServicePath(serviceName,pathName);
129         SetupCDTest.getExtendTest().log(Status.INFO, "path with complex service has been created");
130     }
131
132     // Test#6 Jira issue 5506
133     @Test
134     public void CreateExtendedPathWithComplex() throws Exception {
135         List<String> vnfFiles = new ArrayList<>();
136         vnfFiles.add(fullCompositionFile);
137         vnfFiles.add(fullCompositionFile2);
138         String[] services = getToComplexService(filePath, vnfFiles);
139         PathValidations.validateComplexExtendedPath(services);
140         SetupCDTest.getExtendTest().log(Status.INFO, "path with complex service has been created");
141     }
142
143     // Test#7 Jira issue 5441
144     @Test
145     public void CreatePathExtendedTest() throws Exception {
146         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
147         runCreateExtendedPathFlow(resourceReqDetails, filePath, fullCompositionFile);
148     }
149
150     ////////////////////////////////////////////////////////////////////////////////////////
151     //                               flow methods                                         //
152     ////////////////////////////////////////////////////////////////////////////////////////
153
154     // workflow leading to path
155     public String onboardAndCertify(ResourceReqDetails resourceReqDetails, String filePath, String vnfFile) throws Exception {
156         VendorSoftwareProductObject vendorSoftwareProductObject = OnboardingUiUtils.onboardAndValidate(resourceReqDetails, filePath, vnfFile, getUser());
157         String vspName = vendorSoftwareProductObject.getName();
158
159         DeploymentArtifactPage.getLeftPanel().moveToCompositionScreen();
160         ExtentTestActions.addScreenshot(Status.INFO, "TopologyTemplate_" + vnfFile, "The topology template for " + vnfFile + " is as follows : ");
161
162         DeploymentArtifactPage.clickSubmitForTestingButton(vspName);
163         SetupCDTest.getExtendTest().log(Status.INFO, "relogin as TESTER");
164         reloginWithNewRole(UserRoleEnum.TESTER);
165         GeneralUIUtils.findComponentAndClick(vspName);
166         TesterOperationPage.certifyComponent(vspName);
167         return vspName;
168     }
169
170     public List<String> onboardAndCertifyMultipleVFs(String filePath, List<String> vnfFiles) throws Exception {
171         List<String> VFNames = new ArrayList<>();
172         for (int i = 0; i < vnfFiles.size(); i++) {
173             ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
174             VendorSoftwareProductObject vendorSoftwareProductObject = OnboardingUiUtils.onboardAndValidate(resourceReqDetails, filePath, vnfFiles.get(i), getUser());
175             VFNames.add(i, vendorSoftwareProductObject.getName());
176             DeploymentArtifactPage.getLeftPanel().moveToCompositionScreen();
177             ExtentTestActions.addScreenshot(Status.INFO, "TopologyTemplate_" + vnfFiles.get(i), "The topology template for " + vnfFiles.get(i) + " is as follows : ");
178             DeploymentArtifactPage.clickSubmitForTestingButton(VFNames.get(i));
179         }
180         SetupCDTest.getExtendTest().log(Status.INFO, "relogin as TESTER");
181         reloginWithNewRole(UserRoleEnum.TESTER);
182         for (String VFName : VFNames) {
183             GeneralUIUtils.findComponentAndClick(VFName);
184             TesterOperationPage.certifyComponent(VFName);
185         }
186         return VFNames;
187     }
188
189     public Pair<String, ServiceReqDetails> getToPathFlow(ResourceReqDetails resourceReqDetails, String filepath, String vnfFile) throws Exception {
190         String vspName = onboardAndCertify(resourceReqDetails, filepath, vnfFile);
191         reloginWithNewRole(UserRoleEnum.DESIGNER);
192         ServiceReqDetails serviceMetadata = PathUtilities.createService(getUser());
193         return new Pair<>(vspName, serviceMetadata);
194     }
195
196     public String[] getToComplexService(String filepath, List<String> vnfFiles) throws Exception {
197         // create & certify  2 VF
198         List<String> VFNames = onboardAndCertifyMultipleVFs(filepath, vnfFiles);
199         reloginWithNewRole(UserRoleEnum.DESIGNER);
200         ServiceReqDetails serviceMetadata1 = PathUtilities.createService(getUser());
201
202         // create path 1
203         PathUtilities.createPath("newPath", VFNames.get(0));
204         PathUtilities.submitForTesting();
205         GeneralUIUtils.ultimateWait();
206         ServiceReqDetails serviceMetadata2 = PathUtilities.createService(getUser());
207
208         // create path 2
209         PathUtilities.createPath("newPath2", VFNames.get(1));
210         PathUtilities.submitForTesting();
211
212         //tester
213         reloginWithNewRole(UserRoleEnum.TESTER);
214         GeneralUIUtils.findComponentAndClick(serviceMetadata1.getName());
215         TesterOperationPage.certifyComponent(serviceMetadata1.getName());
216         GeneralUIUtils.findComponentAndClick(serviceMetadata2.getName());
217         TesterOperationPage.certifyComponent(serviceMetadata2.getName());
218
219         //governor
220         reloginWithNewRole(UserRoleEnum.GOVERNOR);
221         GeneralUIUtils.findComponentAndClick(serviceMetadata1.getName());
222         GovernorOperationPage.approveSerivce(serviceMetadata1.getName());
223         GeneralUIUtils.findComponentAndClick(serviceMetadata2.getName());
224         GovernorOperationPage.approveSerivce(serviceMetadata2.getName());
225
226         //create service for complex service
227         reloginWithNewRole(UserRoleEnum.DESIGNER);
228         ServiceReqDetails serviceMetadata3 = PathUtilities.createService(getUser());
229         return new String[]{serviceMetadata1.getName(), serviceMetadata2.getName(), serviceMetadata3.getName()};
230     }
231
232     public Pair<String, String> CreatePathComplexServiceFlow(String filepath, List<String> vnfFiles) throws Exception {
233         String[] servicesName = getToComplexService(filepath, vnfFiles);
234         CanvasManager canvasManager = CanvasManager.getCanvasManager();
235         CompositionPage.searchForElement(servicesName[0]);
236         CanvasElement service1 = canvasManager.createElementOnCanvas(servicesName[0]);
237         CompositionPage.searchForElement(servicesName[1]);
238         CanvasElement service2 = canvasManager.createElementOnCanvas(servicesName[1]);
239         canvasManager.linkElements(service1, CircleSize.SERVICE, service2, CircleSize.SERVICE);
240
241         // create path
242         String pathName = "name1";
243         PathUtilities.openCreatePath();
244         PathUtilities.insertValues(pathName, "pathProtocol1", "pathPortNumbers1");
245         PathUtilities.selectFirstLineParam();
246         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ComplexServiceAmdocs.CREATE_BUTTON.getValue()).click();
247         return new Pair<>(servicesName[2], pathName);
248     }
249
250     public void runCreateExtendedPathFlow(ResourceReqDetails resourceReqDetails, String filepath, String vnfFile) throws Exception {
251         Pair<String, ServiceReqDetails> pair = getToPathFlow(resourceReqDetails, filepath, vnfFile);
252         String vspName = pair.left;
253         PathUtilities.linkVFs(vspName, 4);
254
255         //create path
256         PathUtilities.openCreatePath();
257         String pathName = "name1";
258         PathUtilities.insertValues(pathName, "pathProtocol1", "pathPortNumbers1");
259         PathUtilities.selectFirstLineParam();
260         int numOfLines = 3;
261         PathValidations.extendPath(numOfLines);
262
263         //delete line
264         PathUtilities.deleteLines(1, numOfLines);
265         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.CREATE_BUTTON.getValue());
266         ExtentTestActions.log(Status.INFO, "path has been created");
267
268         // check path is on the list
269         PathUtilities.openPathList();
270         String PathListName1 = GeneralUIUtils.findByText(pathName).getText();
271         String newPathName = "name2";
272         PathUtilities.editPathName(pathName, newPathName);
273         GeneralUIUtils.findElementsByXpath("//*[@data-tests-id='" + DataTestIdEnum.ComplexServiceAmdocs.PATH_MENU_BUTTON.getValue() + "']/parent::*").get(0).click();
274         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ComplexServiceAmdocs.PATH_LIST_BUTTON.getValue());
275         String PathListName2 = GeneralUIUtils.findByText(newPathName).getText();
276         PathValidations.AssertNameChangeFromPathList(PathListName1, PathListName2);
277
278         // delete path and validate
279         PathValidations.ValidateAndDeletePathFromPathList(newPathName);
280         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.PropertiesAssignmentScreen.INPUT_DELETE_DIALOG_CLOSE.getValue());
281         SetupCDTest.getExtendTest().log(Status.INFO, "Path has been created");
282     }
283
284     @Override
285     protected UserRoleEnum getRole() {
286         return UserRoleEnum.DESIGNER;
287     }
288
289 }