X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fstreams%2Flisteners%2FNotificationListenerTest.java;h=1e12b8145ed8f9bf482a89fedd049aa3f27a792a;hb=c8f61b164f0515cccc8d21f6b9c5a279be818ae6;hp=a2d794aa14609dcecd348b2e00fe487cfacf6fdf;hpb=53646a063c2ec4251bb4f9d02a4ff488956a0dcc;p=netconf.git diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/streams/listeners/NotificationListenerTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/streams/listeners/NotificationListenerTest.java index a2d794aa14..1e12b8145e 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/streams/listeners/NotificationListenerTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/streams/listeners/NotificationListenerTest.java @@ -18,7 +18,7 @@ import com.google.common.collect.Lists; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.URI; -import java.text.SimpleDateFormat; +import java.text.ParseException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -36,6 +36,7 @@ import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev14070 import org.opendaylight.yangtools.util.SingletonSet; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; +import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; @@ -50,6 +51,15 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; public class NotificationListenerTest { + private static final QNameModule MODULE; + static { + try { + MODULE = QNameModule.create(URI.create("notifi:mod"), + SimpleDateFormatUtil.getRevisionFormat().parse("2016-11-23")); + } catch (ParseException e) { + throw new ExceptionInInitializerError(e); + } + } private SchemaContext schmeaCtx; @@ -62,13 +72,11 @@ public class NotificationListenerTest { @Test public void notifi_leafTest() throws Exception { - final QNameModule moduleQName = - QNameModule.create(new URI("notifi:mod"), new SimpleDateFormat("yyyy-MM-dd").parse("2016-11-23")); - final SchemaPath schemaPathNotifi = SchemaPath.create(false, QName.create(moduleQName, "notifi-leaf")); + final SchemaPath schemaPathNotifi = SchemaPath.create(false, QName.create(MODULE, "notifi-leaf")); final DOMNotification notificationData = mock(DOMNotification.class); - final LeafNode leaf = mockLeaf(QName.create(moduleQName, "lf")); + final LeafNode leaf = mockLeaf(QName.create(MODULE, "lf")); final ContainerNode notifiBody = mockCont(schemaPathNotifi.getLastComponent(), leaf); when(notificationData.getType()).thenReturn(schemaPathNotifi); @@ -84,16 +92,12 @@ public class NotificationListenerTest { @Test public void notifi_cont_leafTest() throws Exception { - final QNameModule moduleQName = - QNameModule.create(new URI("notifi:mod"), new SimpleDateFormat("yyyy-MM-dd").parse("2016-11-23")); - - final SchemaPath schemaPathNotifi = - SchemaPath.create(false, QName.create(moduleQName, "notifi-cont")); + final SchemaPath schemaPathNotifi = SchemaPath.create(false, QName.create(MODULE, "notifi-cont")); final DOMNotification notificationData = mock(DOMNotification.class); - final LeafNode leaf = mockLeaf(QName.create(moduleQName, "lf")); - final ContainerNode cont = mockCont(QName.create(moduleQName, "cont"), leaf); + final LeafNode leaf = mockLeaf(QName.create(MODULE, "lf")); + final ContainerNode cont = mockCont(QName.create(MODULE, "cont"), leaf); final ContainerNode notifiBody = mockCont(schemaPathNotifi.getLastComponent(), cont); when(notificationData.getType()).thenReturn(schemaPathNotifi); @@ -110,17 +114,14 @@ public class NotificationListenerTest { @Test public void notifi_list_Test() throws Exception { - final QNameModule moduleQName = - QNameModule.create(new URI("notifi:mod"), new SimpleDateFormat("yyyy-MM-dd").parse("2016-11-23")); - - final SchemaPath schemaPathNotifi = SchemaPath.create(false, QName.create(moduleQName, "notifi-list")); + final SchemaPath schemaPathNotifi = SchemaPath.create(false, QName.create(MODULE, "notifi-list")); final DOMNotification notificationData = mock(DOMNotification.class); - final LeafNode leaf = mockLeaf(QName.create(moduleQName, "lf")); - final MapEntryNode entry = mockMapEntry(QName.create(moduleQName, "lst"), leaf); - final MapNode list = mockList(QName.create(moduleQName, "lst"), entry); - final ContainerNode cont = mockCont(QName.create(moduleQName, "cont"), list); + final LeafNode leaf = mockLeaf(QName.create(MODULE, "lf")); + final MapEntryNode entry = mockMapEntry(QName.create(MODULE, "lst"), leaf); + final MapNode list = mockList(QName.create(MODULE, "lst"), entry); + final ContainerNode cont = mockCont(QName.create(MODULE, "cont"), list); final ContainerNode notifiBody = mockCont(schemaPathNotifi.getLastComponent(), cont); when(notificationData.getType()).thenReturn(schemaPathNotifi); @@ -137,14 +138,11 @@ public class NotificationListenerTest { @Test public void notifi_grpTest() throws Exception { - final QNameModule moduleQName = - QNameModule.create(new URI("notifi:mod"), new SimpleDateFormat("yyyy-MM-dd").parse("2016-11-23")); - - final SchemaPath schemaPathNotifi = SchemaPath.create(false, QName.create(moduleQName, "notifi-grp")); + final SchemaPath schemaPathNotifi = SchemaPath.create(false, QName.create(MODULE, "notifi-grp")); final DOMNotification notificationData = mock(DOMNotification.class); - final LeafNode leaf = mockLeaf(QName.create(moduleQName, "lf")); + final LeafNode leaf = mockLeaf(QName.create(MODULE, "lf")); final ContainerNode notifiBody = mockCont(schemaPathNotifi.getLastComponent(), leaf); when(notificationData.getType()).thenReturn(schemaPathNotifi); @@ -159,14 +157,11 @@ public class NotificationListenerTest { @Test public void notifi_augmTest() throws Exception { - final QNameModule moduleQName = - QNameModule.create(new URI("notifi:mod"), new SimpleDateFormat("yyyy-MM-dd").parse("2016-11-23")); - - final SchemaPath schemaPathNotifi = SchemaPath.create(false, QName.create(moduleQName, "notifi-augm")); + final SchemaPath schemaPathNotifi = SchemaPath.create(false, QName.create(MODULE, "notifi-augm")); final DOMNotification notificationData = mock(DOMNotification.class); - final LeafNode leaf = mockLeaf(QName.create(moduleQName, "lf-augm")); + final LeafNode leaf = mockLeaf(QName.create(MODULE, "lf-augm")); final AugmentationNode augm = mockAugm(leaf); final ContainerNode notifiBody = mockCont(schemaPathNotifi.getLastComponent(), augm); @@ -180,7 +175,7 @@ public class NotificationListenerTest { assertTrue(result.contains("lf-augm" + '"' + ":" + '"' + "value")); } - private AugmentationNode mockAugm(final LeafNode leaf) { + private static AugmentationNode mockAugm(final LeafNode leaf) { final AugmentationNode augm = mock(AugmentationNode.class); final AugmentationIdentifier augmId = new AugmentationIdentifier(SingletonSet.of(leaf.getNodeType())); when(augm.getIdentifier()).thenReturn(augmId); @@ -192,7 +187,7 @@ public class NotificationListenerTest { return augm; } - private MapEntryNode mockMapEntry(final QName entryQName, final LeafNode leaf) { + private static MapEntryNode mockMapEntry(final QName entryQName, final LeafNode leaf) { final MapEntryNode entry = mock(MapEntryNode.class); final Map keyValues = new HashMap<>(); keyValues.put(leaf.getNodeType(), "value"); @@ -207,7 +202,7 @@ public class NotificationListenerTest { return entry; } - private MapNode mockList(final QName listQName, final MapEntryNode... entries) { + private static MapNode mockList(final QName listQName, final MapEntryNode... entries) { final MapNode list = mock(MapNode.class); when(list.getIdentifier()).thenReturn(NodeIdentifier.create(listQName)); when(list.getNodeType()).thenReturn(listQName); @@ -215,7 +210,7 @@ public class NotificationListenerTest { return list; } - private ContainerNode mockCont(final QName contQName, final DataContainerChild child) { + private static ContainerNode mockCont(final QName contQName, final DataContainerChild child) { final ContainerNode cont = mock(ContainerNode.class); when(cont.getIdentifier()).thenReturn(NodeIdentifier.create(contQName)); when(cont.getNodeType()).thenReturn(contQName); @@ -226,7 +221,7 @@ public class NotificationListenerTest { return cont; } - private LeafNode mockLeaf(final QName leafQName) { + private static LeafNode mockLeaf(final QName leafQName) { final LeafNode child = mock(LeafNode.class); when(child.getNodeType()).thenReturn(leafQName); when(child.getIdentifier()).thenReturn(NodeIdentifier.create(leafQName));