01: /*
02: * Copyright 2004, 2005, 2006 Odysseus Software GmbH
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: */
16: package de.odysseus.calyxo.base;
17:
18: import javax.servlet.ServletContext;
19: import javax.servlet.ServletException;
20:
21: import de.odysseus.calyxo.base.test.TestModuleGroup;
22: import de.odysseus.calyxo.base.test.TestModuleContext;
23: import de.odysseus.calyxo.base.test.TestPageContext;
24: import de.odysseus.calyxo.base.test.TestRequest;
25:
26: import junit.framework.TestCase;
27:
28: /**
29: *
30: * @author Christoph Beck
31: */
32: public class ModuleSupportTest extends TestCase {
33:
34: private TestRequest request;
35: private ModuleSupport support;
36: private TestModuleContext module;
37:
38: /**
39: * Constructor for I18nSupportTest.
40: * @param arg0
41: */
42: public ModuleSupportTest(String arg0) {
43: super (arg0);
44: }
45:
46: protected void setUp() throws ServletException {
47: request = new TestRequest();
48: ServletContext context = request.getSession()
49: .getServletContext();
50: // set support instance
51: context.setAttribute(ModuleSupport.MODULE_SUPPORT_KEY,
52: support = new ModuleSupport());
53: // configure test module
54: module = new TestModuleContext("test", context);
55: // configure module container
56: TestModuleGroup group = TestModuleGroup.getInstance(context);
57: group.add(module);
58: // select module
59: group.setTestModuleContext(request, module);
60: }
61:
62: public void testGetInstance() {
63: assertSame(support, ModuleSupport.getInstance(request));
64: assertSame(support, ModuleSupport
65: .getInstance(new TestPageContext(request)));
66: assertSame(support, ModuleSupport.getInstance(request
67: .getSession().getServletContext()));
68: }
69:
70: public void testGetModuleContext() {
71: assertSame(module, support.getModuleContext(request));
72: assertSame(module, support
73: .getModuleContext(new TestPageContext(request)));
74: }
75:
76: public static void main(String[] args) {
77: junit.textui.TestRunner.run(ModuleSupportTest.class);
78: }
79: }
|