001: /*
002: * $Id: CompositeActionMapperTest.java 478625 2006-11-23 17:31:52Z wsmoak $
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.Iterator;
024: import java.util.LinkedHashMap;
025: import java.util.List;
026: import java.util.Map;
027:
028: import javax.servlet.http.HttpServletRequest;
029:
030: import org.apache.struts2.StrutsConstants;
031: import org.springframework.mock.web.MockHttpServletRequest;
032:
033: import com.mockobjects.dynamic.C;
034: import com.mockobjects.dynamic.Mock;
035: import com.opensymphony.xwork2.config.ConfigurationManager;
036: import com.opensymphony.xwork2.inject.Container;
037: import com.opensymphony.xwork2.inject.Scope.Strategy;
038:
039: import junit.framework.TestCase;
040:
041: /**
042: *
043: * @version $Date: 2006-11-23 12:31:52 -0500 (Thu, 23 Nov 2006) $ $Id: CompositeActionMapperTest.java 478625 2006-11-23 17:31:52Z wsmoak $
044: */
045: public class CompositeActionMapperTest extends TestCase {
046:
047: CompositeActionMapper compositeActionMapper;
048: Mock mockContainer;
049:
050: public void setUp() throws Exception {
051: compositeActionMapper = new CompositeActionMapper();
052: mockContainer = new Mock(Container.class);
053: compositeActionMapper.setContainer((Container) mockContainer
054: .proxy());
055: }
056:
057: public void testGetActionMappingAndUri1() throws Exception {
058: ActionMapper mapper1 = new InnerActionMapper1();
059: ActionMapper mapper2 = new InnerActionMapper2();
060: ActionMapper mapper3 = new InnerActionMapper3();
061: mockContainer.expectAndReturn("getInstance", C.args(C
062: .eq(ActionMapper.class), C.eq("mapper1")), mapper1);
063: mockContainer.expectAndReturn("getInstance", C.args(C
064: .eq(ActionMapper.class), C.eq("mapper2")), mapper3);
065: mockContainer.expectAndReturn("getInstance", C.args(C
066: .eq(ActionMapper.class), C.eq("mapper3")), mapper2);
067: compositeActionMapper
068: .setActionMappers("mapper1,mapper2,mapper3");
069:
070: ActionMapping actionMapping = compositeActionMapper.getMapping(
071: new MockHttpServletRequest(),
072: new ConfigurationManager());
073: String uri = compositeActionMapper
074: .getUriFromActionMapping(new ActionMapping());
075: mockContainer.verify();
076:
077: assertNotNull(actionMapping);
078: assertNotNull(uri);
079: assertTrue(actionMapping == InnerActionMapper3.actionMapping);
080: assertTrue(uri == InnerActionMapper3.uri);
081:
082: }
083:
084: public void testGetActionMappingAndUri2() throws Exception {
085: ActionMapper mapper1 = new InnerActionMapper1();
086: ActionMapper mapper2 = new InnerActionMapper2();
087: mockContainer.expectAndReturn("getInstance", C.args(C
088: .eq(ActionMapper.class), C.eq("mapper1")), mapper1);
089: mockContainer.expectAndReturn("getInstance", C.args(C
090: .eq(ActionMapper.class), C.eq("mapper2")), mapper2);
091: compositeActionMapper.setActionMappers("mapper1,mapper2");
092:
093: ActionMapping actionMapping = compositeActionMapper.getMapping(
094: new MockHttpServletRequest(),
095: new ConfigurationManager());
096: String uri = compositeActionMapper
097: .getUriFromActionMapping(new ActionMapping());
098: mockContainer.verify();
099:
100: assertNull(actionMapping);
101: assertNull(uri);
102: }
103:
104: public static class InnerActionMapper1 implements ActionMapper {
105: public static ActionMapping actionMapping = new ActionMapping();
106: public static String uri = "uri1";
107:
108: public ActionMapping getMapping(HttpServletRequest request,
109: ConfigurationManager configManager) {
110: return null;
111: }
112:
113: public String getUriFromActionMapping(ActionMapping mapping) {
114: return null;
115: }
116: }
117:
118: public static class InnerActionMapper2 implements ActionMapper {
119: public static ActionMapping actionMapping = new ActionMapping();
120: public static String uri = "uri2";
121:
122: public ActionMapping getMapping(HttpServletRequest request,
123: ConfigurationManager configManager) {
124: return null;
125: }
126:
127: public String getUriFromActionMapping(ActionMapping mapping) {
128: return null;
129: }
130: }
131:
132: public static class InnerActionMapper3 implements ActionMapper {
133: public static ActionMapping actionMapping = new ActionMapping();
134: public static String uri = "uri3";
135:
136: public ActionMapping getMapping(HttpServletRequest request,
137: ConfigurationManager configManager) {
138: return actionMapping;
139: }
140:
141: public String getUriFromActionMapping(ActionMapping mapping) {
142: return uri;
143: }
144: }
145: }
|