- Revision
- 100
- Author
- mauro
- Date
- 2007-05-28 06:43:57 -0500 (Mon, 28 May 2007)
Log Message
Better missing action method exception handling. Renamed default controller implementations to have names which explicit better the functionality.
Modified Paths
- trunk/core/src/main/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinder.java
- trunk/core/src/main/java/org/codehaus/waffle/action/NoDefaultMethodException.java
- trunk/core/src/main/java/org/codehaus/waffle/context/pico/PicoWaffleComponentRegistry.java
- trunk/core/src/main/java/org/codehaus/waffle/controller/RubyControllerDefinitionFactory.java
- trunk/core/src/test/java/org/codehaus/waffle/context/pico/PicoWaffleComponentRegistryTest.java
- trunk/pom.xml
Added Paths
- trunk/core/src/main/java/org/codehaus/waffle/action/MissingMethodException.java
- trunk/core/src/main/java/org/codehaus/waffle/action/NoValidMethodException.java
- trunk/core/src/main/java/org/codehaus/waffle/controller/ContextControllerDefinitionFactory.java
- trunk/core/src/main/java/org/codehaus/waffle/controller/ContextPathControllerNameResolver.java
- trunk/core/src/test/java/org/codehaus/waffle/controller/ContextControllerDefinitionFactoryTest.java
- trunk/core/src/test/java/org/codehaus/waffle/controller/ContextPathControllerNameResolverTest.java
Removed Paths
- trunk/core/src/main/java/org/codehaus/waffle/action/InvalidMethodException.java
- trunk/core/src/main/java/org/codehaus/waffle/controller/DefaultControllerDefinitionFactory.java
- trunk/core/src/main/java/org/codehaus/waffle/controller/DefaultControllerNameResolver.java
- trunk/core/src/test/java/org/codehaus/waffle/controller/DefaultControllerDefinitionFactoryTest.java
- trunk/core/src/test/java/org/codehaus/waffle/controller/DefaultControllerNameResolverTest.java
Diff
Modified: trunk/core/src/main/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinder.java (99 => 100)
--- trunk/core/src/main/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinder.java 2007-05-28 10:14:28 UTC (rev 99) +++ trunk/core/src/main/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinder.java 2007-05-28 11:43:57 UTC (rev 100) @@ -167,7 +167,7 @@ List<Object> arguments = getArguments(method, request); try { methodDefinitions.add(buildMethodDefinition(request, response, method, arguments)); - } catch ( InvalidMethodException e) { + } catch ( NoValidMethodException e) { // continue } } @@ -201,7 +201,7 @@ if (Modifier.isPublic(method.getModifiers())) { try { methodDefinitions.add(buildMethodDefinition(request, response, method, arguments)); - } catch (InvalidMethodException e) { + } catch (NoValidMethodException e) { // continue } } @@ -241,8 +241,8 @@ } else if (iterator.hasNext()) { methodDefinition.addMethodArgument(iterator.next()); } else { - // not valid - throw new InvalidMethodException(method.getName()); + // no valid method found + throw new NoValidMethodException(method.getName()); } } @@ -251,7 +251,7 @@ } } - throw new InvalidMethodException(method.getName()); + throw new NoValidMethodException(method.getName()); } private boolean hasEquivalentParameterTypes(MethodDefinition methodDefinition) {
Deleted: trunk/core/src/main/java/org/codehaus/waffle/action/InvalidMethodException.java (99 => 100)
--- trunk/core/src/main/java/org/codehaus/waffle/action/InvalidMethodException.java 2007-05-28 10:14:28 UTC (rev 99) +++ trunk/core/src/main/java/org/codehaus/waffle/action/InvalidMethodException.java 2007-05-28 11:43:57 UTC (rev 100) @@ -1,25 +0,0 @@ -/***************************************************************************** - * Copyright (C) 2005,2006 Michael Ward * - * All rights reserved. * - * ------------------------------------------------------------------------- * - * The software in this package is published under the terms of the BSD * - * style license a copy of which has been included with this distribution in * - * the LICENSE.txt file. * - * * - * Original code by: Michael Ward * - *****************************************************************************/ -package org.codehaus.waffle.action; - - -/** - * Thrown when method is invalid - * - * @author Mauro Talevi - */ -public class InvalidMethodException extends MatchingMethodException { - - public InvalidMethodException(String message) { - super(message); - } - -}
Added: trunk/core/src/main/java/org/codehaus/waffle/action/MissingMethodException.java (0 => 100)
--- trunk/core/src/main/java/org/codehaus/waffle/action/MissingMethodException.java (rev 0) +++ trunk/core/src/main/java/org/codehaus/waffle/action/MissingMethodException.java 2007-05-28 11:43:57 UTC (rev 100) @@ -0,0 +1,14 @@ +package org.codehaus.waffle.action; + +/** + * Thrown when missing methods are identified. + * + * @author Mauro Talevi + */ +public class MissingMethodException extends MethodInvocationException { + + public MissingMethodException(String message) { + super(message); + } + +}
Modified: trunk/core/src/main/java/org/codehaus/waffle/action/NoDefaultMethodException.java (99 => 100)
--- trunk/core/src/main/java/org/codehaus/waffle/action/NoDefaultMethodException.java 2007-05-28 10:14:28 UTC (rev 99) +++ trunk/core/src/main/java/org/codehaus/waffle/action/NoDefaultMethodException.java 2007-05-28 11:43:57 UTC (rev 100) @@ -16,7 +16,7 @@ * * @author Mauro Talevi */ -public class NoDefaultMethodException extends MatchingMethodException { +public class NoDefaultMethodException extends MissingMethodException { public NoDefaultMethodException(String message) { super(message);
Copied: trunk/core/src/main/java/org/codehaus/waffle/action/NoValidMethodException.java (from rev 98, trunk/core/src/main/java/org/codehaus/waffle/action/InvalidMethodException.java) (0 => 100)
--- trunk/core/src/main/java/org/codehaus/waffle/action/NoValidMethodException.java (rev 0) +++ trunk/core/src/main/java/org/codehaus/waffle/action/NoValidMethodException.java 2007-05-28 11:43:57 UTC (rev 100) @@ -0,0 +1,25 @@ +/***************************************************************************** + * Copyright (C) 2005,2006 Michael Ward * + * All rights reserved. * + * ------------------------------------------------------------------------- * + * The software in this package is published under the terms of the BSD * + * style license a copy of which has been included with this distribution in * + * the LICENSE.txt file. * + * * + * Original code by: Michael Ward * + *****************************************************************************/ +package org.codehaus.waffle.action; + + +/** + * Thrown when method is no valid action method is found + * + * @author Mauro Talevi + */ +public class NoValidMethodException extends MissingMethodException { + + public NoValidMethodException(String message) { + super(message); + } + +}
Modified: trunk/core/src/main/java/org/codehaus/waffle/context/pico/PicoWaffleComponentRegistry.java (99 => 100)
--- trunk/core/src/main/java/org/codehaus/waffle/context/pico/PicoWaffleComponentRegistry.java 2007-05-28 10:14:28 UTC (rev 99) +++ trunk/core/src/main/java/org/codehaus/waffle/context/pico/PicoWaffleComponentRegistry.java 2007-05-28 11:43:57 UTC (rev 100) @@ -36,8 +36,8 @@ import org.codehaus.waffle.context.ContextContainerFactory; import org.codehaus.waffle.controller.ControllerDefinitionFactory; import org.codehaus.waffle.controller.ControllerNameResolver; -import org.codehaus.waffle.controller.DefaultControllerDefinitionFactory; -import org.codehaus.waffle.controller.DefaultControllerNameResolver; +import org.codehaus.waffle.controller.ContextControllerDefinitionFactory; +import org.codehaus.waffle.controller.ContextPathControllerNameResolver; import org.codehaus.waffle.i18n.DefaultMessageResources; import org.codehaus.waffle.i18n.MessageResources; import org.codehaus.waffle.monitor.ConsoleMonitor; @@ -78,8 +78,8 @@ register(ArgumentResolver.class, HierarchicalArgumentResolver.class, servletContext); register(BindErrorMessageResolver.class, DefaultBindErrorMessageResolver.class, servletContext); register(ContextContainerFactory.class, PicoContextContainerFactory.class, servletContext); - register(ControllerDefinitionFactory.class, DefaultControllerDefinitionFactory.class, servletContext); - register(ControllerNameResolver.class, DefaultControllerNameResolver.class, servletContext); + register(ControllerDefinitionFactory.class, ContextControllerDefinitionFactory.class, servletContext); + register(ControllerNameResolver.class, ContextPathControllerNameResolver.class, servletContext); register(DataBinder.class, OgnlDataBinder.class, servletContext); register(DispatchAssistant.class, DefaultDispatchAssistant.class, servletContext); register(MessageResources.class, DefaultMessageResources.class, servletContext);
Copied: trunk/core/src/main/java/org/codehaus/waffle/controller/ContextControllerDefinitionFactory.java (from rev 98, trunk/core/src/main/java/org/codehaus/waffle/controller/DefaultControllerDefinitionFactory.java) (0 => 100)
--- trunk/core/src/main/java/org/codehaus/waffle/controller/ContextControllerDefinitionFactory.java (rev 0) +++ trunk/core/src/main/java/org/codehaus/waffle/controller/ContextControllerDefinitionFactory.java 2007-05-28 11:43:57 UTC (rev 100) @@ -0,0 +1,87 @@ +/***************************************************************************** + * Copyright (C) 2005,2006 Michael Ward * + * All rights reserved. * + * ------------------------------------------------------------------------- * + * The software in this package is published under the terms of the BSD * + * style license a copy of which has been included with this distribution in * + * the LICENSE.txt file. * + * * + * Original code by: Michael Ward * + *****************************************************************************/ +package org.codehaus.waffle.controller; + +import static org.codehaus.waffle.Constants.CONTROLLER_KEY; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.codehaus.waffle.WaffleException; +import org.codehaus.waffle.action.MethodDefinition; +import org.codehaus.waffle.action.MethodDefinitionFinder; +import org.codehaus.waffle.action.MissingMethodException; +import org.codehaus.waffle.context.ContextContainer; +import org.codehaus.waffle.context.RequestLevelContainer; + +/** + * Implementation of the controller definition factory which uses the context container to look up the + * controller objected registered. + * + * @author Michael Ward + * @author Mauro Talevi + */ +public class ContextControllerDefinitionFactory implements ControllerDefinitionFactory { + private final MethodDefinitionFinder methodDefinitionFinder; + private final ControllerNameResolver controllerNameResolver; + + public ContextControllerDefinitionFactory(MethodDefinitionFinder methodDefinitionFinder, ControllerNameResolver controllerNameResolver) { + this.methodDefinitionFinder = methodDefinitionFinder; + this.controllerNameResolver = controllerNameResolver; + } + + /** + * Retrieves the controller definition from the context container via the WaffleRequestFilter + * + * @see org.codehaus.waffle.context.WaffleRequestFilter + */ + public ControllerDefinition getControllerDefinition(HttpServletRequest request, HttpServletResponse response) { + String name = controllerNameResolver.findControllerName(request); + + Object controller = findController(name, request); + MethodDefinition methodDefinition = null; + try { + methodDefinition = findMethodDefinition(controller, request, response); + } catch ( MissingMethodException e) { + // default to null + // TODO introduce a NullMethodDefinition? + } + // set the controller to the request so it can be accessed from the view + request.setAttribute(CONTROLLER_KEY, controller); + return new ControllerDefinition(name, controller, methodDefinition); + } + + protected Object findController(String name, HttpServletRequest request) { + ContextContainer requestLevelContainer = RequestLevelContainer.get(); + + if (requestLevelContainer == null) { + String error = "No context container found at request level. " + + "Please ensure that a WaffleRequestFilter was registered in the web.xml"; + throw new WaffleException(error); + } + + Object controller = requestLevelContainer.getComponentInstance(name); + if (controller == null) { + String error = "No controller configured for the specified path: '" + + request.getRequestURI() + "' (controller name='" + name + "') " + + "Please ensure that controller '" + name + "' was registered in the Registrar."; + throw new WaffleException(error); + } + + return controller; + } + + protected MethodDefinition findMethodDefinition(Object controller, HttpServletRequest request, HttpServletResponse response) { + return methodDefinitionFinder.find(controller, request, response); + } + + +}
Copied: trunk/core/src/main/java/org/codehaus/waffle/controller/ContextPathControllerNameResolver.java (from rev 98, trunk/core/src/main/java/org/codehaus/waffle/controller/DefaultControllerNameResolver.java) (0 => 100)
--- trunk/core/src/main/java/org/codehaus/waffle/controller/ContextPathControllerNameResolver.java (rev 0) +++ trunk/core/src/main/java/org/codehaus/waffle/controller/ContextPathControllerNameResolver.java 2007-05-28 11:43:57 UTC (rev 100) @@ -0,0 +1,37 @@ +/***************************************************************************** + * Copyright (C) 2005,2006 Michael Ward * + * All rights reserved. * + * ------------------------------------------------------------------------- * + * The software in this package is published under the terms of the BSD * + * style license a copy of which has been included with this distribution in * + * the LICENSE.txt file. * + * * + * Original code by: Michael Ward * + *****************************************************************************/ +package org.codehaus.waffle.controller; + +import javax.servlet.http.HttpServletRequest; + +/** + * Default implementations of name resolver which return the name of the last portion of the context path before the dot. + * + * @author Michael Ward + */ +public class ContextPathControllerNameResolver implements ControllerNameResolver { + private static final String DOT_REGEX = "\\."; + + public ContextPathControllerNameResolver() { + } + + public String findControllerName(HttpServletRequest request) { + String path = request.getPathInfo(); + + if (path == null) { + path = request.getRequestURI().replaceFirst(request.getContextPath(), ""); + } + + path = path.substring(1); // remove '/' + return path.split(DOT_REGEX)[0]; + } + +}
Deleted: trunk/core/src/main/java/org/codehaus/waffle/controller/DefaultControllerDefinitionFactory.java (99 => 100)
--- trunk/core/src/main/java/org/codehaus/waffle/controller/DefaultControllerDefinitionFactory.java 2007-05-28 10:14:28 UTC (rev 99) +++ trunk/core/src/main/java/org/codehaus/waffle/controller/DefaultControllerDefinitionFactory.java 2007-05-28 11:43:57 UTC (rev 100) @@ -1,80 +0,0 @@ -/***************************************************************************** - * Copyright (C) 2005,2006 Michael Ward * - * All rights reserved. * - * ------------------------------------------------------------------------- * - * The software in this package is published under the terms of the BSD * - * style license a copy of which has been included with this distribution in * - * the LICENSE.txt file. * - * * - * Original code by: Michael Ward * - *****************************************************************************/ -package org.codehaus.waffle.controller; - -import static org.codehaus.waffle.Constants.CONTROLLER_KEY; -import org.codehaus.waffle.WaffleException; -import org.codehaus.waffle.action.MethodDefinition; -import org.codehaus.waffle.action.MethodDefinitionFinder; -import org.codehaus.waffle.context.ContextContainer; -import org.codehaus.waffle.context.RequestLevelContainer; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * Default implementation of the controller definition factory which uses the context container to look up the - * controller objected registered. - * - * @author Michael Ward - * @author Mauro Talevi - * @todo (mt) Rename to ContextContainerControllerDefinitionFactory? - */ -public class DefaultControllerDefinitionFactory implements ControllerDefinitionFactory { - private final MethodDefinitionFinder methodDefinitionFinder; - private final ControllerNameResolver controllerNameResolver; - - public DefaultControllerDefinitionFactory(MethodDefinitionFinder methodDefinitionFinder, ControllerNameResolver controllerNameResolver) { - this.methodDefinitionFinder = methodDefinitionFinder; - this.controllerNameResolver = controllerNameResolver; - } - - protected Object findController(String name, HttpServletRequest request) { - ContextContainer requestLevelContainer = RequestLevelContainer.get(); - - if (requestLevelContainer == null) { - String error = "No context container found at request level." - + "Please ensure that a WaffleRequestFilter was registered in the web.xml"; - throw new WaffleException(error); - } - - Object controller = requestLevelContainer.getComponentInstance(name); - if (controller == null) { - String error = "No controller configured for the specified path: '" - + request.getRequestURI() + "' (controller name='" + name + "') " - + "Please ensure that controller '" + name + "' was registered in the Registrar."; - throw new WaffleException(error); - } - - return controller; - } - - protected MethodDefinition findMethodDefinition(Object controller, HttpServletRequest request, HttpServletResponse response) { - return methodDefinitionFinder.find(controller, request, response); - } - - /** - * Retrieves the controller definition from the context container via the WaffleRequestFilter - * - * @see org.codehaus.waffle.context.WaffleRequestFilter - */ - public ControllerDefinition getControllerDefinition(HttpServletRequest request, HttpServletResponse response) { - String name = controllerNameResolver.findControllerName(request); - - Object controller = findController(name, request); - MethodDefinition methodDefinition = findMethodDefinition(controller, request, response); - - // set the controller to the request so it can be accessed from the view - request.setAttribute(CONTROLLER_KEY, controller); - return new ControllerDefinition(name, controller, methodDefinition); - } - -}
Deleted: trunk/core/src/main/java/org/codehaus/waffle/controller/DefaultControllerNameResolver.java (99 => 100)
--- trunk/core/src/main/java/org/codehaus/waffle/controller/DefaultControllerNameResolver.java 2007-05-28 10:14:28 UTC (rev 99) +++ trunk/core/src/main/java/org/codehaus/waffle/controller/DefaultControllerNameResolver.java 2007-05-28 11:43:57 UTC (rev 100) @@ -1,37 +0,0 @@ -/***************************************************************************** - * Copyright (C) 2005,2006 Michael Ward * - * All rights reserved. * - * ------------------------------------------------------------------------- * - * The software in this package is published under the terms of the BSD * - * style license a copy of which has been included with this distribution in * - * the LICENSE.txt file. * - * * - * Original code by: Michael Ward * - *****************************************************************************/ -package org.codehaus.waffle.controller; - -import javax.servlet.http.HttpServletRequest; - -/** - * Default implementations of name resolver which return the name of the last portion of the context path before the dot. - * - * @author Michael Ward - */ -public class DefaultControllerNameResolver implements ControllerNameResolver { - private static final String DOT_REGEX = "\\."; - - public DefaultControllerNameResolver() { - } - - public String findControllerName(HttpServletRequest request) { - String path = request.getPathInfo(); - - if (path == null) { - path = request.getRequestURI().replaceFirst(request.getContextPath(), ""); - } - - path = path.substring(1); // remove '/' - return path.split(DOT_REGEX)[0]; - } - -}
Modified: trunk/core/src/main/java/org/codehaus/waffle/controller/RubyControllerDefinitionFactory.java (99 => 100)
--- trunk/core/src/main/java/org/codehaus/waffle/controller/RubyControllerDefinitionFactory.java 2007-05-28 10:14:28 UTC (rev 99) +++ trunk/core/src/main/java/org/codehaus/waffle/controller/RubyControllerDefinitionFactory.java 2007-05-28 11:43:57 UTC (rev 100) @@ -10,7 +10,7 @@ import javax.servlet.http.HttpServletResponse; import java.lang.reflect.Method; -public class RubyControllerDefinitionFactory extends DefaultControllerDefinitionFactory { +public class RubyControllerDefinitionFactory extends ContextControllerDefinitionFactory { private final MethodNameResolver methodNameResolver; private static final Method executeMethod;
Modified: trunk/core/src/test/java/org/codehaus/waffle/context/pico/PicoWaffleComponentRegistryTest.java (99 => 100)
--- trunk/core/src/test/java/org/codehaus/waffle/context/pico/PicoWaffleComponentRegistryTest.java 2007-05-28 10:14:28 UTC (rev 99) +++ trunk/core/src/test/java/org/codehaus/waffle/context/pico/PicoWaffleComponentRegistryTest.java 2007-05-28 11:43:57 UTC (rev 100) @@ -30,8 +30,8 @@ import org.codehaus.waffle.context.ContextContainerFactory; import org.codehaus.waffle.controller.ControllerDefinitionFactory; import org.codehaus.waffle.controller.ControllerNameResolver; -import org.codehaus.waffle.controller.DefaultControllerDefinitionFactory; -import org.codehaus.waffle.controller.DefaultControllerNameResolver; +import org.codehaus.waffle.controller.ContextControllerDefinitionFactory; +import org.codehaus.waffle.controller.ContextPathControllerNameResolver; import org.codehaus.waffle.i18n.DefaultMessageResources; import org.codehaus.waffle.i18n.MessageResources; import org.codehaus.waffle.monitor.ConsoleMonitor; @@ -103,8 +103,8 @@ ServletContext servletContext = (ServletContext) mockServletContext.proxy(); WaffleComponentRegistry componentRegistry = new PicoWaffleComponentRegistry(servletContext); - assertTrue(componentRegistry.getControllerNameResolver() instanceof DefaultControllerNameResolver); - assertTrue(componentRegistry.getControllerDefinitionFactory() instanceof DefaultControllerDefinitionFactory); + assertTrue(componentRegistry.getControllerNameResolver() instanceof ContextPathControllerNameResolver); + assertTrue(componentRegistry.getControllerDefinitionFactory() instanceof ContextControllerDefinitionFactory); assertTrue(componentRegistry.getContextContainerFactory() instanceof AbstractContextContainerFactory); assertTrue(componentRegistry.getBindErrorMessageResolver() instanceof DefaultBindErrorMessageResolver); assertTrue(componentRegistry.getDataBinder() instanceof OgnlDataBinder);
Copied: trunk/core/src/test/java/org/codehaus/waffle/controller/ContextControllerDefinitionFactoryTest.java (from rev 98, trunk/core/src/test/java/org/codehaus/waffle/controller/DefaultControllerDefinitionFactoryTest.java) (0 => 100)
--- trunk/core/src/test/java/org/codehaus/waffle/controller/ContextControllerDefinitionFactoryTest.java (rev 0) +++ trunk/core/src/test/java/org/codehaus/waffle/controller/ContextControllerDefinitionFactoryTest.java 2007-05-28 11:43:57 UTC (rev 100) @@ -0,0 +1,108 @@ +package org.codehaus.waffle.controller; + +import org.codehaus.waffle.Constants; +import org.codehaus.waffle.WaffleException; +import org.codehaus.waffle.action.MethodDefinition; +import org.codehaus.waffle.action.MethodDefinitionFinder; +import org.codehaus.waffle.context.RequestLevelContainer; +import org.codehaus.waffle.context.pico.PicoContextContainer; +import org.codehaus.waffle.testmodel.FakeController; +import org.jmock.Mock; +import org.jmock.MockObjectTestCase; +import org.picocontainer.MutablePicoContainer; +import org.picocontainer.defaults.DefaultPicoContainer; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class ContextControllerDefinitionFactoryTest extends MockObjectTestCase { + + public void testCanGetControllerDefinition() throws NoSuchMethodException { + MutablePicoContainer pico = new DefaultPicoContainer(); + pico.registerComponentImplementation("theController", FakeController.class); + RequestLevelContainer.set(new PicoContextContainer(pico)); + + // Mock HttpServletRequest + Mock mockRequest = mock(HttpServletRequest.class); + mockRequest.expects(once()) + .method("getPathInfo") + .will(returnValue("/theController.htm")); + mockRequest.expects(once()).method("setAttribute") + .with(eq(Constants.CONTROLLER_KEY), isA(FakeController.class)); + HttpServletRequest httpRequest = (HttpServletRequest) mockRequest.proxy(); + + // Mock HttpServletResponse + Mock mockResponse = mock(HttpServletResponse.class); + HttpServletResponse response = (HttpServletResponse) mockResponse.proxy(); + + MethodDefinition methodDefinition = new MethodDefinition(null); + + // Mock MethodDefinitionFinder + Mock mockMethodDefinitionFinder = mock(MethodDefinitionFinder.class); + mockMethodDefinitionFinder.expects(once()) + .method("find") + .with(isA(FakeController.class), same(httpRequest), same(response)) + .will(returnValue(methodDefinition)); + MethodDefinitionFinder methodDefinitionFinder = (MethodDefinitionFinder) mockMethodDefinitionFinder.proxy(); + + ControllerDefinitionFactory controllerDefinitionFactory + = new ContextControllerDefinitionFactory(methodDefinitionFinder, new ContextPathControllerNameResolver()); + ControllerDefinition controllerDefinition = controllerDefinitionFactory.getControllerDefinition(httpRequest, response); + + assertNotNull(controllerDefinition.getController()); + assertSame(methodDefinition, controllerDefinition.getMethodDefinition()); + } + + public void testRequestingControllerDefinitionThatiIsNotRegisteredThrowsException() throws NoSuchMethodException { + MutablePicoContainer pico = new DefaultPicoContainer(); + RequestLevelContainer.set(new PicoContextContainer(pico)); + + // Mock HttpServletRequest + Mock mockRequest = mock(HttpServletRequest.class); + mockRequest.expects(once()) + .method("getPathInfo") + .will(returnValue("/theController.htm")); + mockRequest.expects(once()) + .method("getRequestURI") + .will(returnValue("/theController.htm")); + HttpServletRequest httpRequest = (HttpServletRequest) mockRequest.proxy(); + + // Mock HttpServletResponse + Mock mockResponse = mock(HttpServletResponse.class); + HttpServletResponse response = (HttpServletResponse) mockResponse.proxy(); + + // Mock MethodDefinitionFinder + Mock mockMethodDefinitionFinder = mock(MethodDefinitionFinder.class); + MethodDefinitionFinder methodDefinitionFinder = (MethodDefinitionFinder) mockMethodDefinitionFinder.proxy(); + + ControllerDefinitionFactory controllerDefinitionFactory + = new ContextControllerDefinitionFactory(methodDefinitionFinder, new ContextPathControllerNameResolver()); + + try { + controllerDefinitionFactory.getControllerDefinition(httpRequest, response); + fail("WaffleException expected"); + } catch (WaffleException e) { + //expected + } + } + + public void testMissingRequestLevelContainerThrowsException() throws NoSuchMethodException { + RequestLevelContainer.set(null); + // Mock HttpServletRequest + Mock mockHttpServletRequest = mock(HttpServletRequest.class); + HttpServletRequest httpRequest = (HttpServletRequest) mockHttpServletRequest.proxy(); + + // Mock HttpServletResponse + Mock mockResponse = mock(HttpServletResponse.class); + + ContextControllerDefinitionFactory controllerDefinitionFactory = new ContextControllerDefinitionFactory(null, null); + + try { + controllerDefinitionFactory.findController("foobar", httpRequest); + fail("WaffleException should have been thrown when no request level container exists"); + } catch (WaffleException expected) { + // expected + } + } + +}
Copied: trunk/core/src/test/java/org/codehaus/waffle/controller/ContextPathControllerNameResolverTest.java (from rev 98, trunk/core/src/test/java/org/codehaus/waffle/controller/DefaultControllerNameResolverTest.java) (0 => 100)
--- trunk/core/src/test/java/org/codehaus/waffle/controller/ContextPathControllerNameResolverTest.java (rev 0) +++ trunk/core/src/test/java/org/codehaus/waffle/controller/ContextPathControllerNameResolverTest.java 2007-05-28 11:43:57 UTC (rev 100) @@ -0,0 +1,50 @@ +package org.codehaus.waffle.controller; + +import org.jmock.Mock; +import org.jmock.MockObjectTestCase; +import org.codehaus.waffle.controller.ContextPathControllerNameResolver; +import org.codehaus.waffle.controller.ControllerNameResolver; + +import javax.servlet.http.HttpServletRequest; + +public class ContextPathControllerNameResolverTest extends MockObjectTestCase { + + public void testFindControllerName() { + Mock mockRequest = mock(HttpServletRequest.class); + mockRequest.expects(once()) + .method("getPathInfo") + .will(returnValue("/foo/bar.htm")); + HttpServletRequest request = (HttpServletRequest) mockRequest.proxy(); + + ControllerNameResolver controllerNameResolver = new ContextPathControllerNameResolver(); + assertEquals("foo/bar", controllerNameResolver.findControllerName(request)); + } + + public void testFindControllerNameWithoutExtension() { + Mock mockRequest = mock(HttpServletRequest.class); + mockRequest.expects(once()) + .method("getPathInfo") + .will(returnValue("/foobar")); + HttpServletRequest request = (HttpServletRequest) mockRequest.proxy(); + + ControllerNameResolver controllerNameResolver = new ContextPathControllerNameResolver(); + assertEquals("foobar", controllerNameResolver.findControllerName(request)); + } + + public void testFindControllerNameWhenPathInfoIsNull() { + Mock mockRequest = mock(HttpServletRequest.class); + mockRequest.expects(once()) + .method("getPathInfo") + .will(returnValue(null)); + mockRequest.expects(once()) + .method("getRequestURI") + .will(returnValue("/waffle/foobar.htm")); + mockRequest.expects(once()) + .method("getContextPath") + .will(returnValue("/waffle")); + HttpServletRequest request = (HttpServletRequest) mockRequest.proxy(); + + ControllerNameResolver controllerNameResolver = new ContextPathControllerNameResolver(); + assertEquals("foobar", controllerNameResolver.findControllerName(request)); + } +}
Deleted: trunk/core/src/test/java/org/codehaus/waffle/controller/DefaultControllerDefinitionFactoryTest.java (99 => 100)
--- trunk/core/src/test/java/org/codehaus/waffle/controller/DefaultControllerDefinitionFactoryTest.java 2007-05-28 10:14:28 UTC (rev 99) +++ trunk/core/src/test/java/org/codehaus/waffle/controller/DefaultControllerDefinitionFactoryTest.java 2007-05-28 11:43:57 UTC (rev 100) @@ -1,108 +0,0 @@ -package org.codehaus.waffle.controller; - -import org.codehaus.waffle.Constants; -import org.codehaus.waffle.WaffleException; -import org.codehaus.waffle.action.MethodDefinition; -import org.codehaus.waffle.action.MethodDefinitionFinder; -import org.codehaus.waffle.context.RequestLevelContainer; -import org.codehaus.waffle.context.pico.PicoContextContainer; -import org.codehaus.waffle.testmodel.FakeController; -import org.jmock.Mock; -import org.jmock.MockObjectTestCase; -import org.picocontainer.MutablePicoContainer; -import org.picocontainer.defaults.DefaultPicoContainer; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -public class DefaultControllerDefinitionFactoryTest extends MockObjectTestCase { - - public void testCanGetControllerDefinition() throws NoSuchMethodException { - MutablePicoContainer pico = new DefaultPicoContainer(); - pico.registerComponentImplementation("theController", FakeController.class); - RequestLevelContainer.set(new PicoContextContainer(pico)); - - // Mock HttpServletRequest - Mock mockRequest = mock(HttpServletRequest.class); - mockRequest.expects(once()) - .method("getPathInfo") - .will(returnValue("/theController.htm")); - mockRequest.expects(once()).method("setAttribute") - .with(eq(Constants.CONTROLLER_KEY), isA(FakeController.class)); - HttpServletRequest httpRequest = (HttpServletRequest) mockRequest.proxy(); - - // Mock HttpServletResponse - Mock mockResponse = mock(HttpServletResponse.class); - HttpServletResponse response = (HttpServletResponse) mockResponse.proxy(); - - MethodDefinition methodDefinition = new MethodDefinition(null); - - // Mock MethodDefinitionFinder - Mock mockMethodDefinitionFinder = mock(MethodDefinitionFinder.class); - mockMethodDefinitionFinder.expects(once()) - .method("find") - .with(isA(FakeController.class), same(httpRequest), same(response)) - .will(returnValue(methodDefinition)); - MethodDefinitionFinder methodDefinitionFinder = (MethodDefinitionFinder) mockMethodDefinitionFinder.proxy(); - - ControllerDefinitionFactory controllerDefinitionFactory - = new DefaultControllerDefinitionFactory(methodDefinitionFinder, new DefaultControllerNameResolver()); - ControllerDefinition controllerDefinition = controllerDefinitionFactory.getControllerDefinition(httpRequest, response); - - assertNotNull(controllerDefinition.getController()); - assertSame(methodDefinition, controllerDefinition.getMethodDefinition()); - } - - public void testRequestingControllerDefinitionThatiIsNotRegisteredThrowsException() throws NoSuchMethodException { - MutablePicoContainer pico = new DefaultPicoContainer(); - RequestLevelContainer.set(new PicoContextContainer(pico)); - - // Mock HttpServletRequest - Mock mockRequest = mock(HttpServletRequest.class); - mockRequest.expects(once()) - .method("getPathInfo") - .will(returnValue("/theController.htm")); - mockRequest.expects(once()) - .method("getRequestURI") - .will(returnValue("/theController.htm")); - HttpServletRequest httpRequest = (HttpServletRequest) mockRequest.proxy(); - - // Mock HttpServletResponse - Mock mockResponse = mock(HttpServletResponse.class); - HttpServletResponse response = (HttpServletResponse) mockResponse.proxy(); - - // Mock MethodDefinitionFinder - Mock mockMethodDefinitionFinder = mock(MethodDefinitionFinder.class); - MethodDefinitionFinder methodDefinitionFinder = (MethodDefinitionFinder) mockMethodDefinitionFinder.proxy(); - - ControllerDefinitionFactory controllerDefinitionFactory - = new DefaultControllerDefinitionFactory(methodDefinitionFinder, new DefaultControllerNameResolver()); - - try { - controllerDefinitionFactory.getControllerDefinition(httpRequest, response); - fail("WaffleException expected"); - } catch (WaffleException e) { - //expected - } - } - - public void testMissingRequestLevelContainerThrowsException() throws NoSuchMethodException { - RequestLevelContainer.set(null); - // Mock HttpServletRequest - Mock mockHttpServletRequest = mock(HttpServletRequest.class); - HttpServletRequest httpRequest = (HttpServletRequest) mockHttpServletRequest.proxy(); - - // Mock HttpServletResponse - Mock mockResponse = mock(HttpServletResponse.class); - - DefaultControllerDefinitionFactory controllerDefinitionFactory = new DefaultControllerDefinitionFactory(null, null); - - try { - controllerDefinitionFactory.findController("foobar", httpRequest); - fail("WaffleException should have been thrown when no request level container exists"); - } catch (WaffleException expected) { - // expected - } - } - -}
Deleted: trunk/core/src/test/java/org/codehaus/waffle/controller/DefaultControllerNameResolverTest.java (99 => 100)
--- trunk/core/src/test/java/org/codehaus/waffle/controller/DefaultControllerNameResolverTest.java 2007-05-28 10:14:28 UTC (rev 99) +++ trunk/core/src/test/java/org/codehaus/waffle/controller/DefaultControllerNameResolverTest.java 2007-05-28 11:43:57 UTC (rev 100) @@ -1,50 +0,0 @@ -package org.codehaus.waffle.controller; - -import org.jmock.Mock; -import org.jmock.MockObjectTestCase; -import org.codehaus.waffle.controller.DefaultControllerNameResolver; -import org.codehaus.waffle.controller.ControllerNameResolver; - -import javax.servlet.http.HttpServletRequest; - -public class DefaultControllerNameResolverTest extends MockObjectTestCase { - - public void testFindControllerName() { - Mock mockRequest = mock(HttpServletRequest.class); - mockRequest.expects(once()) - .method("getPathInfo") - .will(returnValue("/foo/bar.htm")); - HttpServletRequest request = (HttpServletRequest) mockRequest.proxy(); - - ControllerNameResolver controllerNameResolver = new DefaultControllerNameResolver(); - assertEquals("foo/bar", controllerNameResolver.findControllerName(request)); - } - - public void testFindControllerNameWithoutExtension() { - Mock mockRequest = mock(HttpServletRequest.class); - mockRequest.expects(once()) - .method("getPathInfo") - .will(returnValue("/foobar")); - HttpServletRequest request = (HttpServletRequest) mockRequest.proxy(); - - ControllerNameResolver controllerNameResolver = new DefaultControllerNameResolver(); - assertEquals("foobar", controllerNameResolver.findControllerName(request)); - } - - public void testFindControllerNameWhenPathInfoIsNull() { - Mock mockRequest = mock(HttpServletRequest.class); - mockRequest.expects(once()) - .method("getPathInfo") - .will(returnValue(null)); - mockRequest.expects(once()) - .method("getRequestURI") - .will(returnValue("/waffle/foobar.htm")); - mockRequest.expects(once()) - .method("getContextPath") - .will(returnValue("/waffle")); - HttpServletRequest request = (HttpServletRequest) mockRequest.proxy(); - - ControllerNameResolver controllerNameResolver = new DefaultControllerNameResolver(); - assertEquals("foobar", controllerNameResolver.findControllerName(request)); - } -}
Modified: trunk/pom.xml (99 => 100)
--- trunk/pom.xml 2007-05-28 10:14:28 UTC (rev 99) +++ trunk/pom.xml 2007-05-28 11:43:57 UTC (rev 100) @@ -96,6 +96,32 @@ <version>4.3.1</version> <scope>provided</scope> </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <version>1.1</version> + <scope>provided</scope> + <exclusions> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + <exclusion> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.14</version> + <scope>provided</scope> + </dependency> </dependencies> </dependencyManagement>
To unsubscribe from this list please visit:
