Search in sources :

Example 1 with NetconfNotificationListener

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");
}
Also used : StreamNameType(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType) BaseNotificationPublisherRegistration(org.opendaylight.netconf.notifications.BaseNotificationPublisherRegistration) NetconfCapabilityChangeBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChangeBuilder) NetconfNotificationListener(org.opendaylight.netconf.notifications.NetconfNotificationListener) NetconfNotificationCollector(org.opendaylight.netconf.notifications.NetconfNotificationCollector) Stream(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream) Test(org.junit.Test)

Example 2 with NetconfNotificationListener

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);
}
Also used : StreamNameType(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType) BaseNotificationPublisherRegistration(org.opendaylight.netconf.notifications.BaseNotificationPublisherRegistration) NetconfCapabilityChangeBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChangeBuilder) NetconfNotificationListener(org.opendaylight.netconf.notifications.NetconfNotificationListener) NotificationListenerRegistration(org.opendaylight.netconf.notifications.NotificationListenerRegistration) NetconfCapabilityChange(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange) NetconfNotification(org.opendaylight.netconf.notifications.NetconfNotification) Test(org.junit.Test)

Example 3 with NetconfNotificationListener

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));
}
Also used : StreamNameType(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType) NetconfNotificationListener(org.opendaylight.netconf.notifications.NetconfNotificationListener) Stream(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream) StreamBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamBuilder) NetconfNotification(org.opendaylight.netconf.notifications.NetconfNotification) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 NetconfNotificationListener (org.opendaylight.netconf.notifications.NetconfNotificationListener)3 StreamNameType (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType)3 BaseNotificationPublisherRegistration (org.opendaylight.netconf.notifications.BaseNotificationPublisherRegistration)2 NetconfNotification (org.opendaylight.netconf.notifications.NetconfNotification)2 Stream (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream)2 NetconfCapabilityChangeBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChangeBuilder)2 NetconfNotificationCollector (org.opendaylight.netconf.notifications.NetconfNotificationCollector)1 NotificationListenerRegistration (org.opendaylight.netconf.notifications.NotificationListenerRegistration)1 StreamBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamBuilder)1 NetconfCapabilityChange (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange)1