1 package org.jacorb.test.notification.typed; 2 3 22 23 import junit.framework.Test; 24 25 import org.easymock.MockControl; 26 import org.jacorb.notification.OfferManager; 27 import org.jacorb.notification.SubscriptionManager; 28 import org.jacorb.notification.TypedEventMessage; 29 import org.jacorb.notification.servant.ITypedAdmin; 30 import org.jacorb.notification.servant.TypedProxyPullSupplierImpl; 31 import org.jacorb.test.notification.NotificationTestCase; 32 import org.jacorb.test.notification.NotificationTestCaseSetup; 33 import org.omg.CORBA.IntHolder ; 34 import org.omg.CORBA.StringHolder ; 35 import org.omg.CosNotification.EventType; 36 import org.omg.CosNotification.Property; 37 import org.omg.CosNotifyChannelAdmin.ConsumerAdmin; 38 import org.omg.CosNotifyChannelAdmin.ConsumerAdminPOATie; 39 import org.omg.CosNotifyComm.InvalidEventType; 40 import org.omg.CosNotifyComm.PullConsumerPOA; 41 import org.omg.CosTypedNotifyChannelAdmin.TypedProxyPullSupplier; 42 import org.omg.CosTypedNotifyChannelAdmin.TypedProxyPullSupplierHelper; 43 44 import EDU.oswego.cs.dl.util.concurrent.Latch; 45 46 50 public class TypedProxyPullSupplierImplTest extends NotificationTestCase 51 { 52 private TypedProxyPullSupplierImpl objectUnderTest_; 53 54 private TypedProxyPullSupplier proxyPullSupplier_; 55 56 private static String DRINKING_COFFEE_ID = "::org::jacorb::test::notification::typed::Coffee::drinking_coffee"; 57 58 private MockControl controlAdmin_; 59 60 private ITypedAdmin mockAdmin_; 61 62 private ConsumerAdmin mockConsumerAdmin_; 63 64 private MockControl controlConsumerAdmin_; 65 66 public void setUpTest() throws Exception 67 { 68 controlAdmin_ = MockControl.createNiceControl(ITypedAdmin.class); 69 mockAdmin_ = (ITypedAdmin) controlAdmin_.getMock(); 70 mockAdmin_.getProxyID(); 71 controlAdmin_.setReturnValue(10); 72 73 mockAdmin_.isIDPublic(); 74 controlAdmin_.setReturnValue(true); 75 76 mockAdmin_.getContainer(); 77 controlAdmin_.setReturnValue(getPicoContainer()); 78 79 mockAdmin_.getSupportedInterface(); 80 controlAdmin_.setReturnValue(PullCoffeeHelper.id()); 81 82 controlAdmin_.replay(); 83 84 controlConsumerAdmin_ = MockControl.createControl(ConsumerAdmin.class); 85 mockConsumerAdmin_ = (ConsumerAdmin) controlConsumerAdmin_.getMock(); 86 87 objectUnderTest_ = new TypedProxyPullSupplierImpl(mockAdmin_, new ConsumerAdminPOATie( 88 mockConsumerAdmin_)._this(getORB()), getORB(), getPOA(), getConfiguration(), 89 getTaskProcessor(), new OfferManager(), new SubscriptionManager(), 90 getDynAnyFactory(), getRepository()); 91 92 proxyPullSupplier_ = TypedProxyPullSupplierHelper.narrow(objectUnderTest_.activate()); 93 } 94 95 public TypedProxyPullSupplierImplTest(String name, NotificationTestCaseSetup setup) 96 { 97 super(name, setup); 98 } 99 100 public void testID() 101 { 102 assertEquals(new Integer (10), objectUnderTest_.getID()); 103 assertTrue(objectUnderTest_.isIDPublic()); 104 } 105 106 public void testMyAdmin() 107 { 108 mockConsumerAdmin_.remove_all_filters(); 109 110 controlConsumerAdmin_.replay(); 111 proxyPullSupplier_.MyAdmin().remove_all_filters(); 112 113 controlConsumerAdmin_.verify(); 114 } 115 116 public void testConnect() throws Exception 117 { 118 NullPullConsumer _pullConsumer = new NullPullConsumer(); 119 120 proxyPullSupplier_.connect_typed_pull_consumer(_pullConsumer._this(getClientORB())); 121 } 122 123 public void testEmptyPull() throws Exception 124 { 125 NullPullConsumer _pullConsumer = new NullPullConsumer(); 126 127 proxyPullSupplier_.connect_typed_pull_consumer(_pullConsumer._this(getClientORB())); 128 129 org.omg.CORBA.Object _object = proxyPullSupplier_.get_typed_supplier(); 130 131 String _objectAsString = _object.toString(); 132 133 PullCoffee _pullCoffee = PullCoffeeHelper.narrow(getClientORB().string_to_object( 134 _objectAsString)); 135 136 StringHolder _name = new StringHolder (); 137 IntHolder _minutes = new IntHolder (); 138 139 assertFalse(_pullCoffee.try_drinking_coffee(_name, _minutes)); 140 } 141 142 public void testTryPullDrinkingCoffee() throws Exception 143 { 144 TypedEventMessage _mesg = new TypedEventMessage(); 145 146 _mesg.setTypedEvent(PullCoffeeHelper.id(), DRINKING_COFFEE_ID, new Property[] { 147 new Property("name", toAny("jacorb")), new Property("minutes", toAny(10)) }); 148 149 NullPullConsumer _pullConsumer = new NullPullConsumer(); 150 151 proxyPullSupplier_.connect_typed_pull_consumer(_pullConsumer._this(getClientORB())); 152 153 org.omg.CORBA.Object _object = proxyPullSupplier_.get_typed_supplier(); 154 155 String _objectAsString = _object.toString(); 156 157 PullCoffee _pullCoffee = PullCoffeeHelper.narrow(getClientORB().string_to_object( 158 _objectAsString)); 159 160 StringHolder _name = new StringHolder (); 161 IntHolder _minutes = new IntHolder (); 162 163 objectUnderTest_.getMessageConsumer().deliverMessage(_mesg.getHandle()); 164 165 assertTrue(_pullCoffee.try_drinking_coffee(_name, _minutes)); 166 167 assertEquals("jacorb", _name.value); 168 assertEquals(10, _minutes.value); 169 } 170 171 public void testPullDrinkingCoffee() throws Exception 172 { 173 TypedEventMessage _mesg = new TypedEventMessage(); 174 175 _mesg.setTypedEvent(PullCoffeeHelper.id(), DRINKING_COFFEE_ID, new Property[] { 176 new Property("name", toAny("jacorb")), new Property("minutes", toAny(10)) }); 177 178 NullPullConsumer _pullConsumer = new NullPullConsumer(); 179 180 proxyPullSupplier_.connect_typed_pull_consumer(_pullConsumer._this(getClientORB())); 181 182 org.omg.CORBA.Object _object = proxyPullSupplier_.get_typed_supplier(); 183 184 String _objectAsString = _object.toString(); 185 186 final PullCoffee _pullCoffee = PullCoffeeHelper.narrow(getClientORB().string_to_object( 187 _objectAsString)); 188 189 final StringHolder _name = new StringHolder (); 190 final IntHolder _minutes = new IntHolder (); 191 192 final Latch _latch = new Latch(); 193 194 new Thread () 195 { 196 public void run() 197 { 198 _pullCoffee.drinking_coffee(_name, _minutes); 199 _latch.release(); 200 } 201 }.start(); 202 203 objectUnderTest_.getMessageConsumer().deliverMessage(_mesg.getHandle()); 204 205 assertTrue(_latch.attempt(1000)); 206 207 assertEquals("jacorb", _name.value); 208 assertEquals(10, _minutes.value); 209 } 210 211 public static Test suite() throws Exception 212 { 213 return NotificationTestCase.suite(TypedProxyPullSupplierImplTest.class); 214 } 215 } 216 217 class NullPullConsumer extends PullConsumerPOA 218 { 219 public void offer_change(EventType[] eventTypeArray, EventType[] eventTypeArray1) 220 throws InvalidEventType 221 { 222 } 224 225 public void disconnect_pull_consumer() 226 { 227 } 229 } | Popular Tags |