Search in sources :

Example 11 with DOMNotification

use of org.opendaylight.mdsal.dom.api.DOMNotification in project netconf by opendaylight.

the class JsonNotificationListenerTest method notifi_leafTest.

@Test
public void notifi_leafTest() throws Exception {
    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);
    LOG.info("json result: {}", result);
    assertTrue(result.contains("ietf-restconf:notification"));
    assertTrue(result.contains("event-time"));
    assertTrue(result.contains("notifi-module:notifi-leaf"));
    assertTrue(result.contains("lf" + '"' + ":" + '"' + "value"));
}
Also used : DOMNotification(org.opendaylight.mdsal.dom.api.DOMNotification) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) Test(org.junit.Test)

Example 12 with DOMNotification

use of org.opendaylight.mdsal.dom.api.DOMNotification in project netconf by opendaylight.

the class JsonNotificationListenerTest method notifi_augmTest.

@Test
public void notifi_augmTest() throws Exception {
    final Absolute schemaPathNotifi = Absolute.of(QName.create(MODULE, "notifi-augm"));
    final DOMNotification notificationData = mock(DOMNotification.class);
    final LeafNode<String> leaf = mockLeaf(QName.create(MODULE, "lf-augm"));
    final AugmentationNode augm = mockAugm(leaf);
    final ContainerNode notifiBody = mockCont(schemaPathNotifi.lastNodeIdentifier(), augm);
    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("lf-augm" + '"' + ":" + '"' + "value"));
}
Also used : DOMNotification(org.opendaylight.mdsal.dom.api.DOMNotification) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) AugmentationNode(org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode) Test(org.junit.Test)

Example 13 with DOMNotification

use of org.opendaylight.mdsal.dom.api.DOMNotification in project netconf by opendaylight.

the class NetconfNestedNotificationTest method testNestedNotificationToNotificationFunction.

@Test
public void testNestedNotificationToNotificationFunction() throws Exception {
    final EffectiveModelContext schemaContext = getNotificationSchemaContext(Collections.singleton("/schemas/nested-notification.yang"));
    final NetconfMessage notificationMessage = prepareNotification("/nested-notification-payload.xml");
    NetconfMessageTransformer messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(schemaContext), true, BASE_SCHEMAS.getBaseSchema());
    final DOMNotification domNotification = messageTransformer.toNotification(notificationMessage);
    final ContainerNode root = domNotification.getBody();
    assertNotNull(root);
    assertEquals(1, root.body().size());
    assertEquals("interface-enabled", root.getIdentifier().getNodeType().getLocalName());
    assertEquals(NetconfNotification.RFC3339_DATE_PARSER.apply("2008-07-08T00:01:00Z").toInstant(), ((DOMEvent) domNotification).getEventInstant());
    assertEquals(Absolute.of(INTERFACES_QNAME, INTERFACE_QNAME, INTERFACE_ENABLED_NOTIFICATION_QNAME), domNotification.getType());
}
Also used : EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) DOMNotification(org.opendaylight.mdsal.dom.api.DOMNotification) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NetconfMessageTransformer(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 14 with DOMNotification

use of org.opendaylight.mdsal.dom.api.DOMNotification in project netconf by opendaylight.

the class NetconfToNotificationTest method testToNotificationFunction.

@Test
public void testToNotificationFunction() throws Exception {
    final EffectiveModelContext schemaContext = getNotificationSchemaContext(getClass(), false);
    messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(schemaContext), true, BASE_SCHEMAS.getBaseSchema());
    final DOMNotification domNotification = messageTransformer.toNotification(userNotification);
    final ContainerNode root = domNotification.getBody();
    assertNotNull(root);
    assertEquals(6, root.body().size());
    assertEquals("user-visited-page", root.getIdentifier().getNodeType().getLocalName());
    assertEquals(NetconfNotification.RFC3339_DATE_PARSER.apply("2015-10-23T09:42:27.67175+00:00").toInstant(), ((DOMEvent) domNotification).getEventInstant());
}
Also used : EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) DOMNotification(org.opendaylight.mdsal.dom.api.DOMNotification) NetconfMessageTransformer(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 15 with DOMNotification

use of org.opendaylight.mdsal.dom.api.DOMNotification in project netconf by opendaylight.

the class NetconfDeviceSalFacadeTest method testOnDeviceNotification.

@Test
public void testOnDeviceNotification() throws Exception {
    final DOMNotification domNotification = mock(DOMNotification.class);
    deviceFacade.onNotification(domNotification);
    verify(mountInstance).publish(domNotification);
}
Also used : DOMNotification(org.opendaylight.mdsal.dom.api.DOMNotification) Test(org.junit.Test)

Aggregations

DOMNotification (org.opendaylight.mdsal.dom.api.DOMNotification)25 Test (org.junit.Test)24 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)18 Absolute (org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute)16 AugmentationNode (org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)2 NetconfMessageTransformer (org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer)2 EmptyMountPointContext (org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext)2 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)2 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)2 Diff (org.custommonkey.xmlunit.Diff)1 BindingNormalizedNodeSerializer (org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer)1 DOMNotificationListener (org.opendaylight.mdsal.dom.api.DOMNotificationListener)1 DOMNotificationSubscriptionListener (org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListener)1 VRFPREFIXTABLE (org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.cisco.ios.xr.ip._static.cfg.rev130722.VRFPREFIXTABLE)1 TwoLevelListChangedBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.TwoLevelListChangedBuilder)1 Notification (org.opendaylight.yangtools.yang.binding.Notification)1 QName (org.opendaylight.yangtools.yang.common.QName)1 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)1