/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
- package org.springside.examples.miniweb.functional.account;
- import static org.junit.Assert.*;
- import java.util.List;
- import org.junit.Test;
- import org.junit.experimental.categories.Category;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebElement;
- import org.springside.examples.miniweb.data.AccountData;
- import org.springside.examples.miniweb.entity.account.Group;
- import org.springside.examples.miniweb.entity.account.User;
- import org.springside.examples.miniweb.functional.BaseFunctionalTestCase;
- import org.springside.examples.miniweb.functional.Gui;
- import org.springside.examples.miniweb.functional.Gui.UserColumn;
- import org.springside.modules.test.category.Smoke;
- import org.springside.modules.utils.Collections3;
- /**
- * ?????????, ????JavaScript?????????.
- *
- * @author calvin
- */
- public class UserManagerIT extends BaseFunctionalTestCase {
- /**
- * ??????.
- */
- @Test
- @Category(Smoke.class)
- public void viewUserList() {
- s.click(Gui.MENU_USER);
- WebElement table = s.findElement(By.id("contentTable"));
- assertEquals("admin", s.getTable(table, 0, UserColumn.LOGIN_NAME.ordinal()));
- assertEquals("Admin", s.getTable(table, 0, UserColumn.NAME.ordinal()));
- assertEquals("???, ??", s.getTable(table, 0, UserColumn.GROUPS.ordinal()));
- }
- /**
- * ????.
- */
- @Category(Smoke.class)
- @Test
- public void createUser() {
- //????????
- s.click(Gui.MENU_USER);
- s.click(By.linkText("????"));
- //????????????
- User user = AccountData.getRandomUserWithOneGroup();
- //????
- s.type(By.id("loginName"), user.getLoginName());
- s.type(By.id("name"), user.getName());
- s.type(By.id("password"), user.getPassword());
- s.type(By.id("passwordConfirm"), user.getPassword());
- List<WebElement> checkBoxes = s.findElements(By.name("groupList"));
- for (Group group : user.getGroupList()) {
- for (WebElement checkBox : checkBoxes) {
- if (String.valueOf(group.getId()).equals(s.getValue(checkBox))) {
- s.check(checkBox);
- }
- }
- }
- s.click(By.id("submit"));
- //????
- assertTrue(s.isTextPresent("????" + user.getLoginName() + "??"));
- verifyUser(user);
- }
- /**
- * ???????????.
- */
- private void verifyUser(User user) {
- s.click(By.id("editLink-" + user.getLoginName()));
- assertEquals(user.getLoginName(), s.getValue(By.id("loginName")));
- assertEquals(user.getName(), s.getValue(By.id("name")));
- List<WebElement> checkBoxes = s.findElements(By.name("groupList"));
- for (Group group : user.getGroupList()) {
- for (WebElement checkBox : checkBoxes) {
- if (String.valueOf(group.getId()).equals(s.getValue(checkBox))) {
- assertTrue(s.isChecked(checkBox));
- }
- }
- }
- List<Group> uncheckGroupList = Collections3.subtract(AccountData.getDefaultGroupList(), user.getGroupList());
- for (Group group : uncheckGroupList) {
- for (WebElement checkBox : checkBoxes) {
- if (String.valueOf(group.getId()).equals(s.getValue(checkBox))) {
- assertFalse(s.isChecked(checkBox));
- }
- }
- }
- }
- /**
- * ????????????.
- */
- @Test
- public void inputInValidateUser() {
- s.click(Gui.MENU_USER);
- s.click(By.linkText("????"));
- s.type(By.id("loginName"), "admin");
- s.type(By.id("name"), "");
- s.type(By.id("password"), "a");
- s.type(By.id("passwordConfirm"), "abc");
- s.type(By.id("email"), "abc");
- s.click(By.id("submit"));
- assertEquals("????????", s.getText(By.xpath("//fieldset/div[2]/div/label")));
- assertEquals("????", s.getText(By.xpath("//fieldset/div[3]/div/label")));
- assertEquals("?????????? 3 ????", s.getText(By.xpath("//fieldset/div[4]/div/label")));
- assertEquals("??????????", s.getText(By.xpath("//fieldset/div[5]/div/label")));
- assertEquals("????????????", s.getText(By.xpath("//fieldset/div[6]/div/label")));
- }
- }