aboutsummaryrefslogtreecommitdiffstats
path: root/vid-automation/src/main/java/vid/automation/test/test/NewServiceInstanceTest.java
blob: 42749c15f49b757cd232b37e566edf3b8f76166e (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
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
package vid.automation.test.test;

import static junit.framework.TestCase.assertNull;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetCloudOwnersByCloudRegionId.PRESET_SOME_LEGACY_REGION_TO_ATT_AIC;
import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet.COMPLETE;
import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet.DEFAULT_SERVICE_INSTANCE_ID;
import static org.testng.Assert.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
import static vid.automation.test.infra.Features.FLAG_1902_VNF_GROUPING;
import static vid.automation.test.infra.Features.FLAG_5G_IN_NEW_INSTANTIATION_UI;
import static vid.automation.test.infra.Features.FLAG_ASYNC_INSTANTIATION;
import static vid.automation.test.infra.ModelInfo.PASQUALEVmxVpeBvService488Annotations;
import static vid.automation.test.infra.ModelInfo.aLaCarteNetworkProvider5G;
import static vid.automation.test.infra.ModelInfo.aLaCarteVnfGroupingService;
import static vid.automation.test.infra.ModelInfo.macroSriovNoDynamicFieldsEcompNamingFalseFullModelDetails;
import static vid.automation.test.infra.ModelInfo.macroSriovNoDynamicFieldsEcompNamingFalseFullModelDetailsVnfEcompNamingFalse;
import static vid.automation.test.infra.ModelInfo.macroSriovWithDynamicFieldsEcompNamingFalsePartialModelDetailsVnfEcompNamingFalse;
import static vid.automation.test.infra.ModelInfo.macroSriovWithDynamicFieldsEcompNamingTruePartialModelDetails;
import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND;
import static vid.automation.test.services.SimulatorApi.registerExpectationFromPreset;
import static vid.automation.test.services.SimulatorApi.registerExpectationFromPresets;
import static vid.automation.test.test.ALaCarteflowTest.AIC;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hamcrest.Matchers;
import org.onap.sdc.ci.tests.datatypes.UserCredentials;
import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetCloudOwnersByCloudRegionId;
import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetTenants;
import org.onap.simulator.presetGenerator.presets.aai.PresetAAIPostNamedQueryForViewEdit;
import org.onap.simulator.presetGenerator.presets.mso.PresetMSOBaseCreateInstancePost;
import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateNetworkALaCarte5G;
import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstanceAlacarte5GServiceWithNetwork;
import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstanceGen2WithNamesAlacarteGroupingService;
import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstanceGen2WithNamesEcompNamingFalse;
import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet;
import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestsGet5GServiceInstanceAndNetwork;
import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestsGet5GServiceInstanceAndNetwork.ResponseDetails;
import org.onap.simulator.presetGenerator.presets.mso.PresetMSOServiceInstanceGen2WithNames.Keys;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.RemoteWebElement;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import vid.automation.test.Constants;
import vid.automation.test.Constants.BrowseASDC.NewServicePopup;
import vid.automation.test.infra.Click;
import vid.automation.test.infra.FeatureTogglingTest;
import vid.automation.test.infra.Features;
import vid.automation.test.infra.Get;
import vid.automation.test.infra.Input;
import vid.automation.test.infra.ModelInfo;
import vid.automation.test.infra.SelectOption;
import vid.automation.test.infra.Wait;
import vid.automation.test.model.Service;
import vid.automation.test.model.User;
import vid.automation.test.sections.BrowseASDCPage;
import vid.automation.test.sections.DrawingBoardPage;
import vid.automation.test.sections.InstantiationStatusPage;
import vid.automation.test.sections.SideMenu;
import vid.automation.test.sections.VidBasePage;
import vid.automation.test.services.AsyncJobsService;
import vid.automation.test.services.ServicesService;
import vid.automation.test.services.SimulatorApi;
import vid.automation.test.utils.ReadFile;

@FeatureTogglingTest(FLAG_ASYNC_INSTANTIATION)
public class NewServiceInstanceTest extends CreateInstanceDialogBaseTest {

    private static final String COMPLETED = "COMPLETED";
    private static final String IN_PROGRESS = "IN_PROGRESS";
    private static final String PENDING = "PENDING";
    private final String vfModule0Name = "2017488_PASQUALEvpe0..2017488PASQUALEVpe..PASQUALE_base_vPE_BV..module-0";
    private final String vfModule0UUID = "f8360508-3f17-4414-a2ed-6bc71161e8db";
    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 VidBasePage vidBasePage = new VidBasePage();
    public static final String VNF_SET_BUTTON_TEST_ID = "form-set";
    private static final Logger logger = LogManager.getLogger(NewServiceInstanceTest.class);

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

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

    @BeforeMethod
    protected void goToWelcome() {
        SideMenu.navigateToWelcomePage();
    }

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

    @Test
    public void createNewServiceInstance_fullModelData_LeftPaneLabelsCorrect() throws Exception {
        prepareServicePreset(macroSriovNoDynamicFieldsEcompNamingFalseFullModelDetails, false);
        loadServicePopup(macroSriovNoDynamicFieldsEcompNamingFalseFullModelDetails);
        assertServiceModelLabelsCorrect(serviceModelLabelList);
    }

    @Test
    public void createNewServiceInstance_partialModelData_LeftPaneLabelsCorrect() throws Exception {
        prepareServicePreset(macroSriovWithDynamicFieldsEcompNamingTruePartialModelDetails, false);
        loadServicePopup(macroSriovWithDynamicFieldsEcompNamingTruePartialModelDetails);
        assertServiceModelLabelsCorrect(mandatoryServiceModelLabelList);
    }

    @Test
    public void createNewServiceInstance_setFieldValue_resetDependenciesListsAndValues() {
        resetGetTenantsCache();
        try {
            BrowseASDCPage browseASDCPage = new BrowseASDCPage();
            prepareServicePreset(macroSriovNoDynamicFieldsEcompNamingFalseFullModelDetails, false);
            SimulatorApi.registerExpectation(Constants.RegisterToSimulator.CreateNewServiceInstance.GET_SUBSCRIBERS_FOR_CUSTOMER_CAR_2020_ER, SimulatorApi.RegistrationStrategy.APPEND);
            registerExpectationFromPreset(
                    new PresetAAIGetTenants(
                            "CAR_2020_ER",
                            "MSO-dev-service-type",
                            "registration_to_simulator/create_new_instance/aai_get_tenants_for_customer_CAR_2020_ER.json"),
                    SimulatorApi.RegistrationStrategy.APPEND);

            loadServicePopup(macroSriovNoDynamicFieldsEcompNamingFalseFullModelDetails);
            Wait.waitByClassAndText(Constants.CreateNewInstance.SUBSCRIBER_NAME_OPTION_CLASS, "SILVIA ROBBINS", 30);
            VidBasePage.selectSubscriberById("e433710f-9217-458d-a79d-1c7aff376d89");
            GeneralUIUtils.ultimateWait();
            String serviceType = "TYLER SILVIA";
            Wait.waitByClassAndText(Constants.CreateNewInstance.SERVICE_TYPE_OPTION_CLASS, serviceType, 30);
            browseASDCPage.selectServiceTypeByName(serviceType);
            String lcpRegion = "hvf6";
            Wait.waitByClassAndText("lcpRegionOption", lcpRegion, 30);
            viewEditPage.selectLcpRegion(lcpRegion, AIC);
            browseASDCPage.selectTenant("bae71557c5bb4d5aac6743a4e5f1d054");

            VidBasePage.selectSubscriberById("CAR_2020_ER");
            assertElementDisabled("lcpRegion-select");
            serviceType = "MSO-dev-service-type";
            Wait.waitByClassAndText(Constants.CreateNewInstance.SERVICE_TYPE_OPTION_CLASS, serviceType, 30);
            browseASDCPage.selectServiceTypeByName(serviceType);
            lcpRegion = "CAR_2020_ER";
            Wait.waitByClassAndText("lcpRegionOption", lcpRegion, 30);
            viewEditPage.selectLcpRegion(lcpRegion, AIC);
            browseASDCPage.selectTenant("092eb9e8e4b7412e8787dd091bc58e66");
        } finally {
            resetGetTenantsCache();
        }
    }

    /**
     * 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 genericPopup = getDriver().findElement(By.tagName("generic-form-popup"));
        WebElement modelInformation = genericPopup.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(macroSriovNoDynamicFieldsEcompNamingFalseFullModelDetails.modelVersionId);
        String prefix = NewServicePopup.SERVICE_MODEL_DATA_TEST_ID_VALUE_PREFIX;
        prepareServicePreset(macroSriovNoDynamicFieldsEcompNamingFalseFullModelDetails, false);
        loadServicePopup(macroSriovNoDynamicFieldsEcompNamingFalseFullModelDetails);
        logger.info("Expected service model properties: "+service.toString());
        assertModelDataCorrect(NewServicePopup.SERVICE_MODEL_FIELD_TO_DATA_TESTS_ID, prefix, service);
    }

    @Test
    public void createNewServiceInstance_macro_validPopupDataAndUI__ecompNamingFalse() {

        ServiceData serviceData = new ServiceData(
                macroSriovNoDynamicFieldsEcompNamingFalseFullModelDetails.modelVersionId,
                new ArrayList<>(),
                false, true, true, true,
                "2017-488_PASQUALE-vPE 0",
                "2017488_PASQUALEvpe0..2017488PASQUALEVpe..PASQUALE_vRE_BV..module-1", 0, 1, new ArrayList<>(), "25284168-24bb-4698-8cb4-3f509146eca5");

        prepareServicePreset(macroSriovNoDynamicFieldsEcompNamingFalseFullModelDetails, false);

        final String serviceInstanceName = createSriovService(serviceData, true);
        createVnf(serviceData, true, true, serviceInstanceName);

        createVfModule(serviceData, serviceInstanceName, false, false);

    }

    @Test(groups = "underDevelopment")
    public void createNewServiceInstance_macro_validPopupDataAndUI__dynamicFieldsEcompNamingFalse_DEV() {
        /*
        Upon failure in test dynamicFieldsEcompNamingFalse_FLESH(), exception will provide
        the needed data for this DEV method:

          1. "Current step" when the failure occurred
          2. "Random alphabetic" that was randomized while test
          3. "Starting reduxState" that was on the step that failed.

        These data can be used for, accordingly, 1. startInStep param; 2, randomAlphabetic
        param; 3. reduxForStep param.
         */

        // It should be easier to put `reduxForStep` in this file, to avoid Java's code-clutter and json escaping.
        final String reduxForStep = ReadFile.loadResourceAsString(
                "NewServiceInstanceTest/createNewServiceInstance_macro_validPopupDataAndUI__dynamicFieldsEcompNamingFalse.json");

        createNewServiceInstance_macro_validPopupDataAndUI__dynamicFieldsEcompNamingFalse_FLESH("DEV", 5, reduxForStep, "mCaNk");
    }

    @Test
    public void createNewServiceInstance_macro_validPopupDataAndUI__dynamicFieldsEcompNamingFalse() {
        createNewServiceInstance_macro_validPopupDataAndUI__dynamicFieldsEcompNamingFalse_FLESH("RUNTIME", 0, null, randomAlphabetic(5));
    }

    private void createNewServiceInstance_macro_validPopupDataAndUI__dynamicFieldsEcompNamingFalse_FLESH(String mode, int startInStep, String reduxForStep, String randomAlphabetic) {

        MutableInt i = new MutableInt();
        Map<String, String> reduxStates = new HashMap<>();

        ServiceData serviceData = new ServiceData(
                macroSriovWithDynamicFieldsEcompNamingFalsePartialModelDetailsVnfEcompNamingFalse.modelVersionId,
                Collections.singletonList("2017488 PASQUALEvpe0 asn:"),
                false, false, true, false,
                "2017-488_PASQUALE-vPE 0",
                "2017488_PASQUALEvpe0..2017488PASQUALEVpe..PASQUALE_vRE_BV..module-1", 0, 1, ImmutableList.of("Bandwidth", "Bandwidth units"),
                "25284168-24bb-4698-8cb4-3f509146eca5");

        // this is the instance-name that createSriovService is going to use
        String serviceInstanceName = randomAlphabetic + "instancename";

        doReduxStep(reduxStates, randomAlphabetic, startInStep, reduxForStep, i, mode, () -> {
            prepareServicePreset(macroSriovWithDynamicFieldsEcompNamingFalsePartialModelDetailsVnfEcompNamingFalse,
                    false);
            createSriovService(serviceData, false, randomAlphabetic);
        });

        doReduxStep(reduxStates, randomAlphabetic, startInStep, reduxForStep, i, mode, () ->
                createVnf(serviceData, false, true, serviceInstanceName)
        );

        final String vnfInstanceName2 = randomAlphabetic + "instanceName";
        final String vnfName2 = "2017-388_PASQUALE-vPE";

        doReduxStep(reduxStates, randomAlphabetic, startInStep, reduxForStep, i, mode, () ->
                createVnf(new VnfData(vnfName2 + " 0", "afacccf6-397d-45d6-b5ae-94c39734b168", vnfInstanceName2, false),
                        false, Features.FLAG_DEFAULT_VNF.isActive(), serviceInstanceName)
        );

        doReduxStep(reduxStates, randomAlphabetic, startInStep, reduxForStep, i, mode, () ->
                createVfModule(serviceData, serviceInstanceName, false, true)
        );

        doReduxStep(reduxStates, randomAlphabetic, startInStep, reduxForStep, i, mode, () -> {

            editVfModuleAndJustSetName(vfModule0Name, vfModule0UUID);
            if (Features.FLAG_DUPLICATE_VNF.isActive()) {
                duplicateVnf(serviceData.vnfData, 2);
            }
            vidBasePage.screenshotDeployDialog(serviceInstanceName);
        });

        doReduxStep(reduxStates, randomAlphabetic, startInStep, reduxForStep, i, mode, () -> {
            prepareServicePreset(macroSriovWithDynamicFieldsEcompNamingFalsePartialModelDetailsVnfEcompNamingFalse,
                    true);

            final String vfModuleName1 = "2017488PASQUALEVpe..PASQUALE_base_vPE_BV..module-0";
            final String vfModuleName2 = "2017488PASQUALEVpe..PASQUALE_vRE_BV..module-1";
            final String request1 = PresetMSOBaseCreateInstancePost.DEFAULT_REQUEST_ID;
            final String request2 = "ce010256-3fdd-4cb5-aed7-37112a2c6e93";
            final ImmutableMap<Keys, String> vars = ImmutableMap.<Keys, String>builder()
                    .put(Keys.SERVICE_NAME, serviceInstanceName)
                    .put(Keys.VNF_NAME, cleanSeparators("2017-488_PASQUALE-vPE", serviceData.vnfData.vnfInstanceName))
                    .put(Keys.VFM_NAME1, cleanSeparators(vfModuleName1 , "VF instance name ZERO"))
                    .put(Keys.VFM_NAME2, cleanSeparators(vfModuleName2 , "VF instance name"))
                    .put(Keys.VG_NAME, cleanSeparators(vfModuleName2 , "VF instance name") + "_vol_abc")
                    .put(Keys.VNF_NAME2, cleanSeparators(vnfName2, vnfInstanceName2))
                    .build();
            registerExpectationFromPresets(ImmutableList.of(
                    // although "some legacy region" is provided for vnf, Service's region "hvf6" overrides it
                    PresetAAIGetCloudOwnersByCloudRegionId.PRESET_MTN6_TO_ATT_AIC,
                    new PresetMSOCreateServiceInstanceGen2WithNamesEcompNamingFalse(vars, 0, request1),
                    new PresetMSOCreateServiceInstanceGen2WithNamesEcompNamingFalse(vars, 1, request2)
            ), SimulatorApi.RegistrationStrategy.APPEND);

            deployAndVerifyModuleInPendingTableMacro(serviceInstanceName, request1, request2);
            verifyOpenAuditInfo(serviceInstanceName);
            verifyOpenViewEdit(serviceInstanceName);
            verifyDeleteJob(serviceInstanceName);
            verifyHideJob(serviceInstanceName);
        });
    }

    @Test
    @FeatureTogglingTest(FLAG_1902_VNF_GROUPING)
    public void createNewServiceInstance_aLaCarte_VnfGrouping() {

        String randomAlphabetic = randomAlphabetic(5);

        ServiceData serviceData = new ServiceData(
                aLaCarteVnfGroupingService.modelVersionId,
                ImmutableList.of(),
                false, false, true, false,
                null, null, 0, 1, ImmutableList.of(), null);
        prepareServicePreset(aLaCarteVnfGroupingService, false);

        createALaCarteService(serviceData, randomAlphabetic);

        // this is the instance-name that createALaCarteService is using
        String serviceInstanceName = randomAlphabetic + "instancename";

        final String requestId = PresetMSOBaseCreateInstancePost.DEFAULT_REQUEST_ID;
        final String serviceInstanceId = "d2391436-8d55-4fde-b4d5-72dd2cf13cgh";
        final ImmutableMap<Keys, String> names = ImmutableMap.<Keys, String>builder()
                .put(Keys.SERVICE_NAME, serviceInstanceName)
                .build();
        SimulatorApi.registerExpectationFromPresets(ImmutableList.of(
                new PresetMSOCreateServiceInstanceGen2WithNamesAlacarteGroupingService(names, 0, requestId, serviceInstanceId, "us16807000"),
                new PresetAAIPostNamedQueryForViewEdit(serviceInstanceId, serviceInstanceName, false, false)
        ), SimulatorApi.RegistrationStrategy.APPEND);

        deploy();
        verifyModuleInPendingTable(serviceInstanceName, requestId, null, ImmutableSet.of(IN_PROGRESS), false, false);
        verifyModuleInPendingTable(serviceInstanceName, requestId, null, ImmutableSet.of(COMPLETED), false, true);
        InstantiationStatusPage.verifyOpenNewViewEdit(serviceInstanceName, serviceInstanceId, aLaCarteVnfGroupingService.modelVersionId, "TYLER SILVIA", "e433710f-9217-458d-a79d-1c7aff376d89", "EDIT");
    }

    public interface Invoker{
        void invoke();
    }

    private void doReduxStep(Map<String, String> reduxStates, String randomAlphabetic, int startInStep, String reduxForStep, MutableInt currentStep, String mode, Invoker todo) {
        try {
            switch (mode) {
                case "DEV":
                    if (currentStep.getValue() < startInStep) {
                        // skip up to startInStep
                        return;
                    } else if (currentStep.getValue() == startInStep) {

                        setReduxState(reduxForStep);

                        vidBasePage.navigateTo("serviceModels.htm#/servicePlanning?serviceModelId=6b528779-44a3-4472-bdff-9cd15ec93450");
                        vidBasePage.goToIframe();
                    }

                    reduxStates.put(String.valueOf(currentStep), getReduxState());
                    break;

                case "RUNTIME":
                default:
                    // log current redux state, before invocation
                    reduxStates.put(String.valueOf(currentStep), getReduxState());
                    logger.info("reduxGator runtime reduxState for step {}:\n{}", currentStep, getReduxState());
                    break;
            }

            try {
                todo.invoke();
            } catch (AssertionError | Exception e) {
                throw new AssertionError(String.join("\n",
                        "Current step: " + currentStep,
                        "Random alphabetic: " + randomAlphabetic,
                        "Starting reduxState: " + reduxStates.get(String.valueOf(currentStep)),
                        "Current reduxState:  " + getReduxState()
                ), e);
            }
        } finally {
            logger.info("Cumulative reduxState: {}", reduxStates);
            currentStep.increment();
        }
    }

    private void duplicateVnf(VnfData vnfData, int count) {
        hoverAndClickDuplicateButton(extractNodeToEdit(vnfData));
        vidBasePage.screenshotDeployDialog("duplicateVnf-" + vnfData.vnfName);
        List<WebElement> options = ((RemoteWebElement)Get.byId("duplicate-select")).findElementsByTagName("option");
        assertThat(options.stream().map(x -> x.getText()).collect(Collectors.toList()), Matchers.contains("1","2"));
        SelectOption.byIdAndVisibleText("duplicate-select", String.valueOf(count));
        Click.byClassAndVisibleText("sdc-button__primary", "DUPLICATE");
    }

    private String cleanSeparators(String... s) {
        return String.join("", s).replace(" ", "");
    }

    private void editVfModuleAndJustSetName(String vfModuleName, String vfModuleUUID) {
        if (Features.FLAG_SETTING_DEFAULTS_IN_DRAWING_BOARD.isActive()) {
            hoverAndClickEditButton(vfModuleUUID + "-" + vfModuleName);
        } else {
            drawingBoardPage.clickAddButtonByNodeName(vfModuleName);
        }
        Input.text("VF instance name ZERO", "instanceName");
        Click.byTestId("form-set");
    }

    @Test
    public void createNewServiceInstance_macro_validPopupDataAndUI__ecompNamingServiceFalseVnfTrue_vgNameFalse() {
        ServiceData serviceData = new ServiceData(
                macroSriovNoDynamicFieldsEcompNamingFalseFullModelDetails.modelVersionId,
                new ArrayList<>(),
                false, true, false, true,
                "2017-488_PASQUALE-vPE 0",
                vfModule0Name, 1, 1, new ArrayList<>(), vfModule0UUID);

        prepareServicePreset(macroSriovNoDynamicFieldsEcompNamingFalseFullModelDetails, false);

        final String serviceInstanceName = createSriovService(serviceData, true);
        createVnf(serviceData, true, true, serviceInstanceName);
        createVfModule(serviceData, serviceInstanceName, true, false);

    }

    @Test
    public void createNewServiceInstance_macro_validPopupDataAndUI__ecompNamingServiceFalseVnfFalse_vgNameFalse() {
        ServiceData serviceData = new ServiceData(
                macroSriovNoDynamicFieldsEcompNamingFalseFullModelDetailsVnfEcompNamingFalse.modelVersionId,
                new ArrayList<>(),
                false, false, false, false,
                "2017-488_PASQUALE-vPE 0",
                vfModule0Name, 1, 1, new ArrayList<>(), vfModule0UUID);

        prepareServicePreset(macroSriovNoDynamicFieldsEcompNamingFalseFullModelDetailsVnfEcompNamingFalse, false);

        final String serviceInstanceName = createSriovService(serviceData, true);
        createVnf(serviceData, true, true, serviceInstanceName);
        createVfModule(serviceData, serviceInstanceName, true, false);

    }

    @Test
    public void createNewServiceInstance_macro_validPopupDataAndUI__ecompNamingServiceFalseVnfFalse_vgNameTrue() throws Exception {
        ServiceData serviceData = new ServiceData(
                macroSriovNoDynamicFieldsEcompNamingFalseFullModelDetailsVnfEcompNamingFalse.modelVersionId,
                new ArrayList<>(),
                false, false, true, false,
                "2017-488_PASQUALE-vPE 0",
                "2017488_PASQUALEvpe0..2017488PASQUALEVpe..PASQUALE_vRE_BV..module-1", 0, 1, new ArrayList<>(), "25284168-24bb-4698-8cb4-3f509146eca5");

        prepareServicePreset(macroSriovNoDynamicFieldsEcompNamingFalseFullModelDetailsVnfEcompNamingFalse, false);

        final String serviceInstanceName = createSriovService(serviceData, true);
        createVnf(serviceData, true, true, serviceInstanceName);
        clickRemoveVfModule(vfModule0UUID, vfModule0Name);
        createVfModule(serviceData, serviceInstanceName, false, true);

    }


    @Test
    @FeatureTogglingTest(FLAG_5G_IN_NEW_INSTANTIATION_UI)
    public void createNewServiceInstance_aLaCarte_validPopupDataAndUI() {
        String serviceInstanceName = "NcService"+randomAlphabetic(5);
        String networkInstanceName= "NcNetowrk"+randomAlphabetic(5);
        String defactoNetworkInstanceName = "ExtVL"+networkInstanceName;
        BrowseASDCPage browseASDCPage = new BrowseASDCPage();
        prepareServicePreset(aLaCarteNetworkProvider5G, true);
        String serviceRequestId = UUID.randomUUID().toString();
        String networkRequestId = UUID.randomUUID().toString();
        String requestorID = getUserCredentials().getUserId();
        registerExpectationFromPresets(
                ImmutableList.of(
                    new PresetMSOCreateServiceInstanceAlacarte5GServiceWithNetwork(
                        ImmutableMap.of(Keys.SERVICE_NAME, serviceInstanceName),
                        serviceRequestId,
                            requestorID),
                    new PresetMSOOrchestrationRequestGet(COMPLETE, serviceRequestId),
                    PRESET_SOME_LEGACY_REGION_TO_ATT_AIC,
                    new PresetMSOCreateNetworkALaCarte5G(networkRequestId, DEFAULT_SERVICE_INSTANCE_ID, defactoNetworkInstanceName, requestorID),
                    new PresetMSOOrchestrationRequestGet(COMPLETE, networkRequestId),
                    new PresetMSOOrchestrationRequestsGet5GServiceInstanceAndNetwork(
                            new ResponseDetails(serviceInstanceName, serviceRequestId, COMPLETE, "service"),
                            new ResponseDetails(defactoNetworkInstanceName, networkRequestId, COMPLETE, "network"),
                            DEFAULT_SERVICE_INSTANCE_ID)
                ),
            APPEND
        );
        loadServicePopup(aLaCarteNetworkProvider5G.modelVersionId);
        WebElement instanceNameInput = Get.byId("instanceName");
        instanceNameInput.sendKeys(serviceInstanceName);
        VidBasePage.selectSubscriberById("e433710f-9217-458d-a79d-1c7aff376d89");
        String serviceType = "TYLER SILVIA";
        Wait.waitByClassAndText(Constants.CreateNewInstance.SERVICE_TYPE_OPTION_CLASS, serviceType, 30);
        browseASDCPage.selectServiceTypeByName(serviceType);
        SelectOption.byTestIdAndVisibleText("WayneHolland", (Constants.OwningEntity.OWNING_ENTITY_SELECT_TEST_ID));
        SelectOption.byTestIdAndVisibleText("WATKINS", Constants.OwningEntity.PROJECT_SELECT_TEST_ID);
        Click.byTestId("form-set");
        VidBasePage.goOutFromIframe();
        browseASDCPage.goToIframe();
        VnfData networkData = new VnfData("SR-IOV Provider-1", "840ffc47-e4cf-46de-8e23-525fd8c6fdc3", defactoNetworkInstanceName, false);
        createNetwork(networkData, false, false, serviceInstanceName);
        drawingBoardPage.clickDeployButton();

        VidBasePage.goOutFromIframe();
        GeneralUIUtils.ultimateWait();
        vidBasePage.goToIframe();
        GeneralUIUtils.ultimateWait();

        DrawingBoardPage.ServiceStatusChecker serviceStatusChecker = new DrawingBoardPage.ServiceStatusChecker(serviceInstanceName, Collections.singleton(COMPLETED));
        boolean statusIsShown = Wait.waitFor(serviceStatusChecker, null, 20, 2);
        assertTrue("service "+serviceInstanceName+" wasnt completed after in time", statusIsShown);

        VidBasePage.goOutFromIframe();
    }

    @Test
    public void createNewServiceInstance_macro_validPopupDataAndUI() {

        List<String> serviceDynamicFields = Arrays.asList("2017488 PASQUALEvpe0 asn:");
        ServiceData serviceData = new ServiceData(
                macroSriovWithDynamicFieldsEcompNamingTruePartialModelDetails.modelVersionId,
                serviceDynamicFields,
                true, true, true, false,
                "2017-488_PASQUALE-vPE 0",
                "2017488_PASQUALEvpe0..2017488PASQUALEVpe..PASQUALE_vRE_BV..module-1", 0, 1, new ArrayList<>(), "25284168-24bb-4698-8cb4-3f509146eca5");

        prepareServicePreset(macroSriovWithDynamicFieldsEcompNamingTruePartialModelDetails, false);

        final String serviceInstanceName = createSriovService(serviceData, true);
        createVnf(serviceData, true, true, serviceInstanceName);
        clickRemoveVfModule(vfModule0UUID, vfModule0Name);
        createVfModule(serviceData, serviceInstanceName, false, false);

    }

    private void deployAndVerifyModuleInPendingTableMacro(String serviceInstanceName, String requestId1, String requestId2) {
        deploy();

        boolean simulatorUpdated = false;

        int[] ids = {0, 0, 1, 2};
        String[] statuses = {IN_PROGRESS, COMPLETED, IN_PROGRESS, PENDING};
        for (int i = 0; i < ids.length; i++) {
            String actualInstanceName = getActualInstanceName(serviceInstanceName, ids[i], statuses[i]);
            verifyModuleInPendingTable(actualInstanceName, requestId1, requestId2, ImmutableSet.of(statuses[i]), true, simulatorUpdated);
            simulatorUpdated = true;
        }
        vidBasePage.screenshotDeployDialog(serviceInstanceName);
    }

    private void deploy() {
        try {
            logger.info("Redux state before deploy:");
            logger.info(getReduxState());
        }
        catch (Exception e) {
            //do nothing just logging
        }
        drawingBoardPage.clickDeployButton();

        VidBasePage.goOutFromIframe();
        GeneralUIUtils.ultimateWait();
        vidBasePage.goToIframe();
        GeneralUIUtils.ultimateWait();
    }

    private void verifyModuleInPendingTable(String serviceInstanceName, String requestId1, String requestId2, Set<String> expectedStatuses, boolean isMacro, boolean simulatorUpdated) {
        DrawingBoardPage.ServiceStatusChecker serviceStatusChecker = new DrawingBoardPage.ServiceStatusChecker(serviceInstanceName, expectedStatuses);
        boolean statusIsShown = Wait.waitFor(serviceStatusChecker, null, 20, 2);
        final String assertionMessage = String.format("service %s: none of rowClasses [%s] is in expectedStatuses: [%s]  ",
                serviceInstanceName,
                String.join(",", serviceStatusChecker.getColumnClassesSet()),
                String.join(",", expectedStatuses));

        assertTrue(assertionMessage, statusIsShown);

        if (isMacro) {
            InstantiationStatusPage.assertInstantiationStatusRow(
                    serviceInstanceName, expectedRowFields(serviceInstanceName));
        } else {
            InstantiationStatusPage.assertInstantiationStatusRow(
                    serviceInstanceName, expectedALaCarteRowFields(serviceInstanceName));
        }

        if (!simulatorUpdated) {
            if (requestId2 != null) {
                registerExpectationFromPreset(new PresetMSOOrchestrationRequestGet(IN_PROGRESS, requestId2), APPEND);
            }
            registerExpectationFromPreset(new PresetMSOOrchestrationRequestGet("COMPLETE", requestId1), APPEND);
        }
        vidBasePage.screenshotDeployDialog(serviceInstanceName);
    }

    private String getActualInstanceName(String serviceInstanceName, Integer i, String status) {
        return i==0 ? serviceInstanceName : serviceInstanceName + "_00" + i;
    }

    private void verifyOpenViewEdit(String serviceInstanceName) {
        boolean[] openEnabled = {true, false, false};
        String[] statuses = {COMPLETED, IN_PROGRESS, PENDING};
        ImmutableList.of(0, 1, 2).forEach(i -> {
            String actualInstanceName = getActualInstanceName(serviceInstanceName, i, statuses[i]);
            if (Features.FLAG_1902_NEW_VIEW_EDIT.isActive()) {
                InstantiationStatusPage.verifyOpenNewViewEdit(actualInstanceName, openEnabled[i], "EDIT");
            }
            else {
                vidBasePage.verifyOpenOldViewEdit(actualInstanceName, null, openEnabled[i], true, true);
            }
        });
    }

    private void verifyOpenAuditInfo(String serviceInstanceName) {
        boolean auditInfoEnabled = true;
        String[] statuses = {COMPLETED, IN_PROGRESS, PENDING};
        for (Integer i : ImmutableList.of(0, 1, 2)) {
            String actualInstanceName = getActualInstanceName(serviceInstanceName, i, statuses[i]);
            InstantiationStatusPage.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))).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, 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(3, MSOTableElement.findElement(By.tagName("thead")).findElements(By.tagName("th")).size(), "MSO table must contain 3 columns");

        if (statuses[i].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_REMOVE, 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 = 0; i < statuses.length; i++) {
            String actualInstanceName = getActualInstanceName(serviceInstanceName, i, statuses[i]);
            InstantiationStatusPage.checkMenuItem(actualInstanceName, contextMenuItem, operationEnabled[i], contextMenuDelete -> {
                Click.byTestId(contextMenuDelete);
                GeneralUIUtils.ultimateWait();
                assertNull(actualInstanceName + " should be " + operationName,
                        InstantiationStatusPage.getInstantiationStatusRow(actualInstanceName));
            });
        }
        vidBasePage.screenshotDeployDialog(serviceInstanceName);
    }

    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", "SILVIA ROBBINS")
                .put("serviceType", "TYLER SILVIA")
                .put("regionId", "hvf6")
                .put("tenantName", "AIN Web Tool-15-D-testalexandria")
                .put("aicZoneName", "NFTJSSSS-NFT1")
                .put("project", "WATKINS")
                .put("owningEntityName", "WayneHolland")
                .put("pause", "false")
                .build();
    }

    private ImmutableMap<String, String> expectedALaCarteRowFields(String actualInstanceName) {
        return ImmutableMap.<String, String>builder()
                .put("userId", getUserCredentials().getUserId())
                .put("serviceModelName", "Grouping Service for Test")
                .put("serviceInstanceName", actualInstanceName)
                .put("serviceModelVersion", "1.0")
                .put("subscriberName", "SILVIA ROBBINS")
                .put("serviceType", "TYLER SILVIA")
                .put("project", "WATKINS")
                .put("owningEntityName", "WayneHolland")
                .put("pause", "false")
                .build();
    }

    private String createSriovService(ServiceData serviceData, boolean tryCancelsAndReentries) {
        return createSriovService(serviceData, tryCancelsAndReentries, randomAlphabetic(5));
    }

    private String createSriovService(ServiceData serviceData, boolean tryCancelsAndReentries, String randomAlphabetic) {
        BrowseASDCPage browseASDCPage = new BrowseASDCPage();
        User user = usersService.getUser(Constants.Users.SILVIA_ROBBINS_TYLER_SILVIA);

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

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

            WebElement instanceName = Get.byId("instanceName");
            boolean isRequired = isElementByIdRequired("instanceName-label");
            if (serviceData.isGeneratedNaming) {
                Assert.assertNotNull(instanceName, "instance name input should be visible when serviceEcompNaming == true.");
                Assert.assertFalse(isRequired,"instance name input should be optional when ecompNaming == true.");

            } else {
                Assert.assertTrue(isRequired,"instance name input should be required when serviceEcompNaming == false.");
                instanceName.sendKeys(serviceInstanceName);
            }

            //serviceType should be dependent on subscriber selection
            assertElementDisabled("serviceType-select");
            Wait.waitByClassAndText(Constants.CreateNewInstance.SUBSCRIBER_NAME_OPTION_CLASS, "SILVIA ROBBINS", 30);
            GeneralUIUtils.ultimateWait();
            Click.byTestId(Constants.SUBSCRIBER_NAME_SELECT_TESTS_ID);
            if (Features.FLAG_RESTRICTED_SELECT.isActive())
                assertElementExistAccordingTagNameAndTestId("select", Constants.SUBSCRIBER_SELECT_ID);
            else{
                assertDropdownPermittedItemsByLabel(user.subscriberNames, Constants.CreateNewInstance.SUBSCRIBER_NAME_OPTION_CLASS);

            }
            VidBasePage.selectSubscriberById("e433710f-9217-458d-a79d-1c7aff376d89");
            //lcpRegion should be dependent on serviceType selection
            assertElementDisabled("lcpRegion-select");

            String serviceType = "TYLER SILVIA";
            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 = "hvf6";
            Wait.waitByClassAndText("lcpRegionOption", lcpRegion, 30);
            viewEditPage.selectLcpRegion(lcpRegion, AIC);

            GeneralUIUtils.ultimateWait();
            browseASDCPage.selectTenant("bae71557c5bb4d5aac6743a4e5f1d054");

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

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

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

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

            browseASDCPage.selectAicZone("NFT1");

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

            assertNotificationAreaVisibilityBehaviour();

            assertPauseOnPausePointsVisibility(serviceData.multiStageDesign);

            validateDynamicFields(serviceData.dynamicFields);

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

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

            VidBasePage.goOutFromIframe();

            browseASDCPage.goToIframe();

        });
        return serviceInstanceName;
    }

    private String createALaCarteService(ServiceData serviceData, String randomAlphabetic) {
        BrowseASDCPage browseASDCPage = new BrowseASDCPage();
        User user = usersService.getUser(Constants.Users.SILVIA_ROBBINS_TYLER_SILVIA);

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

        loadServicePopup(serviceData.modelUuid);

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

        //serviceType should be dependent on subscriber selection
        assertElementDisabled("serviceType-select");
        Wait.waitByClassAndText(Constants.CreateNewInstance.SUBSCRIBER_NAME_OPTION_CLASS, "SILVIA ROBBINS", 30);
        GeneralUIUtils.ultimateWait();
        Click.byTestId(Constants.SUBSCRIBER_NAME_SELECT_TESTS_ID);
        if (Features.FLAG_RESTRICTED_SELECT.isActive())
            assertElementExistAccordingTagNameAndTestId("select", Constants.SUBSCRIBER_SELECT_ID);
        else{
            assertDropdownPermittedItemsByLabel(user.subscriberNames, Constants.CreateNewInstance.SUBSCRIBER_NAME_OPTION_CLASS);

        }
        VidBasePage.selectSubscriberById("e433710f-9217-458d-a79d-1c7aff376d89");

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

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

        SelectOption.byTestIdAndVisibleText("WayneHolland", (Constants.OwningEntity.OWNING_ENTITY_SELECT_TEST_ID));

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

        validateDynamicFields(serviceData.dynamicFields);

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

        Click.byTestId(setButtonTestId);

        VidBasePage.goOutFromIframe();

        browseASDCPage.goToIframe();

        return serviceInstanceName;
    }

    private void assertElementExistAccordingTagNameAndTestId(String tag, String testId) {
        WebElement webElement = Get.byId(testId);
        Assert.assertEquals(webElement.getTagName(), tag);
    }

    private void createVnf(ServiceData serviceData, boolean tryCancelsAndReentries, boolean addedByDefault, String serviceInstanceName) {
        createVnf(serviceData.vnfData, tryCancelsAndReentries, addedByDefault, serviceInstanceName);
    }

    private void createNetwork(VnfData vnfData, boolean tryCancelsAndReentries, boolean addedByDefault, String serviceInstanceName) {
        createVnf(vnfData, tryCancelsAndReentries, addedByDefault, serviceInstanceName, true);
    }

    private void createVnf(VnfData vnfData, boolean tryCancelsAndReentries, boolean addedByDefault, String serviceInstanceName) {
        createVnf(vnfData, tryCancelsAndReentries, addedByDefault, serviceInstanceName, false);
    }

    private void createVnf(VnfData vnfData, boolean tryCancelsAndReentries, boolean addedByDefault, String serviceInstanceName, boolean isNetwork) {
        BrowseASDCPage browseASDCPage = new BrowseASDCPage();

        String nodeToEdit = extractNodeToEdit(vnfData);
        if (addedByDefault && Features.FLAG_SETTING_DEFAULTS_IN_DRAWING_BOARD.isActive()) {
            hoverAndClickEditButton(nodeToEdit);
        } else {
            drawingBoardPage.clickAddButtonByNodeName(vnfData.vnfName);
        }

        GeneralUIUtils.ultimateWait();

        if (vnfData.isGeneratedNaming) {
            Assert.assertFalse(isElementByIdRequired("instanceName-label") ,"instance name input should be optional when EcompNaming == true, and required when false.");
        } else {
            Input.text(vnfData.vnfInstanceName, "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 JANET25,olson3 or olson5a.");

        browseASDCPage.selectLcpRegion("JANET25");

        legacyRegion = Get.byTestId("lcpRegionText");
        Assert.assertNotNull(legacyRegion, "legacy region should be visible when lcp region is JANET25,olson3 or olson5a.");

        browseASDCPage.selectTenant("092eb9e8e4b7412e8787dd091bc58e86");

        assertSetButtonDisabled(VNF_SET_BUTTON_TEST_ID);

        browseASDCPage.selectPlatform("platform");

        assertSetButtonEnabled(VNF_SET_BUTTON_TEST_ID);

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

        Wait.waitByTestId("model-item-value-subscriberName", 10);
        Assert.assertEquals(Get.byTestId("model-item-value-subscriberName").getText(), "SILVIA ROBBINS", "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 (!vnfData.isGeneratedNaming) {
            Assert.assertEquals(Get.byTestId("model-item-value-serviceName").getText(), serviceInstanceName, "Subscriber name should be shown in vf module");
        }

        vidBasePage.screenshotDeployDialog("createVnf-" + serviceInstanceName);
        Click.byTestId(VNF_SET_BUTTON_TEST_ID);
        if (isNetwork) {
            return;
        }
        if (tryCancelsAndReentries) {
            hoverAndClickEditButton(nodeToEdit);

            Wait.byText("TYLER SILVIA");
            GeneralUIUtils.ultimateWait();
            assertThat(Get.selectedOptionText(Constants.ViewEdit.LCP_REGION_SELECT_TESTS_ID), startsWith("JANET25"));
            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), "ONAP");
            Assert.assertEquals(Get.selectedOptionText(Constants.OwningEntity.PLATFORM_SELECT_TEST_ID), "platform");
            Click.byTestId(Constants.CANCEL_BUTTON_TEST_ID);
            GeneralUIUtils.ultimateWait();
        } else {
            toggleItemInTree(Constants.DrawingBoard.AVAILABLE_MODELS_TREE);
        }
        Click.byTestId("node-" + nodeToEdit);
    }

    private String extractNodeToEdit(VnfData vnfData) {
        return vnfData.vnfUuid + "-" + vnfData.vnfName;
    }


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

    private void hoverAndClickEditButton(String nodeToEdit) {
        hoverAndClickButton(nodeToEdit, Constants.DrawingBoard.CONTEXT_MENU_EDIT);
    }

    private void hoverAndClickDeleteButton(String nodeToEdit) {
        hoverAndClickButton(nodeToEdit, Constants.InstantiationStatus.CONTEXT_MENU_REMOVE);
    }

    private void hoverAndClickDuplicateButton(String nodeToEdit) {
        hoverAndClickButton(nodeToEdit, Constants.InstantiationStatus.CONTEXT_MENU_DUPLICATE);
    }
    private void hoverAndClickButton(String nodeToEdit, String contextMenuItem) {
        String nodeOfEdit = Constants.DrawingBoard.NODE_PREFIX + nodeToEdit;
        String buttonOfEdit = nodeOfEdit + Constants.DrawingBoard.CONTEXT_MENU_BUTTON;
        GeneralUIUtils.hoverOnAreaByTestId(buttonOfEdit);
        Click.byTestId(buttonOfEdit);
        Click.byTestId(contextMenuItem);
    }

    private void uploadSupplementaryFile(String inputFileName, boolean isValid, BrowseASDCPage browseASDCPage, String setButtonTestId) {
        if (Features.FLAG_SUPPLEMENTARY_FILE.isActive()) {
            GeneralUIUtils.ultimateWait();
            Input.file("supplementaryFiles/" + inputFileName, "supplementaryFile");
            GeneralUIUtils.ultimateWait();
            WebElement fileName = Get.byTestId("file-name");
            Assert.assertEquals(fileName.getText(),inputFileName);
            browseASDCPage.assertButtonState(setButtonTestId, isValid);
        }
    }

    private void deleteSupplementaryFile() {
        if (Features.FLAG_SUPPLEMENTARY_FILE.isActive()) {
            Click.byTestId("remove-uploaded-file");
            GeneralUIUtils.ultimateWait();
            WebElement fileName = Get.byTestId("file-name");
            Assert.assertEquals(fileName.getText(),"Choose file");
        }
    }

    private void createVfModule(ServiceData serviceData, String serviceInstanceName, boolean addedByDefault, boolean addOpensPopup) {
        clickAddVfModule(serviceData, addedByDefault);
        if (!addOpensPopup) {
            clickEditVfModule(serviceData);
        }
        fillAndSetVfModulePopup(serviceData, serviceInstanceName);
    }

    private void fillAndSetVfModulePopup(ServiceData serviceData, String serviceInstanceName) {
        String setButtonTestId = "form-set";
        BrowseASDCPage browseASDCPage = new BrowseASDCPage();

        Assert.assertEquals(isElementByIdRequired("instanceName-label"), !serviceData.vnfData.isGeneratedNaming,"instance name input should be optional when EcompNaming == true, and required when false.");

        if (!serviceData.vnfData.isGeneratedNaming) {
            Input.text("VF instance name", "instanceName");
        }

        if (serviceData.vfData.vgEnabled) {
            browseASDCPage.setInputText("volumeGroupName", "_abc");
            Assert.assertEquals(isElementByIdRequired("volumeGroupName-label"), false,  "volume Group name input should be always optional");
        } 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(), "SILVIA ROBBINS", "Subscriber name should be shown in vf module");
        Assert.assertEquals(Get.byTestId("model-item-value-min").getText(), Integer.toString(serviceData.vfData.vfMin), "Min should be shown");
        Assert.assertEquals(Get.byTestId("model-item-value-max").getText(), Integer.toString(serviceData.vfData.vfMax), "Max should be shown");
        if (!serviceData.vnfData.isGeneratedNaming) {
            Wait.byText(serviceInstanceName);
            Assert.assertEquals(Get.byTestId("model-item-value-serviceName").getText(), serviceInstanceName, "Service name should be shown in vf module");
        }
        validateDynamicFields(serviceData.vfData.dynamicFields);

        uploadSupplementaryFile("invalid-file.json", false, browseASDCPage, setButtonTestId);
        deleteSupplementaryFile();
        uploadSupplementaryFile("sample.json", true, browseASDCPage, setButtonTestId);

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

    private void clickEditVfModule(ServiceData serviceData) {
        if (Features.FLAG_SETTING_DEFAULTS_IN_DRAWING_BOARD.isActive()) {
            hoverAndClickEditButton(serviceData.vfData.uuid + "-" + serviceData.vfData.vfName);
        }
    }

    private void clickAddVfModule(ServiceData serviceData, boolean addedByDefault) {
        if (Features.FLAG_SETTING_DEFAULTS_IN_DRAWING_BOARD.isActive() && addedByDefault) {
            return;
        }
        System.out.println("VFModule should be added 'manually'");

        final WebElement vfModuleNode = Get.byTestId(Constants.DrawingBoard.NODE_PREFIX + serviceData.vfData.vfName);

        if (vfModuleNode == null || !vfModuleNode.isDisplayed()) {
            // expand tree
            drawingBoardPage.clickNode(serviceData.vnfData.vnfName);
        }
        drawingBoardPage.clickAddButtonByNodeName(serviceData.vfData.vfName);
    }

    private void clickRemoveVfModule(String vfModuleId, String vfModuleName) {
        if (Features.FLAG_SETTING_DEFAULTS_IN_DRAWING_BOARD.isActive()) {
            System.out.println("will remove " + vfModule0Name);
            hoverAndClickDeleteButton(vfModuleId + "-" + vfModuleName);
        }
    }

    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.");
    }

    private void prepareServicePreset(ModelInfo modelInfo, boolean deploy) {
        String subscriberId = "e433710f-9217-458d-a79d-1c7aff376d89";

        if (deploy) {
            registerExpectationForServiceDeployment(
                    ImmutableList.of(
                            modelInfo,
                            PASQUALEVmxVpeBvService488Annotations
                    ),
                    subscriberId, null);
        } else {
            registerExpectationForServiceBrowseAndDesign(ImmutableList.of(modelInfo), subscriberId);
        }
    }

    private class ServiceData {
        ServiceData(String modelUuid, List<String> dynamicFields, boolean isServiceGeneratedNaming, boolean isVnfGeneratedNaming, boolean isVgEnabled, boolean multiStageDesign, String vnfName, String vfName, int vfMin, int vfMax, List<String> vfModuleDynamicFields, String vfVersionId) {
            this.modelUuid = modelUuid;
            this.dynamicFields = dynamicFields;
            this.isGeneratedNaming = isServiceGeneratedNaming;
            this.multiStageDesign = multiStageDesign;
            this.vnfData = new VnfData(vnfName, "69e09f68-8b63-4cc9-b9ff-860960b5db09", "VNF instance name", isVnfGeneratedNaming);
            this.vfData = new VfData(vfName, isVgEnabled, vfMin, vfMax, vfModuleDynamicFields, vfVersionId);
        }

        final String modelUuid;
        final List<String> dynamicFields;
        final boolean isGeneratedNaming;
        final boolean multiStageDesign;
        final VnfData vnfData;
        final VfData vfData;
    }

    private class VnfData {
        VnfData(String vnfName, String vnfUuid, String vnfInstanceName, boolean isGeneratedNaming) {
            this.vnfName = vnfName;
            this.vnfUuid = vnfUuid;
            this.vnfInstanceName = vnfInstanceName;
            this.isGeneratedNaming = isGeneratedNaming;
        }

        final String vnfName;
        final String vnfUuid;
        final String vnfInstanceName;
        final boolean isGeneratedNaming;
    }


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

        final int vfMin;
        final int vfMax;
        final String uuid;
        final String vfName;
        final boolean vgEnabled;
        final List<String> dynamicFields;
    }


}