1 | package gov.va.med.edp.web.servlet.filter;
|
---|
2 |
|
---|
3 | import junit.framework.TestCase;
|
---|
4 | import org.springframework.mock.web.MockFilterChain;
|
---|
5 | import org.springframework.mock.web.MockFilterConfig;
|
---|
6 | import org.springframework.mock.web.MockHttpServletRequest;
|
---|
7 | import org.springframework.mock.web.MockHttpServletResponse;
|
---|
8 |
|
---|
9 | import javax.servlet.FilterConfig;
|
---|
10 | import javax.servlet.ServletException;
|
---|
11 | import java.io.IOException;
|
---|
12 |
|
---|
13 | public class ResponseHeaderFilterTest extends TestCase {
|
---|
14 | private MockHttpServletRequest request;
|
---|
15 | private MockHttpServletResponse response;
|
---|
16 | private MockFilterChain filterChain;
|
---|
17 |
|
---|
18 | protected void setUp() throws Exception {
|
---|
19 | request = new MockHttpServletRequest();
|
---|
20 | response = new MockHttpServletResponse();
|
---|
21 | filterChain = new MockFilterChain();
|
---|
22 | }
|
---|
23 |
|
---|
24 | public void testInitDestroy() throws ServletException {
|
---|
25 | FilterConfig filterConfig = new MockFilterConfig();
|
---|
26 | ResponseHeaderFilter f = new ResponseHeaderFilter();
|
---|
27 |
|
---|
28 | f.init(filterConfig);
|
---|
29 | assertSame(filterConfig, f.filterConfig);
|
---|
30 |
|
---|
31 | f.destroy();
|
---|
32 | assertNull(f.filterConfig);
|
---|
33 | }
|
---|
34 |
|
---|
35 | public void testFilter() throws IOException, ServletException {
|
---|
36 | ResponseHeaderFilter f = new ResponseHeaderFilter();
|
---|
37 |
|
---|
38 | MockFilterConfig config = new MockFilterConfig();
|
---|
39 | config.addInitParameter("Foo", "Bar");
|
---|
40 | f.init(config);
|
---|
41 |
|
---|
42 | f.doFilter(request, response, filterChain);
|
---|
43 |
|
---|
44 | assertEquals("Bar", response.getHeader("Foo"));
|
---|
45 |
|
---|
46 | assertSame(request, filterChain.getRequest());
|
---|
47 | assertSame(response, filterChain.getResponse());
|
---|
48 | }
|
---|
49 | }
|
---|