1 package org.jacorb.test.notification.plugins; 2 3 import junit.framework.Test; 4 5 import org.jacorb.notification.filter.bsh.BSHFilter; 6 import org.jacorb.notification.impl.DefaultEvaluationContextFactory; 7 import org.jacorb.notification.impl.DefaultMessageFactory; 8 import org.jacorb.test.notification.NotificationTestCase; 9 import org.jacorb.test.notification.NotificationTestCaseSetup; 10 import org.omg.CORBA.Any ; 11 import org.omg.CosNotification.EventType; 12 import org.omg.CosNotifyFilter.ConstraintExp; 13 import org.omg.CosNotifyFilter.InvalidConstraint; 14 15 18 19 public class BSHFilterTest extends NotificationTestCase 20 { 21 private BSHFilter objectUnderTest_; 22 23 private Any testData_; 24 25 27 public BSHFilterTest(String test, NotificationTestCaseSetup setup) 28 { 29 super(test, setup); 30 } 31 32 34 public void setUpTest() throws Exception 35 { 36 objectUnderTest_ = new BSHFilter(getConfiguration(), new DefaultEvaluationContextFactory( 37 getEvaluator()), new DefaultMessageFactory(getConfiguration()), getORB(), getPOA()); 38 39 objectUnderTest_.configure(getConfiguration()); 40 41 testData_ = getORB().create_any(); 42 43 testData_.insert_long(10); 44 } 45 46 private void attachFilter(String filterExpr) throws InvalidConstraint 47 { 48 ConstraintExp[] _constraintExp = new ConstraintExp[1]; 49 EventType[] _eventType = new EventType[1]; 50 _eventType[0] = new EventType("*", "*"); 51 52 _constraintExp[0] = new ConstraintExp(_eventType, filterExpr); 53 objectUnderTest_.add_constraints(_constraintExp); 54 } 55 56 59 public void testReturnTrue() throws Exception 60 { 61 String filterExpr = "return true"; 62 63 attachFilter(filterExpr); 64 65 assertTrue(objectUnderTest_.match(testData_)); 67 } 68 69 public void testSimpleMatch() throws Exception 70 { 71 attachFilter("event.extract_long() == 10"); 72 73 objectUnderTest_.match(testData_); 74 } 75 76 public void testReturnFalse() throws Exception 77 { 78 attachFilter("return false"); 79 80 assertFalse(objectUnderTest_.match(testData_)); 81 } 82 83 public static Test suite() throws Exception 84 { 85 return NotificationTestCase.suite(BSHFilterTest.class); 86 } 87 } | Popular Tags |