- Revision
- 861
- Author
- paul
- Date
- 2009-01-13 23:44:24 -0600 (Tue, 13 Jan 2009)
Log Message
more undoing RequestLevelContainer.get() usage
Modified Paths
- trunk/waffle-core/pom.xml
- trunk/waffle-core/src/main/java/org/codehaus/waffle/servlet/WaffleServlet.java
- trunk/waffle-core/src/main/java/org/codehaus/waffle/validation/DefaultValidator.java
- trunk/waffle-core/src/main/java/org/codehaus/waffle/validation/Validator.java
- trunk/waffle-core/src/test/java/org/codehaus/waffle/servlet/WaffleServletTest.java
- trunk/waffle-core/src/test/java/org/codehaus/waffle/testmodel/StubValidator.java
Removed Paths
Diff
Modified: trunk/waffle-core/pom.xml (860 => 861)
--- trunk/waffle-core/pom.xml 2009-01-13 23:21:09 UTC (rev 860) +++ trunk/waffle-core/pom.xml 2009-01-14 05:44:24 UTC (rev 861) @@ -18,7 +18,7 @@ <dependency> <groupId>org.picocontainer</groupId> <artifactId>picocontainer</artifactId> - <version>2.5.1</version> + <version>2.6</version> </dependency> <dependency> <groupId>javax.servlet</groupId>
Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/servlet/WaffleServlet.java (860 => 861)
--- trunk/waffle-core/src/main/java/org/codehaus/waffle/servlet/WaffleServlet.java 2009-01-13 23:21:09 UTC (rev 860) +++ trunk/waffle-core/src/main/java/org/codehaus/waffle/servlet/WaffleServlet.java 2009-01-14 05:44:24 UTC (rev 861) @@ -40,9 +40,12 @@ import org.codehaus.waffle.i18n.MessageResources; import org.codehaus.waffle.i18n.MessagesContext; import org.codehaus.waffle.monitor.ServletMonitor; +import org.codehaus.waffle.monitor.ValidationMonitor; import org.codehaus.waffle.validation.ErrorsContext; import org.codehaus.waffle.validation.GlobalErrorMessage; import org.codehaus.waffle.validation.Validator; +import org.codehaus.waffle.validation.ValidatorConfiguration; +import org.codehaus.waffle.validation.DefaultValidatorConfiguration; import org.codehaus.waffle.view.RedirectView; import org.codehaus.waffle.view.View; import org.codehaus.waffle.view.ViewResolver; @@ -168,6 +171,12 @@ Collection<MethodInterceptor> methodInterceptors = requestContainer.getAllComponentInstancesOfType(MethodInterceptor.class); MessagesContext messageContext = requestContainer.getComponent(MessagesContext.class); + ValidationMonitor validationMonitor = requestContainer.getComponent(ValidationMonitor.class); + ValidatorConfiguration validatorConfiguration = requestContainer.getComponent(ValidatorConfiguration.class); + if (validatorConfiguration == null) { + validatorConfiguration = new DefaultValidatorConfiguration(); + } + ActionMethodResponse actionMethodResponse = new ActionMethodResponse(); View view = null; try { @@ -175,7 +184,18 @@ ControllerDefinition controllerDefinition = controllerDefinitionFactory.getControllerDefinition(request, response, messageContext); controllerDataBinder.bind(request, response, errorsContext, controllerDefinition.getController()); - validator.validate(controllerDefinition, errorsContext); + String controllerName = controllerDefinition.getName(); + Object controllerValidator; + String controllerValidatorName = controllerName + validatorConfiguration.getSuffix(); + controllerValidator = requestContainer.getComponentInstance(controllerValidatorName); + + if (controllerValidator == null) { + // default to use controller as validator + controllerValidator = requestContainer.getComponentInstance(controllerName); + validationMonitor.controllerValidatorNotFound(controllerValidatorName, controllerName); + } + + validator.validate(controllerDefinition, errorsContext, controllerValidator); try { if (errorsContext.hasErrorMessages() || noMethodDefinition(controllerDefinition)) { @@ -321,4 +341,5 @@ return sb.toString(); } + }
Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/validation/DefaultValidator.java (860 => 861)
--- trunk/waffle-core/src/main/java/org/codehaus/waffle/validation/DefaultValidator.java 2009-01-13 23:21:09 UTC (rev 860) +++ trunk/waffle-core/src/main/java/org/codehaus/waffle/validation/DefaultValidator.java 2009-01-14 05:44:24 UTC (rev 861) @@ -22,30 +22,15 @@ * @author Mauro Talevi */ public class DefaultValidator implements Validator { + private final ValidationMonitor validationMonitor; - private final ValidatorConfiguration validatorConfiguration; - + public DefaultValidator(ValidationMonitor validationMonitor){ - this(new DefaultValidatorConfiguration(), validationMonitor); + this.validationMonitor = validationMonitor; } - - public DefaultValidator(ValidatorConfiguration validatorConfiguration, ValidationMonitor validationMonitor){ - this.validatorConfiguration = validatorConfiguration; - this.validationMonitor = validationMonitor; - } - public void validate(ControllerDefinition controllerDefinition, ErrorsContext errorsContext) { - ContextContainer container = RequestLevelContainer.get(); - String controllerName = controllerDefinition.getName(); - String controllerValidatorName = controllerName + validatorConfiguration.getSuffix(); - Object controllerValidator = container.getComponentInstance(controllerValidatorName); + public void validate(ControllerDefinition controllerDefinition, ErrorsContext errorsContext, Object controllerValidator) { - if (controllerValidator == null) { - // default to use controller as validator - controllerValidator = container.getComponentInstance(controllerName); - validationMonitor.controllerValidatorNotFound(controllerValidatorName, controllerName); - } - MethodDefinition methodDefinition = controllerDefinition.getMethodDefinition(); if (methodDefinition == null) { validationMonitor.methodDefinitionNotFound(controllerDefinition); @@ -80,4 +65,5 @@ throw new WaffleException(e); } } + }
Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/validation/Validator.java (860 => 861)
--- trunk/waffle-core/src/main/java/org/codehaus/waffle/validation/Validator.java 2009-01-13 23:21:09 UTC (rev 860) +++ trunk/waffle-core/src/main/java/org/codehaus/waffle/validation/Validator.java 2009-01-14 05:44:24 UTC (rev 861) @@ -7,6 +7,7 @@ public interface Validator { - void validate(ControllerDefinition controllerDefinition, ErrorsContext errorsContext); + void validate(ControllerDefinition controllerDefinition, ErrorsContext errorsContext, + Object controllerValidator); }
Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/servlet/WaffleServletTest.java (860 => 861)
--- trunk/waffle-core/src/test/java/org/codehaus/waffle/servlet/WaffleServletTest.java 2009-01-13 23:21:09 UTC (rev 860) +++ trunk/waffle-core/src/test/java/org/codehaus/waffle/servlet/WaffleServletTest.java 2009-01-14 05:44:24 UTC (rev 861) @@ -48,9 +48,11 @@ import org.codehaus.waffle.i18n.MessagesContext; import org.codehaus.waffle.monitor.ServletMonitor; import org.codehaus.waffle.monitor.SilentMonitor; +import org.codehaus.waffle.monitor.ValidationMonitor; import org.codehaus.waffle.validation.ErrorMessage; import org.codehaus.waffle.validation.ErrorsContext; import org.codehaus.waffle.validation.Validator; +import org.codehaus.waffle.validation.ValidatorConfiguration; import org.codehaus.waffle.view.DefaultViewResolver; import org.codehaus.waffle.view.View; import org.codehaus.waffle.view.ViewResolver; @@ -131,6 +133,8 @@ final ErrorsContext errorsContext = mockery.mock(ErrorsContext.class); final ContextContainer contextContainer = mockery.mock(ContextContainer.class); final MessagesContext messageContext = mockery.mock(MessagesContext.class); + final ValidationMonitor validationMonitor = mockery.mock(ValidationMonitor.class); + final ValidatorConfiguration validatorConfiguration = mockery.mock(ValidatorConfiguration.class); mockery.checking(new Expectations() { { @@ -142,6 +146,14 @@ will(returnValue(new ArrayList<Object>())); one(contextContainer).getComponent(MessagesContext.class); will(returnValue(messageContext)); + one(contextContainer).getComponent(ValidationMonitor.class); + will(returnValue(validationMonitor)); + one(contextContainer).getComponent(ValidatorConfiguration.class); + will(returnValue(validatorConfiguration)); + one(validatorConfiguration).getSuffix(); + will(returnValue(".xx")); + one(contextContainer).getComponentInstance("no name.xx"); + will(returnValue("yy")); } }); @@ -183,7 +195,7 @@ final Validator validator = mockery.mock(Validator.class); mockery.checking(new Expectations() { { - one(validator).validate(with(any(ControllerDefinition.class)), with(any(ErrorsContext.class))); + one(validator).validate(with(any(ControllerDefinition.class)), with(any(ErrorsContext.class)), with(same("yy"))); } }); @@ -229,6 +241,8 @@ final ErrorsContext errorsContext = mockery.mock(ErrorsContext.class); final ContextContainer contextContainer = mockery.mock(ContextContainer.class); final MessagesContext messageContext = mockery.mock(MessagesContext.class); + final ValidationMonitor validationMonitor = mockery.mock(ValidationMonitor.class); + final ValidatorConfiguration validatorConfiguration = mockery.mock(ValidatorConfiguration.class); mockery.checking(new Expectations() { { @@ -240,6 +254,14 @@ will(returnValue(new ArrayList<Object>())); one(contextContainer).getComponent(MessagesContext.class); will(returnValue(messageContext)); + one(contextContainer).getComponent(ValidationMonitor.class); + will(returnValue(validationMonitor)); + one(contextContainer).getComponent(ValidatorConfiguration.class); + will(returnValue(validatorConfiguration)); + one(validatorConfiguration).getSuffix(); + will(returnValue(".xx")); + one(contextContainer).getComponentInstance("no name.xx"); + will(returnValue("yy")); } }); @@ -284,7 +306,7 @@ final Validator validator = mockery.mock(Validator.class); mockery.checking(new Expectations() { { - one(validator).validate(with(any(ControllerDefinition.class)), with(any(ErrorsContext.class))); + one(validator).validate(with(any(ControllerDefinition.class)), with(any(ErrorsContext.class)), with(same("yy"))); } }); @@ -329,6 +351,8 @@ final ErrorsContext errorsContext = mockery.mock(ErrorsContext.class); final ContextContainer contextContainer = mockery.mock(ContextContainer.class); final MessagesContext messageContext = mockery.mock(MessagesContext.class); + final ValidationMonitor validationMonitor = mockery.mock(ValidationMonitor.class); + final ValidatorConfiguration validatorConfiguration = mockery.mock(ValidatorConfiguration.class); mockery.checking(new Expectations() { { one(contextContainer).getComponent(ErrorsContext.class); @@ -338,6 +362,10 @@ will(returnValue(new ArrayList<MethodInterceptor>())); one(contextContainer).getComponent(MessagesContext.class); will(returnValue(messageContext)); + one(contextContainer).getComponent(ValidationMonitor.class); + will(returnValue(validationMonitor)); + one(contextContainer).getComponent(ValidatorConfiguration.class); + will(returnValue(validatorConfiguration)); } }); @@ -423,6 +451,8 @@ final ErrorsContext errorsContext = mockery.mock(ErrorsContext.class); final ContextContainer contextContainer = mockery.mock(ContextContainer.class); final MessagesContext messageContext = mockery.mock(MessagesContext.class); + final ValidationMonitor validationMonitor = mockery.mock(ValidationMonitor.class); + final ValidatorConfiguration validatorConfiguration = mockery.mock(ValidatorConfiguration.class); mockery.checking(new Expectations() { { one(contextContainer).getComponent(ErrorsContext.class); @@ -433,6 +463,14 @@ will(returnValue(new ArrayList<MethodInterceptor>())); one(contextContainer).getComponent(MessagesContext.class); will(returnValue(messageContext)); + one(contextContainer).getComponent(ValidationMonitor.class); + will(returnValue(validationMonitor)); + one(contextContainer).getComponent(ValidatorConfiguration.class); + will(returnValue(validatorConfiguration)); + one(validatorConfiguration).getSuffix(); + will(returnValue(".xx")); + one(contextContainer).getComponentInstance("no name.xx"); + will(returnValue("yy")); } }); @@ -469,7 +507,7 @@ final Validator validator = mockery.mock(Validator.class); mockery.checking(new Expectations() { { - one(validator).validate(with(any(ControllerDefinition.class)), with(any(ErrorsContext.class))); + one(validator).validate(with(any(ControllerDefinition.class)), with(any(ErrorsContext.class)), with(same("yy"))); } }); @@ -516,6 +554,8 @@ final ErrorsContext errorsContext = mockery.mock(ErrorsContext.class); final ContextContainer contextContainer = mockery.mock(ContextContainer.class); final MessagesContext messageContext = mockery.mock(MessagesContext.class); + final ValidationMonitor validationMonitor = mockery.mock(ValidationMonitor.class); + final ValidatorConfiguration validatorConfiguration = mockery.mock(ValidatorConfiguration.class); mockery.checking(new Expectations() { { one(contextContainer).getComponent(ErrorsContext.class); @@ -527,6 +567,14 @@ will(returnValue(new ArrayList<MethodInterceptor>())); one(contextContainer).getComponent(MessagesContext.class); will(returnValue(messageContext)); + one(contextContainer).getComponent(ValidationMonitor.class); + will(returnValue(validationMonitor)); + one(contextContainer).getComponent(ValidatorConfiguration.class); + will(returnValue(validatorConfiguration)); + one(validatorConfiguration).getSuffix(); + will(returnValue(".xx")); + one(contextContainer).getComponentInstance("no name.xx"); + will(returnValue("yy")); } }); @@ -568,7 +616,7 @@ final Validator validator = mockery.mock(Validator.class); mockery.checking(new Expectations() { { - allowing(validator).validate(with(any(ControllerDefinition.class)), with(any(ErrorsContext.class))); + allowing(validator).validate(with(any(ControllerDefinition.class)), with(any(ErrorsContext.class)), with(same("yy"))); } });
Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/testmodel/StubValidator.java (860 => 861)
--- trunk/waffle-core/src/test/java/org/codehaus/waffle/testmodel/StubValidator.java 2009-01-13 23:21:09 UTC (rev 860) +++ trunk/waffle-core/src/test/java/org/codehaus/waffle/testmodel/StubValidator.java 2009-01-14 05:44:24 UTC (rev 861) @@ -6,7 +6,7 @@ public class StubValidator implements Validator { - public void validate(ControllerDefinition controllerDefinition, ErrorsContext errorsContext) { + public void validate(ControllerDefinition controllerDefinition, ErrorsContext errorsContext, Object controllerValidator) { throw new UnsupportedOperationException(); } }
Deleted: trunk/waffle-core/src/test/java/org/codehaus/waffle/validation/DefaultValidatorTest.java (860 => 861)
--- trunk/waffle-core/src/test/java/org/codehaus/waffle/validation/DefaultValidatorTest.java 2009-01-13 23:21:09 UTC (rev 860) +++ trunk/waffle-core/src/test/java/org/codehaus/waffle/validation/DefaultValidatorTest.java 2009-01-14 05:44:24 UTC (rev 861) @@ -1,117 +0,0 @@ -package org.codehaus.waffle.validation; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; - -import java.lang.reflect.Method; - -import org.codehaus.waffle.action.MethodDefinition; -import org.codehaus.waffle.context.ContextContainer; -import org.codehaus.waffle.context.RequestLevelContainer; -import org.codehaus.waffle.controller.ControllerDefinition; -import org.codehaus.waffle.monitor.SilentMonitor; -import org.codehaus.waffle.testmodel.FakeController; -import org.codehaus.waffle.testmodel.FakeControllerValidator; -import org.codehaus.waffle.testmodel.FakeControllerWithValidation; -import org.jmock.Expectations; -import org.jmock.Mockery; -import org.jmock.integration.junit4.JMock; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * - * @author Michael Ward - * @author Mauro Talevi - */ -...@runwith(JMock.class) -public class DefaultValidatorTest { - - private Mockery mockery = new Mockery(); - - @After - public void tearDown() throws Exception { - RequestLevelContainer.set(null); - } - - @Test - public void canValidateWithControllerValidation() throws Exception { - FakeController fakeController = new FakeControllerWithValidation(); - Validator validator = new DefaultValidator(new SilentMonitor()); - assertValidation(validator, fakeController, null, DefaultValidatorConfiguration.DEFAULT_SUFFIX); - } - - @Test - public void canValidateWithControllerValidatorOfDefaultSuffix() throws Exception { - FakeController fakeController = new FakeController(); - Validator validator = new DefaultValidator(new SilentMonitor()); - assertValidation(validator, fakeController, new FakeControllerValidator(), DefaultValidatorConfiguration.DEFAULT_SUFFIX); - } - - @Test - public void canValidateWithControllerValidatorOfCustomSuffix() throws Exception { - FakeController fakeController = new FakeController(); - String suffix = "Check"; - Validator validator = new DefaultValidator(new DefaultValidatorConfiguration(suffix), new SilentMonitor()); - assertValidation(validator, fakeController, new FakeControllerValidator(), suffix); - } - - private void assertValidation(Validator validator, final FakeController fakeController, final FakeControllerValidator fakeControllerValidator, final String suffix) throws NoSuchMethodException { - // Mock ContextContainer - final ContextContainer contextContainer = mockery.mock(ContextContainer.class); - mockery.checking(new Expectations() { - { - one(contextContainer).getComponentInstance("theController"+suffix); - will(returnValue(fakeControllerValidator)); - if (fakeControllerValidator == null) { - one(contextContainer).getComponentInstance("theController"); - will(returnValue(fakeController)); - } - } - }); - RequestLevelContainer.set(contextContainer); - - - Method method = FakeController.class.getMethod("sayHello", String.class); - MethodDefinition methodDefinition = new MethodDefinition(method); - methodDefinition.addMethodArgument("foobar"); - - ControllerDefinition controllerDefinition = new ControllerDefinition("theController", fakeController, methodDefinition); - - ErrorsContext errorsContext = new DefaultErrorsContext(null); - validator.validate(controllerDefinition, errorsContext); - - if ( fakeControllerValidator != null ){ - assertSame(errorsContext, fakeControllerValidator.errorsContext); - assertEquals("foobar", fakeControllerValidator.value); - } else if ( fakeController instanceof FakeControllerWithValidation ){ - FakeControllerWithValidation fakeControllerWithValidation = (FakeControllerWithValidation) fakeController; - assertSame(errorsContext, fakeControllerWithValidation.errorsContext); - assertEquals("foobar", fakeControllerWithValidation.value); - } - } - - @Test - public void canValidateWhenControllerDefinitionHasANullMethodDefinition() { - final FakeControllerValidator fakeControllerValidator = new FakeControllerValidator(); - - // Mock ContextContainer - final ContextContainer contextContainer = mockery.mock(ContextContainer.class); - mockery.checking(new Expectations() { - { - one(contextContainer).getComponentInstance("theControllerValidator"); - will(returnValue(fakeControllerValidator)); - } - }); - RequestLevelContainer.set(contextContainer); - - FakeController fakeController = new FakeController(); - ControllerDefinition controllerDefinition = new ControllerDefinition("theController", fakeController, null); - - ErrorsContext errorsContext = new DefaultErrorsContext(null); - Validator validator = new DefaultValidator(new SilentMonitor()); - validator.validate(controllerDefinition, errorsContext); - } - -}
To unsubscribe from this list please visit:
