Bump versions to 2.0.0-SNAPSHOT
[netconf.git] / netconf / messagebus-netconf / src / test / java / org / opendaylight / netconf / messagebus / eventsources / netconf / NetconfEventSourceMountTest.java
index 369d6b4df8da162a46752a1e8cc971bcec7f814a..ec06c223b412c9fc9bc08d6098a13cc869645749 100644 (file)
@@ -5,52 +5,52 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.messagebus.eventsources.netconf;
 
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
-import com.google.common.util.concurrent.Futures;
+import com.google.common.collect.Collections2;
+import java.time.Instant;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
-import java.util.Date;
-import java.util.List;
-import javax.annotation.Nullable;
+import java.util.Collection;
+import java.util.Optional;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMNotificationService;
+import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionInput;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.Netconf;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.Streams;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamBuilder;
+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.api.schema.LeafNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-
-public class NetconfEventSourceMountTest {
 
+@Deprecated(forRemoval = true)
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
+public class NetconfEventSourceMountTest extends AbstractCodecTest {
     public static final String STREAM_1 = "stream-1";
     public static final String STREAM_2 = "stream-2";
+
     @Mock
     private DOMMountPoint domMountPoint;
     @Mock
@@ -58,20 +58,25 @@ public class NetconfEventSourceMountTest {
     @Mock
     DOMRpcService rpcService;
     @Mock
-    private DOMDataReadOnlyTransaction tx;
+    DOMSchemaService schemaService;
+    @Mock
+    private DOMDataTreeReadTransaction tx;
     private NetconfEventSourceMount mount;
 
     @Before
-    public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
+    public void setUp() {
         doReturn(Optional.of(dataBroker)).when(domMountPoint).getService(DOMDataBroker.class);
         doReturn(Optional.of(rpcService)).when(domMountPoint).getService(DOMRpcService.class);
-        doReturn(Optional.of(mock(DOMNotificationService.class))).when(domMountPoint).getService(DOMNotificationService.class);
+        doReturn(Optional.of(mock(DOMNotificationService.class))).when(domMountPoint)
+                .getService(DOMNotificationService.class);
+        doReturn(Optional.of(schemaService)).when(domMountPoint).getService(DOMSchemaService.class);
         doReturn(tx).when(dataBroker).newReadOnlyTransaction();
-        final YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(Netconf.QNAME).node(Streams.QNAME).build();
+        final YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(Netconf.QNAME).node(Streams.QNAME)
+                .build();
         final NormalizedNode<?, ?> streamsNode = NetconfTestUtils.getStreamsNode(STREAM_1, STREAM_2);
-        doReturn(Futures.immediateCheckedFuture(Optional.of(streamsNode))).when(tx).read(LogicalDatastoreType.OPERATIONAL, path);
-        mount = new NetconfEventSourceMount(NetconfTestUtils.getNode("node-1"), domMountPoint);
+        doReturn(FluentFutures.immediateFluentFuture(Optional.of(streamsNode)))
+                .when(tx).read(LogicalDatastoreType.OPERATIONAL, path);
+        mount = new NetconfEventSourceMount(SERIALIZER, NetconfTestUtils.getNode("node-1"), domMountPoint);
     }
 
     @Test
@@ -79,8 +84,8 @@ public class NetconfEventSourceMountTest {
         Stream stream = new StreamBuilder()
                 .setName(new StreamNameType(STREAM_1))
                 .build();
-        mount.invokeCreateSubscription(stream, Optional.absent());
-        final SchemaPath type = SchemaPath.create(true, QName.create(CreateSubscriptionInput.QNAME, "create-subscription"));
+        mount.invokeCreateSubscription(stream, Optional.empty());
+        final QName type = QName.create(CreateSubscriptionInput.QNAME, "create-subscription");
         ArgumentCaptor<ContainerNode> captor = ArgumentCaptor.forClass(ContainerNode.class);
         verify(rpcService).invokeRpc(eq(type), captor.capture());
         Assert.assertEquals(STREAM_1, getStreamName(captor.getValue()));
@@ -92,13 +97,13 @@ public class NetconfEventSourceMountTest {
                 .setName(new StreamNameType(STREAM_1))
                 .setReplaySupport(true)
                 .build();
-        final Date date = new Date();
+        final Instant date = Instant.now();
         mount.invokeCreateSubscription(stream, Optional.of(date));
-        final SchemaPath type = SchemaPath.create(true, QName.create(CreateSubscriptionInput.QNAME, "create-subscription"));
+        final QName type = QName.create(CreateSubscriptionInput.QNAME, "create-subscription");
         ArgumentCaptor<ContainerNode> captor = ArgumentCaptor.forClass(ContainerNode.class);
         verify(rpcService).invokeRpc(eq(type), captor.capture());
         Assert.assertEquals(STREAM_1, getStreamName(captor.getValue()));
-        final String expDate = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(date.toInstant().atZone(ZoneId.systemDefault()));
+        final String expDate = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(date.atZone(ZoneId.systemDefault()));
         final Optional<LeafNode> actual = (Optional<LeafNode>) getDate(captor.getValue());
         Assert.assertTrue(actual.isPresent());
         String actualDate = (String) actual.get().getValue();
@@ -111,8 +116,8 @@ public class NetconfEventSourceMountTest {
                 .setName(new StreamNameType(STREAM_1))
                 .setReplaySupport(true)
                 .build();
-        mount.invokeCreateSubscription(stream, Optional.absent());
-        final SchemaPath type = SchemaPath.create(true, QName.create(CreateSubscriptionInput.QNAME, "create-subscription"));
+        mount.invokeCreateSubscription(stream, Optional.empty());
+        final QName type = QName.create(CreateSubscriptionInput.QNAME, "create-subscription");
         ArgumentCaptor<ContainerNode> captor = ArgumentCaptor.forClass(ContainerNode.class);
         verify(rpcService).invokeRpc(eq(type), captor.capture());
         Assert.assertEquals(STREAM_1, getStreamName(captor.getValue()));
@@ -123,26 +128,23 @@ public class NetconfEventSourceMountTest {
 
     @Test
     public void testGetAvailableStreams() throws Exception {
-        final List<Stream> availableStreams = mount.getAvailableStreams();
+        final Collection<Stream> availableStreams = mount.getAvailableStreams();
         Assert.assertEquals(2, availableStreams.size());
-        final List<String> streamNames = Lists.transform(availableStreams, new Function<Stream, String>() {
-            @Nullable
-            @Override
-            public String apply(@Nullable Stream input) {
-                return input.getName().getValue();
-            }
-        });
+        final Collection<String> streamNames = Collections2.transform(availableStreams,
+            input -> input.getName().getValue());
         streamNames.contains(STREAM_1);
         streamNames.contains(STREAM_2);
     }
 
-    private String getStreamName(ContainerNode value) {
-        YangInstanceIdentifier.NodeIdentifier STREAM = new YangInstanceIdentifier.NodeIdentifier(QName.create(CreateSubscriptionInput.QNAME, "stream"));
-        return (String) value.getChild(STREAM).get().getValue();
+    private static String getStreamName(final ContainerNode value) {
+        YangInstanceIdentifier.NodeIdentifier stream =
+                new YangInstanceIdentifier.NodeIdentifier(QName.create(CreateSubscriptionInput.QNAME, "stream"));
+        return (String) value.getChild(stream).get().getValue();
     }
 
-    private Optional<?> getDate(ContainerNode value) {
-        YangInstanceIdentifier.NodeIdentifier START_TIME = new YangInstanceIdentifier.NodeIdentifier(QName.create(CreateSubscriptionInput.QNAME, "startTime"));
-        return value.getChild(START_TIME);
+    private static Optional<?> getDate(final ContainerNode value) {
+        YangInstanceIdentifier.NodeIdentifier startTime =
+                new YangInstanceIdentifier.NodeIdentifier(QName.create(CreateSubscriptionInput.QNAME, "startTime"));
+        return value.getChild(startTime);
     }
 }
\ No newline at end of file