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

This page was automatically generated by Maven