KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > NotificationEventTest


1 package org.jacorb.test.notification;
2
3 import junit.framework.Test;
4
5 import org.jacorb.notification.filter.EvaluationContext;
6 import org.jacorb.notification.filter.EvaluationResult;
7 import org.jacorb.notification.filter.etcl.AbstractTCLNode;
8 import org.jacorb.notification.filter.etcl.ETCLComponentName;
9 import org.jacorb.notification.filter.etcl.TCLCleanUp;
10 import org.jacorb.notification.filter.etcl.TCLParser;
11 import org.jacorb.notification.impl.DefaultMessageFactory;
12 import org.jacorb.notification.interfaces.Message;
13 import org.omg.CORBA.Any JavaDoc;
14 import org.omg.CosNotification.StructuredEvent;
15
16 /**
17  * @author Alphonse Bendt
18  */

19 public class NotificationEventTest extends NotificationTestCase {
20
21     DefaultMessageFactory factory_;
22     Any JavaDoc testPerson_;
23     Any JavaDoc testUnion_;
24
25     StructuredEvent testStructured_;
26     EvaluationContext evaluationContext_;
27     NotificationTestUtils testUtils_;
28
29     public void setUpTest() throws Exception JavaDoc {
30         testUtils_ = new NotificationTestUtils(getORB());
31         
32         evaluationContext_ = new EvaluationContext(getEvaluator());
33
34         factory_ = new DefaultMessageFactory(getConfiguration());
35        
36         testPerson_ = testUtils_.getTestPersonAny();
37
38         TestUnion _t1 = new TestUnion();
39         _t1.default_person(testUtils_.getTestPerson());
40         testUnion_ = getORB().create_any();
41         TestUnionHelper.insert(testUnion_, _t1);
42
43         testStructured_ = testUtils_.getStructuredEvent();
44     }
45
46
47     public void testGetType() throws Exception JavaDoc {
48         Message _event = factory_.newMessage(testPerson_);
49
50         assertTrue(_event.getType() == Message.TYPE_ANY);
51     }
52
53     public void testEvaluate_Any() throws Exception JavaDoc {
54         String JavaDoc _expr = "$.first_name";
55         AbstractTCLNode _root = TCLParser.parse(_expr);
56
57         _root.acceptPreOrder(new TCLCleanUp());
58
59         Message _event = factory_.newMessage(testPerson_);
60
61         EvaluationResult _result =
62             _event.extractValue(evaluationContext_,
63                             (ETCLComponentName) _root);
64
65         assertEquals("firstname", _result.getString());
66     }
67
68     public void testEvaluate_Structured() throws Exception JavaDoc {
69         String JavaDoc _expr = "$.header.fixed_header.event_type.domain_name";
70         Message _event = factory_.newMessage(testStructured_);
71         AbstractTCLNode _root = TCLParser.parse(_expr);
72
73         _root.acceptPreOrder(new TCLCleanUp());
74
75         EvaluationResult _result =
76             _event.extractValue(evaluationContext_,
77                                 (ETCLComponentName) _root);
78
79         assertEquals("TESTING", _result.getString());
80     }
81
82     public void testToStructuredEvent() throws Exception JavaDoc {
83         Message _event = factory_.newMessage(testPerson_);
84         StructuredEvent _structuredEvent = _event.toStructuredEvent();
85
86         assertEquals("", _structuredEvent.header.fixed_header.event_type.domain_name);
87         assertEquals("%ANY", _structuredEvent.header.fixed_header.event_type.type_name);
88
89         Person _p = PersonHelper.extract(_structuredEvent.remainder_of_body);
90         assertEquals("firstname", _p.first_name);
91         assertEquals("lastname", _p.last_name);
92     }
93
94
95     public NotificationEventTest(String JavaDoc name, NotificationTestCaseSetup setup){
96         super(name, setup);
97     }
98
99
100     public static Test suite() throws Exception JavaDoc {
101         return NotificationTestCase.suite(NotificationEventTest.class);
102     }
103 }
104
Popular Tags