1 package vid.automation.test.test;
3 import org.junit.Assert;
4 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
5 import org.openqa.selenium.WebElement;
6 import vid.automation.test.Constants;
7 import vid.automation.test.infra.Click;
8 import vid.automation.test.infra.Exists;
9 import vid.automation.test.infra.Get;
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;
15 import java.util.ArrayList;
16 import java.util.List;
18 public class CreateInstanceDialogBaseTest extends VidBaseTestCase {
20 protected ViewEditPage viewEditPage= new ViewEditPage();
22 void assertServiceMetadata(String expectedMetadata, String actualMetadata) {
23 WebElement serviceNameElem = GeneralUIUtils.getWebElementByTestID(actualMetadata);
24 String actualServiceName = serviceNameElem.getText();
25 Assert.assertEquals(expectedMetadata, actualServiceName);
28 void validateServiceCreationDialog(Service expectedService) {
29 assertThatServiceCreationDialogIsVisible();
30 assertServiceMetadata(expectedService.name, Constants.SERVICE_NAME);
31 assertServiceMetadata(expectedService.uuid, Constants.SERVICE_UUID);
32 assertServiceMetadata(expectedService.invariantUuid, Constants.SERVICE_INVARIANT_UUID);
33 assertServiceMetadata(expectedService.category, Constants.SERVICE_CATEGORY);
34 assertServiceMetadata(expectedService.version, Constants.SERVICE_VERSION);
35 assertServiceMetadata(expectedService.description, Constants.SERVICE_DESCRIPTION);
38 public void assertThatServiceCreationDialogIsVisible() {
39 boolean byText = GeneralUIUtils.findAndWaitByText(Constants.BrowseASDC.CREATE_SERVICE_INSTANCE, 15);
40 Assert.assertTrue(byText);
43 void assertSuccessfulServiceInstanceCreation() {
44 boolean byText = GeneralUIUtils.findAndWaitByText(Constants.BrowseASDC.SERVICE_INSTANCE_CREATED_SUCCESSFULLY_TEXT, 100);
45 Assert.assertTrue(Constants.BrowseASDC.SERVICE_INSTANCE_CREATION_FAILED_MESSAGE, byText);
48 void validateVnfCreationDialog(ServiceModel expectedServiceInstance) {
49 GeneralUIUtils.ultimateWait();
50 validateNodeTemplateCreationDialog(expectedServiceInstance);
51 assertServiceMetadata(expectedServiceInstance.resourceName, Constants.CreateNewInstance.RESOURCE_NAME);
52 assertServiceMetadata(expectedServiceInstance.nfType, Constants.CreateNewInstance.NF_TYPE);
53 assertServiceMetadata(expectedServiceInstance.nfRole, Constants.CreateNewInstance.NF_ROLE);
54 assertServiceMetadata(expectedServiceInstance.nfFunction, Constants.CreateNewInstance.NF_FUNCTION);
55 assertServiceMetadata(expectedServiceInstance.nfNamingCode, Constants.CreateNewInstance.NF_NAMING_CODE);
58 void validateNodeTemplateCreationDialog(ServiceModel expectedServiceInstance){
59 GeneralUIUtils.ultimateWait();
60 assertServiceMetadata(expectedServiceInstance.serviceName, Constants.SERVICE_NAME);
61 assertServiceMetadata(expectedServiceInstance.subscriberName, Constants.SUBSCRIBER_NAME);
62 assertServiceMetadata(expectedServiceInstance.serviceInstanceName, Constants.SERVICE_INSTANCE_NAME);
63 assertServiceMetadata(expectedServiceInstance.modelName, Constants.CreateNewInstance.MODEL_NAME);
64 assertServiceMetadata(expectedServiceInstance.modelInvariantUuid, Constants.CreateNewInstance.MODEL_INVARIANT_UUID);
65 assertServiceMetadata(expectedServiceInstance.modelVersion, Constants.CreateNewInstance.MODEL_VERSION);
66 assertServiceMetadata(expectedServiceInstance.modelUuid, Constants.CreateNewInstance.MODEL_UUID);
67 assertServiceMetadata(expectedServiceInstance.modelCustomizationUuid, Constants.CreateNewInstance.MODEL_CUSTOMIZATION_UUID);
70 private String fillDetailsInDialog(String name, String lcpRegion, String cloudOwner, String tenant, String suppressRollback,
71 String legacyRegion, ArrayList<String> permittedTenants)
73 viewEditPage.setInstanceName(name);
74 viewEditPage.selectLcpRegion(lcpRegion, cloudOwner);
75 assertDropdownPermittedItemsByValue(permittedTenants, Constants.ViewEdit.TENANT_OPTION_CLASS);
76 viewEditPage.selectTenant(tenant);
77 viewEditPage.selectSuppressRollback(suppressRollback);
78 viewEditPage.setLegacyRegion(legacyRegion);
83 protected String addVFModule(String modelName, String instanceName, String lcpRegion, String cloudOwner, String tenant, String suppressRollback,
84 String legacyRegion, ArrayList<String> permittedTenants,ServiceModel expectedServiceInstance) {
85 viewEditPage.selectVfModuleToAdd(modelName);
86 if(expectedServiceInstance != null) {
87 validateNodeTemplateCreationDialog(expectedServiceInstance);
89 fillDetailsInDialog(instanceName, lcpRegion, cloudOwner, tenant, suppressRollback, legacyRegion, permittedTenants);
90 viewEditPage.clickConfirmButton();
91 assertSuccessfulVFModuleCreation();
92 viewEditPage.clickCloseButton();
93 GeneralUIUtils.ultimateWait();
97 protected void addVolumeGroup (String modelName, String instanceName, String lcpRegion, String cloudOwner, String tenant, String suppressRollback,
98 String legacyRegion, ArrayList<String> permittedTenants, ServiceModel expectedServiceInstance) {
99 viewEditPage.selectVolumeGroupToAdd(modelName);
100 if(expectedServiceInstance != null) {
101 validateNodeTemplateCreationDialog(expectedServiceInstance);
103 fillDetailsInDialog(instanceName, lcpRegion, cloudOwner, tenant, suppressRollback, legacyRegion, permittedTenants);
104 viewEditPage.clickConfirmButton();
105 assertSuccessfulVolumeGroupCreation();
106 viewEditPage.clickCloseButton();
107 GeneralUIUtils.ultimateWait();
110 protected void addVNF(String name, String lcpRegion, String cloudOwner, String tenant, String suppressRollback,
111 String legacyRegion, String productFamily, String platform, ArrayList<String> permittedTenants, String lobs, ServiceModel serviceModel, String instanceName) {
112 openAndFillVnfPopup(name, lcpRegion, cloudOwner, tenant, suppressRollback, legacyRegion, productFamily, platform,permittedTenants, lobs, serviceModel, instanceName);
113 viewEditPage.clickConfirmButton();
114 successConfirmVnfAndClosePopup();
118 protected void openAndFillVnfPopup(String name, String lcpRegion, String cloudOwner, String tenant, String suppressRollback,
119 String legacyRegion, String productFamily, String platform, ArrayList<String> permittedTenants, String lobs, ServiceModel serviceModel, String instanceName) {
120 viewEditPage.selectNodeInstanceToAdd(name);
121 GeneralUIUtils.ultimateWait();
122 if(serviceModel != null) {
123 validateVnfCreationDialog(serviceModel);
125 viewEditPage.selectProductFamily(productFamily);
126 if(platform != null) {
127 SelectOption.byTestIdAndVisibleText(platform, Constants.OwningEntity.PLATFORM_SELECT_TEST_ID);
130 Click.onFirstSelectOptionById(Constants.OwningEntity.PLATFORM_SELECT_TEST_ID);
133 viewEditPage.selectLineOfBusiness(lobs);
135 fillDetailsInDialog(instanceName, lcpRegion, cloudOwner, tenant, suppressRollback, legacyRegion, permittedTenants);
138 protected void successConfirmVnfAndClosePopup() {
139 assertSuccessfulVNFCreation();
140 viewEditPage.clickCloseButton();
141 GeneralUIUtils.ultimateWait();
144 protected void assertConfirmShowMissingDataErrorOnCurrentPopup(String field) {
145 viewEditPage.clickConfirmButton();
146 boolean byclassAndText = Exists.byClassAndText(Constants.ViewEdit.ERROR_CLASS, String.format(Constants.MISSING_DATA, field));
147 Assert.assertTrue(field + " " + Constants.REQUIRED, byclassAndText);
150 protected void cancelPopup() {
151 viewEditPage.clickCancelButtonByTestID();
152 GeneralUIUtils.ultimateWait();
157 public static void AssertUnselectedOptionInMultiselectById(String multiSelectId, String unselectedOption){
158 Click.byId(multiSelectId);
159 WebElement element = Get.byClassAndText(Constants.MULTI_SELECT_UNSELECTED_CLASS, unselectedOption);
160 Assert.assertTrue("The option "+ unselectedOption +" is already selected",element != null);
161 Click.byId(multiSelectId);
164 public void validateDynamicFields(List<String> dynamicFields) {
165 for (String field : dynamicFields) {
166 WebElement fieldElement = GeneralUIUtils.findByText(field);
167 Assert.assertNotNull("couldn't find dynamic field: " + field, fieldElement);