1 5 9 package com.opensymphony.webwork.dispatcher; 10 11 import com.mockobjects.servlet.MockHttpServletRequest; 12 import com.opensymphony.webwork.WebWorkTestCase; 13 import com.opensymphony.webwork.dispatcher.mapper.ActionMapping; 14 import com.opensymphony.webwork.dispatcher.mapper.DefaultActionMapper; 15 16 import java.util.HashMap ; 17 18 19 22 public class DefautActionMapperTest extends WebWorkTestCase { 23 public void testGetMapping() throws Exception { 24 MockHttpServletRequest req = new MockHttpServletRequest(); 25 req.setupGetParameterMap(new HashMap ()); 26 req.setupGetRequestURI("/my/namespace/actionName.action"); 27 req.setupGetServletPath("/my/namespace/actionName.action"); 28 req.setupGetAttribute(null); 29 req.addExpectedGetAttributeName("javax.servlet.include.servlet_path"); 30 31 DefaultActionMapper mapper = new DefaultActionMapper(); 32 ActionMapping mapping = mapper.getMapping(req); 33 34 assertEquals("/my/namespace", mapping.getNamespace()); 35 assertEquals("actionName", mapping.getName()); 36 assertNull(mapping.getMethod()); 37 } 38 39 public void testGetMappingWithMethod() throws Exception { 40 MockHttpServletRequest req = new MockHttpServletRequest(); 41 req.setupGetParameterMap(new HashMap ()); 42 req.setupGetRequestURI("/my/namespace/actionName!add.action"); 43 req.setupGetServletPath("/my/namespace/actionName!add.action"); 44 req.setupGetAttribute(null); 45 req.addExpectedGetAttributeName("javax.servlet.include.servlet_path"); 46 47 DefaultActionMapper mapper = new DefaultActionMapper(); 48 ActionMapping mapping = mapper.getMapping(req); 49 50 assertEquals("/my/namespace", mapping.getNamespace()); 51 assertEquals("actionName", mapping.getName()); 52 assertEquals("add", mapping.getMethod()); 53 } 54 55 public void testGetUri() throws Exception { 56 MockHttpServletRequest req = new MockHttpServletRequest(); 57 req.setupGetParameterMap(new HashMap ()); 58 req.setupGetRequestURI("/my/namespace/actionName.action"); 59 req.setupGetServletPath("/my/namespace/actionName.action"); 60 req.setupGetAttribute(null); 61 req.addExpectedGetAttributeName("javax.servlet.include.servlet_path"); 62 63 DefaultActionMapper mapper = new DefaultActionMapper(); 64 ActionMapping mapping = mapper.getMapping(req); 65 assertEquals("/my/namespace/actionName.action", mapper.getUriFromActionMapping(mapping)); 66 } 67 68 public void testGetUriWithMethod() throws Exception { 69 MockHttpServletRequest req = new MockHttpServletRequest(); 70 req.setupGetParameterMap(new HashMap ()); 71 req.setupGetRequestURI("/my/namespace/actionName!add.action"); 72 req.setupGetServletPath("/my/namespace/actionName!add.action"); 73 req.setupGetAttribute(null); 74 req.addExpectedGetAttributeName("javax.servlet.include.servlet_path"); 75 76 DefaultActionMapper mapper = new DefaultActionMapper(); 77 ActionMapping mapping = mapper.getMapping(req); 78 79 assertEquals("/my/namespace/actionName!add.action", mapper.getUriFromActionMapping(mapping)); 80 } 81 } 82 | Popular Tags |