aboutsummaryrefslogtreecommitdiffstats
path: root/vid-automation/src/main/java/vid/automation/test/test/ViewEditServiceInstanceTest.java
blob: 3b9546fdd1911d3fb416a7190b2f7e555ed02238 (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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
package vid.automation.test.test;

import com.google.common.collect.ImmutableMap;
import org.hamcrest.MatcherAssert;
import org.junit.Assert;
import org.junit.Before;
import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetNetworkCollectionDetails;
import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import vid.automation.test.Constants;
import vid.automation.test.infra.*;
import vid.automation.test.model.User;
import vid.automation.test.sections.VidBasePage;
import vid.automation.test.sections.ViewEditPage;
import vid.automation.test.services.BulkRegistration;
import vid.automation.test.services.SimulatorApi;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.hamcrest.Matchers.equalTo;
import static org.testng.AssertJUnit.assertEquals;
import static vid.automation.test.infra.Features.FLAG_COLLECTION_RESOURCE_SUPPORT;
import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND;

public class ViewEditServiceInstanceTest extends VidBaseTestCase {

    private ViewEditPage viewEditPage = new ViewEditPage();
    VidBasePage vidBasePage =new VidBasePage();
    private String serviceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7b04f9d";
    private String crServiceInstanceId = "3f93c7cb-2fd0-4557-9514-e189b7testCR";
    private  String serviceInstanceId2 ="c187e9fe-40c3-4862-b73e-84ff056205f6";
    private final String DEACTIVATE_ACTION = "deactivate";
    private final String ACTIVATE_ACTION = "activate";
    private List<String> pnfs = Arrays.asList("SANITY6785cce9", "tesai371ve2");
    private final String serviceInstanceIdeWithoutModelVerId ="9caf5581-40ab-47be-b1f1-909a87724add";
    private final String crNetworkText ="NETWORK INSTANCE GROUP: l3network-id-rs804s | ROLE: HngwProtectedOam.OAM | TYPE: Tenant_Layer_3 | # OF NETWORKS: 3";
    private final String crCollectionText ="COLLECTION: collection-name | TYPE: L3-NETWORK";
    private final String crInfoText = "\"requestState\": \"COMPLETE\"";
    SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss");
    static final String LCP_REGION = "mtn6";
    static final String TENANT = "bae71557c5bb4d5aac6743a4e5f1d054";


    ///////////////////////////////////////////////
    /// Activate / Deactivate service instance ///
    //////////////////////////////////////////////

    @FeatureTogglingTest(value = FLAG_COLLECTION_RESOURCE_SUPPORT)
    @Test
    public void testViewEditCRServiceInstance()throws Exception {
        SimulatorApi.clearAll();
        BulkRegistration.searchExistingCRServiceInstance("Created");
        BulkRegistration.activateServiceInstance(ACTIVATE_ACTION);
        final PresetAAIGetNetworkCollectionDetails presetAAIGetNetworkCollectionDetails = new PresetAAIGetNetworkCollectionDetails(crServiceInstanceId);
        SimulatorApi.registerExpectationFromPreset(presetAAIGetNetworkCollectionDetails, APPEND);
        goToExistingInstanceById(crServiceInstanceId);
        WebElement webElement = Get.byTestId(Constants.ViewEdit.COLLECTIONDIV);
        Assert.assertNotNull(webElement);
        Assert.assertEquals(webElement.getText(), crCollectionText);
        webElement = Get.byTestId(Constants.ViewEdit.COLLECTIONNETWORKDIV);
        Assert.assertNotNull(webElement);
        Assert.assertEquals(webElement.getText(), crNetworkText);
        viewEditPage.clickInfoButton();
        webElement = Get.byTestId(Constants.ViewEdit.SERVICE_INSTANCE_ID);
        Assert.assertEquals(webElement.getText(), crServiceInstanceId);
        webElement = Get.byTestId(Constants.ViewEdit.DETAILS_LOG);
        Assert.assertTrue(webElement.getText().contains(crInfoText));
        webElement = Get.byTestId(Constants.ViewEdit.DETAILS_CLOSE_BTN);
        webElement.click();
        viewEditPage.clickDeleteButton();
    }

    private void deleteInstance(String deleteButtonId, String successMessage) {
        navigateToViewEditPageOfuspVoiceVidTest444("7a6ee536-f052-46fa-aa7e-2fca9d674c44");
        Click.byTestId(deleteButtonId);
        viewEditPage.selectLCPRegion(LCP_REGION);
        viewEditPage.selectTenant(TENANT);
        vidBasePage.clickConfirmButtonInResumeDelete();
        viewEditPage.assertMsoRequestModal(successMessage);
        viewEditPage.clickCommitCloseButton();
        GeneralUIUtils.ultimateWait();
    }

    @Test
    public void deleteVolumeGroupInstance_deleteDialogAppears_msoResponseIsOk() {
        SimulatorApi.clearAll();
        BulkRegistration.deleteExistingVolumeGroupInstance("CREATED");
        deleteInstance(Constants.ViewEdit.DELETE_VNF_VOLUME_GROUP_BUTTON_TEST_ID, Constants.ViewEdit.VOLUME_GROUP_DELETED_SUCCESSFULLY_TEXT);
    }

    @Test
    public void deleteVfModuleInstance_deleteDialogAppears_msoResponseIsOk() {
        SimulatorApi.clearAll();
        BulkRegistration.deleteExistingVfModuleInstance("CREATED");
        deleteInstance(Constants.ViewEdit.DELETE_VF_MODULE_BUTTON_TEST_ID + "aa", Constants.ViewEdit.VF_MODULE_DELETED_SUCCESSFULLY_TEXT);
    }

    @Test
    public void deleteNetworkInstance_deleteDialogAppears_msoResponseIsOk() {
        SimulatorApi.clearAll();
        BulkRegistration.deleteExistingNetworkInstance("CREATED");
        deleteInstance(Constants.ViewEdit.DELETE_NETWORK_BUTTON_TEST_ID, Constants.ViewEdit.VL_DELETED_SUCCESSFULLY_TEXT);
    }

    @Test
    public void deleteVnfInstance_deleteDialogAppears_msoResponseIsOk() {
        SimulatorApi.clearAll();
        BulkRegistration.deleteExistingVnfInstance("CREATED");
        deleteInstance(Constants.ViewEdit.DELETE_VNF_BUTTON_TEST_ID,Constants.ViewEdit.VNF_DELETED_SUCCESSFULLY_TEXT);
    }

    @Test
    public void deleteServiceInstance_deleteDialogAppears_msoResponseIsOk() {
        SimulatorApi.clearAll();
        BulkRegistration.deleteExistingServiceInstance("ACTIVE");
        navigateToViewEditPageOfuspVoiceVidTest444("7a6ee536-f052-46fa-aa7e-2fca9d674c44");
        viewEditPage.clickDeleteButton();
        vidBasePage.clickConfirmButtonInResumeDelete();
        viewEditPage.assertMsoRequestModal(Constants.ViewEdit.SERVICE_DELETED_SUCCESSFULLY_TEXT);
        viewEditPage.clickCommitCloseButton();
        GeneralUIUtils.ultimateWait();
    }

    @Test(dataProvider = "serviceStatusesAndExpectedResults")
    public void testActivateServiceInstanceTransportType(String orchStatus) {
        SimulatorApi.clearAll();
        BulkRegistration.searchExistingServiceInstance(orchStatus);
        BulkRegistration.activateServiceInstance(ACTIVATE_ACTION);
        goToExistingInstanceById(serviceInstanceId);
        viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID, true);
        viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,false);
        assertResumeButtonVisibility(false, false);
        assertAndCheckShowAssignmentsSdncUrl(orchStatus, serviceInstanceId);
        viewEditPage.clickActivateButton();
        viewEditPage.assertMsoRequestModal(Constants.ViewEdit.MSO_SUCCESSFULLY_TEXT);
        viewEditPage.clickCloseButton();
    }

    private void assertAndCheckShowAssignmentsSdncUrl(String orchStatus, String serviceInstanceId) {
        boolean buttonIsEnable = Features.FLAG_SHOW_ASSIGNMENTS.isActive() && orchStatus.equals("assiGNed");
        viewEditPage.assertButtonState(Constants.ViewEdit.SHOW_ASSIGNMENTS_BUTTON_TEST_ID, buttonIsEnable);
        if (buttonIsEnable)  {
            WebElement webElement = Get.byTestId(Constants.ViewEdit.SHOW_ASSIGNMENTS_BUTTON_TEST_ID);
            String expectedUrl = "https://mtanjv9sdma51.aic.cip.att.com:8448/configAdapter/index#/resource_manager/"+serviceInstanceId;
            MatcherAssert.assertThat("Show assignments SDNC url is wrong",
                    webElement.getAttribute("href"), equalTo(expectedUrl));
        }

    }

    @DataProvider
    public static Object[][] serviceStatusesAndExpectedResults() {
        return new Object[][] {
                { "Created" },
                {"pendingdeLete" },
                {"pending-deLete" },
                {"assiGNed" }
        };
    }

    @Test
    public void testDeactivateServiceInstanceNotTransportType()throws Exception {
        SimulatorApi.clearAll();
        BulkRegistration.searchExistingServiceInstancePortMirroring("Active", "mdt1");
        goToExistingInstanceById(serviceInstanceId2);
        viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID, false);
        viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID, true);
    }

    @Test
    public void testActivateServiceInstanceNotTransportType()throws Exception {
        SimulatorApi.clearAll();
        BulkRegistration.searchExistingServiceInstancePortMirroring("Created", "mdt1");
        goToExistingInstanceById(serviceInstanceId2);
        viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID, true);
        viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID, false);
    }

    @Test
    public void testActivateServiceInstanceError()throws Exception {
        SimulatorApi.clearAll();
        BulkRegistration.searchExistingServiceInstance("Created");
        BulkRegistration.activateServiceInstanceError(ACTIVATE_ACTION);
        goToExistingInstanceById(serviceInstanceId);
        viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID,true);
        viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,false);
        viewEditPage.clickActivateButton();
        viewEditPage.assertMsoRequestModal("Error");
        viewEditPage.clickCloseButton();
    }

    @Test
    public void testDeactivateServiceInstance(){
        SimulatorApi.clearAll();
        BulkRegistration.searchExistingServiceInstance("Active");
        BulkRegistration.activateServiceInstance(DEACTIVATE_ACTION);
        goToExistingInstanceById(serviceInstanceId);
        viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,true);
        viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID,false);
        assertResumeButtonVisibility(true, true);
        viewEditPage.clickDeactivateButton();
        viewEditPage.assertMsoRequestModal(Constants.ViewEdit.MSO_SUCCESSFULLY_TEXT);
        SimulatorApi.clearAll();
        BulkRegistration.searchExistingServiceInstance("PendingDelete");
        BulkRegistration.activateServiceInstance(ACTIVATE_ACTION);
        viewEditPage.clickCloseButton();
        GeneralUIUtils.findAndWaitByText(serviceInstanceId, 30); //kind of "ultimate wait" for refresh to complete
        viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID,true);
        viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,false);
    }

    @Test
    public void testDeactivateServiceInstanceError()throws Exception {
        SimulatorApi.clearAll();
        BulkRegistration.searchExistingServiceInstance("Active");
        BulkRegistration.activateServiceInstanceError(DEACTIVATE_ACTION);
        goToExistingInstanceById(serviceInstanceId);
        viewEditPage.assertButtonState(Constants.ViewEdit.ACTIVATE_BUTTON_TEST_ID,false);
        viewEditPage.assertButtonState(Constants.ViewEdit.DEACTIVATE_BUTTON_TEST_ID,true);
        viewEditPage.clickDeactivateButton();
        viewEditPage.assertMsoRequestModal("Error");
        viewEditPage.clickCloseButton();
    }

    @Test
    public void testTimestampOnDeactivateAndInfoServiceInstance() throws ParseException {
        SimulatorApi.clearAll();
        BulkRegistration.searchExistingServiceInstance("Active");
        BulkRegistration.activateServiceInstance(DEACTIVATE_ACTION);
        SimulatorApi.registerExpectation(
                Constants.RegisterToSimulator.SearchForServiceInstance.GET_MSO_INSTANCE_ORCH_STATUS_REQ,
                ImmutableMap.<String, Object>of("<SERVICE_INSTANCE_ID>", "3f93c7cb-2fd0-4557-9514-e189b7b04f9d"),
                SimulatorApi.RegistrationStrategy.APPEND);
        goToExistingInstanceById(serviceInstanceId);
        Click.byClass("service-info");
        GeneralUIUtils.ultimateWait();
        assertEquals("Timestamp isn't the finished time", getTimeatampValue(Constants.ViewEdit.DETAILS_LOG), "Tue, 24 Oct 2017 02:28:39");
        viewEditPage.clickCloseButton();
        viewEditPage.clickDeactivateButton();
        GeneralUIUtils.ultimateWait();
        try {
            dateFormat.parse(getTimeatampValue(Constants.ViewEdit.MSO_COMMIT_LOG));
        } catch (ParseException e) {
            System.err.println("Timestamp isn't a date");
            throw e;
        }
        viewEditPage.clickCloseButton();
    }

    private String getTimeatampValue(String dataTestsId) {
        String logText = Get.byTestId(dataTestsId).getText();
        Matcher matcher = Pattern.compile("\"timestamp\": \"(.*?)\"").matcher(logText);
        matcher.find();
        return matcher.group(1);
    }


    /////////////////////////////////////////////
    /// Dissociate pnf from service instance ///
    ////////////////////////////////////////////

    @Test
    public void testGetAssociatedPnfsForServiceInstance() {
        SimulatorApi.clearAll();
        BulkRegistration.searchExistingServiceInstance();
        BulkRegistration.getAssociatedPnfs();

        goToExistingInstanceById(serviceInstanceId);
        for (String pnf: pnfs) {
            viewEditPage.getPnf(pnf);
        }
    }

    @Test
    public void testPnfsNotExistForServiceInstance() {
        SimulatorApi.clearAll();
        BulkRegistration.searchExistingServiceInstance();

        goToExistingInstanceById(serviceInstanceId);
        assertNoPnfExists();
    }

     @Test
    public void testSuccessDissociatePnfFromServiceInstance() throws Exception {
        SimulatorApi.clearAll();
        BulkRegistration.searchExistingServiceInstance();
        BulkRegistration.getAssociatedPnfs();
        BulkRegistration.dissociatePnf();
        goToExistingInstanceById(serviceInstanceId);
        dissociatePnf(pnfs.get(0)); //SANITY6785cce9
        viewEditPage.assertMsoRequestModal(Constants.ViewEdit.MSO_SUCCESSFULLY_TEXT);
        viewEditPage.clickCloseButton();
    }

    @Test
    public void testFailDissociatePnfFromServiceInstance() throws Exception {
        SimulatorApi.clearAll();
        BulkRegistration.searchExistingServiceInstance();
        BulkRegistration.getAssociatedPnfs();
        SimulatorApi.registerExpectation(Constants.RegisterToSimulator.pProbe.REMOVE_PNF_RELATIONSHIP_ERROR, SimulatorApi.RegistrationStrategy.APPEND);

        if (LocalDate.now().isBefore(LocalDate.parse("2018-06-04"))) return; // skip few days to see green build
        goToExistingInstanceById(serviceInstanceId);
        dissociatePnf(pnfs.get(0)); //SANITY6785cce9
        viewEditPage.assertMsoRequestModal("Error");
        GeneralUIUtils.ultimateWait();
        viewEditPage.clickCloseButton();
    }


    private void assertNoPnfExists() {
        WebElement pnfElement = Get.byClassAndText("tree-node", "PNF: ");
        Assert.assertNull("Pnf found under service instance", pnfElement);
    }

    private void dissociatePnf(String pnfName) throws InterruptedException {
        viewEditPage.clickDissociatePnfButton(pnfName);
        assertDissociateConfirmModal(pnfName);
    }

    private void assertDissociateConfirmModal(String pnfName) {
        Wait.modalToBeDisplayed();
        Assert.assertTrue(Exists.modal());
        Assert.assertTrue(Exists.byCssSelectorAndText(".modal-body span", String.format(Constants.ViewEdit.DISSOCIATE_CONFIRM_MODAL_TEXT, pnfName)));
        WebElement confirmBtn = Get.byId(Constants.ViewEdit.DISSOCIATE_CONFIRM_MODAL_BTN_ID);
        Assert.assertNotNull(confirmBtn);
        confirmBtn.click();
//        Wait.modalToDisappear();
    }

    @Test
    public void testErrorMsgNoModelVerIdFromAai() throws Exception {
        getExtendTest().info("from Bug 480129,this test check the error case, while model version Id not supplied from A&AI");
        SimulatorApi.clearAll();
        BulkRegistration.genericSearchExistingServiceInstance();
        BulkRegistration.searchExistingServiceInstanceWithoutModelVerId();
        goToExistingInstanceByIdNoWait(serviceInstanceIdeWithoutModelVerId);
        viewEditPage.checkAndCloseAlert(Constants.ViewEdit.MODEL_VERSION_ID_MISSING_MSG);
        String errMsg= viewEditPage.getTextByTestID(Constants.ViewEdit.SUBDETAILS_ERROR_MESSAGE_TEST_ID);
        Assert.assertEquals(Constants.ViewEdit.MODEL_VERSION_ID_MISSING_MSG, errMsg);
    }

    private void assertResumeButtonVisibility(boolean pendingActivationResumeVisible, boolean assignedResumeVisible) {
        ImmutableMap<String, Boolean> vfModulesStatuses = ImmutableMap.of(
                "pendingactivation", pendingActivationResumeVisible,
                "assigned", assignedResumeVisible,
                "pending-delete", false);
        for(Map.Entry<String, Boolean> entry: vfModulesStatuses.entrySet()) {
            WebElement vfModule = GeneralUIUtils.getWebElementByClassName("vfModuleTreeNode-" + entry.getKey());
            Assert.assertEquals(!vfModule.findElements(By.className("resume")).isEmpty(), entry.getValue());
        }
    }

    @Before
    public void before() throws Exception {
        User user = usersService.getUser(Constants.Users.USP_VOICE_VIRTUAL_USP);
        relogin(user.credentials);
    }

    @AfterMethod(alwaysRun = true)
    public void finallyClosePopup() {
        // Tries closing left-out popups, if any
        // If none -- catch clause will swallow the exception
        try {
            viewEditPage.clickCloseButton(3);
        } catch (Exception e) {
            // ok, stop
        }
    }
}