blob: 0bb1e8ccdc7addedc20f75fe2872d023e0662cc9 [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 {
31 public FooEvent(String subject) { super(Type.FOO, subject); }
32 }
33
34 private static class BarEvent extends TestEvent {
35 public BarEvent(String subject) { super(Type.BAR, subject); }
36 }
37
38 private static class FooSink implements EventSink<FooEvent> {
39 @Override public void process(FooEvent event) {}
40 }
41
42 private static class BarSink implements EventSink<BarEvent> {
43 @Override public void process(BarEvent event) {}
44 }
45
46 @Before
47 public void setUp() {
48 registry = new DefaultEventSinkRegistry();
49 }
50
51 @Test
52 public void basics() {
53 FooSink fooSink = new FooSink();
54 BarSink barSink = new BarSink();
55 registry.addSink(FooEvent.class, fooSink);
56 registry.addSink(BarEvent.class, barSink);
57
58 assertEquals("incorrect sink count", 2, registry.getSinks().size());
59 assertEquals("incorrect sink", fooSink, registry.getSink(FooEvent.class));
60 assertEquals("incorrect sink", barSink, registry.getSink(BarEvent.class));
61
62 registry.removeSink(FooEvent.class);
63 assertNull("incorrect sink", registry.getSink(FooEvent.class));
64 assertEquals("incorrect sink", barSink, registry.getSink(BarEvent.class));
65
66 }
67}