use of org.opendaylight.netconf.notifications.NetconfNotification in project netconf by opendaylight.
the class NotificationsTransformUtil method transform.
private NetconfNotification transform(final Notification notification, final Optional<Date> eventTime, final SchemaPath path) {
final ContainerNode containerNode = serializer.toNormalizedNodeNotification(notification);
final DOMResult result = new DOMResult(XmlUtil.newDocument());
try {
NetconfUtil.writeNormalizedNode(containerNode, result, path, schemaContext);
} catch (final XMLStreamException | IOException e) {
throw new IllegalStateException("Unable to serialize " + notification, e);
}
final Document node = (Document) result.getNode();
return eventTime.isPresent() ? new NetconfNotification(node, eventTime.get()) : new NetconfNotification(node);
}
use of org.opendaylight.netconf.notifications.NetconfNotification 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