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