KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > plugins > BSHFilterTest


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 JavaDoc;
11 import org.omg.CosNotification.EventType;
12 import org.omg.CosNotifyFilter.ConstraintExp;
13 import org.omg.CosNotifyFilter.InvalidConstraint;
14
15 /**
16  * @author Alphonse Bendt
17  */

18
19 public class BSHFilterTest extends NotificationTestCase
20 {
21     private BSHFilter objectUnderTest_;
22
23     private Any JavaDoc testData_;
24
25     ////////////////////////////////////////
26

27     public BSHFilterTest(String JavaDoc test, NotificationTestCaseSetup setup)
28     {
29         super(test, setup);
30     }
31
32     ////////////////////////////////////////
33

34     public void setUpTest() throws Exception JavaDoc
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 JavaDoc 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     /**
57      * create remote filter object and invoke match operation on it
58      */

59     public void testReturnTrue() throws Exception JavaDoc
60     {
61         String JavaDoc filterExpr = "return true";
62
63         attachFilter(filterExpr);
64
65         // this should match
66
assertTrue(objectUnderTest_.match(testData_));
67     }
68
69     public void testSimpleMatch() throws Exception JavaDoc
70     {
71         attachFilter("event.extract_long() == 10");
72
73         objectUnderTest_.match(testData_);
74     }
75
76     public void testReturnFalse() throws Exception JavaDoc
77     {
78         attachFilter("return false");
79
80         assertFalse(objectUnderTest_.match(testData_));
81     }
82
83     public static Test suite() throws Exception JavaDoc
84     {
85         return NotificationTestCase.suite(BSHFilterTest.class);
86     }
87 }
Popular Tags