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.web;
16:
17: import static org.easymock.EasyMock.expect;
18: import static org.easymock.classextension.EasyMock.createStrictMock;
19: import static org.easymock.classextension.EasyMock.replay;
20: import static org.easymock.classextension.EasyMock.verify;
21:
22: import javax.servlet.ServletContext;
23: import javax.servlet.http.HttpServletRequest;
24: import javax.servlet.http.HttpSession;
25:
26: import org.testng.annotations.Test;
27:
28: /**
29: * @author Phil Zoio
30: */
31: public class TestWebHelperImpl {
32:
33: @Test
34: public void test() {
35:
36: HttpServletRequest request = createStrictMock(HttpServletRequest.class);
37: HttpSession session = createStrictMock(HttpSession.class);
38: ServletContext context = createStrictMock(ServletContext.class);
39:
40: WebHelperImpl wc = new WebHelperImpl(request, context);
41:
42: // 1.
43: request.setAttribute("name1", "value1");
44: expect(request.getSession()).andReturn(session);
45: session.setAttribute("name2", "value2");
46: context.setAttribute("name3", "value3");
47:
48: // 2.
49: request.removeAttribute("name1");
50: expect(request.getSession(false)).andReturn(session);
51: session.removeAttribute("name2");
52: context.removeAttribute("name3");
53:
54: // 3.
55: expect(request.getSession(false)).andReturn(null);
56:
57: replay(request);
58: replay(session);
59: replay(context);
60:
61: // 1.
62: wc.setRequestAttribute("name1", "value1");
63: wc.setSessionAttribute("name2", "value2");
64: wc.setContextAttribute("name3", "value3");
65:
66: // 2.
67: wc.removeRequestAttribute("name1");
68: wc.removeSessionAttribute("name2");
69: wc.removeContextAttribute("name3");
70:
71: // 3.
72: // Now try remove from session when it is null - notice, no expected call to session
73: wc.removeSessionAttribute("name2");
74:
75: verify(request);
76: verify(session);
77: verify(context);
78:
79: }
80:
81: }
|