/*
* 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.control.base;
import java.util.HashMap;
import junit.framework.TestCase;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import de.odysseus.calyxo.base.ModuleSupport;
import de.odysseus.calyxo.base.conf.ConfigException;
import de.odysseus.calyxo.base.test.TestRequest;
import de.odysseus.calyxo.base.test.TestServletConfig;
import de.odysseus.calyxo.base.test.TestSession;
import de.odysseus.calyxo.control.base.ControlModuleContext;
import de.odysseus.calyxo.control.base.ControlModuleGroup;
import de.odysseus.calyxo.control.base.ControlModuleMapping;
/**
*
* @author Christoph Beck
*/
public class ControlModuleGroupTest extends TestCase {
/**
* Constructor for SupportTest.
* @param arg0
*/
public ControlModuleGroupTest(String arg0) {
super(arg0);
}
public void test1() throws ConfigException, ServletException {
HashMap params = new HashMap();
params.put(
"config",
"/de/odysseus/calyxo/control/calyxo-control-config-empty.xml"
);
TestServletConfig config = new TestServletConfig("test", params);
ControlModuleMapping mapping = new ControlModuleMapping("/test/*");
ServletContext context = config.getServletContext();
ControlModuleGroup group = ControlModuleGroup.getInstance(context);
ControlModuleContext module = new ControlModuleContext(config, mapping, null);
assertTrue(group.isEmpty());
group.add(module);
assertFalse(group.isEmpty());
assertSame(module, group.getControlModuleContext("test"));
TestRequest request = new TestRequest(new TestSession(module.getServletContext()));
group.setControlModuleContext(request, module);
assertSame(module, ModuleSupport.getInstance(context).getModuleContext(request));
group.remove(module);
assertTrue(group.isEmpty());
}
public static void main(String[] args) {
junit.textui.TestRunner.run(ControlModuleGroupTest.class);
}
}