import akka.testkit.TestActorRef;
import akka.util.Timeout;
import com.google.common.base.MoreObjects;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
+import com.google.common.net.InetAddresses;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.net.InetAddress;
import java.net.InetSocketAddress;
-import java.net.UnknownHostException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
import org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
-import org.opendaylight.controller.sal.core.api.Broker;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.netconf.topology.singleton.impl.actors.NetconfNodeActor;
import org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException;
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.SchemaSourceException;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
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;
@Mock
private DOMRpcService domRpcService;
+ @Mock
+ private DOMMountPointService mountPointService;
+ @Mock
+ private DataBroker dataBroker;
@Before
- public void setup() throws UnknownHostException {
- initMocks
- (this);
+ public void setup() {
+ initMocks(this);
remoteDeviceId = new RemoteDeviceId("netconf-topology",
- new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 9999));
+ new InetSocketAddress(InetAddresses.forString("127.0.0.1"), 9999));
final NetconfTopologySetup setup = mock(NetconfTopologySetup.class);
final Props props = NetconfNodeActor.props(setup, remoteDeviceId, DEFAULT_SCHEMA_REPOSITORY,
- DEFAULT_SCHEMA_REPOSITORY, TIMEOUT);
+ DEFAULT_SCHEMA_REPOSITORY, TIMEOUT, mountPointService);
system = ActorSystem.create();
/* Test refresh master data */
final RemoteDeviceId remoteDeviceId2 = new RemoteDeviceId("netconf-topology2",
- new InetSocketAddress(InetAddress.getByName("127.0.0.2"), 9999));
+ new InetSocketAddress(InetAddresses.forString("127.0.0.2"), 9999));
final NetconfTopologySetup setup2 = mock(NetconfTopologySetup.class);
final DOMDataBroker domDataBroker = mock(DOMDataBroker.class);
final List<SourceIdentifier> sourceIdentifiers =
- Lists.newArrayList(RevisionSourceIdentifier.create("testID", Optional.absent()));
+ Lists.newArrayList(RevisionSourceIdentifier.create("testID"));
// init master data
@Test
public void testReceiveRegisterMountpoint() throws Exception {
final NetconfTopologySetup setup = mock(NetconfTopologySetup.class);
- doReturn(mock(Broker.class)).when(setup).getDomBroker();
final RevisionSourceIdentifier yang1 = RevisionSourceIdentifier.create("yang1");
final RevisionSourceIdentifier yang2 = RevisionSourceIdentifier.create("yang2");
final SchemaSourceRegistry registry = mock(SchemaSourceRegistry.class);
final SchemaRepository schemaRepository = mock(SchemaRepository.class);
- final SchemaSourceRegistration regYang1 = mock(SchemaSourceRegistration.class);
- final SchemaSourceRegistration regYang2 = mock(SchemaSourceRegistration.class);
+ final SchemaSourceRegistration<?> regYang1 = mock(SchemaSourceRegistration.class);
+ final SchemaSourceRegistration<?> regYang2 = mock(SchemaSourceRegistration.class);
doReturn(regYang1).when(registry).registerSchemaSource(any(), withSourceId(yang1));
doReturn(regYang2).when(registry).registerSchemaSource(any(), withSourceId(yang2));
final SchemaContextFactory schemaContextFactory = mock(SchemaContextFactory.class);
- doReturn(schemaContextFactory).when(schemaRepository).createSchemaContextFactory(any());
+ doReturn(schemaContextFactory).when(schemaRepository).createSchemaContextFactory(any(SchemaSourceFilter.class));
final SettableFuture<SchemaContext> schemaContextFuture = SettableFuture.create();
final CheckedFuture<SchemaContext, SchemaResolutionException> checkedFuture =
Futures.makeChecked(schemaContextFuture, e -> new SchemaResolutionException("fail", e));
doReturn(checkedFuture).when(schemaContextFactory).createSchemaContext(any());
final ActorRef slaveRef =
- system.actorOf(NetconfNodeActor.props(setup, remoteDeviceId, registry, schemaRepository, TIMEOUT));
+ system.actorOf(NetconfNodeActor.props(setup, remoteDeviceId, registry, schemaRepository, TIMEOUT,
+ mountPointService));
final List<SourceIdentifier> sources = ImmutableList.of(yang1, yang2);
slaveRef.tell(new RegisterMountPoint(sources), masterRef);
@Test
public void testYangTextSchemaSourceRequestMessage() throws Exception {
final SchemaRepository schemaRepository = mock(SchemaRepository.class);
- final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("testID", Optional.absent());
+ final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("testID");
final Props props = NetconfNodeActor.props(mock(NetconfTopologySetup.class), remoteDeviceId,
- DEFAULT_SCHEMA_REPOSITORY, schemaRepository, TIMEOUT);
+ DEFAULT_SCHEMA_REPOSITORY, schemaRepository, TIMEOUT, mountPointService);
final ActorRef actorRefSchemaRepo = TestActorRef.create(system, props, "master_mocked_schema_repository");
final ActorContext actorContext = mock(ActorContext.class);
final YangTextSchemaSource yangTextSchemaSource = new YangTextSchemaSource(sourceIdentifier) {
@Override
- protected MoreObjects.ToStringHelper addToStringAttributes(final MoreObjects.ToStringHelper toStringHelper) {
+ protected MoreObjects.ToStringHelper addToStringAttributes(
+ final MoreObjects.ToStringHelper toStringHelper) {
return null;
}
};
- final CheckedFuture<YangTextSchemaSource, SchemaSourceException> result =
- Futures.immediateCheckedFuture(yangTextSchemaSource);
+ final ListenableFuture<YangTextSchemaSource> result = Futures.immediateFuture(yangTextSchemaSource);
doReturn(result).when(schemaRepository).getSchemaSource(sourceIdentifier, YangTextSchemaSource.class);
final DOMDataBroker domDataBroker = mock(DOMDataBroker.class);
final List<SourceIdentifier> sourceIdentifiers =
- Lists.newArrayList(RevisionSourceIdentifier.create("testID", Optional.absent()));
+ Lists.newArrayList(RevisionSourceIdentifier.create("testID"));
// init master data
// test if slave get right identifiers from master
- final ProxyDOMRpcService slaveDomRPCService = new ProxyDOMRpcService(system, masterRef, remoteDeviceId, TIMEOUT);
+ final ProxyDOMRpcService slaveDomRPCService =
+ new ProxyDOMRpcService(system, masterRef, remoteDeviceId, TIMEOUT);
- final SchemaPath schemaPath = SchemaPath.create(true, QName.create("TestQname"));
+ final QName testQName = QName.create("", "TestQname");
+ final SchemaPath schemaPath = SchemaPath.create(true, testQName);
final NormalizedNode<?, ?> outputNode = ImmutableContainerNodeBuilder.create()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create("TestQname")))
- .withChild(ImmutableNodes.leafNode(QName.create("NodeQname"), "foo")).build();
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(testQName))
+ .withChild(ImmutableNodes.leafNode(testQName, "foo")).build();
final RpcError rpcError = RpcResultBuilder.newError(RpcError.ErrorType.RPC, null, "Rpc invocation failed.");
// EmptyResultResponse message
// InvokeRpcMessageReply message
- doReturn(Futures.immediateCheckedFuture(new DefaultDOMRpcResult(outputNode))).
- when(domRpcService).invokeRpc(any(), any());
+ doReturn(Futures.immediateCheckedFuture(new DefaultDOMRpcResult(outputNode)))
+ .when(domRpcService).invokeRpc(any(), any());
final CheckedFuture<DOMRpcResult, DOMRpcException> resultFutureNn =
slaveDomRPCService.invokeRpc(schemaPath, outputNode);