View Javadoc

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