use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener in project open-smart-grid-platform by OSGP.
the class DlmsConnectionHelperTest method initializesInvocationCounterWhenInvocationCounterIsOutOfSyncForLAndGDevice.
@Test
void initializesInvocationCounterWhenInvocationCounterIsOutOfSyncForLAndGDevice() throws Exception {
final DlmsDevice device = new DlmsDeviceBuilder().withHls5Active(true).withProtocol("SMR").withInvocationCounter(123L).build();
final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
final ConnectionException exception = new ConnectionException("Error creating connection for device E0051004228715518 with Ip address:62.133.88.34 Port:null " + "UseHdlc:false UseSn:false Message:Socket was closed by remote host.");
doThrow(exception).when(this.connectionFactory).createAndHandleConnection(this.messageMetadata, device, listener, null, this.task);
assertThrows(ConnectionException.class, () -> this.helper.createAndHandleConnectionForDevice(this.messageMetadata, device, listener, null, this.task));
verify(this.invocationCounterManager).initializeInvocationCounter(this.messageMetadata, device);
verify(this.connectionFactory, times(2)).createAndHandleConnection(this.messageMetadata, device, listener, null, this.task);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener in project open-smart-grid-platform by OSGP.
the class DlmsConnectionHelperTest method doesNotPingDeviceWithoutIpAddressBeforeCreatingConnectionIfPingingIsEnabled.
@Test
void doesNotPingDeviceWithoutIpAddressBeforeCreatingConnectionIfPingingIsEnabled() throws Exception {
when(this.devicePingConfig.pingingEnabled()).thenReturn(true);
final DlmsDevice device = new DlmsDeviceBuilder().withHls5Active(true).build();
device.setIpAddress(null);
final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
this.helper.createAndHandleConnectionForDevice(this.messageMetadata, device, listener, this.task);
verifyNoInteractions(this.pinger);
verifyNoMoreInteractions(this.devicePingConfig);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener in project open-smart-grid-platform by OSGP.
the class DlmsConnectionHelperTest method pingsDeviceWithIpAddressBeforeCreatingConnectionIfPingingIsEnabled.
@Test
void pingsDeviceWithIpAddressBeforeCreatingConnectionIfPingingIsEnabled() throws Exception {
final String deviceIpAddress = "192.168.92.56";
when(this.devicePingConfig.pingingEnabled()).thenReturn(true);
when(this.devicePingConfig.pinger()).thenReturn(this.pinger);
final DlmsDevice device = new DlmsDeviceBuilder().withHls5Active(true).build();
device.setIpAddress(deviceIpAddress);
final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
this.helper.createAndHandleConnectionForDevice(this.messageMetadata, device, listener, this.task);
verify(this.pinger).ping(deviceIpAddress);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener in project open-smart-grid-platform by OSGP.
the class DlmsConnectionHelperTest method doesNotResetInvocationCounterWhenInvocationCounterIsOutOfSyncForDeviceThatNeedsNoInvocationCounter.
@Test
void doesNotResetInvocationCounterWhenInvocationCounterIsOutOfSyncForDeviceThatNeedsNoInvocationCounter() throws Exception {
final DlmsDevice device = new DlmsDeviceBuilder().withHls5Active(true).withProtocol("DSMR").withInvocationCounter(123L).build();
final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
final ConnectionException exception = new ConnectionException("Error creating connection for device E0051004228715518 with Ip address:62.133.88.34 Port:null " + "UseHdlc:false UseSn:false Message:Socket was closed by remote host.");
doThrow(exception).when(this.connectionFactory).createAndHandleConnection(this.messageMetadata, device, listener, null, this.task);
assertThrows(ConnectionException.class, () -> this.helper.createAndHandleConnectionForDevice(this.messageMetadata, device, listener, this.task));
verifyNoMoreInteractions(this.invocationCounterManager);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener in project open-smart-grid-platform by OSGP.
the class DlmsConnectionFactoryTest method createsPublicClientConnectionManagerForDevice.
@Test
void createsPublicClientConnectionManagerForDevice() throws Exception {
final DlmsDevice device = new DlmsDeviceBuilder().withHls5Active(true).build();
final DlmsMessageListener listener = new InvocationCountingDlmsMessageListener();
when(this.lls0Connector.connect(this.messageMetadata, device, listener)).thenReturn(this.connection);
final DlmsConnectionManager expected = this.newConnectionManager(device, listener, this.lls0Connector);
this.factory.createAndHandlePublicClientConnection(this.messageMetadata, device, listener, this.task);
this.assertConnectionManagerForDevice(expected);
}
Aggregations