aboutsummaryrefslogtreecommitdiffstats
path: root/vid-automation/src/main/java/vid/automation/test/test/NewServiceInstanceTest.java
blob: 173897095955406d477e54818205626c914c915b (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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
package vid.automation.test.test;

import com.google.common.collect.*;
import org.apache.commons.lang3.RandomStringUtils;
import org.onap.simulator.presetGenerator.presets.mso.PresetMSOBaseCreateServiceInstancePost;
import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstanceGen2;
import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet;
import org.openecomp.sdc.ci.tests.datatypes.UserCredentials;
import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.*;
import vid.automation.test.Constants;
import vid.automation.test.Constants.BrowseASDC.NewServicePopup;
import vid.automation.test.infra.*;
import vid.automation.test.model.Service;
import vid.automation.test.model.User;
import vid.automation.test.sections.*;
import vid.automation.test.services.AsyncJobsService;
import vid.automation.test.services.ServicesService;
import vid.automation.test.services.SimulatorApi;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static junit.framework.TestCase.assertNull;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.testng.Assert.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
import static vid.automation.test.infra.Features.FLAG_ASYNC_INSTANTIATION;
import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND;

@FeatureTogglingTest(FLAG_ASYNC_INSTANTIATION)
public class NewServiceInstanceTest extends CreateInstanceDialogBaseTest {

    private ServicesService servicesService = new ServicesService();
    private DrawingBoardPage drawingBoardPage = new DrawingBoardPage();
    List<String> serviceModelLabelList = Arrays.asList("Model version", "Description", "Category", "UUID",
            "Invariant UUID", "Service type", "Service role");
    List<String> mandatoryServiceModelLabelList = Arrays.asList("Model version", "UUID", "Invariant UUID");
    private final String defaultServiceModelForMostTests = "6e59c5de-f052-46fa-aa7e-2fca9d674c44";
    private final VidBasePage vidBasePage = new VidBasePage();

    @BeforeClass
    protected void dropAllAsyncJobs() {
        AsyncJobsService asyncJobsService = new AsyncJobsService();
        asyncJobsService.dropAllAsyncJobs();
    }

    @AfterClass
    protected void muteAllAsyncJobs() {
        AsyncJobsService asyncJobsService = new AsyncJobsService();
        asyncJobsService.muteAllAsyncJobs();
    }

    @BeforeMethod
    protected void refreshPage() {
        GeneralUIUtils.ultimateWait();

        vidBasePage.refreshPage();
    }

    @Override
    protected UserCredentials getUserCredentials() {
        String userName = Constants.Users.USP_VOICE_VIRTUAL_USP;
        User user = usersService.getUser(userName);
        return new UserCredentials(user.credentials.userId, user.credentials.password, userName, "", "");
    }

    @Test
    public void createNewServiceInstance_fullModelData_LeftPaneLabelsCorrect() throws Exception {
        loadMacroServicePopup_noDynamicFields_fullModelDetails_ecompNamingFalse();
        assertServiceModelLabelsCorrect(serviceModelLabelList);
    }

    @Test
    public void createNewServiceInstance_partialModelData_LeftPaneLabelsCorrect() throws Exception {
        loadMacroServicePopup_withDynamicFields_partialModelDetails_ecompNamingTrue();
        assertServiceModelLabelsCorrect(mandatoryServiceModelLabelList);
    }

    /**
     * asserts that the provided labels list is visible and that no other detail item appears in the model details panel.
     */
    protected void assertServiceModelLabelsCorrect(List<String> serviceModelLabelList) throws Exception {
        WebElement modelInformation = getDriver().findElement(By.id("model-information"));
        List<WebElement> modelInformationItems = modelInformation.findElements(By.xpath("./div"));
        assertEquals(modelInformationItems.size(), serviceModelLabelList.size());
        serviceModelLabelList.forEach(label -> {
            WebElement webElement = Get.byTestId("model-item-" + label);
            WebElement itemWarpper = webElement.findElements(By.className("wrapper")).get(0);
            assertEquals(itemWarpper.findElements(By.tagName("label")).get(0).getText(), label, "model details item label is incorrect.");
        });
    }

    @Test
    public void createNewServiceInstance_leftPane_serviceModelDataCorrect() {
        Service service = servicesService.getService(NewServicePopup.SERVICE_UUID);
        String prefix = NewServicePopup.SERVICE_MODEL_DATA_TEST_ID_VALUE_PREFIX;
        loadMacroServicePopup_noDynamicFields_fullModelDetails_ecompNamingFalse();
        setNewInstance_leftPane_assertModelDataCorrect(NewServicePopup.SERVICE_MODEL_FIELD_TO_DATA_TESTS_ID, prefix, service);
    }

    @Test
    public void createNewServiceInstance_macro_validPopupDataAndUI__ecompNamingFalse() {

        ServiceData serviceData = new ServiceData("csar-noDynamicFields-ecompNamingFalse-fullModelDetails-1a80c596.zip",
                "1a80c596-27e5-4ca9-b5bb-e03a7fd4c0fd",
                new ArrayList<>(),
                false, true, true, true,
                "2017-488_ADIOD-vPE 0",
                "2017488_adiodvpe0..2017488AdiodVpe..ADIOD_vRE_BV..module-1", 0, 1,  ImmutableList.of("Bandwidth", "Bandwidth units"));

        String serviceInstanceName = deployServiceInstance(serviceData, false);
        vidBasePage.screenshotDeployDialog(serviceInstanceName);
        deployAndVerifyModuleInPendingTable(serviceInstanceName);
        verifyOpenAuditInfo(serviceInstanceName);
        verifyOpenViewEdit(serviceInstanceName);
        verifyDeleteJob(serviceInstanceName);
        verifyHideJob(serviceInstanceName);
    }

    @Test
    public void createNewServiceInstance_macro_validPopupDataAndUI__ecompNamingServiceFalseVnfTrue_vgNameFalse() {
        ServiceData serviceData = new ServiceData("csar-noDynamicFields-ecompNamingFalse-fullModelDetails-1a80c596.zip",
                "1a80c596-27e5-4ca9-b5bb-e03a7fd4c0fd",
                new ArrayList<>(),
                false, true, false, true,
                "2017-488_ADIOD-vPE 0",
                "2017488_adiodvpe0..2017488AdiodVpe..ADIOD_base_vPE_BV..module-0", 1, 1, new ArrayList<>());

        deployServiceInstance(serviceData);
    }

    @Test
    public void createNewServiceInstance_macro_validPopupDataAndUI__ecompNamingServiceFalseVnfFalse_vgNameFalse() {
        ServiceData serviceData = new ServiceData("csar-noDynamicFields-ecompNamingFalse-fullModelDetails-1a80c596-vnfEcompNamingFalse.zip",
                "4a80c596-27e5-4ca9-b5bb-e03a7fd4c0fd",
                new ArrayList<>(),
                false, false, false, false,
                "2017-488_ADIOD-vPE 0",
                "2017488_adiodvpe0..2017488AdiodVpe..ADIOD_base_vPE_BV..module-0", 1, 1, new ArrayList<>());

        deployServiceInstance(serviceData);
    }

    @Test
    public void createNewServiceInstance_macro_validPopupDataAndUI__ecompNamingServiceFalseVnfFalse_vgNameTrue() {
        ServiceData serviceData = new ServiceData("csar-noDynamicFields-ecompNamingFalse-fullModelDetails-1a80c596-vnfEcompNamingFalse.zip",
                "4a80c596-27e5-4ca9-b5bb-e03a7fd4c0fd",
                new ArrayList<>(),
                false, false, true, false,
                "2017-488_ADIOD-vPE 0",
                "2017488_adiodvpe0..2017488AdiodVpe..ADIOD_vRE_BV..module-1", 0, 1, new ArrayList<>());

        deployServiceInstance(serviceData);
    }

    private void deployServiceInstance(ServiceData serviceData) {
        deployServiceInstance(serviceData, true);
    }

    private String deployServiceInstance(ServiceData serviceData, boolean tryCancelsAndReentries) {
        User user = usersService.getUser(Constants.Users.USP_VOICE_VIRTUAL_USP);

        final String serviceInstanceName = createSriovService(
                user, serviceData.dynamicFields, serviceData.csarName, serviceData.modelUuid,
                serviceData.isGeneratedNaming, serviceData.multiStageDesign,
                tryCancelsAndReentries);

        createVnf(serviceData.vnfData.isGeneratedNaming, serviceData.vnfData.vnfName, serviceInstanceName, tryCancelsAndReentries);

        createVfModule(
                serviceData.vfData.vfName, serviceData.vnfData.isGeneratedNaming,
                serviceData.vfData.vgEnabled, serviceData.vfData.vfMin, serviceData.vfData.vfMax,
                serviceData.vfData.dynamicFields, serviceInstanceName);

        return serviceInstanceName;
    }


    @Test
    public void createNewServiceInstance_macro_validPopupDataAndUI__ecompNamingTrue() {

        List<String> serviceDynamicFields = Arrays.asList("2017488 adiodvpe0 asn:");
        ServiceData serviceData = new ServiceData("csar-withDynamicFields-ecompNamingTrue-partialModelDetails.zip",
                "2f80c596-27e5-4ca9-b5bb-e03a7fd4c0fd",
                serviceDynamicFields,
                true, true, false, false,
                "2017-488_ADIOD-vPE 0",
                "2017488_adiodvpe0..2017488AdiodVpe..ADIOD_vRE_BV..module-1", 0, 1, new ArrayList<>());

        deployServiceInstance(serviceData);

    }

    private void deployAndVerifyModuleInPendingTable(String serviceInstanceName) {
        drawingBoardPage.clickDeployButton();

        boolean simulatorUpdated = false;

        vidBasePage.goToIframe();
        GeneralUIUtils.ultimateWait();
        int[] ids = {1, 1, 2, 3};
        String[] statuses = {"IN_PROGRESS", "COMPLETED", "IN_PROGRESS", "PENDING"};
        for (int i = 0; i < ids.length; i++) {
            String actualInstanceName = getActualInstanceName(serviceInstanceName, ids[i], statuses[i]);

            final Set<String> expectedStatuses = ImmutableSet.of(statuses[i]);
            ServiceStatusChecker serviceStatusChecker = new ServiceStatusChecker(actualInstanceName, expectedStatuses);
            boolean statusIsShown = Wait.waitFor(serviceStatusChecker, null, 20, 2);
            final String assertionMessage = String.format("service %s: none of rowClasses [%s] is in expectedStatuses: [%s]  ",
                    actualInstanceName,
                    String.join(",", serviceStatusChecker.getColumnClassesSet()),
                    String.join(",", expectedStatuses));

            assertTrue(assertionMessage, statusIsShown);

            InstantiationStatusPage.assertInstantiationStatusRow(
                    actualInstanceName, expectedRowFields(actualInstanceName));

            if (!simulatorUpdated) {
                simulatorUpdated = true;
                final String request1 = PresetMSOBaseCreateServiceInstancePost.DEFAULT_REQUEST_ID;
                final String request2 = "ce010256-3fdd-4cb5-aed7-37112a2c6e93";
                SimulatorApi.registerExpectationFromPreset(new PresetMSOCreateServiceInstanceGen2(request2), APPEND);
                SimulatorApi.registerExpectationFromPreset(new PresetMSOOrchestrationRequestGet("IN_PROGRESS", request2), APPEND);
                SimulatorApi.registerExpectationFromPreset(new PresetMSOOrchestrationRequestGet("COMPLETE", request1), APPEND);
            }
        }
        vidBasePage.screenshotDeployDialog(serviceInstanceName);
    }

    private String getActualInstanceName(String serviceInstanceName, Integer i, String status) {
        return "PENDING".equals(status) ? serviceInstanceName : serviceInstanceName + "_00" + i;
    }

    private void verifyOpenViewEdit(String serviceInstanceName) {
        boolean[] openEnabled = {true, false, false};
        String[] statuses = {"COMPLETED", "IN_PROGRESS", "PENDING"};
        ImmutableList.of(1, 2, 3).forEach(i -> {
            String actualInstanceName = getActualInstanceName(serviceInstanceName, i, statuses[i - 1]);
            checkMenuItem(actualInstanceName, Constants.InstantiationStatus.CONTEXT_MENU_HEADER_OPEN_ITEM, openEnabled[i - 1], contextMenuOpen -> {
                Click.byTestId(contextMenuOpen);
                vidBasePage.goOutFromIframe();
                GeneralUIUtils.ultimateWait();

                Wait.byText("View/Edit Service Instance");
                Wait.byText("Add node instance");
                Wait.byText("i'm a port");
                Wait.byText("f8791436-8d55-4fde-b4d5-72dd2cf13cfb");

                vidBasePage.screenshotDeployDialog("view-edit-" + actualInstanceName);
                SideMenu.navigateToMacroInstantiationStatus();
            });
        });
    }


    private void verifyOpenAuditInfo(String serviceInstanceName) {
        boolean auditInfoEnabled = true;
        String[] statuses = {"COMPLETED", "IN_PROGRESS", "PENDING"};
        for (Integer i : ImmutableList.of(1, 2, 3)) {
            String actualInstanceName = getActualInstanceName(serviceInstanceName, i, statuses[i - 1]);
            checkMenuItem(actualInstanceName, Constants.InstantiationStatus.CONTEXT_MENU_HEADER_AUDIT_INFO_ITEM, auditInfoEnabled, contextMenuOpen -> {
                Click.byTestId(contextMenuOpen);
                checkAuditInfoModal(actualInstanceName, i, statuses);
            });
            final WebElement row = InstantiationStatusPage.getInstantiationStatusRow(actualInstanceName);
            row.findElement(By.id(Constants.InstantiationStatus.TD_JOB_STATUS_ICON + "-" + (i - 1))).click();
            checkAuditInfoModal(actualInstanceName, i, statuses);
        }
    }

    private void checkAuditInfoModal(String actualInstanceName, Integer i, String[] statuses) {

        Wait.waitByTestId("vidJobStatus", 10);

        WebElement webElement = Get.byTestId("model-item-value-serviceInstanceName");
        assertEquals(webElement.getText(), actualInstanceName, "Service Instance Name must be equal");

        WebElement vidTableElement = Get.byId("service-instantiation-audit-info-vid");
        assertEquals(3, vidTableElement.findElement(By.tagName("thead")).findElements(By.tagName("th")).size(), "VID table must contain 3 columns");

        List<WebElement> vidStatusesElements = vidTableElement.findElements(By.id("vidJobStatus"));
        List<String> vidStatuses = vidStatusesElements.stream()
                .map(s ->
                        convertUITextCapitalizeAndFormatPipe(s.getText()))
                .collect(Collectors.toList());

        List<String> serviceStatus = Arrays.asList(Arrays.copyOfRange(statuses, i - 1, statuses.length));
        assertThat("statuses for " + actualInstanceName + " must be as expected", vidStatuses, is(Lists.reverse(serviceStatus)));

        String dateString = vidTableElement.findElements(By.id("vidStatusTime")).get(0).getText();
        assertTrue("vid Status Time column must contains valid date in format : MMM dd, yyyy HH:mm", isDateValid(dateString, "MMM dd, yyyy HH:mm"));

        WebElement MSOTableElement = Get.byId("service-instantiation-audit-info-mso");
        assertEquals(4, MSOTableElement.findElement(By.tagName("thead")).findElements(By.tagName("th")).size(), "MSO table must contain 4 columns");

        if (statuses[i - 1].equals("PENDING")) {
            assertEquals(0, MSOTableElement.findElement(By.tagName("tbody")).findElements(By.tagName("tr")).size(), "When status is PENDING MSO table is empty");
        }

        vidBasePage.screenshotDeployDialog("audit-info-" + actualInstanceName);
        Click.byId(Constants.AuditInfoModal.CANCEL_BUTTON);
    }

    private String convertUITextCapitalizeAndFormatPipe(String text) {
        return text.toUpperCase().replace("-", "_");
    }

    private boolean isDateValid(String dateToValidate, String dateFromat) {

        if (dateToValidate == null) {
            return false;
        }
        SimpleDateFormat sdf = new SimpleDateFormat(dateFromat);
        sdf.setLenient(false);
        try {
            //if not valid, it will throw ParseException
            Date date = sdf.parse(dateToValidate);

        } catch (ParseException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    private void verifyDeleteJob(String serviceInstanceName) {
        boolean[] deleteEnabled = {false, false, true};
        String[] statuses = {"COMPLETED", "IN_PROGRESS", "PENDING"};
        verifyDeleteOrHideOperation(serviceInstanceName, Constants.InstantiationStatus.CONTEXT_MENU_DELETE, statuses, deleteEnabled, "deleted");
    }

    private void verifyHideJob(String serviceInstanceName) {
        boolean[] hideEnabled = {true, false};
        String[] statuses = {"COMPLETED", "IN_PROGRESS"};
        verifyDeleteOrHideOperation(serviceInstanceName, Constants.InstantiationStatus.CONTEXT_MENU_HIDE, statuses, hideEnabled, "hidden");
    }

    private void verifyDeleteOrHideOperation(String serviceInstanceName, String contextMenuItem, String[] statuses, boolean[] operationEnabled, String operationName) {
        for (int i = 1; i <= statuses.length; i++) {
            String actualInstanceName = getActualInstanceName(serviceInstanceName, i, statuses[i - 1]);
            checkMenuItem(actualInstanceName, contextMenuItem, operationEnabled[i - 1], contextMenuDelete -> {
                Click.byTestId(contextMenuDelete);
                GeneralUIUtils.ultimateWait();
                assertNull(actualInstanceName + " should be " + operationName,
                        InstantiationStatusPage.getInstantiationStatusRow(actualInstanceName));
            });
        }
        vidBasePage.screenshotDeployDialog(serviceInstanceName);
    }

    private void checkMenuItem(String actualInstanceName, String contextMenuItem, boolean shouldBeEnabled, Consumer<String> doIfEnabled) {
        Wait.waitFor(name -> {
            if (null == InstantiationStatusPage.getInstantiationStatusRow(name)) {
                InstantiationStatusPage.clickRefreshButton();
                return false;
            } else {
                return true;
            }
        }, actualInstanceName, 8, 1);
        final WebElement row = InstantiationStatusPage.getInstantiationStatusRow(actualInstanceName);
        row.findElement(By.className("menu-div")).click();
        String clazz = Get.byXpath("//div[@data-tests-id='" + contextMenuItem + "']/ancestor::li").getAttribute("class");
        assertThat("item " + contextMenuItem + " of " + actualInstanceName +
                " should be " + (shouldBeEnabled ? "enabled" : "disabled"), !clazz.equals("disabled"), is(shouldBeEnabled));
        if (shouldBeEnabled) {
            doIfEnabled.accept(contextMenuItem);
        } else {
            // dismiss menu
            Get.byClass("title").get(0).click();
        }
    }

    private ImmutableMap<String, String> expectedRowFields(String actualInstanceName) {
        return ImmutableMap.<String, String>builder()
                .put("userId", getUserCredentials().getUserId())
                .put("serviceModelName", "action-data")
                .put("serviceInstanceName", actualInstanceName)
                .put("serviceModelVersion", "1.0")
                .put("subscriberName", "USP VOICE")
                .put("serviceType", "VIRTUAL USP")
                .put("regionId", "mtn6")
                .put("tenantName", "AIN Web Tool-15-D-testgamma")
                .put("aicZoneName", "NFTJSSSS-NFT1")
                .put("project", "DFW")
                .put("owningEntityName", "MetroPacketCore")
                .put("pause", "false")
                .build();
    }

    private String createSriovService(User user, List<String> serviceDynamicFields,
                                      String csarName, String modelId, boolean modelWithGeneratedName,
                                      boolean multiStageDesign, boolean tryCancelsAndReentries) {
        BrowseASDCPage browseASDCPage = new BrowseASDCPage();

        // simulate typing with spaces, but expected is without spaces
        String serviceInstanceNameWithSpaces = RandomStringUtils.randomAlphabetic(5) + " instance name";
        String serviceInstanceName = serviceInstanceNameWithSpaces.replace(" ", "");

        List<String> cycles = tryCancelsAndReentries ? ImmutableList.of("WILL_CANCEL", "AFTER_CANCEL") : ImmutableList.of("SINGLE_SHOT");
        cycles.forEach(cycle -> {
            if ("AFTER_CANCEL".equals(cycle)) {
                loadServicePopupOnBrowseASDCPage(modelId);
            } else {
                loadServicePopup(csarName, modelId);
            }

            WebElement instanceName = Get.byId("instance-name");
            if (modelWithGeneratedName) {
                Assert.assertNull(instanceName, "instance name input should be invisible when serviceEcompNaming == true.");
            } else {
                instanceName.sendKeys(serviceInstanceNameWithSpaces);
            }

            //serviceType should be dependent on subscriber selection
            assertElementDisabled("service-type-select");

            GeneralUIUtils.ultimateWait();
            assertDropdownPermittedItemsByLabel(user.subscriberNames, Constants.CreateNewInstance.SUBSCRIBER_NAME_OPTION_CLASS);
            VidBasePage.selectSubscriberById("e433710f-9217-458d-a79d-1c7aff376d89");
            GeneralUIUtils.ultimateWait();

            //lcpRegion should be dependent on serviceType selection
            assertElementDisabled("lcpRegion-select");

            String serviceType = "VIRTUAL USP";
            Wait.waitByClassAndText(Constants.CreateNewInstance.SERVICE_TYPE_OPTION_CLASS, serviceType, 30);
            browseASDCPage.selectServiceTypeByName(serviceType);

            //tenant should be dependent on lcpRegion selection
            assertElementDisabled("tenant-select");

            String lcpRegion = "mtn6";
            Wait.waitByClassAndText("lcpRegionOption", lcpRegion, 30);
            browseASDCPage.selectLcpRegion(lcpRegion);

            browseASDCPage.selectTenant("bae71557c5bb4d5aac6743a4e5f1d054");

            String setButtonTestId = "service-form-set";
            assertSetButtonDisabled(setButtonTestId);

            SelectOption.byTestIdAndVisibleText("MetroPacketCore", (Constants.OwningEntity.OWNING_ENTITY_SELECT_TEST_ID));
            assertSetButtonDisabled(setButtonTestId);

            SelectOption.byTestIdAndVisibleText("DHV", Constants.ViewEdit.PRODUCT_FAMILY_SELECT_TESTS_ID);
            assertSetButtonEnabled(setButtonTestId);

            browseASDCPage.selectProductFamily("e433710f-9217-458d-a79d-1c7aff376d89");

            assertAllIsPermitted(Constants.BrowseASDC.AIC_OPTION_CLASS);
            browseASDCPage.selectAicZone("NFT1");

            SelectOption.byTestIdAndVisibleText("DFW", Constants.OwningEntity.PROJECT_SELECT_TEST_ID);

            assertNotificationAreaVisibilityBehaviour();

            assertPauseOnPausePointsVisibility(multiStageDesign);

            validateDynamicFields(serviceDynamicFields);

            vidBasePage.screenshotDeployDialog("createSriovService-" + serviceInstanceName);

            if ("WILL_CANCEL".equals(cycle)) {
                Click.byTestId(Constants.CANCEL_BUTTON_TEST_ID);
            } else {
                Click.byTestId(setButtonTestId);
            }

            browseASDCPage.goOutFromIframe();

            browseASDCPage.goToIframe();

        });
        return serviceInstanceName;
    }

    private void createVnf(boolean isInstanceNameGenerated, String vnfName, String serviceInstanceName, boolean tryCancelsAndReentries) {
        BrowseASDCPage browseASDCPage = new BrowseASDCPage();
        drawingBoardPage.clickAddButtonByNodeName(vnfName);

        if (isInstanceNameGenerated) {
            WebElement instanceName = Get.byId("instance-name");
            Assert.assertNull(instanceName, "instance name input should be invisible when serviceEcompNaming == true.");
        } else {
            Input.text("VNF instance name", "instanceName");
        }

        //tenant should be dependent on lcpRegion selection
        assertElementDisabled("tenant-select");

        WebElement legacyRegion = Get.byTestId("lcpRegionText");
        Assert.assertNull(legacyRegion, "legacy region shouldn't be visible when lcp region isn't AAIAIC25,rdm3 or rdm5a.");

        browseASDCPage.selectLcpRegion("AAIAIC25");

        legacyRegion = Get.byTestId("lcpRegionText");
        Assert.assertNotNull(legacyRegion, "legacy region should be visible when lcp region is AAIAIC25,rdm3 or rdm5a.");

        browseASDCPage.selectTenant("092eb9e8e4b7412e8787dd091bc58e86");

        String setButtonTestId = "vnf-form-set";
        assertSetButtonDisabled(setButtonTestId);

        browseASDCPage.selectPlatform("platform");

        assertSetButtonEnabled(setButtonTestId);

        browseASDCPage.setLegacyRegion("some legacy region");
        browseASDCPage.selectLineOfBusiness("ECOMP");

        Wait.waitByTestId("model-item-value-subscriberName", 10);
        Assert.assertEquals(Get.byTestId("model-item-value-subscriberName").getText(), "USP VOICE", "Subscriber name should be shown in vf module");
        Assert.assertEquals(Get.byTestId("model-item-value-min"), null, "Min value should not be shown in VNF popup");
        Assert.assertEquals(Get.byTestId("model-item-value-max"), null, "Max value should not be show in VNF popup");
        if (!isInstanceNameGenerated) {
            Assert.assertEquals(Get.byTestId("model-item-value-serviceName").getText(), serviceInstanceName, "Subscriber name should be shown in vf module");
        }

        vidBasePage.screenshotDeployDialog("createVnf-" + serviceInstanceName);
        Click.byTestId(setButtonTestId);

        String nodeToEdit = "69e09f68-8b63-4cc9-b9ff-860960b5db09-2017-488_ADIOD-vPE 0";
        if (tryCancelsAndReentries) {
            hoverAndClickEditButton(nodeToEdit);

            Wait.byText("VIRTUAL USP");
            GeneralUIUtils.ultimateWait();
            Assert.assertEquals(Get.selectedOptionText(Constants.ViewEdit.LCP_REGION_SELECT_TESTS_ID), "AAIAIC25");
            Assert.assertEquals(Get.selectedOptionText(Constants.ViewEdit.TENANT_SELECT_TESTS_ID), "USP-SIP-IC-24335-T-01");
            Assert.assertEquals(Get.selectedOptionText(Constants.ViewEdit.LINE_OF_BUSINESS_SELECT_TESTS_ID), "ECOMP");
            Assert.assertEquals(Get.selectedOptionText(Constants.OwningEntity.PLATFORM_SELECT_TEST_ID), "platform");
            Click.byTestId(Constants.CANCEL_BUTTON_TEST_ID);
        } else {
            toggleItemInTree(nodeToEdit);
        }
    }

    private void toggleItemInTree(String nodeToEdit) {
        Click.byXpath("//tree-root[@data-tests-id='" + Constants.DrawingBoard.AVAILABLE_MODELS_TREE + "']//span[@class='" + Constants.DrawingBoard.TOGGLE_CHILDREN + "']");
    }

    private void hoverAndClickEditButton(String nodeToEdit) {
        String buttonOfEdit = Constants.DrawingBoard.NODE_PREFIX + nodeToEdit + Constants.DrawingBoard.CONTEXT_MENU_BUTTON;
        GeneralUIUtils.hoverOnAreaByTestId(buttonOfEdit);
        Click.byTestId(buttonOfEdit);
        Click.byTestId(Constants.DrawingBoard.CONTEXT_MENU_ITEM);
    }

    private void createVfModule(String vfModuleName, boolean isInstanceNameGenerated, boolean vgEnabled, int vgMin,
                                int vgMax, List<String> vfModuleDynamicFields, String serviceInstanceName) {
        String setButtonTestId = "vnf-form-set";
        BrowseASDCPage browseASDCPage = new BrowseASDCPage();
//        Click.byTestId(Constants.DrawingBoard.NODE_PREFIX + vnfName);
        drawingBoardPage.clickAddButtonByNodeName(vfModuleName);
        if (!isInstanceNameGenerated) {
            Input.text("VF instance name", "instanceName");
        } else {
            Assert.assertNull(Get.byTestId("instanceName"));
            Assert.assertNull(Get.byTestId("volumeGroupName"));

        }
        if (vgEnabled && !isInstanceNameGenerated) {
            browseASDCPage.setInputText("volumeGroupName", "some group name name");
        } else {
            Assert.assertNull(Get.byTestId("volumeGroupName"), "volumeGroupName input should be invisible when vgEnabled == false");
        }
        Wait.waitByTestId("model-item-value-subscriberName", 10);
        Assert.assertEquals(Get.byTestId("model-item-value-subscriberName").getText(), "USP VOICE", "Subscriber name should be shown in vf module");
        Assert.assertEquals(Get.byTestId("model-item-value-min").getText(), Integer.toString(vgMin), "Min should be shown");
        Assert.assertEquals(Get.byTestId("model-item-value-max").getText(), Integer.toString(vgMax), "Max should be shown");
        if (!isInstanceNameGenerated) {
            Wait.byText(serviceInstanceName);
            Assert.assertEquals(Get.byTestId("model-item-value-serviceName").getText(), serviceInstanceName, "Service name should be shown in vf module");
        }
        validateDynamicFields(vfModuleDynamicFields);

        browseASDCPage.screenshotDeployDialog("createVfModule-" + serviceInstanceName);
        Click.byTestId(setButtonTestId);
    }

    private void assertPauseOnPausePointsVisibility(boolean visibility) {
        WebElement pauseElem = Get.byId("pause");
        final String assertionMessage = "pause on pause points visibility should be " + visibility;
        if (visibility) {
            Assert.assertNotNull(pauseElem, assertionMessage);
        } else {
            Assert.assertNull(pauseElem, assertionMessage);
        }
    }

    private void assertNotificationAreaVisibilityBehaviour() {
        WebElement webElement = Get.byId("notification-area");
        Assert.assertNull(webElement, "notification area should be invisible if only 1 qty.");

        SelectOption.byIdAndVisibleText("quantity-select", "3");

        webElement = Get.byId("notification-area");
        Assert.assertNotNull(webElement, "notification area should be visible if more then 1 qty.");
    }

    /**
     * following are two popup service models that represent two opposite/extreme states of the popup.
     * they should be enough to test all the possible popup states.
     */
    private void loadMacroServicePopup_withDynamicFields_partialModelDetails_ecompNamingTrue() {
        loadServicePopup("csar-withDynamicFields-ecompNamingTrue-partialModelDetails.zip", "2f80c596-27e5-4ca9-b5bb-e03a7fd4c0fd");
    }

    private void loadMacroServicePopup_noDynamicFields_fullModelDetails_ecompNamingFalse() {
        loadServicePopup("csar-noDynamicFields-ecompNamingFalse-fullModelDetails-1a80c596.zip", "1a80c596-27e5-4ca9-b5bb-e03a7fd4c0fd");
    }

    @DataProvider
    private Object[][] createSriovService(
    ) {
        List<String> dynamicFields = Arrays.asList(
                "2017488 adiodvpe0 VNF config template version:",
                "Adiodvpe0 bandwidth units:",
                "Adiodvpe0 bandwidth:",
                "2017488 adiodvpe0 aic clli:",
                "2017488 adiodvpe0 asn:",
                "2017488 adiodvpe0 VNF instance name");
        ServiceData withEcompNaming = new ServiceData("csar-withDynamicFields-ecompNamingTrue-partialModelDetails.zip",
                "2f80c596-27e5-4ca9-b5bb-e03a7fd4c0fd",
                dynamicFields,
                true, true, true, false,
                "2017-488_ADIOD-vPE 0",
                "2017488_adiodvpe0..2017488AdiodVpe..ADIOD_vRE_BV..module-1", 0, 1, new ArrayList<>());
        return new Object[][]{{withEcompNaming}};
    }


    private class ServiceData {

        public ServiceData(String csarName, String modelUuid, List<String> dynamicFields, boolean isServiceGeneratedNaming, boolean isVnfGeneratedNaming, boolean isVgEnabled, boolean multiStageDesign, String vnfName, String vfName, int vfMin, int vfMax, List<String> vfModuleDynamicFields) {
            this.csarName = csarName;
            this.modelUuid = modelUuid;
            this.dynamicFields = dynamicFields;
            this.isGeneratedNaming = isServiceGeneratedNaming;
            this.multiStageDesign = multiStageDesign;
            this.vnfData = new VnfData(vnfName, isVnfGeneratedNaming);
            this.vfData = new VfData(vfName, isVgEnabled, vfMin, vfMax, vfModuleDynamicFields);
        }

        public String csarName;
        public String modelUuid;
        public List<String> dynamicFields;
        public boolean isGeneratedNaming;
        public boolean multiStageDesign;
        public VnfData vnfData;
        public VfData vfData;

    }

    private class VnfData {

        public VnfData(String vnfName, boolean isGeneratedNaming) {
            this.vnfName = vnfName;
            this.isGeneratedNaming = isGeneratedNaming;
        }

        public String vnfName;
        public boolean isGeneratedNaming;
    }


    private class VfData {
        public VfData(String vfName, boolean vgEnabled, int vfMin, int vfMax, List<String> dynamicFields) {
            this.vfName = vfName;
            this.vgEnabled = vgEnabled;
            this.vfMin = vfMin;
            this.vfMax = vfMax;
            this.dynamicFields = dynamicFields;
        }

        public int vfMin;

        public int vfMax;

        public String vfName;

        public boolean vgEnabled;

        public List<String> dynamicFields;

    }


    private class ServiceStatusChecker implements Predicate<Boolean> {
        private String actualInstanceName;
        private Set<String> expectedStatuses;
        private Set<String> columnClassesSet;

        public ServiceStatusChecker(String actualInstanceName, Set<String> expectedStatuses) {
            this.actualInstanceName = actualInstanceName;
            this.expectedStatuses = expectedStatuses;
        }

        @Override
        public boolean test(Boolean noMeaning) {
            InstantiationStatusPage.clickRefreshButton();
            final WebElement row = InstantiationStatusPage.getInstantiationStatusRow(actualInstanceName);
            if (row == null) {
                System.err.println("**********************" + actualInstanceName + "************************************************");
                columnClassesSet = Collections.singleton(actualInstanceName + " NOT FOUND");
                return false; // treat missing row as if test condition not fulfilled
            } else {
                columnClassesSet = new HashSet<>(Arrays.asList(
                        row.findElements(By.xpath(".//*[@id='" + "jobStatus" + "']")).get(0).getAttribute("class").split(" ")));
                return !(Sets.intersection(expectedStatuses, columnClassesSet).isEmpty());
            }
        }

        public Set<String> getColumnClassesSet() {
            return columnClassesSet;
        }
    }
}