1 package vid.automation.test.test;
3 import com.fasterxml.jackson.databind.ObjectMapper;
4 import com.google.common.collect.ImmutableList;
5 import org.apache.commons.lang3.StringUtils;
6 import org.glassfish.jersey.uri.internal.JerseyUriBuilder;
7 import org.junit.Assert;
8 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubDetailsGet;
9 import org.onap.simulator.presetGenerator.presets.BasePresets.BaseMSOPreset;
10 import org.onap.simulator.presetGenerator.presets.BasePresets.BasePreset;
11 import org.onap.simulator.presetGenerator.presets.aai.PresetAAICloudRegionAndSourceFromConfigurationPut;
12 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetNetworkZones;
13 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetPortMirroringSourcePorts;
14 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetServicesGet;
15 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubDetailsWithoutInstancesGet;
16 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
17 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetTenants;
18 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIPostNamedQueryForViewEdit;
19 import org.onap.simulator.presetGenerator.presets.aai.PresetAAIServiceDesignAndCreationPut;
20 import org.onap.simulator.presetGenerator.presets.ecompportal_att.EcompPortalPresetsUtils;
21 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstanceGen2;
22 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOCreateServiceInstancePost;
23 import org.onap.simulator.presetGenerator.presets.mso.PresetMSOOrchestrationRequestGet;
24 import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceMetadataGet;
25 import org.onap.simulator.presetGenerator.presets.sdc.PresetSDCGetServiceToscaModelGet;
26 import org.onap.sdc.ci.tests.datatypes.UserCredentials;
27 import org.onap.sdc.ci.tests.execute.setup.SetupCDTest;
28 import org.onap.sdc.ci.tests.utilities.FileHandling;
29 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
30 import org.openqa.selenium.By;
31 import org.openqa.selenium.JavascriptExecutor;
32 import org.openqa.selenium.WebElement;
33 import org.springframework.http.client.ClientHttpRequestInterceptor;
34 import org.springframework.web.client.RestTemplate;
35 import org.testng.ITestContext;
36 import org.testng.annotations.BeforeMethod;
37 import org.testng.annotations.BeforeSuite;
38 import org.testng.annotations.Test;
39 import vid.automation.test.Constants;
40 import vid.automation.test.infra.*;
41 import vid.automation.test.model.Credentials;
42 import vid.automation.test.model.User;
43 import vid.automation.test.sections.*;
44 import vid.automation.test.services.CategoryParamsService;
45 import vid.automation.test.services.SimulatorApi;
46 import vid.automation.test.services.UsersService;
47 import vid.automation.test.utils.CookieAndJsonHttpHeadersInterceptor;
48 import vid.automation.test.utils.DB_CONFIG;
49 import vid.automation.test.utils.TestConfigurationHelper;
50 import vid.automation.test.utils.TestHelper;
53 import java.lang.reflect.Method;
55 import java.net.URISyntaxException;
58 import java.util.concurrent.TimeUnit;
60 import static java.util.Collections.emptySet;
61 import static java.util.Collections.singletonList;
62 import static java.util.stream.Collectors.*;
63 import static org.hamcrest.CoreMatchers.not;
64 import static org.hamcrest.Matchers.contains;
65 import static org.hamcrest.Matchers.containsInAnyOrder;
66 import static org.hamcrest.collection.IsEmptyCollection.empty;
67 import static org.hamcrest.core.Is.is;
68 import static org.junit.Assert.assertThat;
69 import static org.testng.Assert.assertEquals;
70 import static org.testng.AssertJUnit.fail;
71 import static vid.automation.test.utils.TestHelper.GET_SERVICE_MODELS_BY_DISTRIBUTION_STATUS;
72 import static vid.automation.test.utils.TestHelper.GET_TENANTS;
74 public class VidBaseTestCase extends SetupCDTest{
76 protected final UsersService usersService = new UsersService();
77 protected final CategoryParamsService categoryParamsService = new CategoryParamsService();
78 protected final RestTemplate restTemplate = new RestTemplate();
79 protected final URI uri;
80 protected final URI envUrI;
82 public VidBaseTestCase() {
84 this.envUrI = new URI(System.getProperty("ENV_URL"));
85 } catch (URISyntaxException e) {
86 throw new RuntimeException(e);
88 this.uri = new JerseyUriBuilder().host(envUrI.getHost()).port(envUrI.getPort()).scheme("http").path("vid").build();
92 UserCredentials userCredentials = getUserCredentials();
93 final List<ClientHttpRequestInterceptor> interceptors = singletonList(new CookieAndJsonHttpHeadersInterceptor(uri, userCredentials));
94 restTemplate.setInterceptors(interceptors);
97 public void invalidateSdcModelsCache() {
98 if (Features.FLAG_SERVICE_MODEL_CACHE.isActive()) {
99 restTemplate.postForObject(uri + "/rest/models/reset", "", Object.class);
103 protected void resetGetServicesCache() {
105 TestHelper.resetAaiCache(GET_SERVICE_MODELS_BY_DISTRIBUTION_STATUS, restTemplate, uri);
108 protected void resetGetTenantsCache() {
110 TestHelper.resetAaiCache(GET_TENANTS, restTemplate, uri);
114 protected UserCredentials getUserCredentials() {
115 ObjectMapper mapper = new ObjectMapper().enableDefaultTyping();
117 File configFile = FileHandling.getConfigFile("credentials");
118 if(!configFile.exists()) {
119 String basePath = System.getProperty("BASE_PATH");
120 configFile = new File( basePath + File.separator + "conf" + File.separator + "credentials");
122 Credentials credentials = mapper.readValue(configFile, Credentials.class);
123 User user = usersService.getUser(credentials.userId);
124 return new UserCredentials(user.credentials.userId, user.credentials.password, credentials.userId, "", "");
125 } catch (Exception e) {
132 protected org.onap.sdc.ci.tests.datatypes.Configuration getEnvConfiguration() {
134 return TestConfigurationHelper.getEnvConfiguration();
137 @BeforeMethod(alwaysRun = true)
138 public void setBrowserBeforeTestIfDataProvider(Method method, ITestContext context, Object[] params) {
139 // Hack to overcome limitations of SetupCDTest.setBrowserBeforeTest(java.lang.reflect.Method, org.testng.ITestContext)
140 // that skips over dataProvided methods
141 boolean emptyDataProvider = method.getAnnotation(Test.class).dataProvider().isEmpty();
142 if (!emptyDataProvider) {
143 final String testName = method.getName();
144 final String listOfParams = Arrays.deepToString(params)
147 .replaceAll("[\\\\/:*?\"<>|]", "_");
149 setLog(testName+listOfParams);
153 @BeforeSuite(alwaysRun = true)
154 public void screenShotsForReportPortal(){
156 //ReportPortalListener.setScreenShotsProvider(new WebDriverScreenshotsProvider(getDriver()));
157 System.out.println("Called to ReportPortalListener to set ScreenShotsProvider");
158 } catch (Exception e) {
163 @BeforeSuite(alwaysRun = true)
164 public void setSmallDefaultTimeout() throws Exception {
165 getDriver().manage().timeouts().implicitlyWait(250, TimeUnit.MILLISECONDS);
169 protected void loginToLocalSimulator(UserCredentials userCredentials) {
170 LoginExternalPage.performLoginExternal(userCredentials);
173 protected String getReduxState() {
174 final JavascriptExecutor javascriptExecutor = (JavascriptExecutor) GeneralUIUtils.getDriver();
175 String reduxState = (String)javascriptExecutor.executeScript("return window.sessionStorage.getItem('reduxState');");
176 System.out.println(reduxState);
180 protected void setReduxState(String state) {
181 final JavascriptExecutor javascriptExecutor = (JavascriptExecutor) GeneralUIUtils.getDriver();
182 String script = String.format("window.sessionStorage.setItem('reduxState', '%s');", state);
183 System.out.println("executing script:");
184 System.out.println(script);
185 javascriptExecutor.executeScript(script);
188 protected void registerExpectationForLegacyServiceDeployment(ModelInfo modelInfo, String subscriberId) {
189 List<BasePreset> presets = new ArrayList<>(Arrays.asList(
190 new PresetAAIPostNamedQueryForViewEdit(BaseMSOPreset.DEFAULT_INSTANCE_ID, true, false),
191 new PresetAAIGetPortMirroringSourcePorts("9533-config-LB1113", "myRandomInterfaceId", "i'm a port", true)
194 presets.add(new PresetMSOCreateServiceInstancePost());
195 presets.add(new PresetMSOOrchestrationRequestGet());
197 presets.addAll(getPresetForServiceBrowseAndDesign(ImmutableList.of(modelInfo), subscriberId));
199 SimulatorApi.registerExpectationFromPresets(presets, SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET);
202 protected void registerExpectationForServiceDeployment(List<ModelInfo> modelInfoList, String subscriberId, PresetMSOCreateServiceInstanceGen2 createServiceInstancePreset) {
203 List<BasePreset> presets = new ArrayList<>(Arrays.asList(
204 new PresetAAIPostNamedQueryForViewEdit(BaseMSOPreset.DEFAULT_INSTANCE_ID, true, false),
205 new PresetAAIGetPortMirroringSourcePorts("9533-config-LB1113", "myRandomInterfaceId", "i'm a port", true)
208 if (createServiceInstancePreset != null) {
209 presets.add(createServiceInstancePreset);
211 presets.add(new PresetMSOOrchestrationRequestGet("IN_PROGRESS"));
213 presets.addAll(getPresetForServiceBrowseAndDesign(modelInfoList, subscriberId));
215 SimulatorApi.registerExpectationFromPresets(presets, SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET);
218 protected void registerExpectationForServiceBrowseAndDesign(List<ModelInfo> modelInfoList, String subscriberId) {
219 SimulatorApi.registerExpectationFromPresets(getPresetForServiceBrowseAndDesign(modelInfoList, subscriberId), SimulatorApi.RegistrationStrategy.CLEAR_THEN_SET);
222 protected List<BasePreset> getPresetForServiceBrowseAndDesign(List<ModelInfo> modelInfoList, String subscriberId) {
224 List<BasePreset> presets = new ArrayList<>(Arrays.asList(
225 new PresetAAIGetSubDetailsGet(subscriberId),
226 new PresetAAIGetSubDetailsWithoutInstancesGet(subscriberId),
227 new PresetAAIGetSubscribersGet(),
228 new PresetAAIGetServicesGet(),
229 new PresetAAICloudRegionAndSourceFromConfigurationPut("9533-config-LB1113", "myRandomCloudRegionId"),
230 new PresetAAIGetNetworkZones(),
231 new PresetAAIGetTenants(),
232 new PresetAAIServiceDesignAndCreationPut()
235 presets.addAll(EcompPortalPresetsUtils.getEcompPortalPresets());
237 modelInfoList.forEach(modelInfo -> {
238 presets.add(new PresetSDCGetServiceMetadataGet(modelInfo.modelVersionId, modelInfo.modelInvariantId, modelInfo.zipFileName));
239 presets.add(new PresetSDCGetServiceToscaModelGet(modelInfo.modelVersionId, modelInfo.zipFileName));
245 protected void relogin(Credentials credentials) throws Exception {
246 // `getWindowTest().getPreviousUser()` is SetupCDTest's state of previous user used
247 if (!credentials.userId.equals(getWindowTest().getPreviousUser())) {
248 UserCredentials userCredentials = new UserCredentials(credentials.userId,
249 credentials.password, "", "", "");
250 reloginWithNewRole(userCredentials);
252 System.out.println(String.format("VidBaseTestCase.relogin() " +
253 "-> '%s' is already logged in, so skipping", credentials.userId));
258 * Validates that permitted options are enabled and others are disabled.
260 * @param permittedItems the list of permitted items.
261 * @param dropdownOptionsClassName the class name of the specific dropdown options.
262 * @return true, if all dropdown options disabled state is according to the permissions.
264 protected void assertDropdownPermittedItemsByValue(ArrayList<String> permittedItems, String dropdownOptionsClassName) {
265 assertDropdownPermittedItemsByValue(permittedItems, dropdownOptionsClassName, "value");
268 protected void assertDropdownPermittedItemsByLabel(ArrayList<String> permittedItems, String dropdownOptionsClassName) {
269 assertDropdownPermittedItemsByValue(permittedItems, dropdownOptionsClassName, "label");
273 * Validates that permitted options are enabled and others are disabled.
275 * @param permittedItems the list of permitted items.
276 * @param dropdownOptionsClassName the class name of the specific dropdown options.
278 * @return true, if all dropdown options disabled state is according to the permissions.
280 private void assertDropdownPermittedItemsByValue(ArrayList<String> permittedItems, String dropdownOptionsClassName, String attribute) {
281 GeneralUIUtils.ultimateWait();
282 List<WebElement> optionsList =
283 GeneralUIUtils.getWebElementsListBy(By.className(dropdownOptionsClassName), 30);
285 final Map<Boolean, Set<String>> optionsMap = optionsList.stream()
286 .collect(groupingBy(WebElement::isEnabled, mapping(option -> option.getAttribute(attribute), toSet())));
288 assertGroupedPermissionsAreCorrect(permittedItems, optionsMap);
291 private void assertGroupedPermissionsAreCorrect(ArrayList<String> permittedItems, Map<Boolean, Set<String>> optionsMap) {
292 if (permittedItems.isEmpty()) {
293 assertThat(Constants.DROPDOWN_PERMITTED_ASSERT_FAIL_MESSAGE, optionsMap.getOrDefault(Boolean.TRUE, emptySet()), is(empty()));
295 assertThat(Constants.DROPDOWN_PERMITTED_ASSERT_FAIL_MESSAGE, optionsMap.getOrDefault(Boolean.TRUE, emptySet()), containsInAnyOrder(permittedItems.toArray()));
296 assertThat(Constants.DROPDOWN_PERMITTED_ASSERT_FAIL_MESSAGE, optionsMap.getOrDefault(Boolean.FALSE, emptySet()), not(contains(permittedItems.toArray())));
300 protected void assertAllIsPermitted(String dropdownOptionsClassName) {
301 GeneralUIUtils.ultimateWait();
302 List<WebElement> optionsList =
303 GeneralUIUtils.getWebElementsListBy(By.className(dropdownOptionsClassName), 30);
304 for (WebElement option :
306 //String optionValue = option.getAttribute("value");
307 if (!option.isEnabled()) {
308 fail(Constants.DROPDOWN_PERMITTED_ASSERT_FAIL_MESSAGE);
313 protected void assertDropdownPermittedItemsByName(ArrayList<String> permittedItems, String dropdownOptionsClassName) {
314 GeneralUIUtils.ultimateWait();
315 List<WebElement> optionsList =
316 GeneralUIUtils.getWebElementsListBy(By.className(dropdownOptionsClassName), 30);
318 final Map<Boolean, Set<String>> optionsMap = optionsList.stream()
319 .collect(groupingBy(WebElement::isEnabled, mapping(WebElement::getText, toSet())));
321 assertGroupedPermissionsAreCorrect(permittedItems, optionsMap);
324 protected void assertViewEditButtonState(String expectedButtonText, String UUID) {
325 WebElement viewEditWebElement = GeneralUIUtils.getWebElementByTestID(Constants.VIEW_EDIT_TEST_ID_PREFIX + UUID, 100);
326 Assert.assertEquals(expectedButtonText, viewEditWebElement.getText());
327 GeneralUIUtils.ultimateWait();
331 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,
332 String legacyRegion, ArrayList<String> permittedTenants) {
333 ViewEditPage viewEditPage = new ViewEditPage();
335 viewEditPage.selectNetworkToAdd(name);
336 assertModelInfo(metadata, false);
337 viewEditPage.setInstanceName(instanceName);
338 viewEditPage.selectLcpRegion(lcpRegion, cloudOwner);
339 viewEditPage.selectProductFamily(productFamily);
340 viewEditPage.selectLineOfBusiness(lineOfBusiness);
341 assertDropdownPermittedItemsByValue(permittedTenants, Constants.ViewEdit.TENANT_OPTION_CLASS);
342 viewEditPage.selectTenant(tenant);
344 viewEditPage.selectSuppressRollback(suppressRollback);
345 viewEditPage.selectPlatform(platform);
346 //viewEditPage.setLegacyRegion(legacyRegion);
348 viewEditPage.clickConfirmButton();
349 viewEditPage.assertMsoRequestModal(Constants.ViewEdit.MSO_SUCCESSFULLY_TEXT);
350 viewEditPage.clickCloseButton();
351 GeneralUIUtils.ultimateWait();
354 void assertSuccessfulVNFCreation() {
355 boolean byText = GeneralUIUtils.findAndWaitByText(Constants.ViewEdit.VNF_CREATED_SUCCESSFULLY_TEXT, 100);
356 Assert.assertTrue(Constants.ViewEdit.VNF_CREATION_FAILED_MESSAGE, byText);
359 void assertSuccessfulPNFAssociation() {
361 boolean byText = GeneralUIUtils.findAndWaitByText(Constants.PnfAssociation.PNF_ASSOCIATED_SUCCESSFULLY_TEXT, 100);
362 Assert.assertTrue(Constants.PnfAssociation.PNF_ASSOCIATED_FAILED_MESSAGE, byText);
364 void assertSuccessfulVolumeGroupCreation() {
365 boolean byText = GeneralUIUtils.findAndWaitByText(Constants.ViewEdit.VOLUME_GROUP_CREATED_SUCCESSFULLY_TEXT, 100);
366 Assert.assertTrue(Constants.ViewEdit.VOLUME_GROUP_CREATION_FAILED_MESSAGE, byText);
369 void assertSuccessfulVFModuleCreation() {
370 boolean byText = GeneralUIUtils.findAndWaitByText(Constants.ViewEdit.VF_MODULE_CREATED_SUCCESSFULLY_TEXT, 100);
371 Assert.assertTrue(Constants.ViewEdit.VF_MODULE_CREATION_FAILED_MESSAGE, byText);
374 void goToExistingInstanceById(String instanceUUID) {
375 SearchExistingPage searchExistingPage = searchExistingInstanceById(instanceUUID);
376 assertViewEditButtonState( Constants.VIEW_EDIT_BUTTON_TEXT, instanceUUID);
378 searchExistingPage.clickEditViewByInstanceId(instanceUUID);
379 GeneralUIUtils.ultimateWait();
382 void searchForExistingInstanceByIdReadonlyMode(String instanceUUID) {
383 searchExistingInstanceById(instanceUUID);
384 assertViewEditButtonState( Constants.VIEW_BUTTON_TEXT, instanceUUID);
387 SearchExistingPage searchExistingInstanceById(String instanceUUID){
388 SearchExistingPage searchExistingPage = new SearchExistingPage();
389 SideMenu.navigateToSearchExistingPage();
390 searchExistingPage.searchForInstanceByUuid(instanceUUID);
391 return searchExistingPage;
395 void goToExistingInstanceByIdNoWait(String instanceUUID) {
396 SearchExistingPage searchExistingPage = searchExistingInstanceById(instanceUUID);
397 searchExistingPage.clickEditViewByInstanceId(instanceUUID);
400 void resumeVFModule(String vfModuleName, String lcpRegion, String cloudOwner, String tenant, String legacyRegion, ArrayList<String> permittedTenants){
401 ViewEditPage viewEditPage = new ViewEditPage();
402 viewEditPage.clickResumeButton(vfModuleName);
403 viewEditPage.selectLcpRegion(lcpRegion, cloudOwner);
404 assertDropdownPermittedItemsByValue(permittedTenants, Constants.ViewEdit.TENANT_OPTION_CLASS);
405 viewEditPage.selectTenant(tenant);
406 viewEditPage.setLegacyRegion(legacyRegion);
407 viewEditPage.clickConfirmButtonInResumeDelete();
408 assertSuccessfulVFModuleCreation();
409 viewEditPage.clickCommitCloseButton();
410 GeneralUIUtils.ultimateWait();
413 void goToExistingInstanceByName(String instanceName) {
414 SearchExistingPage searchExistingPage = new SearchExistingPage();
415 SideMenu.navigateToSearchExistingPage();
416 searchExistingPage.searchForInstanceByName(instanceName);
417 WebElement instanceIdRow = GeneralUIUtils.getWebElementByTestID(Constants.INSTANCE_ID_FOR_NAME_TEST_ID_PREFIX + instanceName, 30);
418 String instanceId = instanceIdRow.getText();
419 assertViewEditButtonState( Constants.VIEW_EDIT_BUTTON_TEXT, instanceId);
420 searchExistingPage.clickEditViewByInstanceId(instanceId);
421 GeneralUIUtils.ultimateWait();
424 String confirmFilterById(String instanceName, String instanceUUID) {
425 WebElement filter = GeneralUIUtils.getWebElementByTestID(Constants.FILTER_SUBSCRIBER_DETAILS_ID, 30);
426 filter.sendKeys(instanceUUID);
428 WebElement firstElement = GeneralUIUtils.getWebElementByTestID(Constants.INSTANCE_ID_FOR_NAME_TEST_ID_PREFIX + instanceName, 30);
429 String filteredId = firstElement.getText();
430 Assert.assertTrue(filteredId.equals(instanceUUID));
434 void goToExistingInstanceBySubscriber(String subscriberName,String instanceName,String instanceUUID) {
435 SearchExistingPage searchExistingPage = new SearchExistingPage();
436 SideMenu.navigateToSearchExistingPage();
437 SelectOption.byIdAndVisibleText(Constants.EditExistingInstance.SELECT_SUBSCRIBER, subscriberName);
438 searchExistingPage.clickSubmitButton();
439 GeneralUIUtils.ultimateWait();
440 confirmFilterById(instanceName, instanceUUID);
441 searchExistingPage.clickEditViewByInstanceId(instanceUUID);
442 GeneralUIUtils.ultimateWait();
445 void selectMsoTestApiOption(String msoTestApiOption) {
446 final String id = "selectTestApi";
447 final String sectionId = "selectTestApiSection";
449 SideMenu.navigateToWelcomePage();
451 if (Exists.byId(sectionId)) {
452 final JavascriptExecutor javascriptExecutor = (JavascriptExecutor) GeneralUIUtils.getDriver();
453 javascriptExecutor.executeScript(
454 "document.getElementById('" + sectionId + "').style.visibility = 'inherit';"
457 if (null == SelectOption.byIdAndVisibleText(id, msoTestApiOption)) {
458 Assert.fail("selectMsoTestApiOptionIfPossible couldnt apply " + msoTestApiOption);
463 protected void assertModelInfo(Map<String, String> expectedMetadata, boolean withPrefix) {
464 Wait.angularHttpRequestsLoaded();
465 GeneralUIUtils.ultimateWait();
466 for (Map.Entry<String, String> item: expectedMetadata.entrySet()) {
467 assertMetadataItem(item.getKey(), item.getValue(), withPrefix);
471 protected <T> void assertModelDataCorrect(Map<String, String> modelKeyToDataTestsIdMap, String prefix, T model) {
472 modelKeyToDataTestsIdMap.forEach((fieldName, dataTestsId) -> {
473 WebElement webElement = Get.byTestId(prefix + dataTestsId);
474 assertEquals(webElement.getText(), getServiceFieldByName(fieldName, model));
478 protected <T> void setNewInstance_leftPane_assertModelLabelsVisibilityCorrect(Map<String, String> modelKeyToDataTestsIdMap, String prefix, T model) {
479 modelKeyToDataTestsIdMap.forEach((fieldName, dataTestsId) -> {
480 WebElement webElement = Get.byTestId(prefix + dataTestsId);
481 String field = getServiceFieldByName(fieldName, model);
482 assertEquals(webElement.isDisplayed(), !(StringUtils.isEmpty(field)) , dataTestsId + " label shouldn't appear when " + fieldName + " is empty");
486 private <T> String getServiceFieldByName(String name, T model) {
488 return model.getClass().getField(name).get(model).toString();
489 } catch (IllegalAccessException | NoSuchFieldException e) {
490 throw new RuntimeException(e);
494 private void assertMetadataItem(String keyTestId, String value, boolean withPrefix) {
495 String elementTestId = (withPrefix ? Constants.ServiceModelInfo.INFO_TEST_ID_PREFIX:"") + keyTestId;
496 String infoItemText = GeneralUIUtils.getWebElementByTestID(elementTestId, 60).getText();
497 assertThat(String.format(Constants.ServiceModelInfo.METADETA_ERROR_MESSAGE, elementTestId), infoItemText, is(value));
500 public DeployMacroDialogBase getMacroDialog(){
501 if (Features.FLAG_ASYNC_INSTANTIATION.isActive()) {
502 VidBasePage vidBasePage =new VidBasePage();
503 vidBasePage.goToIframe();
504 return new DeployMacroDialog();
507 return new DeployMacroDialogOld();
510 protected void loadServicePopup(ModelInfo modelInfo) {
511 loadServicePopup(modelInfo.modelVersionId);
515 protected void loadServicePopup(String modelVersionId) {
516 SideMenu.navigateToBrowseASDCPage();
517 GeneralUIUtils.ultimateWait();
518 loadServicePopupOnBrowseASDCPage(modelVersionId);
521 protected void loadServicePopupOnBrowseASDCPage(String modelVersionId ) {
522 DeployMacroDialog deployMacroDialog = new DeployMacroDialog();
523 VidBasePage.goOutFromIframe();
524 deployMacroDialog.clickDeployServiceButtonByServiceUUID(modelVersionId);
525 deployMacroDialog.goToIframe();
526 GeneralUIUtils.ultimateWait();
527 Wait.byText("Model version");
530 public void assertSetButtonDisabled(String buttonTestId) {
531 WebElement webElement = Get.byTestId(buttonTestId);
532 org.testng.Assert.assertFalse(webElement.isEnabled(), "Set button should be disabled if not all mandatory fields are field.");
535 public void assertSetButtonEnabled(String buttonTestId) {
537 WebElement webElement = Get.byTestId(buttonTestId);
538 org.testng.Assert.assertTrue(webElement.isEnabled(), "Set button should be enabled if all mandatory fields are field.");
541 public void assertElementDisabled(String id) {
542 WebElement webElement = Get.byId(id);
543 assert webElement != null;
544 org.testng.Assert.assertFalse(webElement.isEnabled(), "field should be disabled if the field it depends on was not selected yet.");
547 public boolean isElementByIdRequired(String id) {
548 return Get.byId(id).getAttribute("class").contains("required");
551 protected int getUserIdNumberFromDB(User user) {
552 try (Connection connection = DriverManager.getConnection(DB_CONFIG.url, DB_CONFIG.username, DB_CONFIG.password)) {
553 Statement stmt = connection.createStatement();
554 ResultSet userIdResultSet;
555 userIdResultSet = stmt.executeQuery("SELECT USER_ID FROM fn_user where LOGIN_ID = '" + user.credentials.userId + "'");
556 Assert.assertTrue("Exactly one user should be found", userIdResultSet.next());
557 int userId = userIdResultSet.getInt("USER_ID");
558 Assert.assertFalse("There are more than one user for id " + userId, userIdResultSet.next());
560 } catch (SQLException e) {
561 throw new IllegalStateException("Cannot connect the database!", e);
565 protected List<Integer> getRoleIDsAssignedToUser(int userId) {
566 try (Connection connection = DriverManager.getConnection(DB_CONFIG.url, DB_CONFIG.username, DB_CONFIG.password)) {
567 Statement stmt = connection.createStatement();
568 ResultSet userRolesResultSet;
569 userRolesResultSet = stmt.executeQuery("SELECT ROLE_ID FROM fn_user_role where USER_ID = '" + userId + "' order by ROLE_ID");
571 List<Integer> userRoles = new ArrayList<Integer>();
572 while (userRolesResultSet.next()) {
573 userRoles.add(userRolesResultSet.getInt("ROLE_ID"));
576 } catch (SQLException e) {
577 throw new IllegalStateException("Cannot connect the database!", e);
581 protected void navigateToViewEditPageOfuspVoiceVidTest444(String aaiModelVersionId) {
582 navigateToViewEditPage("3f93c7cb-2fd0-4557-9514-e189b7b04f9d", aaiModelVersionId);
585 protected void navigateToViewEditPageOf_test_sssdad() {
586 navigateToViewEditPage("c187e9fe-40c3-4862-b73e-84ff056205f6", "ee6d61be-4841-4f98-8f23-5de9da846ca7");
589 protected void navigateToViewEditPage(final String serviceInstanceId, String aaiModelVersionId) {
590 VidBasePage vidBasePage = new VidBasePage();
591 SideMenu.navigateToWelcomePage();
592 vidBasePage.navigateTo("serviceModels.htm#/instantiate?" +
593 "subscriberId=e433710f-9217-458d-a79d-1c7aff376d89&" +
594 "subscriberName=USP%20VOICE&" +
595 "serviceType=VIRTUAL%20USP&" +
596 "serviceInstanceId=" + serviceInstanceId + "&" +
597 "aaiModelVersionId=" + aaiModelVersionId + "&" +
599 GeneralUIUtils.ultimateWait();
603 public void hoverAndClickMenuByName(String nodeName, String nodeToEdit, String contextMenuItem ) {
604 String buttonOfEdit = Constants.DrawingBoard.NODE_PREFIX + nodeToEdit + Constants.DrawingBoard.CONTEXT_MENU_BUTTON;
606 WebElement rightTreeNode = getTreeNodeByName(nodeName);
607 WebElement menuButton = Get.byXpath(rightTreeNode, ".//span[@data-tests-id='" + buttonOfEdit + "']");
609 GeneralUIUtils.clickElementUsingActions(menuButton);
610 Click.byTestId(contextMenuItem);
613 private WebElement getTreeNodeByName(String nodeName) {
614 return Get.byXpath("//tree-node-content[.//*[contains(text(), '" + nodeName + "')]]");