View Javadoc

1   /*
2    * $Id: ContextUtilTest.java 454565 2006-10-10 00:02:56Z jmitchell $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.views.util;
19  
20  import junit.framework.TestCase;
21  
22  import org.apache.struts2.StrutsConstants;
23  import org.apache.struts2.config.Settings;
24  
25  import com.opensymphony.xwork2.util.ValueStack;
26  import com.opensymphony.xwork2.util.ValueStackFactory;
27  
28  /***
29   * Test case for ContextUtil
30   * 
31   */
32  public class ContextUtilTest extends TestCase {
33  
34      public void testAltSyntaxMethod1() throws Exception {
35          ValueStack stack = ValueStackFactory.getFactory().createValueStack();
36          stack.getContext().put("useAltSyntax", "true");
37          
38          Settings.reset();
39          Settings.set(StrutsConstants.STRUTS_TAG_ALTSYNTAX, "true");
40          
41          assertEquals(Settings.get(StrutsConstants.STRUTS_TAG_ALTSYNTAX), "true");
42          assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
43      }
44      
45      public void testAltSyntaxMethod2() throws Exception {
46          ValueStack stack = ValueStackFactory.getFactory().createValueStack();
47          stack.getContext().put("useAltSyntax", "false");
48          
49          Settings.reset();
50          Settings.set(StrutsConstants.STRUTS_TAG_ALTSYNTAX, "true");
51          
52          assertEquals(Settings.get(StrutsConstants.STRUTS_TAG_ALTSYNTAX), "true");
53          assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
54      }
55      
56      public void testAltSyntaxMethod3() throws Exception {
57          ValueStack stack = ValueStackFactory.getFactory().createValueStack();
58          stack.getContext().put("useAltSyntax", "true");
59          
60          Settings.reset();
61          Settings.set(StrutsConstants.STRUTS_TAG_ALTSYNTAX, "false");
62          
63          assertEquals(Settings.get(StrutsConstants.STRUTS_TAG_ALTSYNTAX), "false");
64          assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
65      }
66      
67      public void testAltSyntaxMethod4() throws Exception {
68          ValueStack stack = ValueStackFactory.getFactory().createValueStack();
69          stack.getContext().put("useAltSyntax", "false");
70          
71          Settings.reset();
72          Settings.set(StrutsConstants.STRUTS_TAG_ALTSYNTAX, "false");
73          
74          assertEquals(Settings.get(StrutsConstants.STRUTS_TAG_ALTSYNTAX), "false");
75          assertFalse(ContextUtil.isUseAltSyntax(stack.getContext()));
76      }
77      
78      //========================================================
79      
80      public void testAltSyntaxMethod5() throws Exception {
81          ValueStack stack = ValueStackFactory.getFactory().createValueStack();
82          stack.getContext().put("useAltSyntax", Boolean.TRUE);
83          
84          Settings.reset();
85          Settings.set(StrutsConstants.STRUTS_TAG_ALTSYNTAX, "true");
86          
87          assertEquals(Settings.get(StrutsConstants.STRUTS_TAG_ALTSYNTAX), "true");
88          assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
89      }
90      public void testAltSyntaxMethod6() throws Exception {
91          ValueStack stack = ValueStackFactory.getFactory().createValueStack();
92          stack.getContext().put("useAltSyntax", Boolean.FALSE);
93          
94          Settings.reset();
95          Settings.set(StrutsConstants.STRUTS_TAG_ALTSYNTAX, "true");
96          
97          assertEquals(Settings.get(StrutsConstants.STRUTS_TAG_ALTSYNTAX), "true");
98          assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
99      }
100     public void testAltSyntaxMethod7() throws Exception {
101         ValueStack stack = ValueStackFactory.getFactory().createValueStack();
102         stack.getContext().put("useAltSyntax", Boolean.TRUE);
103         
104         Settings.reset();
105         Settings.set(StrutsConstants.STRUTS_TAG_ALTSYNTAX, "false");
106         
107         assertEquals(Settings.get(StrutsConstants.STRUTS_TAG_ALTSYNTAX), "false");
108         assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
109     }
110     public void testAltSyntaxMethod8() throws Exception {
111         ValueStack stack = ValueStackFactory.getFactory().createValueStack();
112         stack.getContext().put("useAltSyntax", Boolean.FALSE);
113         
114         Settings.reset();
115         Settings.set(StrutsConstants.STRUTS_TAG_ALTSYNTAX, "false");
116         
117         assertEquals(Settings.get(StrutsConstants.STRUTS_TAG_ALTSYNTAX), "false");
118         assertFalse(ContextUtil.isUseAltSyntax(stack.getContext()));
119     }
120     
121     // ==========================================
122     public void testAltSyntaxMethod9() throws Exception {
123         ValueStack stack = ValueStackFactory.getFactory().createValueStack();
124         stack.getContext().put("useAltSyntax", null);
125         
126         Settings.reset();
127         Settings.set(StrutsConstants.STRUTS_TAG_ALTSYNTAX, "true");
128         
129         assertEquals(Settings.get(StrutsConstants.STRUTS_TAG_ALTSYNTAX), "true");
130         assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
131     }
132 }