001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: /*
006: * Created on 2/10/2003
007: *
008: */
009: package com.opensymphony.webwork.dispatcher;
010:
011: import com.mockobjects.servlet.MockHttpServletRequest;
012: import com.opensymphony.webwork.WebWorkTestCase;
013: import com.opensymphony.webwork.WebWorkConstants;
014: import com.opensymphony.webwork.config.Configuration;
015: import com.opensymphony.webwork.dispatcher.mapper.ActionMapping;
016: import com.opensymphony.webwork.dispatcher.mapper.DefaultActionMapper;
017:
018: import java.util.HashMap;
019:
020: /**
021: * @author roughley
022: */
023: public class DefautActionMapperTest extends WebWorkTestCase {
024: private MockHttpServletRequest req;
025:
026: protected void setUp() throws Exception {
027: super .setUp();
028: req = new MockHttpServletRequest();
029: req.setupGetParameterMap(new HashMap());
030: req.setupGetContextPath("/my/namespace");
031: }
032:
033: public void testGetMapping() throws Exception {
034: setUp();
035: req.setupGetRequestURI("/my/namespace/actionName.action");
036: req.setupGetServletPath("/my/namespace/actionName.action");
037: req.setupGetAttribute(null);
038: req
039: .addExpectedGetAttributeName("javax.servlet.include.servlet_path");
040:
041: DefaultActionMapper mapper = new DefaultActionMapper();
042: ActionMapping mapping = mapper.getMapping(req);
043:
044: assertEquals("/my/namespace", mapping.getNamespace());
045: assertEquals("actionName", mapping.getName());
046: assertNull(mapping.getMethod());
047: }
048:
049: public void testGetMappingWithMethod() throws Exception {
050: req.setupGetParameterMap(new HashMap());
051: req.setupGetRequestURI("/my/namespace/actionName!add.action");
052: req.setupGetServletPath("/my/namespace/actionName!add.action");
053: req.setupGetAttribute(null);
054: req
055: .addExpectedGetAttributeName("javax.servlet.include.servlet_path");
056:
057: DefaultActionMapper mapper = new DefaultActionMapper();
058: ActionMapping mapping = mapper.getMapping(req);
059:
060: assertEquals("/my/namespace", mapping.getNamespace());
061: assertEquals("actionName", mapping.getName());
062: assertEquals("add", mapping.getMethod());
063: }
064:
065: public void testGetUri() throws Exception {
066: req.setupGetParameterMap(new HashMap());
067: req.setupGetRequestURI("/my/namespace/actionName.action");
068: req.setupGetServletPath("/my/namespace/actionName.action");
069: req.setupGetAttribute(null);
070: req
071: .addExpectedGetAttributeName("javax.servlet.include.servlet_path");
072:
073: DefaultActionMapper mapper = new DefaultActionMapper();
074: ActionMapping mapping = mapper.getMapping(req);
075: assertEquals("/my/namespace/actionName.action", mapper
076: .getUriFromActionMapping(mapping));
077: }
078:
079: public void testGetUriWithMethod() throws Exception {
080: req.setupGetParameterMap(new HashMap());
081: req.setupGetRequestURI("/my/namespace/actionName!add.action");
082: req.setupGetServletPath("/my/namespace/actionName!add.action");
083: req.setupGetAttribute(null);
084: req
085: .addExpectedGetAttributeName("javax.servlet.include.servlet_path");
086:
087: DefaultActionMapper mapper = new DefaultActionMapper();
088: ActionMapping mapping = mapper.getMapping(req);
089:
090: assertEquals("/my/namespace/actionName!add.action", mapper
091: .getUriFromActionMapping(mapping));
092: }
093:
094: public void testGetMappingWithNoExtension() throws Exception {
095: Object old = Configuration
096: .get(WebWorkConstants.WEBWORK_ACTION_EXTENSION);
097: Configuration
098: .set(WebWorkConstants.WEBWORK_ACTION_EXTENSION, "");
099: try {
100: req.setupGetParameterMap(new HashMap());
101: req.setupGetRequestURI("/my/namespace/actionName");
102: req.setupGetServletPath("/my/namespace/actionName");
103: req.setupGetAttribute(null);
104: req
105: .addExpectedGetAttributeName("javax.servlet.include.servlet_path");
106:
107: DefaultActionMapper mapper = new DefaultActionMapper();
108: ActionMapping mapping = mapper.getMapping(req);
109:
110: assertEquals("/my/namespace", mapping.getNamespace());
111: assertEquals("actionName", mapping.getName());
112: assertNull(mapping.getMethod());
113: } finally {
114: Configuration.set(
115: WebWorkConstants.WEBWORK_ACTION_EXTENSION, old);
116: }
117: }
118: }
|