01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: **/package org.araneaframework.tests.servlet.router;
16:
17: import junit.framework.TestCase;
18: import org.araneaframework.Environment;
19: import org.araneaframework.Path;
20: import org.araneaframework.Service;
21: import org.araneaframework.core.ServiceFactory;
22: import org.araneaframework.http.core.StandardServletInputData;
23: import org.araneaframework.http.core.StandardServletOutputData;
24: import org.araneaframework.http.router.StandardHttpSessionRouterService;
25: import org.araneaframework.http.util.ServletUtil;
26: import org.araneaframework.mock.MockLifeCycle;
27: import org.araneaframework.mock.core.MockEventfulBaseService;
28: import org.springframework.mock.web.MockHttpServletRequest;
29: import org.springframework.mock.web.MockHttpServletResponse;
30:
31: /**
32: * @author "Toomas Römer" <toomas@webmedia.ee>
33: */
34: public class StandardServletSessionRouterServiceTests extends TestCase {
35: private StandardHttpSessionRouterService service;
36: private MockEventfulBaseService child;
37:
38: private StandardServletInputData input;
39: private StandardServletOutputData output;
40:
41: private MockHttpServletRequest req;
42: private MockHttpServletResponse res;
43:
44: private Path path;
45:
46: public void setUp() throws Exception {
47: service = new StandardHttpSessionRouterService();
48: child = new MockEventfulBaseService();
49: ServiceFactory factory = new ServiceFactory() {
50: public Service buildService(Environment env) {
51: return child;
52: }
53: };
54:
55: service.setSessionServiceFactory(factory);
56: MockLifeCycle.begin(service);
57:
58: req = new MockHttpServletRequest();
59: res = new MockHttpServletResponse();
60:
61: input = new StandardServletInputData(req);
62: output = new StandardServletOutputData(req, res);
63: }
64:
65: public void testCreatesNewSession() throws Exception {
66: service._getService().action(path, input, output);
67: assertTrue(child.getInitCalled());
68: assertTrue(null != ServletUtil
69: .getRequest(input)
70: .getSession()
71: .getAttribute(
72: StandardHttpSessionRouterService.SESSION_SERVICE_KEY));
73: }
74:
75: public void testReusesOldSession() throws Exception {
76: service._getService().action(path, input, output);
77: Service sessService = (Service) ServletUtil
78: .getRequest(input)
79: .getSession()
80: .getAttribute(
81: StandardHttpSessionRouterService.SESSION_SERVICE_KEY);
82: service._getService().action(path, input, output);
83:
84: assertEquals(sessService, (Service) ServletUtil.getRequest(
85: input).getSession().getAttribute(
86: StandardHttpSessionRouterService.SESSION_SERVICE_KEY));
87: }
88: }
|