1
2 package org.drools.reteoo.impl;
3
4 import org.drools.AssertionException;
5 import org.drools.rule.Declaration;
6 import org.drools.spi.Condition;
7 import org.drools.spi.TrueCondition;
8 import org.drools.spi.FalseCondition;
9 import org.drools.semantics.java.ClassObjectType;
10
11 import junit.framework.TestCase;
12
13 import java.util.List;
14 import java.util.Set;
15
16 public class ConditionNodeImplTest extends TestCase
17 {
18 private ReteTuple tuple;
19
20 public ConditionNodeImplTest(String name)
21 {
22 super( name );
23 }
24
25 public void setUp()
26 {
27 this.tuple = new ReteTuple();
28 }
29
30 public void tearDown()
31 {
32 }
33
34 /*** If a condition allows an incoming Object, then
35 * the Object MUST be propagated.
36 */
37 public void testAllowed()
38 {
39 ConditionNodeImpl node = new ConditionNodeImpl( null,
40 new TrueCondition() );
41
42
43 InstrumentedTupleSink sink = new InstrumentedTupleSink();
44
45 node.setTupleSink( sink );
46
47 try
48 {
49 node.assertTuple( this.tuple,
50 null );
51
52 List asserted = sink.getAssertedTuples();
53
54 assertEquals( 1,
55 asserted.size() );
56
57 ReteTuple tuple = (ReteTuple) asserted.get( 0 );
58
59 assertSame( this.tuple,
60 tuple );
61 }
62 catch (AssertionException e)
63 {
64 fail( e.toString() );
65 }
66 }
67
68 /*** If a Condition does not allow an incoming Object,
69 * then the object MUST NOT be propagated.
70 */
71 public void testNotAllowed()
72 {
73 ConditionNodeImpl node = new ConditionNodeImpl( null,
74 new FalseCondition() );
75
76 InstrumentedTupleSink sink = new InstrumentedTupleSink();
77
78 node.setTupleSink( sink );
79
80 try
81 {
82 node.assertTuple( this.tuple,
83 null );
84
85 List asserted = sink.getAssertedTuples();
86
87 assertEquals( 0,
88 asserted.size() );
89 }
90 catch (AssertionException e)
91 {
92 fail( e.toString() );
93 }
94 }
95
96 /*** A FilterNode MUST delegate to its input source
97 * for getTupleDeclarations() since it does not alter
98 * the structure of the Tuples.
99 */
100 public void testGetTupleDeclarations()
101 {
102 Declaration decl = new Declaration( new ClassObjectType( String.class ),
103 "object" );
104
105 ParameterNodeImpl paramNode = new ParameterNodeImpl( null,
106 decl );
107
108 ConditionNodeImpl condNode = new ConditionNodeImpl( paramNode,
109 null );
110
111 Set decls = condNode.getTupleDeclarations();
112
113 assertEquals( 1,
114 decls.size() );
115
116 assertTrue( decls.contains( decl ) );
117 }
118 }
This page was automatically generated by Maven