/examples/mini-web/src/test/functional/org/springside/examples/miniweb/functional/account/UserManagerIT.java

http://github.com/springside/springside4 · Java · 126 lines · 85 code · 20 blank · 21 comment · 9 complexity · 2a75707825d211f951232de748ab6350 MD5 · raw file

  1. package org.springside.examples.miniweb.functional.account;
  2. import static org.junit.Assert.*;
  3. import java.util.List;
  4. import org.junit.Test;
  5. import org.junit.experimental.categories.Category;
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.WebElement;
  8. import org.springside.examples.miniweb.data.AccountData;
  9. import org.springside.examples.miniweb.entity.account.Group;
  10. import org.springside.examples.miniweb.entity.account.User;
  11. import org.springside.examples.miniweb.functional.BaseFunctionalTestCase;
  12. import org.springside.examples.miniweb.functional.Gui;
  13. import org.springside.examples.miniweb.functional.Gui.UserColumn;
  14. import org.springside.modules.test.category.Smoke;
  15. import org.springside.modules.utils.Collections3;
  16. /**
  17. * ?????????, ????JavaScript?????????.
  18. *
  19. * @author calvin
  20. */
  21. public class UserManagerIT extends BaseFunctionalTestCase {
  22. /**
  23. * ??????.
  24. */
  25. @Test
  26. @Category(Smoke.class)
  27. public void viewUserList() {
  28. s.click(Gui.MENU_USER);
  29. WebElement table = s.findElement(By.id("contentTable"));
  30. assertEquals("admin", s.getTable(table, 0, UserColumn.LOGIN_NAME.ordinal()));
  31. assertEquals("Admin", s.getTable(table, 0, UserColumn.NAME.ordinal()));
  32. assertEquals("???, ??", s.getTable(table, 0, UserColumn.GROUPS.ordinal()));
  33. }
  34. /**
  35. * ????.
  36. */
  37. @Category(Smoke.class)
  38. @Test
  39. public void createUser() {
  40. //????????
  41. s.click(Gui.MENU_USER);
  42. s.click(By.linkText("????"));
  43. //????????????
  44. User user = AccountData.getRandomUserWithOneGroup();
  45. //????
  46. s.type(By.id("loginName"), user.getLoginName());
  47. s.type(By.id("name"), user.getName());
  48. s.type(By.id("password"), user.getPassword());
  49. s.type(By.id("passwordConfirm"), user.getPassword());
  50. List<WebElement> checkBoxes = s.findElements(By.name("groupList"));
  51. for (Group group : user.getGroupList()) {
  52. for (WebElement checkBox : checkBoxes) {
  53. if (String.valueOf(group.getId()).equals(s.getValue(checkBox))) {
  54. s.check(checkBox);
  55. }
  56. }
  57. }
  58. s.click(By.id("submit"));
  59. //????
  60. assertTrue(s.isTextPresent("????" + user.getLoginName() + "??"));
  61. verifyUser(user);
  62. }
  63. /**
  64. * ???????????.
  65. */
  66. private void verifyUser(User user) {
  67. s.click(By.id("editLink-" + user.getLoginName()));
  68. assertEquals(user.getLoginName(), s.getValue(By.id("loginName")));
  69. assertEquals(user.getName(), s.getValue(By.id("name")));
  70. List<WebElement> checkBoxes = s.findElements(By.name("groupList"));
  71. for (Group group : user.getGroupList()) {
  72. for (WebElement checkBox : checkBoxes) {
  73. if (String.valueOf(group.getId()).equals(s.getValue(checkBox))) {
  74. assertTrue(s.isChecked(checkBox));
  75. }
  76. }
  77. }
  78. List<Group> uncheckGroupList = Collections3.subtract(AccountData.getDefaultGroupList(), user.getGroupList());
  79. for (Group group : uncheckGroupList) {
  80. for (WebElement checkBox : checkBoxes) {
  81. if (String.valueOf(group.getId()).equals(s.getValue(checkBox))) {
  82. assertFalse(s.isChecked(checkBox));
  83. }
  84. }
  85. }
  86. }
  87. /**
  88. * ????????????.
  89. */
  90. @Test
  91. public void inputInValidateUser() {
  92. s.click(Gui.MENU_USER);
  93. s.click(By.linkText("????"));
  94. s.type(By.id("loginName"), "admin");
  95. s.type(By.id("name"), "");
  96. s.type(By.id("password"), "a");
  97. s.type(By.id("passwordConfirm"), "abc");
  98. s.type(By.id("email"), "abc");
  99. s.click(By.id("submit"));
  100. assertEquals("????????", s.getText(By.xpath("//fieldset/div[2]/div/label")));
  101. assertEquals("????", s.getText(By.xpath("//fieldset/div[3]/div/label")));
  102. assertEquals("?????????? 3 ????", s.getText(By.xpath("//fieldset/div[4]/div/label")));
  103. assertEquals("??????????", s.getText(By.xpath("//fieldset/div[5]/div/label")));
  104. assertEquals("????????????", s.getText(By.xpath("//fieldset/div[6]/div/label")));
  105. }
  106. }