aboutsummaryrefslogtreecommitdiffstats
path: root/vid-automation/src/main/java/vid/automation/test/test/CreateInstanceDialogBaseTest.java
blob: b486d27dfd762f3ae73a811abaf087b717dcb071 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package vid.automation.test.test;

import org.junit.Assert;
import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
import org.openqa.selenium.WebElement;
import vid.automation.test.Constants;
import vid.automation.test.infra.Click;
import vid.automation.test.infra.Exists;
import vid.automation.test.infra.Get;
import vid.automation.test.infra.SelectOption;
import vid.automation.test.model.Service;
import vid.automation.test.model.ServiceModel;
import vid.automation.test.sections.ViewEditPage;

import java.util.ArrayList;
import java.util.List;

public class CreateInstanceDialogBaseTest extends VidBaseTestCase {

    private ViewEditPage viewEditPage= new ViewEditPage();

    void assertServiceMetadata(String expectedMetadata, String actualMetadata) {
        WebElement serviceNameElem = GeneralUIUtils.getWebElementByTestID(actualMetadata);
        String actualServiceName = serviceNameElem.getText();
        Assert.assertEquals(expectedMetadata, actualServiceName);
    }

    void validateServiceCreationDialog(Service expectedService) {
        assertThatServiceCreationDialogIsVisible();
        assertServiceMetadata(expectedService.name, Constants.SERVICE_NAME);
        assertServiceMetadata(expectedService.uuid, Constants.SERVICE_UUID);
        assertServiceMetadata(expectedService.invariantUuid, Constants.SERVICE_INVARIANT_UUID);
        assertServiceMetadata(expectedService.category, Constants.SERVICE_CATEGORY);
        assertServiceMetadata(expectedService.version, Constants.SERVICE_VERSION);
        assertServiceMetadata(expectedService.description, Constants.SERVICE_DESCRIPTION);
    }

    public void assertThatServiceCreationDialogIsVisible() {
        boolean byText = GeneralUIUtils.findAndWaitByText(Constants.BrowseASDC.CREATE_SERVICE_INSTANCE, 15);
        Assert.assertTrue(byText);
    }

    void assertSuccessfulServiceInstanceCreation() {
        boolean byText = GeneralUIUtils.findAndWaitByText(Constants.BrowseASDC.SERVICE_INSTANCE_CREATED_SUCCESSFULLY_TEXT, 100);
        Assert.assertTrue(Constants.BrowseASDC.SERVICE_INSTANCE_CREATION_FAILED_MESSAGE, byText);
    }

    void validateVnfCreationDialog(ServiceModel expectedServiceInstance) {
        GeneralUIUtils.ultimateWait();
        validateNodeTemplateCreationDialog(expectedServiceInstance);
        assertServiceMetadata(expectedServiceInstance.resourceName, Constants.CreateNewInstance.RESOURCE_NAME);
        assertServiceMetadata(expectedServiceInstance.nfType, Constants.CreateNewInstance.NF_TYPE);
        assertServiceMetadata(expectedServiceInstance.nfRole, Constants.CreateNewInstance.NF_ROLE);
        assertServiceMetadata(expectedServiceInstance.nfFunction, Constants.CreateNewInstance.NF_FUNCTION);
        assertServiceMetadata(expectedServiceInstance.nfNamingCode, Constants.CreateNewInstance.NF_NAMING_CODE);
    }

    void validateNodeTemplateCreationDialog(ServiceModel expectedServiceInstance){
        GeneralUIUtils.ultimateWait();
        assertServiceMetadata(expectedServiceInstance.serviceName, Constants.SERVICE_NAME);
        assertServiceMetadata(expectedServiceInstance.subscriberName, Constants.SUBSCRIBER_NAME);
        assertServiceMetadata(expectedServiceInstance.serviceInstanceName, Constants.SERVICE_INSTANCE_NAME);
        assertServiceMetadata(expectedServiceInstance.modelName, Constants.CreateNewInstance.MODEL_NAME);
        assertServiceMetadata(expectedServiceInstance.modelInvariantUuid, Constants.CreateNewInstance.MODEL_INVARIANT_UUID);
        assertServiceMetadata(expectedServiceInstance.modelVersion, Constants.CreateNewInstance.MODEL_VERSION);
        assertServiceMetadata(expectedServiceInstance.modelUuid, Constants.CreateNewInstance.MODEL_UUID);
        assertServiceMetadata(expectedServiceInstance.modelCustomizationUuid, Constants.CreateNewInstance.MODEL_CUSTOMIZATION_UUID);
    }

    private String fillDetailsInDialogWithGeneratedName(String name, String lcpRegion, String tenant, String suppressRollback,
                                                        String legacyRegion, ArrayList<String> permittedTenants)
    {
        String generatedInstanceName = viewEditPage.generateInstanceName(name);
        return fillDetailsInDialog(generatedInstanceName, lcpRegion, tenant, suppressRollback, legacyRegion, permittedTenants);
    }

    private String fillDetailsInDialog(String name, String lcpRegion, String tenant, String suppressRollback,
                      String legacyRegion, ArrayList<String> permittedTenants)
    {
        viewEditPage.setInstanceName(name);
        viewEditPage.selectLCPRegion(lcpRegion);
        assertDropdownPermittedItemsByValue(permittedTenants, Constants.ViewEdit.TENANT_OPTION_CLASS);
        viewEditPage.selectTenant(tenant);
        viewEditPage.selectSuppressRollback(suppressRollback);
        viewEditPage.setLegacyRegion(legacyRegion);
        return name;
    }


    protected String addVFModule(String name, String lcpRegion, String tenant, String suppressRollback,
                                 String legacyRegion, ArrayList<String> permittedTenants,ServiceModel expectedServiceInstance) {
        viewEditPage.selectVfModuleToAdd(name);
        if(expectedServiceInstance != null) {
            validateNodeTemplateCreationDialog(expectedServiceInstance);
        }
        String instanceName = fillDetailsInDialogWithGeneratedName(Constants.INSTANCE_NAME_SELECT_TESTS_ID, lcpRegion, tenant, suppressRollback, legacyRegion, permittedTenants);
        viewEditPage.clickConfirmButton();
        assertSuccessfulVFModuleCreation();
        viewEditPage.clickCloseButton();
        GeneralUIUtils.ultimateWait();
        return instanceName;
    }

    protected void addVolumeGroup (String name, String lcpRegion, String tenant, String suppressRollback,
                                  String legacyRegion, ArrayList<String> permittedTenants, ServiceModel expectedServiceInstance) {
        viewEditPage.selectVolumeGroupToAdd(name);
        if(expectedServiceInstance != null) {
            validateNodeTemplateCreationDialog(expectedServiceInstance);
        }
        fillDetailsInDialogWithGeneratedName(Constants.ViewEdit.VOLUME_GROUP_INSTANCE_NAME_PREFIX, lcpRegion, tenant, suppressRollback, legacyRegion, permittedTenants);
        viewEditPage.clickConfirmButton();
        assertSuccessfulVolumeGroupCreation();
        viewEditPage.clickCloseButton();
        GeneralUIUtils.ultimateWait();
    }

    protected void addVNF(String name, String lcpRegion, String tenant, String suppressRollback,
                          String legacyRegion, String productFamily, String platform, ArrayList<String> permittedTenants, List<String> lobs, ServiceModel serviceModel, String instanceName) {
        openAndFillVnfPopup(name, lcpRegion, tenant, suppressRollback, legacyRegion, productFamily, platform,permittedTenants, lobs, serviceModel, instanceName);
        viewEditPage.clickConfirmButton();
        successConfirmVnfAndClosePopup();

    }

    protected void openAndFillVnfPopup(String name, String lcpRegion, String tenant, String suppressRollback,
                                       String legacyRegion, String productFamily, String platform, ArrayList<String> permittedTenants, List<String> lobs, ServiceModel serviceModel, String instanceName) {
        viewEditPage.selectNodeInstanceToAdd(name);
        GeneralUIUtils.ultimateWait();
        if(serviceModel != null) {
            validateVnfCreationDialog(serviceModel);
        }
        viewEditPage.selectProductFamily(productFamily);
        if(platform != null) {
            SelectOption.byTestIdAndVisibleText(platform, Constants.OwningEntity.PLATFORM_SELECT_TEST_ID);
        }
        else {
            Click.onFirstSelectOptionById(Constants.OwningEntity.PLATFORM_SELECT_TEST_ID);
        }
        if(lobs != null) {
            SelectOption.selectOptionsFromMultiselectById(Constants.OwningEntity.LOB_SELECT_TEST_ID, lobs);
        }
        fillDetailsInDialog(instanceName, lcpRegion, tenant, suppressRollback, legacyRegion, permittedTenants);
    }

    protected void successConfirmVnfAndClosePopup() {
        assertSuccessfulVNFCreation();
        viewEditPage.clickCloseButton();
        GeneralUIUtils.ultimateWait();
    }

    protected void assertConfirmShowMissingDataErrorOnCurrentPopup(String field) {
        viewEditPage.clickConfirmButton();
        boolean byclassAndText = Exists.byClassAndText(Constants.ViewEdit.ERROR_CLASS, String.format(Constants.MISSING_DATA, field));
        Assert.assertFalse(field + " " + Constants.REQUIRED, byclassAndText);
    }

    protected void cancelPopup() {
        viewEditPage.clickCancelButtonByTestID();
        GeneralUIUtils.ultimateWait();
    }



    public static void AssertUnselectedOptionInMultiselectById(String multiSelectId, String unselectedOption){
        Click.byId(multiSelectId);
        WebElement element = Get.byClassAndText(Constants.MULTI_SELECT_UNSELECTED_CLASS, unselectedOption);
        Assert.assertTrue("The option "+ unselectedOption +" is already selected",element != null);
        Click.byId(multiSelectId);
    }

    public void validateDynamicFields(List<String> dynamicFields) {
        for (String field : dynamicFields) {
            WebElement fieldElement = GeneralUIUtils.findByText(field);
            Assert.assertNotNull("couldn't find dynamic field: " + field, fieldElement);
        }
    }
}