Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.event; |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 17 | |
| 18 | import org.junit.Before; |
| 19 | import org.junit.Test; |
| 20 | |
| 21 | import static org.junit.Assert.*; |
| 22 | |
| 23 | /** |
| 24 | * Tests of the default event sink registry. |
| 25 | */ |
| 26 | public class DefaultEventSinkRegistryTest { |
| 27 | |
| 28 | private DefaultEventSinkRegistry registry; |
| 29 | |
| 30 | private static class FooEvent extends TestEvent { |
Yuta HIGUCHI | 5e8ceb4 | 2014-11-04 17:22:26 -0800 | [diff] [blame] | 31 | public FooEvent(String subject) { |
| 32 | super(Type.FOO, subject); |
| 33 | } |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | private static class BarEvent extends TestEvent { |
Yuta HIGUCHI | 5e8ceb4 | 2014-11-04 17:22:26 -0800 | [diff] [blame] | 37 | public BarEvent(String subject) { |
| 38 | super(Type.BAR, subject); |
| 39 | } |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 40 | } |
| 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 | } |