5fdf502b9a9c61b54ebe4b413a9591e4af58947b
[hc2vpp.git] /
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
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  */
16 package io.fd.honeycomb.v3po.notification.impl;
17
18 import static org.hamcrest.CoreMatchers.hasItem;
19 import static org.hamcrest.CoreMatchers.is;
20 import static org.mockito.Mockito.doReturn;
21
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;
27 import java.util.Map;
28 import java.util.Set;
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;
39
40 public class NotificationProducerRegistryTest {
41
42     @Mock
43     private ManagedNotificationProducer producer;
44     @Mock
45     private ManagedNotificationProducer producer2;
46
47     @Before
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();
56     }
57
58     @Test
59     public void testNotificationTypes() throws Exception {
60         final NotificationProducerRegistry notificationRegistry =
61             new NotificationProducerRegistry(Lists.newArrayList(producer, producer2));
62
63         final Set<Class<? extends Notification>> notificationTypes =
64             notificationRegistry.getNotificationTypes();
65
66         Assert.assertThat(notificationTypes, hasItem(NetconfSessionEnd.class));
67         Assert.assertThat(notificationTypes, hasItem(NetconfSessionStart.class));
68         Assert.assertThat(notificationTypes, hasItem(NetconfCapabilityChange.class));
69     }
70
71     @Test
72     public void testNotificationTypesMapped() throws Exception {
73         final NotificationProducerRegistry notificationRegistry =
74             new NotificationProducerRegistry(Lists.newArrayList(producer, producer2));
75
76         final Multimap<ManagedNotificationProducer, QName> notificationTypes =
77             notificationRegistry.getNotificationProducerQNames();
78
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));
84
85         final Map<QName, ManagedNotificationProducer> notificationQNameToProducer =
86             notificationRegistry.getNotificationQNameToProducer();
87
88         Assert.assertThat(notificationQNameToProducer.keySet(), hasItem(NetconfCapabilityChange.QNAME));
89         Assert.assertThat(notificationQNameToProducer.get(NetconfCapabilityChange.QNAME), is(producer));
90
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));
95
96
97     }
98 }