01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.navigate.spring;
16:
17: import static org.easymock.EasyMock.expect;
18: import static org.easymock.EasyMock.expectLastCall;
19: import static org.easymock.classextension.EasyMock.createStrictMock;
20: import static org.easymock.classextension.EasyMock.replay;
21: import static org.easymock.classextension.EasyMock.verify;
22:
23: import java.util.Map;
24:
25: import javax.servlet.http.HttpServletRequest;
26: import javax.servlet.http.HttpServletResponse;
27:
28: import org.springframework.web.servlet.View;
29: import org.strecks.context.ActionContext;
30: import org.strecks.exceptions.ApplicationRuntimeException;
31: import org.testng.annotations.Test;
32:
33: public class TestSpringRenderingViewAdapter {
34:
35: @Test
36: public void test() throws Exception {
37:
38: View view = createStrictMock(View.class);
39: Map model = createStrictMock(Map.class);
40: ActionContext context = createStrictMock(ActionContext.class);
41: HttpServletRequest request = createStrictMock(HttpServletRequest.class);
42: HttpServletResponse response = createStrictMock(HttpServletResponse.class);
43:
44: SpringRenderingViewAdapter va = new SpringRenderingViewAdapter(
45: view, model);
46:
47: expect(context.getRequest()).andReturn(request);
48: expect(context.getResponse()).andReturn(response);
49: view.render(model, request, response);
50:
51: replay(context);
52: replay(view);
53: replay(model);
54:
55: va.render(context);
56:
57: verify(context);
58: verify(view);
59: verify(model);
60:
61: }
62:
63: @Test
64: public void testException() throws Exception {
65:
66: View view = createStrictMock(View.class);
67: Map model = createStrictMock(Map.class);
68: ActionContext context = createStrictMock(ActionContext.class);
69: HttpServletRequest request = createStrictMock(HttpServletRequest.class);
70: HttpServletResponse response = createStrictMock(HttpServletResponse.class);
71:
72: SpringRenderingViewAdapter va = new SpringRenderingViewAdapter(
73: view, model);
74:
75: expect(context.getRequest()).andReturn(request);
76: expect(context.getResponse()).andReturn(response);
77: view.render(model, request, response);
78: expectLastCall().andThrow(new IllegalStateException());
79:
80: replay(context);
81: replay(view);
82: replay(model);
83:
84: try {
85: va.render(context);
86: } catch (ApplicationRuntimeException e) {
87: assert e.getMessage().startsWith(
88: "Exception thrown during rendering of view");
89: assert e.getCause() instanceof IllegalStateException;
90: }
91:
92: verify(context);
93: verify(view);
94: verify(model);
95:
96: }
97:
98: }
|