Search in sources :

Example 1 with NetconfClientSessionListener

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);
}
Also used : NetconfClientSessionListener(org.opendaylight.netconf.client.NetconfClientSessionListener) NetconfNodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder) InetSocketAddress(java.net.InetSocketAddress) NetconfNode(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode) Host(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) LoginPasswordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPasswordBuilder) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) NetconfReconnectingClientConfiguration(org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Test(org.junit.Test)

Example 2 with NetconfClientSessionListener

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();
}
Also used : NetconfClientSessionListener(org.opendaylight.netconf.client.NetconfClientSessionListener) NetconfHelloMessageAdditionalHeader(org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader) ReconnectStrategy(org.opendaylight.netconf.nettyutil.ReconnectStrategy) NetconfClientConfiguration(org.opendaylight.netconf.client.conf.NetconfClientConfiguration) AuthenticationHandler(org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler)

Example 3 with NetconfClientSessionListener

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));
}
Also used : NetconfClientSessionListener(org.opendaylight.netconf.client.NetconfClientSessionListener) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) Test(org.junit.Test)

Example 4 with NetconfClientSessionListener

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));
}
Also used : NetconfClientSessionListener(org.opendaylight.netconf.client.NetconfClientSessionListener) NetconfTerminationReason(org.opendaylight.netconf.api.NetconfTerminationReason) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) Test(org.junit.Test)

Example 5 with NetconfClientSessionListener

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));
}
Also used : NetconfClientSessionListener(org.opendaylight.netconf.client.NetconfClientSessionListener) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) Test(org.junit.Test)

Aggregations

NetconfClientSessionListener (org.opendaylight.netconf.client.NetconfClientSessionListener)9 Test (org.junit.Test)6 NetconfClientSession (org.opendaylight.netconf.client.NetconfClientSession)4 NetconfReconnectingClientConfiguration (org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration)4 NetconfNode (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode)3 NetconfDeviceCapabilities (org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities)2 NetconfDeviceCommunicator (org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator)2 Host (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)2 PortNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber)2 NetconfNodeBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder)2 LoginPasswordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPasswordBuilder)2 BigDecimal (java.math.BigDecimal)1 InetSocketAddress (java.net.InetSocketAddress)1 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)1 NetconfTerminationReason (org.opendaylight.netconf.api.NetconfTerminationReason)1 NetconfHelloMessageAdditionalHeader (org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader)1 NetconfClientConfiguration (org.opendaylight.netconf.client.conf.NetconfClientConfiguration)1 ReconnectStrategy (org.opendaylight.netconf.nettyutil.ReconnectStrategy)1