/*
* Copyright 2004, 2005, 2006 Odysseus Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.odysseus.calyxo.panels;
import java.util.Locale;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import de.odysseus.calyxo.base.conf.ConfigException;
import de.odysseus.calyxo.base.test.TestModuleGroup;
import de.odysseus.calyxo.base.test.TestModuleContext;
import de.odysseus.calyxo.base.test.TestPageContext;
import de.odysseus.calyxo.base.test.TestRequest;
import de.odysseus.calyxo.panels.conf.PanelConfig;
import junit.framework.TestCase;
/**
*
* @author Christoph Beck
*/
public class PanelsSupportTest extends TestCase {
private TestRequest request;
private TestModuleContext module;
private PanelsSupport support;
/**
* Constructor for I18nSupportTest.
* @param arg0
*/
public PanelsSupportTest(String arg0) {
super(arg0);
}
protected void setUp() throws ServletException, ConfigException {
request = new TestRequest();
// configure module container
ServletContext context = request.getSession().getServletContext();
TestModuleGroup group = TestModuleGroup.getInstance(context);
// configure test module
module = new TestModuleContext("test", context);
group.add(module);
group.setTestModuleContext(request, module);
PanelsService service = new PanelsService();
String xml = "/" + getClass().getName().replace('.', '/') + ".xml";
service.init(module, xml);
support = PanelsSupport.getInstance(module);
module.setAttribute(PanelsSupport.PANELS_SUPPORT_KEY, support);
}
public void testGetInstance() {
assertSame(support, PanelsSupport.getInstance(module));
assertSame(support, PanelsSupport.getInstance(request));
assertSame(support, PanelsSupport.getInstance(new TestPageContext(request)));
}
public void testGetOrCreateContext() {
PanelsContext context =
support.getOrCreateContext(request, new Locale("", ""));
assertSame(context, support.getContext(request));
assertSame(context, support.getOrCreateContext(request, new Locale("de", "")));
assertSame(context, support.getContext(new TestPageContext(request)));
}
public void testFindPanelConfig() {
PanelConfig foo = support.findPanelConfig("foo", new Locale("", ""));
assertNotNull(foo);
PanelConfig bar = support.findPanelConfig("bar", new Locale("", ""));
assertNotNull(bar);
PanelConfig foo_de = support.findPanelConfig("foo", new Locale("de", ""));
assertNotNull(foo_de);
PanelConfig bar_de = support.findPanelConfig("bar", new Locale("de", ""));
assertNotNull(bar_de);
assertNotSame(foo, foo_de);
assertSame(bar, bar_de);
}
public static void main(String[] args) {
junit.textui.TestRunner.run(PanelsSupportTest.class);
}
}