1 package vid.automation.test.test;
3 import static java.util.Collections.emptySet;
4 import static java.util.Collections.singletonList;
5 import static java.util.stream.Collectors.groupingBy;
6 import static java.util.stream.Collectors.mapping;
7 import static java.util.stream.Collectors.toSet;
8 import static org.hamcrest.CoreMatchers.not;
9 import static org.hamcrest.Matchers.contains;
10 import static org.hamcrest.Matchers.containsInAnyOrder;
11 import static org.hamcrest.collection.IsEmptyCollection.empty;
12 import static org.hamcrest.core.Is.is;
13 import static org.junit.Assert.assertThat;
14 import static org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet.COMPLETE;
15 import static org.testng.Assert.assertEquals;
16 import static org.testng.AssertJUnit.fail;
17 import static vid.automation.test.utils.TestHelper.GET_SERVICE_MODELS_BY_DISTRIBUTION_STATUS;
18 import static vid.automation.test.utils.TestHelper.GET_TENANTS;
20 import com.fasterxml.jackson.databind.ObjectMapper;
21 import com.google.common.collect.ImmutableList;
23 import java.lang.reflect.Method;
25 import java.net.URISyntaxException;
26 import java.sql.Connection;
27 import java.sql.DriverManager;
28 import java.sql.ResultSet;
29 import java.sql.SQLException;
30 import java.sql.Statement;
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.List;
36 import java.util.concurrent.TimeUnit;
37 import org.apache.commons.lang3.StringUtils;
38 import org.glassfish.jersey.uri.internal.JerseyUriBuilder;
39 import org.junit.Assert;
40 import org.onap.sdc.ci.tests.datatypes.Configuration;
41 import org.onap.sdc.ci.tests.datatypes.UserCredentials;
42 import org.onap.sdc.ci.tests.execute.setup.SetupCDTest;
43 import org.onap.sdc.ci.tests.utilities.FileHandling;
44 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
45 import org.onap.simulator.presetGenerator.presets.BasePresets.BaseMSOPreset;
46 import org.onap.simulator.presetGenerator.presets.BasePresets.BasePreset;
47 import org.onap.simulator.presetGenerator.presets.aai.PresetAAICloudRegionAndSourceFromConfigurationPut;
48 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetNetworkZones;
49 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetPortMirroringSourcePorts;
50 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetServicesGet;
51 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubDetailsGet;
52 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubDetailsWithoutInstancesGet;
53 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
54 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetTenants;
55 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIPostNamedQueryForViewEdit;
56 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIServiceDesignAndCreationPut;
57 import org.onap.simulator.presetGenerator.presets.ecompportal_att.EcompPortalPresetsUtils;
58 import org.onap.simulator.presetGenerator.presets.ecompportal_att.PresetGetSessionSlotCheckIntervalGet;
59 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstanceGen2;
60 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstancePost;
61 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet;
62 import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceMetadataGet;
63 import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGet;
64 import org.openqa.selenium.By;
65 import org.openqa.selenium.JavascriptExecutor;
66 import org.openqa.selenium.WebElement;
67 import org.springframework.http.client.ClientHttpRequestInterceptor;
68 import org.springframework.web.client.RestTemplate;
69 import org.testng.ITestContext;
70 import org.testng.annotations.BeforeMethod;
71 import org.testng.annotations.BeforeSuite;
72 import org.testng.annotations.Listeners;
73 import org.testng.annotations.Test;
74 import vid.automation.reportportal.ReportPortalListenerDelegator;
75 import vid.automation.test.Constants;
76 import vid.automation.test.Constants.ViewEdit;
77 import vid.automation.test.infra.Click;
78 import vid.automation.test.infra.Exists;
79 import vid.automation.test.infra.Features;
80 import vid.automation.test.infra.Get;
81 import vid.automation.test.infra.ModelInfo;
82 import vid.automation.test.infra.SelectOption;
83 import vid.automation.test.infra.Wait;
84 import vid.automation.test.model.Credentials;
85 import vid.automation.test.model.User;
86 import vid.automation.test.sections.LoginExternalPage;
87 import vid.automation.test.sections.SearchExistingPage;
88 import vid.automation.test.sections.SideMenu;
89 import vid.automation.test.sections.VidBasePage;
90 import vid.automation.test.sections.ViewEditPage;
91 import vid.automation.test.sections.deploy.DeployModernUIMacroDialog;
92 import vid.automation.test.services.CategoryParamsService;
93 import vid.automation.test.services.SimulatorApi;
94 import vid.automation.test.services.UsersService;
95 import vid.automation.test.utils.CookieAndJsonHttpHeadersInterceptor;
96 import vid.automation.test.utils.DB_CONFIG;
97 import vid.automation.test.utils.InsecureHttpsClient;
98 import vid.automation.test.utils.TestConfigurationHelper;
99 import vid.automation.test.utils.TestHelper;
101 @Listeners(ReportPortalListenerDelegator.class)
102 public class VidBaseTestCase extends SetupCDTest{
104 protected final UsersService usersService = new UsersService();
105 protected final CategoryParamsService categoryParamsService = new CategoryParamsService();
106 protected final RestTemplate restTemplate = InsecureHttpsClient.newRestTemplate();
107 protected final URI uri;
108 protected final URI envUrI;
110 public VidBaseTestCase() {
112 this.envUrI = new URI(System.getProperty("ENV_URL"));
113 } catch (URISyntaxException e) {
114 throw new RuntimeException(e);
116 this.uri = new JerseyUriBuilder().host(envUrI.getHost()).port(envUrI.getPort()).scheme("http").path("vid").build();
119 public void login() {
120 UserCredentials userCredentials = getUserCredentials();
121 final List<ClientHttpRequestInterceptor> interceptors = singletonList(new CookieAndJsonHttpHeadersInterceptor(uri, userCredentials));
122 restTemplate.setInterceptors(interceptors);
125 public void invalidateSdcModelsCache() {
126 if (Features.FLAG_SERVICE_MODEL_CACHE.isActive()) {
127 restTemplate.postForObject(uri + "/rest/models/reset", "", Object.class);
131 protected void resetGetServicesCache() {
133 TestHelper.resetAaiCache(GET_SERVICE_MODELS_BY_DISTRIBUTION_STATUS, restTemplate, uri);
136 protected void resetGetTenantsCache() {
138 TestHelper.resetAaiCache(GET_TENANTS, restTemplate, uri);
142 protected UserCredentials getUserCredentials() {
143 ObjectMapper mapper = new ObjectMapper().enableDefaultTyping();
145 File configFile = FileHandling.getConfigFile("credentials");
146 if(!configFile.exists()) {
147 String basePath = System.getProperty("BASE_PATH");
148 configFile = new File( basePath + File.separator + "conf" + File.separator + "credentials");
150 Credentials credentials = mapper.readValue(configFile, Credentials.class);
151 User user = usersService.getUser(credentials.userId);
152 return new UserCredentials(user.credentials.userId, user.credentials.password, credentials.userId, "", "");
153 } catch (Exception e) {
160 protected Configuration getEnvConfiguration() {
162 return TestConfigurationHelper.getEnvConfiguration();
165 @BeforeMethod(alwaysRun = true)
166 public void setBrowserBeforeTestIfDataProvider(Method method, ITestContext context, Object[] params) {
167 // Hack to overcome limitations of SetupCDTest.setBrowserBeforeTest(java.lang.reflect.Method, org.testng.ITestContext)
168 // that skips over dataProvided methods
169 boolean emptyDataProvider = method.getAnnotation(Test.class).dataProvider().isEmpty();
170 if (!emptyDataProvider) {
171 final String testName = method.getName();
172 final String listOfParams = Arrays.deepToString(params)
175 .replaceAll("[\\\\/:*?\"<>|]", "_");
177 setLog(testName+listOfParams);
181 @BeforeSuite(alwaysRun = true)
182 public void screenShotsForReportPortal(){
184 ReportPortalListenerDelegator.setScreenShotsWebDriver(getDriver());
185 System.out.println("Called to ReportPortalListener to set ScreenShotsProvider");
186 } catch (Exception e) {
191 @BeforeSuite(alwaysRun = true)
192 public void setSmallDefaultTimeout() throws Exception {
193 getDriver().manage().timeouts().implicitlyWait(500, TimeUnit.MILLISECONDS);
197 protected void loginToLocalSimulator(UserCredentials userCredentials) {
198 LoginExternalPage.performLoginExternal(userCredentials);
201 protected void registerExpectationForLegacyServiceDeployment(ModelInfo modelInfo, String subscriberId) {
202 List<BasePreset> presets = new ArrayList<>(Arrays.asList(
203 new PresetAAIPostNamedQueryForViewEdit(BaseMSOPreset.DEFAULT_INSTANCE_ID, true, false),
204 new PresetAAIGetPortMirroringSourcePorts("9533-config-LB1113", "myRandomInterfaceId", ViewEdit.COMMON_PORT_MIRRORING_PORT_NAME, true)
207 presets.add(new PresetMSOCreateServiceInstancePost());
208 presets.add(new PresetMSOOrchestrationRequestGet(COMPLETE, false));
210 presets.addAll(getPresetForServiceBrowseAndDesign(ImmutableList.of(modelInfo), subscriberId));
212 SimulatorApi.registerExpectationFromPresets(presets, SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET);
215 protected void registerExpectationForServiceDeployment(List<ModelInfo> modelInfoList, String subscriberId, PresetMSOCreateServiceInstanceGen2 createServiceInstancePreset) {
216 List<BasePreset> presets = new ArrayList<>(Arrays.asList(
217 new PresetAAIPostNamedQueryForViewEdit(BaseMSOPreset.DEFAULT_INSTANCE_ID, true, false),
218 new PresetAAIGetPortMirroringSourcePorts("9533-config-LB1113", "myRandomInterfaceId", ViewEdit.COMMON_PORT_MIRRORING_PORT_NAME, true)
221 if (createServiceInstancePreset != null) {
222 presets.add(createServiceInstancePreset);
224 presets.add(new PresetMSOOrchestrationRequestGet("IN_PROGRESS"));
226 presets.addAll(getPresetForServiceBrowseAndDesign(modelInfoList, subscriberId));
228 SimulatorApi.registerExpectationFromPresets(presets, SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET);
231 protected void registerExpectationForServiceBrowseAndDesign(List<ModelInfo> modelInfoList, String subscriberId) {
232 SimulatorApi.registerExpectationFromPresets(getPresetForServiceBrowseAndDesign(modelInfoList, subscriberId), SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET);
235 protected List<BasePreset> getPresetForServiceBrowseAndDesign(List<ModelInfo> modelInfoList, String subscriberId) {
237 List<BasePreset> presets = new ArrayList<>(Arrays.asList(
238 new PresetGetSessionSlotCheckIntervalGet(),
239 new PresetAAIGetSubDetailsGet(subscriberId),
240 new PresetAAIGetSubDetailsWithoutInstancesGet(subscriberId),
241 new PresetAAIGetSubscribersGet(),
242 new PresetAAIGetServicesGet(),
243 new PresetAAICloudRegionAndSourceFromConfigurationPut("9533-config-LB1113", "myRandomCloudRegionId"),
244 new PresetAAIGetNetworkZones(),
245 new PresetAAIGetTenants(),
246 new PresetAAIServiceDesignAndCreationPut()
249 presets.addAll(EcompPortalPresetsUtils.getEcompPortalPresets());
251 modelInfoList.forEach(modelInfo -> {
252 presets.add(new PresetSDCGetServiceMetadataGet(modelInfo.modelVersionId, modelInfo.modelInvariantId, modelInfo.zipFileName));
253 presets.add(new PresetSDCGetServiceToscaModelGet(modelInfo.modelVersionId, modelInfo.zipFileName));
259 protected void relogin(Credentials credentials) {
260 // `getWindowTest().getPreviousUser()` is SetupCDTest's state of previous user used
261 if (!credentials.userId.equals(getWindowTest().getPreviousUser())) {
262 UserCredentials userCredentials = new UserCredentials(credentials.userId,
263 credentials.password, "", "", "");
264 reloginWithNewRole(userCredentials);
266 System.out.println(String.format("VidBaseTestCase.relogin() " +
267 "-> '%s' is already logged in, so skipping", credentials.userId));
272 * Validates that permitted options are enabled and others are disabled.
274 * @param permittedItems the list of permitted items.
275 * @param dropdownOptionsClassName the class name of the specific dropdown options.
276 * @return true, if all dropdown options disabled state is according to the permissions.
278 protected void assertDropdownPermittedItemsByValue(ArrayList<String> permittedItems, String dropdownOptionsClassName) {
279 assertDropdownPermittedItemsByValue(permittedItems, dropdownOptionsClassName, "value");
282 protected void assertDropdownPermittedItemsByLabel(ArrayList<String> permittedItems, String dropdownOptionsClassName) {
283 assertDropdownPermittedItemsByValue(permittedItems, dropdownOptionsClassName, "label");
287 * Validates that permitted options are enabled and others are disabled.
289 * @param permittedItems the list of permitted items.
290 * @param dropdownOptionsClassName the class name of the specific dropdown options.
292 * @return true, if all dropdown options disabled state is according to the permissions.
294 private void assertDropdownPermittedItemsByValue(ArrayList<String> permittedItems, String dropdownOptionsClassName, String attribute) {
295 GeneralUIUtils.ultimateWait();
296 List<WebElement> optionsList =
297 GeneralUIUtils.getWebElementsListBy(By.className(dropdownOptionsClassName), 30);
299 final Map<Boolean, Set<String>> optionsMap = optionsList.stream()
300 .collect(groupingBy(WebElement::isEnabled, mapping(option -> option.getAttribute(attribute), toSet())));
302 assertGroupedPermissionsAreCorrect(permittedItems, optionsMap);
305 private void assertGroupedPermissionsAreCorrect(ArrayList<String> permittedItems, Map<Boolean, Set<String>> optionsMap) {
306 if (permittedItems.isEmpty()) {
307 assertThat(Constants.DROPDOWN_PERMITTED_ASSERT_FAIL_MESSAGE, optionsMap.getOrDefault(Boolean.TRUE, emptySet()), is(empty()));
309 assertThat(Constants.DROPDOWN_PERMITTED_ASSERT_FAIL_MESSAGE, optionsMap.getOrDefault(Boolean.TRUE, emptySet()), containsInAnyOrder(permittedItems.toArray()));
310 assertThat(Constants.DROPDOWN_PERMITTED_ASSERT_FAIL_MESSAGE, optionsMap.getOrDefault(Boolean.FALSE, emptySet()), not(contains(permittedItems.toArray())));
314 protected void assertAllIsPermitted(String dropdownOptionsClassName) {
315 GeneralUIUtils.ultimateWait();
316 List<WebElement> optionsList =
317 GeneralUIUtils.getWebElementsListBy(By.className(dropdownOptionsClassName), 30);
318 for (WebElement option :
320 //String optionValue = option.getAttribute("value");
321 if (!option.isEnabled()) {
322 fail(Constants.DROPDOWN_PERMITTED_ASSERT_FAIL_MESSAGE);
327 protected void assertDropdownPermittedItemsByName(ArrayList<String> permittedItems, String dropdownOptionsClassName) {
328 GeneralUIUtils.ultimateWait();
329 List<WebElement> optionsList =
330 GeneralUIUtils.getWebElementsListBy(By.className(dropdownOptionsClassName), 30);
332 final Map<Boolean, Set<String>> optionsMap = optionsList.stream()
333 .collect(groupingBy(WebElement::isEnabled, mapping(WebElement::getText, toSet())));
335 assertGroupedPermissionsAreCorrect(permittedItems, optionsMap);
338 protected void assertViewEditButtonState(String expectedButtonText, String UUID) {
339 WebElement viewEditWebElement = GeneralUIUtils.getWebElementByTestID(Constants.VIEW_EDIT_TEST_ID_PREFIX + UUID, 100);
340 Assert.assertEquals(expectedButtonText, viewEditWebElement.getText());
341 GeneralUIUtils.ultimateWait();
345 protected void addNetwork(Map<String, String> metadata,String instanceName, String name, String lcpRegion, String cloudOwner, String productFamily,String platform, String lineOfBusiness, String tenant, String suppressRollback,
346 String legacyRegion, ArrayList<String> permittedTenants) {
347 ViewEditPage viewEditPage = new ViewEditPage();
349 viewEditPage.selectNetworkToAdd(name);
350 assertModelInfo(metadata, false);
351 viewEditPage.setInstanceName(instanceName);
352 viewEditPage.selectLcpRegion(lcpRegion, cloudOwner);
353 viewEditPage.selectProductFamily(productFamily);
354 viewEditPage.selectLineOfBusiness(lineOfBusiness);
355 assertDropdownPermittedItemsByValue(permittedTenants, Constants.ViewEdit.TENANT_OPTION_CLASS);
356 viewEditPage.selectTenant(tenant);
358 viewEditPage.selectSuppressRollback(suppressRollback);
359 if(platform != null){
360 viewEditPage.selectPlatform(platform);
362 viewEditPage.clickConfirmButton();
363 viewEditPage.assertMsoRequestModal(Constants.ViewEdit.MSO_SUCCESSFULLY_TEXT);
364 viewEditPage.clickCloseButton();
365 GeneralUIUtils.ultimateWait();
368 void assertSuccessfulVNFCreation() {
369 boolean byText = GeneralUIUtils.findAndWaitByText(Constants.ViewEdit.VNF_CREATED_SUCCESSFULLY_TEXT, 100);
370 Assert.assertTrue(Constants.ViewEdit.VNF_CREATION_FAILED_MESSAGE, byText);
373 void assertSuccessfulPNFAssociation() {
375 boolean byText = GeneralUIUtils.findAndWaitByText(Constants.PnfAssociation.PNF_ASSOCIATED_SUCCESSFULLY_TEXT, 100);
376 Assert.assertTrue(Constants.PnfAssociation.PNF_ASSOCIATED_FAILED_MESSAGE, byText);
378 void assertSuccessfulVolumeGroupCreation() {
379 boolean byText = GeneralUIUtils.findAndWaitByText(Constants.ViewEdit.VOLUME_GROUP_CREATED_SUCCESSFULLY_TEXT, 100);
380 Assert.assertTrue(Constants.ViewEdit.VOLUME_GROUP_CREATION_FAILED_MESSAGE, byText);
383 void assertSuccessfulVFModuleCreation() {
384 boolean byText = GeneralUIUtils.findAndWaitByText(Constants.ViewEdit.VF_MODULE_CREATED_SUCCESSFULLY_TEXT, 100);
385 Assert.assertTrue(Constants.ViewEdit.VF_MODULE_CREATION_FAILED_MESSAGE, byText);
388 //@Step("${method}: ${instanceUUID}")
389 void goToExistingInstanceById(String instanceUUID) {
390 SearchExistingPage searchExistingPage = searchExistingInstanceById(instanceUUID);
391 assertViewEditButtonState( Constants.VIEW_EDIT_BUTTON_TEXT, instanceUUID);
393 searchExistingPage.clickEditViewByInstanceId(instanceUUID);
394 GeneralUIUtils.ultimateWait();
397 void searchForExistingInstanceByIdReadonlyMode(String instanceUUID) {
398 searchExistingInstanceById(instanceUUID);
399 assertViewEditButtonState( Constants.VIEW_BUTTON_TEXT, instanceUUID);
402 SearchExistingPage searchExistingInstanceById(String instanceUUID){
403 SearchExistingPage searchExistingPage = new SearchExistingPage();
404 SideMenu.navigateToSearchExistingPage();
405 searchExistingPage.searchForInstanceByUuid(instanceUUID);
406 return searchExistingPage;
410 void goToExistingInstanceByIdNoWait(String instanceUUID) {
411 SearchExistingPage searchExistingPage = searchExistingInstanceById(instanceUUID);
412 searchExistingPage.clickEditViewByInstanceId(instanceUUID);
415 void resumeVFModule(String vfModuleName, String lcpRegion, String cloudOwner, String tenant, String legacyRegion, ArrayList<String> permittedTenants){
416 ViewEditPage viewEditPage = new ViewEditPage();
417 viewEditPage.clickResumeButton(vfModuleName);
418 viewEditPage.selectLcpRegion(lcpRegion, cloudOwner);
419 assertDropdownPermittedItemsByValue(permittedTenants, Constants.ViewEdit.TENANT_OPTION_CLASS);
420 viewEditPage.selectTenant(tenant);
421 viewEditPage.setLegacyRegion(legacyRegion);
422 viewEditPage.clickConfirmButtonInResumeDelete();
423 assertSuccessfulVFModuleCreation();
424 viewEditPage.clickCommitCloseButton();
425 GeneralUIUtils.ultimateWait();
428 void goToExistingInstanceByName(String instanceName) {
429 SearchExistingPage searchExistingPage = new SearchExistingPage();
430 SideMenu.navigateToSearchExistingPage();
431 searchExistingPage.searchForInstanceByName(instanceName);
432 WebElement instanceIdRow = GeneralUIUtils.getWebElementByTestID(Constants.INSTANCE_ID_FOR_NAME_TEST_ID_PREFIX + instanceName, 30);
433 String instanceId = instanceIdRow.getText();
434 assertViewEditButtonState( Constants.VIEW_EDIT_BUTTON_TEXT, instanceId);
435 searchExistingPage.clickEditViewByInstanceId(instanceId);
436 GeneralUIUtils.ultimateWait();
439 String confirmFilterById(String instanceName, String instanceUUID) {
440 WebElement filter = GeneralUIUtils.getWebElementByTestID(Constants.FILTER_SUBSCRIBER_DETAILS_ID, 30);
441 filter.sendKeys(instanceUUID);
443 WebElement firstElement = GeneralUIUtils.getWebElementByTestID(Constants.INSTANCE_ID_FOR_NAME_TEST_ID_PREFIX + instanceName, 30);
444 String filteredId = firstElement.getText();
445 Assert.assertTrue(filteredId.equals(instanceUUID));
449 void goToExistingInstanceBySubscriber(String subscriberName,String instanceName,String instanceUUID) {
450 SearchExistingPage searchExistingPage = new SearchExistingPage();
451 SideMenu.navigateToSearchExistingPage();
452 SelectOption.byIdAndVisibleText(Constants.EditExistingInstance.SELECT_SUBSCRIBER, subscriberName);
453 searchExistingPage.clickSubmitButton();
454 GeneralUIUtils.ultimateWait();
455 confirmFilterById(instanceName, instanceUUID);
456 searchExistingPage.clickEditViewByInstanceId(instanceUUID);
457 GeneralUIUtils.ultimateWait();
460 void selectMsoTestApiOption(String msoTestApiOption) {
461 final String id = "selectTestApi";
462 final String sectionId = "selectTestApiSection";
464 SideMenu.navigateToWelcomePage();
466 if (Exists.byId(sectionId)) {
467 final JavascriptExecutor javascriptExecutor = (JavascriptExecutor) GeneralUIUtils.getDriver();
468 javascriptExecutor.executeScript(
469 "document.getElementById('" + sectionId + "').style.visibility = 'inherit';"
472 if (null == SelectOption.byIdAndVisibleText(id, msoTestApiOption)) {
473 Assert.fail("selectMsoTestApiOptionIfPossible couldnt apply " + msoTestApiOption);
478 protected void assertModelInfo(Map<String, String> expectedMetadata, boolean withPrefix) {
479 Wait.angularHttpRequestsLoaded();
480 GeneralUIUtils.ultimateWait();
481 for (Map.Entry<String, String> item: expectedMetadata.entrySet()) {
482 assertMetadataItem(item.getKey(), item.getValue(), withPrefix);
486 protected <T> void assertModelDataCorrect(Map<String, String> modelKeyToDataTestsIdMap, String prefix, T model) {
487 modelKeyToDataTestsIdMap.forEach((fieldName, dataTestsId) -> {
488 WebElement webElement = Get.byTestId(prefix + dataTestsId);
489 assertEquals(webElement.getText(), getServiceFieldByName(fieldName, model));
493 protected <T> void setNewInstance_leftPane_assertModelLabelsVisibilityCorrect(Map<String, String> modelKeyToDataTestsIdMap, String prefix, T model) {
494 modelKeyToDataTestsIdMap.forEach((fieldName, dataTestsId) -> {
495 WebElement webElement = Get.byTestId(prefix + dataTestsId);
496 String field = getServiceFieldByName(fieldName, model);
497 assertEquals(webElement.isDisplayed(), !(StringUtils.isEmpty(field)) , dataTestsId + " label shouldn't appear when " + fieldName + " is empty");
501 private <T> String getServiceFieldByName(String name, T model) {
503 return model.getClass().getField(name).get(model).toString();
504 } catch (IllegalAccessException | NoSuchFieldException e) {
505 throw new RuntimeException(e);
509 private void assertMetadataItem(String keyTestId, String value, boolean withPrefix) {
510 String elementTestId = (withPrefix ? Constants.ServiceModelInfo.INFO_TEST_ID_PREFIX:"") + keyTestId;
511 String infoItemText = GeneralUIUtils.getWebElementByTestID(elementTestId, 60).getText();
512 assertThat(String.format(Constants.ServiceModelInfo.METADETA_ERROR_MESSAGE, elementTestId), infoItemText, is(value));
515 protected void loadServicePopup(ModelInfo modelInfo) {
516 loadServicePopup(modelInfo.modelVersionId);
520 protected void loadServicePopup(String modelVersionId) {
521 SideMenu.navigateToBrowseASDCPage();
522 GeneralUIUtils.ultimateWait();
523 loadServicePopupOnBrowseASDCPage(modelVersionId);
526 protected void loadServicePopupOnBrowseASDCPage(String modelVersionId ) {
527 DeployModernUIMacroDialog deployMacroDialog = new DeployModernUIMacroDialog();
528 VidBasePage.goOutFromIframe();
529 deployMacroDialog.clickDeployServiceButtonByServiceUUID(modelVersionId);
530 deployMacroDialog.goToIframe();
531 GeneralUIUtils.ultimateWait();
532 Wait.byText("Model version");
535 public void assertSetButtonDisabled(String buttonTestId) {
536 WebElement webElement = Get.byTestId(buttonTestId);
537 org.testng.Assert.assertFalse(webElement.isEnabled(), "Set button should be disabled if not all mandatory fields are field.");
540 public void assertSetButtonEnabled(String buttonTestId) {
542 WebElement webElement = Get.byTestId(buttonTestId);
543 org.testng.Assert.assertTrue(webElement.isEnabled(), "Set button should be enabled if all mandatory fields are field.");
546 public void assertElementDisabled(String id) {
547 WebElement webElement = Get.byId(id);
548 assert webElement != null;
549 org.testng.Assert.assertFalse(webElement.isEnabled(), "field should be disabled if the field it depends on was not selected yet.");
552 public boolean isElementByIdRequired(String id) {
553 return Get.byId(id).getAttribute("class").contains("required");
556 protected int getUserIdNumberFromDB(User user) {
557 try (Connection connection = DriverManager.getConnection(DB_CONFIG.url, DB_CONFIG.username, DB_CONFIG.password)) {
558 Statement stmt = connection.createStatement();
559 ResultSet userIdResultSet;
560 userIdResultSet = stmt.executeQuery("SELECT USER_ID FROM fn_user where LOGIN_ID = '" + user.credentials.userId + "'");
561 Assert.assertTrue("Exactly one user should be found", userIdResultSet.next());
562 int userId = userIdResultSet.getInt("USER_ID");
563 Assert.assertFalse("There are more than one user for id " + userId, userIdResultSet.next());
565 } catch (SQLException e) {
566 throw new IllegalStateException("Cannot connect the database!", e);
570 protected List<Integer> getRoleIDsAssignedToUser(int userId) {
571 try (Connection connection = DriverManager.getConnection(DB_CONFIG.url, DB_CONFIG.username, DB_CONFIG.password)) {
572 Statement stmt = connection.createStatement();
573 ResultSet userRolesResultSet;
574 userRolesResultSet = stmt.executeQuery("SELECT ROLE_ID FROM fn_user_role where USER_ID = '" + userId + "' order by ROLE_ID");
576 List<Integer> userRoles = new ArrayList<Integer>();
577 while (userRolesResultSet.next()) {
578 userRoles.add(userRolesResultSet.getInt("ROLE_ID"));
581 } catch (SQLException e) {
582 throw new IllegalStateException("Cannot connect the database!", e);
586 protected void navigateToViewEditPageOfuspVoiceVidTest444(String aaiModelVersionId) {
587 navigateToViewEditPage("3f93c7cb-2fd0-4557-9514-e189b7b04f9d", aaiModelVersionId);
590 protected void navigateToViewEditPageOf_test_sssdad() {
591 navigateToViewEditPage("c187e9fe-40c3-4862-b73e-84ff056205f6", "ee6d61be-4841-4f98-8f23-5de9da846ca7");
594 protected void navigateToViewEditPage(final String serviceInstanceId, String aaiModelVersionId) {
595 VidBasePage vidBasePage = new VidBasePage();
596 SideMenu.navigateToWelcomePage();
597 vidBasePage.navigateTo("serviceModels.htm#/instantiate?" +
598 "subscriberId=e433710f-9217-458d-a79d-1c7aff376d89&" +
599 "subscriberName=SILVIA%20ROBBINS&" +
600 "serviceType=TYLER%20SILVIA&" +
601 "serviceInstanceId=" + serviceInstanceId + "&" +
602 "aaiModelVersionId=" + aaiModelVersionId + "&" +
604 GeneralUIUtils.ultimateWait();
608 public void hoverAndClickMenuByName(String nodeName, String nodeToEdit, String contextMenuItem ) {
609 String buttonOfEdit = Constants.DrawingBoard.NODE_PREFIX + nodeToEdit + Constants.DrawingBoard.CONTEXT_MENU_BUTTON;
611 WebElement rightTreeNode = getTreeNodeByName(nodeName);
612 WebElement menuButton = Get.byXpath(rightTreeNode, ".//span[@data-tests-id='" + buttonOfEdit + "']");
614 GeneralUIUtils.clickElementUsingActions(menuButton);
615 Click.byTestId(contextMenuItem);
618 private WebElement getTreeNodeByName(String nodeName) {
619 return Get.byXpath("//tree-node-content[.//*[contains(text(), '" + nodeName + "')]]");