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);
}
}
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));
}
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));
}
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));
}
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();
}
Aggregations