use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder 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.domain.entities.DlmsDeviceBuilder 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.domain.entities.DlmsDeviceBuilder 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);
}
use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder 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.domain.entities.DlmsDeviceBuilder 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));
}
Aggregations