1 21 22 package org.jacorb.test.notification; 23 24 import java.util.Date ; 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 ; 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 name, NotifyServerTestSetup setup) 50 { 51 super(name, setup); 52 } 53 54 public void setUpTest() throws Exception 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 74 { 75 sendEvent(1000, 500, false); 77 78 sendEvent(1000, 2000, true); 80 81 sendEvent(0, -1000, false); 83 } 84 85 public void testDisableStopTimeSupported() throws Exception 86 { 87 if (true) 88 { 89 return; 90 } 91 92 Any 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 101 { 102 structuredEvent_.header.variable_header = new Property[2]; 103 104 Date _time = new Date (System.currentTimeMillis() + startOffset); 105 106 Any _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 (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 (_receiver).start(); 128 new Thread (_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 146 { 147 return NotifyServerTestCase.suite(StopTimeIntegrationTest.class); 148 } 149 } 150 | Popular Tags |