blob: b79b836d60cfcc50cc9fc616fc230e0748377131 [file] [log] [blame]
tomb36046e2014-08-27 00:22:24 -07001package org.onlab.onos.event;
2
3import org.junit.Test;
4
5import static org.junit.Assert.assertEquals;
6import static org.junit.Assert.assertTrue;
7import static org.onlab.onos.event.TestEvent.Type.FOO;
8
9/**
10 * Tests of the base event abstraction.
11 */
12public class AbstractEventTest {
13
tomca20e0c2014-09-03 23:22:24 -070014 /**
15 * Validates the base attributes of an event.
16 *
17 * @param event event to validate
18 * @param type event type
19 * @param subject event subject
20 * @param time event time
21 * @param <T> type of event
22 * @param <S> type of subject
23 */
24 protected static <T extends Enum, S>
25 void validateEvent(Event<T, S> event, T type, S subject, long time) {
26 assertEquals("incorrect type", type, event.type());
27 assertEquals("incorrect subject", subject, event.subject());
28 assertEquals("incorrect time", time, event.time());
29 }
30
31 /**
32 * Validates the base attributes of an event.
33 *
34 * @param event event to validate
35 * @param type event type
36 * @param subject event subject
37 * @param minTime minimum event time inclusive
38 * @param maxTime maximum event time inclusive
39 * @param <T> type of event
40 * @param <S> type of subject
41 */
42 protected static <T extends Enum, S>
43 void validateEvent(Event<T, S> event, T type, S subject,
44 long minTime, long maxTime) {
45 assertEquals("incorrect type", type, event.type());
46 assertEquals("incorrect subject", subject, event.subject());
47 assertTrue("incorrect time", minTime <= event.time() && event.time() <= maxTime);
48 }
49
tomb36046e2014-08-27 00:22:24 -070050 @Test
51 public void withTime() {
52 TestEvent event = new TestEvent(FOO, "foo", 123L);
tomca20e0c2014-09-03 23:22:24 -070053 validateEvent(event, FOO, "foo", 123L);
tomb36046e2014-08-27 00:22:24 -070054 }
55
56 @Test
57 public void withoutTime() {
58 long before = System.currentTimeMillis();
59 TestEvent event = new TestEvent(FOO, "foo");
60 long after = System.currentTimeMillis();
tomca20e0c2014-09-03 23:22:24 -070061 validateEvent(event, FOO, "foo", before, after);
tomb36046e2014-08-27 00:22:24 -070062 }
tomca20e0c2014-09-03 23:22:24 -070063
tomb36046e2014-08-27 00:22:24 -070064}