001: /*
002: * Copyright (c) 2002-2006 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork.dispatcher.mapper;
006:
007: import junit.framework.TestCase;
008:
009: import java.util.Map;
010: import java.util.Collections;
011: import java.util.HashMap;
012:
013: import com.opensymphony.webwork.views.jsp.WebWorkMockHttpServletRequest;
014:
015: /**
016: * Unit test for {@link RestfulActionMapper}.
017: *
018: * @author Claus Ibsen
019: */
020: public class RestfulActionMapperTest extends TestCase {
021:
022: private RestfulActionMapper mapper;
023:
024: public void testGetUri() {
025: ActionMapping am = new ActionMapping();
026: am.setName("view");
027: am.setNamespace("secure");
028: am.setParams(Collections.EMPTY_MAP);
029:
030: assertEquals("secureview", mapper.getUriFromActionMapping(am));
031: }
032:
033: public void testGetUriParam() {
034: Map param = new HashMap();
035: param.put("article", "123");
036: ActionMapping am = new ActionMapping();
037: am.setName("view");
038: am.setNamespace("secure");
039: am.setParams(param);
040:
041: assertEquals("secureview", mapper.getUriFromActionMapping(am));
042: }
043:
044: public void testGetUriParamId() {
045: Map param = new HashMap();
046: param.put("article", "123");
047: param.put("viewId", "456");
048: ActionMapping am = new ActionMapping();
049: am.setName("view");
050: am.setNamespace("secure");
051: am.setParams(param);
052:
053: assertEquals("secureview/456", mapper
054: .getUriFromActionMapping(am));
055: }
056:
057: public void testGetMappingNoSlash() throws Exception {
058: WebWorkMockHttpServletRequest request = new WebWorkMockHttpServletRequest();
059: request.setupGetServletPath("noslash");
060:
061: assertNull(mapper.getMapping(request));
062: }
063:
064: public void testGetMapping() throws Exception {
065: WebWorkMockHttpServletRequest request = new WebWorkMockHttpServletRequest();
066: request.setupGetServletPath("/myapp/view/12");
067:
068: ActionMapping am = mapper.getMapping(request);
069: assertEquals("myapp", am.getName());
070: assertEquals(1, am.getParams().size());
071: assertEquals("12", am.getParams().get("view"));
072: }
073:
074: public void testGetMapping2() throws Exception {
075: WebWorkMockHttpServletRequest request = new WebWorkMockHttpServletRequest();
076: request.setupGetServletPath("/myapp/12/region/europe");
077:
078: ActionMapping am = mapper.getMapping(request);
079: assertEquals("myapp", am.getName());
080: assertEquals(2, am.getParams().size());
081: assertEquals("12", am.getParams().get("myappId"));
082: assertEquals("europe", am.getParams().get("region"));
083: }
084:
085: public void testGetMapping3() throws Exception {
086: WebWorkMockHttpServletRequest request = new WebWorkMockHttpServletRequest();
087: request.setupGetServletPath("/myapp/view/12/region/europe");
088:
089: ActionMapping am = mapper.getMapping(request);
090: assertEquals("myapp", am.getName());
091: assertEquals(2, am.getParams().size());
092: assertEquals("12", am.getParams().get("view"));
093: assertEquals("europe", am.getParams().get("region"));
094: }
095:
096: protected void setUp() throws Exception {
097: mapper = new RestfulActionMapper();
098: }
099:
100: protected void tearDown() throws Exception {
101: mapper = null;
102: }
103:
104: }
|