Search in sources :

Example 21 with DOMNotification

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

the class XmlNotificationListenerTest 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 = 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-leaf xmlns=\"notifi:mod\">" + "<lf>value</lf></notifi-leaf></notification>";
    assertXmlMatches(result, control);
}
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 22 with DOMNotification

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

the class JsonNotificationListenerTest 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 = 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"));
}
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) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) Test(org.junit.Test)

Example 23 with DOMNotification

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

the class JsonNotificationListenerTest 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 = prepareJson(notificationData, schemaPathNotifi);
    assertTrue(result.contains("ietf-restconf:notification"));
    assertTrue(result.contains("event-time"));
    assertTrue(result.contains("notifi-module:notifi-cont"));
    assertTrue(result.contains("cont"));
    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 24 with DOMNotification

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

the class DOMNotificationRouterTest method offerNotification.

@Test
public void offerNotification() throws Exception {
    final DOMNotificationRouter domNotificationRouter = DOMNotificationRouter.create(1024);
    final DOMNotification domNotification = mock(DOMNotification.class);
    doReturn(Absolute.of(TestModel.TEST_QNAME)).when(domNotification).getType();
    doReturn(TEST_CHILD).when(domNotification).getBody();
    assertNotNull(domNotificationRouter.putNotification(domNotification));
    assertNotNull(domNotificationRouter.offerNotification(domNotification));
    assertNotNull(domNotificationRouter.offerNotification(domNotification, 1, TimeUnit.SECONDS));
}
Also used : DOMNotification(org.opendaylight.mdsal.dom.api.DOMNotification) Test(org.junit.Test)

Example 25 with DOMNotification

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

the class DOMNotificationRouterTest method complexTest.

@SuppressWarnings("checkstyle:IllegalCatch")
@Test
public void complexTest() throws Exception {
    final DOMNotificationSubscriptionListener domNotificationSubscriptionListener = mock(DOMNotificationSubscriptionListener.class);
    doNothing().when(domNotificationSubscriptionListener).onSubscriptionChanged(any());
    final CountDownLatch latch = new CountDownLatch(1);
    final DOMNotificationListener domNotificationListener = new TestListener(latch);
    final DOMNotificationRouter domNotificationRouter = DOMNotificationRouter.create(1024);
    Multimap<Absolute, ?> listeners = domNotificationRouter.listeners();
    assertTrue(listeners.isEmpty());
    assertNotNull(domNotificationRouter.registerNotificationListener(domNotificationListener, Absolute.of(TestModel.TEST_QNAME)));
    assertNotNull(domNotificationRouter.registerNotificationListener(domNotificationListener, Absolute.of(TestModel.TEST2_QNAME)));
    listeners = domNotificationRouter.listeners();
    assertFalse(listeners.isEmpty());
    ListenerRegistry<DOMNotificationSubscriptionListener> subscriptionListeners = domNotificationRouter.subscriptionListeners();
    assertEquals(0, subscriptionListeners.streamListeners().count());
    assertNotNull(domNotificationRouter.registerSubscriptionListener(domNotificationSubscriptionListener));
    subscriptionListeners = domNotificationRouter.subscriptionListeners();
    assertSame(domNotificationSubscriptionListener, subscriptionListeners.streamListeners().findAny().orElseThrow());
    final DOMNotification domNotification = mock(DOMNotification.class);
    doReturn("test").when(domNotification).toString();
    doReturn(Absolute.of(TestModel.TEST_QNAME)).when(domNotification).getType();
    doReturn(TEST_CHILD).when(domNotification).getBody();
    assertNotNull(domNotificationRouter.offerNotification(domNotification));
    try {
        assertNotNull(domNotificationRouter.offerNotification(domNotification, 1, TimeUnit.SECONDS));
        assertNotNull(domNotificationRouter.offerNotification(domNotification, 1, TimeUnit.SECONDS));
    } catch (Exception e) {
        // FIXME: what is the point here?!
        assertTrue(e instanceof UnsupportedOperationException);
    }
    assertNotNull(domNotificationRouter.putNotification(domNotification));
}
Also used : DOMNotificationListener(org.opendaylight.mdsal.dom.api.DOMNotificationListener) DOMNotification(org.opendaylight.mdsal.dom.api.DOMNotification) DOMNotificationSubscriptionListener(org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListener) CountDownLatch(java.util.concurrent.CountDownLatch) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) 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