cvs commit: jakarta-struts/src/test/org/apache/struts/util TestRequestUtils.java
dgraham 2003/08/02 14:18:46 Modified:src/test/org/apache/struts/util TestRequestUtils.java Log: Replace RequestUtils calls with ModuleUtils. Revision ChangesPath 1.22 +10 -9 jakarta-struts/src/test/org/apache/struts/util/TestRequestUtils.java Index: TestRequestUtils.java === RCS file: /home/cvs/jakarta-struts/src/test/org/apache/struts/util/TestRequestUtils.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- TestRequestUtils.java 26 Jul 2003 04:25:16 - 1.21 +++ TestRequestUtils.java 2 Aug 2003 21:18:46 - 1.22 @@ -68,6 +68,7 @@ import java.util.Map; import javax.servlet.jsp.JspException; + import junit.framework.Test; import junit.framework.TestSuite; @@ -76,8 +77,8 @@ import org.apache.struts.action.ActionMapping; import org.apache.struts.action.DynaActionForm; import org.apache.struts.action.RequestProcessor; -import org.apache.struts.config.ModuleConfig; import org.apache.struts.config.ForwardConfig; +import org.apache.struts.config.ModuleConfig; import org.apache.struts.mock.MockFormBean; import org.apache.struts.mock.MockPrincipal; import org.apache.struts.mock.TestMockBase; @@ -1489,7 +1490,7 @@ public void testSelectApplication1a() { request.setPathElements(/myapp, /noform.do, null, null); -RequestUtils.selectModule(request, context); +ModuleUtils.getInstance().selectModule(request, context); ModuleConfig moduleConfig = (ModuleConfig) request.getAttribute(Globals.MODULE_KEY); assertNotNull(Selected a module, moduleConfig); @@ -1506,7 +1507,7 @@ context.setAttribute(Globals.MODULE_PREFIXES_KEY, prefixes); request.setPathElements(/myapp, /2/noform.do, null, null); -RequestUtils.selectModule(request, context); +ModuleUtils.getInstance().selectModule(request, context); ModuleConfig moduleConfig = (ModuleConfig) request.getAttribute(Globals.MODULE_KEY); assertNotNull(Selected a module, moduleConfig); @@ -1523,7 +1524,7 @@ request.setPathElements(/myapp, /2/noform.do, null, null); request.setAttribute(RequestProcessor.INCLUDE_SERVLET_PATH, /noform.do); -RequestUtils.selectModule(request, context); +ModuleUtils.getInstance().selectModule(request, context); ModuleConfig moduleConfig = (ModuleConfig) request.getAttribute(Globals.MODULE_KEY); assertNotNull(Selected an application, moduleConfig); @@ -1541,7 +1542,7 @@ request.setPathElements(/myapp, /noform.do, null, null); request.setAttribute(RequestProcessor.INCLUDE_SERVLET_PATH, /2/noform.do); -RequestUtils.selectModule(request, context); +ModuleUtils.getInstance().selectModule(request, context); ModuleConfig moduleConfig = (ModuleConfig) request.getAttribute(Globals.MODULE_KEY); assertNotNull(Selected a module, moduleConfig); - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-struts/src/test/org/apache/struts/util TestRequestUtils.java
sraeburn2003/07/25 00:19:48 Modified:src/test/org/apache/struts/util TestRequestUtils.java Log: Add initialisation of module prefixes for selectApplication tests Revision ChangesPath 1.20 +9 -6 jakarta-struts/src/test/org/apache/struts/util/TestRequestUtils.java Index: TestRequestUtils.java === RCS file: /home/cvs/jakarta-struts/src/test/org/apache/struts/util/TestRequestUtils.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- TestRequestUtils.java 2 Jul 2003 03:09:47 - 1.19 +++ TestRequestUtils.java 25 Jul 2003 07:19:48 - 1.20 @@ -1503,8 +1503,10 @@ // Map to the second module -- direct public void testSelectApplication1b() { - +String[] prefixes = { /1, /2 }; +context.setAttribute(Globals.MODULE_PREFIXES_KEY, prefixes); request.setPathElements(/myapp, /2/noform.do, null, null); + RequestUtils.selectModule(request, context); ApplicationConfig appConfig = (ApplicationConfig) request.getAttribute(Globals.MODULE_KEY); @@ -1535,7 +1537,8 @@ // Map to the second module -- include public void testSelectApplication2b() { - +String[] prefixes = { /1, /2 }; +context.setAttribute(Globals.MODULE_PREFIXES_KEY, prefixes); request.setPathElements(/myapp, /noform.do, null, null); request.setAttribute(RequestProcessor.INCLUDE_SERVLET_PATH, /2/noform.do); - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-struts/src/test/org/apache/struts/util TestRequestUtils.java
rleland 2003/07/25 21:25:16 Modified:src/test/org/apache/struts/util TestRequestUtils.java Log: Make tests use ModuleConfig instead of ApplicationConfig. Revision ChangesPath 1.21 +84 -85 jakarta-struts/src/test/org/apache/struts/util/TestRequestUtils.java Index: TestRequestUtils.java === RCS file: /home/cvs/jakarta-struts/src/test/org/apache/struts/util/TestRequestUtils.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- TestRequestUtils.java 25 Jul 2003 07:19:48 - 1.20 +++ TestRequestUtils.java 26 Jul 2003 04:25:16 - 1.21 @@ -72,12 +72,11 @@ import junit.framework.TestSuite; import org.apache.struts.Globals; -import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.DynaActionForm; import org.apache.struts.action.RequestProcessor; -import org.apache.struts.config.ApplicationConfig; +import org.apache.struts.config.ModuleConfig; import org.apache.struts.config.ForwardConfig; import org.apache.struts.mock.MockFormBean; import org.apache.struts.mock.MockPrincipal; @@ -163,10 +162,10 @@ // Default application -- extension mapping public void testActionURL1() { -request.setAttribute(Globals.MODULE_KEY, appConfig); +request.setAttribute(Globals.MODULE_KEY, moduleConfig); request.setPathElements(/myapp, /foo.do, null, null); String url = RequestUtils.actionURL -(request, appConfig.findActionConfig(/dynamic), *.do); +(request, moduleConfig.findActionConfig(/dynamic), *.do); assertNotNull(URL was returned, url); assertEquals(URL value, /dynamic.do, @@ -178,10 +177,10 @@ // Second application -- extension mapping public void testActionURL2() { -request.setAttribute(Globals.MODULE_KEY, appConfig2); +request.setAttribute(Globals.MODULE_KEY, moduleConfig2); request.setPathElements(/myapp, /2/foo.do, null, null); String url = RequestUtils.actionURL -(request, appConfig2.findActionConfig(/dynamic2), *.do); +(request, moduleConfig2.findActionConfig(/dynamic2), *.do); assertNotNull(URL was returned, url); assertEquals(URL value, /2/dynamic2.do, @@ -193,10 +192,10 @@ // Default application -- path mapping public void testActionURL3() { -request.setAttribute(Globals.MODULE_KEY, appConfig); +request.setAttribute(Globals.MODULE_KEY, moduleConfig); request.setPathElements(/myapp, /do/foo, null, null); String url = RequestUtils.actionURL -(request, appConfig.findActionConfig(/dynamic), /do/*); +(request, moduleConfig.findActionConfig(/dynamic), /do/*); assertNotNull(URL was returned, url); assertEquals(URL value, /do/dynamic, @@ -552,7 +551,7 @@ // Default module -- Forward with pattern public void testComputeURL1d() { -appConfig.getControllerConfig().setForwardPattern +moduleConfig.getControllerConfig().setForwardPattern ($C/WEB-INF/pages$M$P); request.setPathElements(/myapp, /action.do, null, null); String url = null; @@ -575,7 +574,7 @@ // Default module -- Page with pattern public void testComputeURL1e() { -appConfig.getControllerConfig().setPagePattern +moduleConfig.getControllerConfig().setPagePattern ($C/WEB-INF/pages$M$P); request.setPathElements(/myapp, /action.do, null, null); String url = null; @@ -660,7 +659,7 @@ // Second module -- Forward only public void testComputeURL2a() { -request.setAttribute(Globals.MODULE_KEY, appConfig2); +request.setAttribute(Globals.MODULE_KEY, moduleConfig2); request.setPathElements(/myapp, /2/action.do, null, null); String url = null; try { @@ -682,7 +681,7 @@ // Second module -- Href only public void testComputeURL2b() { -request.setAttribute(Globals.MODULE_KEY, appConfig2); +request.setAttribute(Globals.MODULE_KEY, moduleConfig2); request.setPathElements(/myapp, /2/action.do, null, null); String url = null; try { @@ -704,7 +703,7 @@ // Second module -- Page only public void testComputeURL2c() { -request.setAttribute(Globals.MODULE_KEY, appConfig2); +request.setAttribute(Globals.MODULE_KEY, moduleConfig2); request.setPathElements(/myapp, /2/action.do, null, null); String url = null; try { @@ -726,8
cvs commit: jakarta-struts/src/test/org/apache/struts/util TestRequestUtils.java
craigmcc2003/02/08 13:01:52 Modified:src/test/org/apache/struts/mock TestMockBase.java src/test/org/apache/struts/util TestRequestUtils.java Log: As part of the investigation of Bugzilla ticket #16603, create unit tests that validate the current behavior of RequestUtils.forwardURL() -- in other words, practice what I've started preaching about test first design. I think I've got 100% coverage on the functional behavior of this method, and have found no functional flaws yet. Now, on to pageURL(). PR: 16603 Submitted by: Malik Recoing Revision ChangesPath 1.10 +140 -4jakarta-struts/src/test/org/apache/struts/mock/TestMockBase.java Index: TestMockBase.java === RCS file: /home/cvs/jakarta-struts/src/test/org/apache/struts/mock/TestMockBase.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- TestMockBase.java 24 Dec 2002 18:49:52 - 1.9 +++ TestMockBase.java 8 Feb 2003 21:01:52 - 1.10 @@ -72,7 +72,9 @@ import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.config.ApplicationConfig; +import org.apache.struts.config.ControllerConfig; import org.apache.struts.config.FormPropertyConfig; +import org.apache.struts.config.ForwardConfig; @@ -116,6 +118,7 @@ protected ApplicationConfig appConfig = null; protected ApplicationConfig appConfig2 = null; +protected ApplicationConfig appConfig3 = null; protected MockServletConfig config = null; protected MockServletContext context = null; protected MockPageContext page = null; @@ -144,6 +147,7 @@ // Set up application configurations for our supported modules setUpDefaultApp(); setUpSecondApp(); +setUpThirdApp(); // NOTE - we do not initialize the request attribute // for the selected module so that fallbacks to the @@ -256,6 +260,43 @@ mapping.setType(org.apache.struts.mock.MockAction); appConfig.addActionConfig(mapping); +// Configure global forward declarations +appConfig.addForwardConfig +(new ForwardConfig(moduleForward, + /module/forward, + false, // No redirect + false)); // Not context relative + +appConfig.addForwardConfig +(new ForwardConfig(moduleRedirect, + /module/redirect, + true,// Redirect + false)); // Not context relative + +appConfig.addForwardConfig +(new ForwardConfig(contextForward, + /context/forward, + false, // No redirect + true)); // Context relative + +appConfig.addForwardConfig +(new ForwardConfig(contextRedirect, + /context/redirect, + true,// Redirect + true)); // Context relative + +appConfig.addForwardConfig +(new ForwardConfig(moduleNoslash, + module/noslash, + false, // No redirect + false)); // Not context relative + +appConfig.addForwardConfig +(new ForwardConfig(contextNoslash, + context/noslash, + false, // No redirect + true)); // Not context relative + } @@ -325,11 +366,106 @@ mapping.setType(org.apache.struts.mock.MockAction); appConfig2.addActionConfig(mapping); +// Configure global forward declarations +appConfig2.addForwardConfig +(new ForwardConfig(moduleForward, + /module/forward, + false, // No redirect + false)); // Not context relative + +appConfig2.addForwardConfig +(new ForwardConfig(moduleRedirect, + /module/redirect, + true,// Redirect + false)); // Not context relative + +appConfig2.addForwardConfig +(new ForwardConfig(contextForward, + /context/forward, + false, // No redirect + true)); // Context relative + +appConfig2.addForwardConfig +(new ForwardConfig(contextRedirect, +
cvs commit: jakarta-struts/src/test/org/apache/struts/util TestRequestUtils.java
craigmcc2003/02/08 14:12:09 Modified:src/share/org/apache/struts/util RequestUtils.java src/test/org/apache/struts/util TestRequestUtils.java Log: Unit tests for the current behavior of RequestUtils.pageURL(). We deliberately do *not* do slash prepending here -- the input value must start with a slash. (Doing '/' prepending in forwardURL() was a bad idea IMHO, but apparently it was needed for Tiles, and now it's too late). Revision ChangesPath 1.84 +6 -5 jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java Index: RequestUtils.java === RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v retrieving revision 1.83 retrieving revision 1.84 diff -u -r1.83 -r1.84 --- RequestUtils.java 8 Feb 2003 21:20:19 - 1.83 +++ RequestUtils.java 8 Feb 2003 22:12:09 - 1.84 @@ -1458,7 +1458,8 @@ * * @param request The servlet request we are processing * @param page The module-relative URL to be substituted in - * to the codepagePattern/code pattern for the current module. + * to the codepagePattern/code pattern for the current module + * (strongMUST/strong start with a slash) * @return context-relative URL * @since Struts 1.1b2 */ 1.17 +64 -4 jakarta-struts/src/test/org/apache/struts/util/TestRequestUtils.java Index: TestRequestUtils.java === RCS file: /home/cvs/jakarta-struts/src/test/org/apache/struts/util/TestRequestUtils.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- TestRequestUtils.java 8 Feb 2003 21:01:52 - 1.16 +++ TestRequestUtils.java 8 Feb 2003 22:12:09 - 1.17 @@ -1403,6 +1403,66 @@ } +// -- pageURL() + + +// Default module (default pagePattern) +public void testPageURL1() { + +request.setAttribute(Action.APPLICATION_KEY, appConfig); +request.setPathElements(/myapp, /action.do, null, null); +String page = null; +String result = null; + +// Straight substitution +page = /mypages/index.jsp; +result = RequestUtils.pageURL(request, page); +assertNotNull(straight sub found, result); +assertEquals(straight sub value, + /mypages/index.jsp, result); + + +} + + +// Second module (default pagePattern) +public void testPageURL2() { + +request.setAttribute(Action.APPLICATION_KEY, appConfig2); +request.setPathElements(/myapp, /2/action.do, null, null); +String page = null; +String result = null; + +// Straight substitution +page = /mypages/index.jsp; +result = RequestUtils.pageURL(request, page); +assertNotNull(straight sub found, result); +assertEquals(straight sub value, + /2/mypages/index.jsp, result); + + +} + + +// Third module (custom pagePattern) +public void testPageURL3() { + +request.setAttribute(Action.APPLICATION_KEY, appConfig3); +request.setPathElements(/myapp, /3/action.do, null, null); +String page = null; +String result = null; + +// Straight substitution +page = /mypages/index.jsp; +result = RequestUtils.pageURL(request, page); +assertNotNull(straight sub found, result); +assertEquals(straight sub value, + /paging/3/mypages/index.jsp, result); + + +} + + // --- requestURL() - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-struts/src/test/org/apache/struts/util TestRequestUtils.java
craigmcc2002/12/24 10:49:52 Modified:src/share/org/apache/struts/config FormPropertyConfig.java src/test/org/apache/struts/action TestDynaActionForm.java TestDynaActionFormClass.java src/test/org/apache/struts/mock MockPrincipal.java TestMockBase.java src/test/org/apache/struts/util TestRequestUtils.java Log: The second half of the fix for 14800. The problem with mutable property values is *not* limited to array elements -- it will also occur when a scalar property is of a mutable type. As a solution to this, initial() now calculates and returns a new value every time, rather than caching the old one. This is a relatively minor performance hit, but not (in principle at least) any worse than evaluating the initialization expression for an instance variable in a JavaBean every time one is created. As an added benefit, the initial() method will also attempt to create instances of properties (via a zero-args constructor) if you did not specify an initial value to pass in to ConvertUtils.convert(). This is true both for scalar properties and for elements of arrays constructed with the size attribute. In general, DynaActionForm beans now act very much more like standard ActionForm beans with respect to preinitialized property values than they did before these changes. PR: Bugzilla #14800 Submitted by: James Turner turner at blackbear.com Revision ChangesPath 1.9 +62 -49 jakarta-struts/src/share/org/apache/struts/config/FormPropertyConfig.java Index: FormPropertyConfig.java === RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/FormPropertyConfig.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- FormPropertyConfig.java 23 Dec 2002 22:00:24 - 1.8 +++ FormPropertyConfig.java 24 Dec 2002 18:49:52 - 1.9 @@ -138,18 +138,6 @@ protected boolean configured = false; -/** - * Have we calculated the initial value object yet? - */ -protected transient boolean initialized = false; - - -/** - * The calculated initial value for this property. - */ -protected transient Object initialValue = null; - - // - Properties @@ -189,7 +177,8 @@ /** * pThe size of the array to be created if this property is an array - * type and there is no specified codeinitial/code value./p + * type and there is no specified codeinitial/code value. This + * value must be non-negative./p * * @since Struts 1.1-b3 */ @@ -203,6 +192,9 @@ if (configured) { throw new IllegalStateException(Configuration is frozen); } +if (size 0) { +throw new IllegalArgumentException(size 0); +} this.size = size; } @@ -288,46 +280,67 @@ /** - * Return an object representing the initial value of this property. + * pReturn an object representing the initial value of this property. + * This is calculated according to the following algorithm:/p + * ul + * liIf the value you have specified for the codetype/code + * property represents an array (i.e. it ends with []): + * ul + * liIf you have specified a value for the codeinitial/code + * property, codeConvertUtils.convert()/code will be + * called to convert it into an instance of the specified + * array type./li + * liIf you have not specified a value for the codeinitial/code + * property, an array of the length specified by the + * codesize/code property will be created. Each element + * of the array will be instantiated via the zero-args constructor + * on the specified class (if any). Otherwise, codenull/code + * will be returned./li + * /ul/li + * liIf the value you have specified for the codetype/code + * property does not represent an array: + * ul + * liIf you have specified a value for the codeinitial/code + * property, codeConvertUtils.convert()/code + * will be called to convert it into an object instance./li + * liIf you have not specified a value for the codeinitial/code + * attribute, Struts will instantiate an instance via the + * zero-args constructor on the specified class (if any). + * Otherwise, codenull/code will be returned./li + * /ul/li + * /ul */ public Object initial() { -// Compute our initial value the first
cvs commit: jakarta-struts/src/test/org/apache/struts/util TestRequestUtils.java
craigmcc2002/12/23 14:00:25 Modified:conf/share struts-config_1_1.dtd src/share/org/apache/struts/config FormPropertyConfig.java src/test/org/apache/struts/action TestDynaActionForm.java src/test/org/apache/struts/mock TestMockBase.java src/test/org/apache/struts/util TestRequestUtils.java Log: Add an optional size attribute on form-property, so that you can ask for an array of a specific size without having to specify initial values in the initial attribute. For example, form-property name=foo type=java.lang.String[] size=10/ will cause the initialize() method of the DynaActionForm to create an array of ten Strings (all initialized to null). The size attribute will be ignored if the initial attribute is present. Updated unit tests included. This is the non-controversial half of the recommendations in Bugzilla #14800. I'm still reviewing the advisability of changing the way that initial arrays get cloned or not. PR: Bugzilla #14800 Submitted by: James Turner turner at blackbear.com Revision ChangesPath 1.34 +6 -1 jakarta-struts/conf/share/struts-config_1_1.dtd Index: struts-config_1_1.dtd === RCS file: /home/cvs/jakarta-struts/conf/share/struts-config_1_1.dtd,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- struts-config_1_1.dtd 8 Dec 2002 00:22:56 - 1.33 +++ struts-config_1_1.dtd 23 Dec 2002 22:00:24 - 1.34 @@ -255,6 +255,10 @@ nameThe name of the JavaBean property described by this element. + sizeThe number of array elements to create if the value of the + type attribute specifies an array, but there is no value + specified for the initial attribute. + typeFully qualified Java class name of the field underlying this property, optionally followed by [] to indicate that the field is indexed. @@ -263,6 +267,7 @@ !ATTLIST form-property className %ClassName; #IMPLIED !ATTLIST form-property initialCDATA #IMPLIED !ATTLIST form-property name %PropName; #REQUIRED +!ATTLIST form-property size %Integer; #IMPLIED !ATTLIST form-property type %ClassName; #REQUIRED 1.8 +54 -5 jakarta-struts/src/share/org/apache/struts/config/FormPropertyConfig.java Index: FormPropertyConfig.java === RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/FormPropertyConfig.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- FormPropertyConfig.java 9 Jul 2002 23:57:37 - 1.7 +++ FormPropertyConfig.java 23 Dec 2002 22:00:24 - 1.8 @@ -103,10 +103,28 @@ */ public FormPropertyConfig(String name, String type, String initial) { +this(name, type, initial, 0); + +} + + +/** + * Constructor that preconfigures the relevant properties. + * + * @param name Name of this property + * @param type Fully qualified class name of this property + * @param initial Initial value of this property (if any) + * @param size Size of the array to be created if this property is an + * array with no defined initial value + */ +public FormPropertyConfig(String name, String type, + String initial, int size) { + super(); setName(name); setType(type); setInitial(initial); +setSize(size); } @@ -170,6 +188,27 @@ /** + * pThe size of the array to be created if this property is an array + * type and there is no specified codeinitial/code value./p + * + * @since Struts 1.1-b3 + */ +protected int size = 0; + +public int getSize() { +return (this.size); +} + +public void setSize(int size) { +if (configured) { +throw new IllegalStateException(Configuration is frozen); +} +this.size = size; +} + + + +/** * The fully qualified Java class name of the implementation class * of this bean property, optionally followed by code[]/code to * indicate that the property is indexed. @@ -258,7 +297,17 @@ if (!initialized) { try { Class clazz = getTypeClass(); -initialValue = ConvertUtils.convert(initial, clazz); +if (clazz.isArray()) { +if (initial != null) { +initialValue = +
cvs commit: jakarta-struts/src/test/org/apache/struts/util TestRequestUtils.java
craigmcc2002/10/12 18:59:32 Modified:src/share/org/apache/struts/util RequestUtils.java src/test/org/apache/struts/util TestRequestUtils.java Log: Enhance computeURL() to use amp; as the connector between parameters on a forward URL (but not a redirect URL). PR: Bugzilla #13458 Bug report submitted by Matt Raible matt at raibledesigns.com Patch submitted by Antoni Reuss areus at ibit.org Revision ChangesPath 1.59 +14 -8 jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java Index: RequestUtils.java === RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v retrieving revision 1.58 retrieving revision 1.59 diff -u -r1.58 -r1.59 --- RequestUtils.java 13 Oct 2002 01:33:38 - 1.58 +++ RequestUtils.java 13 Oct 2002 01:59:31 - 1.59 @@ -448,6 +448,12 @@ anchor = null; } +// Define the parameter separator +String separator = amp;; +if (redirect) { +separator = ; +} + // Add the required request parameters boolean question = temp.indexOf('?') = 0; Iterator keys = params.keySet().iterator(); @@ -459,7 +465,7 @@ url.append('?'); question = true; } else { -url.append(); +url.append(separator); } url.append(URLEncoder.encode(key)); url.append('='); // Interpret null as no value @@ -468,7 +474,7 @@ url.append('?'); question = true; } else { -url.append(); +url.append(separator); } url.append(URLEncoder.encode(key)); url.append('='); @@ -480,7 +486,7 @@ url.append('?'); question = true; } else { -url.append(); +url.append(separator); } url.append(URLEncoder.encode(key)); url.append('='); @@ -491,7 +497,7 @@ url.append('?'); question = true; } else { -url.append(); +url.append(separator); } url.append(URLEncoder.encode(key)); url.append('='); 1.11 +80 -11 jakarta-struts/src/test/org/apache/struts/util/TestRequestUtils.java Index: TestRequestUtils.java === RCS file: /home/cvs/jakarta-struts/src/test/org/apache/struts/util/TestRequestUtils.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- TestRequestUtils.java 27 Jul 2002 23:26:09 - 1.10 +++ TestRequestUtils.java 13 Oct 2002 01:59:32 - 1.11 @@ -831,7 +831,7 @@ } -// Add parameters only +// Add parameters only -- forward URL public void testComputeURL3a() { request.setPathElements(/myapp, /action.do, null, null); @@ -849,13 +849,13 @@ } assertNotNull(url present, url); assertTrue(url value, - url.equals(/myapp/bar?foo1=bar1foo2=bar2) || - url.equals(/myapp/bar?foo2=bar2foo1=bar1)); + url.equals(/myapp/bar?foo1=bar1amp;foo2=bar2) || + url.equals(/myapp/bar?foo2=bar2amp;foo1=bar1)); } -// Add anchor only +// Add anchor only -- forward URL public void testComputeURL3b() { request.setPathElements(/myapp, /action.do, null, null); @@ -876,7 +876,7 @@ } -// Add parameters + anchor +// Add parameters + anchor -- forward URL public void testComputeURL3c() { request.setPathElements(/myapp, /action.do, null, null); @@ -894,8 +894,77 @@ } assertNotNull(url present, url); assertTrue(url value, - url.equals(/myapp/bar?foo1=bar1foo2=bar2#anchor) || - url.equals(/myapp/bar?foo2=bar2foo1=bar1#anchor)); + url.equals(/myapp/bar?foo1=bar1amp;foo2=bar2#anchor) || + url.equals(/myapp/bar?foo2=bar2amp;foo1=bar1#anchor)); + +} + + +// Add parameters only -- redirect URL +public void testComputeURL3d() { + +request.setPathElements(/myapp,
cvs commit: jakarta-struts/src/test/org/apache/struts/util TestRequestUtils.java
craigmcc2002/07/27 16:26:09 Modified:.STATUS src/share/org/apache/struts/util RequestUtils.java src/test/org/apache/struts/mock TestMockBase.java src/test/org/apache/struts/util TestRequestUtils.java Log: Fixed computeURL() so that it supports absolute and relative URLs again. This fixes the bug in html:link that Ted reported, but I don't know what it does to forwards that are actually tiles definitions -- can someone please check that I didn't break this? PR: Bugzilla #11021 Submitted by: Ted Husted husted at apache.org Revision ChangesPath 1.44 +2 -3 jakarta-struts/STATUS Index: STATUS === RCS file: /home/cvs/jakarta-struts/STATUS,v retrieving revision 1.43 retrieving revision 1.44 diff -u -r1.43 -r1.44 --- STATUS27 Jul 2002 22:50:38 - 1.43 +++ STATUS27 Jul 2002 23:26:08 - 1.44 @@ -6,12 +6,11 @@ OUTSTANDING BUGS IN STRUTS 1.1-b1 AND NIGHTLY BUILDS - 13 open bugs to swat!! + 12 open bugs to swat!! Controller: -- -11021 ActionForward or html:link tag does not support absolute URIs 11089 Data source keys are global, even when using application modules 1.51 +10 -6 jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java Index: RequestUtils.java === RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v retrieving revision 1.50 retrieving revision 1.51 diff -u -r1.50 -r1.51 --- RequestUtils.java 27 Jul 2002 18:55:56 - 1.50 +++ RequestUtils.java 27 Jul 2002 23:26:08 - 1.51 @@ -412,8 +412,12 @@ if (fc.getRedirect()) { redirect = true; } -url.append(request.getContextPath()); -url.append(forwardURL(request, fc)); +if (fc.getPath().startsWith(/)) { +url.append(request.getContextPath()); +url.append(forwardURL(request, fc)); +} else { +url.append(fc.getPath()); +} } else if (href != null) { url.append(href); } else /* if (page != null) */ { 1.5 +14 -4 jakarta-struts/src/test/org/apache/struts/mock/TestMockBase.java Index: TestMockBase.java === RCS file: /home/cvs/jakarta-struts/src/test/org/apache/struts/mock/TestMockBase.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- TestMockBase.java 10 Jul 2002 20:36:23 - 1.4 +++ TestMockBase.java 27 Jul 2002 23:26:09 - 1.5 @@ -160,6 +160,11 @@ appConfig = new ApplicationConfig(); context.setAttribute(Action.APPLICATION_KEY, appConfig); +// Forward external to http://jakarta.apache.org/; +appConfig.addForwardConfig +(new ActionForward(external, http://jakarta.apache.org/;, + false, false)); + // Forward foo to /bar.jsp appConfig.addForwardConfig (new ActionForward(foo, /bar.jsp, false, false)); @@ -223,6 +228,11 @@ appConfig2 = new ApplicationConfig(/2); context.setAttribute(Action.APPLICATION_KEY + /2, appConfig2); + +// Forward external to http://jakarta.apache.org/; +appConfig2.addForwardConfig +(new ActionForward(external, http://jakarta.apache.org/;, + false, false)); // Forward foo to /baz.jsp (different from default) appConfig2.addForwardConfig 1.10 +53 -8 jakarta-struts/src/test/org/apache/struts/util/TestRequestUtils.java Index: TestRequestUtils.java === RCS file: /home/cvs/jakarta-struts/src/test/org/apache/struts/util/TestRequestUtils.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- TestRequestUtils.java 24 Jul 2002 13:01:46 - 1.9 +++ TestRequestUtils.java 27 Jul 2002 23:26:09 - 1.10 @@ -605,7 +605,8 @@ } assertNotNull(url present, url); assertEquals(url value, - /myapp/relative.jsp, + // /myapp/relative.jsp, + relative.jsp, url); } @@ -625,7 +626,28 @@ } assertNotNull(url present, url); assertEquals(url value, - /myapp/relative.jsp, +
cvs commit: jakarta-struts/src/test/org/apache/struts/util TestRequestUtils.java
husted 2002/07/12 02:51:57 Modified:src/test/org/apache/struts/util TestRequestUtils.java Log: Change $A token to $M. Revision ChangesPath 1.8 +12 -12 jakarta-struts/src/test/org/apache/struts/util/TestRequestUtils.java Index: TestRequestUtils.java === RCS file: /home/cvs/jakarta-struts/src/test/org/apache/struts/util/TestRequestUtils.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- TestRequestUtils.java 10 Jul 2002 20:36:23 - 1.7 +++ TestRequestUtils.java 12 Jul 2002 09:51:57 - 1.8 @@ -205,7 +205,7 @@ // No parameters and no transaction token public void testComputeParameters0a() { - + Map map = null; try { map = RequestUtils.computeParameters(page, @@ -548,7 +548,7 @@ public void testComputeURL1d() { appConfig.getControllerConfig().setForwardPattern -($C/WEB-INF/pages$A$P); +($C/WEB-INF/pages$M$P); request.setPathElements(/myapp, /action.do, null, null); String url = null; try { @@ -571,7 +571,7 @@ public void testComputeURL1e() { appConfig.getControllerConfig().setPagePattern -($C/WEB-INF/pages$A$P); +($C/WEB-INF/pages$M$P); request.setPathElements(/myapp, /action.do, null, null); String url = null; try { @@ -705,7 +705,7 @@ request.setAttribute(Action.APPLICATION_KEY, appConfig2); appConfig2.getControllerConfig().setForwardPattern -($C/WEB-INF/pages$A$P); +($C/WEB-INF/pages$M$P); request.setPathElements(/myapp, /2/action.do, null, null); String url = null; try { @@ -728,7 +728,7 @@ public void testComputeURL2e() { appConfig2.getControllerConfig().setPagePattern -($C/WEB-INF/pages$A$P); +($C/WEB-INF/pages$M$P); request.setAttribute(Action.APPLICATION_KEY, appConfig2); request.setPathElements(/myapp, /2/action.do, null, null); String url = null; @@ -1023,7 +1023,7 @@ // FIXME - check application resources? } - + // Map to the second webapp -- direct public void testSelectApplication1b() { @@ -1055,7 +1055,7 @@ // FIXME - check application resources? } - + // Map to the second subapp -- include public void testSelectApplication2b() { @@ -1072,7 +1072,7 @@ // FIXME - check application resources? } - + // serverURL() -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-struts/src/test/org/apache/struts/util TestRequestUtils.java
craigmcc2002/07/07 16:45:21 Modified:src/share/org/apache/struts/action ActionForward.java src/share/org/apache/struts/config ForwardConfig.java src/share/org/apache/struts/util RequestUtils.java src/test/org/apache/struts/mock TestMockBase.java src/test/org/apache/struts/util TestRequestUtils.java Log: Deal with a path attribute on a forward that does not contain a leading slash by inserting one if necessary, for backwards compatibility. PR: Bugzilla #10534 Submitted by: Matt Raible matt at raibledesigns.com Revision ChangesPath 1.8 +24 -4 jakarta-struts/src/share/org/apache/struts/action/ActionForward.java Index: ActionForward.java === RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionForward.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- ActionForward.java2 Jul 2002 01:52:15 - 1.7 +++ ActionForward.java7 Jul 2002 23:45:21 - 1.8 @@ -163,4 +163,24 @@ } +/** + * Construct a new instance with the specified values. + * + * @param name Name of this instance + * @param path Path for this instance + * @param redirect Redirect flag for this instance + * @param contextRelative Context relative flag for this instance + */ +public ActionForward(String name, String path, boolean redirect, + boolean contextRelative) { + +super(); +setName(name); +setPath(path); +setRedirect(redirect); +setContextRelative(contextRelative); + +} + + } 1.6 +24 -4 jakarta-struts/src/share/org/apache/struts/config/ForwardConfig.java Index: ForwardConfig.java === RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/ForwardConfig.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ForwardConfig.java4 Jul 2002 00:05:48 - 1.5 +++ ForwardConfig.java7 Jul 2002 23:45:21 - 1.6 @@ -109,6 +109,26 @@ } +/** + * Construct a new instance with the specified values. + * + * @param name Name of this forward + * @param path Path to which control should be forwarded or redirected + * @param redirect Should we do a redirect? + * @param contextRelative Is this path context relative? + */ +public ForwardConfig(String name, String path, boolean redirect, + boolean contextRelative) { + +super(); +setName(name); +setPath(path); +setRedirect(redirect); +setContextRelative(contextRelative); + +} + + // - Instance Variables 1.45 +18 -7 jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java Index: RequestUtils.java === RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v retrieving revision 1.44 retrieving revision 1.45 diff -u -r1.44 -r1.45 --- RequestUtils.java 5 Jul 2002 22:03:16 - 1.44 +++ RequestUtils.java 7 Jul 2002 23:45:21 - 1.45 @@ -1186,10 +1186,15 @@ public static String forwardURL(HttpServletRequest request, ForwardConfig forward) { +String path = forward.getPath(); + // Handle a ForwardConfig marked as context relative StringBuffer sb = new StringBuffer(); if (forward.getContextRelative()) { -sb.append(forward.getPath()); +if (!path.startsWith(/)) { +sb.append(/); +} +sb.append(path); return (sb.toString()); } @@ -1201,7 +1206,10 @@ if (forwardPattern == null) { // Performance optimization for previous default behavior sb.append(appConfig.getPrefix()); -sb.append(forward.getPath()); +if (!path.startsWith(/)) { +sb.append(/); +} +sb.append(path); } else { boolean dollar = false; for (int i = 0; i forwardPattern.length(); i++) { @@ -1212,7 +1220,10 @@ sb.append(appConfig.getPrefix()); break; case 'P': -sb.append(forward.getPath()); +if (!path.startsWith(/)) { +sb.append(/); +} +
cvs commit: jakarta-struts/src/test/org/apache/struts/util TestRequestUtils.java
craigmcc2002/07/05 13:56:27 Modified:src/share/org/apache/struts/util RequestUtils.java src/test/org/apache/struts/util TestRequestUtils.java Log: For completeness, define actionURL() to calculate the appropriate server relative URL for an Action, along with associated unit tests. Revision ChangesPath 1.43 +37 -4 jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java Index: RequestUtils.java === RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v retrieving revision 1.42 retrieving revision 1.43 diff -u -r1.42 -r1.43 --- RequestUtils.java 4 Jul 2002 00:05:48 - 1.42 +++ RequestUtils.java 5 Jul 2002 20:56:27 - 1.43 @@ -98,6 +98,7 @@ import org.apache.struts.action.ActionServletWrapper; import org.apache.struts.action.DynaActionFormClass; import org.apache.struts.action.RequestProcessor; +import org.apache.struts.config.ActionConfig; import org.apache.struts.config.ApplicationConfig; import org.apache.struts.config.FormBeanConfig; import org.apache.struts.config.ForwardConfig; @@ -1133,6 +1134,38 @@ sb.append(ref); return (sb.toString()); } + +} + + +/** + * Return the server-relative URL that corresponds to the specified + * {@link ActionConfig}, relative to the sub-application associated + * with the current subapp's {@link ApplicationConfig}. + * + * @param request The servlet request we are processing + * @param action ActionConfig to be evaluated + * @param pattern URL pattern used to map the controller servlet + */ +public static String actionURL(HttpServletRequest request, + ActionConfig action, + String pattern) { + +StringBuffer sb = new StringBuffer(); +sb.append(request.getContextPath()); +if (pattern.endsWith(/*)) { +sb.append(pattern.substring(0, pattern.length() - 2)); +sb.append(action.getPath()); +} else if (pattern.startsWith(*.)) { +ApplicationConfig appConfig = (ApplicationConfig) +request.getAttribute(Action.APPLICATION_KEY); +sb.append(appConfig.getPrefix()); +sb.append(action.getPath()); +sb.append(pattern.substring(1)); +} else { +throw new IllegalArgumentException(pattern); +} +return (sb.toString()); } 1.4 +52 -4 jakarta-struts/src/test/org/apache/struts/util/TestRequestUtils.java Index: TestRequestUtils.java === RCS file: /home/cvs/jakarta-struts/src/test/org/apache/struts/util/TestRequestUtils.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TestRequestUtils.java 4 Jul 2002 00:05:48 - 1.3 +++ TestRequestUtils.java 5 Jul 2002 20:56:27 - 1.4 @@ -152,6 +152,54 @@ } +// actionURL() + + +// Default application -- extension mapping +public void testActionURL1() { + +request.setAttribute(Action.APPLICATION_KEY, appConfig); +request.setPathElements(/myapp, /foo.do, null, null); +String url = RequestUtils.actionURL +(request, appConfig.findActionConfig(/dynamic), *.do); +assertNotNull(URL was returned, url); +assertEquals(URL value, + /myapp/dynamic.do, + url); + +} + + +// Second application -- extension mapping +public void testActionURL2() { + +request.setAttribute(Action.APPLICATION_KEY, appConfig2); +request.setPathElements(/myapp, /2/foo.do, null, null); +String url = RequestUtils.actionURL +(request, appConfig2.findActionConfig(/dynamic2), *.do); +assertNotNull(URL was returned, url); +assertEquals(URL value, + /myapp/2/dynamic2.do, + url); + +} + + +// Default application -- path mapping +public void testActionURL3() { + +request.setAttribute(Action.APPLICATION_KEY, appConfig); +request.setPathElements(/myapp, /do/foo, null, null); +String url = RequestUtils.actionURL +(request, appConfig.findActionConfig(/dynamic), /do/*); +assertNotNull(URL was returned, url); +assertEquals(URL value, + /myapp/do/dynamic, + url); + +} + + // computeParameters() -- To
cvs commit: jakarta-struts/src/test/org/apache/struts/util TestRequestUtils.java
craigmcc2002/07/05 15:03:16 Modified:src/share/org/apache/struts/util RequestUtils.java src/test/org/apache/struts/util TestRequestUtils.java Log: It makes much more sense for actionURL(), forwardURL(), and pageURL() to return context-relative URLs instead of server-relative URLs. Revision ChangesPath 1.44 +16 -18 jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java Index: RequestUtils.java === RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v retrieving revision 1.43 retrieving revision 1.44 diff -u -r1.43 -r1.44 --- RequestUtils.java 5 Jul 2002 20:56:27 - 1.43 +++ RequestUtils.java 5 Jul 2002 22:03:16 - 1.44 @@ -412,10 +412,12 @@ if (fc.getRedirect()) { redirect = true; } +url.append(request.getContextPath()); url.append(forwardURL(request, fc)); } else if (href != null) { url.append(href); } else /* if (page != null) */ { +url.append(request.getContextPath()); url.append(pageURL(request, page)); } @@ -1139,20 +1141,21 @@ /** - * Return the server-relative URL that corresponds to the specified + * Return the context-relative URL that corresponds to the specified * {@link ActionConfig}, relative to the sub-application associated * with the current subapp's {@link ApplicationConfig}. * * @param request The servlet request we are processing * @param action ActionConfig to be evaluated * @param pattern URL pattern used to map the controller servlet + * + * @since Struts 1.1b2 */ public static String actionURL(HttpServletRequest request, ActionConfig action, String pattern) { StringBuffer sb = new StringBuffer(); -sb.append(request.getContextPath()); if (pattern.endsWith(/*)) { sb.append(pattern.substring(0, pattern.length() - 2)); sb.append(action.getPath()); @@ -1171,12 +1174,14 @@ /** - * Return the server-relative URL that corresponds to the specified + * Return the context-relative URL that corresponds to the specified * {@link ForwardConfig}, relative to the sub-application associated * with the current subapp's {@link ApplicationConfig}. * * @param request The servlet request we are processing * @param forward ForwardConfig to be evaluated + * + * @since Struts 1.1b2 */ public static String forwardURL(HttpServletRequest request, ForwardConfig forward) { @@ -1184,19 +1189,17 @@ // Handle a ForwardConfig marked as context relative StringBuffer sb = new StringBuffer(); if (forward.getContextRelative()) { -sb.append(request.getContextPath()); sb.append(forward.getPath()); return (sb.toString()); } -// Calculate a subapp relative path for this ForwardConfig +// Calculate a context relative path for this ForwardConfig ApplicationConfig appConfig = (ApplicationConfig) request.getAttribute(Action.APPLICATION_KEY); String forwardPattern = appConfig.getControllerConfig().getForwardPattern(); if (forwardPattern == null) { // Performance optimization for previous default behavior -sb.append(request.getContextPath()); sb.append(appConfig.getPrefix()); sb.append(forward.getPath()); } else { @@ -1205,9 +1208,6 @@ char ch = forwardPattern.charAt(i); if (dollar) { switch (ch) { -case 'C': -sb.append(request.getContextPath()); -break; case 'A': sb.append(appConfig.getPrefix()); break; @@ -1235,7 +1235,7 @@ /** - * Return the server-relative URL that corresponds to the specified + * Return the context-relative URL that corresponds to the specified * codepage/code attribute value, calculated based on the * codepagePattern/code property of the current subapp's * {@link ApplicationConfig}. @@ -1243,6 +1243,8 @@ * @param request The servlet request we are processing * @param page The application-relative URL to be substituted in * to the codepagePattern/code pattern for the current subapp + * + * @since Struts 1.1b2 */ public
cvs commit: jakarta-struts/src/test/org/apache/struts/util TestRequestUtils.java
craigmcc2002/07/03 17:05:48 Modified:conf/share struts-config_1_1.dtd src/share/org/apache/struts/config ControllerConfig.java ForwardConfig.java src/share/org/apache/struts/util RequestUtils.java src/test/org/apache/struts/util TestRequestUtils.java Log: Support pluggable patterns for mapping the path of an ActionForward (if it is not marked context relative), or the path specified by the page attribute of many tags, so that you can gracefully deal with things like migrating your JSP pages under /WEB-INF. The syntax for the forwardPattern and pagePattern patterns is simple: $C is replaced by the context path of this webapp $A is replaced by the prefix for this subapp $P is replaced by the path of the forward (for forwardPattern) or the specified page value (for pagePattern) $$ is replaced by a literal $ all other characters are passed through unchanged. The default pattern in each case is $C$A$P, which is consistent with the previous behavior (and optimized for performance in the code). To put your pages under /WEB-INF/pages instead of the context root, specify a pattern like $C/WEB-INF/pages$A$P instead. Added unit tests to validate the new behavior (including consistent behavior of the previous defaults). FIXME - Update ImageTag and ImgTag to use RequestUtils.computeURL() so that they will pick up changes like this automatically. Revision ChangesPath 1.20 +39 -2 jakarta-struts/conf/share/struts-config_1_1.dtd Index: struts-config_1_1.dtd === RCS file: /home/cvs/jakarta-struts/conf/share/struts-config_1_1.dtd,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- struts-config_1_1.dtd 30 Jun 2002 04:37:32 - 1.19 +++ struts-config_1_1.dtd 4 Jul 2002 00:05:47 - 1.20 @@ -289,7 +289,12 @@ pathThe application-relative or context-relative path of the mapped resource (determined by the selected value - for the contextRelative attribute). + for the contextRelative attribute). If contextRelative + is false, this value is used in a calculation based on + the forwardPattern property of the controller parameters + for the current sub-application to calculate the + resulting value. This value must begin with a slash + (/) character. redirectSet to true if sendRedirect() should be used to forward to this resource, or false in order to use @@ -434,6 +439,22 @@ debug Debugging detail level for this application. [0] + forwardPattern Replacement pattern defining how the path attribute of + a forward element is mapped to a server-relative URL + when it starts with a slash (and when the contextRelative + property is false). This value may consist of any + combination of the following: + - $C - Replaced by the context path of this webapp + - $A - Replaced by the app prefix of this subapp + - $P - Replaced by the path attribute of the + selected forward element + - $$ - Causes a literal dollar sign to be rendered + - $x - (Where x is any character not defined above) + Silently swallowed, reserved for future use + If not specified, the default forwardPattern is + $C$A$P, which is consistent with previous hard coded + behavior of forwards. + locale Set to true if you want a Locale object stored in the user's session if not already present. [true] @@ -450,6 +471,20 @@ HTTP headers for defeating caching to every response. [false] + pagePattern Replacement pattern defining how the page attribute of + custom tags that use it is mapped to a server-relative URL + of the corresponding resource. This value may consist of + any combination of the following: + - $C - Replaced by the context path of this webapp + - $A - Replaced by the app prefix of this subapp + - $P - Replaced by the value of the page attribute + - $$ - Causes a literal dollar sign to be rendered + - $x - (Where x is any character not defined above) +
cvs commit: jakarta-struts/src/test/org/apache/struts/util TestRequestUtils.java FormBean.java
craigmcc2002/07/01 21:23:14 Modified:src/share/org/apache/struts/action ActionFormBean.java src/test/org/apache/struts/mock TestMockBase.java src/test/org/apache/struts/util TestRequestUtils.java Added: src/test/org/apache/struts/mock MockFormBean.java Removed: src/test/org/apache/struts/util FormBean.java Log: Add RequestUtils unit tests for createActionForm, requestURL, and selectApplication(). Revision ChangesPath 1.6 +31 -4 jakarta-struts/src/share/org/apache/struts/action/ActionFormBean.java Index: ActionFormBean.java === RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionFormBean.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ActionFormBean.java 25 Jun 2002 00:42:44 - 1.5 +++ ActionFormBean.java 2 Jul 2002 04:23:13 - 1.6 @@ -86,4 +86,31 @@ public class ActionFormBean extends FormBeanConfig { +/** + * Construct an instance with default vaslues. + */ +public ActionFormBean() { + +super(); + +} + + +/** + * Construct an instance with the specified values. + * + * @param name Form bean name + * @param type Fully qualified class name + * @param dynamic Is this a DynaActionForm bean? + */ +public ActionFormBean(String name, String type, boolean dynamic) { + +super(); +setName(name); +setType(type); +setDynamic(dynamic); + +} + + } 1.2 +123 -13 jakarta-struts/src/test/org/apache/struts/mock/TestMockBase.java Index: TestMockBase.java === RCS file: /home/cvs/jakarta-struts/src/test/org/apache/struts/mock/TestMockBase.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TestMockBase.java 2 Jul 2002 01:55:27 - 1.1 +++ TestMockBase.java 2 Jul 2002 04:23:14 - 1.2 @@ -65,9 +65,11 @@ import junit.framework.*; import org.apache.struts.action.Action; +import org.apache.struts.action.ActionFormBean; import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; import org.apache.struts.config.ApplicationConfig; -import org.apache.struts.config.ForwardConfig; +import org.apache.struts.config.FormPropertyConfig; @@ -136,24 +138,132 @@ response = new MockHttpServletResponse(); page = new MockPageContext(config, request, response); -// Set up application configuration for the default subapp +// Set up application configurations for our supported subapps +setUpDefaultApp(); +setUpSecondApp(); + +// NOTE - we do not initialize the request attribute +// for the selected subapp so that fallbacks to the +// default subapp can be tested. To select a subapp, +// tests should set the request attribute Action.APPLICATION_KEY +// to the ApplicationConfig instance for the selected subapp + +} + + +protected void setUpDefaultApp() { + +ActionFormBean formBean = null; +ActionForward forward = null; +ActionMapping mapping = null; + appConfig = new ApplicationConfig(); context.setAttribute(Action.APPLICATION_KEY, appConfig); + +// Forward foo to /bar.jsp appConfig.addForwardConfig (new ActionForward(foo, /bar.jsp, false)); -// Set up application configuration for the second subapp +// Form Bean static is a standard ActionForm subclass +formBean = new ActionFormBean +(static, + org.apache.struts.mock.MockFormBean, + false); +appConfig.addFormBeanConfig(formBean); + +// Action /static uses the static form bean in request scope +mapping = new ActionMapping(); +mapping.setInput(/static.jsp); +mapping.setName(static); +mapping.setPath(/static); +mapping.setScope(request); +mapping.setType(org.apache.struts.mock.MockAction); +appConfig.addActionConfig(mapping); + +// Form Bean dynamic is a DynaActionForm with the same properties +formBean = new ActionFormBean +(dynamic, + org.apache.struts.action.DynaActionForm, + true); +formBean.addFormPropertyConfig +(new FormPropertyConfig(booleanProperty, boolean, false)); +formBean.addFormPropertyConfig +(new FormPropertyConfig(stringProperty, java.lang.String, +null)); +appConfig.addFormBeanConfig(formBean); + +