use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener in project open-smart-grid-platform by OSGP.
the class DlmsConnectionFactoryTest method setsIpAddressWhenConnectingToTheDevice.
@Test
void setsIpAddressWhenConnectingToTheDevice() throws Exception {
final DlmsDevice device = new DlmsDeviceBuilder().withHls5Active(true).withIpAddress(null).withIpAddressStatic(false).build();
final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
when(this.hls5Connector.connect(this.messageMetadata, device, listener)).thenReturn(this.connection);
this.factory.createAndHandleConnection(this.messageMetadata, device, listener, this.task);
verify(this.domainHelperService).setIpAddressFromMessageMetadataOrSessionProvider(device, this.messageMetadata);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener in project open-smart-grid-platform by OSGP.
the class DlmsConnectionFactoryTest method createAndHandleConnectionThrowsForHls4Device.
@Test
void createAndHandleConnectionThrowsForHls4Device() {
final DlmsDevice device = new DlmsDeviceBuilder().withHls4Active(true).build();
final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
assertThatExceptionOfType(FunctionalException.class).isThrownBy(() -> this.factory.createAndHandleConnection(this.messageMetadata, device, listener, this.task));
}
use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener in project open-smart-grid-platform by OSGP.
the class DlmsConnectionFactoryTest method createsConnectionManagerForLls1Device.
@Test
void createsConnectionManagerForLls1Device() throws Exception {
final DlmsDevice device = new DlmsDeviceBuilder().withLls1Active(true).build();
final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
when(this.lls1Connector.connect(this.messageMetadata, device, listener)).thenReturn(this.connection);
final DlmsConnectionManager expected = this.newConnectionManager(device, listener, this.lls1Connector);
this.factory.createAndHandleConnection(this.messageMetadata, device, listener, this.task);
this.assertConnectionManagerForDevice(expected);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener in project open-smart-grid-platform by OSGP.
the class SecureDlmsConnector method createConnection.
/**
* Create a connection with the device.
*
* @param messageMetadata the metadata of the request message
* @param device The device to connect with.
* @param dlmsMessageListener Listener to set on the connection.
* @return The connection.
* @throws IOException When there are problems in connecting to or communicating with the device.
* @throws OsgpException When there are problems reading the security and authorization keys.
*/
DlmsConnection createConnection(final MessageMetadata messageMetadata, final DlmsDevice device, final DlmsMessageListener dlmsMessageListener, final SecurityKeyProvider keyProvider) throws IOException, OsgpException {
// Setup connection to device
final TcpConnectionBuilder tcpConnectionBuilder = new TcpConnectionBuilder(InetAddress.getByName(device.getIpAddress())).setResponseTimeout(this.responseTimeout).setLogicalDeviceId(this.logicalDeviceAddress);
tcpConnectionBuilder.setClientId(this.clientId).setReferencingMethod(device.isUseSn() ? ReferencingMethod.SHORT : ReferencingMethod.LOGICAL);
if (device.isUseHdlc()) {
tcpConnectionBuilder.useHdlc();
}
this.setSecurity(messageMetadata, device, keyProvider, tcpConnectionBuilder);
this.setOptionalValues(device, tcpConnectionBuilder);
if (device.isInDebugMode() || dlmsMessageListener instanceof InvocationCountingDlmsMessageListener) {
tcpConnectionBuilder.setRawMessageListener(dlmsMessageListener);
}
return tcpConnectionBuilder.build();
}
Aggregations