use of org.opendaylight.mdsal.dom.api.DOMNotification in project netconf by opendaylight.
the class SchemalessMessageTransformerTest method toNotification.
@Test
public void toNotification() throws Exception {
final Document payload = XmlUtil.readXmlToDocument(getClass().getResourceAsStream("/notification-payload.xml"));
final NetconfMessage netconfMessage = new NetconfMessage(payload);
final DOMNotification domNotification = transformer.toNotification(netconfMessage);
assertEquals(domNotification.getType().lastNodeIdentifier(), SchemalessMessageTransformer.SCHEMALESS_NOTIFICATION_PAYLOAD.getNodeType());
final QName qName = QName.create("org:opendaylight:notification:test:ns:yang:user-notification", "user-visited-page");
final DOMSourceAnyxmlNode dataContainerChild = (DOMSourceAnyxmlNode) domNotification.getBody().findChildByArg(new NodeIdentifier(qName)).get();
final Diff diff = XMLUnit.compareXML(payload, dataContainerChild.body().getNode().getOwnerDocument());
assertTrue(diff.toString(), diff.similar());
}
use of org.opendaylight.mdsal.dom.api.DOMNotification in project netconf by opendaylight.
the class NotificationListenerTest method notifi_leafTest.
@Test
public void notifi_leafTest() {
final Absolute schemaPathNotifi = Absolute.of(QName.create(MODULE, "notifi-leaf"));
final DOMNotification notificationData = mock(DOMNotification.class);
final LeafNode<String> leaf = mockLeaf(QName.create(MODULE, "lf"));
final ContainerNode notifiBody = mockCont(schemaPathNotifi.lastNodeIdentifier(), leaf);
when(notificationData.getType()).thenReturn(schemaPathNotifi);
when(notificationData.getBody()).thenReturn(notifiBody);
final String result = prepareJson(notificationData, schemaPathNotifi);
assertTrue(result.contains("ietf-restconf:notification"));
assertTrue(result.contains("event-time"));
assertTrue(result.contains("notifi-module:notifi-leaf"));
assertTrue(result.contains("lf" + '"' + ":" + '"' + "value"));
}
use of org.opendaylight.mdsal.dom.api.DOMNotification in project netconf by opendaylight.
the class NotificationListenerTest method notifi_list_Test.
@Test
public void notifi_list_Test() {
final Absolute schemaPathNotifi = Absolute.of(QName.create(MODULE, "notifi-list"));
final ContainerNode notifiBody = mockCont(schemaPathNotifi.lastNodeIdentifier(), ImmutableNodes.mapNodeBuilder().withNodeIdentifier(NodeIdentifier.create(QName.create(MODULE, "lst"))).withChild(mockMapEntry(QName.create(MODULE, "lst"), mockLeaf(QName.create(MODULE, "lf")))).build());
final DOMNotification notificationData = mock(DOMNotification.class);
when(notificationData.getType()).thenReturn(schemaPathNotifi);
when(notificationData.getBody()).thenReturn(notifiBody);
final String result = prepareJson(notificationData, schemaPathNotifi);
assertTrue(result.contains("ietf-restconf:notification"));
assertTrue(result.contains("event-time"));
assertTrue(result.contains("notifi-module:notifi-list"));
assertTrue(result.contains("lst"));
assertTrue(result.contains("lf" + '"' + ":" + '"' + "value"));
}
use of org.opendaylight.mdsal.dom.api.DOMNotification in project netconf by opendaylight.
the class XmlNotificationListenerTest method notifi_list_Test.
@Test
public void notifi_list_Test() throws Exception {
final Absolute schemaPathNotifi = Absolute.of(QName.create(MODULE, "notifi-list"));
final DOMNotification notificationData = mock(DOMNotification.class);
final LeafNode<String> leaf = mockLeaf(QName.create(MODULE, "lf"));
final MapEntryNode entry = mockMapEntry(QName.create(MODULE, "lst"), leaf);
final ContainerNode notifiBody = mockCont(schemaPathNotifi.lastNodeIdentifier(), Builders.mapBuilder().withNodeIdentifier(NodeIdentifier.create(QName.create(MODULE, "lst"))).withChild(entry).build());
when(notificationData.getType()).thenReturn(schemaPathNotifi);
when(notificationData.getBody()).thenReturn(notifiBody);
final String result = prepareXmlResult(notificationData, schemaPathNotifi);
final String control = "<notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">" + "<eventTime>2020-06-29T14:23:46.086855+02:00</eventTime><notifi-list xmlns=\"notifi:mod\">" + "<lst><lf>value</lf></lst></notifi-list></notification>";
assertXmlMatches(result, control);
}
use of org.opendaylight.mdsal.dom.api.DOMNotification in project netconf by opendaylight.
the class XmlNotificationListenerTest method notifi_cont_leafTest.
@Test
public void notifi_cont_leafTest() throws Exception {
final Absolute schemaPathNotifi = Absolute.of(QName.create(MODULE, "notifi-cont"));
final DOMNotification notificationData = mock(DOMNotification.class);
final LeafNode<String> leaf = mockLeaf(QName.create(MODULE, "lf"));
final ContainerNode cont = mockCont(QName.create(MODULE, "cont"), leaf);
final ContainerNode notifiBody = mockCont(schemaPathNotifi.lastNodeIdentifier(), cont);
when(notificationData.getType()).thenReturn(schemaPathNotifi);
when(notificationData.getBody()).thenReturn(notifiBody);
final String result = prepareXmlResult(notificationData, schemaPathNotifi);
final String control = "<notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">" + "<eventTime>2020-06-29T14:23:46.086855+02:00</eventTime><notifi-cont xmlns=\"notifi:mod\">" + "<cont><lf>value</lf></cont></notifi-cont></notification>";
assertXmlMatches(result, control);
}
Aggregations