1 package org.jacorb.test.notification.typed; 2 3 22 23 import junit.framework.Test; 24 25 import org.easymock.AbstractMatcher; 26 import org.easymock.MockControl; 27 import org.jacorb.notification.OfferManager; 28 import org.jacorb.notification.SubscriptionManager; 29 import org.jacorb.notification.engine.TaskProcessor; 30 import org.jacorb.notification.interfaces.Message; 31 import org.jacorb.notification.servant.ITypedAdmin; 32 import org.jacorb.notification.servant.TypedProxyPullConsumerImpl; 33 import org.jacorb.test.notification.NotificationTestCase; 34 import org.jacorb.test.notification.NotificationTestCaseSetup; 35 import org.omg.CORBA.IntHolder ; 36 import org.omg.CORBA.StringHolder ; 37 import org.omg.CORBA.TRANSIENT ; 38 import org.omg.CosNotification.EventType; 39 import org.omg.CosNotification.EventTypeHelper; 40 import org.omg.CosNotification.Property; 41 import org.omg.CosNotifyChannelAdmin.ProxyType; 42 import org.omg.CosNotifyChannelAdmin.SupplierAdmin; 43 import org.omg.CosTypedNotifyChannelAdmin.TypedProxyPullConsumer; 44 import org.omg.CosTypedNotifyChannelAdmin.TypedProxyPullConsumerHelper; 45 import org.omg.CosTypedNotifyComm.TypedPullSupplier; 46 import org.omg.CosTypedNotifyComm.TypedPullSupplierHelper; 47 import org.omg.CosTypedNotifyComm.TypedPullSupplierPOATie; 48 49 53 public class TypedProxyPullConsumerImplTest extends NotificationTestCase 54 { 55 private TypedProxyPullConsumerImpl objectUnderTest_; 56 57 private TypedProxyPullConsumer proxyPullConsumer_; 58 59 private MockControl controlTypedPullSupplier_; 60 61 private TypedPullSupplier mockTypedPullSupplier_; 62 63 private MockControl controlAdmin_; 64 65 private ITypedAdmin mockAdmin_; 66 67 private MockControl controlSupplierAdmin_; 68 69 private SupplierAdmin mockSupplierAdmin_; 70 71 private MockControl controlTaskProcessor_; 72 73 private TaskProcessor mockTaskProcessor_; 74 75 public void setUpTest() throws Exception 76 { 77 controlAdmin_ = MockControl.createNiceControl(ITypedAdmin.class); 78 mockAdmin_ = (ITypedAdmin) controlAdmin_.getMock(); 79 mockAdmin_.getProxyID(); 80 controlAdmin_.setReturnValue(10); 81 82 mockAdmin_.isIDPublic(); 83 controlAdmin_.setReturnValue(true); 84 85 mockAdmin_.getContainer(); 86 controlAdmin_.setReturnValue(getPicoContainer()); 87 88 mockAdmin_.getSupportedInterface(); 89 controlAdmin_.setDefaultReturnValue(PullCoffeeHelper.id()); 90 91 controlAdmin_.replay(); 92 93 controlSupplierAdmin_ = MockControl.createControl(SupplierAdmin.class); 94 mockSupplierAdmin_ = (SupplierAdmin) controlSupplierAdmin_.getMock(); 95 96 controlSupplierAdmin_.replay(); 97 98 controlTaskProcessor_ = MockControl.createControl(TaskProcessor.class); 99 mockTaskProcessor_ = (TaskProcessor) controlTaskProcessor_.getMock(); 100 101 objectUnderTest_ = new TypedProxyPullConsumerImpl(mockAdmin_, mockSupplierAdmin_, getORB(), 102 getPOA(), getConfiguration(), mockTaskProcessor_, getMessageFactory(), 103 new OfferManager(), new SubscriptionManager()); 104 105 String string = getORB().object_to_string( 106 TypedProxyPullConsumerHelper.narrow(objectUnderTest_.activate())); 107 proxyPullConsumer_ = TypedProxyPullConsumerHelper.narrow(getClientORB().string_to_object( 108 string)); 109 110 controlTypedPullSupplier_ = MockControl.createControl(TypedPullSupplier.class); 111 mockTypedPullSupplier_ = (TypedPullSupplier) controlTypedPullSupplier_.getMock(); 112 } 113 114 public TypedProxyPullConsumerImplTest(String name, NotificationTestCaseSetup setup) 115 { 116 super(name, setup); 117 } 118 119 public void testId() 120 { 121 assertTrue(objectUnderTest_.isIDPublic()); 122 assertEquals(new Integer (10), objectUnderTest_.getID()); 123 } 124 125 public void testMyType() 126 { 127 assertEquals(ProxyType.PULL_TYPED, proxyPullConsumer_.MyType()); 128 } 129 130 public void testConnect() throws Exception 131 { 132 MockControl controlPullCoffeeOperations = 133 MockControl.createControl(PullCoffeeOperations.class); 134 135 PullCoffeeOperations mockPullCoffee = 136 (PullCoffeeOperations) controlPullCoffeeOperations.getMock(); 137 138 PullCoffee pullCoffee = 139 PullCoffeeHelper.narrow(new PullCoffeePOATie(mockPullCoffee)._this(getClientORB())); 140 141 controlPullCoffeeOperations.replay(); 142 143 mockTypedPullSupplier_.get_typed_supplier(); 144 controlTypedPullSupplier_.setReturnValue(pullCoffee); 145 146 controlTypedPullSupplier_.replay(); 147 148 proxyPullConsumer_.connect_typed_pull_supplier(TypedPullSupplierHelper 149 .narrow(new TypedPullSupplierPOATie(mockTypedPullSupplier_)._this(getClientORB()))); 150 151 controlTypedPullSupplier_.verify(); 152 controlPullCoffeeOperations.verify(); 153 } 154 155 public void testTryOperationsAreInvoked() throws Exception 156 { 157 MockControl controlPullCoffeeOperations = 158 MockControl.createControl(PullCoffeeOperations.class); 159 PullCoffeeOperations mockPullCoffeeOperations = 160 (PullCoffeeOperations) controlPullCoffeeOperations.getMock(); 161 162 controlPullCoffeeOperations.setDefaultMatcher(new AbstractMatcher() 163 { 164 public boolean matches(Object [] arg0, Object [] arg1) 165 { 166 StringHolder name = (StringHolder ) arg0[0]; 167 168 if (name != null) 169 { 170 name.value = ""; 171 } 172 173 return true; 174 } 175 }); 176 177 mockPullCoffeeOperations.try_drinking_coffee(null, null); 178 179 controlPullCoffeeOperations.setReturnValue(false); 180 181 mockPullCoffeeOperations.try_cancel_coffee(null); 182 183 controlPullCoffeeOperations.setReturnValue(false); 184 185 controlPullCoffeeOperations.replay(); 186 187 mockTypedPullSupplier_.get_typed_supplier(); 188 controlTypedPullSupplier_.setReturnValue(new PullCoffeePOATie(mockPullCoffeeOperations)._this(getClientORB())); 189 190 controlTypedPullSupplier_.replay(); 191 192 proxyPullConsumer_.connect_typed_pull_supplier(new TypedPullSupplierPOATie(mockTypedPullSupplier_)._this(getClientORB())); 193 194 objectUnderTest_.runPullMessage(); 195 196 controlPullCoffeeOperations.verify(); 197 controlTypedPullSupplier_.verify(); 198 } 199 200 public void testTryOperationsThrowsException() throws Exception 201 { 202 MockControl controlPullCoffeeOperations = MockControl.createControl(PullCoffeeOperations.class); 203 PullCoffeeOperations mockPullCoffeeOperations = 204 (PullCoffeeOperations) controlPullCoffeeOperations.getMock(); 205 206 mockPullCoffeeOperations.try_drinking_coffee(null, null); 207 controlPullCoffeeOperations.setMatcher(MockControl.ALWAYS_MATCHER); 208 controlPullCoffeeOperations.setThrowable(new TRANSIENT ()); 209 210 mockPullCoffeeOperations.try_cancel_coffee(null); 211 controlPullCoffeeOperations.setMatcher(new AbstractMatcher() 212 { 213 public boolean matches(Object [] arg0, Object [] arg1) 214 { 215 StringHolder name = (StringHolder ) arg0[0]; 216 217 if (name != null) 218 { 219 name.value = "jacorb"; 220 } 221 222 return true; 223 } 224 }); 225 controlPullCoffeeOperations.setReturnValue(true); 226 227 controlPullCoffeeOperations.replay(); 228 229 mockTypedPullSupplier_.get_typed_supplier(); 230 controlTypedPullSupplier_.setReturnValue(new PullCoffeePOATie(mockPullCoffeeOperations)._this(getClientORB())); 231 232 controlTypedPullSupplier_.replay(); 233 234 proxyPullConsumer_.connect_typed_pull_supplier(new TypedPullSupplierPOATie(mockTypedPullSupplier_)._this(getClientORB())); 235 236 objectUnderTest_.runPullMessage(); 237 238 controlPullCoffeeOperations.verify(); 239 controlTypedPullSupplier_.verify(); 240 } 241 242 public void testFormat() throws Exception 243 { 244 mockTaskProcessor_.processMessage(null); 245 246 controlTaskProcessor_.setMatcher(new AbstractMatcher() 247 { 248 public boolean matches(Object [] expected, Object [] actual) 249 { 250 if (expected[0] != null) 251 { 252 try 253 { 254 Property[] _props = ((Message) expected[0]).toTypedEvent(); 255 256 assertEquals(3, _props.length); 257 258 assertEquals("event_type", _props[0].name); 259 EventType et = EventTypeHelper.extract(_props[0].value); 260 assertEquals(PullCoffeeHelper.id(), et.domain_name); 261 262 assertEquals( 263 "::org::jacorb::test::notification::typed::PullCoffee::drinking_coffee", 264 et.type_name); 265 266 assertEquals("jacorb", _props[1].value.extract_string()); 267 assertEquals(20, _props[2].value.extract_long()); 268 269 return true; 270 } catch (Exception e) 271 { 272 return false; 273 } 274 } 275 return true; 276 } 277 }); 278 279 MockControl controlPullCoffeeOperations = 280 MockControl.createControl(PullCoffeeOperations.class); 281 PullCoffeeOperations mockPullCoffeeOperations = 282 (PullCoffeeOperations) controlPullCoffeeOperations.getMock(); 283 284 mockPullCoffeeOperations.try_drinking_coffee(null, null); 285 controlPullCoffeeOperations.setMatcher(new AbstractMatcher() 286 { 287 public boolean matches(Object [] expected, Object [] actual) 288 { 289 StringHolder name = (StringHolder ) expected[0]; 290 IntHolder minutes = (IntHolder ) expected[1]; 291 292 if (name != null) 293 { 294 name.value = "jacorb"; 295 } 296 297 if (minutes != null) 298 { 299 minutes.value = 20; 300 } 301 302 return true; 303 } 304 }); 305 controlPullCoffeeOperations.setReturnValue(true); 306 307 mockPullCoffeeOperations.try_cancel_coffee(null); 308 controlPullCoffeeOperations.setMatcher(new AbstractMatcher() 309 { 310 public boolean matches(Object [] expected, Object [] actual) 311 { 312 StringHolder name = (StringHolder ) expected[0]; 313 314 if (name != null) 315 { 316 name.value = ""; 317 } 318 319 return true; 320 } 321 }); 322 controlPullCoffeeOperations.setReturnValue(false); 323 324 controlPullCoffeeOperations.replay(); 325 326 mockTypedPullSupplier_.get_typed_supplier(); 327 controlTypedPullSupplier_.setReturnValue(new PullCoffeePOATie(mockPullCoffeeOperations)._this(getClientORB())); 328 329 controlTypedPullSupplier_.replay(); 330 331 controlTaskProcessor_.replay(); 332 333 proxyPullConsumer_.connect_typed_pull_supplier(new TypedPullSupplierPOATie(mockTypedPullSupplier_)._this(getClientORB())); 334 335 objectUnderTest_.runPullMessage(); 336 337 controlPullCoffeeOperations.verify(); 338 controlTypedPullSupplier_.verify(); 339 } 340 341 public static Test suite() throws Exception 342 { 343 return NotificationTestCase.suite(TypedProxyPullConsumerImplTest.class); 344 } 345 } | Popular Tags |