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.framework.router;
16:
17: import java.util.HashMap;
18: import java.util.Map;
19: import junit.framework.TestCase;
20: import org.araneaframework.core.NoSuchServiceException;
21: import org.araneaframework.http.core.StandardServletInputData;
22: import org.araneaframework.http.core.StandardServletOutputData;
23: import org.araneaframework.mock.MockUtil;
24: import org.araneaframework.mock.core.MockEventfulStandardService;
25: import org.araneaframework.mock.servlet.filter.MockBaseServiceRouterService;
26: import org.springframework.mock.web.MockHttpServletRequest;
27: import org.springframework.mock.web.MockHttpServletResponse;
28:
29: /**
30: *
31: * @author "Toomas Römer" <toomas@webmedia.ee>
32: */
33: public class BaseServiceRouterServiceTests extends TestCase {
34: private MockBaseServiceRouterService service;
35: private MockEventfulStandardService child1;
36: private MockEventfulStandardService child2;
37:
38: private StandardServletInputData input;
39: private StandardServletOutputData output;
40:
41: private MockHttpServletRequest req;
42: private MockHttpServletResponse res;
43:
44: private Map map;
45:
46: public void setUp() throws Exception {
47: service = new MockBaseServiceRouterService();
48: map = new HashMap();
49:
50: child1 = new MockEventfulStandardService();
51: child2 = new MockEventfulStandardService();
52:
53: req = new MockHttpServletRequest();
54: res = new MockHttpServletResponse();
55:
56: input = new StandardServletInputData(req);
57: output = new StandardServletOutputData(req, res);
58:
59: map.put("first", child1);
60: map.put("second", child2);
61:
62: service.setServiceMap(map);
63: service._getComponent().init(null, MockUtil.getEnv());
64: }
65:
66: public void testActionGetsCalled() throws Exception {
67: req.addParameter("serviceId", "first");
68: input = new StandardServletInputData(req);
69:
70: service._getService().action(MockUtil.getPath(), input, output);
71:
72: req = new MockHttpServletRequest();
73: req.addParameter("serviceId", "second");
74: input = new StandardServletInputData(req);
75:
76: service._getService().action(MockUtil.getPath(), input, output);
77:
78: assertTrue(child1.getActionCalled());
79: assertTrue(child2.getActionCalled());
80: }
81:
82: public void testNonExistentServiceThrowsException()
83: throws Exception {
84: req.addParameter("serviceId", "nonExistentService");
85: input = new StandardServletInputData(req);
86: try {
87: service._getService().action(MockUtil.getPath(), input,
88: output);
89: fail("Was able to call a non existent service");
90: } catch (NoSuchServiceException e) {
91: //success
92: }
93: }
94: }
|