1 package org.drools.semantics.java; 2 3 import org.drools.rule.Declaration; 4 import org.drools.spi.MockTuple; 5 import org.drools.spi.ConditionException; 6 7 import bsh.EvalError; 8 9 import junit.framework.TestCase; 10 11 public class ExprConditionTest extends TestCase 12 { 13 public ExprConditionTest(String name) 14 { 15 super( name ); 16 } 17 18 public void setUp() 19 { 20 } 21 22 public void tearDown() 23 { 24 } 25 26 public void testIsAllowed_NoText() 27 { 28 ExprCondition condition = new ExprCondition(); 29 30 MockTuple tuple = new MockTuple(); 31 32 try 33 { 34 condition.isAllowed( tuple ); 35 } 36 catch (ConditionException e) 37 { 38 // expected and correct 39 NullPointerException npe = (NullPointerException) e.getRootCause(); 40 } 41 } 42 43 public void testIsAllowed_MissingObject() 44 { 45 ExprCondition condition = new ExprCondition(); 46 47 condition.setExpression( "a" ); 48 49 MockTuple tuple = new MockTuple(); 50 51 try 52 { 53 condition.isAllowed( tuple ); 54 } 55 catch (ConditionException e) 56 { 57 // expected and correct 58 EvalError ee = (EvalError) e.getRootCause(); 59 } 60 } 61 62 public void testIsAllowed_ValidTrue() throws Exception 63 { 64 ExprCondition condition = new ExprCondition(); 65 66 condition.setExpression( "a" ); 67 68 MockTuple tuple = new MockTuple(); 69 70 tuple.put( new Declaration( new ClassObjectType( java.lang.Boolean.class ), 71 "a" ), 72 Boolean.TRUE ); 73 74 assertTrue( condition.isAllowed( tuple ) ); 75 } 76 77 public void testIsAllowed_ValidFalse() throws Exception 78 { 79 ExprCondition condition = new ExprCondition(); 80 81 condition.setExpression( "a" ); 82 83 MockTuple tuple = new MockTuple(); 84 85 tuple.put( new Declaration( new ClassObjectType( java.lang.Boolean.class ), 86 "a" ), 87 Boolean.FALSE ); 88 89 assertTrue( ! condition.isAllowed( tuple ) ); 90 } 91 } 92

This page was automatically generated by Maven