001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork.views.util;
006:
007: import com.opensymphony.webwork.config.Configuration;
008: import com.opensymphony.webwork.WebWorkConstants;
009: import com.opensymphony.xwork.util.OgnlValueStack;
010: import junit.framework.TestCase;
011:
012: /**
013: * Test case for ContextUtil
014: *
015: * @author tm_jee
016: * @version $Date: 2005-12-06 02:10:41 +0100 (Tue, 06 Dec 2005) $ $Id: ContextUtilTest.java 1608 2005-12-06 01:10:41Z digi9ten $
017: */
018: public class ContextUtilTest extends TestCase {
019:
020: public void testAltSyntaxMethod1() throws Exception {
021: OgnlValueStack stack = new OgnlValueStack();
022: stack.getContext().put("useAltSyntax", "true");
023:
024: Configuration.reset();
025: Configuration.set(WebWorkConstants.WEBWORK_TAG_ALTSYNTAX,
026: "true");
027:
028: assertEquals(Configuration
029: .getString(WebWorkConstants.WEBWORK_TAG_ALTSYNTAX),
030: "true");
031: assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
032: }
033:
034: public void testAltSyntaxMethod2() throws Exception {
035: OgnlValueStack stack = new OgnlValueStack();
036: stack.getContext().put("useAltSyntax", "false");
037:
038: Configuration.reset();
039: Configuration.set(WebWorkConstants.WEBWORK_TAG_ALTSYNTAX,
040: "true");
041:
042: assertEquals(Configuration
043: .getString(WebWorkConstants.WEBWORK_TAG_ALTSYNTAX),
044: "true");
045: assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
046: }
047:
048: public void testAltSyntaxMethod3() throws Exception {
049: OgnlValueStack stack = new OgnlValueStack();
050: stack.getContext().put("useAltSyntax", "true");
051:
052: Configuration.reset();
053: Configuration.set(WebWorkConstants.WEBWORK_TAG_ALTSYNTAX,
054: "false");
055:
056: assertEquals(Configuration
057: .getString(WebWorkConstants.WEBWORK_TAG_ALTSYNTAX),
058: "false");
059: assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
060: }
061:
062: public void testAltSyntaxMethod4() throws Exception {
063: OgnlValueStack stack = new OgnlValueStack();
064: stack.getContext().put("useAltSyntax", "false");
065:
066: Configuration.reset();
067: Configuration.set(WebWorkConstants.WEBWORK_TAG_ALTSYNTAX,
068: "false");
069:
070: assertEquals(Configuration
071: .getString(WebWorkConstants.WEBWORK_TAG_ALTSYNTAX),
072: "false");
073: assertFalse(ContextUtil.isUseAltSyntax(stack.getContext()));
074: }
075:
076: //========================================================
077:
078: public void testAltSyntaxMethod5() throws Exception {
079: OgnlValueStack stack = new OgnlValueStack();
080: stack.getContext().put("useAltSyntax", Boolean.TRUE);
081:
082: Configuration.reset();
083: Configuration.set(WebWorkConstants.WEBWORK_TAG_ALTSYNTAX,
084: "true");
085:
086: assertEquals(Configuration
087: .getString(WebWorkConstants.WEBWORK_TAG_ALTSYNTAX),
088: "true");
089: assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
090: }
091:
092: public void testAltSyntaxMethod6() throws Exception {
093: OgnlValueStack stack = new OgnlValueStack();
094: stack.getContext().put("useAltSyntax", Boolean.FALSE);
095:
096: Configuration.reset();
097: Configuration.set(WebWorkConstants.WEBWORK_TAG_ALTSYNTAX,
098: "true");
099:
100: assertEquals(Configuration
101: .getString(WebWorkConstants.WEBWORK_TAG_ALTSYNTAX),
102: "true");
103: assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
104: }
105:
106: public void testAltSyntaxMethod7() throws Exception {
107: OgnlValueStack stack = new OgnlValueStack();
108: stack.getContext().put("useAltSyntax", Boolean.TRUE);
109:
110: Configuration.reset();
111: Configuration.set(WebWorkConstants.WEBWORK_TAG_ALTSYNTAX,
112: "false");
113:
114: assertEquals(Configuration
115: .getString(WebWorkConstants.WEBWORK_TAG_ALTSYNTAX),
116: "false");
117: assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
118: }
119:
120: public void testAltSyntaxMethod8() throws Exception {
121: OgnlValueStack stack = new OgnlValueStack();
122: stack.getContext().put("useAltSyntax", Boolean.FALSE);
123:
124: Configuration.reset();
125: Configuration.set(WebWorkConstants.WEBWORK_TAG_ALTSYNTAX,
126: "false");
127:
128: assertEquals(Configuration
129: .getString(WebWorkConstants.WEBWORK_TAG_ALTSYNTAX),
130: "false");
131: assertFalse(ContextUtil.isUseAltSyntax(stack.getContext()));
132: }
133:
134: // ==========================================
135: public void testAltSyntaxMethod9() throws Exception {
136: OgnlValueStack stack = new OgnlValueStack();
137: stack.getContext().put("useAltSyntax", null);
138:
139: Configuration.reset();
140: Configuration.set(WebWorkConstants.WEBWORK_TAG_ALTSYNTAX,
141: Boolean.TRUE);
142:
143: assertEquals(Configuration
144: .get(WebWorkConstants.WEBWORK_TAG_ALTSYNTAX),
145: Boolean.TRUE);
146: assertTrue(ContextUtil.isUseAltSyntax(stack.getContext()));
147: }
148: }
|