e2e test for instantiation template
[vid.git] / vid-automation / src / main / java / vid / automation / test / test / CreateInstanceDialogBaseTest.java
1 package vid.automation.test.test;
2
3 import java.util.ArrayList;
4 import org.junit.Assert;
5 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
6 import org.openqa.selenium.WebElement;
7 import vid.automation.test.Constants;
8 import vid.automation.test.infra.Click;
9 import vid.automation.test.infra.Exists;
10 import vid.automation.test.infra.SelectOption;
11 import vid.automation.test.model.Service;
12 import vid.automation.test.model.ServiceModel;
13 import vid.automation.test.sections.ViewEditPage;
14
15 public class CreateInstanceDialogBaseTest extends VidBaseTestCase {
16
17     protected ViewEditPage viewEditPage= new ViewEditPage();
18
19     void assertServiceMetadata(String expectedMetadata, String actualMetadata) {
20         WebElement serviceNameElem = GeneralUIUtils.getWebElementByTestID(actualMetadata);
21         String actualServiceName = serviceNameElem.getText();
22         Assert.assertEquals(expectedMetadata, actualServiceName);
23     }
24
25     void validateServiceCreationDialog(Service expectedService) {
26         assertThatServiceCreationDialogIsVisible();
27         assertServiceMetadata(expectedService.name, Constants.SERVICE_NAME);
28         assertServiceMetadata(expectedService.uuid, Constants.SERVICE_UUID);
29         assertServiceMetadata(expectedService.invariantUuid, Constants.SERVICE_INVARIANT_UUID);
30         assertServiceMetadata(expectedService.category, Constants.SERVICE_CATEGORY);
31         assertServiceMetadata(expectedService.version, Constants.SERVICE_VERSION);
32         assertServiceMetadata(expectedService.description, Constants.SERVICE_DESCRIPTION);
33     }
34
35     public void assertThatServiceCreationDialogIsVisible() {
36         boolean byText = GeneralUIUtils.findAndWaitByText(Constants.BrowseASDC.CREATE_SERVICE_INSTANCE, 15);
37         Assert.assertTrue(byText);
38     }
39
40     void assertSuccessfulServiceInstanceCreation() {
41         boolean byText = GeneralUIUtils.findAndWaitByText(Constants.BrowseASDC.SERVICE_INSTANCE_CREATED_SUCCESSFULLY_TEXT, 100);
42         Assert.assertTrue(Constants.BrowseASDC.SERVICE_INSTANCE_CREATION_FAILED_MESSAGE, byText);
43     }
44
45     void validateVnfCreationDialog(ServiceModel expectedServiceInstance) {
46         GeneralUIUtils.ultimateWait();
47         validateNodeTemplateCreationDialog(expectedServiceInstance);
48         assertServiceMetadata(expectedServiceInstance.resourceName, Constants.CreateNewInstance.RESOURCE_NAME);
49         assertServiceMetadata(expectedServiceInstance.nfType, Constants.CreateNewInstance.NF_TYPE);
50         assertServiceMetadata(expectedServiceInstance.nfRole, Constants.CreateNewInstance.NF_ROLE);
51         assertServiceMetadata(expectedServiceInstance.nfFunction, Constants.CreateNewInstance.NF_FUNCTION);
52         assertServiceMetadata(expectedServiceInstance.nfNamingCode, Constants.CreateNewInstance.NF_NAMING_CODE);
53     }
54
55     void validateNodeTemplateCreationDialog(ServiceModel expectedServiceInstance){
56         GeneralUIUtils.ultimateWait();
57         assertServiceMetadata(expectedServiceInstance.serviceName, Constants.SERVICE_NAME);
58         assertServiceMetadata(expectedServiceInstance.subscriberName, Constants.SUBSCRIBER_NAME);
59         assertServiceMetadata(expectedServiceInstance.serviceInstanceName, Constants.SERVICE_INSTANCE_NAME);
60         assertServiceMetadata(expectedServiceInstance.modelName, Constants.CreateNewInstance.MODEL_NAME);
61         assertServiceMetadata(expectedServiceInstance.modelInvariantUuid, Constants.CreateNewInstance.MODEL_INVARIANT_UUID);
62         assertServiceMetadata(expectedServiceInstance.modelVersion, Constants.CreateNewInstance.MODEL_VERSION);
63         assertServiceMetadata(expectedServiceInstance.modelUuid, Constants.CreateNewInstance.MODEL_UUID);
64         assertServiceMetadata(expectedServiceInstance.modelCustomizationUuid, Constants.CreateNewInstance.MODEL_CUSTOMIZATION_UUID);
65     }
66
67     private String fillDetailsInDialog(String name, String lcpRegion, String cloudOwner, String tenant, String suppressRollback,
68                       String legacyRegion, ArrayList<String> permittedTenants)
69     {
70         viewEditPage.setInstanceName(name);
71         viewEditPage.selectLcpRegion(lcpRegion, cloudOwner);
72         assertDropdownPermittedItemsByValue(permittedTenants, Constants.ViewEdit.TENANT_OPTION_CLASS);
73         viewEditPage.selectTenant(tenant);
74         viewEditPage.selectSuppressRollback(suppressRollback);
75         viewEditPage.setLegacyRegion(legacyRegion);
76         return name;
77     }
78
79
80     protected String addVFModule(String modelName, String instanceName, String lcpRegion, String cloudOwner, String tenant, String suppressRollback,
81                                  String legacyRegion, ArrayList<String> permittedTenants,ServiceModel expectedServiceInstance) {
82         viewEditPage.selectVfModuleToAdd(modelName);
83         if(expectedServiceInstance != null) {
84             validateNodeTemplateCreationDialog(expectedServiceInstance);
85         }
86         fillDetailsInDialog(instanceName, lcpRegion, cloudOwner, tenant, suppressRollback, legacyRegion, permittedTenants);
87         viewEditPage.clickConfirmButton();
88         assertSuccessfulVFModuleCreation();
89         viewEditPage.clickCloseButton();
90         GeneralUIUtils.ultimateWait();
91         return instanceName;
92     }
93
94     protected void addVolumeGroup (String modelName, String instanceName, String lcpRegion, String cloudOwner, String tenant, String suppressRollback,
95                                   String legacyRegion, ArrayList<String> permittedTenants, ServiceModel expectedServiceInstance) {
96         viewEditPage.selectVolumeGroupToAdd(modelName);
97         if(expectedServiceInstance != null) {
98             validateNodeTemplateCreationDialog(expectedServiceInstance);
99         }
100         fillDetailsInDialog(instanceName, lcpRegion, cloudOwner, tenant, suppressRollback, legacyRegion, permittedTenants);
101         viewEditPage.clickConfirmButton();
102         assertSuccessfulVolumeGroupCreation();
103         viewEditPage.clickCloseButton();
104         GeneralUIUtils.ultimateWait();
105     }
106
107     protected void addVNF(String name, String lcpRegion, String cloudOwner, String tenant, String suppressRollback,
108                           String legacyRegion, String productFamily, String platform, ArrayList<String> permittedTenants, String lobs, ServiceModel serviceModel, String instanceName) {
109         openAndFillVnfPopup(name, lcpRegion, cloudOwner, tenant, suppressRollback, legacyRegion, productFamily, platform,permittedTenants, lobs, serviceModel, instanceName);
110         viewEditPage.clickConfirmButton();
111         successConfirmVnfAndClosePopup();
112
113     }
114
115     protected void openAndFillVnfPopup(String name, String lcpRegion, String cloudOwner, String tenant, String suppressRollback,
116                                        String legacyRegion, String productFamily, String platform, ArrayList<String> permittedTenants, String lobs, ServiceModel serviceModel, String instanceName) {
117         viewEditPage.selectNodeInstanceToAdd(name);
118         GeneralUIUtils.ultimateWait();
119         if(serviceModel != null) {
120             validateVnfCreationDialog(serviceModel);
121         }
122         viewEditPage.selectProductFamily(productFamily);
123         if(platform != null) {
124             SelectOption.byTestIdAndVisibleText(platform, Constants.OwningEntity.PLATFORM_SELECT_TEST_ID);
125         }
126         else {
127             Click.onFirstSelectOptionById(Constants.OwningEntity.PLATFORM_SELECT_TEST_ID);
128         }
129         if(lobs != null) {
130             viewEditPage.selectLineOfBusiness(lobs);
131         }
132         fillDetailsInDialog(instanceName, lcpRegion, cloudOwner, tenant, suppressRollback, legacyRegion, permittedTenants);
133     }
134
135     protected void successConfirmVnfAndClosePopup() {
136         assertSuccessfulVNFCreation();
137         viewEditPage.clickCloseButton();
138         GeneralUIUtils.ultimateWait();
139     }
140
141     protected void assertConfirmShowMissingDataErrorOnCurrentPopup(String field) {
142         viewEditPage.clickConfirmButton();
143         boolean byclassAndText = Exists.byClassAndText(Constants.ViewEdit.ERROR_CLASS, String.format(Constants.MISSING_DATA, field));
144         Assert.assertTrue(field + " " + Constants.REQUIRED, byclassAndText);
145     }
146
147 }