    1   /*
    2    * Copyright 2006 The Apache Software Foundation.
    3    *
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  package org.apache.commons.scxml.env.jexl;
    17
    18  import java.util.HashMap;
    19  import java.util.Map;
    20
    21  import junit.framework.Test;
    22  import junit.framework.TestCase;
    23  import junit.framework.TestSuite;
    24
    25  import org.apache.commons.scxml.Builtin;
    26
    27  public class JexlContextTest extends TestCase {
    28
    29      public JexlContextTest(String testName) {
    30          super(testName);
    31      }
    32
    33      public static Test suite() {
    34          return new TestSuite(JexlContextTest.class);
    35      }
    36
    37      public static void main(String args[]) {
    38          String[] testCaseName = {JexlContextTest.class.getName()};
    39          junit.textui.TestRunner.main(testCaseName);
    40      }
    41
    42      public void testNew() {
    43          JexlContext ctx = new JexlContext();
    44          assertNotNull(ctx);
    45          assertEquals(1, ctx.getVars().size());
    46          assertTrue(ctx.get("_builtin") instanceof Builtin);
    47      }
    48
    49      public void testPrepopulated() {
    50          Map m = new HashMap();
    51          m.put("foo", "bar");
    52          JexlContext ctx = new JexlContext(m);
    53          assertNotNull(ctx);
    54          assertEquals(2, ctx.getVars().size());
    55          assertTrue(ctx.get("_builtin") instanceof Builtin);
    56          String fooValue = (String) ctx.get("foo");
    57          assertEquals("bar", fooValue);
    58      }
    59
    60      public void testSetVars() {
    61          JexlContext ctx = new JexlContext();
    62          assertNotNull(ctx);
    63          assertEquals(1, ctx.getVars().size());
    64          assertTrue(ctx.get("_builtin") instanceof Builtin);
    65          Map m = new HashMap();
    66          m.put("foo", "bar");
    67          ctx.setVars(m);
    68          assertEquals(2, ctx.getVars().size());
    69          String fooValue = (String) ctx.get("foo");
    70          assertTrue(ctx.get("_builtin") instanceof Builtin);
    71          assertEquals("bar", fooValue);
    72      }
    73
    74  }