KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jacorb.test.notification;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1999-2003 Gerald Brose
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  */

23
24 import junit.framework.Test;
25
26 import org.jacorb.notification.impl.DefaultMessageFactory;
27 import org.jacorb.notification.interfaces.FilterStage;
28 import org.jacorb.notification.interfaces.Message;
29 import org.jacorb.notification.servant.AbstractProxyConsumerI;
30 import org.omg.CORBA.Any JavaDoc;
31 import org.omg.CosNotification.EventHeader;
32 import org.omg.CosNotification.EventType;
33 import org.omg.CosNotification.FixedEventHeader;
34 import org.omg.CosNotification.Property;
35 import org.omg.CosNotification.StructuredEvent;
36 import org.omg.CosNotification.Timeout;
37 import org.omg.TimeBase.TimeTHelper;
38
39 /**
40  * @author Alphonse Bendt
41  */

42
43 public class TimeoutTest extends NotificationTestCase
44 {
45     DefaultMessageFactory messageFactory_;
46     StructuredEvent structuredEvent_;
47
48     public TimeoutTest (String JavaDoc name, NotificationTestCaseSetup setup)
49     {
50         super(name, setup);
51     }
52
53
54     public void setUpTest() throws Exception JavaDoc
55     {
56         messageFactory_ = new DefaultMessageFactory(getConfiguration());
57
58         structuredEvent_ = new StructuredEvent();
59         EventHeader _header = new EventHeader();
60         FixedEventHeader _fixed = new FixedEventHeader();
61         _fixed.event_name = "eventname";
62         _fixed.event_type = new EventType("domain", "type");
63         _header.fixed_header = _fixed;
64         _header.variable_header = new Property[0];
65
66         structuredEvent_.header = _header;
67
68         structuredEvent_.filterable_data = new Property[0];
69
70         structuredEvent_.remainder_of_body = getORB().create_any();
71     }
72
73     public void tearDownTest() throws Exception JavaDoc
74     {
75         messageFactory_.dispose();
76     }
77
78     public void testStructuredEventWithoutTimeoutProperty() throws Exception JavaDoc
79     {
80         Message _event = messageFactory_.newMessage(structuredEvent_);
81         assertTrue(!_event.hasTimeout());
82     }
83
84
85     public void testAnyEventHasNoStopTime() throws Exception JavaDoc
86     {
87         Message _event = messageFactory_.newMessage(getORB().create_any());
88
89         assertTrue(!_event.hasTimeout());
90     }
91
92
93     public void testStructuredEventWithTimeoutProperty() throws Exception JavaDoc
94     {
95         structuredEvent_.header.variable_header = new Property[1];
96
97         long _timeout = 1234L;
98
99         Any JavaDoc _any = getORB().create_any();
100
101         TimeTHelper.insert(_any, _timeout);
102
103         structuredEvent_.header.variable_header[0] = new Property(Timeout.value, _any);
104
105         Message _event = messageFactory_.newMessage(structuredEvent_,
106                                                     new AbstractProxyConsumerI() {
107                                                         public boolean isStartTimeSupported() {
108                                                             return true;
109                                                         }
110
111                                                         public boolean isTimeOutSupported() {
112                                                             return true;
113                                                         }
114
115                                                         public FilterStage getFirstStage() {
116                                                             return null;
117                                                         }
118                                                         });
119         assertTrue(_event.hasTimeout());
120         assertEquals(_timeout, _event.getTimeout());
121     }
122
123     public static Test suite() throws Exception JavaDoc
124     {
125         return NotificationTestCase.suite(TimeoutTest.class);
126     }
127 }
128
Popular Tags