Search in sources :

Example 21 with DlmsDeviceBuilder

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);
}
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 22 with DlmsDeviceBuilder

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);
}
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 23 with DlmsDeviceBuilder

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);
}
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 24 with DlmsDeviceBuilder

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);
}
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 25 with DlmsDeviceBuilder

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));
}
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) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) Test(org.junit.jupiter.api.Test)

Aggregations

DlmsDeviceBuilder (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder)28 Test (org.junit.jupiter.api.Test)25 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)24 DlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener)18 InvocationCountingDlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener)17 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)6 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)4 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Builder (org.opensmartgridplatform.shared.infra.jms.MessageMetadata.Builder)3 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)3 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)2 Consumer (java.util.function.Consumer)1 DataObject (org.openmuc.jdlms.datatypes.DataObject)1 SystemEventDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SystemEventDto)1