001: /*
002: * $Id: RestfulActionMapperTest.java 471756 2006-11-06 15:01:43Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.dispatcher.mapper;
022:
023: import java.util.Collections;
024: import java.util.HashMap;
025: import java.util.Map;
026:
027: import junit.framework.TestCase;
028:
029: import org.apache.struts2.views.jsp.StrutsMockHttpServletRequest;
030:
031: /**
032: * Unit test for {@link RestfulActionMapper}.
033: *
034: */
035: public class RestfulActionMapperTest extends TestCase {
036:
037: private RestfulActionMapper mapper;
038:
039: public void testGetUri() {
040: ActionMapping am = new ActionMapping();
041: am.setName("view");
042: am.setNamespace("secure");
043: am.setParams(Collections.EMPTY_MAP);
044:
045: assertEquals("secureview", mapper.getUriFromActionMapping(am));
046: }
047:
048: public void testGetUriParam() {
049: Map param = new HashMap();
050: param.put("article", "123");
051: ActionMapping am = new ActionMapping();
052: am.setName("view");
053: am.setNamespace("secure");
054: am.setParams(param);
055:
056: assertEquals("secureview", mapper.getUriFromActionMapping(am));
057: }
058:
059: public void testGetUriParamId() {
060: Map param = new HashMap();
061: param.put("article", "123");
062: param.put("viewId", "456");
063: ActionMapping am = new ActionMapping();
064: am.setName("view");
065: am.setNamespace("secure");
066: am.setParams(param);
067:
068: assertEquals("secureview/456", mapper
069: .getUriFromActionMapping(am));
070: }
071:
072: public void testGetMappingNoSlash() throws Exception {
073: StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
074: request.setupGetServletPath("noslash");
075:
076: assertNull(mapper.getMapping(request, null));
077: }
078:
079: public void testGetMapping() throws Exception {
080: StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
081: request.setupGetServletPath("/myapp/view/12");
082:
083: ActionMapping am = mapper.getMapping(request, null);
084: assertEquals("myapp", am.getName());
085: assertEquals(1, am.getParams().size());
086: assertEquals("12", am.getParams().get("view"));
087: }
088:
089: public void testGetMapping2() throws Exception {
090: StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
091: request.setupGetServletPath("/myapp/12/region/europe");
092:
093: ActionMapping am = mapper.getMapping(request, null);
094: assertEquals("myapp", am.getName());
095: assertEquals(2, am.getParams().size());
096: assertEquals("12", am.getParams().get("myappId"));
097: assertEquals("europe", am.getParams().get("region"));
098: }
099:
100: public void testGetMapping3() throws Exception {
101: StrutsMockHttpServletRequest request = new StrutsMockHttpServletRequest();
102: request.setupGetServletPath("/myapp/view/12/region/europe");
103:
104: ActionMapping am = mapper.getMapping(request, null);
105: assertEquals("myapp", am.getName());
106: assertEquals(2, am.getParams().size());
107: assertEquals("12", am.getParams().get("view"));
108: assertEquals("europe", am.getParams().get("region"));
109: }
110:
111: protected void setUp() throws Exception {
112: mapper = new RestfulActionMapper();
113: }
114:
115: protected void tearDown() throws Exception {
116: mapper = null;
117: }
118:
119: }
|