You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by mr...@apache.org on 2007/10/21 12:43:18 UTC

svn commit: r586882 - in /struts/sandbox/trunk/struts2-rest-plugin: showcase/src/main/java/org/apache/struts2/rest/example/ showcase/src/main/webapp/ src/main/java/org/apache/struts2/rest/ src/main/java/org/apache/struts2/rest/handler/ src/main/resourc...

Author: mrdon
Date: Sun Oct 21 03:43:07 2007
New Revision: 586882

URL: http://svn.apache.org/viewvc?rev=586882&view=rev
Log:
Changing url conventions to match rails

Added:
    struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/OrdersResource.java
    struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-edit.jsp
    struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-editNew.jsp
    struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-index.jsp
    struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-show.jsp
    struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-success.jsp
Removed:
    struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/OrderResource.java
    struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/order-index.jsp
    struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/order-input.jsp
    struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/order-new.jsp
    struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/order-show.jsp
    struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/order-success.jsp
Modified:
    struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/Order.java
    struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/index.jsp
    struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/RestActionMapper.java
    struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/RestWorkflowInterceptor.java
    struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/handler/XStreamHandler.java
    struts/sandbox/trunk/struts2-rest-plugin/src/main/resources/struts-plugin.xml
    struts/sandbox/trunk/struts2-rest-plugin/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java

Modified: struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/Order.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/Order.java?rev=586882&r1=586881&r2=586882&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/Order.java (original)
+++ struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/Order.java Sun Oct 21 03:43:07 2007
@@ -1,5 +1,7 @@
 package org.apache.struts2.rest.example;
 
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+
 public class Order {
     String id;
     String clientName;

Added: struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/OrdersResource.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/OrdersResource.java?rev=586882&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/OrdersResource.java (added)
+++ struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/java/org/apache/struts2/rest/example/OrdersResource.java Sun Oct 21 03:43:07 2007
@@ -0,0 +1,84 @@
+package org.apache.struts2.rest.example;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.struts2.interceptor.ParameterAware;
+import org.apache.struts2.rest.DefaultRestInfo;
+import org.apache.struts2.rest.RestInfo;
+
+import com.opensymphony.xwork2.ModelDriven;
+import com.opensymphony.xwork2.Validateable;
+import com.opensymphony.xwork2.ValidationAwareSupport;
+
+public class OrdersResource extends ValidationAwareSupport implements ModelDriven<Object>, ParameterAware, Validateable{
+    
+    private Order model = new Order();
+    private static Map<String,Order> orders = new HashMap<String,Order>();
+    
+    static {
+        orders.put("3", new Order("3", "Bob", 33));
+        orders.put("4", new Order("4", "Sarah", 44));
+        orders.put("5", new Order("5", "Jim", 66));
+    }
+    private Collection<Order> list;
+    
+    public void validate() {
+        if (model.getId() == null || model.getId().length() ==0) {
+            addFieldError("id", "ID is wrong");
+        }
+    }
+    
+    public String show() {
+        return "show";
+    }
+    
+    public String edit() {
+        return "edit";
+    }
+    
+    public String editNew() {
+        return "editNew";
+    }
+    
+    public String destroy() {
+        orders.remove(model.getId());
+        return "success";
+    }
+    
+    public RestInfo create() {
+        orders.put(model.getId(), model);
+        return new DefaultRestInfo()
+            .setLocationId(model.getId())
+            .renderResult("success");
+    }
+    
+    public String update() {
+        orders.put(model.getId(), model);
+        return "success";
+    }
+    
+    public RestInfo index() {
+        list = new ArrayList(orders.values());
+        
+        return new DefaultRestInfo()
+            .renderResult("index")
+            .withETag("2323");
+    }
+    
+    public Object getModel() {
+        return (list != null ? list : model);
+    }
+
+    // Silly workaround since modeldriven doesn't work right in xwork 2.1.0
+    public void setParameters(Map<String,String[]> parameters) {
+        if (parameters.get("id") != null && orders.get(parameters.get("id")[0]) != null) {
+            orders.get(parameters.get("id")[0]).copyTo(model);
+        }
+    }
+    
+    
+}

Modified: struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/index.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/index.jsp?rev=586882&r1=586881&r2=586882&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/index.jsp (original)
+++ struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/index.jsp Sun Oct 21 03:43:07 2007
@@ -1,2 +1,2 @@
 
-<% response.sendRedirect("order/.xhtml"); %>
+<% response.sendRedirect("orders.xhtml"); %>

Added: struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-edit.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-edit.jsp?rev=586882&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-edit.jsp (added)
+++ struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-edit.jsp Sun Oct 21 03:43:07 2007
@@ -0,0 +1,27 @@
+<!DOCTYPE html PUBLIC 
+	"-//W3C//DTD XHTML 1.1 Transitional//EN"
+	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+	
+<%@taglib prefix="s" uri="/struts-tags" %>
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+	<title>Order <s:property value="id" /></title>
+</head>
+<body>
+    <s:form method="post" action="%{#request.contextPath}/orders/%{id}.xhtml">
+    <s:hidden name="_method" value="put" />
+    <table>
+        <s:textfield name="id" label="ID" />
+        <s:textfield name="clientName" label="Client"/>
+        <s:textfield name="amount" label="Amount" />
+        <tr>
+            <td colspan="2">
+                <s:submit />
+            </td>
+    </table>
+    </s:form>    	
+    <a href="<%=request.getContextPath() %>/orders.xhtml">Back to Orders</a>
+</body>
+</html>
+	
\ No newline at end of file

Added: struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-editNew.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-editNew.jsp?rev=586882&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-editNew.jsp (added)
+++ struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-editNew.jsp Sun Oct 21 03:43:07 2007
@@ -0,0 +1,26 @@
+<!DOCTYPE html PUBLIC 
+	"-//W3C//DTD XHTML 1.1 Transitional//EN"
+	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+	
+<%@taglib prefix="s" uri="/struts-tags" %>
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+	<title>New Order</title>
+</head>
+<body>
+    <s:form method="post" action="%{#request.contextPath}/orders.xhtml">
+    <table>
+        <s:textfield name="id" label="ID" />
+        <s:textfield name="clientName" label="Client"/>
+        <s:textfield name="amount" label="Amount" />
+        <tr>
+            <td colspan="2">
+                <s:submit />
+            </td>
+    </table>
+    </s:form>    	
+    <a href="<%=request.getContextPath() %>/orders.xhtml">Back to Orders</a>
+</body>
+</html>
+	
\ No newline at end of file

Added: struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-index.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-index.jsp?rev=586882&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-index.jsp (added)
+++ struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-index.jsp Sun Oct 21 03:43:07 2007
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC 
+	"-//W3C//DTD XHTML 1.1 Transitional//EN"
+	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+	
+<%@taglib prefix="s" uri="/struts-tags" %>
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+	<title>Orders</title>
+</head>
+<body>
+    <table>
+        <tr>
+            <th>ID</th>
+            <th>Client</th>
+            <th>Amount</th>
+            <th>Actions</th>
+        </tr>
+        <s:iterator value="model">
+        <tr>
+            <td><s:property value="id" /></td>
+            <td><s:property value="clientName" /></td>
+            <td><s:property value="amount" /></td>
+            <td><a href="orders/<s:property value="id" />.xhtml">View</a> |
+                <a href="orders/<s:property value="id" />;edit.xhtml">Edit</a> |
+                <a href="orders/<s:property value="id" />.xhtml?_method=DELETE">Delete</a></td>
+        </tr>
+        </s:iterator>
+    </table>    	
+    <a href="orders/new.xhtml">Create a new order</a>
+</body>
+</html>
+	
\ No newline at end of file

Added: struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-show.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-show.jsp?rev=586882&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-show.jsp (added)
+++ struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-show.jsp Sun Oct 21 03:43:07 2007
@@ -0,0 +1,29 @@
+<!DOCTYPE html PUBLIC 
+	"-//W3C//DTD XHTML 1.1 Transitional//EN"
+	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+	
+<%@taglib prefix="s" uri="/struts-tags" %>
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+	<title>Order <s:property value="id" /></title>
+</head>
+<body>
+    <table>
+        <tr>
+            <th>ID</th>
+            <td><s:property value="id" /></td>
+        </tr>
+        <tr>
+            <th>Client</th>
+            <td><s:property value="clientName" /></td>
+        </tr>
+        <tr>
+            <th>Amount</th>
+            <td><s:property value="amount" /></td>
+        </tr>
+    </table>    	
+    <a href="../orders.xhtml">Back to Orders</a>
+</body>
+</html>
+	
\ No newline at end of file

Added: struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-success.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-success.jsp?rev=586882&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-success.jsp (added)
+++ struts/sandbox/trunk/struts2-rest-plugin/showcase/src/main/webapp/orders-success.jsp Sun Oct 21 03:43:07 2007
@@ -0,0 +1,16 @@
+<!DOCTYPE html PUBLIC 
+	"-//W3C//DTD XHTML 1.1 Transitional//EN"
+	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+	
+<%@taglib prefix="s" uri="/struts-tags" %>
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+	<title>Operation Successful</title>
+</head>
+<body>
+    Operation Successful    <br />	
+     <a href="<%=request.getContextPath() %>/orders.xhtml">Back to Orders</a>
+</body>
+</html>
+	
\ No newline at end of file

Modified: struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/RestActionMapper.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/RestActionMapper.java?rev=586882&r1=586881&r2=586882&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/RestActionMapper.java (original)
+++ struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/RestActionMapper.java Sun Oct 21 03:43:07 2007
@@ -20,27 +20,22 @@
  */
 package org.apache.struts2.rest;
 
-import com.opensymphony.xwork2.config.Configuration;
-import com.opensymphony.xwork2.config.ConfigurationManager;
-import com.opensymphony.xwork2.config.entities.PackageConfig;
-import com.opensymphony.xwork2.inject.Inject;
-import com.opensymphony.xwork2.util.logging.Logger;
-import com.opensymphony.xwork2.util.logging.LoggerFactory;
-
-import javax.servlet.http.HttpServletRequest;
-
-import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.List;
-import java.util.StringTokenizer;
-import java.net.URLDecoder;
 
-import org.apache.struts2.RequestUtils;
+import javax.servlet.http.HttpServletRequest;
+
 import org.apache.struts2.StrutsConstants;
 import org.apache.struts2.dispatcher.mapper.ActionMapping;
 import org.apache.struts2.dispatcher.mapper.DefaultActionMapper;
 
+import com.opensymphony.xwork2.config.Configuration;
+import com.opensymphony.xwork2.config.ConfigurationManager;
+import com.opensymphony.xwork2.config.entities.PackageConfig;
+import com.opensymphony.xwork2.inject.Inject;
+import com.opensymphony.xwork2.util.logging.Logger;
+import com.opensymphony.xwork2.util.logging.LoggerFactory;
+
 /**
  * <!-- START SNIPPET: description -->
  *
@@ -156,14 +151,14 @@
             // If a method hasn't been explicitly named, try to guess using ReST-style patterns
             if (mapping.getMethod() == null) {
 
-                // Handle uris ending in '/'
-                if (lastSlashPos == fullName.length() -1) {
+                // Handle uris with no id, possibly ending in '/'
+                if (lastSlashPos == -1 || lastSlashPos == fullName.length() -1) {
 
-                    // Index e.g. foo/
+                    // Index e.g. foo
                     if (isGet(request)) {
                         mapping.setMethod("index");
                         
-                    // Creating a new entry on POST e.g. foo/
+                    // Creating a new entry on POST e.g. foo
                     } else if (isPost(request)) {
                         mapping.setMethod("create");
                     }
@@ -174,11 +169,11 @@
                     // Viewing the form to edit an item e.g. foo/1;edit
                     if (isGet(request) && id.endsWith(";edit")) {
                         id = id.substring(0, id.length() - ";edit".length());
-                        mapping.setMethod("input");
+                        mapping.setMethod("edit");
                         
                     // Viewing the form to create a new item e.g. foo/new
                     } else if (isGet(request) && "new".equals(id)) {
-                        mapping.setMethod("input");
+                        mapping.setMethod("editNew");
 
                     // Removing an item e.g. foo/1
                     } else if (isDelete(request)) {
@@ -234,17 +229,22 @@
             namespace = "/";
             name = uri.substring(lastSlash + 1);
         } else {
-            int secondToLastSlash = uri.lastIndexOf('/', lastSlash - 1);
-            if (secondToLastSlash == 0) {
-                namespace = "/";
-                name = uri.substring(secondToLastSlash + 1);
-            } else if (secondToLastSlash > -1) {
-                namespace = uri.substring(0, secondToLastSlash);
-                name = uri.substring(secondToLastSlash + 1);
-            } else {
-                namespace = "";
-                name = uri;
+            // Try to find the namespace in those defined, defaulting to ""
+            Configuration config = configManager.getConfiguration();
+            String prefix = uri.substring(0, lastSlash);
+            namespace = "";
+            // Find the longest matching namespace, defaulting to the default
+            for (Iterator i = config.getPackageConfigs().values().iterator(); i
+                    .hasNext();) {
+                String ns = ((PackageConfig) i.next()).getNamespace();
+                if (ns != null && prefix.startsWith(ns) && (prefix.length() == ns.length() || prefix.charAt(ns.length()) == '/')) {
+                    if (ns.length() > namespace.length()) {
+                        namespace = ns;
+                    }
+                }
             }
+
+            name = uri.substring(namespace.length() + 1);
         }
 
         mapping.setNamespace(namespace);

Modified: struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/RestWorkflowInterceptor.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/RestWorkflowInterceptor.java?rev=586882&r1=586881&r2=586882&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/RestWorkflowInterceptor.java (original)
+++ struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/RestWorkflowInterceptor.java Sun Oct 21 03:43:07 2007
@@ -23,7 +23,11 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.dispatcher.mapper.ActionMapping;
+
 import com.opensymphony.xwork2.Action;
+import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionInvocation;
 import com.opensymphony.xwork2.ValidationAware;
 import com.opensymphony.xwork2.inject.Inject;
@@ -164,12 +168,22 @@
             	if (LOG.isDebugEnabled()) {
             		LOG.debug("Errors on action "+validationAwareAction+", returning result name 'input'");
             	}
+            	ActionMapping mapping = (ActionMapping) ActionContext.getContext().get(ServletActionContext.ACTION_MAPPING);
+            	String method = inputResultName;
+                if ("create".equals(mapping.getMethod())) {
+                    method = "editNew";
+                } else if ("update".equals(mapping.getMethod())) {
+                    method = "edit";
+                }
+                
+                
             	RestInfo info = new DefaultRestInfo()
             	    .disableCaching()
-            	    .renderResult(inputResultName)
+            	    .renderResult(method)
             	    .withStatus(SC_BAD_REQUEST);
             	
             	Map errors = new HashMap();
+            	
             	errors.put("actionErrors", validationAwareAction.getActionErrors());
             	errors.put("fieldErrors", validationAwareAction.getFieldErrors());
             	return manager.handleResult(invocation.getProxy().getConfig(), info, errors);

Modified: struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/handler/XStreamHandler.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/handler/XStreamHandler.java?rev=586882&r1=586881&r2=586882&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/handler/XStreamHandler.java (original)
+++ struts/sandbox/trunk/struts2-rest-plugin/src/main/java/org/apache/struts2/rest/handler/XStreamHandler.java Sun Oct 21 03:43:07 2007
@@ -20,16 +20,10 @@
  */
 package org.apache.struts2.rest.handler;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.struts2.ServletActionContext;
-
-import com.opensymphony.xwork2.ActionInvocation;
 import com.thoughtworks.xstream.XStream;
 
 public class XStreamHandler implements ContentTypeHandler {

Modified: struts/sandbox/trunk/struts2-rest-plugin/src/main/resources/struts-plugin.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/src/main/resources/struts-plugin.xml?rev=586882&r1=586881&r2=586882&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/src/main/resources/struts-plugin.xml (original)
+++ struts/sandbox/trunk/struts2-rest-plugin/src/main/resources/struts-plugin.xml Sun Oct 21 03:43:07 2007
@@ -60,10 +60,10 @@
                 <interceptor-ref name="rest" />
                 <interceptor-ref name="conversionError"/>
                 <interceptor-ref name="validation">
-                    <param name="excludeMethods">input,back,cancel,browse,index,show</param>
+                    <param name="excludeMethods">input,back,cancel,browse,index,show,edit,editNew</param>
                 </interceptor-ref>
                 <interceptor-ref name="restWorkflow">
-                    <param name="excludeMethods">input,back,cancel,browse,index,show</param>
+                    <param name="excludeMethods">input,back,cancel,browse,index,show,edit,editNew</param>
                 </interceptor-ref>
             </interceptor-stack>
     

Modified: struts/sandbox/trunk/struts2-rest-plugin/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-rest-plugin/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java?rev=586882&r1=586881&r2=586882&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-rest-plugin/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java (original)
+++ struts/sandbox/trunk/struts2-rest-plugin/src/test/java/org/apache/struts2/rest/RestActionMapperTest.java Sun Oct 21 03:43:07 2007
@@ -1,36 +1,57 @@
 package org.apache.struts2.rest;
 
+import java.util.HashMap;
+
 import org.apache.struts2.dispatcher.mapper.ActionMapping;
 
+import com.opensymphony.xwork2.config.Configuration;
+import com.opensymphony.xwork2.config.ConfigurationManager;
+import com.opensymphony.xwork2.config.entities.PackageConfig;
+import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
+
 import junit.framework.TestCase;
 
 public class RestActionMapperTest extends TestCase {
 
     private RestActionMapper mapper;
-    
-    public void setUp() throws Exception {
+    private ConfigurationManager configManager;
+    private Configuration config;
+
+    protected void setUp() throws Exception {
+        super.setUp();
         mapper = new RestActionMapper();
+
+        config = new DefaultConfiguration();
+        PackageConfig pkg = new PackageConfig("myns", "/my/namespace", false, null);
+        PackageConfig pkg2 = new PackageConfig("my", "/my", false, null);
+        config.addPackageConfig("mvns", pkg);
+        config.addPackageConfig("my", pkg2);
+        configManager = new ConfigurationManager() {
+            public Configuration getConfiguration() {
+                return config;
+            }
+        };
     }
 
     public void testParseNameAndNamespace() {
-        tryUri("/foo/23", "/", "foo/23");
-        tryUri("/foo/", "/", "foo/");
+        tryUri("/foo/23", "", "foo/23");
+        tryUri("/foo/", "", "foo/");
         tryUri("foo", "", "foo");
         tryUri("/", "/", "");
     }
     
     public void testParseNameAndNamespaceWithNamespaces() {
-        tryUri("/ns/foo/23", "/ns", "foo/23");
-        tryUri("/ns/foo/", "/ns", "foo/");
+        tryUri("/my/foo/23", "/my", "foo/23");
+        tryUri("/my/foo/", "/my", "foo/");
     }
     
     public void testParseNameAndNamespaceWithEdit() {
-        tryUri("/ns/foo/23;edit", "/ns", "foo/23;edit");
+        tryUri("/my/foo/23;edit", "/my", "foo/23;edit");
     }
     
     private void tryUri(String uri, String expectedNamespace, String expectedName) {
         ActionMapping mapping = new ActionMapping();
-        mapper.parseNameAndNamespace(uri, mapping, null);
+        mapper.parseNameAndNamespace(uri, mapping, configManager);
         assertEquals(expectedName, mapping.getName());
         assertEquals(expectedNamespace, mapping.getNamespace());
     }