2 * Copyright (c) 2016 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package io.fd.honeycomb.v3po.notification.impl;
18 import static org.hamcrest.CoreMatchers.hasItem;
19 import static org.hamcrest.CoreMatchers.is;
20 import static org.mockito.Mockito.doReturn;
22 import com.google.common.collect.Lists;
23 import com.google.common.collect.Multimap;
24 import io.fd.honeycomb.v3po.notification.ManagedNotificationProducer;
25 import java.util.ArrayList;
26 import java.util.Collections;
29 import org.junit.Assert;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.mockito.Mock;
33 import org.mockito.MockitoAnnotations;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionEnd;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStart;
37 import org.opendaylight.yangtools.yang.binding.Notification;
38 import org.opendaylight.yangtools.yang.common.QName;
40 public class NotificationProducerRegistryTest {
43 private ManagedNotificationProducer producer;
45 private ManagedNotificationProducer producer2;
48 public void setUp() throws Exception {
49 MockitoAnnotations.initMocks(this);
50 doReturn(Collections.singleton(NetconfCapabilityChange.class))
51 .when(producer).getNotificationTypes();
52 final ArrayList<Object> producer2Notifications = Lists.newArrayList();
53 producer2Notifications.add(NetconfSessionStart.class);
54 producer2Notifications.add(NetconfSessionEnd.class);
55 doReturn(producer2Notifications).when(producer2).getNotificationTypes();
59 public void testNotificationTypes() throws Exception {
60 final NotificationProducerRegistry notificationRegistry =
61 new NotificationProducerRegistry(Lists.newArrayList(producer, producer2));
63 final Set<Class<? extends Notification>> notificationTypes =
64 notificationRegistry.getNotificationTypes();
66 Assert.assertThat(notificationTypes, hasItem(NetconfSessionEnd.class));
67 Assert.assertThat(notificationTypes, hasItem(NetconfSessionStart.class));
68 Assert.assertThat(notificationTypes, hasItem(NetconfCapabilityChange.class));
72 public void testNotificationTypesMapped() throws Exception {
73 final NotificationProducerRegistry notificationRegistry =
74 new NotificationProducerRegistry(Lists.newArrayList(producer, producer2));
76 final Multimap<ManagedNotificationProducer, QName> notificationTypes =
77 notificationRegistry.getNotificationProducerQNames();
79 Assert.assertThat(notificationTypes.keySet(), hasItem(producer));
80 Assert.assertThat(notificationTypes.get(producer), hasItem(NetconfCapabilityChange.QNAME));
81 Assert.assertThat(notificationTypes.keySet(), hasItem(producer2));
82 Assert.assertThat(notificationTypes.get(producer2), hasItem(NetconfSessionStart.QNAME));
83 Assert.assertThat(notificationTypes.get(producer2), hasItem(NetconfSessionEnd.QNAME));
85 final Map<QName, ManagedNotificationProducer> notificationQNameToProducer =
86 notificationRegistry.getNotificationQNameToProducer();
88 Assert.assertThat(notificationQNameToProducer.keySet(), hasItem(NetconfCapabilityChange.QNAME));
89 Assert.assertThat(notificationQNameToProducer.get(NetconfCapabilityChange.QNAME), is(producer));
91 Assert.assertThat(notificationQNameToProducer.keySet(), hasItem(NetconfSessionStart.QNAME));
92 Assert.assertThat(notificationQNameToProducer.keySet(), hasItem(NetconfSessionEnd.QNAME));
93 Assert.assertThat(notificationQNameToProducer.get(NetconfSessionStart.QNAME), is(producer2));
94 Assert.assertThat(notificationQNameToProducer.get(NetconfSessionEnd.QNAME), is(producer2));