1 15 package hivemind.test.services; 16 17 import java.beans.PropertyChangeEvent ; 18 19 import org.apache.hivemind.ErrorLog; 20 import org.apache.hivemind.Location; 21 import org.apache.hivemind.service.EventLinker; 22 import org.apache.hivemind.service.impl.EventLinkerImpl; 23 import org.apache.hivemind.test.HiveMindTestCase; 24 25 31 public class TestEventLinker extends HiveMindTestCase 32 { 33 public void testNoName() 34 { 35 EventProducer p = new EventProducer(); 36 EventConsumer c = new EventConsumer(); 37 EventLinker l = new EventLinkerImpl(null); 38 39 l.addEventListener(p, null, c, null); 40 41 PropertyChangeEvent e = new PropertyChangeEvent (this, "whatever", "foo", "bar"); 42 43 p.fire(e); 44 45 assertSame(e, c.getLastEvent()); 46 47 50 EventConsumer c2 = new EventConsumer(); 51 52 l.addEventListener(p, null, c2, null); 53 54 p.fire(e); 55 56 assertSame(e, c2.getLastEvent()); 57 } 58 59 public void testNameMatch() 60 { 61 EventProducer p = new EventProducer(); 62 EventConsumer c = new EventConsumer(); 63 EventLinker l = new EventLinkerImpl(null); 64 65 l.addEventListener(p, "propertyChange", c, null); 66 67 PropertyChangeEvent e = new PropertyChangeEvent (this, "whatever", "foo", "bar"); 68 69 p.fire(e); 70 71 assertSame(e, c.getLastEvent()); 72 } 73 74 public void testNoMatch() throws Exception 75 { 76 Location location = newLocation(); 77 EventProducer p = new EventProducer(); 78 Object c = "NeverwinterNights"; 79 80 ErrorLog el = (ErrorLog) newMock(ErrorLog.class); 81 82 el 83 .error( 84 "NeverwinterNights does not implement any listener interfaces compatible with EventProducer.", 85 location, 86 null); 87 88 replayControls(); 89 90 EventLinker l = new EventLinkerImpl(el); 91 92 l.addEventListener(p, null, c, location); 93 94 assertEquals(0, p.getListenerCount()); 95 96 verifyControls(); 97 } 98 99 public void testNoMatchingName() throws Exception 100 { 101 Location location = newLocation(); 102 EventProducer p = new EventProducer(); 103 Object c = "SoulCailiburII"; 104 105 ErrorLog el = (ErrorLog) newMock(ErrorLog.class); 106 107 el.error("EventProducer does not implement an event set named 'fred'.", location, null); 108 109 replayControls(); 110 111 EventLinker l = new EventLinkerImpl(el); 112 113 l.addEventListener(p, "fred", c, location); 114 115 assertEquals(0, p.getListenerCount()); 116 117 verifyControls(); 118 } 119 120 public void testIncompatible() throws Exception 121 { 122 Location location = newLocation(); 123 EventProducer p = new EventProducer(); 124 Object c = "SplinterCell"; 125 126 ErrorLog el = (ErrorLog) newMock(ErrorLog.class); 127 128 el 129 .error( 130 "SplinterCell does not implement the java.beans.PropertyChangeListener listener interface (for event set 'propertyChange' of EventProducer).", 131 location, 132 null); 133 134 replayControls(); 135 136 EventLinker l = new EventLinkerImpl(el); 137 138 l.addEventListener(p, "propertyChange", c, location); 139 140 assertEquals(0, p.getListenerCount()); 141 142 verifyControls(); 143 } 144 145 public void testNoProducer() throws Exception 146 { 147 Location location = newLocation(); 148 Object p = "DanceDanceRevolution"; 149 Object c = "SplinterCell"; 150 151 ErrorLog el = (ErrorLog) newMock(ErrorLog.class); 152 153 el 154 .error( 155 "SplinterCell does not implement any listener interfaces compatible with DanceDanceRevolution.", 156 location, 157 null); 158 159 replayControls(); 160 161 EventLinker l = new EventLinkerImpl(el); 162 163 l.addEventListener(p, null, c, location); 164 165 verifyControls(); 166 } 167 168 } | Popular Tags |