1 package org.jacorb.test.notification; 2 3 22 23 import java.util.ArrayList ; 24 import java.util.List ; 25 26 import junit.framework.Test; 27 import junit.framework.TestCase; 28 import junit.framework.TestSuite; 29 30 import org.jacorb.notification.OfferManager; 31 import org.omg.CosNotification.EventType; 32 import org.omg.CosNotifyComm.NotifyPublishOperations; 33 34 37 38 public class OfferManagerTest extends TestCase { 39 40 public static final EventType[] EMPTY_EVENT_TYPE_ARRAY = new EventType[0]; 41 42 OfferManager offerManager_; 43 List added_; 44 List removed_; 45 NotifyPublishOperations listener_; 46 47 49 public OfferManagerTest (String name) { 50 super(name); 51 } 52 53 55 public void setUp() throws Exception { 56 offerManager_ = new OfferManager(); 57 58 added_ = new ArrayList (); 59 removed_ = new ArrayList (); 60 listener_ = new NotifyPublishOperations() { 61 public void offer_change(EventType[] added, EventType[] removed) { 62 for (int x=0; x<added.length; ++x) { 63 added_.add(added[x]); 64 } 65 66 for (int x=0; x<removed.length; ++x) { 67 removed_.add(removed[x]); 68 } 69 } 70 }; 71 } 72 73 76 public void _testRemoveNonExistent() throws Exception { 77 offerManager_.addListener(listener_); 78 79 offerManager_.offer_change(EMPTY_EVENT_TYPE_ARRAY, 80 new EventType[] { new EventType("domain1", "type1") }); 81 82 assertEquals(0, added_.size()); 83 assertEquals(1, removed_.size()); 84 assertEquals("domain1", ((EventType)removed_.get(0)).domain_name); 85 assertEquals("type1", ((EventType)removed_.get(0)).type_name); 86 } 87 88 89 public void testRemoveNotifies() throws Exception { 90 EventType[] _toBeAdded = new EventType[] {new EventType("domain1", "type1")}; 91 92 offerManager_.offer_change(_toBeAdded, EMPTY_EVENT_TYPE_ARRAY); 93 94 offerManager_.addListener(listener_); 95 96 offerManager_.offer_change(EMPTY_EVENT_TYPE_ARRAY, 97 new EventType[] { new EventType("domain1", "type1") }); 98 99 assertEquals(0, added_.size()); 100 assertEquals(1, removed_.size()); 101 assertEquals("domain1", ((EventType)removed_.get(0)).domain_name); 102 assertEquals("type1", ((EventType)removed_.get(0)).type_name); 103 104 offerManager_.offer_change(EMPTY_EVENT_TYPE_ARRAY, 106 new EventType[] { new EventType("domain1", "type1") }); 107 } 108 109 110 public void testAddNotifies() throws Exception { 111 EventType[] _toBeAdded = new EventType[] {new EventType("domain1", "type1")}; 112 113 offerManager_.offer_change(_toBeAdded, EMPTY_EVENT_TYPE_ARRAY); 114 115 offerManager_.addListener(listener_); 116 117 _toBeAdded = new EventType[] {new EventType("domain2", "type2")}; 118 119 offerManager_.offer_change(_toBeAdded, EMPTY_EVENT_TYPE_ARRAY); 120 121 assertEquals(1, added_.size()); 122 123 assertEquals("domain2", ((EventType)added_.get(0)).domain_name); 124 assertEquals("type2", ((EventType)added_.get(0)).type_name); 125 126 assertEquals(0, removed_.size()); 127 128 offerManager_.offer_change(_toBeAdded, EMPTY_EVENT_TYPE_ARRAY); 130 131 assertEquals(1, added_.size()); 132 } 133 134 135 public static Test suite() throws Exception { 136 return new TestSuite(OfferManagerTest.class); 137 } 138 } 139 | Popular Tags |