Search in sources :

Example 36 with DlmsDevice

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.

the class DomainHelperServiceTest method setsIpAddressFromMessageMetadataIfIpAddressIsStatic.

@Test
void setsIpAddressFromMessageMetadataIfIpAddressIsStatic() throws Exception {
    final String ipAddress = IP_ADDRESS;
    final DlmsDevice dlmsDevice = new DlmsDeviceBuilder().withIpAddress(null).withIpAddressStatic(true).build();
    final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withIpAddress(ipAddress).build();
    this.domainHelperService.setIpAddressFromMessageMetadataOrSessionProvider(dlmsDevice, messageMetadata);
    assertThat(dlmsDevice.getIpAddress()).isEqualTo(ipAddress);
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) 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 37 with DlmsDevice

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.

the class ClearAlarmRegisterCommandExecutorTest method connectionProblemAlarmRegister1.

@Test
void connectionProblemAlarmRegister1() throws ProtocolAdapterException, IOException {
    when(this.dlmsConnection.set(this.setParameterArgumentCaptor.capture())).thenThrow(new IOException());
    final DlmsDevice dlmsDevice = new DlmsDevice("SMR 5.2 device");
    this.setupAlarmRegister1(dlmsDevice);
    final Throwable actual = catchThrowable(() -> this.executor.execute(this.connectionManager, dlmsDevice, this.dto, this.messageMetadata));
    assertThat(actual).isInstanceOf(ConnectionException.class);
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) ThrowableAssert.catchThrowable(org.assertj.core.api.ThrowableAssert.catchThrowable) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 38 with DlmsDevice

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.

the class ClearAlarmRegisterCommandExecutorTest method connectionProblemAlarmRegister2.

@Test
void connectionProblemAlarmRegister2() throws ProtocolAdapterException, IOException {
    when(this.dlmsConnection.set(any(SetParameter.class))).thenReturn(AccessResultCode.SUCCESS).thenThrow(new IOException());
    final DlmsDevice dlmsDevice = new DlmsDevice("SMR 5.2 device");
    this.setupAlarmRegister2(dlmsDevice);
    final Throwable actual = catchThrowable(() -> this.executor.execute(this.connectionManager, dlmsDevice, this.dto, this.messageMetadata));
    assertThat(actual).isInstanceOf(ConnectionException.class);
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) ThrowableAssert.catchThrowable(org.assertj.core.api.ThrowableAssert.catchThrowable) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 39 with DlmsDevice

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.

the class ClearAlarmRegisterCommandExecutorTest method nullResultAlarmRegister2.

@Test
void nullResultAlarmRegister2() throws ProtocolAdapterException, IOException {
    when(this.dlmsConnection.set(this.setParameterArgumentCaptor.capture())).thenReturn(AccessResultCode.SUCCESS).thenReturn(null);
    final DlmsDevice dlmsDevice = new DlmsDevice("SMR 5.2 device");
    this.setupAlarmRegister2(dlmsDevice);
    final Throwable actual = catchThrowable(() -> this.executor.execute(this.connectionManager, dlmsDevice, this.dto, this.messageMetadata));
    assertThat(actual).isInstanceOf(ProtocolAdapterException.class);
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) ThrowableAssert.catchThrowable(org.assertj.core.api.ThrowableAssert.catchThrowable) Test(org.junit.jupiter.api.Test)

Example 40 with DlmsDevice

use of org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice in project open-smart-grid-platform by OSGP.

the class ClearAlarmRegisterCommandExecutorTest method successRegister1AndResultAlarmRegister2.

@Test
void successRegister1AndResultAlarmRegister2() throws ProtocolAdapterException, IOException {
    when(this.dlmsConnection.set(this.setParameterArgumentCaptor.capture())).thenReturn(AccessResultCode.SUCCESS).thenReturn(AccessResultCode.TEMPORARY_FAILURE);
    final DlmsDevice dlmsDevice = new DlmsDevice("SMR 5.2 device");
    this.setupAlarmRegister2(dlmsDevice);
    final AccessResultCode accessResultCode = this.executor.execute(this.connectionManager, dlmsDevice, this.dto, this.messageMetadata);
    assertThat(accessResultCode).isEqualTo(AccessResultCode.TEMPORARY_FAILURE);
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) AccessResultCode(org.openmuc.jdlms.AccessResultCode) Test(org.junit.jupiter.api.Test)

Aggregations

DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)103 Test (org.junit.jupiter.api.Test)58 DlmsDeviceBuilder (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder)24 DlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener)17 InvocationCountingDlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener)17 AttributeAddress (org.openmuc.jdlms.AttributeAddress)15 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)13 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)10 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)10 Then (io.cucumber.java.en.Then)9 DataObject (org.openmuc.jdlms.datatypes.DataObject)7 DlmsConnectionManager (org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager)7 AccessResultCode (org.openmuc.jdlms.AccessResultCode)6 Instant (java.time.Instant)5 Protocol (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol)5 IOException (java.io.IOException)4 Date (java.util.Date)4 List (java.util.List)4 ThrowableAssert.catchThrowable (org.assertj.core.api.ThrowableAssert.catchThrowable)4 SetParameter (org.openmuc.jdlms.SetParameter)4