1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.cubby.controller.impl;
17  
18  import org.seasar.cubby.action.Action;
19  import org.seasar.cubby.action.ActionResult;
20  import org.seasar.cubby.controller.ActionDef;
21  import org.seasar.cubby.controller.ActionDefBuilder;
22  import org.seasar.cubby.util.CubbyUtils;
23  import org.seasar.extension.unit.S2TestCase;
24  import org.seasar.framework.mock.servlet.MockHttpServletRequest;
25  import org.seasar.framework.mock.servlet.MockServletContext;
26  
27  public class ActionDefBuilderImplTest extends S2TestCase {
28  
29  	public ActionDefBuilder actionDefBuilder;
30  
31  	@Override
32  	protected void setUp() throws Exception {
33  		include(this.getClass().getName().replaceAll("\\.", "/") + ".dicon");
34  	}
35  
36  	public void testFromPathToActionDefReturnsNull1() {
37  		MockServletContext servletContext = getServletContext();
38  		MockHttpServletRequest request = servletContext.createRequest("/none");
39  		ActionDef actionDef = actionDefBuilder.build(request);
40  		assertNull(actionDef);
41  	}
42  
43  	public void testFromPathToActionDefReturnsNull2() {
44  		MockServletContext servletContext = getServletContext();
45  		MockHttpServletRequest request = servletContext
46  				.createRequest(CubbyUtils.getInternalForwardPath(
47  						MockAction.class, ""));
48  		ActionDef actionDef = actionDefBuilder.build(request);
49  		assertNull(actionDef);
50  	}
51  
52  	public void testFromPathToActionDefReturnsNull3() {
53  		MockServletContext servletContext = getServletContext();
54  		MockHttpServletRequest request = servletContext
55  				.createRequest(CubbyUtils.getInternalForwardPath(
56  						MockAction.class, "none"));
57  		ActionDef actionDef = actionDefBuilder.build(request);
58  		assertNull(actionDef);
59  	}
60  
61  	public void testFromPathToActionDefReturnsNull4() {
62  		MockServletContext servletContext = getServletContext();
63  		MockHttpServletRequest request = servletContext
64  				.createRequest(CubbyUtils.getInternalForwardPath(
65  						NoDeployedAction.class, "none"));
66  		ActionDef actionDef = actionDefBuilder.build(request);
67  		assertNull(actionDef);
68  	}
69  
70  	public void testFromPathToActionDef() {
71  		MockServletContext servletContext = getServletContext();
72  		MockHttpServletRequest request = servletContext
73  				.createRequest(CubbyUtils.getInternalForwardPath(
74  						MockAction.class, "update"));
75  		ActionDef actionDef = actionDefBuilder.build(request);
76  		assertNotNull(actionDef);
77  		assertEquals(MockAction.class, actionDef.getComponentDef()
78  				.getComponentClass());
79  		assertEquals("update", actionDef.getMethod().getName());
80  	}
81  
82  	private class NoDeployedAction extends Action {
83  		public ActionResult update() {
84  			return null;
85  		}
86  	}
87  }