X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fmdsal-netconf-notification%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fmdsal%2Fnotification%2Fimpl%2FNetconfNotificationManagerTest.java;h=5fbc48a9196a4b9d73e823347fbaf1c296edd154;hb=429abad6e4893a4ac620f496ea91e9f98a1a3251;hp=a3daf2698baafb4c6a68a341c24206d49239eb9a;hpb=6b369ef9085496ea80ba7435050080be1163034b;p=netconf.git diff --git a/netconf/mdsal-netconf-notification/src/test/java/org/opendaylight/netconf/mdsal/notification/impl/NetconfNotificationManagerTest.java b/netconf/mdsal-netconf-notification/src/test/java/org/opendaylight/netconf/mdsal/notification/impl/NetconfNotificationManagerTest.java index a3daf2698b..5fbc48a919 100644 --- a/netconf/mdsal-netconf-notification/src/test/java/org/opendaylight/netconf/mdsal/notification/impl/NetconfNotificationManagerTest.java +++ b/netconf/mdsal-netconf-notification/src/test/java/org/opendaylight/netconf/mdsal/notification/impl/NetconfNotificationManagerTest.java @@ -5,14 +5,15 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.netconf.mdsal.notification.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; @@ -24,31 +25,29 @@ import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.opendaylight.mdsal.binding.dom.codec.impl.DefaultBindingDOMCodecFactory; +import org.opendaylight.mdsal.binding.generator.impl.DefaultBindingRuntimeGenerator; +import org.opendaylight.netconf.api.xml.XmlUtil; +import org.opendaylight.netconf.mdsal.notification.impl.ops.NotificationsTransformUtil; import org.opendaylight.netconf.notifications.BaseNotificationPublisherRegistration; import org.opendaylight.netconf.notifications.NetconfNotification; import org.opendaylight.netconf.notifications.NetconfNotificationCollector; import org.opendaylight.netconf.notifications.NetconfNotificationListener; -import org.opendaylight.netconf.notifications.NetconfNotificationRegistry; import org.opendaylight.netconf.notifications.NotificationListenerRegistration; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChangeBuilder; +import org.opendaylight.yangtools.yang.parser.api.YangParserException; +import org.opendaylight.yangtools.yang.parser.impl.DefaultYangParserFactory; +@RunWith(MockitoJUnitRunner.class) public class NetconfNotificationManagerTest { - public static final String RFC3339_DATE_FORMAT_WITH_MILLIS_BLUEPRINT = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"; - @Mock - private NetconfNotificationRegistry notificationRegistry; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } @Test public void testEventTime() throws Exception { @@ -140,7 +139,7 @@ public class NetconfNotificationManagerTest { @Test public void testNotificationListeners() throws Exception { - final NetconfNotificationManager netconfNotificationManager = new NetconfNotificationManager(); + final NetconfNotificationManager netconfNotificationManager = createManager(); final BaseNotificationPublisherRegistration baseNotificationPublisherRegistration = netconfNotificationManager.registerBaseNotificationPublisher(); @@ -161,15 +160,43 @@ public class NetconfNotificationManagerTest { verifyNoMoreInteractions(listener); } + @Test + public void testCustomNotificationListeners() throws Exception { + final NetconfNotificationManager netconfNotificationManager = createManager(); + + final StreamNameType testStreamName = new StreamNameType("TEST_STREAM"); + final Stream testStream = new StreamBuilder().setName(testStreamName).build(); + + final NetconfNotificationListener listenerBase = mock(NetconfNotificationListener.class); + netconfNotificationManager.registerNotificationListener( + NetconfNotificationManager.BASE_NETCONF_STREAM.getName(), listenerBase); + + final NetconfNotificationListener listener = mock(NetconfNotificationListener.class); + netconfNotificationManager.registerNotificationListener(testStream.getName(), listener); + + doNothing().when(listener).onNotification(eq(testStreamName), any(NetconfNotification.class)); + + final NetconfNotification notification = new NetconfNotification( + XmlUtil.readXmlToDocument("")); + netconfNotificationManager.onNotification(testStream.getName(), notification); + + verify(listener).onNotification(eq(testStream.getName()), eq(notification)); + + netconfNotificationManager.close(); + netconfNotificationManager.onNotification(testStream.getName(), notification); + + verifyNoMoreInteractions(listener); + verify(listenerBase, never()).onNotification(eq(testStream.getName()), eq(notification)); + } + @Test public void testClose() throws Exception { - final NetconfNotificationManager netconfNotificationManager = new NetconfNotificationManager(); + final NetconfNotificationManager netconfNotificationManager = createManager(); final BaseNotificationPublisherRegistration baseNotificationPublisherRegistration = netconfNotificationManager.registerBaseNotificationPublisher(); final NetconfNotificationListener listener = mock(NetconfNotificationListener.class); - doNothing().when(listener).onNotification(any(StreamNameType.class), any(NetconfNotification.class)); netconfNotificationManager .registerNotificationListener(NetconfNotificationManager.BASE_NETCONF_STREAM.getName(), listener); @@ -198,7 +225,7 @@ public class NetconfNotificationManagerTest { @Test public void testStreamListeners() throws Exception { - final NetconfNotificationManager netconfNotificationManager = new NetconfNotificationManager(); + final NetconfNotificationManager netconfNotificationManager = createManager(); final NetconfNotificationCollector.NetconfNotificationStreamListener streamListener = mock(NetconfNotificationCollector.NetconfNotificationStreamListener.class); @@ -217,4 +244,9 @@ public class NetconfNotificationManagerTest { verify(streamListener).onStreamUnregistered(NetconfNotificationManager.BASE_STREAM_NAME); } + + private static NetconfNotificationManager createManager() throws YangParserException { + return new NetconfNotificationManager(new NotificationsTransformUtil(new DefaultYangParserFactory(), + new DefaultBindingRuntimeGenerator(), new DefaultBindingDOMCodecFactory())); + } } \ No newline at end of file