Onboard PNF software version Ui test case
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / sanity / OnboardingFlowsUi.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.sanity;
22
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertNotNull;
26 import static org.testng.AssertJUnit.assertTrue;
27 import static org.testng.AssertJUnit.fail;
28
29 import com.aventstack.extentreports.ExtentTest;
30 import com.aventstack.extentreports.Status;
31 import java.io.File;
32 import java.util.Arrays;
33 import java.util.HashMap;
34 import java.util.List;
35 import java.util.Map;
36 import java.util.stream.Collectors;
37 import org.openecomp.sdc.ci.tests.data.providers.OnboardingDataProviders;
38 import org.openecomp.sdc.ci.tests.dataProvider.OnbordingDataProviders;
39 import org.openecomp.sdc.ci.tests.datatypes.CanvasElement;
40 import org.openecomp.sdc.ci.tests.datatypes.CanvasManager;
41 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
42 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
43 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
44 import org.openecomp.sdc.ci.tests.datatypes.VendorLicenseModel;
45 import org.openecomp.sdc.ci.tests.datatypes.VendorSoftwareProductObject;
46 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
47 import org.openecomp.sdc.ci.tests.datatypes.enums.XnfTypeEnum;
48 import org.openecomp.sdc.ci.tests.execute.setup.ArtifactsCorrelationManager;
49 import org.openecomp.sdc.ci.tests.execute.setup.DriverFactory;
50 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
51 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
52 import org.openecomp.sdc.ci.tests.flow.CheckSoftwareVersionPropertyFlow;
53 import org.openecomp.sdc.ci.tests.flow.CreateResourceFlow;
54 import org.openecomp.sdc.ci.tests.flow.CreateVspFlow;
55 import org.openecomp.sdc.ci.tests.flow.ImportVspFlow;
56 import org.openecomp.sdc.ci.tests.flow.exception.UiTestFlowRuntimeException;
57 import org.openecomp.sdc.ci.tests.pages.CompositionPage;
58 import org.openecomp.sdc.ci.tests.pages.DeploymentArtifactPage;
59 import org.openecomp.sdc.ci.tests.pages.GovernorOperationPage;
60 import org.openecomp.sdc.ci.tests.pages.HomePage;
61 import org.openecomp.sdc.ci.tests.pages.HomePage.PageElement;
62 import org.openecomp.sdc.ci.tests.pages.OpsOperationPage;
63 import org.openecomp.sdc.ci.tests.pages.ResourceCreatePage;
64 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
65 import org.openecomp.sdc.ci.tests.pages.ServiceGeneralPage;
66 import org.openecomp.sdc.ci.tests.pages.TesterOperationPage;
67 import org.openecomp.sdc.ci.tests.pages.TopNavComponent;
68 import org.openecomp.sdc.ci.tests.pages.VspValidationPage;
69 import org.openecomp.sdc.ci.tests.pages.VspValidationResultsPage;
70 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
71 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
72 import org.openecomp.sdc.ci.tests.utilities.OnboardingUiUtils;
73 import org.openecomp.sdc.ci.tests.utilities.ServiceUIUtils;
74 import org.openecomp.sdc.ci.tests.utils.Utils;
75 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
76 import org.openecomp.sdc.ci.tests.utils.general.OnboardingUtils;
77 import org.openecomp.sdc.ci.tests.utils.general.VendorLicenseModelRestUtils;
78 import org.openecomp.sdc.ci.tests.utils.general.VendorSoftwareProductRestUtils;
79 import org.openecomp.sdc.ci.tests.verificator.ServiceVerificator;
80 import org.openqa.selenium.WebDriver;
81 import org.openqa.selenium.WebElement;
82 import org.slf4j.Logger;
83 import org.slf4j.LoggerFactory;
84 import org.testng.AssertJUnit;
85 import org.testng.annotations.BeforeMethod;
86 import org.testng.annotations.Optional;
87 import org.testng.annotations.Parameters;
88 import org.testng.annotations.Test;
89
90 public class OnboardingFlowsUi extends SetupCDTest {
91
92     private static final Logger LOGGER = LoggerFactory.getLogger(OnboardingFlowsUi.class);
93     private static final String NO_TESTS_ARE_AVAILABLE = "No Tests are Available";
94     private static final String NEXT_BUTTON_IS_ENABLED_IT_SHOULD_HAVE_BEEN_ENABLED =
95             "Next Button is enabled, it should have been enabled";
96     private static final String NEXT_BUTTON_IS_DISABLED_IT_SHOULD_HAVE_BEEN_ENABLED =
97             "Next Button is disabled, it should have been enabled";
98     private static final String RESULTS_ARE_NOT_AVAILABLE = "Results are not available";
99     private static final String THE_TESTS_ARE_ALREADY_SELECTED_THE_LIST_SHOULD_INITIALLY_BE_EMPTY =
100             "The tests are already selected, the list should initially be empty";
101     private static final String THE_SELECTED_TESTS_ARE_NOT_POPULATED_IN_THE_LIST =
102             "The selected tests are not populated in the list";
103     private static final String THE_SELECTED_TESTS_ARE_NOT_DELETED_FROM_THE_LIST =
104             "The selected tests are not deleted from the list";
105     private static final String NEXT_BUTTON_IS_ENABLED_IT_SHOULD_HAVE_BEEN_DISABLED =
106             "Next Button is enabled, it should have been disabled";
107
108     protected static String filePath = FileHandling.getVnfRepositoryPath();
109     private Boolean makeDistributionValue;
110
111     @Parameters({"makeDistribution"})
112     @BeforeMethod
113     public void beforeTestReadParams(@Optional("true") String makeDistributionReadValue) {
114         LOGGER.debug("makeDistribution parameter is '{}'", makeDistributionReadValue);
115         makeDistributionValue = Boolean.valueOf(makeDistributionReadValue);
116     }
117
118     @Test
119     public void onboardVNFTestSanityOneFile() throws Exception {
120         String vnfFile = "1-VF-vUSP-vCCF-DB_v11.1.zip";
121         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
122         ServiceReqDetails serviceReqDetails = ElementFactory.getDefaultService();
123         runOnboardToDistributionFlow(resourceReqDetails, serviceReqDetails, filePath, vnfFile);
124     }
125
126     @Test
127     public void performanceTest() throws Exception {
128         LOGGER.debug("Start test");
129         Long actualTestRunTime = Utils.getActionDuration(() -> {
130             try {
131                 onboardVNFTestSanityOneFile();
132             } catch (final Exception e) {
133                 LOGGER.debug("An error has occurred during the performance test", e);
134             }
135         });
136         long regularTestRunTime = 400L;
137         double factor = 1.5;
138         assertTrue("Expected test run time should be less from " + regularTestRunTime * factor + ", actual time is " + actualTestRunTime, regularTestRunTime * factor > actualTestRunTime);
139     }
140
141     @Test
142     public void onboardVNFTestSanity() throws Exception {
143         List<String> fileNamesFromFolder = OnboardingUtils.getXnfNamesFileList(XnfTypeEnum.VNF);
144         String vnfFile = fileNamesFromFolder.get(0);
145         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
146         ServiceReqDetails serviceReqDetails = ElementFactory.getDefaultService();
147         runOnboardToDistributionFlow(resourceReqDetails, serviceReqDetails, filePath, vnfFile);
148     }
149
150     @Test(dataProviderClass = OnboardingDataProviders.class, dataProvider = "Single_VNF")
151     public void onapOnboardVNFflow(String filePath, String vnfFile) throws Exception {
152         setLog(vnfFile);
153         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
154         ServiceReqDetails serviceReqDetails = ElementFactory.getDefaultService();
155         runOnboardToDistributionFlow(resourceReqDetails, serviceReqDetails, filePath, vnfFile);
156     }
157
158     @Test(dataProviderClass = OnboardingDataProviders.class, dataProvider = "Single_VNF")
159     public void onapOnboardVSPValidationsSanityFlow(String filePath, String vnfFile) throws Exception {
160         setLog(vnfFile);
161         String vspName = createNewVSP(filePath, vnfFile);
162         if (OnboardingUiUtils.getVspValidationCongiguration()) {
163             goToVspScreen(true, vspName);
164
165             //check links are available
166             checkVspValidationLinksVisibility();
167
168             VspValidationPage.navigateToVspValidationPageUsingNavbar();
169             assertTrue(NEXT_BUTTON_IS_ENABLED_IT_SHOULD_HAVE_BEEN_DISABLED,
170                     VspValidationPage.checkNextButtonDisabled());
171             VspValidationResultsPage.navigateToVspValidationResultsPageUsingNavbar();
172             GeneralUIUtils.ultimateWait();
173             assertNotNull(GeneralUIUtils.findByText("No Test Performed"));
174         } else {
175             goToVspScreen(true, vspName);
176
177             //check links are not available
178             checkVspValidationLinksInvisibility();
179         }
180     }
181
182     @Test(dataProviderClass = OnboardingDataProviders.class, dataProvider = "softwareInformationPnf")
183     public void onboardPNFSoftwareInformationFlow(final String rootFolder, final String pnfFile,
184                                                   final List<String> softwareVersionList) {
185         setLog(pnfFile);
186         final String resourceName = ElementFactory.addRandomSuffixToName(ElementFactory.getResourcePrefix());
187         runOnboardPnfSoftwareVersion(resourceName, rootFolder, pnfFile, softwareVersionList);
188     }
189
190     @Test(dataProviderClass = OnboardingDataProviders.class, dataProvider = "Single_VNF")
191     public void onapOnboardVSPValidationsConfigurationChangeCheck(String filePath, String vnfFile) throws Exception {
192         setLog(vnfFile);
193         String vspName = createNewVSP(filePath, vnfFile);
194         if (OnboardingUiUtils.getVspValidationCongiguration()) {
195             goToVspScreen(true, vspName);
196             //check links are available
197             checkVspValidationLinksVisibility();
198
199             //change config
200             changeVspValidationConfig(false, vspName, OnboardingUiUtils.getVspValidationCongiguration());
201
202             //check links are not available
203             checkVspValidationLinksInvisibility();
204         } else {
205             goToVspScreen(true, vspName);
206             //check links are not available
207             checkVspValidationLinksInvisibility();
208
209             changeVspValidationConfig(false, vspName, OnboardingUiUtils.getVspValidationCongiguration());
210
211             //check links are available
212             checkVspValidationLinksVisibility();
213         }
214     }
215
216     @Test(dataProviderClass = OnboardingDataProviders.class, dataProvider = "Single_VNF")
217     public void onapOnboardVSPCertificationQueryFlow(String filePath, String vnfFile) throws Exception {
218         setLog(vnfFile);
219         String vspName = createNewVSP(filePath, vnfFile);
220         if (!OnboardingUiUtils.getVspValidationCongiguration()) {
221             //change config to true to test the feature
222             changeVspValidationConfig(true, vspName, OnboardingUiUtils.getVspValidationCongiguration());
223         } else {
224             goToVspScreen(true, vspName);
225         }
226         VspValidationPage.navigateToVspValidationPageUsingNavbar();
227         assertTrue(NEXT_BUTTON_IS_ENABLED_IT_SHOULD_HAVE_BEEN_DISABLED, VspValidationPage.checkNextButtonDisabled());
228
229         if (VspValidationPage.checkCertificationQueryExists()) {
230             VspValidationPage.clickCertificationQueryAll();
231             GeneralUIUtils.ultimateWait();
232             assertTrue(NEXT_BUTTON_IS_DISABLED_IT_SHOULD_HAVE_BEEN_ENABLED,
233                     !VspValidationPage.checkNextButtonDisabled());
234             VspValidationPage.clickOnNextButton();
235             GeneralUIUtils.ultimateWait();
236             VspValidationPage.clickOnSubmitButton();
237             GeneralUIUtils.waitForLoader();
238             assertTrue(RESULTS_ARE_NOT_AVAILABLE, VspValidationResultsPage.checkResultsExist());
239         } else {
240             assertNotNull(GeneralUIUtils.findByText("No Certifications Query are Available"));
241         }
242
243     }
244
245     @Test(dataProviderClass = OnbordingDataProviders.class, dataProvider = "Single_Vsp_Test_Csar")
246     public void onapOnboardVSPComplianceCheckFlow(String filePath, String vnfFile) throws Exception {
247         setLog(vnfFile);
248         String vspName = createNewVSP(filePath, vnfFile);
249         if (!OnboardingUiUtils.getVspValidationCongiguration()) {
250             //change config to true to test the feature
251             changeVspValidationConfig(true, vspName, OnboardingUiUtils.getVspValidationCongiguration());
252         } else {
253             goToVspScreen(true, vspName);
254         }
255
256         VspValidationPage.navigateToVspValidationPageUsingNavbar();
257         assertTrue(NEXT_BUTTON_IS_ENABLED_IT_SHOULD_HAVE_BEEN_ENABLED, VspValidationPage.checkNextButtonDisabled());
258         if (VspValidationPage.checkComplianceCheckExists()) {
259             VspValidationPage.clickComplianceChecksAll();
260             GeneralUIUtils.ultimateWait();
261             assertFalse(NEXT_BUTTON_IS_DISABLED_IT_SHOULD_HAVE_BEEN_ENABLED,
262                     VspValidationPage.checkNextButtonDisabled());
263             VspValidationPage.clickOnNextButton();
264             GeneralUIUtils.ultimateWait();
265             VspValidationPage.loadVSPFile(filePath, vnfFile);
266             VspValidationPage.clickOnSubmitButton();
267             GeneralUIUtils.ultimateWait();
268             assertTrue(RESULTS_ARE_NOT_AVAILABLE, VspValidationResultsPage.checkResultsExist());
269         } else {
270             assertNotNull(GeneralUIUtils.findByText(NO_TESTS_ARE_AVAILABLE));
271         }
272
273     }
274
275     @Test(dataProviderClass = OnboardingDataProviders.class, dataProvider = "Single_VNF")
276     public void onapOnboardVSPComplianceCheckOperations(String filePath, String vnfFile) throws Exception {
277         setLog(vnfFile);
278         String vspName = createNewVSP(filePath, vnfFile);
279         if (!OnboardingUiUtils.getVspValidationCongiguration()) {
280             //change config to true to test the feature
281             changeVspValidationConfig(true, vspName, OnboardingUiUtils.getVspValidationCongiguration());
282         } else {
283             goToVspScreen(true, vspName);
284         }
285
286         VspValidationPage.navigateToVspValidationPageUsingNavbar();
287         assertTrue(NEXT_BUTTON_IS_ENABLED_IT_SHOULD_HAVE_BEEN_ENABLED, VspValidationPage.checkNextButtonDisabled());
288         if (VspValidationPage.checkComplianceCheckExists()) {
289             assertFalse(THE_TESTS_ARE_ALREADY_SELECTED_THE_LIST_SHOULD_INITIALLY_BE_EMPTY,
290                     VspValidationPage.checkSelectedComplianceCheckExists());
291             VspValidationPage.clickComplianceChecksAll();
292             GeneralUIUtils.ultimateWait();
293             assertTrue(THE_SELECTED_TESTS_ARE_NOT_POPULATED_IN_THE_LIST,
294                     VspValidationPage.checkSelectedComplianceCheckExists());
295             VspValidationPage.clickComplianceChecksAll();
296             GeneralUIUtils.ultimateWait();
297             assertFalse(THE_SELECTED_TESTS_ARE_NOT_DELETED_FROM_THE_LIST,
298                     VspValidationPage.checkSelectedComplianceCheckExists());
299         } else {
300             assertNotNull(GeneralUIUtils.findByText(NO_TESTS_ARE_AVAILABLE));
301         }
302
303     }
304
305     @Test(dataProviderClass = OnboardingDataProviders.class, dataProvider = "Single_VNF")
306     public void onapOnboardVSPCertificationQueryOperations(String filePath, String vnfFile) throws Exception {
307         setLog(vnfFile);
308         String vspName = createNewVSP(filePath, vnfFile);
309         if (!OnboardingUiUtils.getVspValidationCongiguration()) {
310             //change config to true to test the feature
311             changeVspValidationConfig(true, vspName, OnboardingUiUtils.getVspValidationCongiguration());
312         } else {
313             goToVspScreen(true, vspName);
314         }
315
316         VspValidationPage.navigateToVspValidationPageUsingNavbar();
317         assertTrue(NEXT_BUTTON_IS_ENABLED_IT_SHOULD_HAVE_BEEN_ENABLED, VspValidationPage.checkNextButtonDisabled());
318         if (VspValidationPage.checkCertificationQueryExists()) {
319             assertFalse(THE_TESTS_ARE_ALREADY_SELECTED_THE_LIST_SHOULD_INITIALLY_BE_EMPTY,
320                 VspValidationPage.checkSelectedCertificationQueryExists());
321             VspValidationPage.clickCertificationQueryAll();
322             GeneralUIUtils.ultimateWait();
323             assertTrue(THE_SELECTED_TESTS_ARE_NOT_POPULATED_IN_THE_LIST, VspValidationPage.checkSelectedCertificationQueryExists());
324             VspValidationPage.clickCertificationQueryAll();
325             GeneralUIUtils.ultimateWait();
326             assertFalse(THE_SELECTED_TESTS_ARE_NOT_DELETED_FROM_THE_LIST,
327                 VspValidationPage.checkSelectedCertificationQueryExists());
328         } else {
329             assertNotNull(GeneralUIUtils.findByText(NO_TESTS_ARE_AVAILABLE));
330         }
331
332     }
333
334     private void checkVspValidationLinksVisibility() {
335         //check links are available
336         assertTrue("Validation Link is not available", GeneralUIUtils.isElementVisibleByTestId(DataTestIdEnum.VspValidationPage.VSP_VALIDATION_PAGE_NAVBAR.getValue()));
337         assertTrue("Validation Results Link is not available", GeneralUIUtils.isElementVisibleByTestId(DataTestIdEnum.VspValidationResultsPage.VSP_VALIDATION_RESULTS_PAGE_NAVBAR.getValue()));
338     }
339
340     private void checkVspValidationLinksInvisibility() {
341         //check links not available
342         assertTrue("Validation Link is still available", GeneralUIUtils.isElementInvisibleByTestId(DataTestIdEnum.VspValidationPage.VSP_VALIDATION_PAGE_NAVBAR.getValue()));
343         assertTrue("Validation Results Link is still available", GeneralUIUtils.isElementInvisibleByTestId(DataTestIdEnum.VspValidationResultsPage.VSP_VALIDATION_RESULTS_PAGE_NAVBAR.getValue()));
344     }
345
346     private void changeVspValidationConfig(boolean isCurrentScreenCatalogPage, String vspName, boolean vspConfig) throws Exception {
347         //change config
348         OnboardingUiUtils.putVspValidationCongiguration(!vspConfig);
349         assertTrue(String.format("Failed to set Congiguration to %s", !vspConfig), OnboardingUiUtils.getVspValidationCongiguration() != vspConfig);
350
351         if (!isCurrentScreenCatalogPage) {
352             GeneralUIUtils.refreshWebpage();
353             GeneralUIUtils.ultimateWait();
354         }
355
356         goToVspScreen(isCurrentScreenCatalogPage, vspName);
357
358         //revert the config
359         OnboardingUiUtils.putVspValidationCongiguration(vspConfig);
360         assertEquals(String.format("Failed to revert Configuration to %s", vspConfig), vspConfig,
361             OnboardingUiUtils.getVspValidationCongiguration());
362     }
363
364     private void goToVspScreen(boolean isCurrentScreenCatalogPage, String vspName) {
365         if (isCurrentScreenCatalogPage) {
366             GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.MainMenuButtons.ONBOARD_BUTTON.getValue());
367         }
368         GeneralUIUtils.clickOnElementByText(vspName);
369         GeneralUIUtils.ultimateWait();
370     }
371
372     private String createNewVSP(String filePath, String vnfFile) throws Exception {
373         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
374         return OnboardingUiUtils.createVSP(resourceReqDetails, vnfFile, filePath, getUser()).getName();
375     }
376
377     public void runOnboardPnfSoftwareVersion(final String resourceName, final String rootFolder,
378                                              final String pnfFile, final List<String> softwareVersionList) {
379         final ExtentTest extendTest = getExtendTest();
380
381         final String swVersionsToString = String.join(", ", softwareVersionList);
382
383         extendTest.log(Status.INFO,
384             String.format("Creating VSP '%s' by onboarding package '%s' with software version '%s'",
385                 resourceName, pnfFile, swVersionsToString)
386         );
387         final WebDriver webDriver = DriverFactory.getDriver();
388         final CreateVspFlow createVspFlow = new CreateVspFlow(webDriver, resourceName, pnfFile, rootFolder);
389         createVspFlow.run(new TopNavComponent(webDriver));
390
391         final ImportVspFlow importVspFlow = new ImportVspFlow(webDriver, resourceName);
392         final ResourceCreatePage resourceCreatePage =
393             (ResourceCreatePage) importVspFlow.run()
394                 .orElseThrow(() -> new UiTestFlowRuntimeException("Missing expected return ResourceCreatePage"));
395
396         final CreateResourceFlow createResourceFlow = new CreateResourceFlow(webDriver, resourceName);
397         createResourceFlow.run(resourceCreatePage);
398
399         final CheckSoftwareVersionPropertyFlow checkSoftwareVersionPropertyFlow =
400             new CheckSoftwareVersionPropertyFlow(webDriver, softwareVersionList);
401         checkSoftwareVersionPropertyFlow.run();
402
403         extendTest.log(Status.INFO,
404             String.format("Successfully onboarded the package '%s' with software version '%s'",
405                 pnfFile, swVersionsToString)
406         );
407     }
408
409     private void runOnboardToDistributionFlow(ResourceReqDetails resourceReqDetails, ServiceReqDetails serviceMetadata, String filePath, String vnfFile) throws Exception {
410         getExtendTest().log(Status.INFO, "Going to create resource with category: " + resourceReqDetails.getCategories().get(0).getName()
411                 + " subCategory: " + resourceReqDetails.getCategories().get(0).getSubcategories().get(0).getName()
412                 + " and service category: " + serviceMetadata.getCategory());
413         final String vspName = onboardAndCertify(resourceReqDetails, filePath, vnfFile);
414
415         ServiceUIUtils.createService(serviceMetadata);
416
417         ServiceGeneralPage.getLeftMenu().moveToCompositionScreen();
418         CompositionPage.searchForElement(vspName);
419         final CanvasManager serviceCanvasManager = CanvasManager.getCanvasManager();
420         final CanvasElement vfElement = serviceCanvasManager.createElementOnCanvas(vspName);
421         ArtifactsCorrelationManager.addVNFtoServiceArtifactCorrelation(serviceMetadata.getName(), vspName);
422
423         assertNotNull(vfElement);
424         ServiceVerificator.verifyNumOfComponentInstances(serviceMetadata, "0.1", 1, getUser());
425         ExtentTestActions.addScreenshot(Status.INFO, "ServiceComposition_" + vnfFile, "The service topology is as follows: ");
426
427         ServiceGeneralPage.clickSubmitForTestingButton(serviceMetadata.getName());
428
429         reloginWithNewRole(UserRoleEnum.TESTER);
430         GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
431         TesterOperationPage.certifyComponent(serviceMetadata.getName());
432
433         reloginWithNewRole(UserRoleEnum.GOVERNOR);
434         HomePage.waitForElement(PageElement.COMPONENT_PANEL);
435         HomePage.findComponentAndClick(serviceMetadata.getName());
436         GovernorOperationPage.approveService(serviceMetadata.getName());
437
438         runDistributionFlow(serviceMetadata);
439
440         getExtendTest().log(Status.INFO, String.format("Successfully onboarded the package '%s'", vnfFile));
441     }
442
443     private void runDistributionFlow(final ServiceReqDetails serviceMetadata) throws Exception {
444         if (makeDistributionValue) {
445             reloginWithNewRole(UserRoleEnum.OPS);
446             GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
447             OpsOperationPage.distributeService();
448             OpsOperationPage.displayMonitor();
449
450             final List<WebElement> rowsFromMonitorTable = OpsOperationPage.getRowsFromMonitorTable();
451             AssertJUnit.assertEquals(1, rowsFromMonitorTable.size());
452
453             OpsOperationPage.waitUntilArtifactsDistributed(0);
454         }
455     }
456
457     private String onboardAndCertify(ResourceReqDetails resourceReqDetails, String filePath, String vnfFile) throws Exception {
458         VendorSoftwareProductObject onboardAndValidate = OnboardingUiUtils.onboardAndValidate(resourceReqDetails, filePath, vnfFile, getUser());
459         String vspName = onboardAndValidate.getName();
460
461         DeploymentArtifactPage.getLeftPanel().moveToCompositionScreen();
462         ExtentTestActions.addScreenshot(Status.INFO, "TopologyTemplate_" + vnfFile, "The topology template for " + vnfFile + " is as follows : ");
463
464         DeploymentArtifactPage.clickCertifyButton(vspName);
465         return vspName;
466     }
467
468
469     @Test(dataProviderClass = OnbordingDataProviders.class, dataProvider = "VNF_List")
470     public void onboardVNFTest(String filePath, String vnfFile) throws Exception {
471         setLog(vnfFile);
472         ResourceReqDetails resourceReqDetails = ElementFactory.getRandomCategoryResource();
473         ServiceReqDetails serviceReqDetails = ElementFactory.getRandomCategoryService();
474         runOnboardToDistributionFlow(resourceReqDetails, serviceReqDetails, filePath, vnfFile);
475     }
476
477     @Test(dataProviderClass = OnbordingDataProviders.class, dataProvider = "VNF_List")
478     public void onboardVNFShotFlow(String filePath, String vnfFile) throws Exception {
479         setLog(vnfFile);
480         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
481         onboardAndCertify(resourceReqDetails, filePath, vnfFile);
482     }
483
484     @Test(dataProviderClass = OnbordingDataProviders.class, dataProvider = "randomVNF_List")
485     public void onboardRandomVNFsTest(String filePath, String vnfFile) throws Exception {
486         setLog(vnfFile);
487         LOGGER.debug("Vnf File name is: {}", vnfFile);
488         ResourceReqDetails resourceReqDetails = ElementFactory.getRandomCategoryResource();
489         ServiceReqDetails serviceReqDetails = ElementFactory.getRandomCategoryService();
490         runOnboardToDistributionFlow(resourceReqDetails, serviceReqDetails, filePath, vnfFile);
491     }
492
493
494     @Test
495     public void onboardUpdateVNFTest() throws Exception {
496         List<String> fileNamesFromFolder = FileHandling.getZipFileNamesFromFolder(filePath);
497         String vnfFile = fileNamesFromFolder.get(0);
498         ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
499         VendorSoftwareProductObject vsp = OnboardingUiUtils.onboardAndValidate(resourceReqDetails, filePath, vnfFile, getUser());
500         String vspName = vsp.getName();
501         ResourceGeneralPage.clickCertifyButton(vspName);
502
503         // create service
504         ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
505         ServiceUIUtils.createService(serviceMetadata);
506
507         ServiceGeneralPage.getLeftMenu().moveToCompositionScreen();
508         CompositionPage.searchForElement(vspName);
509         CanvasManager serviceCanvasManager = CanvasManager.getCanvasManager();
510         CanvasElement vfElement = serviceCanvasManager.createElementOnCanvas(vspName);
511         assertNotNull(vfElement);
512         ServiceVerificator.verifyNumOfComponentInstances(serviceMetadata, "0.1", 1, getUser());
513
514         if (!HomePage.navigateToHomePage()) {
515             fail("Could not go to the home page");
516         }
517
518         ///update flow
519         String updatedVnfFile = fileNamesFromFolder.get(1);
520
521         getExtendTest().log(Status.INFO, String.format("Going to update the VNF with %s......", updatedVnfFile));
522         // update VendorSoftwareProduct
523         OnboardingUiUtils.updateVnfAndValidate(filePath, vsp, updatedVnfFile, getUser());
524         ResourceGeneralPage.clickCertifyButton(vspName);
525
526         // replace exiting VFI in service with new updated
527
528         GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
529         ServiceGeneralPage.getLeftMenu().moveToCompositionScreen();
530         serviceCanvasManager = CanvasManager.getCanvasManager();
531         CompositionPage.changeComponentVersion(serviceCanvasManager, vfElement, "2.0");
532         ServiceVerificator.verifyNumOfComponentInstances(serviceMetadata, "0.1", 1, getUser());
533
534         ServiceGeneralPage.clickSubmitForTestingButton(serviceMetadata.getName());
535
536         reloginWithNewRole(UserRoleEnum.TESTER);
537         GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
538         TesterOperationPage.certifyComponent(serviceMetadata.getName());
539
540         reloginWithNewRole(UserRoleEnum.GOVERNOR);
541         GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
542         GovernorOperationPage.approveService(serviceMetadata.getName());
543
544
545         reloginWithNewRole(UserRoleEnum.OPS);
546         GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
547         OpsOperationPage.distributeService();
548         OpsOperationPage.displayMonitor();
549
550         List<WebElement> rowsFromMonitorTable = OpsOperationPage.getRowsFromMonitorTable();
551         AssertJUnit.assertEquals(1, rowsFromMonitorTable.size());
552
553         OpsOperationPage.waitUntilArtifactsDistributed(0);
554         getExtendTest().log(Status.INFO, String.format("Onboarding %s test is passed ! ", vnfFile));
555     }
556
557
558     @Test
559     public void threeVMMSCsInServiceTest() throws Exception {
560         String pathFile = FileHandling.getFilePath("VmmscArtifacts");
561         final String[] list = new File(pathFile).list();
562         assertNotNull("Did not find vMMSCs", list);
563         assertFalse("Did not find vMMSCs", list.length == 0);
564         List<String> vmmscList = Arrays.stream(list).filter(e -> e.contains("vmmsc") && e.endsWith(".zip"))
565             .collect(Collectors.toList());
566         assertFalse("Did not find vMMSCs", vmmscList.isEmpty());
567
568         Map<String, String> vspNames = new HashMap<>();
569         for (String vnfFile : vmmscList) {
570             String msg = String.format("Going to onboard the VNF %s", vnfFile);
571             getExtendTest().log(Status.INFO, msg);
572             LOGGER.info(msg);
573
574             VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(getUser());
575             ResourceReqDetails resourceReqDetails = ElementFactory.getDefaultResource();
576             VendorSoftwareProductObject createVendorSoftwareProduct = VendorSoftwareProductRestUtils
577                 .createVendorSoftwareProduct(resourceReqDetails, vnfFile, pathFile, getUser(), vendorLicenseModel);
578
579             getExtendTest().log(Status.INFO, String.format("Searching for onboarded %s", vnfFile));
580             HomePage.showVspRepository();
581             getExtendTest().log(Status.INFO, String.format("Going to import %s......", vnfFile.substring(0, vnfFile.indexOf("."))));
582             OnboardingUiUtils.importVSP(createVendorSoftwareProduct);
583
584             ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
585             DeploymentArtifactPage.verifyArtifactsExistInTable(pathFile, vnfFile);
586
587             String vspName = createVendorSoftwareProduct.getName();
588             DeploymentArtifactPage.clickCertifyButton(vspName);
589             vspNames.put(vnfFile, vspName);
590         }
591
592         // create service
593         ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
594         ServiceUIUtils.createService(serviceMetadata);
595         ServiceGeneralPage.getLeftMenu().moveToCompositionScreen();
596         CanvasManager serviceCanvasManager = CanvasManager.getCanvasManager();
597
598         for (String vsp : vspNames.values()) {
599             CompositionPage.searchForElement(vsp);
600             CanvasElement vfElement = serviceCanvasManager.createElementOnCanvas(vsp);
601             assertNotNull(vfElement);
602         }
603         ServiceVerificator.verifyNumOfComponentInstances(serviceMetadata, "0.1", vspNames.values().size(), getUser());
604         File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Info_" + getExtendTest().getModel().getName());
605         final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
606         SetupCDTest.getExtendTest().log(Status.INFO, "Three kinds of vMMSC are in canvas now." + getExtendTest().addScreenCaptureFromPath(absolutePath));
607
608         ServiceGeneralPage.clickSubmitForTestingButton(serviceMetadata.getName());
609
610         reloginWithNewRole(UserRoleEnum.TESTER);
611         GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
612         TesterOperationPage.certifyComponent(serviceMetadata.getName());
613
614         reloginWithNewRole(UserRoleEnum.GOVERNOR);
615         GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
616         GovernorOperationPage.approveService(serviceMetadata.getName());
617
618         reloginWithNewRole(UserRoleEnum.OPS);
619         GeneralUIUtils.findComponentAndClick(serviceMetadata.getName());
620         OpsOperationPage.distributeService();
621         OpsOperationPage.displayMonitor();
622
623         List<WebElement> rowsFromMonitorTable = OpsOperationPage.getRowsFromMonitorTable();
624         AssertJUnit.assertEquals(1, rowsFromMonitorTable.size());
625
626         OpsOperationPage.waitUntilArtifactsDistributed(0);
627     }
628
629
630     @Override
631     protected UserRoleEnum getRole() {
632         return UserRoleEnum.DESIGNER;
633     }
634
635 }