View Javadoc
1   /*
2    * Copyright 2002-2012 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.test.web.servlet;
18  
19  import org.springframework.mock.web.MockHttpServletRequest;
20  import org.springframework.mock.web.MockHttpServletResponse;
21  import org.springframework.web.servlet.FlashMap;
22  import org.springframework.web.servlet.HandlerInterceptor;
23  import org.springframework.web.servlet.ModelAndView;
24  
25  /**
26   * A stub implementation of the {@link MvcResult} contract.
27   *
28   * @author Rossen Stoyanchev
29   */
30  public class StubMvcResult implements MvcResult {
31  
32  	private MockHttpServletRequest request;
33  
34  	private Object handler;
35  
36  	private HandlerInterceptor[] interceptors;
37  
38  	private Exception resolvedException;
39  
40  	private ModelAndView mav;
41  
42  	private FlashMap flashMap;
43  
44  	private MockHttpServletResponse response;
45  
46  	public StubMvcResult(MockHttpServletRequest request,
47  						 Object handler,
48  						 HandlerInterceptor[] interceptors,
49  						 Exception resolvedException,
50  						 ModelAndView mav,
51  						 FlashMap flashMap,
52  						 MockHttpServletResponse response) {
53  		this.request = request;
54  		this.handler = handler;
55  		this.interceptors = interceptors;
56  		this.resolvedException = resolvedException;
57  		this.mav = mav;
58  		this.flashMap = flashMap;
59  		this.response = response;
60  	}
61  
62  	@Override
63  	public MockHttpServletRequest getRequest() {
64  		return request;
65  	}
66  
67  	@Override
68  	public Object getHandler() {
69  		return handler;
70  	}
71  
72  	@Override
73  	public HandlerInterceptor[] getInterceptors() {
74  		return interceptors;
75  	}
76  
77  	@Override
78  	public Exception getResolvedException() {
79  		return resolvedException;
80  	}
81  
82  	@Override
83  	public ModelAndView getModelAndView() {
84  		return mav;
85  	}
86  
87  	@Override
88  	public FlashMap getFlashMap() {
89  		return flashMap;
90  	}
91  
92  	@Override
93  	public MockHttpServletResponse getResponse() {
94  		return response;
95  	}
96  
97  	public ModelAndView getMav() {
98  		return mav;
99  	}
100 
101 	public void setMav(ModelAndView mav) {
102 		this.mav = mav;
103 	}
104 
105 	public void setRequest(MockHttpServletRequest request) {
106 		this.request = request;
107 	}
108 
109 	public void setHandler(Object handler) {
110 		this.handler = handler;
111 	}
112 
113 	public void setInterceptors(HandlerInterceptor[] interceptors) {
114 		this.interceptors = interceptors;
115 	}
116 
117 	public void setResolvedException(Exception resolvedException) {
118 		this.resolvedException = resolvedException;
119 	}
120 
121 	public void setFlashMap(FlashMap flashMap) {
122 		this.flashMap = flashMap;
123 	}
124 
125 	public void setResponse(MockHttpServletResponse response) {
126 		this.response = response;
127 	}
128 
129 	@Override
130 	public Object getAsyncResult() {
131 		return null;
132 	}
133 
134 	@Override
135 	public Object getAsyncResult(long timeToWait) {
136 		return null;
137 	}
138 
139 }