Search in sources :

Example 6 with NetconfClientSession

use of org.opendaylight.netconf.client.NetconfClientSession in project lighty-netconf-simulator by PANTHEONtech.

the class ActionDeviceTest method actionsTest.

@Test
public void actionsTest() throws IOException, URISyntaxException, SAXException, InterruptedException, ExecutionException, TimeoutException {
    final SimpleNetconfClientSessionListener sessionListener = new SimpleNetconfClientSessionListener();
    try (NetconfClientSession session = dispatcher.createClient(createSHHConfig(sessionListener)).get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
        final NetconfMessage startActionResponse = sentRequesttoDevice(sessionListener, START_ACTION_REQUEST_XML);
        final String startResultTag = startActionResponse.getDocument().getDocumentElement().getElementsByTagName(START_TAG).item(0).getTextContent();
        assertEquals(startResultTag, START_ACTION_EXPECTED_VALUE);
        final NetconfMessage resetActionResponse = sentRequesttoDevice(sessionListener, RESET_ACTION_REQUEST_XML);
        final String resetResultTag = resetActionResponse.getDocument().getDocumentElement().getElementsByTagName(RESET_TAG).item(0).getTextContent();
        assertEquals(resetResultTag, RESET_ACTION_EXPECTED_VALUE);
    }
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) SimpleNetconfClientSessionListener(org.opendaylight.netconf.client.SimpleNetconfClientSessionListener) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) Test(org.junit.jupiter.api.Test)

Example 7 with NetconfClientSession

use of org.opendaylight.netconf.client.NetconfClientSession 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 8 with NetconfClientSession

use of org.opendaylight.netconf.client.NetconfClientSession 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 9 with NetconfClientSession

use of org.opendaylight.netconf.client.NetconfClientSession 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)

Example 10 with NetconfClientSession

use of org.opendaylight.netconf.client.NetconfClientSession 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();
}
Also used : NetconfClientConfiguration(org.opendaylight.netconf.client.conf.NetconfClientConfiguration) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) SimpleNetconfClientSessionListener(org.opendaylight.netconf.client.SimpleNetconfClientSessionListener) Document(org.w3c.dom.Document) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession)

Aggregations

NetconfClientSession (org.opendaylight.netconf.client.NetconfClientSession)18 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)12 SimpleNetconfClientSessionListener (org.opendaylight.netconf.client.SimpleNetconfClientSessionListener)11 Test (org.junit.jupiter.api.Test)10 Test (org.junit.Test)5 NodeList (org.w3c.dom.NodeList)5 NetconfClientSessionListener (org.opendaylight.netconf.client.NetconfClientSessionListener)4 Element (org.w3c.dom.Element)4 HashedWheelTimer (io.netty.util.HashedWheelTimer)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 NetconfClientConfiguration (org.opendaylight.netconf.client.conf.NetconfClientConfiguration)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)1 InetSocketAddress (java.net.InetSocketAddress)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 NetconfTerminationReason (org.opendaylight.netconf.api.NetconfTerminationReason)1 NetconfClientDispatcherImpl (org.opendaylight.netconf.client.NetconfClientDispatcherImpl)1 NetconfClientSessionNegotiatorFactory (org.opendaylight.netconf.client.NetconfClientSessionNegotiatorFactory)1 TlsClientChannelInitializer (org.opendaylight.netconf.client.TlsClientChannelInitializer)1 Document (org.w3c.dom.Document)1