1 package org.jacorb.test.notification; 2 3 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import junit.framework.Test; 28 29 import org.jacorb.notification.OfferManager; 30 import org.jacorb.notification.SubscriptionManager; 31 import org.jacorb.notification.interfaces.ApplicationEvent; 32 import org.jacorb.notification.interfaces.ProxyEvent; 33 import org.jacorb.notification.interfaces.ProxyEventListener; 34 import org.jacorb.notification.servant.ConsumerAdminImpl; 35 import org.jacorb.notification.servant.IEventChannel; 36 import org.jacorb.notification.util.QoSPropertySet; 37 import org.omg.CORBA.IntHolder ; 38 import org.omg.CosNotifyChannelAdmin.AdminLimitExceeded; 39 import org.omg.CosNotifyChannelAdmin.ClientType; 40 import org.omg.CosNotifyChannelAdmin.ConsumerAdminOperations; 41 import org.omg.CosNotifyChannelAdmin.EventChannel; 42 import org.omg.CosNotifyChannelAdmin.ProxySupplier; 43 import org.picocontainer.MutablePicoContainer; 44 45 import EDU.oswego.cs.dl.util.concurrent.SynchronizedInt; 46 47 51 52 public class AdminLimitTest extends NotificationTestCase 53 { 54 private ConsumerAdminImpl objectUnderTest_; 55 56 private ConsumerAdminOperations consumerAdmin_; 57 58 public void setUpTest() throws Exception 59 { 60 QoSPropertySet _qosSettings = new QoSPropertySet(getConfiguration(), 61 QoSPropertySet.ADMIN_QOS); 62 63 getPicoContainer().registerComponentImplementation(OfferManager.class); 64 getPicoContainer().registerComponentImplementation(SubscriptionManager.class); 65 66 IEventChannel channel = new IEventChannel() 67 { 68 public MutablePicoContainer getContainer() 69 { 70 return getPicoContainer(); 71 } 72 73 public EventChannel getEventChannel() 74 { 75 try 76 { 77 return getDefaultChannel(); 78 } catch (Exception e) 79 { 80 throw new RuntimeException (); 81 } 82 } 83 84 public int getAdminID() 85 { 86 return 20; 87 } 88 89 public int getChannelID() 90 { 91 return 10; 92 } 93 94 public void destroy() 95 { 96 } 98 }; 99 100 objectUnderTest_ = new ConsumerAdminImpl(channel, getORB(), getPOA(), 101 getConfiguration(), getMessageFactory(), (OfferManager) getPicoContainer() 102 .getComponentInstance(OfferManager.class), (SubscriptionManager) getPicoContainer() 103 .getComponentInstance(SubscriptionManager.class)); 104 105 objectUnderTest_.set_qos(_qosSettings.get_qos()); 106 107 consumerAdmin_ = objectUnderTest_; 108 } 109 110 public void testBasics() throws Exception 111 { 112 assertEquals(20, consumerAdmin_.MyID()); 113 114 assertEquals(getDefaultChannel(), consumerAdmin_.MyChannel()); 115 } 116 117 public void testObtainNotificationPullSupplierFiresEvent() throws Exception 118 { 119 IntHolder _proxyId = new IntHolder (); 120 121 final List _events = new ArrayList (); 122 123 ProxyEventListener _listener = new ProxyEventListener() 124 { 125 public void actionProxyCreationRequest(ProxyEvent event) throws AdminLimitExceeded 126 { 127 _events.add(event); 128 } 129 130 public void actionProxyCreated(ProxyEvent event) 131 { 132 } 134 135 public void actionProxyDisposed(ProxyEvent event) 136 { 137 } 139 }; 140 141 objectUnderTest_.addProxyEventListener(_listener); 142 143 ProxySupplier _proxySupplier = objectUnderTest_.obtain_notification_pull_supplier( 144 ClientType.STRUCTURED_EVENT, _proxyId); 145 146 assertNotNull(_proxySupplier); 147 148 assertEquals(1, _events.size()); 149 150 assertEquals(objectUnderTest_, ((ApplicationEvent) _events.get(0)).getSource()); 151 } 152 153 public void testDenyCreateNotificationPullSupplier() throws Exception 154 { 155 IntHolder _proxyId = new IntHolder (); 156 157 ProxyEventListener _listener = new ProxyEventListener() 158 { 159 public void actionProxyCreationRequest(ProxyEvent e) throws AdminLimitExceeded 160 { 161 throw new AdminLimitExceeded(); 162 } 163 164 public void actionProxyDisposed(ProxyEvent event) 165 { 166 } 168 169 public void actionProxyCreated(ProxyEvent event) 170 { 171 } 173 }; 174 175 objectUnderTest_.addProxyEventListener(_listener); 176 177 try 178 { 179 objectUnderTest_.obtain_notification_pull_supplier(ClientType.STRUCTURED_EVENT, 180 _proxyId); 181 182 fail(); 183 } catch (AdminLimitExceeded e) 184 { 185 } 187 } 188 189 public void testEvents() throws Exception 190 { 191 IntHolder _proxyId = new IntHolder (); 192 final SynchronizedInt _counter = new SynchronizedInt(0); 193 194 ProxyEventListener _listener = new ProxyEventListener() 195 { 196 public void actionProxyCreated(ProxyEvent event) 197 { 198 } 200 201 public void actionProxyDisposed(ProxyEvent event) 202 { 203 } 205 206 public void actionProxyCreationRequest(ProxyEvent event) throws AdminLimitExceeded 207 { 208 _counter.increment(); 209 } 210 }; 211 212 objectUnderTest_.addProxyEventListener(_listener); 213 214 ProxySupplier[] _seqProxySupplier = new ProxySupplier[3]; 215 216 _seqProxySupplier[0] = objectUnderTest_.obtain_notification_pull_supplier( 217 ClientType.STRUCTURED_EVENT, _proxyId); 218 assertEquals(_seqProxySupplier[0], objectUnderTest_.get_proxy_supplier(_proxyId.value)); 219 220 _seqProxySupplier[1] = objectUnderTest_.obtain_notification_pull_supplier( 221 ClientType.ANY_EVENT, _proxyId); 222 assertEquals(_seqProxySupplier[1], objectUnderTest_.get_proxy_supplier(_proxyId.value)); 223 224 _seqProxySupplier[2] = objectUnderTest_.obtain_notification_pull_supplier( 225 ClientType.SEQUENCE_EVENT, _proxyId); 226 assertEquals(_seqProxySupplier[2], objectUnderTest_.get_proxy_supplier(_proxyId.value)); 227 228 objectUnderTest_.obtain_pull_supplier(); 229 230 assertEquals(3, _counter.get()); 231 } 232 233 public AdminLimitTest(String name, NotificationTestCaseSetup setup) 234 { 235 super(name, setup); 236 } 237 238 public static Test suite() throws Exception 239 { 240 return NotificationTestCase.suite(AdminLimitTest.class); 241 } 242 } | Popular Tags |