Revision: 1332
http://stripes.svn.sourceforge.net/stripes/?rev=1332&view=rev
Author: bengunter
Date: 2010-11-12 05:29:00 +0000 (Fri, 12 Nov 2010)
Log Message:
-----------
Fixed STS-777. Parameters were getting messed up when MockRoundTrip constructor
was passed an ActionBean class with clean URL instead of a string path.
Modified Paths:
--------------
branches/1.5.x/stripes/src/net/sourceforge/stripes/mock/MockRoundtrip.java
Added Paths:
-----------
branches/1.5.x/tests/src/net/sourceforge/stripes/mock/TestMockRoundtrip2.java
Modified:
branches/1.5.x/stripes/src/net/sourceforge/stripes/mock/MockRoundtrip.java
===================================================================
--- branches/1.5.x/stripes/src/net/sourceforge/stripes/mock/MockRoundtrip.java
2010-11-11 22:03:55 UTC (rev 1331)
+++ branches/1.5.x/stripes/src/net/sourceforge/stripes/mock/MockRoundtrip.java
2010-11-12 05:29:00 UTC (rev 1332)
@@ -23,8 +23,11 @@
import javax.servlet.Filter;
import net.sourceforge.stripes.action.ActionBean;
+import net.sourceforge.stripes.controller.ActionResolver;
+import net.sourceforge.stripes.controller.AnnotatedClassActionResolver;
import net.sourceforge.stripes.controller.StripesConstants;
import net.sourceforge.stripes.controller.StripesFilter;
+import net.sourceforge.stripes.controller.UrlBindingFactory;
import net.sourceforge.stripes.util.CryptoUtil;
import net.sourceforge.stripes.validation.ValidationErrors;
@@ -90,7 +93,7 @@
public MockRoundtrip(MockServletContext context,
Class<? extends ActionBean> beanType,
MockHttpSession session) {
- this(context, getUrlBinding(beanType, context), session);
+ this(context, getUrlBindingStub(beanType, context), session);
}
/**
@@ -341,20 +344,43 @@
return this.response.getRedirectUrl();
}
- /**
- * A helper method that fetches the UrlBinding of a class in the manner it
would
- * be interpreted by the current context configuration.
- */
- private static String getUrlBinding(Class<? extends ActionBean> clazz,
- MockServletContext context) {
- List<Filter> filters = context.getFilters();
- for (Filter filter : filters) {
+ /** Find and return the {...@link AnnotatedClassActionResolver} for the
given context. */
+ private static AnnotatedClassActionResolver
getActionResolver(MockServletContext context) {
+ for (Filter filter : context.getFilters()) {
if (filter instanceof StripesFilter) {
- return ((StripesFilter) filter).getInstanceConfiguration()
- .getActionResolver().getUrlBinding(clazz);
+ ActionResolver resolver = ((StripesFilter)
filter).getInstanceConfiguration()
+ .getActionResolver();
+ if (resolver instanceof AnnotatedClassActionResolver) {
+ return (AnnotatedClassActionResolver) resolver;
+ }
}
}
return null;
}
+
+ /** Find and return the {...@link UrlBindingFactory} for the given
context. */
+ private static UrlBindingFactory getUrlBindingFactory(MockServletContext
context) {
+ ActionResolver resolver = getActionResolver(context);
+ if (resolver instanceof AnnotatedClassActionResolver) {
+ return ((AnnotatedClassActionResolver)
resolver).getUrlBindingFactory();
+ }
+
+ return null;
+ }
+
+ /**
+ * A helper method that fetches the UrlBinding of a class in the manner it
would be interpreted
+ * by the current context configuration.
+ */
+ private static String getUrlBinding(Class<? extends ActionBean> clazz,
+ MockServletContext context) {
+ return getActionResolver(context).getUrlBinding(clazz);
+ }
+
+ /** Get the URL binding for an {...@link ActionBean} class up to the first
parameter. */
+ private static String getUrlBindingStub(Class<? extends ActionBean> clazz,
+ MockServletContext context) {
+ return
getUrlBindingFactory(context).getBindingPrototype(clazz).getPath();
+ }
}
Added:
branches/1.5.x/tests/src/net/sourceforge/stripes/mock/TestMockRoundtrip2.java
===================================================================
---
branches/1.5.x/tests/src/net/sourceforge/stripes/mock/TestMockRoundtrip2.java
(rev 0)
+++
branches/1.5.x/tests/src/net/sourceforge/stripes/mock/TestMockRoundtrip2.java
2010-11-12 05:29:00 UTC (rev 1332)
@@ -0,0 +1,68 @@
+package net.sourceforge.stripes.mock;
+
+import static net.sourceforge.stripes.StripesTestFixture.getServletContext;
+import static org.testng.Assert.assertEquals;
+import net.sourceforge.stripes.action.ActionBean;
+import net.sourceforge.stripes.action.ActionBeanContext;
+import net.sourceforge.stripes.action.DefaultHandler;
+import net.sourceforge.stripes.action.Resolution;
+import net.sourceforge.stripes.action.UrlBinding;
+
+import org.testng.annotations.Test;
+
+/**
+ * Submitted by Nathan Maves and Remi Vankeisbelck to test a specific failure
in
+ * {...@link MockRoundtrip}. Unit test behavior differed when using an
{...@link ActionBean} class to
+ * construct the {...@link MockRoundtrip} and when using a string.
+ *
+ * @author Nathan Maves, Remi Vankeisbelck
+ */
+...@urlbinding("/foo/{id}/{$event}")
+public class TestMockRoundtrip2 implements ActionBean {
+ ActionBeanContext context;
+ Integer id;
+
+ @DefaultHandler
+ public Resolution bar() {
+ return null;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public void setContext(ActionBeanContext context) {
+ this.context = context;
+ }
+
+ public ActionBeanContext getContext() {
+ return this.context;
+ }
+
+ private final static Integer REF_ID = 2;
+
+ @Test
+ public void testUsingBeanClass() throws Exception {
+ executeTest(new MockRoundtrip(getServletContext(), getClass()));
+ }
+
+ @Test
+ public void testUsingUrlWithEventSpecified() throws Exception {
+ executeTest(new MockRoundtrip(getServletContext(), "/foo/" + REF_ID +
"/bar"));
+ }
+
+ @Test
+ public void testUsingUrlWithoutEventSpecified() throws Exception {
+ executeTest(new MockRoundtrip(getServletContext(), "/foo/" + REF_ID));
+ }
+
+ private void executeTest(MockRoundtrip trip) throws Exception {
+ trip.setParameter("id", REF_ID.toString());
+ trip.execute();
+ assertEquals(trip.getActionBean(getClass()).getId(), REF_ID);
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development