*/
package org.opendaylight.netconf.topology.singleton.impl;
-import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyCollection;
import static org.mockito.ArgumentMatchers.argThat;
import akka.testkit.javadsl.TestKit;
import akka.util.Timeout;
import com.google.common.collect.ImmutableList;
-import com.google.common.io.ByteSource;
+import com.google.common.io.CharSource;
import com.google.common.net.InetAddresses;
import com.google.common.util.concurrent.FluentFuture;
import com.google.common.util.concurrent.Futures;
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.List;
import java.util.Optional;
-import java.util.Scanner;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMActionException;
-import org.opendaylight.mdsal.dom.api.DOMActionResult;
import org.opendaylight.mdsal.dom.api.DOMActionService;
import org.opendaylight.mdsal.dom.api.DOMDataBroker;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.mdsal.dom.api.DOMRpcService;
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.client.mdsal.api.DeviceNetconfSchemaProvider;
+import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceId;
+import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceServices;
+import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceServices.Actions;
+import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceServices.Rpcs;
import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
-import org.opendaylight.netconf.sal.connect.api.RemoteDeviceId;
-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.topology.singleton.impl.actors.NetconfNodeActor;
import org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringActionException;
import org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException;
import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup;
-import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup.NetconfTopologySetupBuilder;
import org.opendaylight.netconf.topology.singleton.messages.AskForMasterMountPoint;
import org.opendaylight.netconf.topology.singleton.messages.CreateInitialMasterActorData;
import org.opendaylight.netconf.topology.singleton.messages.MasterActorDataInitialized;
import org.opendaylight.netconf.topology.singleton.messages.RegisterMountPoint;
import org.opendaylight.netconf.topology.singleton.messages.UnregisterSlaveMountPoint;
import org.opendaylight.yangtools.concepts.ObjectRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.QName;
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.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
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.SchemaRepository;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
+import org.opendaylight.yangtools.yang.model.spi.source.DelegatedYangTextSource;
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;
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class NetconfNodeActorTest extends AbstractBaseSchemasTest {
+@ExtendWith(MockitoExtension.class)
+class NetconfNodeActorTest extends AbstractBaseSchemasTest {
private static final Timeout TIMEOUT = Timeout.create(Duration.ofSeconds(5));
private static final SourceIdentifier SOURCE_IDENTIFIER1 = new SourceIdentifier("yang1");
private final SharedSchemaRepository masterSchemaRepository = new SharedSchemaRepository("master");
@Mock
- private Rpcs.Normalized mockDOMRpcService;
-
+ private Rpcs.Normalized mockRpc;
+ @Mock
+ private DOMRpcService mockDOMRpcService;
@Mock
private Actions.Normalized mockDOMActionService;
-
@Mock
private DOMMountPointService mockMountPointService;
-
@Mock
private DOMMountPointService.DOMMountPointBuilder mockMountPointBuilder;
-
@Mock
private ObjectRegistration<DOMMountPoint> mockMountPointReg;
-
@Mock
private DOMDataBroker mockDOMDataBroker;
-
@Mock
private NetconfDataTreeService netconfService;
-
@Mock
- private SchemaSourceRegistration<?> mockSchemaSourceReg1;
-
+ private Registration mockSchemaSourceReg1;
@Mock
- private SchemaSourceRegistration<?> mockSchemaSourceReg2;
-
+ private Registration mockSchemaSourceReg2;
@Mock
private SchemaSourceRegistry mockRegistry;
-
@Mock
private EffectiveModelContextFactory mockSchemaContextFactory;
-
@Mock
private SchemaRepository mockSchemaRepository;
-
@Mock
private EffectiveModelContext mockSchemaContext;
-
@Mock
- private SchemaResourcesDTO schemaResourceDTO;
+ private DeviceNetconfSchemaProvider deviceSchemaProvider;
- @Before
- public void setup() {
+ @BeforeEach
+ void setup() {
remoteDeviceId = new RemoteDeviceId("netconf-topology",
new InetSocketAddress(InetAddresses.forString("127.0.0.1"), 9999));
masterSchemaRepository.registerSchemaSourceListener(
TextToIRTransformer.create(masterSchemaRepository, masterSchemaRepository));
- doReturn(masterSchemaRepository).when(schemaResourceDTO).getSchemaRepository();
- doReturn(mockRegistry).when(schemaResourceDTO).getSchemaRegistry();
- final NetconfTopologySetup setup = NetconfTopologySetupBuilder.create().setActorSystem(system)
- .setIdleTimeout(Duration.ofSeconds(1)).setSchemaResourceDTO(schemaResourceDTO)
- .setBaseSchemas(BASE_SCHEMAS).build();
+ final NetconfTopologySetup setup = NetconfTopologySetup.builder()
+ .setActorSystem(system)
+ .setIdleTimeout(Duration.ofSeconds(1))
+ .setDeviceSchemaProvider(deviceSchemaProvider)
+ .setBaseSchemaProvider(BASE_SCHEMAS)
+ .build();
final Props props = NetconfNodeActor.props(setup, remoteDeviceId, TIMEOUT, mockMountPointService);
masterRef = TestActorRef.create(system, props, "master_messages");
-
- resetMountPointMocks();
-
- doReturn(mockMountPointBuilder).when(mockMountPointService).createMountPoint(any());
-
- doReturn(mockSchemaSourceReg1).when(mockRegistry).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER1));
- doReturn(mockSchemaSourceReg2).when(mockRegistry).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER2));
-
- doReturn(mockSchemaContextFactory).when(mockSchemaRepository)
- .createEffectiveModelContextFactory();
}
- @After
- public void teardown() {
+ @AfterEach
+ void teardown() {
TestKit.shutdownActorSystem(system, true);
system = null;
}
@Test
- public void testInitializeAndRefreshMasterData() {
+ void testInitializeAndRefreshMasterData() {
// Test CreateInitialMasterActorData.
final RemoteDeviceId newRemoteDeviceId = new RemoteDeviceId("netconf-topology2",
new InetSocketAddress(InetAddresses.forString("127.0.0.2"), 9999));
- final NetconfTopologySetup newSetup = NetconfTopologySetupBuilder.create().setBaseSchemas(BASE_SCHEMAS)
- .setSchemaResourceDTO(schemaResourceDTO).setActorSystem(system).build();
+ final NetconfTopologySetup newSetup = NetconfTopologySetup.builder()
+ .setBaseSchemaProvider(BASE_SCHEMAS)
+ .setDeviceSchemaProvider(deviceSchemaProvider)
+ .setActorSystem(system)
+ .build();
masterRef.tell(new RefreshSetupMasterActorData(newSetup, newRemoteDeviceId), testKit.getRef());
}
@Test
- public void testAskForMasterMountPoint() {
+ void testAskForMasterMountPoint() {
// Test with master not setup yet.
masterRef.tell(new AskForMasterMountPoint(kit.getRef()), kit.getRef());
final Failure failure = kit.expectMsgClass(Failure.class);
- assertTrue(failure.cause() instanceof NotMasterException);
+ assertInstanceOf(NotMasterException.class, failure.cause());
// Now initialize - master should send the RegisterMountPoint message.
}
@Test
- public void testRegisterAndUnregisterMountPoint() throws Exception {
+ void testRegisterAndUnregisterMountPoint() throws Exception {
+ resetMountPointMocks();
+ doReturn(mockMountPointBuilder).when(mockMountPointService).createMountPoint(any());
+ doReturn(mockSchemaSourceReg1).when(mockRegistry).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER1));
+ doReturn(mockSchemaSourceReg2).when(mockRegistry).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER2));
+ doReturn(mockSchemaContextFactory).when(mockSchemaRepository).createEffectiveModelContextFactory();
ActorRef slaveRef = registerSlaveMountPoint();
doReturn(mockSchemaSourceReg1).when(mockRegistry).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER1));
- final SchemaSourceRegistration<?> newMockSchemaSourceReg = mock(SchemaSourceRegistration.class);
+ final var newMockSchemaSourceReg = mock(Registration.class);
final EffectiveModelContextFactory newMockSchemaContextFactory = mock(EffectiveModelContextFactory.class);
doReturn(Futures.immediateFuture(mockSchemaContext))
verify(newMockSchemaSourceReg).close();
}
- @SuppressWarnings("unchecked")
@Test
- public void testRegisterMountPointWithSchemaFailures() throws Exception {
- SchemaResourcesDTO schemaResourceDTO2 = mock(SchemaResourcesDTO.class);
- doReturn(mockRegistry).when(schemaResourceDTO2).getSchemaRegistry();
- doReturn(mockSchemaRepository).when(schemaResourceDTO2).getSchemaRepository();
- final NetconfTopologySetup setup = NetconfTopologySetupBuilder.create()
- .setSchemaResourceDTO(schemaResourceDTO2)
- .setBaseSchemas(BASE_SCHEMAS)
+ void testRegisterMountPointWithSchemaFailures() {
+ resetMountPointMocks();
+ doReturn(mockMountPointBuilder).when(mockMountPointService).createMountPoint(any());
+ doReturn(mockSchemaSourceReg1).when(mockRegistry).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER1));
+ doReturn(mockSchemaSourceReg2).when(mockRegistry).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER2));
+ doReturn(mockSchemaContextFactory).when(mockSchemaRepository).createEffectiveModelContextFactory();
+
+ var deviceSchemaProvider2 = mock(DeviceNetconfSchemaProvider.class);
+ doReturn(mockRegistry).when(deviceSchemaProvider2).registry();
+ doReturn(mockSchemaRepository).when(deviceSchemaProvider2).repository();
+ final NetconfTopologySetup setup = NetconfTopologySetup.builder()
+ .setDeviceSchemaProvider(deviceSchemaProvider2)
+ .setBaseSchemaProvider(BASE_SCHEMAS)
.setActorSystem(system)
.build();
// Test unrecoverable failure.
- doReturn(Futures.immediateFailedFuture(new SchemaResolutionException("mock")))
+ doReturn(Futures.immediateFailedFuture(
+ new SchemaResolutionException("mock", new SourceIdentifier("foo"), null)))
.when(mockSchemaContextFactory).createEffectiveModelContext(anyCollection());
slaveRef.tell(new RegisterMountPoint(ImmutableList.of(SOURCE_IDENTIFIER1, SOURCE_IDENTIFIER2),
reset(mockSchemaSourceReg1, mockSchemaSourceReg2);
- doReturn(Futures.immediateFailedFuture(new SchemaResolutionException("mock",
+ doReturn(Futures.immediateFailedFuture(new SchemaResolutionException("mock", new SourceIdentifier("foo"),
new AskTimeoutException("timeout"))))
.doReturn(Futures.immediateFuture(mockSchemaContext))
.when(mockSchemaContextFactory).createEffectiveModelContext(anyCollection());
slaveRef.tell(new RegisterMountPoint(ImmutableList.of(SOURCE_IDENTIFIER1, SOURCE_IDENTIFIER2),
masterRef), testKit.getRef());
- future.setException(new SchemaResolutionException("mock", new AskTimeoutException("timeout")));
+ future.setException(new SchemaResolutionException("mock", new SourceIdentifier("foo"),
+ new AskTimeoutException("timeout")));
}).start();
return future;
}).when(mockSchemaContextFactory).createEffectiveModelContext(anyCollection());
verify(mockSchemaRepository, times(2)).createEffectiveModelContextFactory();
}
- @Test(expected = MissingSchemaSourceException.class)
- public void testMissingSchemaSourceOnMissingProvider() throws Exception {
- final SharedSchemaRepository repository = new SharedSchemaRepository("test");
-
- SchemaResourcesDTO schemaResourceDTO2 = mock(SchemaResourcesDTO.class);
- doReturn(repository).when(schemaResourceDTO2).getSchemaRegistry();
- doReturn(repository).when(schemaResourceDTO2).getSchemaRepository();
- final NetconfTopologySetup setup = NetconfTopologySetupBuilder.create().setActorSystem(system)
- .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");
+ @Test
+ void testMissingSchemaSourceOnMissingProvider() {
+ final var repository = new SharedSchemaRepository("test");
+
+ final var deviceSchemaProvider2 = mock(DeviceNetconfSchemaProvider.class);
+ doReturn(repository).when(deviceSchemaProvider2).repository();
+ final var setup = NetconfTopologySetup.builder()
+ .setActorSystem(system)
+ .setDeviceSchemaProvider(deviceSchemaProvider2)
+ .setIdleTimeout(Duration.ofSeconds(1))
+ .setBaseSchemaProvider(BASE_SCHEMAS)
+ .build();
+ final var props = NetconfNodeActor.props(setup, remoteDeviceId, TIMEOUT, mockMountPointService);
+ final var actor = TestActorRef.create(system, props, "master_messages_2");
- final SourceIdentifier sourceIdentifier = new SourceIdentifier("testID");
+ final var sourceIdentifier = new SourceIdentifier("testID");
- final ProxyYangTextSourceProvider proxyYangProvider =
- new ProxyYangTextSourceProvider(actor, system.dispatcher(), TIMEOUT);
+ final var proxyYangProvider = new ProxyYangTextSourceProvider(actor, system.dispatcher(), TIMEOUT);
- final Future<YangTextSchemaSourceSerializationProxy> resolvedSchemaFuture =
- proxyYangProvider.getYangTextSchemaSource(sourceIdentifier);
- Await.result(resolvedSchemaFuture, TIMEOUT.duration());
+ final var resolvedSchemaFuture = proxyYangProvider.getYangTextSchemaSource(sourceIdentifier);
+ final var ex = assertThrows(MissingSchemaSourceException.class,
+ () -> Await.result(resolvedSchemaFuture, TIMEOUT.duration()));
+ assertEquals("No providers registered for source SourceIdentifier [testID]", ex.getMessage());
}
@Test
- public void testYangTextSchemaSourceRequest() throws Exception {
- final SourceIdentifier sourceIdentifier = new SourceIdentifier("testID");
-
- final ProxyYangTextSourceProvider proxyYangProvider =
- new ProxyYangTextSourceProvider(masterRef, system.dispatcher(), TIMEOUT);
+ void testYangTextSchemaSourceRequest() throws Exception {
+ doReturn(masterSchemaRepository).when(deviceSchemaProvider).repository();
- final YangTextSchemaSource yangTextSchemaSource = YangTextSchemaSource.delegateForByteSource(sourceIdentifier,
- ByteSource.wrap("YANG".getBytes(UTF_8)));
+ final var sourceIdentifier = new SourceIdentifier("testID");
- // Test success.
+ final var proxyYangProvider = new ProxyYangTextSourceProvider(masterRef, system.dispatcher(), TIMEOUT);
- final SchemaSourceRegistration<YangTextSchemaSource> schemaSourceReg = masterSchemaRepository
- .registerSchemaSource(id -> Futures.immediateFuture(yangTextSchemaSource),
- PotentialSchemaSource.create(sourceIdentifier, YangTextSchemaSource.class, 1));
+ final var yangTextSchemaSource = new DelegatedYangTextSource(sourceIdentifier, CharSource.wrap("YANG"));
- final Future<YangTextSchemaSourceSerializationProxy> resolvedSchemaFuture =
- proxyYangProvider.getYangTextSchemaSource(sourceIdentifier);
+ // Test success.
- final YangTextSchemaSourceSerializationProxy success = Await.result(resolvedSchemaFuture, TIMEOUT.duration());
+ try (var schemaSourceReg = masterSchemaRepository.registerSchemaSource(
+ id -> Futures.immediateFuture(yangTextSchemaSource),
+ PotentialSchemaSource.create(sourceIdentifier, YangTextSource.class, 1))) {
+ final var resolvedSchemaFuture = proxyYangProvider.getYangTextSchemaSource(sourceIdentifier);
+ final var success = Await.result(resolvedSchemaFuture, TIMEOUT.duration());
- assertEquals(sourceIdentifier, success.getRepresentation().getIdentifier());
- assertEquals("YANG", convertStreamToString(success.getRepresentation().openStream()));
+ assertEquals(sourceIdentifier, success.getRepresentation().sourceId());
+ assertEquals("YANG", success.getRepresentation().read());
+ }
// Test missing source failure.
- schemaSourceReg.close();
-
- final MissingSchemaSourceException ex = assertThrows(MissingSchemaSourceException.class,
- () -> {
- final Future<YangTextSchemaSourceSerializationProxy> failedSchemaFuture =
- proxyYangProvider.getYangTextSchemaSource(sourceIdentifier);
- Await.result(failedSchemaFuture, TIMEOUT.duration());
- });
+ final var failedSchemaFuture = proxyYangProvider.getYangTextSchemaSource(sourceIdentifier);
+ final var ex = assertThrows(MissingSchemaSourceException.class,
+ () -> Await.result(failedSchemaFuture, TIMEOUT.duration()));
assertThat(ex.getMessage(), startsWith("No providers registered for source"));
assertThat(ex.getMessage(), containsString(sourceIdentifier.toString()));
}
@Test
- public void testSlaveInvokeRpc() throws Exception {
+ void testSlaveInvokeRpc() throws Exception {
+ resetMountPointMocks();
+ doReturn(mockMountPointBuilder).when(mockMountPointService).createMountPoint(any());
+ doReturn(mockSchemaSourceReg1).when(mockRegistry).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER1));
+ doReturn(mockSchemaSourceReg2).when(mockRegistry).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER2));
+ doReturn(mockSchemaContextFactory).when(mockSchemaRepository).createEffectiveModelContextFactory();
+ doReturn(mockDOMRpcService).when(mockRpc).domRpcService();
initializeMaster(List.of(new SourceIdentifier("testID")));
registerSlaveMountPoint();
verify(mockMountPointBuilder).addService(eq(DOMRpcService.class), domRPCServiceCaptor.capture());
final DOMRpcService slaveDomRPCService = domRPCServiceCaptor.getValue();
- assertTrue(slaveDomRPCService instanceof ProxyDOMRpcService);
+ assertInstanceOf(ProxyDOMRpcService.class, slaveDomRPCService);
final QName testQName = QName.create("", "TestQname");
- final ContainerNode outputNode = Builders.containerBuilder()
+ final ContainerNode outputNode = ImmutableNodes.newContainerBuilder()
.withNodeIdentifier(new NodeIdentifier(testQName))
.withChild(ImmutableNodes.leafNode(testQName, "foo")).build();
final RpcError rpcError = RpcResultBuilder.newError(ErrorType.RPC, null, "Rpc invocation failed.");
final ExecutionException e = assertThrows(ExecutionException.class, () -> future.get(2, TimeUnit.SECONDS));
final Throwable cause = e.getCause();
- assertThat(cause, instanceOf(DOMRpcException.class));
+ assertInstanceOf(DOMRpcException.class, cause);
assertEquals("mock", cause.getMessage());
}
@Test
- public void testSlaveInvokeAction() throws Exception {
+ void testSlaveInvokeAction() throws Exception {
+ resetMountPointMocks();
+ doReturn(mockMountPointBuilder).when(mockMountPointService).createMountPoint(any());
+ doReturn(mockSchemaSourceReg1).when(mockRegistry).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER1));
+ doReturn(mockSchemaSourceReg2).when(mockRegistry).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER2));
+ doReturn(mockSchemaContextFactory).when(mockSchemaRepository).createEffectiveModelContextFactory();
+ doReturn(mockDOMRpcService).when(mockRpc).domRpcService();
+
initializeMaster(List.of(new SourceIdentifier("testActionID")));
registerSlaveMountPoint();
- ArgumentCaptor<DOMActionService> domActionServiceCaptor = ArgumentCaptor.forClass(DOMActionService.class);
+ final var domActionServiceCaptor = ArgumentCaptor.forClass(DOMActionService.class);
verify(mockMountPointBuilder).addService(eq(DOMActionService.class), domActionServiceCaptor.capture());
final DOMActionService slaveDomActionService = domActionServiceCaptor.getValue();
- assertTrue(slaveDomActionService instanceof ProxyDOMActionService);
+ assertInstanceOf(ProxyDOMActionService.class, slaveDomActionService);
final QName testQName = QName.create("test", "2019-08-16", "TestActionQname");
final Absolute schemaPath = Absolute.of(testQName);
- final YangInstanceIdentifier yangIIdPath = YangInstanceIdentifier.create(new NodeIdentifier(testQName));
+ final YangInstanceIdentifier yangIIdPath = YangInstanceIdentifier.of(testQName);
- final DOMDataTreeIdentifier domDataTreeIdentifier = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
+ final DOMDataTreeIdentifier domDataTreeIdentifier = DOMDataTreeIdentifier.of(LogicalDatastoreType.OPERATIONAL,
yangIIdPath);
- final ContainerNode outputNode = Builders.containerBuilder()
+ final ContainerNode outputNode = ImmutableNodes.newContainerBuilder()
.withNodeIdentifier(new NodeIdentifier(testQName))
.withChild(ImmutableNodes.leafNode(testQName, "foo")).build();
// Action with no response output.
doReturn(FluentFutures.immediateNullFluentFuture()).when(mockDOMActionService)
.invokeAction(any(), any(), any());
- DOMActionResult result = slaveDomActionService.invokeAction(schemaPath, domDataTreeIdentifier, outputNode)
+ var result = slaveDomActionService.invokeAction(schemaPath, domDataTreeIdentifier, outputNode)
.get(2, TimeUnit.SECONDS);
assertEquals(null, result);
// Action with response output.
- doReturn(FluentFutures.immediateFluentFuture(new SimpleDOMActionResult(outputNode))).when(mockDOMActionService)
+ doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(outputNode))).when(mockDOMActionService)
.invokeAction(any(), any(), any());
result = slaveDomActionService.invokeAction(schemaPath, domDataTreeIdentifier, outputNode)
.get(2, TimeUnit.SECONDS);
- assertEquals(outputNode, result.getOutput().get());
- assertTrue(result.getErrors().isEmpty());
+ assertEquals(outputNode, result.value());
+ assertTrue(result.errors().isEmpty());
// Action failure.
doReturn(FluentFutures.immediateFailedFluentFuture(new ClusteringActionException("mock")))
.when(mockDOMActionService).invokeAction(any(), any(), any());
- final ListenableFuture<? extends DOMActionResult> future = slaveDomActionService.invokeAction(schemaPath,
- domDataTreeIdentifier, outputNode);
+ final var future = slaveDomActionService.invokeAction(schemaPath, domDataTreeIdentifier, outputNode);
final ExecutionException e = assertThrows(ExecutionException.class, () -> future.get(2, TimeUnit.SECONDS));
final Throwable cause = e.getCause();
- assertThat(cause, instanceOf(DOMActionException.class));
+ assertInstanceOf(DOMActionException.class, cause);
assertEquals("mock", cause.getMessage());
}
@Test
- public void testSlaveNewTransactionRequests() {
+ void testSlaveNewTransactionRequests() {
+ resetMountPointMocks();
+ doReturn(mockMountPointBuilder).when(mockMountPointService).createMountPoint(any());
+ doReturn(mockSchemaSourceReg1).when(mockRegistry).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER1));
+ doReturn(mockSchemaSourceReg2).when(mockRegistry).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER2));
+ doReturn(mockSchemaContextFactory).when(mockSchemaRepository).createEffectiveModelContextFactory();
+ doReturn(mockDOMRpcService).when(mockRpc).domRpcService();
+
doReturn(mock(DOMDataTreeReadTransaction.class)).when(mockDOMDataBroker).newReadOnlyTransaction();
doReturn(mock(DOMDataTreeReadWriteTransaction.class)).when(mockDOMDataBroker).newReadWriteTransaction();
doReturn(mock(DOMDataTreeWriteTransaction.class)).when(mockDOMDataBroker).newWriteOnlyTransaction();
initializeMaster(List.of());
registerSlaveMountPoint();
- ArgumentCaptor<DOMDataBroker> domDataBrokerCaptor = ArgumentCaptor.forClass(DOMDataBroker.class);
+ final var domDataBrokerCaptor = ArgumentCaptor.forClass(DOMDataBroker.class);
verify(mockMountPointBuilder).addService(eq(DOMDataBroker.class), domDataBrokerCaptor.capture());
final DOMDataBroker slaveDOMDataBroker = domDataBrokerCaptor.getValue();
- assertTrue(slaveDOMDataBroker instanceof ProxyDOMDataBroker);
+ assertInstanceOf(ProxyDOMDataBroker.class, slaveDOMDataBroker);
slaveDOMDataBroker.newReadOnlyTransaction();
verify(mockDOMDataBroker).newReadOnlyTransaction();
}
@Test
- public void testSlaveNewNetconfDataTreeServiceRequest() {
+ void testSlaveNewNetconfDataTreeServiceRequest() {
+ doReturn(mockMountPointBuilder).when(mockMountPointService).createMountPoint(any());
+ doReturn(mockSchemaSourceReg1).when(mockRegistry).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER1));
+ doReturn(mockSchemaSourceReg2).when(mockRegistry).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER2));
+ doReturn(mockSchemaContextFactory).when(mockSchemaRepository).createEffectiveModelContextFactory();
+ doReturn(mockDOMRpcService).when(mockRpc).domRpcService();
+
initializeMaster(List.of());
registerSlaveMountPoint();
verify(mockMountPointBuilder).addService(eq(NetconfDataTreeService.class), netconfCaptor.capture());
final NetconfDataTreeService slaveNetconfService = netconfCaptor.getValue();
- assertTrue(slaveNetconfService instanceof ProxyNetconfDataTreeService);
+ assertInstanceOf(ProxyNetconfDataTreeService.class, slaveNetconfService);
- final YangInstanceIdentifier PATH = YangInstanceIdentifier.empty();
+ final YangInstanceIdentifier PATH = YangInstanceIdentifier.of();
final LogicalDatastoreType STORE = LogicalDatastoreType.CONFIGURATION;
- final ContainerNode NODE = Builders.containerBuilder()
+ final ContainerNode NODE = ImmutableNodes.newContainerBuilder()
.withNodeIdentifier(new NodeIdentifier(QName.create("", "cont")))
.build();
}
private ActorRef registerSlaveMountPoint() {
- SchemaResourcesDTO schemaResourceDTO2 = mock(SchemaResourcesDTO.class);
- doReturn(mockRegistry).when(schemaResourceDTO2).getSchemaRegistry();
- doReturn(mockSchemaRepository).when(schemaResourceDTO2).getSchemaRepository();
- final ActorRef slaveRef = system.actorOf(NetconfNodeActor.props(
- NetconfTopologySetupBuilder.create().setSchemaResourceDTO(schemaResourceDTO2).setActorSystem(system)
- .setBaseSchemas(BASE_SCHEMAS).build(), remoteDeviceId, TIMEOUT, mockMountPointService));
+ var deviceSchemaProvider2 = mock(DeviceNetconfSchemaProvider.class);
+ doReturn(mockRegistry).when(deviceSchemaProvider2).registry();
+ doReturn(mockSchemaRepository).when(deviceSchemaProvider2).repository();
+ final ActorRef slaveRef = system.actorOf(NetconfNodeActor.props(NetconfTopologySetup.builder()
+ .setDeviceSchemaProvider(deviceSchemaProvider2)
+ .setActorSystem(system)
+ .setBaseSchemaProvider(BASE_SCHEMAS)
+ .build(), remoteDeviceId, TIMEOUT, mockMountPointService));
doReturn(Futures.immediateFuture(mockSchemaContext))
.when(mockSchemaContextFactory).createEffectiveModelContext(anyCollection());
private void initializeMaster(final List<SourceIdentifier> sourceIdentifiers) {
masterRef.tell(new CreateInitialMasterActorData(mockDOMDataBroker, netconfService, sourceIdentifiers,
- new RemoteDeviceServices(mockDOMRpcService, mockDOMActionService)), testKit.getRef());
+ new RemoteDeviceServices(mockRpc, mockDOMActionService)), testKit.getRef());
testKit.expectMsgClass(MasterActorDataInitialized.class);
}
private static PotentialSchemaSource<?> withSourceId(final SourceIdentifier identifier) {
return argThat(argument -> identifier.equals(argument.getSourceIdentifier()));
}
-
- private static String convertStreamToString(final InputStream is) {
- try (Scanner scanner = new Scanner(is)) {
- return scanner.useDelimiter("\\A").hasNext() ? scanner.next() : "";
- }
- }
}