Update link to Security Vulnerability
[vid.git] / vid-automation / src / main / java / vid / automation / test / test / NewServiceInstanceTest.java
1 package vid.automation.test.test;
2
3 import com.google.common.collect.*;
4 import org.apache.commons.lang3.RandomStringUtils;
5 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOBaseCreateServiceInstancePost;
6 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstanceGen2;
7 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet;
8 import org.openecomp.sdc.ci.tests.datatypes.UserCredentials;
9 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
10 import org.openqa.selenium.By;
11 import org.openqa.selenium.WebElement;
12 import org.testng.Assert;
13 import org.testng.annotations.*;
14 import vid.automation.test.Constants;
15 import vid.automation.test.Constants.BrowseASDC.NewServicePopup;
16 import vid.automation.test.infra.*;
17 import vid.automation.test.model.Service;
18 import vid.automation.test.model.User;
19 import vid.automation.test.sections.*;
20 import vid.automation.test.services.AsyncJobsService;
21 import vid.automation.test.services.ServicesService;
22 import vid.automation.test.services.SimulatorApi;
23
24 import java.text.ParseException;
25 import java.text.SimpleDateFormat;
26 import java.util.*;
27 import java.util.function.Consumer;
28 import java.util.function.Predicate;
29 import java.util.stream.Collectors;
30
31 import static junit.framework.TestCase.assertNull;
32 import static org.hamcrest.CoreMatchers.is;
33 import static org.hamcrest.MatcherAssert.assertThat;
34 import static org.testng.Assert.assertEquals;
35 import static org.testng.AssertJUnit.assertTrue;
36 import static vid.automation.test.infra.Features.FLAG_ASYNC_INSTANTIATION;
37 import static vid.automation.test.services.SimulatorApi.RegistrationStrategy.APPEND;
38
39 @FeatureTogglingTest(FLAG_ASYNC_INSTANTIATION)
40 public class NewServiceInstanceTest extends CreateInstanceDialogBaseTest {
41
42     private ServicesService servicesService = new ServicesService();
43     private DrawingBoardPage drawingBoardPage = new DrawingBoardPage();
44     List<String> serviceModelLabelList = Arrays.asList("Model version", "Description", "Category", "UUID",
45             "Invariant UUID", "Service type", "Service role");
46     List<String> mandatoryServiceModelLabelList = Arrays.asList("Model version", "UUID", "Invariant UUID");
47     private final String defaultServiceModelForMostTests = "6e59c5de-f052-46fa-aa7e-2fca9d674c44";
48     private final VidBasePage vidBasePage = new VidBasePage();
49
50     @BeforeClass
51     protected void dropAllAsyncJobs() {
52         AsyncJobsService asyncJobsService = new AsyncJobsService();
53         asyncJobsService.dropAllAsyncJobs();
54     }
55
56     @AfterClass
57     protected void muteAllAsyncJobs() {
58         AsyncJobsService asyncJobsService = new AsyncJobsService();
59         asyncJobsService.muteAllAsyncJobs();
60     }
61
62     @BeforeMethod
63     protected void refreshPage() {
64         GeneralUIUtils.ultimateWait();
65
66         vidBasePage.refreshPage();
67     }
68
69     @Override
70     protected UserCredentials getUserCredentials() {
71         String userName = Constants.Users.USP_VOICE_VIRTUAL_USP;
72         User user = usersService.getUser(userName);
73         return new UserCredentials(user.credentials.userId, user.credentials.password, userName, "", "");
74     }
75
76     @Test
77     public void createNewServiceInstance_fullModelData_LeftPaneLabelsCorrect() throws Exception {
78         loadMacroServicePopup_noDynamicFields_fullModelDetails_ecompNamingFalse();
79         assertServiceModelLabelsCorrect(serviceModelLabelList);
80     }
81
82     @Test
83     public void createNewServiceInstance_partialModelData_LeftPaneLabelsCorrect() throws Exception {
84         loadMacroServicePopup_withDynamicFields_partialModelDetails_ecompNamingTrue();
85         assertServiceModelLabelsCorrect(mandatoryServiceModelLabelList);
86     }
87
88     /**
89      * asserts that the provided labels list is visible and that no other detail item appears in the model details panel.
90      */
91     protected void assertServiceModelLabelsCorrect(List<String> serviceModelLabelList) throws Exception {
92         WebElement modelInformation = getDriver().findElement(By.id("model-information"));
93         List<WebElement> modelInformationItems = modelInformation.findElements(By.xpath("./div"));
94         assertEquals(modelInformationItems.size(), serviceModelLabelList.size());
95         serviceModelLabelList.forEach(label -> {
96             WebElement webElement = Get.byTestId("model-item-" + label);
97             WebElement itemWarpper = webElement.findElements(By.className("wrapper")).get(0);
98             assertEquals(itemWarpper.findElements(By.tagName("label")).get(0).getText(), label, "model details item label is incorrect.");
99         });
100     }
101
102     @Test
103     public void createNewServiceInstance_leftPane_serviceModelDataCorrect() {
104         Service service = servicesService.getService(NewServicePopup.SERVICE_UUID);
105         String prefix = NewServicePopup.SERVICE_MODEL_DATA_TEST_ID_VALUE_PREFIX;
106         loadMacroServicePopup_noDynamicFields_fullModelDetails_ecompNamingFalse();
107         setNewInstance_leftPane_assertModelDataCorrect(NewServicePopup.SERVICE_MODEL_FIELD_TO_DATA_TESTS_ID, prefix, service);
108     }
109
110     @Test
111     public void createNewServiceInstance_macro_validPopupDataAndUI__ecompNamingFalse() {
112
113         ServiceData serviceData = new ServiceData("csar-noDynamicFields-ecompNamingFalse-fullModelDetails-1a80c596.zip",
114                 "1a80c596-27e5-4ca9-b5bb-e03a7fd4c0fd",
115                 new ArrayList<>(),
116                 false, true, true, true,
117                 "2017-488_ADIOD-vPE 0",
118                 "2017488_adiodvpe0..2017488AdiodVpe..ADIOD_vRE_BV..module-1", 0, 1,  new ArrayList<>());
119
120         String serviceInstanceName = deployServiceInstance(serviceData, false);
121         vidBasePage.screenshotDeployDialog(serviceInstanceName);
122         deployAndVerifyModuleInPendingTable(serviceInstanceName);
123         verifyOpenAuditInfo(serviceInstanceName);
124         verifyOpenViewEdit(serviceInstanceName);
125         verifyDeleteJob(serviceInstanceName);
126         verifyHideJob(serviceInstanceName);
127     }
128
129     @Test
130     public void createNewServiceInstance_macro_validPopupDataAndUI__ecompNamingServiceFalseVnfTrue_vgNameFalse() {
131         ServiceData serviceData = new ServiceData("csar-noDynamicFields-ecompNamingFalse-fullModelDetails-1a80c596.zip",
132                 "1a80c596-27e5-4ca9-b5bb-e03a7fd4c0fd",
133                 new ArrayList<>(),
134                 false, true, false, true,
135                 "2017-488_ADIOD-vPE 0",
136                 "2017488_adiodvpe0..2017488AdiodVpe..ADIOD_base_vPE_BV..module-0", 1, 1, new ArrayList<>());
137
138         deployServiceInstance(serviceData);
139     }
140
141     @Test
142     public void createNewServiceInstance_macro_validPopupDataAndUI__ecompNamingServiceFalseVnfFalse_vgNameFalse() {
143         ServiceData serviceData = new ServiceData("csar-noDynamicFields-ecompNamingFalse-fullModelDetails-1a80c596-vnfEcompNamingFalse.zip",
144                 "4a80c596-27e5-4ca9-b5bb-e03a7fd4c0fd",
145                 new ArrayList<>(),
146                 false, false, false, false,
147                 "2017-488_ADIOD-vPE 0",
148                 "2017488_adiodvpe0..2017488AdiodVpe..ADIOD_base_vPE_BV..module-0", 1, 1, new ArrayList<>());
149
150         deployServiceInstance(serviceData);
151     }
152
153     @Test
154     public void createNewServiceInstance_macro_validPopupDataAndUI__ecompNamingServiceFalseVnfFalse_vgNameTrue() {
155         ServiceData serviceData = new ServiceData("csar-noDynamicFields-ecompNamingFalse-fullModelDetails-1a80c596-vnfEcompNamingFalse.zip",
156                 "4a80c596-27e5-4ca9-b5bb-e03a7fd4c0fd",
157                 new ArrayList<>(),
158                 false, false, true, false,
159                 "2017-488_ADIOD-vPE 0",
160                 "2017488_adiodvpe0..2017488AdiodVpe..ADIOD_vRE_BV..module-1", 0, 1, new ArrayList<>());
161
162         deployServiceInstance(serviceData);
163     }
164
165     private void deployServiceInstance(ServiceData serviceData) {
166         deployServiceInstance(serviceData, true);
167     }
168
169     private String deployServiceInstance(ServiceData serviceData, boolean tryCancelsAndReentries) {
170         User user = usersService.getUser(Constants.Users.USP_VOICE_VIRTUAL_USP);
171
172         final String serviceInstanceName = createSriovService(
173                 user, serviceData.dynamicFields, serviceData.csarName, serviceData.modelUuid,
174                 serviceData.isGeneratedNaming, serviceData.multiStageDesign,
175                 tryCancelsAndReentries);
176
177         createVnf(serviceData.vnfData.isGeneratedNaming, serviceData.vnfData.vnfName, serviceInstanceName, tryCancelsAndReentries);
178
179         createVfModule(
180                 serviceData.vfData.vfName, serviceData.vnfData.isGeneratedNaming,
181                 serviceData.vfData.vgEnabled, serviceData.vfData.vfMin, serviceData.vfData.vfMax,
182                 serviceData.vfData.dynamicFields, serviceInstanceName);
183
184         return serviceInstanceName;
185     }
186
187
188     @Test
189     public void createNewServiceInstance_macro_validPopupDataAndUI__ecompNamingTrue() {
190
191         List<String> serviceDynamicFields = Arrays.asList("2017488 adiodvpe0 asn:");
192         ServiceData serviceData = new ServiceData("csar-withDynamicFields-ecompNamingTrue-partialModelDetails.zip",
193                 "2f80c596-27e5-4ca9-b5bb-e03a7fd4c0fd",
194                 serviceDynamicFields,
195                 true, true, false, false,
196                 "2017-488_ADIOD-vPE 0",
197                 "2017488_adiodvpe0..2017488AdiodVpe..ADIOD_vRE_BV..module-1", 0, 1, new ArrayList<>());
198
199         deployServiceInstance(serviceData);
200
201     }
202
203     private void deployAndVerifyModuleInPendingTable(String serviceInstanceName) {
204         drawingBoardPage.clickDeployButton();
205
206         boolean simulatorUpdated = false;
207
208         vidBasePage.goToIframe();
209         GeneralUIUtils.ultimateWait();
210         int[] ids = {1, 1, 2, 3};
211         String[] statuses = {"IN_PROGRESS", "COMPLETED", "IN_PROGRESS", "PENDING"};
212         for (int i = 0; i < ids.length; i++) {
213             String actualInstanceName = getActualInstanceName(serviceInstanceName, ids[i], statuses[i]);
214
215             final Set<String> expectedStatuses = ImmutableSet.of(statuses[i]);
216             ServiceStatusChecker serviceStatusChecker = new ServiceStatusChecker(actualInstanceName, expectedStatuses);
217             boolean statusIsShown = Wait.waitFor(serviceStatusChecker, null, 20, 2);
218             final String assertionMessage = String.format("service %s: none of rowClasses [%s] is in expectedStatuses: [%s]  ",
219                     actualInstanceName,
220                     String.join(",", serviceStatusChecker.getColumnClassesSet()),
221                     String.join(",", expectedStatuses));
222
223             assertTrue(assertionMessage, statusIsShown);
224
225             InstantiationStatusPage.assertInstantiationStatusRow(
226                     actualInstanceName, expectedRowFields(actualInstanceName));
227
228             if (!simulatorUpdated) {
229                 simulatorUpdated = true;
230                 final String request1 = PresetMSOBaseCreateServiceInstancePost.DEFAULT_REQUEST_ID;
231                 final String request2 = "ce010256-3fdd-4cb5-aed7-37112a2c6e93";
232                 SimulatorApi.registerExpectationFromPreset(new PresetMSOCreateServiceInstanceGen2(request2), APPEND);
233                 SimulatorApi.registerExpectationFromPreset(new PresetMSOOrchestrationRequestGet("IN_PROGRESS", request2), APPEND);
234                 SimulatorApi.registerExpectationFromPreset(new PresetMSOOrchestrationRequestGet("COMPLETE", request1), APPEND);
235             }
236         }
237         vidBasePage.screenshotDeployDialog(serviceInstanceName);
238     }
239
240     private String getActualInstanceName(String serviceInstanceName, Integer i, String status) {
241         return "PENDING".equals(status) ? serviceInstanceName : serviceInstanceName + "_00" + i;
242     }
243
244     private void verifyOpenViewEdit(String serviceInstanceName) {
245         boolean[] openEnabled = {true, false, false};
246         String[] statuses = {"COMPLETED", "IN_PROGRESS", "PENDING"};
247         ImmutableList.of(1, 2, 3).forEach(i -> {
248             String actualInstanceName = getActualInstanceName(serviceInstanceName, i, statuses[i - 1]);
249             checkMenuItem(actualInstanceName, Constants.InstantiationStatus.CONTEXT_MENU_HEADER_OPEN_ITEM, openEnabled[i - 1], contextMenuOpen -> {
250                 Click.byTestId(contextMenuOpen);
251                 vidBasePage.goOutFromIframe();
252                 GeneralUIUtils.ultimateWait();
253
254                 Wait.byText("View/Edit Service Instance");
255                 Wait.byText("Add node instance");
256                 Wait.byText("i'm a port");
257                 Wait.byText("f8791436-8d55-4fde-b4d5-72dd2cf13cfb");
258
259                 vidBasePage.screenshotDeployDialog("view-edit-" + actualInstanceName);
260                 SideMenu.navigateToMacroInstantiationStatus();
261             });
262         });
263     }
264
265
266     private void verifyOpenAuditInfo(String serviceInstanceName) {
267         boolean auditInfoEnabled = true;
268         String[] statuses = {"COMPLETED", "IN_PROGRESS", "PENDING"};
269         for (Integer i : ImmutableList.of(1, 2, 3)) {
270             String actualInstanceName = getActualInstanceName(serviceInstanceName, i, statuses[i - 1]);
271             checkMenuItem(actualInstanceName, Constants.InstantiationStatus.CONTEXT_MENU_HEADER_AUDIT_INFO_ITEM, auditInfoEnabled, contextMenuOpen -> {
272                 Click.byTestId(contextMenuOpen);
273                 checkAuditInfoModal(actualInstanceName, i, statuses);
274             });
275             final WebElement row = InstantiationStatusPage.getInstantiationStatusRow(actualInstanceName);
276             row.findElement(By.id(Constants.InstantiationStatus.TD_JOB_STATUS_ICON + "-" + (i - 1))).click();
277             checkAuditInfoModal(actualInstanceName, i, statuses);
278         }
279     }
280
281     private void checkAuditInfoModal(String actualInstanceName, Integer i, String[] statuses) {
282
283         Wait.waitByTestId("vidJobStatus", 10);
284
285         WebElement webElement = Get.byTestId("model-item-value-serviceInstanceName");
286         assertEquals(webElement.getText(), actualInstanceName, "Service Instance Name must be equal");
287
288         WebElement vidTableElement = Get.byId("service-instantiation-audit-info-vid");
289         assertEquals(3, vidTableElement.findElement(By.tagName("thead")).findElements(By.tagName("th")).size(), "VID table must contain 3 columns");
290
291         List<WebElement> vidStatusesElements = vidTableElement.findElements(By.id("vidJobStatus"));
292         List<String> vidStatuses = vidStatusesElements.stream()
293                 .map(s ->
294                         convertUITextCapitalizeAndFormatPipe(s.getText()))
295                 .collect(Collectors.toList());
296
297         List<String> serviceStatus = Arrays.asList(Arrays.copyOfRange(statuses, i - 1, statuses.length));
298         assertThat("statuses for " + actualInstanceName + " must be as expected", vidStatuses, is(Lists.reverse(serviceStatus)));
299
300         String dateString = vidTableElement.findElements(By.id("vidStatusTime")).get(0).getText();
301         assertTrue("vid Status Time column must contains valid date in format : MMM dd, yyyy HH:mm", isDateValid(dateString, "MMM dd, yyyy HH:mm"));
302
303         WebElement MSOTableElement = Get.byId("service-instantiation-audit-info-mso");
304         assertEquals(4, MSOTableElement.findElement(By.tagName("thead")).findElements(By.tagName("th")).size(), "MSO table must contain 4 columns");
305
306         if (statuses[i - 1].equals("PENDING")) {
307             assertEquals(0, MSOTableElement.findElement(By.tagName("tbody")).findElements(By.tagName("tr")).size(), "When status is PENDING MSO table is empty");
308         }
309
310         vidBasePage.screenshotDeployDialog("audit-info-" + actualInstanceName);
311         Click.byId(Constants.AuditInfoModal.CANCEL_BUTTON);
312     }
313
314     private String convertUITextCapitalizeAndFormatPipe(String text) {
315         return text.toUpperCase().replace("-", "_");
316     }
317
318     private boolean isDateValid(String dateToValidate, String dateFromat) {
319
320         if (dateToValidate == null) {
321             return false;
322         }
323         SimpleDateFormat sdf = new SimpleDateFormat(dateFromat);
324         sdf.setLenient(false);
325         try {
326             //if not valid, it will throw ParseException
327             Date date = sdf.parse(dateToValidate);
328
329         } catch (ParseException e) {
330             e.printStackTrace();
331             return false;
332         }
333         return true;
334     }
335
336     private void verifyDeleteJob(String serviceInstanceName) {
337         boolean[] deleteEnabled = {false, false, true};
338         String[] statuses = {"COMPLETED", "IN_PROGRESS", "PENDING"};
339         verifyDeleteOrHideOperation(serviceInstanceName, Constants.InstantiationStatus.CONTEXT_MENU_DELETE, statuses, deleteEnabled, "deleted");
340     }
341
342     private void verifyHideJob(String serviceInstanceName) {
343         boolean[] hideEnabled = {true, false};
344         String[] statuses = {"COMPLETED", "IN_PROGRESS"};
345         verifyDeleteOrHideOperation(serviceInstanceName, Constants.InstantiationStatus.CONTEXT_MENU_HIDE, statuses, hideEnabled, "hidden");
346     }
347
348     private void verifyDeleteOrHideOperation(String serviceInstanceName, String contextMenuItem, String[] statuses, boolean[] operationEnabled, String operationName) {
349         for (int i = 1; i <= statuses.length; i++) {
350             String actualInstanceName = getActualInstanceName(serviceInstanceName, i, statuses[i - 1]);
351             checkMenuItem(actualInstanceName, contextMenuItem, operationEnabled[i - 1], contextMenuDelete -> {
352                 Click.byTestId(contextMenuDelete);
353                 GeneralUIUtils.ultimateWait();
354                 assertNull(actualInstanceName + " should be " + operationName,
355                         InstantiationStatusPage.getInstantiationStatusRow(actualInstanceName));
356             });
357         }
358         vidBasePage.screenshotDeployDialog(serviceInstanceName);
359     }
360
361     private void checkMenuItem(String actualInstanceName, String contextMenuItem, boolean shouldBeEnabled, Consumer<String> doIfEnabled) {
362         Wait.waitFor(name -> {
363             if (null == InstantiationStatusPage.getInstantiationStatusRow(name)) {
364                 InstantiationStatusPage.clickRefreshButton();
365                 return false;
366             } else {
367                 return true;
368             }
369         }, actualInstanceName, 8, 1);
370         final WebElement row = InstantiationStatusPage.getInstantiationStatusRow(actualInstanceName);
371         row.findElement(By.className("menu-div")).click();
372         String clazz = Get.byXpath("//div[@data-tests-id='" + contextMenuItem + "']/ancestor::li").getAttribute("class");
373         assertThat("item " + contextMenuItem + " of " + actualInstanceName +
374                 " should be " + (shouldBeEnabled ? "enabled" : "disabled"), !clazz.equals("disabled"), is(shouldBeEnabled));
375         if (shouldBeEnabled) {
376             doIfEnabled.accept(contextMenuItem);
377         } else {
378             // dismiss menu
379             Get.byClass("title").get(0).click();
380         }
381     }
382
383     private ImmutableMap<String, String> expectedRowFields(String actualInstanceName) {
384         return ImmutableMap.<String, String>builder()
385                 .put("userId", getUserCredentials().getUserId())
386                 .put("serviceModelName", "action-data")
387                 .put("serviceInstanceName", actualInstanceName)
388                 .put("serviceModelVersion", "1.0")
389                 .put("subscriberName", "USP VOICE")
390                 .put("serviceType", "VIRTUAL USP")
391                 .put("regionId", "mtn6")
392                 .put("tenantName", "AIN Web Tool-15-D-testgamma")
393                 .put("aicZoneName", "NFTJSSSS-NFT1")
394                 .put("project", "DFW")
395                 .put("owningEntityName", "MetroPacketCore")
396                 .put("pause", "false")
397                 .build();
398     }
399
400     private String createSriovService(User user, List<String> serviceDynamicFields,
401                                       String csarName, String modelId, boolean modelWithGeneratedName,
402                                       boolean multiStageDesign, boolean tryCancelsAndReentries) {
403         BrowseASDCPage browseASDCPage = new BrowseASDCPage();
404
405         // simulate typing with spaces, but expected is without spaces
406         String serviceInstanceNameWithSpaces = RandomStringUtils.randomAlphabetic(5) + " instance name";
407         String serviceInstanceName = serviceInstanceNameWithSpaces.replace(" ", "");
408
409         List<String> cycles = tryCancelsAndReentries ? ImmutableList.of("WILL_CANCEL", "AFTER_CANCEL") : ImmutableList.of("SINGLE_SHOT");
410         cycles.forEach(cycle -> {
411             if ("AFTER_CANCEL".equals(cycle)) {
412                 loadServicePopupOnBrowseASDCPage(modelId);
413             } else {
414                 loadServicePopup(csarName, modelId);
415             }
416
417             WebElement instanceName = Get.byId("instance-name");
418             if (modelWithGeneratedName) {
419                 Assert.assertNull(instanceName, "instance name input should be invisible when serviceEcompNaming == true.");
420             } else {
421                 instanceName.sendKeys(serviceInstanceNameWithSpaces);
422             }
423
424             //serviceType should be dependent on subscriber selection
425             assertElementDisabled("service-type-select");
426
427             GeneralUIUtils.ultimateWait();
428             assertDropdownPermittedItemsByLabel(user.subscriberNames, Constants.CreateNewInstance.SUBSCRIBER_NAME_OPTION_CLASS);
429             VidBasePage.selectSubscriberById("e433710f-9217-458d-a79d-1c7aff376d89");
430             GeneralUIUtils.ultimateWait();
431
432             //lcpRegion should be dependent on serviceType selection
433             assertElementDisabled("lcpRegion-select");
434
435             String serviceType = "VIRTUAL USP";
436             Wait.waitByClassAndText(Constants.CreateNewInstance.SERVICE_TYPE_OPTION_CLASS, serviceType, 30);
437             browseASDCPage.selectServiceTypeByName(serviceType);
438
439             //tenant should be dependent on lcpRegion selection
440             assertElementDisabled("tenant-select");
441
442             String lcpRegion = "mtn6";
443             Wait.waitByClassAndText("lcpRegionOption", lcpRegion, 30);
444             browseASDCPage.selectLcpRegion(lcpRegion);
445
446             browseASDCPage.selectTenant("bae71557c5bb4d5aac6743a4e5f1d054");
447
448             String setButtonTestId = "service-form-set";
449             assertSetButtonDisabled(setButtonTestId);
450
451             SelectOption.byTestIdAndVisibleText("MetroPacketCore", (Constants.OwningEntity.OWNING_ENTITY_SELECT_TEST_ID));
452             assertSetButtonDisabled(setButtonTestId);
453
454             SelectOption.byTestIdAndVisibleText("DHV", Constants.ViewEdit.PRODUCT_FAMILY_SELECT_TESTS_ID);
455             assertSetButtonEnabled(setButtonTestId);
456
457             browseASDCPage.selectProductFamily("e433710f-9217-458d-a79d-1c7aff376d89");
458
459             assertAllIsPermitted(Constants.BrowseASDC.AIC_OPTION_CLASS);
460             browseASDCPage.selectAicZone("NFT1");
461
462             SelectOption.byTestIdAndVisibleText("DFW", Constants.OwningEntity.PROJECT_SELECT_TEST_ID);
463
464             assertNotificationAreaVisibilityBehaviour();
465
466             assertPauseOnPausePointsVisibility(multiStageDesign);
467
468             validateDynamicFields(serviceDynamicFields);
469
470             vidBasePage.screenshotDeployDialog("createSriovService-" + serviceInstanceName);
471
472             if ("WILL_CANCEL".equals(cycle)) {
473                 Click.byTestId(Constants.CANCEL_BUTTON_TEST_ID);
474             } else {
475                 Click.byTestId(setButtonTestId);
476             }
477
478             browseASDCPage.goOutFromIframe();
479
480             browseASDCPage.goToIframe();
481
482         });
483         return serviceInstanceName;
484     }
485
486     private void createVnf(boolean isInstanceNameGenerated, String vnfName, String serviceInstanceName, boolean tryCancelsAndReentries) {
487         BrowseASDCPage browseASDCPage = new BrowseASDCPage();
488         drawingBoardPage.clickAddButtonByNodeName(vnfName);
489
490         if (isInstanceNameGenerated) {
491             WebElement instanceName = Get.byId("instance-name");
492             Assert.assertNull(instanceName, "instance name input should be invisible when serviceEcompNaming == true.");
493         } else {
494             Input.text("VNF instance name", "instanceName");
495         }
496
497         //tenant should be dependent on lcpRegion selection
498         assertElementDisabled("tenant-select");
499
500         WebElement legacyRegion = Get.byTestId("lcpRegionText");
501         Assert.assertNull(legacyRegion, "legacy region shouldn't be visible when lcp region isn't AAIAIC25,rdm3 or rdm5a.");
502
503         browseASDCPage.selectLcpRegion("AAIAIC25");
504
505         legacyRegion = Get.byTestId("lcpRegionText");
506         Assert.assertNotNull(legacyRegion, "legacy region should be visible when lcp region is AAIAIC25,rdm3 or rdm5a.");
507
508         browseASDCPage.selectTenant("092eb9e8e4b7412e8787dd091bc58e86");
509
510         String setButtonTestId = "vnf-form-set";
511         assertSetButtonDisabled(setButtonTestId);
512
513         browseASDCPage.selectPlatform("platform");
514
515         assertSetButtonEnabled(setButtonTestId);
516
517         browseASDCPage.setLegacyRegion("some legacy region");
518         browseASDCPage.selectLineOfBusiness("ECOMP");
519
520         Wait.waitByTestId("model-item-value-subscriberName", 10);
521         Assert.assertEquals(Get.byTestId("model-item-value-subscriberName").getText(), "USP VOICE", "Subscriber name should be shown in vf module");
522         Assert.assertEquals(Get.byTestId("model-item-value-min"), null, "Min value should not be shown in VNF popup");
523         Assert.assertEquals(Get.byTestId("model-item-value-max"), null, "Max value should not be show in VNF popup");
524         if (!isInstanceNameGenerated) {
525             Assert.assertEquals(Get.byTestId("model-item-value-serviceName").getText(), serviceInstanceName, "Subscriber name should be shown in vf module");
526         }
527
528         vidBasePage.screenshotDeployDialog("createVnf-" + serviceInstanceName);
529         Click.byTestId(setButtonTestId);
530
531         String nodeToEdit = "69e09f68-8b63-4cc9-b9ff-860960b5db09-2017-488_ADIOD-vPE 0";
532         if (tryCancelsAndReentries) {
533             hoverAndClickEditButton(nodeToEdit);
534
535             Wait.byText("VIRTUAL USP");
536             GeneralUIUtils.ultimateWait();
537             Assert.assertEquals(Get.selectedOptionText(Constants.ViewEdit.LCP_REGION_SELECT_TESTS_ID), "AAIAIC25");
538             Assert.assertEquals(Get.selectedOptionText(Constants.ViewEdit.TENANT_SELECT_TESTS_ID), "USP-SIP-IC-24335-T-01");
539             Assert.assertEquals(Get.selectedOptionText(Constants.ViewEdit.LINE_OF_BUSINESS_SELECT_TESTS_ID), "ECOMP");
540             Assert.assertEquals(Get.selectedOptionText(Constants.OwningEntity.PLATFORM_SELECT_TEST_ID), "platform");
541             Click.byTestId(Constants.CANCEL_BUTTON_TEST_ID);
542         } else {
543             toggleItemInTree(nodeToEdit);
544         }
545     }
546
547     private void toggleItemInTree(String nodeToEdit) {
548         Click.byXpath("//tree-root[@data-tests-id='" + Constants.DrawingBoard.AVAILABLE_MODELS_TREE + "']//span[@class='" + Constants.DrawingBoard.TOGGLE_CHILDREN + "']");
549     }
550
551     private void hoverAndClickEditButton(String nodeToEdit) {
552         String buttonOfEdit = Constants.DrawingBoard.NODE_PREFIX + nodeToEdit + Constants.DrawingBoard.CONTEXT_MENU_BUTTON;
553         GeneralUIUtils.hoverOnAreaByTestId(buttonOfEdit);
554         Click.byTestId(buttonOfEdit);
555         Click.byTestId(Constants.DrawingBoard.CONTEXT_MENU_ITEM);
556     }
557
558     private void createVfModule(String vfModuleName, boolean isInstanceNameGenerated, boolean vgEnabled, int vgMin,
559                                 int vgMax, List<String> vfModuleDynamicFields, String serviceInstanceName) {
560         String setButtonTestId = "vnf-form-set";
561         BrowseASDCPage browseASDCPage = new BrowseASDCPage();
562 //        Click.byTestId(Constants.DrawingBoard.NODE_PREFIX + vnfName);
563         drawingBoardPage.clickAddButtonByNodeName(vfModuleName);
564         if (!isInstanceNameGenerated) {
565             Input.text("VF instance name", "instanceName");
566         } else {
567             Assert.assertNull(Get.byTestId("instanceName"));
568             Assert.assertNull(Get.byTestId("volumeGroupName"));
569
570         }
571         if (vgEnabled && !isInstanceNameGenerated) {
572             browseASDCPage.setInputText("volumeGroupName", "some group name name");
573         } else {
574             Assert.assertNull(Get.byTestId("volumeGroupName"), "volumeGroupName input should be invisible when vgEnabled == false");
575         }
576         Wait.waitByTestId("model-item-value-subscriberName", 10);
577         Assert.assertEquals(Get.byTestId("model-item-value-subscriberName").getText(), "USP VOICE", "Subscriber name should be shown in vf module");
578         Assert.assertEquals(Get.byTestId("model-item-value-min").getText(), Integer.toString(vgMin), "Min should be shown");
579         Assert.assertEquals(Get.byTestId("model-item-value-max").getText(), Integer.toString(vgMax), "Max should be shown");
580         if (!isInstanceNameGenerated) {
581             Wait.byText(serviceInstanceName);
582             Assert.assertEquals(Get.byTestId("model-item-value-serviceName").getText(), serviceInstanceName, "Service name should be shown in vf module");
583         }
584         validateDynamicFields(vfModuleDynamicFields);
585
586         browseASDCPage.screenshotDeployDialog("createVfModule-" + serviceInstanceName);
587         Click.byTestId(setButtonTestId);
588     }
589
590     private void assertPauseOnPausePointsVisibility(boolean visibility) {
591         WebElement pauseElem = Get.byId("pause");
592         final String assertionMessage = "pause on pause points visibility should be " + visibility;
593         if (visibility) {
594             Assert.assertNotNull(pauseElem, assertionMessage);
595         } else {
596             Assert.assertNull(pauseElem, assertionMessage);
597         }
598     }
599
600     private void assertNotificationAreaVisibilityBehaviour() {
601         WebElement webElement = Get.byId("notification-area");
602         Assert.assertNull(webElement, "notification area should be invisible if only 1 qty.");
603
604         SelectOption.byIdAndVisibleText("quantity-select", "3");
605
606         webElement = Get.byId("notification-area");
607         Assert.assertNotNull(webElement, "notification area should be visible if more then 1 qty.");
608     }
609
610     /**
611      * following are two popup service models that represent two opposite/extreme states of the popup.
612      * they should be enough to test all the possible popup states.
613      */
614     private void loadMacroServicePopup_withDynamicFields_partialModelDetails_ecompNamingTrue() {
615         loadServicePopup("csar-withDynamicFields-ecompNamingTrue-partialModelDetails.zip", "2f80c596-27e5-4ca9-b5bb-e03a7fd4c0fd");
616     }
617
618     private void loadMacroServicePopup_noDynamicFields_fullModelDetails_ecompNamingFalse() {
619         loadServicePopup("csar-noDynamicFields-ecompNamingFalse-fullModelDetails-1a80c596.zip", "1a80c596-27e5-4ca9-b5bb-e03a7fd4c0fd");
620     }
621
622     @DataProvider
623     private Object[][] createSriovService(
624     ) {
625         List<String> dynamicFields = Arrays.asList(
626                 "2017488 adiodvpe0 VNF config template version:",
627                 "Adiodvpe0 bandwidth units:",
628                 "Adiodvpe0 bandwidth:",
629                 "2017488 adiodvpe0 aic clli:",
630                 "2017488 adiodvpe0 asn:",
631                 "2017488 adiodvpe0 VNF instance name");
632         ServiceData withEcompNaming = new ServiceData("csar-withDynamicFields-ecompNamingTrue-partialModelDetails.zip",
633                 "2f80c596-27e5-4ca9-b5bb-e03a7fd4c0fd",
634                 dynamicFields,
635                 true, true, true, false,
636                 "2017-488_ADIOD-vPE 0",
637                 "2017488_adiodvpe0..2017488AdiodVpe..ADIOD_vRE_BV..module-1", 0, 1, new ArrayList<>());
638         return new Object[][]{{withEcompNaming}};
639     }
640
641
642     private class ServiceData {
643
644         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) {
645             this.csarName = csarName;
646             this.modelUuid = modelUuid;
647             this.dynamicFields = dynamicFields;
648             this.isGeneratedNaming = isServiceGeneratedNaming;
649             this.multiStageDesign = multiStageDesign;
650             this.vnfData = new VnfData(vnfName, isVnfGeneratedNaming);
651             this.vfData = new VfData(vfName, isVgEnabled, vfMin, vfMax, vfModuleDynamicFields);
652         }
653
654         public String csarName;
655         public String modelUuid;
656         public List<String> dynamicFields;
657         public boolean isGeneratedNaming;
658         public boolean multiStageDesign;
659         public VnfData vnfData;
660         public VfData vfData;
661
662     }
663
664     private class VnfData {
665
666         public VnfData(String vnfName, boolean isGeneratedNaming) {
667             this.vnfName = vnfName;
668             this.isGeneratedNaming = isGeneratedNaming;
669         }
670
671         public String vnfName;
672         public boolean isGeneratedNaming;
673     }
674
675
676     private class VfData {
677         public VfData(String vfName, boolean vgEnabled, int vfMin, int vfMax, List<String> dynamicFields) {
678             this.vfName = vfName;
679             this.vgEnabled = vgEnabled;
680             this.vfMin = vfMin;
681             this.vfMax = vfMax;
682             this.dynamicFields = dynamicFields;
683         }
684
685         public int vfMin;
686
687         public int vfMax;
688
689         public String vfName;
690
691         public boolean vgEnabled;
692
693         public List<String> dynamicFields;
694
695     }
696
697
698     private class ServiceStatusChecker implements Predicate<Boolean> {
699         private String actualInstanceName;
700         private Set<String> expectedStatuses;
701         private Set<String> columnClassesSet;
702
703         public ServiceStatusChecker(String actualInstanceName, Set<String> expectedStatuses) {
704             this.actualInstanceName = actualInstanceName;
705             this.expectedStatuses = expectedStatuses;
706         }
707
708         @Override
709         public boolean test(Boolean noMeaning) {
710             InstantiationStatusPage.clickRefreshButton();
711             final WebElement row = InstantiationStatusPage.getInstantiationStatusRow(actualInstanceName);
712             if (row == null) {
713                 System.err.println("**********************" + actualInstanceName + "************************************************");
714                 columnClassesSet = Collections.singleton(actualInstanceName + " NOT FOUND");
715                 return false; // treat missing row as if test condition not fulfilled
716             } else {
717                 columnClassesSet = new HashSet<>(Arrays.asList(
718                         row.findElements(By.xpath(".//*[@id='" + "jobStatus" + "']")).get(0).getAttribute("class").split(" ")));
719                 return !(Sets.intersection(expectedStatuses, columnClassesSet).isEmpty());
720             }
721         }
722
723         public Set<String> getColumnClassesSet() {
724             return columnClassesSet;
725         }
726     }
727 }