📄 logincontrollertest.java
字号:
package lee;
import org.springframework.mock.web.MockServletContext;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.XmlWebApplicationContext;
import org.springframework.web.servlet.ModelAndView;
import junit.framework.TestCase;
import junit.textui.TestRunner;
import java.util.Map;
/**
* @author yeeku.H.lee kongyeeku@163.com
* @version 1.0
* <br>Copyright (C), 2005-2008, yeeku.H.Lee
* <br>This program is protected by copyright laws.
* <br>Program Name:
* <br>Date:
*/
public class LoginControllerTest extends TestCase
{
private XmlWebApplicationContext ctx;
public void setUp()
{
ctx = new XmlWebApplicationContext();
String[] paths = {"mvc4-servlet.xml"};
ctx.setConfigLocations(paths);
ctx.setServletContext(new MockServletContext(""));
ctx.refresh();
}
public void testOnSubmit() throws Exception
{
LoginController c = (LoginController) ctx.getBean("/login.do");
LoginBean command = new LoginBean();
command.setUser("user");
command.setPass("pass");
ModelAndView mav = c.onSubmit(command);
Map m = (Map)mav.getModel().get("model");
assertEquals(m.get("error"),"您输入的用户名和密码不匹配");
}
public static void main(String[] args)
{
TestRunner.run(LoginControllerTest.class);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -