blob: cde9314d6d2ee472d471a24cd81a5cffc0acee1d [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
tom96dfcab2014-08-28 09:26:03 -070016package org.onlab.onos.event;
17
18import org.junit.Before;
19import org.junit.Test;
20
21import static org.junit.Assert.*;
22
23/**
24 * Tests of the default event sink registry.
25 */
26public class DefaultEventSinkRegistryTest {
27
28 private DefaultEventSinkRegistry registry;
29
30 private static class FooEvent extends TestEvent {
Yuta HIGUCHI5e8ceb42014-11-04 17:22:26 -080031 public FooEvent(String subject) {
32 super(Type.FOO, subject);
33 }
tom96dfcab2014-08-28 09:26:03 -070034 }
35
36 private static class BarEvent extends TestEvent {
Yuta HIGUCHI5e8ceb42014-11-04 17:22:26 -080037 public BarEvent(String subject) {
38 super(Type.BAR, subject);
39 }
tom96dfcab2014-08-28 09:26:03 -070040 }
41
42 private static class FooSink implements EventSink<FooEvent> {
43 @Override public void process(FooEvent event) {}
44 }
45
46 private static class BarSink implements EventSink<BarEvent> {
47 @Override public void process(BarEvent event) {}
48 }
49
50 @Before
51 public void setUp() {
52 registry = new DefaultEventSinkRegistry();
53 }
54
55 @Test
56 public void basics() {
57 FooSink fooSink = new FooSink();
58 BarSink barSink = new BarSink();
59 registry.addSink(FooEvent.class, fooSink);
60 registry.addSink(BarEvent.class, barSink);
61
62 assertEquals("incorrect sink count", 2, registry.getSinks().size());
63 assertEquals("incorrect sink", fooSink, registry.getSink(FooEvent.class));
64 assertEquals("incorrect sink", barSink, registry.getSink(BarEvent.class));
65
66 registry.removeSink(FooEvent.class);
67 assertNull("incorrect sink", registry.getSink(FooEvent.class));
68 assertEquals("incorrect sink", barSink, registry.getSink(BarEvent.class));
69
70 }
71}