X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fmessagebus-netconf%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fmessagebus%2Feventsources%2Fnetconf%2FNetconfEventSourceTest.java;h=61287c6f21def404daed9f7254b557742d4cdd78;hb=982e75ece2483e413befe3edd8fd90022a644f72;hp=1a439b9ff66224cea5c85616f1bb490cee229aab;hpb=bc160d46add32a267c47b58df2061158616f6ba1;p=netconf.git diff --git a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceTest.java b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceTest.java index 1a439b9ff6..61287c6f21 100644 --- a/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceTest.java +++ b/netconf/messagebus-netconf/src/test/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceTest.java @@ -7,13 +7,12 @@ */ package org.opendaylight.netconf.messagebus.eventsources.netconf; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.only; import static org.mockito.Mockito.verify; -import com.google.common.util.concurrent.Futures; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -26,9 +25,9 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.opendaylight.controller.md.sal.dom.api.DOMNotification; -import org.opendaylight.controller.md.sal.dom.api.DOMNotificationPublishService; import org.opendaylight.controller.messagebus.app.util.TopicDOMNotification; +import org.opendaylight.mdsal.dom.api.DOMNotification; +import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId; import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicNotification; @@ -42,11 +41,12 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.r import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.util.concurrent.FluentFutures; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder; import org.opendaylight.yangtools.yang.model.api.NotificationDefinition; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; @@ -54,8 +54,10 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; public class NetconfEventSourceTest { - private static final SchemaPath notification1Path = SchemaPath.create(true, QName.create("ns1", "1970-01-15", "not1")); - private static final SchemaPath notification2Path = SchemaPath.create(true, QName.create("ns2", "1980-02-18", "not2")); + private static final SchemaPath NOTIFICATION_1_PATH = SchemaPath.create(true, QName.create("ns1", "1970-01-15", + "not1")); + private static final SchemaPath NOTIFICATION_2_PATH = SchemaPath.create(true, QName.create("ns2", "1980-02-18", + "not2")); NetconfEventSource netconfEventSource; @@ -72,14 +74,16 @@ public class NetconfEventSourceTest { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); //init notification mocks - doReturn(notification1Path).when(matchnigNotification).getType(); - doReturn(notification2Path).when(nonMachtingNotification).getType(); - DataContainerNodeAttrBuilder body = Builders.containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create("ns1", "1970-01-15", "not1data"))); + doReturn(NOTIFICATION_1_PATH).when(matchnigNotification).getType(); + doReturn(NOTIFICATION_2_PATH).when(nonMachtingNotification).getType(); + DataContainerNodeBuilder body = Builders + .containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create("ns1", + "1970-01-15", "not1data"))); doReturn(body.build()).when(matchnigNotification).getBody(); //init schema context mock Set notifications = new HashSet<>(); - notifications.add(getNotificationDefinitionMock(notification1Path.getLastComponent())); - notifications.add(getNotificationDefinitionMock(notification2Path.getLastComponent())); + notifications.add(getNotificationDefinitionMock(NOTIFICATION_1_PATH.getLastComponent())); + notifications.add(getNotificationDefinitionMock(NOTIFICATION_2_PATH.getLastComponent())); SchemaContext schemaContext = mock(SchemaContext.class); doReturn(notifications).when(schemaContext).getNotifications(); //init mount point mock @@ -88,14 +92,16 @@ public class NetconfEventSourceTest { streams.add(createStream("stream-2")); doReturn(streams).when(mount).getAvailableStreams(); doReturn(schemaContext).when(mount).getSchemaContext(); - doReturn(Futures.immediateCheckedFuture(null)).when(mount).invokeCreateSubscription(any(), any()); - doReturn(Futures.immediateCheckedFuture(null)).when(mount).invokeCreateSubscription(any()); + doReturn(FluentFutures.immediateNullFluentFuture()).when(mount).invokeCreateSubscription(any(), any()); + doReturn(FluentFutures.immediateNullFluentFuture()).when(mount).invokeCreateSubscription(any()); doReturn(mock(ListenerRegistration.class)).when(mount).registerNotificationListener(any(), any()); - final Node nodeId1 = NetconfTestUtils.getNetconfNode("NodeId1", "node.test.local", ConnectionStatus.Connected, NetconfTestUtils.notification_capability_prefix); + final Node nodeId1 = NetconfTestUtils.getNetconfNode("NodeId1", "node.test.local", ConnectionStatus + .Connected, NetconfTestUtils.NOTIFICATION_CAPABILITY_PREFIX); doReturn(nodeId1).when(mount).getNode(); + doReturn(nodeId1.getNodeId().getValue()).when(mount).getNodeId(); Map streamMap = new HashMap<>(); - streamMap.put(notification1Path.getLastComponent().getNamespace().toString(), "stream-1"); + streamMap.put(NOTIFICATION_1_PATH.getLastComponent().getNamespace().toString(), "stream-1"); netconfEventSource = new NetconfEventSource( streamMap, mount, @@ -121,7 +127,7 @@ public class NetconfEventSourceTest { final TopicDOMNotification value = (TopicDOMNotification) captor.getValue(); final QName qname = TopicNotification.QNAME; final YangInstanceIdentifier.NodeIdentifier topicIdNode = - new YangInstanceIdentifier.NodeIdentifier(QName.create(qname.getNamespace().toString(), qname.getFormattedRevision(), "topic-id")); + new YangInstanceIdentifier.NodeIdentifier(QName.create(qname, "topic-id")); final Object actualTopicId = value.getBody().getChild(topicIdNode).get().getValue(); Assert.assertEquals(topic1.getTopicId(), actualTopicId); } @@ -145,17 +151,17 @@ public class NetconfEventSourceTest { verify(domNotificationPublishServiceMock, only()).putNotification(any()); } - private Stream createStream(String name) { + private static Stream createStream(final String name) { return new StreamBuilder() .setName(new StreamNameType(name)) .setReplaySupport(true) .build(); } - private NotificationDefinition getNotificationDefinitionMock(QName qName) { + private static NotificationDefinition getNotificationDefinitionMock(final QName qualifiedName) { NotificationDefinition notification = mock(NotificationDefinition.class); - doReturn(qName).when(notification).getQName(); - doReturn(SchemaPath.create(true, qName)).when(notification).getPath(); + doReturn(qualifiedName).when(notification).getQName(); + doReturn(SchemaPath.create(true, qualifiedName)).when(notification).getPath(); return notification; }