1 package org.drools.semantics.java;
2
3 import org.drools.WorkingMemory;
4 import org.drools.rule.Declaration;
5 import org.drools.spi.MockTuple;
6 import org.drools.spi.ConsequenceException;
7
8 import junit.framework.TestCase;
9
10 public class BlockConsequenceTest extends TestCase
11 {
12 private boolean poked;
13 private boolean prodded;
14
15 public BlockConsequenceTest(String name)
16 {
17 super( name );
18 }
19
20 public void setUp()
21 {
22 this.poked = false;
23 this.prodded = false;
24 }
25
26 public void tearDown()
27 {
28 this.poked = false;
29 this.prodded = false;
30 }
31
32 public void testInvoke_NoText()
33 {
34 BlockConsequence conseq = new BlockConsequence();
35
36 MockTuple tuple = new MockTuple();
37
38 try
39 {
40 conseq.invoke( tuple,
41 new TestWorkingMemory() );
42 }
43 catch (ConsequenceException e)
44 {
45 // expected and correct
46 NullPointerException npe = (NullPointerException) e.getRootCause();
47 }
48 }
49
50 public void testInvoke_Valid() throws Exception
51 {
52 BlockConsequence conseq = new BlockConsequence();
53
54 conseq.setText( "test.poke();test.prod(appData);" );
55
56 MockTuple tuple = new MockTuple();
57
58 tuple.put( new Declaration( new ClassObjectType( BlockConsequenceTest.class ),
59 "test" ),
60 this );
61
62 WorkingMemory memory = new TestWorkingMemory();
63 memory.setApplicationData( "This is app data" );
64
65 conseq.invoke( tuple,
66 memory );
67
68 assertTrue( this.poked );
69 assertTrue( this.prodded );
70
71 }
72
73 public void poke()
74 {
75 this.poked = true;
76 }
77
78 public void prod( String appData )
79 {
80 if ( appData.equals( "This is app data" ) )
81 {
82 this.prodded = true;
83 }
84 }
85
86 /*** Simple subclass so we can call the protected constructor */
87 private static class TestWorkingMemory extends WorkingMemory
88 {
89 public TestWorkingMemory()
90 {
91 super( null );
92 }
93 }
94 }
This page was automatically generated by Maven