logincontrollertest.java

来自「Spring2.0宝典」· Java 代码 · 共 54 行

JAVA
54
字号
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 + =
减小字号Ctrl + -
显示快捷键?