use of org.opendaylight.netconf.notifications.NetconfNotificationListener in project netconf by opendaylight.
the class NetconfNotificationManagerTest method testClose.
@Test
public void testClose() throws Exception {
final NetconfNotificationManager netconfNotificationManager = createManager();
final BaseNotificationPublisherRegistration baseNotificationPublisherRegistration = netconfNotificationManager.registerBaseNotificationPublisher();
final NetconfNotificationListener listener = mock(NetconfNotificationListener.class);
netconfNotificationManager.registerNotificationListener(NetconfNotificationManager.BASE_NETCONF_STREAM.getName(), listener);
final NetconfNotificationCollector.NetconfNotificationStreamListener streamListener = mock(NetconfNotificationCollector.NetconfNotificationStreamListener.class);
doNothing().when(streamListener).onStreamUnregistered(any(StreamNameType.class));
doNothing().when(streamListener).onStreamRegistered(any(Stream.class));
netconfNotificationManager.registerStreamListener(streamListener);
verify(streamListener).onStreamRegistered(NetconfNotificationManager.BASE_NETCONF_STREAM);
netconfNotificationManager.close();
verify(streamListener).onStreamUnregistered(NetconfNotificationManager.BASE_NETCONF_STREAM.getName());
try {
baseNotificationPublisherRegistration.onCapabilityChanged(new NetconfCapabilityChangeBuilder().build());
} catch (final IllegalStateException e) {
// Exception should be thrown after manager is closed
return;
}
fail("Publishing into a closed manager should fail");
}
use of org.opendaylight.netconf.notifications.NetconfNotificationListener in project netconf by opendaylight.
the class NetconfNotificationManagerTest method testNotificationListeners.
@Test
public void testNotificationListeners() throws Exception {
final NetconfNotificationManager netconfNotificationManager = createManager();
final BaseNotificationPublisherRegistration baseNotificationPublisherRegistration = netconfNotificationManager.registerBaseNotificationPublisher();
final NetconfCapabilityChangeBuilder capabilityChangedBuilder = new NetconfCapabilityChangeBuilder();
final NetconfNotificationListener listener = mock(NetconfNotificationListener.class);
doNothing().when(listener).onNotification(any(StreamNameType.class), any(NetconfNotification.class));
final NotificationListenerRegistration notificationListenerRegistration = netconfNotificationManager.registerNotificationListener(NetconfNotificationManager.BASE_NETCONF_STREAM.getName(), listener);
final NetconfCapabilityChange notification = capabilityChangedBuilder.build();
baseNotificationPublisherRegistration.onCapabilityChanged(notification);
verify(listener).onNotification(any(StreamNameType.class), any(NetconfNotification.class));
notificationListenerRegistration.close();
baseNotificationPublisherRegistration.onCapabilityChanged(notification);
verifyNoMoreInteractions(listener);
}
use of org.opendaylight.netconf.notifications.NetconfNotificationListener in project netconf by opendaylight.
the class NetconfNotificationManagerTest method testCustomNotificationListeners.
@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("<notification/>"));
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));
}
Aggregations