1 21 22 package org.jacorb.test.notification.servant; 23 24 import junit.framework.Test; 25 26 import org.easymock.MockControl; 27 import org.jacorb.notification.OfferManager; 28 import org.jacorb.notification.SubscriptionManager; 29 import org.jacorb.notification.engine.DefaultPushTaskExecutorFactory; 30 import org.jacorb.notification.engine.TaskExecutor; 31 import org.jacorb.notification.engine.TaskProcessor; 32 import org.jacorb.notification.interfaces.Message; 33 import org.jacorb.notification.servant.IAdmin; 34 import org.jacorb.notification.servant.StructuredProxyPushSupplierImpl; 35 import org.jacorb.test.notification.NotificationTestCase; 36 import org.jacorb.test.notification.NotificationTestCaseSetup; 37 import org.omg.CORBA.TRANSIENT ; 38 import org.omg.CosNotification.StructuredEvent; 39 import org.omg.CosNotifyComm.StructuredPushConsumer; 40 41 45 public class StructuredProxyPushSupplierImplTest extends NotificationTestCase 46 { 47 private StructuredProxyPushSupplierImpl objectUnderTest_; 48 49 private MockControl controlTaskExecutor_; 50 51 private MockControl controlTaskProcessor_; 52 53 private TaskProcessor mockTaskProcessor_; 54 55 58 protected void setUpTest() throws Exception 59 { 60 MockControl controlAdmin = MockControl.createControl(IAdmin.class); 61 IAdmin mockAdmin = (IAdmin) controlAdmin.getMock(); 62 63 mockAdmin.isIDPublic(); 64 controlAdmin.setReturnValue(true); 65 66 mockAdmin.getProxyID(); 67 controlAdmin.setReturnValue(10); 68 69 mockAdmin.getContainer(); 70 controlAdmin.setReturnValue(null); 71 72 controlAdmin.replay(); 73 74 controlTaskProcessor_ = MockControl.createControl(TaskProcessor.class); 75 mockTaskProcessor_ = (TaskProcessor) controlTaskProcessor_.getMock(); 76 controlTaskExecutor_ = MockControl.createControl(TaskExecutor.class); 77 objectUnderTest_ = new StructuredProxyPushSupplierImpl(mockAdmin, getORB(), getPOA(), 78 getConfiguration(), mockTaskProcessor_, new DefaultPushTaskExecutorFactory(1), new OfferManager(), 79 new SubscriptionManager(), null); 80 81 assertEquals(new Integer (10), objectUnderTest_.getID()); 82 } 83 84 89 public StructuredProxyPushSupplierImplTest(String name, NotificationTestCaseSetup setup) 90 { 91 super(name, setup); 92 } 93 94 public void testDeliveryToNotConnectedDoesNotAccessMessage() 95 { 96 MockControl controlMessage = MockControl.createStrictControl(Message.class); 97 Message mockMessage = (Message) controlMessage.getMock(); 98 99 controlMessage.replay(); 100 101 controlTaskExecutor_.replay(); 102 103 controlTaskProcessor_.replay(); 104 105 objectUnderTest_.deliverMessage(mockMessage); 106 107 controlMessage.verify(); 108 109 controlTaskExecutor_.verify(); 110 111 controlTaskProcessor_.verify(); 112 } 113 114 public void testDeliveryToDisabledConsumerEnqueues() throws Exception 115 { 116 MockControl controlMessage = MockControl.createStrictControl(Message.class); 117 Message mockMessage = (Message) controlMessage.getMock(); 118 119 mockMessage.clone(); 120 controlMessage.setReturnValue(mockMessage); 121 122 controlMessage.replay(); 123 124 controlTaskExecutor_.replay(); 125 126 controlTaskProcessor_.replay(); 127 128 MockControl controlStructuredPushConsumer = MockControl 129 .createControl(StructuredPushConsumer.class); 130 StructuredPushConsumer mockStructuredPushConsumer = (StructuredPushConsumer) controlStructuredPushConsumer 131 .getMock(); 132 133 objectUnderTest_.connect_structured_push_consumer(mockStructuredPushConsumer); 134 135 objectUnderTest_.disableDelivery(); 136 137 objectUnderTest_.deliverMessage(mockMessage); 138 139 controlMessage.verify(); 140 141 controlTaskExecutor_.verify(); 142 143 controlTaskProcessor_.verify(); 144 } 145 146 public void testDeliveryToConsumerDoesEnqueueAndDisposeMessage() throws Exception 147 { 148 StructuredEvent event = new StructuredEvent(); 149 150 MockControl controlMessage = MockControl.createStrictControl(Message.class); 151 Message mockMessage = (Message) controlMessage.getMock(); 152 153 mockMessage.clone(); 154 controlMessage.setReturnValue(mockMessage); 155 156 mockMessage.toStructuredEvent(); 157 controlMessage.setReturnValue(event); 158 159 mockMessage.dispose(); 160 161 controlMessage.replay(); 162 163 controlTaskExecutor_.replay(); 164 165 MockControl controlStructuredPushConsumer = MockControl 166 .createControl(StructuredPushConsumer.class); 167 StructuredPushConsumer mockStructuredPushConsumer = (StructuredPushConsumer) controlStructuredPushConsumer 168 .getMock(); 169 170 mockStructuredPushConsumer.push_structured_event(event); 171 172 controlStructuredPushConsumer.replay(); 173 174 objectUnderTest_.connect_structured_push_consumer(mockStructuredPushConsumer); 175 176 objectUnderTest_.deliverMessage(mockMessage); 177 178 objectUnderTest_.pushPendingData(); 179 180 controlMessage.verify(); 181 182 controlTaskExecutor_.verify(); 183 } 184 185 public void testFailedDeliveryToConsumerDoesNotDisposeMessage() throws Exception 186 { 187 StructuredEvent event = new StructuredEvent(); 188 189 MockControl controlMessage = MockControl.createControl(Message.class); 190 Message mockMessage = (Message) controlMessage.getMock(); 191 192 mockMessage.clone(); 193 controlMessage.setReturnValue(mockMessage, 2); 194 195 mockMessage.toStructuredEvent(); 196 controlMessage.setReturnValue(event); 197 198 mockMessage.dispose(); 199 200 controlMessage.replay(); 201 202 controlTaskExecutor_.replay(); 203 204 mockTaskProcessor_.executeTaskAfterDelay(0, null); 205 controlTaskProcessor_.setMatcher(MockControl.ALWAYS_MATCHER); 206 controlTaskProcessor_.setReturnValue(null); 207 208 controlTaskProcessor_.replay(); 209 210 MockControl controlStructuredPushConsumer = MockControl 211 .createControl(StructuredPushConsumer.class); 212 StructuredPushConsumer mockStructuredPushConsumer = (StructuredPushConsumer) controlStructuredPushConsumer 213 .getMock(); 214 215 mockStructuredPushConsumer.push_structured_event(event); 216 controlStructuredPushConsumer.setThrowable(new TRANSIENT ()); 217 218 controlStructuredPushConsumer.replay(); 219 220 objectUnderTest_.connect_structured_push_consumer(mockStructuredPushConsumer); 221 222 objectUnderTest_.deliverMessage(mockMessage); 223 224 objectUnderTest_.pushPendingData(); 225 226 controlMessage.verify(); 227 228 controlTaskExecutor_.verify(); 229 230 controlTaskProcessor_.verify(); 231 } 232 233 public static Test suite() throws Exception 234 { 235 return NotificationTestCase.suite(StructuredProxyPushSupplierImplTest.class); 236 } 237 } | Popular Tags |