Commits

Anonymous committed 732d006

Issue number: ww-1046

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@1866573baa09-0c28-0410-bef9-dab3c582ae83

Comments (0)

Files changed (2)

src/java/com/opensymphony/webwork/dispatcher/mapper/DefaultActionMapper.java

  * </pre>
  *
  * @author Patrick Lightbody
+ * @author tm_jee
  */
 public class DefaultActionMapper implements ActionMapper {
 
             mapping.setName(name.substring(0, exclamation));
             mapping.setMethod(name.substring(exclamation + 1));
         }
-
         return mapping;
     }
 
         String namespace, name;
         int lastSlash = uri.lastIndexOf("/");
         if (lastSlash == -1) {
-            namespace = "";
+            namespace = ""; 
             name = uri;
+        } else if (lastSlash == 0) {
+            // ww-1046, assume it is the root namespace, it will fallback to default
+        	// namespace anyway if not found in root namespace.
+        	namespace = "/";
+        	name = uri.substring(lastSlash + 1);
         } else {
             namespace = uri.substring(0, lastSlash);
             name = uri.substring(lastSlash + 1);

src/test/com/opensymphony/webwork/dispatcher/mapper/DefaultActionMapperTest.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.webwork.dispatcher.mapper;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.opensymphony.webwork.dispatcher.ServletRedirectResult;
+import com.opensymphony.webwork.views.jsp.WebWorkMockHttpServletRequest;
+import com.opensymphony.xwork.Result;
+
+import junit.framework.TestCase;
+
+/**
+ * DefaultActionMapper test case.
+ * 
+ * @author tm_jee
+ * @version $Date$ $Id$
+ */
+public class DefaultActionMapperTest extends TestCase {
+
+	// =============================
+	// === test name & namespace ===
+	// =============================
+	
+	public void testParseNameAndNamespace1() throws Exception {
+		ActionMapping actionMapping = new ActionMapping();
+		
+		DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
+		defaultActionMapper.parseNameAndNamespace("someAction.action", actionMapping);
+		
+		assertEquals(actionMapping.getName(), "someAction");
+		assertEquals(actionMapping.getNamespace(), "");
+	}
+	
+	public void testParseNameAndNamespace2() throws Exception {
+		ActionMapping actionMapping = new ActionMapping();
+		
+		DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
+		defaultActionMapper.parseNameAndNamespace("/someAction.action", actionMapping);
+		
+		assertEquals(actionMapping.getName(), "someAction");
+		assertEquals(actionMapping.getNamespace(), "/");
+	}
+	
+	public void testParseNameAndNamespace3() throws Exception {
+		ActionMapping actionMapping = new ActionMapping();
+		
+		DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
+		defaultActionMapper.parseNameAndNamespace("/one/two/three/someAction.action", actionMapping);
+
+		assertEquals(actionMapping.getName(), "someAction");
+		assertEquals(actionMapping.getNamespace(), "/one/two/three");
+	}
+	
+	
+	// ===========================
+	// === test special prefix ===
+	// ===========================
+	public void testMethodPrefix() throws Exception {
+		Map parameterMap = new HashMap();
+		parameterMap.put(DefaultActionMapper.METHOD_PREFIX+"myMethod", "");
+		
+		WebWorkMockHttpServletRequest request = new WebWorkMockHttpServletRequest();
+		request.setParameterMap(parameterMap);
+		request.setupGetServletPath("/someServletPath.action");
+		
+		DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
+		ActionMapping actionMapping = defaultActionMapper.getMapping(request);
+		
+		assertEquals(actionMapping.getMethod(), "myMethod");
+	}
+	
+	public void testActionPrefix() throws Exception {
+		Map parameterMap = new HashMap();
+		parameterMap.put(DefaultActionMapper.ACTION_PREFIX+"myAction", "");
+		
+		WebWorkMockHttpServletRequest request = new WebWorkMockHttpServletRequest();
+		request.setParameterMap(parameterMap);
+		request.setupGetServletPath("/someServletPath.action");
+		
+		DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
+		ActionMapping actionMapping = defaultActionMapper.getMapping(request);
+		
+		assertEquals(actionMapping.getName(), "myAction");
+	}
+	
+	public void testRedirectPrefix() throws Exception {
+		Map parameterMap = new HashMap();
+		parameterMap.put(DefaultActionMapper.REDIRECT_PREFIX+"www.google.com", "");
+		
+		WebWorkMockHttpServletRequest request = new WebWorkMockHttpServletRequest();
+		request.setupGetServletPath("/someServletPath.action");
+		request.setParameterMap(parameterMap);
+		
+		DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
+		ActionMapping actionMapping = defaultActionMapper.getMapping(request);
+		
+		Result result = actionMapping.getResult();
+		assertNotNull(result);
+		assertTrue(result instanceof ServletRedirectResult);
+		
+		//TODO: need to test location but there's noaccess to the property/method, unless we use reflection
+	}
+	
+	public void testRedirectActionPrefix() throws Exception {
+		Map parameterMap = new HashMap();
+		parameterMap.put(DefaultActionMapper.REDIRECT_ACTION_PREFIX+"myAction", "");
+		
+		WebWorkMockHttpServletRequest request = new WebWorkMockHttpServletRequest();
+		request.setupGetServletPath("/someServletPath.action");
+		request.setParameterMap(parameterMap);
+		
+		DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
+		ActionMapping actionMapping = defaultActionMapper.getMapping(request);
+		
+		Result result = actionMapping.getResult();
+		assertNotNull(result);
+		assertTrue(result instanceof ServletRedirectResult);
+		
+		// TODO: need to test location but there's noaccess to the property/method, unless we use reflection
+	}
+	
+	
+	
+	// ==========================
+	// === test action!method ===
+	// ==========================
+	public void testActionBangMethod() throws Exception {
+		
+		WebWorkMockHttpServletRequest request = new WebWorkMockHttpServletRequest();
+		request.setupGetServletPath("/someName!someMethod.action");
+		
+		DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
+		ActionMapping actionMapping = defaultActionMapper.getMapping(request);
+		
+		assertEquals(actionMapping.getMethod(), "someMethod");
+		assertEquals(actionMapping.getName(), "someName");
+	}
+	
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.