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.ExtractionException; 8 9 import org.python.core.PyException; 10 11 import junit.framework.TestCase; 12 13 public class ExprExtractorTest extends TestCase 14 { 15 public ExprExtractorTest(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 testExtractFact_NoText() 29 { 30 ExprExtractor extractor = new ExprExtractor(); 31 32 MockTuple tuple = new MockTuple(); 33 34 try 35 { 36 extractor.extractFact( tuple ); 37 } 38 catch (ExtractionException e) 39 { 40 // expected and correct 41 PyException pe = (PyException) e.getRootCause(); 42 } 43 } 44 45 public void testExtractFact_MissingObject() 46 { 47 ExprExtractor extractor = new ExprExtractor(); 48 extractor.setExpression( "len(a)" ); 49 50 MockTuple tuple = new MockTuple(); 51 52 try 53 { 54 extractor.extractFact( tuple ); 55 } 56 catch (ExtractionException e) 57 { 58 // expected and correct 59 PyException pe = (PyException) e.getRootCause(); 60 } 61 } 62 63 public void testExtractFact_Valid() throws Exception 64 { 65 ExprExtractor extractor = new ExprExtractor(); 66 extractor.setExpression( "len(a)" ); 67 68 MockTuple tuple = new MockTuple(); 69 70 String value = "I like cheese"; 71 72 tuple.put( new Declaration( new ClassObjectType( java.lang.String.class ), 73 "a" ), 74 value ); 75 76 Object extractedValue = extractor.extractFact( tuple ); 77 78 assertEquals( new Integer(value.length()), 79 extractedValue ); 80 } 81 } 82

This page was automatically generated by Maven