1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.codebehind;
22
23 import java.util.HashMap;
24
25 import javax.servlet.ServletContext;
26
27 import org.apache.struts2.StrutsTestCase;
28 import org.apache.struts2.config.NullResult;
29 import org.apache.struts2.dispatcher.ServletDispatcherResult;
30
31 import com.mockobjects.dynamic.Mock;
32 import com.opensymphony.xwork2.ActionContext;
33 import com.opensymphony.xwork2.ActionInvocation;
34 import com.opensymphony.xwork2.ObjectFactory;
35 import com.opensymphony.xwork2.Result;
36 import com.opensymphony.xwork2.config.entities.ResultTypeConfig;
37
38 public class CodebehindUnknownHandlerTest extends StrutsTestCase {
39
40 CodebehindUnknownHandler handler;
41 Mock mockServletContext;
42
43 public void setUp() throws Exception {
44 super.setUp();
45 mockServletContext = new Mock(ServletContext.class);
46 handler = new CodebehindUnknownHandler("codebehind-default", configuration);
47 handler.setPathPrefix("/");
48 handler.setObjectFactory(container.getInstance(ObjectFactory.class));
49 handler.setServletContext((ServletContext)mockServletContext.proxy());
50 }
51
52 public void testBuildResult() {
53 ActionContext ctx = new ActionContext(new HashMap());
54 ResultTypeConfig config = new ResultTypeConfig("null", SomeResult.class.getName(), "location");
55
56 Result result = handler.buildResult("/foo.jsp", "success", config, ctx);
57 assertNotNull(result);
58 assertTrue(result instanceof SomeResult);
59 assertEquals("/foo.jsp", ((SomeResult) result).location);
60
61 }
62
63 public void testString() {
64 assertEquals("foo.bar.jim", handler.string("foo", ".", "bar", ".", "jim"));
65 }
66
67 public void testDeterminePath() {
68 assertEquals("/", handler.determinePath("/", ""));
69 assertEquals("/", handler.determinePath("/", null));
70 assertEquals("/", handler.determinePath("/", "/"));
71 assertEquals("/foo/", handler.determinePath("/", "/foo"));
72 assertEquals("/foo/", handler.determinePath("/", "/foo/"));
73 assertEquals("/foo/", handler.determinePath("/", "foo"));
74 }
75
76 public static class SomeResult implements Result {
77
78 public String location;
79 public void setLocation(String loc) {
80 this.location = loc;
81 }
82
83 public void execute(ActionInvocation invocation) throws Exception {
84 }
85
86 }
87
88 }