1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.views.util;
23
24 import junit.framework.TestCase;
25
26 import org.apache.struts2.StrutsConstants;
27 import org.apache.struts2.StrutsTestCase;
28
29 import com.mockobjects.dynamic.C;
30 import com.mockobjects.dynamic.Mock;
31 import com.opensymphony.xwork2.ActionContext;
32 import com.opensymphony.xwork2.inject.Container;
33 import com.opensymphony.xwork2.util.ValueStack;
34 import com.opensymphony.xwork2.util.ValueStackFactory;
35
36 /***
37 * Test case for ContextUtil
38 *
39 */
40 public class ContextUtilTest extends StrutsTestCase {
41
42 private void setAltSyntax(ValueStack stack, String val) {
43 Mock container = new Mock(Container.class);
44 container.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(StrutsConstants.STRUTS_TAG_ALTSYNTAX)), val);
45 stack.getContext().put(ActionContext.CONTAINER, container.proxy());
46 }
47
48 public void testAltSyntaxMethod1() throws Exception {
49 ValueStack stack = ActionContext.getContext().getValueStack();
50 stack.getContext().put("useAltSyntax", "true");
51
52 setAltSyntax(stack, "true");
53 assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
54 }
55
56 public void testAltSyntaxMethod2() throws Exception {
57 ValueStack stack = ActionContext.getContext().getValueStack();
58 stack.getContext().put("useAltSyntax", "false");
59
60 setAltSyntax(stack, "true");
61 assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
62 }
63
64 public void testAltSyntaxMethod3() throws Exception {
65 ValueStack stack = ActionContext.getContext().getValueStack();
66 stack.getContext().put("useAltSyntax", "true");
67
68 setAltSyntax(stack, "false");
69 assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
70 }
71
72 public void testAltSyntaxMethod4() throws Exception {
73 ValueStack stack = ActionContext.getContext().getValueStack();
74 stack.getContext().put("useAltSyntax", "false");
75
76 setAltSyntax(stack, "false");
77 assertFalse(ContextUtil.isUseAltSyntax(stack.getContext()));
78 }
79
80
81
82 public void testAltSyntaxMethod5() throws Exception {
83 ValueStack stack = ActionContext.getContext().getValueStack();
84 stack.getContext().put("useAltSyntax", Boolean.TRUE);
85
86 setAltSyntax(stack, "true");
87 assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
88 }
89 public void testAltSyntaxMethod6() throws Exception {
90 ValueStack stack = ActionContext.getContext().getValueStack();
91 stack.getContext().put("useAltSyntax", Boolean.FALSE);
92
93 setAltSyntax(stack, "true");
94 assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
95 }
96 public void testAltSyntaxMethod7() throws Exception {
97 ValueStack stack = ActionContext.getContext().getValueStack();
98 stack.getContext().put("useAltSyntax", Boolean.TRUE);
99
100 setAltSyntax(stack, "false");
101 assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
102 }
103 public void testAltSyntaxMethod8() throws Exception {
104 ValueStack stack = ActionContext.getContext().getValueStack();
105 stack.getContext().put("useAltSyntax", Boolean.FALSE);
106
107 setAltSyntax(stack, "false");
108 assertFalse(ContextUtil.isUseAltSyntax(stack.getContext()));
109 }
110
111
112 public void testAltSyntaxMethod9() throws Exception {
113 ValueStack stack = ActionContext.getContext().getValueStack();
114 stack.getContext().put("useAltSyntax", null);
115
116 setAltSyntax(stack, "true");
117 assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
118 }
119 }