1 package org.jacorb.test.notification; 2 3 import java.util.Date ; 4 5 import junit.framework.Test; 6 7 import org.jacorb.notification.impl.DefaultMessageFactory; 8 import org.jacorb.notification.interfaces.FilterStage; 9 import org.jacorb.notification.interfaces.Message; 10 import org.jacorb.notification.servant.AbstractProxyConsumerI; 11 import org.jacorb.util.Time; 12 import org.omg.CORBA.Any ; 13 import org.omg.CosNotification.EventHeader; 14 import org.omg.CosNotification.EventType; 15 import org.omg.CosNotification.FixedEventHeader; 16 import org.omg.CosNotification.Property; 17 import org.omg.CosNotification.StopTime; 18 import org.omg.CosNotification.StructuredEvent; 19 import org.omg.CosNotification.StructuredEventHelper; 20 import org.omg.TimeBase.UtcT; 21 import org.omg.TimeBase.UtcTHelper; 22 23 26 27 public class MessageFactoryTest extends NotificationTestCase 28 { 29 DefaultMessageFactory messageFactory_; 30 31 NotificationTestUtils testUtils_; 32 33 Any testPerson_; 34 35 StructuredEvent testStructured_; 36 37 39 public void testStructuredEventWithStopTimeProperty() throws Exception 40 { 41 testStructured_.header.variable_header = new Property[1]; 42 43 Date _now = new Date (); 44 45 Any _any = getORB().create_any(); 46 UtcT _utc = Time.corbaTime(_now); 47 UtcTHelper.insert(_any, _utc); 48 49 testStructured_.header.variable_header[0] = new Property(StopTime.value, _any); 50 51 Message _event = messageFactory_.newMessage(testStructured_); 52 assertTrue(_event.hasStopTime()); 53 assertEquals(_now.getTime(), _event.getStopTime()); 54 } 55 56 57 public void testStructuredEventWithoutStopTimeProperty() throws Exception 58 { 59 Message _event = messageFactory_.newMessage(testStructured_); 60 assertTrue(!_event.hasStopTime()); 61 } 62 63 public void testAnyEventHasNoStopTime() throws Exception 64 { 65 Message _event = messageFactory_.newMessage(getORB().create_any()); 66 assertTrue(!_event.hasStopTime()); 67 } 68 69 public void testNewEventStructured() throws Exception 70 { 71 assertNotNull(messageFactory_.newMessage(testStructured_)); 72 } 73 74 public void testStructuredToAny() throws Exception 75 { 76 Message _notifyEvent = messageFactory_.newMessage(testStructured_); 77 assertNotNull(_notifyEvent); 78 Any _any = _notifyEvent.toAny(); 79 StructuredEvent _event = StructuredEventHelper.extract(_any); 80 assertNotNull(_event); 81 assertEquals("domain", _event.header.fixed_header.event_type.domain_name); 82 assertEquals("type", _event.header.fixed_header.event_type.type_name); 83 } 84 85 public void testStructuredToStructured() throws Exception 86 { 87 Message _notifyEvent = messageFactory_.newMessage(testStructured_); 88 assertNotNull(_notifyEvent); 89 StructuredEvent _event = _notifyEvent.toStructuredEvent(); 90 assertNotNull(_event); 91 assertEquals("domain", _event.header.fixed_header.event_type.domain_name); 92 assertEquals("type", _event.header.fixed_header.event_type.type_name); 93 } 94 95 public void testNewEventAny() throws Exception 96 { 97 Message _notifyEvent = messageFactory_.newMessage(testPerson_); 98 99 assertNotNull(_notifyEvent); 100 } 101 102 public void testAnyToStructured() throws Exception 103 { 104 Message _notifyEvent = messageFactory_.newMessage(testPerson_); 105 StructuredEvent _structured = _notifyEvent.toStructuredEvent(); 106 assertNotNull(_structured); 107 assertEquals("%ANY", _structured.header.fixed_header.event_type.type_name); 108 assertEquals("", _structured.header.fixed_header.event_type.domain_name); 109 assertEquals("", _structured.header.fixed_header.event_name); 110 111 Person _p = PersonHelper.extract(_structured.remainder_of_body); 112 assertNotNull(_p); 113 assertEquals("firstname", _p.first_name); 114 assertEquals("lastname", _p.last_name); 115 } 116 117 public void testAnyToAny() throws Exception 118 { 119 Message _notifyEvent = messageFactory_.newMessage(testPerson_); 120 Any _anyEvent = _notifyEvent.toAny(); 121 assertNotNull(_anyEvent); 122 123 Person _p = PersonHelper.extract(_anyEvent); 124 assertNotNull(_p); 125 assertEquals("firstname", _p.first_name); 126 assertEquals("lastname", _p.last_name); 127 } 128 129 public void testWrappedStructuredEventToStructuredEvent() throws Exception 130 { 131 Any _wrappedStructuredEvent = getORB().create_any(); 132 133 StructuredEventHelper.insert(_wrappedStructuredEvent, testStructured_); 134 135 Message _mesg = messageFactory_.newMessage(_wrappedStructuredEvent, 136 new AbstractProxyConsumerI() 137 { 138 public boolean isStartTimeSupported() 139 { 140 return false; 141 } 142 143 public boolean isTimeOutSupported() 144 { 145 return false; 146 } 147 148 public FilterStage getFirstStage() 149 { 150 return null; 151 } 152 }); 153 154 StructuredEvent _recvd = _mesg.toStructuredEvent(); 155 156 assertEquals(testStructured_.header.fixed_header.event_name, 157 _recvd.header.fixed_header.event_name); 158 159 assertEquals(testStructured_.remainder_of_body, _recvd.remainder_of_body); 160 assertEquals(testStructured_.remainder_of_body, _recvd.remainder_of_body); 161 } 162 163 public void testWrappedAnyToAny() throws Exception 164 { 165 StructuredEvent _wrappedAny = new StructuredEvent(); 166 167 EventHeader _header = new EventHeader(); 168 FixedEventHeader _fixed = new FixedEventHeader(); 169 _fixed.event_name = ""; 170 _fixed.event_type = new EventType("", "%ANY"); 171 _header.fixed_header = _fixed; 172 _header.variable_header = new Property[0]; 173 174 _wrappedAny.header = _header; 175 176 _wrappedAny.filterable_data = new Property[0]; 177 178 _wrappedAny.remainder_of_body = testPerson_; 179 180 Message _mesg = messageFactory_.newMessage(_wrappedAny, new AbstractProxyConsumerI() 181 { 182 public boolean isStartTimeSupported() 183 { 184 return false; 185 } 186 187 public boolean isTimeOutSupported() 188 { 189 return false; 190 } 191 192 public FilterStage getFirstStage() 193 { 194 return null; 195 } 196 }); 197 198 assertEquals(testPerson_, _mesg.toAny()); 199 } 200 201 public void setUpTest() throws Exception 202 { 203 testUtils_ = new NotificationTestUtils(getORB()); 204 205 messageFactory_ = new DefaultMessageFactory(getConfiguration()); 206 207 testPerson_ = testUtils_.getTestPersonAny(); 208 209 testStructured_ = new StructuredEvent(); 210 EventHeader _header = new EventHeader(); 211 FixedEventHeader _fixed = new FixedEventHeader(); 212 _fixed.event_name = "eventname"; 213 _fixed.event_type = new EventType("domain", "type"); 214 _header.fixed_header = _fixed; 215 _header.variable_header = new Property[0]; 216 217 testStructured_.header = _header; 218 219 testStructured_.filterable_data = new Property[0]; 220 221 testStructured_.remainder_of_body = getORB().create_any(); 222 } 223 224 public MessageFactoryTest(String test, NotificationTestCaseSetup setup) 225 { 226 super(test, setup); 227 } 228 229 public static Test suite() throws Exception 230 { 231 return NotificationTestCase.suite(MessageFactoryTest.class); 232 } 233 } 234 | Popular Tags |