KickJava   Java API By Example, From Geeks To Geeks.

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


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

21
22 package org.jacorb.test.notification;
23
24 import java.util.Date JavaDoc;
25
26 import junit.framework.Test;
27
28 import org.jacorb.test.notification.common.NotifyServerTestCase;
29 import org.jacorb.test.notification.common.NotifyServerTestSetup;
30 import org.jacorb.util.Time;
31 import org.omg.CORBA.Any JavaDoc;
32 import org.omg.CosNotification.EventHeader;
33 import org.omg.CosNotification.EventType;
34 import org.omg.CosNotification.FixedEventHeader;
35 import org.omg.CosNotification.Property;
36 import org.omg.CosNotification.StartTime;
37 import org.omg.CosNotification.StopTime;
38 import org.omg.CosNotification.StopTimeSupported;
39 import org.omg.CosNotification.StructuredEvent;
40 import org.omg.CosNotifyChannelAdmin.EventChannel;
41 import org.omg.TimeBase.UtcTHelper;
42
43 public class StopTimeIntegrationTest extends NotifyServerTestCase
44 {
45     EventChannel eventChannel_;
46     
47     StructuredEvent structuredEvent_;
48     
49     public StopTimeIntegrationTest(String JavaDoc name, NotifyServerTestSetup setup)
50     {
51         super(name, setup);
52     }
53     
54     public void setUpTest() throws Exception JavaDoc
55     {
56         eventChannel_ = getDefaultChannel();
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 = getClientORB().create_any();
71     }
72
73     public void testA_SendEvent() throws Exception JavaDoc
74     {
75         // StartTime +1000ms, StopTime +500ms
76
sendEvent(1000, 500, false);
77
78         // StartTime +1000ms, StopTime +2000ms
79
sendEvent(1000, 2000, true);
80
81         // StartTime now, StopTime in the Past
82
sendEvent(0, -1000, false);
83     }
84
85     public void testDisableStopTimeSupported() throws Exception JavaDoc
86     {
87         if (true)
88         {
89             return;
90         }
91
92         Any JavaDoc falseAny = getClientORB().create_any();
93         falseAny.insert_boolean(false);
94
95         eventChannel_.set_qos(new Property[] { new Property(StopTimeSupported.value, falseAny) });
96
97         sendEvent(0, 1000, false);
98     }
99
100     public void sendEvent(long startOffset, long stopOffset, boolean expect) throws Exception JavaDoc
101     {
102         structuredEvent_.header.variable_header = new Property[2];
103
104         Date JavaDoc _time = new Date JavaDoc(System.currentTimeMillis() + startOffset);
105
106         Any JavaDoc _any = getClientORB().create_any();
107         UtcTHelper.insert(_any, Time.corbaTime(_time));
108
109         structuredEvent_.header.variable_header[0] = new Property(StartTime.value, _any);
110
111         _time = new Date JavaDoc(System.currentTimeMillis() + stopOffset);
112
113         _any = getClientORB().create_any();
114         UtcTHelper.insert(_any, Time.corbaTime(_time));
115
116         structuredEvent_.header.variable_header[1] = new Property(StopTime.value, _any);
117
118         StructuredPushSender _sender = new StructuredPushSender(getClientORB());
119         _sender.setStructuredEvent(new StructuredEvent[] {structuredEvent_});
120         
121         StructuredPushReceiver _receiver = new StructuredPushReceiver(getClientORB());
122
123         _sender.connect(eventChannel_, false);
124
125         _receiver.connect(eventChannel_, false);
126
127         new Thread JavaDoc(_receiver).start();
128         new Thread JavaDoc(_sender).start();
129
130         Thread.sleep(startOffset + 1000);
131
132         if (expect)
133         {
134             assertTrue("Receiver should have received something", _receiver.isEventHandled());
135         }
136         else
137         {
138             assertTrue("Receiver shouldn't have received anything", !_receiver.isEventHandled());
139         }
140
141         _receiver.shutdown();
142         _sender.shutdown();
143     }
144
145     public static Test suite() throws Exception JavaDoc
146     {
147         return NotifyServerTestCase.suite(StopTimeIntegrationTest.class);
148     }
149 }
150
Popular Tags