⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sampledelegatetest.java

📁 Spring2.0宝典
💻 JAVA
字号:
package lee;

import org.springframework.mock.web.MockServletContext; 
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.context.ApplicationContext; 
import org.springframework.web.context.support.XmlWebApplicationContext; 
import org.springframework.web.servlet.ModelAndView; 

import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
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 SampleDelegateTest extends TestCase
{ 

    private XmlWebApplicationContext ctx; 

    public void setUp()
	{		
        ctx = new XmlWebApplicationContext(); 
		String[] paths = {"mvc5-servlet.xml"};
        ctx.setConfigLocations(paths); 
        ctx.setServletContext(new MockServletContext("")); 
        ctx.refresh();
    } 

		

    public void testWelcome() throws Exception 
	{
        SampleDelegate sd = (SampleDelegate) ctx.getBean("sampleDelegate");
        MockHttpServletRequest request = new MockHttpServletRequest(); 
        MockHttpServletResponse response = new MockHttpServletResponse(); 
        request.addParameter("method", "welcome"); 
        ModelAndView mav = sd.welcome(request,response); 
		assertEquals(mav.getViewName(),"/WEB-INF/jsp/welcome.jsp");
	} 
    public void testHello() throws Exception 
	{
        SampleDelegate sd = (SampleDelegate) ctx.getBean("sampleDelegate");
        MockHttpServletRequest request = new MockHttpServletRequest(); 
        MockHttpServletResponse response = new MockHttpServletResponse(); 
        request.addParameter("method", "hello"); 
        ModelAndView mav = sd.hello(request,response); 
		String tmp = (String)mav.getModel().get("model");
		assertEquals(mav.getViewName(),"/WEB-INF/jsp/hello.jsp");
		assertEquals(tmp,"欢迎学习Spring");
	} 

    public static void main(String[] args)
	{
		
		TestRunner.run(SampleDelegateTest.class);
    }
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -