Search in sources :

Example 11 with DlmsMessageListener

use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener 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);
}
Also used : DlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) Test(org.junit.jupiter.api.Test)

Example 12 with DlmsMessageListener

use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener 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);
}
Also used : DlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) Test(org.junit.jupiter.api.Test)

Example 13 with DlmsMessageListener

use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener 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);
}
Also used : DlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException) Test(org.junit.jupiter.api.Test)

Example 14 with DlmsMessageListener

use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener 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);
}
Also used : DlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) Test(org.junit.jupiter.api.Test)

Example 15 with DlmsMessageListener

use of org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener 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);
}
Also used : DlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener) InvocationCountingDlmsMessageListener(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)17 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)17 DlmsDeviceBuilder (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder)17 DlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener)17 InvocationCountingDlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener)17 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)4 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2