1 package org.drools.semantics.java; 2 3 import org.drools.rule.Declaration; 4 import org.drools.spi.MockTuple; 5 import org.drools.spi.ExtractionException; 6 7 import bsh.EvalError; 8 9 import junit.framework.TestCase; 10 11 public class ExprExtractorTest extends TestCase 12 { 13 public ExprExtractorTest(String name) 14 { 15 super( name ); 16 } 17 18 public void setUp() 19 { 20 } 21 22 public void tearDown() 23 { 24 } 25 26 public void testExtractFact_NoText() 27 { 28 ExprExtractor extractor = new ExprExtractor(); 29 30 MockTuple tuple = new MockTuple(); 31 32 try 33 { 34 extractor.extractFact( tuple ); 35 } 36 catch (ExtractionException e) 37 { 38 // expected and correct 39 NullPointerException npe = (NullPointerException) e.getRootCause(); 40 } 41 } 42 43 public void testExtractFact_MissingObject() 44 { 45 ExprExtractor extractor = new ExprExtractor(); 46 extractor.setExpression( "a.length()" ); 47 48 MockTuple tuple = new MockTuple(); 49 50 try 51 { 52 extractor.extractFact( tuple ); 53 } 54 catch (ExtractionException e) 55 { 56 // expected and correct 57 EvalError ee = (EvalError) e.getRootCause(); 58 } 59 } 60 61 public void testExtractFact_Valid() throws Exception 62 { 63 ExprExtractor extractor = new ExprExtractor(); 64 extractor.setExpression( "a.length()" ); 65 66 MockTuple tuple = new MockTuple(); 67 68 String value = "I like cheese"; 69 70 tuple.put( new Declaration( new ClassObjectType( java.lang.String.class ), 71 "a" ), 72 value ); 73 74 Object extractedValue = extractor.extractFact( tuple ); 75 76 assertEquals( new Integer(value.length()), 77 extractedValue ); 78 } 79 } 80

This page was automatically generated by Maven