KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > mock > web > MockFilterChain


1 /*
2  * Copyright 2002-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.mock.web;
18
19 import javax.servlet.FilterChain JavaDoc;
20 import javax.servlet.ServletRequest JavaDoc;
21 import javax.servlet.ServletResponse JavaDoc;
22
23 import org.springframework.util.Assert;
24
25 /**
26  * Mock implementation of the {@link javax.servlet.FilterConfig} interface.
27  *
28  * <p>Used for testing the web framework; also usefol for testing
29  * custom {@link javax.servlet.Filter} implementations.
30  *
31  * @author Juergen Hoeller
32  * @since 2.0.3
33  * @see MockFilterConfig
34  * @see PassThroughFilterChain
35  */

36 public class MockFilterChain implements FilterChain JavaDoc {
37
38     private ServletRequest JavaDoc request;
39
40     private ServletResponse JavaDoc response;
41
42
43     /**
44      * Records the request and response.
45      */

46     public void doFilter(ServletRequest JavaDoc request, ServletResponse JavaDoc response) {
47         Assert.notNull(request, "Request must not be null");
48         Assert.notNull(response, "Response must not be null");
49         if (this.request != null) {
50             throw new IllegalStateException JavaDoc("This FilterChain has already been called!");
51         }
52         this.request = request;
53         this.response = response;
54     }
55
56     /**
57      * Return the request that {@link #doFilter} has been called with.
58      */

59     public ServletRequest JavaDoc getRequest() {
60         return this.request;
61     }
62
63     /**
64      * Return the response that {@link #doFilter} has been called with.
65      */

66     public ServletResponse JavaDoc getResponse() {
67         return this.response;
68     }
69
70 }
71
Popular Tags