use of org.opendaylight.netconf.client.NetconfClientSessionListener in project netconf by opendaylight.
the class RemoteDeviceConnectorImplTest method testGetClientConfig.
@Test
public void testGetClientConfig() {
final NetconfClientSessionListener listener = mock(NetconfClientSessionListener.class);
final Host host = new Host(new IpAddress(new Ipv4Address("127.0.0.1")));
final PortNumber portNumber = new PortNumber(Uint16.valueOf(9999));
final NetconfNode testingNode = new NetconfNodeBuilder().setConnectionTimeoutMillis(Uint32.valueOf(1000)).setDefaultRequestTimeoutMillis(Uint32.valueOf(2000)).setHost(host).setPort(portNumber).setCredentials(new LoginPasswordBuilder().setUsername("testuser").setPassword("testpassword").build()).setTcpOnly(true).build();
final RemoteDeviceConnectorImpl remoteDeviceConnection = new RemoteDeviceConnectorImpl(builder.build(), remoteDeviceId, deviceActionFactory);
final NetconfReconnectingClientConfiguration defaultClientConfig = remoteDeviceConnection.getClientConfig(listener, testingNode);
assertEquals(defaultClientConfig.getConnectionTimeoutMillis().longValue(), 1000L);
assertEquals(defaultClientConfig.getAddress(), new InetSocketAddress(InetAddresses.forString("127.0.0.1"), 9999));
assertSame(defaultClientConfig.getSessionListener(), listener);
assertEquals(defaultClientConfig.getAuthHandler().getUsername(), "testuser");
assertEquals(defaultClientConfig.getProtocol(), NetconfClientConfiguration.NetconfClientProtocol.TCP);
}
use of org.opendaylight.netconf.client.NetconfClientSessionListener 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.NetconfClientSessionListener in project netconf by opendaylight.
the class CallHomeMountSessionContextTest method activationOfListenerSupportsSessionUp.
@Test
public void activationOfListenerSupportsSessionUp() {
// given
when(mockActivator.activate(any(NetconfClientSessionListener.class))).thenAnswer(invocationOnMock -> {
NetconfClientSession mockSession = mock(NetconfClientSession.class);
Object arg = invocationOnMock.getArguments()[0];
((NetconfClientSessionListener) arg).onSessionUp(mockSession);
return null;
});
NetconfClientSessionListener mockListener = mock(NetconfClientSessionListener.class);
// when
mockActivator.activate(mockListener);
// then
verify(mockListener, times(1)).onSessionUp(any(NetconfClientSession.class));
}
use of org.opendaylight.netconf.client.NetconfClientSessionListener in project netconf by opendaylight.
the class CallHomeMountSessionContextTest method activationOfListenerSupportsSessionTermination.
@Test
public void activationOfListenerSupportsSessionTermination() {
// given
when(mockActivator.activate(any(NetconfClientSessionListener.class))).thenAnswer(invocationOnMock -> {
NetconfClientSession mockSession = mock(NetconfClientSession.class);
NetconfTerminationReason mockReason = mock(NetconfTerminationReason.class);
Object arg = invocationOnMock.getArguments()[0];
((NetconfClientSessionListener) arg).onSessionTerminated(mockSession, mockReason);
return null;
});
NetconfClientSessionListener mockListener = mock(NetconfClientSessionListener.class);
// when
mockActivator.activate(mockListener);
// then
verify(mockListener, times(1)).onSessionTerminated(any(NetconfClientSession.class), any(NetconfTerminationReason.class));
}
use of org.opendaylight.netconf.client.NetconfClientSessionListener in project netconf by opendaylight.
the class CallHomeMountSessionContextTest method activationOfListenerSupportsSessionMessages.
@Test
public void activationOfListenerSupportsSessionMessages() {
// given
when(mockActivator.activate(any(NetconfClientSessionListener.class))).thenAnswer(invocationOnMock -> {
NetconfClientSession mockSession = mock(NetconfClientSession.class);
NetconfMessage mockMsg = mock(NetconfMessage.class);
Object arg = invocationOnMock.getArguments()[0];
((NetconfClientSessionListener) arg).onMessage(mockSession, mockMsg);
return null;
});
// given
NetconfClientSessionListener mockListener = mock(NetconfClientSessionListener.class);
// when
mockActivator.activate(mockListener);
// then
verify(mockListener, times(1)).onMessage(any(NetconfClientSession.class), any(NetconfMessage.class));
}
Aggregations