import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
+import akka.util.Timeout;
+import com.google.common.util.concurrent.Futures;
import io.netty.util.concurrent.EventExecutor;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import org.mockito.Mock;
import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
import org.opendaylight.controller.config.threadpool.ThreadPool;
+import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
-import org.opendaylight.controller.sal.core.api.Broker;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
import org.opendaylight.netconf.client.NetconfClientDispatcher;
import org.opendaylight.netconf.client.NetconfClientSessionListener;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfConnectorDTO;
import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup;
+import org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologyUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
+import scala.concurrent.duration.Duration;
public class RemoteDeviceConnectorImplTest {
private static final NodeId NODE_ID = new NodeId("testing-node");
private static final String TOPOLOGY_ID = "testing-topology";
+ private static final Timeout TIMEOUT = new Timeout(Duration.create(5, "seconds"));
@Mock
private DataBroker dataBroker;
@Mock
private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
- @Mock
- private BindingAwareBroker bindingAwareBroker;
-
@Mock
private ScheduledThreadPool keepaliveExecutor;
@Mock
private ThreadPool processingExecutor;
- @Mock
- private Broker domBroker;
-
@Mock
private ActorSystem actorSystem;
@Mock
private NetconfClientDispatcher clientDispatcher;
+ @Mock
+ private DOMMountPointService mountPointService;
+
+ @Mock
+ private BindingTransactionChain txChain;
+
+ @Mock
+ private WriteTransaction writeTx;
+
private NetconfTopologySetup.NetconfTopologySetupBuilder builder;
private RemoteDeviceId remoteDeviceId;
remoteDeviceId = new RemoteDeviceId(TOPOLOGY_ID,
new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 9999));
+ doReturn(txChain).when(dataBroker).createTransactionChain(any(TransactionChainListener.class));
+ doReturn(writeTx).when(txChain).newWriteOnlyTransaction();
+ doNothing().when(writeTx).merge(eq(LogicalDatastoreType.OPERATIONAL), any(), any());
+ doReturn("Some object").when(writeTx).getIdentifier();
+ doReturn(Futures.immediateCheckedFuture(null)).when(writeTx).submit();
builder = new NetconfTopologySetup.NetconfTopologySetupBuilder();
builder.setDataBroker(dataBroker);
builder.setRpcProviderRegistry(rpcProviderRegistry);
builder.setClusterSingletonServiceProvider(clusterSingletonServiceProvider);
- builder.setBindingAwareBroker(bindingAwareBroker);
builder.setKeepaliveExecutor(keepaliveExecutor);
builder.setProcessingExecutor(processingExecutor);
- builder.setDomBroker(domBroker);
builder.setActorSystem(actorSystem);
builder.setEventExecutor(eventExecutor);
builder.setNetconfClientDispatcher(clientDispatcher);
builder.setTopologyId(TOPOLOGY_ID);
-
}
@Test
final RemoteDeviceHandler salFacade = mock(RemoteDeviceHandler.class);
final TestingRemoteDeviceConnectorImpl remoteDeviceConnection =
- new TestingRemoteDeviceConnectorImpl(builder.build(), remoteDeviceId, communicator, salFacade);
+ new TestingRemoteDeviceConnectorImpl(builder.build(), remoteDeviceId, communicator, salFacade, TIMEOUT,
+ mountPointService);
final ActorRef masterRef = mock(ActorRef.class);
.setCredentials(credentials)
.build();
+ final Node node = new NodeBuilder().setNodeId(NODE_ID).addAugmentation(NetconfNode.class, netconfNode).build();
+ builder.setSchemaResourceDTO(NetconfTopologyUtils.setupSchemaCacheDTO(node));
final RemoteDeviceConnectorImpl remoteDeviceConnection =
- new RemoteDeviceConnectorImpl(builder.build(), remoteDeviceId);
+ new RemoteDeviceConnectorImpl(builder.build(), remoteDeviceId, TIMEOUT, mountPointService);
final ActorRef masterRef = mock(ActorRef.class);
final RemoteDeviceId remoteDeviceId = new RemoteDeviceId(TOPOLOGY_ID,
new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 9999));
+ final Node node = new NodeBuilder().setNodeId(NODE_ID).addAugmentation(NetconfNode.class, netconfNode).build();
+ builder.setSchemaResourceDTO(NetconfTopologyUtils.setupSchemaCacheDTO(node));
final RemoteDeviceConnectorImpl remoteDeviceConnection =
- new RemoteDeviceConnectorImpl(builder.build(), remoteDeviceId);
+ new RemoteDeviceConnectorImpl(builder.build(), remoteDeviceId, TIMEOUT, mountPointService);
final ActorRef masterRef = mock(ActorRef.class);
.build();
final RemoteDeviceConnectorImpl remoteDeviceConnection =
- new RemoteDeviceConnectorImpl(builder.build(), remoteDeviceId);
+ new RemoteDeviceConnectorImpl(builder.build(), remoteDeviceId, TIMEOUT, mountPointService);
final NetconfReconnectingClientConfiguration defaultClientConfig =
remoteDeviceConnection.getClientConfig(listener, testingNode);
assertEquals(defaultClientConfig.getAuthHandler().getUsername(), "testuser");
assertEquals(defaultClientConfig.getProtocol(), NetconfClientConfiguration.NetconfClientProtocol.TCP);
}
-
- @Test
- public void testSchemaResourceDTO() throws UnknownHostException {
- final ExecutorService executorService = mock(ExecutorService.class);
- doReturn(executorService).when(processingExecutor).getExecutor();
-
- final Credentials credentials = new LoginPasswordBuilder().setPassword("admin").setUsername("admin").build();
- final NetconfNode netconfNode = new NetconfNodeBuilder()
- .setHost(new Host(new IpAddress(new Ipv4Address("127.0.0.1"))))
- .setPort(new PortNumber(9999))
- .setReconnectOnChangedSchema(true)
- .setDefaultRequestTimeoutMillis(1000L)
- .setBetweenAttemptsTimeoutMillis(100)
- .setSchemaless(false)
- .setTcpOnly(false)
- .setCredentials(credentials)
- .setSchemaCacheDirectory("schemas-test")
- .build();
-
- final RemoteDeviceConnectorImpl remoteDeviceConnection =
- new RemoteDeviceConnectorImpl(builder.build(), remoteDeviceId);
-
- final ActorRef masterRef = mock(ActorRef.class);
-
- remoteDeviceConnection.createDeviceCommunicator(NODE_ID, netconfNode, masterRef);
-
- assertTrue(remoteDeviceConnection.getSchemaResourcesDTOs().containsKey("schemas-test"));
- }
-
}