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;
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;
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;
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;
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);
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;
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);
// 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());
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);
@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);
@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);
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.");
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.
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.
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")))
@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);
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.
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);
@Test
public void testSlaveNewNetconfDataTreeServiceRequest() {
- initializeMaster(Collections.emptyList());
+ initializeMaster(List.of());
registerSlaveMountPoint();
ArgumentCaptor<NetconfDataTreeService> netconfCaptor = ArgumentCaptor.forClass(NetconfDataTreeService.class);
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));
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);
}