Split out odl-netconf-device.yang
[netconf.git] / netconf / netconf-topology-singleton / src / test / java / org / opendaylight / netconf / topology / singleton / impl / NetconfNodeActorTest.java
index a0df29f994d7b315f35a5fe5208f6c5f78f28d1d..b29a4ce9b60cc95553d1fa351bc74c21faed41a2 100644 (file)
@@ -44,7 +44,6 @@ import akka.testkit.TestActorRef;
 import akka.testkit.javadsl.TestKit;
 import akka.util.Timeout;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
 import com.google.common.io.ByteSource;
 import com.google.common.net.InetAddresses;
 import com.google.common.util.concurrent.FluentFuture;
@@ -53,8 +52,8 @@ import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.SettableFuture;
 import java.io.InputStream;
 import java.net.InetSocketAddress;
+import java.time.Duration;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
 import java.util.Scanner;
@@ -87,6 +86,9 @@ import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult;
 import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices.Actions;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices.Rpcs;
 import org.opendaylight.netconf.sal.connect.netconf.NetconfDevice.SchemaResourcesDTO;
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.netconf.topology.singleton.impl.actors.NetconfNodeActor;
@@ -108,17 +110,15 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
 import org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory;
 import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
-import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
@@ -130,14 +130,13 @@ import org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
 import scala.concurrent.Await;
 import scala.concurrent.Future;
-import scala.concurrent.duration.Duration;
 
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
 
-    private static final Timeout TIMEOUT = new Timeout(Duration.create(5, "seconds"));
-    private static final RevisionSourceIdentifier SOURCE_IDENTIFIER1 = RevisionSourceIdentifier.create("yang1");
-    private static final RevisionSourceIdentifier SOURCE_IDENTIFIER2 = RevisionSourceIdentifier.create("yang2");
+    private static final Timeout TIMEOUT = Timeout.create(Duration.ofSeconds(5));
+    private static final SourceIdentifier SOURCE_IDENTIFIER1 = new SourceIdentifier("yang1");
+    private static final SourceIdentifier SOURCE_IDENTIFIER2 = new SourceIdentifier("yang2");
 
     private ActorSystem system = ActorSystem.create();
     private final TestKit testKit = new TestKit(system);
@@ -147,10 +146,10 @@ public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
     private final SharedSchemaRepository masterSchemaRepository = new SharedSchemaRepository("master");
 
     @Mock
-    private DOMRpcService mockDOMRpcService;
+    private Rpcs.Normalized mockDOMRpcService;
 
     @Mock
-    private DOMActionService mockDOMActionService;
+    private Actions.Normalized mockDOMActionService;
 
     @Mock
     private DOMMountPointService mockMountPointService;
@@ -199,7 +198,7 @@ public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
         doReturn(masterSchemaRepository).when(schemaResourceDTO).getSchemaRepository();
         doReturn(mockRegistry).when(schemaResourceDTO).getSchemaRegistry();
         final NetconfTopologySetup setup = NetconfTopologySetupBuilder.create().setActorSystem(system)
-                .setIdleTimeout(Duration.apply(1, TimeUnit.SECONDS)).setSchemaResourceDTO(schemaResourceDTO)
+                .setIdleTimeout(Duration.ofSeconds(1)).setSchemaResourceDTO(schemaResourceDTO)
                 .setBaseSchemas(BASE_SCHEMAS).build();
 
         final Props props = NetconfNodeActor.props(setup, remoteDeviceId, TIMEOUT, mockMountPointService);
@@ -257,7 +256,7 @@ public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
 
         // Now initialize - master should send the RegisterMountPoint message.
 
-        List<SourceIdentifier> sourceIdentifiers = Lists.newArrayList(RevisionSourceIdentifier.create("testID"));
+        List<SourceIdentifier> sourceIdentifiers = List.of(new SourceIdentifier("testID"));
         initializeMaster(sourceIdentifiers);
 
         masterRef.tell(new AskForMasterMountPoint(kit.getRef()), kit.getRef());
@@ -426,12 +425,12 @@ public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
         doReturn(repository).when(schemaResourceDTO2).getSchemaRegistry();
         doReturn(repository).when(schemaResourceDTO2).getSchemaRepository();
         final NetconfTopologySetup setup = NetconfTopologySetupBuilder.create().setActorSystem(system)
-                .setSchemaResourceDTO(schemaResourceDTO2).setIdleTimeout(Duration.apply(1, TimeUnit.SECONDS))
+                .setSchemaResourceDTO(schemaResourceDTO2).setIdleTimeout(Duration.ofSeconds(1))
                 .setBaseSchemas(BASE_SCHEMAS).build();
         final Props props = NetconfNodeActor.props(setup, remoteDeviceId, TIMEOUT, mockMountPointService);
         ActorRef actor = TestActorRef.create(system, props, "master_messages_2");
 
-        final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("testID");
+        final SourceIdentifier sourceIdentifier = new SourceIdentifier("testID");
 
         final ProxyYangTextSourceProvider proxyYangProvider =
                 new ProxyYangTextSourceProvider(actor, system.dispatcher(), TIMEOUT);
@@ -443,7 +442,7 @@ public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
 
     @Test
     public void testYangTextSchemaSourceRequest() throws Exception {
-        final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("testID");
+        final SourceIdentifier sourceIdentifier = new SourceIdentifier("testID");
 
         final ProxyYangTextSourceProvider proxyYangProvider =
                 new ProxyYangTextSourceProvider(masterRef, system.dispatcher(), TIMEOUT);
@@ -482,10 +481,7 @@ public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
     @Test
     public void testSlaveInvokeRpc() throws Exception {
 
-        final List<SourceIdentifier> sourceIdentifiers =
-                Lists.newArrayList(RevisionSourceIdentifier.create("testID"));
-
-        initializeMaster(sourceIdentifiers);
+        initializeMaster(List.of(new SourceIdentifier("testID")));
         registerSlaveMountPoint();
 
         ArgumentCaptor<DOMRpcService> domRPCServiceCaptor = ArgumentCaptor.forClass(DOMRpcService.class);
@@ -495,8 +491,8 @@ public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
         assertTrue(slaveDomRPCService instanceof ProxyDOMRpcService);
 
         final QName testQName = QName.create("", "TestQname");
-        final NormalizedNode outputNode = ImmutableContainerNodeBuilder.create()
-                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(testQName))
+        final ContainerNode outputNode = Builders.containerBuilder()
+                .withNodeIdentifier(new NodeIdentifier(testQName))
                 .withChild(ImmutableNodes.leafNode(testQName, "foo")).build();
         final RpcError rpcError = RpcResultBuilder.newError(ErrorType.RPC, null, "Rpc invocation failed.");
 
@@ -515,8 +511,8 @@ public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
 
         result = slaveDomRPCService.invokeRpc(testQName, outputNode).get(2, TimeUnit.SECONDS);
 
-        assertEquals(outputNode, result.getResult());
-        assertTrue(result.getErrors().isEmpty());
+        assertEquals(outputNode, result.value());
+        assertTrue(result.errors().isEmpty());
 
         // RPC with response error.
 
@@ -525,8 +521,8 @@ public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
 
         result = slaveDomRPCService.invokeRpc(testQName, outputNode).get(2, TimeUnit.SECONDS);
 
-        assertNull(result.getResult());
-        assertEquals(rpcError, result.getErrors().iterator().next());
+        assertNull(result.value());
+        assertEquals(rpcError, result.errors().iterator().next());
 
         // RPC with response output and error.
 
@@ -536,8 +532,8 @@ public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
         final DOMRpcResult resultOutputError =
                 slaveDomRPCService.invokeRpc(testQName, outputNode).get(2, TimeUnit.SECONDS);
 
-        assertEquals(outputNode, resultOutputError.getResult());
-        assertEquals(rpcError, resultOutputError.getErrors().iterator().next());
+        assertEquals(outputNode, resultOutputError.value());
+        assertEquals(rpcError, resultOutputError.errors().iterator().next());
 
         // RPC failure.
         doReturn(FluentFutures.immediateFailedFluentFuture(new ClusteringRpcException("mock")))
@@ -552,9 +548,7 @@ public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
 
     @Test
     public void testSlaveInvokeAction() throws Exception {
-        final List<SourceIdentifier> sourceIdentifiers = Lists
-            .newArrayList(RevisionSourceIdentifier.create("testActionID"));
-        initializeMaster(sourceIdentifiers);
+        initializeMaster(List.of(new SourceIdentifier("testActionID")));
         registerSlaveMountPoint();
 
         ArgumentCaptor<DOMActionService> domActionServiceCaptor = ArgumentCaptor.forClass(DOMActionService.class);
@@ -566,14 +560,13 @@ public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
         final QName testQName = QName.create("test", "2019-08-16", "TestActionQname");
         final Absolute schemaPath = Absolute.of(testQName);
 
-        final YangInstanceIdentifier yangIIdPath = YangInstanceIdentifier
-            .create(new YangInstanceIdentifier.NodeIdentifier(testQName));
+        final YangInstanceIdentifier yangIIdPath = YangInstanceIdentifier.create(new NodeIdentifier(testQName));
 
         final DOMDataTreeIdentifier domDataTreeIdentifier = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
             yangIIdPath);
 
-        final ContainerNode outputNode = ImmutableContainerNodeBuilder.create()
-            .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(testQName))
+        final ContainerNode outputNode = Builders.containerBuilder()
+            .withNodeIdentifier(new NodeIdentifier(testQName))
             .withChild(ImmutableNodes.leafNode(testQName, "foo")).build();
 
         // Action with no response output.
@@ -610,7 +603,7 @@ public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
         doReturn(mock(DOMDataTreeReadWriteTransaction.class)).when(mockDOMDataBroker).newReadWriteTransaction();
         doReturn(mock(DOMDataTreeWriteTransaction.class)).when(mockDOMDataBroker).newWriteOnlyTransaction();
 
-        initializeMaster(Collections.emptyList());
+        initializeMaster(List.of());
         registerSlaveMountPoint();
 
         ArgumentCaptor<DOMDataBroker> domDataBrokerCaptor = ArgumentCaptor.forClass(DOMDataBroker.class);
@@ -631,7 +624,7 @@ public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
 
     @Test
     public void testSlaveNewNetconfDataTreeServiceRequest() {
-        initializeMaster(Collections.emptyList());
+        initializeMaster(List.of());
         registerSlaveMountPoint();
 
         ArgumentCaptor<NetconfDataTreeService> netconfCaptor = ArgumentCaptor.forClass(NetconfDataTreeService.class);
@@ -643,7 +636,7 @@ public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
         final YangInstanceIdentifier PATH = YangInstanceIdentifier.empty();
         final LogicalDatastoreType STORE = LogicalDatastoreType.CONFIGURATION;
         final ContainerNode NODE = Builders.containerBuilder()
-            .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create("", "cont")))
+            .withNodeIdentifier(new NodeIdentifier(QName.create("", "cont")))
             .build();
 
         final FluentFuture<Optional<Object>> result = immediateFluentFuture(Optional.of(NODE));
@@ -701,7 +694,7 @@ public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
 
     private void initializeMaster(final List<SourceIdentifier> sourceIdentifiers) {
         masterRef.tell(new CreateInitialMasterActorData(mockDOMDataBroker, netconfService, sourceIdentifiers,
-                mockDOMRpcService, mockDOMActionService), testKit.getRef());
+                new RemoteDeviceServices(mockDOMRpcService, mockDOMActionService)), testKit.getRef());
         testKit.expectMsgClass(MasterActorDataInitialized.class);
     }