staticfiltertest.java

来自「基于Maven的质量保证自动化环境配置和演示程序」· Java 代码 · 共 39 行

JAVA
39
字号
package com.cib.webapp.filter;

import junit.framework.TestCase;
import org.springframework.mock.web.MockFilterConfig;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;

public class StaticFilterTest extends TestCase {
    private StaticFilter filter = null;

    protected void setUp() throws Exception {
        filter = new StaticFilter();
        MockFilterConfig config = new MockFilterConfig();
        config.addInitParameter("includes", "/scripts/*");
        filter.init(config);
    }

    public void testFilterDoesntForwardWhenPathMatches() throws Exception {
        MockHttpServletRequest request = new MockHttpServletRequest("GET", "/scripts/dojo/test.html");
        MockHttpServletResponse response = new MockHttpServletResponse();
        MockFilterChain chain = new MockFilterChain();

        filter.doFilter(request, response, chain);

        assertNull(chain.getForwardURL());
    }

    public void testFilterForwardsWhenPathDoesntMatch() throws Exception {
        MockHttpServletRequest request = new MockHttpServletRequest("GET", "/editProfile.html");
        MockHttpServletResponse response = new MockHttpServletResponse();
        MockFilterChain chain = new MockFilterChain();

        filter.doFilter(request, response, chain);

        assertNotNull(chain.getForwardURL());
    }
}

⌨️ 快捷键说明

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