1 package org.objectweb.celtix; 2 3 import java.util.List ; 4 5 import junit.framework.TestCase; 6 7 import org.easymock.EasyMock; 8 import static org.easymock.EasyMock.isA; 9 10 public class BusEventTest extends TestCase { 12 Bus bus; 13 14 BusEventListener bel; 15 BusEventFilter bef; 16 BusEvent event; 17 18 public void setUp() throws Exception { 19 bel = EasyMock.createMock(BusEventListener.class); 20 bef = EasyMock.createMock(BusEventFilter.class); 21 bus = Bus.init(); 22 event = new BusEvent("Test for EventListener", BusEvent.BUS_EVENT); 23 } 24 25 public void tearDown() throws Exception { 26 Thread.sleep(100); 27 bus.shutdown(true); 28 } 29 30 public void testBusSendEvent() throws BusException { 31 EasyMock.reset(bel); 32 EasyMock.reset(bef); 33 bef.isEventEnabled(isA(BusEvent.class)); 34 EasyMock.expectLastCall().andReturn(true); 35 bel.processEvent(isA(BusEvent.class)); 36 EasyMock.expectLastCall(); 37 EasyMock.replay(bel); 38 EasyMock.replay(bef); 39 40 bus.addListener(bel, bef); 41 bus.sendEvent(event); 42 bus.removeListener(bel); 43 bus.sendEvent(event); 45 46 EasyMock.verify(bel); 47 EasyMock.verify(bef); 48 } 49 50 public void testBusRemoveListener() throws BusException { 51 bus.addListener(bel, bef); 52 53 bus.removeListener(bel); 54 55 bus.sendEvent(new BusEvent("Test for EventListener", BusEvent.BUS_EVENT)); 56 57 } 58 59 public void testBusEventCache() throws BusException { 61 62 BusEventCache cache = bus.getEventCache(); 63 64 BusEvent event1 = new BusEvent("Test for EventCache", BusEvent.BUS_EVENT); 65 BusEvent event2 = new BusEvent("Test for EventCache", "TEST"); 66 67 cache.flushEvents(); 68 69 bus.sendEvent(event); 70 bus.sendEvent(event1); 71 bus.sendEvent(event2); 72 73 assertEquals("The event cache getEvents size is not correct", 74 3, cache.getEvents().size()); 75 76 assertEquals("The event cache getEvents() size is not correct", 77 1, cache.getEvents("TEST").size()); 78 79 List <BusEvent> events = cache.flushEvents("TEST"); 80 81 assertEquals("The event cache flushEvent TEST events size is not correct", 82 1, events.size()); 83 84 assertEquals("The event cache getID is not correct", 85 0, events.get(0).getID().compareTo("TEST")); 86 87 assertEquals("The event cache getEvents size is not correct", 88 2, cache.getEvents().size()); 89 90 cache.flushEvents(BusEvent.class); 91 assertEquals("After flush the event cache getEvents size is not correct", 92 0, cache.getEvents().size()); 93 94 } 95 96 } 97 | Popular Tags |