NetconfConnectionManagerImpl implements NetconfConnectionManager, CallHomeListener { @Override public <RT> RT executeWithSession(Device device, NetconfTemplate<RT> netconfTemplate) throws IllegalStateException, ExecutionException { if (!isConnected(device)) { throw new IllegalStateException(String.format("Device not connected : %s", device.getDeviceName())); } NetconfClientSession deviceSession = null; try { deviceSession = m_connPool.borrowObject(device); return netconfTemplate.execute(deviceSession); } catch (Exception e) { throw new ExecutionException(e); } finally { if (deviceSession != null) { m_connPool.returnObject(device, deviceSession); } } } NetconfConnectionManagerImpl(CallHomeListenerComposite callHomeListenerComposite,
                                        NetconfClientDispatcher dispatcher); DeviceDao getDeviceDao(); void setDeviceDao(DeviceDao deviceDao); TxService getTxService(); void setTxService(TxService txService); static void fillTransportDetails(Authentication authentication, NetconfClientConfigurationBuilder
            configurationBuilder); Map<String, List<DefaultPooledObjectInfo>> getAllSessions(); @Override Future<NetConfResponse> executeNetconf(Device device, AbstractNetconfRequest request); @Override Future<NetConfResponse> executeNetconf(String deviceName, AbstractNetconfRequest request); @Override RT executeWithSession(Device device, NetconfTemplate<RT> netconfTemplate); @Override boolean isConnected(Device device); @Override ConnectionState getConnectionState(Device device); @Override List<NewDeviceInfo> getNewDevices(); @Override void dropNewDeviceConnection(String duid); @Override void registerDeviceConnectionListener(ConnectionListener connectionListener); @Override void unregisterDeviceConnectionListener(ConnectionListener connectionListener); void init(); @Override void connectionEstablished(NetconfClientSession deviceSession, NetconfLoginProvider netconfLoginProvider,
                                      X509Certificate deviceCert, boolean isSelfSigned); String extractDuid(X509Certificate x509Certificate, String ipAddress, Integer port); void destroy();  }
@Test public void testExecuteNetconfTemplateThrowsIllegalStateException() throws Exception { AbstractNetconfRequest request = mock(AbstractNetconfRequest.class); try { m_cm.executeWithSession(createDirectDevice("1"), session -> { try { return session.sendRpc(request); } catch (NetconfMessageBuilderException e) { fail("un expected exception" + e.getMessage()); } return null; }); fail("Expected an IllegalStateException here"); } catch (IllegalStateException e) { assertEquals("Device not connected : 1", e.getMessage()); } }