use of org.opendaylight.netconf.client.conf.NetconfClientConfiguration in project netconf by opendaylight.
the class CallHomeMountDispatcherTest method someConfiguration.
NetconfClientConfiguration someConfiguration(final InetSocketAddress address) {
// NetconfClientConfiguration has mostly final methods, making it un-mock-able
final NetconfClientConfiguration.NetconfClientProtocol protocol = NetconfClientConfiguration.NetconfClientProtocol.SSH;
final NetconfHelloMessageAdditionalHeader additionalHeader = mock(NetconfHelloMessageAdditionalHeader.class);
final NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class);
final ReconnectStrategy reconnectStrategy = mock(ReconnectStrategy.class);
final AuthenticationHandler authHandler = mock(AuthenticationHandler.class);
return NetconfClientConfigurationBuilder.create().withProtocol(protocol).withAddress(address).withConnectionTimeoutMillis(0).withAdditionalHeader(additionalHeader).withSessionListener(sessionListener).withReconnectStrategy(reconnectStrategy).withAuthHandler(authHandler).build();
}
use of org.opendaylight.netconf.client.conf.NetconfClientConfiguration in project netconf by opendaylight.
the class TestToolTest method invokeRpc.
private Document invokeRpc(final Configuration simulatorConfig, final String xmlRequest) throws Exception {
// GIVEN
int localPort = launchSimulator(simulatorConfig);
SimpleNetconfClientSessionListener sessionListener = new SimpleNetconfClientSessionListener();
NetconfClientConfiguration clientConfig = getClientConfig("localhost", localPort, simulatorConfig, sessionListener);
Document docRequest = XmlUtil.readXmlToDocument(xmlRequest);
NetconfMessage request = new NetconfMessage(docRequest);
// WHEN
NetconfMessage response;
try (NetconfClientSession ignored = dispatcher.createClient(clientConfig).get()) {
response = sessionListener.sendRequest(request).get(RECEIVE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
}
// THEN
assertNotNull(response);
return response.getDocument();
}
use of org.opendaylight.netconf.client.conf.NetconfClientConfiguration in project netconf by opendaylight.
the class NetconfClientConfigurationTest method testNetconfClientConfiguration.
@Test
public void testNetconfClientConfiguration() throws Exception {
Long timeout = 200L;
NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader("a", "host", "port", "trans", "id");
NetconfClientSessionListener listener = new SimpleNetconfClientSessionListener();
InetSocketAddress address = InetSocketAddress.createUnresolved("host", 830);
ReconnectStrategy strategy = Mockito.mock(ReconnectStrategy.class);
AuthenticationHandler handler = Mockito.mock(AuthenticationHandler.class);
NetconfClientConfiguration cfg = NetconfClientConfigurationBuilder.create().withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH).withAddress(address).withConnectionTimeoutMillis(timeout).withReconnectStrategy(strategy).withAdditionalHeader(header).withSessionListener(listener).withAuthHandler(handler).build();
Assert.assertEquals(timeout, cfg.getConnectionTimeoutMillis());
Assert.assertEquals(Optional.of(header), cfg.getAdditionalHeader());
Assert.assertEquals(listener, cfg.getSessionListener());
Assert.assertEquals(handler, cfg.getAuthHandler());
Assert.assertEquals(strategy, cfg.getReconnectStrategy());
Assert.assertEquals(NetconfClientConfiguration.NetconfClientProtocol.SSH, cfg.getProtocol());
Assert.assertEquals(address, cfg.getAddress());
SslHandlerFactory sslHandlerFactory = Mockito.mock(SslHandlerFactory.class);
NetconfClientConfiguration cfg2 = NetconfClientConfigurationBuilder.create().withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TLS).withAddress(address).withConnectionTimeoutMillis(timeout).withReconnectStrategy(strategy).withAdditionalHeader(header).withSessionListener(listener).withSslHandlerFactory(sslHandlerFactory).build();
Assert.assertEquals(timeout, cfg2.getConnectionTimeoutMillis());
Assert.assertEquals(Optional.of(header), cfg2.getAdditionalHeader());
Assert.assertEquals(listener, cfg2.getSessionListener());
Assert.assertEquals(sslHandlerFactory, cfg2.getSslHandlerFactory());
Assert.assertEquals(strategy, cfg2.getReconnectStrategy());
Assert.assertEquals(NetconfClientConfiguration.NetconfClientProtocol.TLS, cfg2.getProtocol());
Assert.assertEquals(address, cfg2.getAddress());
}
use of org.opendaylight.netconf.client.conf.NetconfClientConfiguration in project netconf by opendaylight.
the class CallHomeMountDispatcherTest method canCreateASessionFromAConfiguration.
@Test
public void canCreateASessionFromAConfiguration() {
// given
final CallHomeMountSessionContext mockContext = mock(CallHomeMountSessionContext.class);
final InetSocketAddress someAddress = InetSocketAddress.createUnresolved("1.2.3.4", 123);
doReturn(mockContext).when(mockSessMgr).getByAddress(eq(someAddress));
final NetconfClientConfiguration someCfg = someConfiguration(someAddress);
// when
instance.createClient(someCfg);
// then
verify(mockContext, times(1)).activateNetconfChannel(any(NetconfClientSessionListener.class));
}
use of org.opendaylight.netconf.client.conf.NetconfClientConfiguration in project netconf by opendaylight.
the class CallHomeMountDispatcherTest method noSessionIsCreatedWithoutAContextAvailableForAGivenAddress.
@Test
public void noSessionIsCreatedWithoutAContextAvailableForAGivenAddress() {
// given
final InetSocketAddress someAddress = InetSocketAddress.createUnresolved("1.2.3.4", 123);
final NetconfClientConfiguration someCfg = someConfiguration(someAddress);
// when
final Future<NetconfClientSession> future = instance.createClient(someCfg);
// then
assertFalse(future.isSuccess());
}
Aggregations