/*
* 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 de.odysseus.calyxo.base.conf.ConfigException;
import de.odysseus.calyxo.base.test.TestRequest;
import de.odysseus.calyxo.control.base.ControlModuleMapping;
import junit.framework.TestCase;
/**
*
* @author Christoph Beck
*/
public class ControlModuleMappingTest extends TestCase {
private static final String INCLUDE_PATH_INFO =
"javax.servlet.include.path_info";
private static final String INCLUDE_SERVLET_PATH =
"javax.servlet.include.servlet_path";
/**
* Constructor for ControlModuleMappingTest.
* @param arg0
*/
public ControlModuleMappingTest(String arg0) {
super(arg0);
}
public void testPattern() throws ConfigException {
ControlModuleMapping mapping = null;
mapping = new ControlModuleMapping("/test/*");
assertEquals("/test", mapping.getPrefix());
assertNull(mapping.getExtension());
mapping = new ControlModuleMapping("*.test");
assertEquals(".test", mapping.getExtension());
assertNull(mapping.getPrefix());
mapping = new ControlModuleMapping("/");
assertEquals("", mapping.getPrefix());
assertNull(mapping.getExtension());
mapping = new ControlModuleMapping("/*");
assertEquals("", mapping.getPrefix());
assertNull(mapping.getExtension());
}
public void testEmptyPrefixPath() throws ConfigException {
ControlModuleMapping mapping = new ControlModuleMapping("", null);
assertEquals("/action", mapping.getPath("/action"));
}
public void testPrefixPath() throws ConfigException {
ControlModuleMapping mapping = new ControlModuleMapping("/test", null);
assertEquals("/test/action", mapping.getPath("/action"));
assertEquals("/test/action", mapping.getPath("action"));
assertEquals("/test/action?foo=bar", mapping.getPath("/action?foo=bar"));
}
public void testPrefixAction() throws ConfigException {
ControlModuleMapping mapping = new ControlModuleMapping("/test", null);
TestRequest request = new TestRequest();
request.setAttribute(INCLUDE_SERVLET_PATH, "/test");
request.setAttribute(INCLUDE_PATH_INFO, "/action");
assertEquals("/action", mapping.getAction(request));
}
public void testExtensionPath() throws ConfigException {
ControlModuleMapping mapping = new ControlModuleMapping(null, ".test");
assertEquals("/action.test", mapping.getPath("/action"));
assertEquals("/action.test", mapping.getPath("action"));
assertEquals("/action.test?foo=bar", mapping.getPath("/action?foo=bar"));
}
public void testExtensionAction() throws ConfigException {
ControlModuleMapping mapping = new ControlModuleMapping(null, ".test");
TestRequest request = new TestRequest();
request.setAttribute(INCLUDE_SERVLET_PATH, "/action.test");
request.removeAttribute(INCLUDE_PATH_INFO);
assertEquals("/action", mapping.getAction(request));
}
public void testPrefixExtensionAction() throws ConfigException {
ControlModuleMapping mapping = new ControlModuleMapping("/test", ".do");
TestRequest request = new TestRequest();
request.setAttribute(INCLUDE_SERVLET_PATH, "/test/action.do");
request.removeAttribute(INCLUDE_PATH_INFO);
assertEquals("/action", mapping.getAction(request));
}
public void testPrefixExtensionPath() throws ConfigException {
ControlModuleMapping mapping = new ControlModuleMapping("/test", ".do");
assertEquals("/test/action.do", mapping.getPath("/action"));
assertEquals("/test/action.do", mapping.getPath("action"));
assertEquals("/test/action.do?foo=bar", mapping.getPath("/action?foo=bar"));
}
public static void main(String[] args) {
junit.textui.TestRunner.run(ControlModuleMappingTest.class);
}
}