Search in sources :

Example 6 with NetconfNotification

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);
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) XMLStreamException(javax.xml.stream.XMLStreamException) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) IOException(java.io.IOException) Document(org.w3c.dom.Document) NetconfNotification(org.opendaylight.netconf.notifications.NetconfNotification)

Example 7 with NetconfNotification

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));
}
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

NetconfNotification (org.opendaylight.netconf.notifications.NetconfNotification)7 Test (org.junit.Test)5 Document (org.w3c.dom.Document)2 ChannelFuture (io.netty.channel.ChannelFuture)1 IOException (java.io.IOException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 DOMResult (javax.xml.transform.dom.DOMResult)1 NetconfNotificationListener (org.opendaylight.netconf.notifications.NetconfNotificationListener)1 StreamNameType (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType)1 Stream (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream)1 StreamBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamBuilder)1 Uri (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)1 NetconfCapabilityChange (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange)1 NetconfCapabilityChangeBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChangeBuilder)1 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)1