Package modTransf.rules.core

Source Code of modTransf.rules.core.ScriptActionTest

package modTransf.rules.core;

import junit.framework.TestCase;
import java.io.IOException;

import java.util.Collection;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
import java.util.Arrays;
import javax.script.ScriptException;
import modTransf.engine.RuleContext;
import modTransf.engine.SimpleRuleContext;
import modTransf.engine.TransformationException;

/**
* Test case for SimpleRuleContext.
*/
public class ScriptActionTest extends TestCase
{
  /**
   * The context being tested.
   */
  protected RuleContext context;
  /**
   * The context being tested.
   */
  protected SimpleRuleContext contextImpl;


  public ScriptActionTest(String name)
  {
    super(name);
  }

  /**
   * Initialize the context for a new test.
   * This method is called befor each test
   * @throws IOException
   */
  public void setUp() throws IOException
  {
    // create context.
    contextImpl = new SimpleRuleContext();
    context = contextImpl;
  }

  /**
   * Tear down the test.
   * This method is called after each test.
   */
  public void tearDown()
  {
   context = null;
  }

  /**
   * Test as a guard returning true
   */
  public void testTrueGuard()
    throws ScriptException, TransformationException
  {
    ScriptAction script = new ScriptAction( "2<3", "rhino" );
    boolean res = script.isAllowed( null, context);
    assertTrue( "res is true", res );
  }

  /**
   * Test as a guard returning true
   */
  public void testFalseGuard()
    throws ScriptException, TransformationException
  {
    ScriptAction script = new ScriptAction( "2>3", "rhino" );
    boolean res = script.isAllowed( null, context);
    assertFalse( "res is false", res );
  }

  /**
   * Test as a guard returning true
   */
  public void testLiteralGuard()
    throws ScriptException, TransformationException
  {
    ScriptAction script = new ScriptAction( "true", "rhino" );
    boolean res = script.isAllowed( null, context);
    assertTrue( "res is true", res );
  }

  /**
   * Test as a guard returning true
   */
  public void testBadGuard()
    throws ScriptException, TransformationException
  {
    ScriptAction script = new ScriptAction( "3", "rhino" );
    try
    {
      boolean res = script.isAllowed(null, context);
      fail("should fail.");
    }
    catch(TransformationException ex)
    { // must fail with an exception
    }
  }


}
TOP

Related Classes of modTransf.rules.core.ScriptActionTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.