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.interceptor;
16:
17: import static org.easymock.EasyMock.expect;
18: import static org.easymock.classextension.EasyMock.createMock;
19: import static org.easymock.classextension.EasyMock.replay;
20: import static org.easymock.classextension.EasyMock.verify;
21:
22: import java.util.ArrayList;
23: import java.util.List;
24:
25: import javax.servlet.http.HttpServletRequest;
26: import javax.servlet.http.HttpSession;
27:
28: import org.strecks.constants.InfrastructureKeys;
29: import org.strecks.context.impl.TestContextImpl;
30: import org.testng.annotations.Test;
31:
32: /**
33: * @author Phil Zoio
34: */
35: public class TestHistoryRecorder {
36:
37: @Test
38: public void testHistoryRecorderPost() {
39:
40: HttpServletRequest request = createMock(HttpServletRequest.class);
41:
42: expect(request.getMethod()).andReturn("POST");
43:
44: replay(request);
45:
46: HistoryRecorder interceptor = new HistoryRecorder();
47: interceptor.afterExecute(null, new TestContextImpl(request,
48: null, null, null, null), null);
49:
50: verify(request);
51:
52: }
53:
54: @Test
55: public void testHistoryRecorderGet() {
56:
57: HttpServletRequest request = createMock(HttpServletRequest.class);
58: HttpSession session = createMock(HttpSession.class);
59:
60: expect(request.getMethod()).andReturn("GET");
61: expect(request.getSession()).andReturn(session);
62: expect(request.getServletPath()).andReturn("path");
63: expect(request.getQueryString()).andReturn("queryString");
64: List<String> arrayList = new ArrayList<String>();
65: expect(
66: session
67: .getAttribute(InfrastructureKeys.GOOD_URL_HISTORY))
68: .andReturn(arrayList);
69: arrayList.add("path?queryString");
70: session.setAttribute(InfrastructureKeys.GOOD_URL_HISTORY,
71: arrayList);
72:
73: replay(request);
74: replay(session);
75:
76: HistoryRecorder interceptor = new HistoryRecorder();
77: interceptor.afterExecute(null, new TestContextImpl(request,
78: null, null, null, null), null);
79:
80: verify(request);
81: verify(session);
82: }
83:
84: }
|