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