package org.xmx0632.deliciousfruit.functional.gui;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Ignore;
import org.junit.Test;
import org.openqa.selenium.By;
import org.xmx0632.deliciousfruit.functional.BaseSeleniumTestCase;
/**
* 系统安全控制的功能测试, 测试主要用户故事.
*
* @author calvin
*/
@Ignore
public class SecurityFT extends BaseSeleniumTestCase {
/**
* 测试匿名用户访问系统时的行为.
*/
@Test
public void anonymousUserAccessSystem() {
// 访问退出登录页面,退出之前的登录
s.open("/logout");
assertEquals("deliciousfruit示例:登录页", s.getTitle());
// 访问任意页面会跳转到登录界面
s.open("/task");
assertEquals("deliciousfruit示例:登录页", s.getTitle());
}
/**
* 测试普通用户访问管理员的用户管理功能时代行为。
*/
@Test
public void userTryToManageUsers() {
loginAsUserIfNecessary();
s.open("/admin/user");
assertEquals("Error 401 Unauthorized", s.getTitle());
}
/**
* 登录错误的用户名密码.
*/
@Test
public void loginWithWrongPassword() {
s.open("/logout");
s.type(By.name("username"), "wrongUser");
s.type(By.name("password"), "WrongPassword");
s.check(By.name("rememberMe"));
s.click(By.id("submit_btn"));
assertEquals("deliciousfruit示例:登录页", s.getTitle());
assertTrue(s.isTextPresent("登录失败,请重试."));
}
}