*/
package org.opendaylight.restconf.nb.rfc8040.streams;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.mock;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.when;
-import com.google.common.collect.ImmutableSet;
import java.time.Instant;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.mdsal.dom.api.DOMNotification;
-import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.xmlunit.assertj.XmlAssert;
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class XmlNotificationListenerTest extends AbstractNotificationListenerTest {
- private final ListenersBroker listenersBroker = new ListenersBroker.ServerSentEvents();
+@ExtendWith(MockitoExtension.class)
+class XMLNotificationFormatterTest extends AbstractNotificationListenerTest {
+ @Mock
+ private DOMNotification notificationData;
@Test
- public void notifi_leafTest() throws Exception {
+ void notifi_leafTest() throws Exception {
final QName schemaPathNotifi = 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, leaf);
+ final var leaf = mockLeaf(QName.create(MODULE, "lf"));
+ final var notifiBody = mockCont(schemaPathNotifi, leaf);
when(notificationData.getType()).thenReturn(Absolute.of(schemaPathNotifi));
when(notificationData.getBody()).thenReturn(notifiBody);
- assertXmlMatches(prepareXmlResult(notificationData, schemaPathNotifi), """
+ assertXmlMatches(prepareXmlResult(schemaPathNotifi), """
<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>""");
}
@Test
- public void notifi_cont_leafTest() throws Exception {
+ void notifi_cont_leafTest() throws Exception {
final QName schemaPathNotifi = 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, cont);
+ final var leaf = mockLeaf(QName.create(MODULE, "lf"));
+ final var cont = mockCont(QName.create(MODULE, "cont"), leaf);
+ final var notifiBody = mockCont(schemaPathNotifi, cont);
when(notificationData.getType()).thenReturn(Absolute.of(schemaPathNotifi));
when(notificationData.getBody()).thenReturn(notifiBody);
- assertXmlMatches(prepareXmlResult(notificationData, schemaPathNotifi), """
+ assertXmlMatches(prepareXmlResult(schemaPathNotifi), """
<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>""");
}
@Test
- public void notifi_list_Test() throws Exception {
+ void notifi_list_Test() throws Exception {
final QName schemaPathNotifi = 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, Builders.mapBuilder()
+ final var leaf = mockLeaf(QName.create(MODULE, "lf"));
+ final var entry = mockMapEntry(QName.create(MODULE, "lst"), leaf);
+ final var notifiBody = mockCont(schemaPathNotifi, Builders.mapBuilder()
.withNodeIdentifier(NodeIdentifier.create(QName.create(MODULE, "lst")))
.withChild(entry)
.build());
when(notificationData.getType()).thenReturn(Absolute.of(schemaPathNotifi));
when(notificationData.getBody()).thenReturn(notifiBody);
- assertXmlMatches(prepareXmlResult(notificationData, schemaPathNotifi), """
+ assertXmlMatches(prepareXmlResult(schemaPathNotifi), """
<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>""");
}
@Test
- public void notifi_grpTest() throws Exception {
+ void notifi_grpTest() throws Exception {
final QName schemaPathNotifi = QName.create(MODULE, "notifi-grp");
- final DOMNotification notificationData = mock(DOMNotification.class);
-
- final LeafNode<String> leaf = mockLeaf(QName.create(MODULE, "lf"));
- final ContainerNode notifiBody = mockCont(schemaPathNotifi, leaf);
+ final var leaf = mockLeaf(QName.create(MODULE, "lf"));
+ final var notifiBody = mockCont(schemaPathNotifi, leaf);
when(notificationData.getType()).thenReturn(Absolute.of(schemaPathNotifi));
when(notificationData.getBody()).thenReturn(notifiBody);
- assertXmlMatches(prepareXmlResult(notificationData, schemaPathNotifi), """
+ assertXmlMatches(prepareXmlResult(schemaPathNotifi), """
<notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">\
<eventTime>2020-06-29T14:23:46.086855+02:00</eventTime><notifi-grp xmlns="notifi:mod">\
<lf>value</lf></notifi-grp></notification>""");
}
@Test
- public void notifi_augmTest() throws Exception {
+ void notifi_augmTest() throws Exception {
final QName schemaPathNotifi = QName.create(MODULE, "notifi-augm");
- final DOMNotification notificationData = mock(DOMNotification.class);
-
- final LeafNode<String> leaf = mockLeaf(QName.create(MODULE, "lf-augm"));
- final ContainerNode notifiBody = mockCont(schemaPathNotifi, leaf);
+ final var leaf = mockLeaf(QName.create(MODULE, "lf-augm"));
+ final var notifiBody = mockCont(schemaPathNotifi, leaf);
when(notificationData.getType()).thenReturn(Absolute.of(schemaPathNotifi));
when(notificationData.getBody()).thenReturn(notifiBody);
- assertXmlMatches(prepareXmlResult(notificationData, schemaPathNotifi), """
+ assertXmlMatches(prepareXmlResult(schemaPathNotifi), """
<notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">\
<eventTime>2020-06-29T14:23:46.086855+02:00</eventTime><notifi-augm xmlns="notifi:mod">\
<lf-augm>value</lf-augm></notifi-augm></notification>""");
return ImmutableNodes.leafNode(leafQName, "value");
}
- private String prepareXmlResult(final DOMNotification notificationData, final QName schemaPathNotifi)
- throws Exception {
- final var ret = listenersBroker.registerNotificationListener(MODEL_CONTEXT, ImmutableSet.of(schemaPathNotifi),
- NotificationOutputType.XML).formatter().eventData(MODEL_CONTEXT, notificationData, Instant.now());
+ private String prepareXmlResult(final QName schemaPathNotifi) throws Exception {
+ final var ret = XMLNotificationFormatter.EMPTY.eventData(MODEL_CONTEXT, notificationData, Instant.now());
assertNotNull(ret);
return ret;
}