Search in sources :

Example 91 with DlmsDevice

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

the class GetPeriodicMeterReadsCommandExecutorTest method createDevice.

private DlmsDevice createDevice(final Protocol protocol) {
    final DlmsDevice device = new DlmsDevice();
    device.setProtocol(protocol);
    return device;
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)

Example 92 with DlmsDevice

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

the class UpdateFirmwareCommandExecutorIntegrationTest method testExecuteMbusFirmware.

@Test
void testExecuteMbusFirmware() throws Exception {
    final DlmsDevice device = new DlmsDevice();
    device.setMbusIdentificationNumber("00000001");
    final String firmwareIdentification = RandomStringUtils.randomAlphabetic(10);
    final String deviceIdentification = RandomStringUtils.randomAlphabetic(10);
    device.setDeviceIdentification(deviceIdentification);
    final byte[] firmwareFile = org.bouncycastle.util.encoders.Hex.decode("534d523500230011004000310000001000020801e91effffffff500303000000000000831c9d5aa5b4f" + "fbfd057035a8a7896a4abe7afa36687fbc48944bcee0343eed3a75aab882ec1cf57820adfd4394e262d" + "5fa821c678e71c05c47e1c69c4bfffe1fd");
    when(this.dlmsDeviceRepository.findByDeviceIdentification(deviceIdentification)).thenReturn(device);
    when(this.firmwareFileCachingRepository.retrieve(firmwareIdentification)).thenReturn(firmwareFile);
    when(this.macGenerationService.calculateMac(any(), any(), any())).thenReturn(new byte[16]);
    final UpdateFirmwareRequestDto updateFirmwareRequestDto = new UpdateFirmwareRequestDto(firmwareIdentification, deviceIdentification);
    this.commandExecutor.execute(this.connectionManagerStub, device, updateFirmwareRequestDto, this.messageMetadata);
    verify(this.dlmsDeviceRepository, times(1)).findByDeviceIdentification(deviceIdentification);
    verify(this.macGenerationService, times(1)).calculateMac(any(), any(), any());
    verify(this.firmwareFileCachingRepository, times(1)).retrieve(firmwareIdentification);
    verify(this.firmwareImageIdentifierCachingRepository, never()).retrieve(firmwareIdentification);
    this.assertImageTransferRelatedInteractionWithConnection();
}
Also used : UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Test(org.junit.jupiter.api.Test)

Example 93 with DlmsDevice

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

the class UpdateFirmwareCommandExecutorIntegrationTest method testExecute.

@Test
void testExecute() throws Exception {
    final DlmsDevice device = new DlmsDevice();
    final String firmwareIdentification = RandomStringUtils.randomAlphabetic(10);
    final String deviceIdentification = RandomStringUtils.randomAlphabetic(10);
    final byte[] firmwareFile = RandomStringUtils.randomAlphabetic(100).getBytes(StandardCharsets.UTF_8);
    final byte[] firmwareImageIdentifier = Hex.decode("496d6167654964656e746966696572");
    when(this.firmwareFileCachingRepository.retrieve(firmwareIdentification)).thenReturn(firmwareFile);
    when(this.firmwareImageIdentifierCachingRepository.retrieve(firmwareIdentification)).thenReturn(firmwareImageIdentifier);
    final UpdateFirmwareRequestDto updateFirmwareRequestDto = new UpdateFirmwareRequestDto(firmwareIdentification, deviceIdentification);
    this.commandExecutor.execute(this.connectionManagerStub, device, updateFirmwareRequestDto, this.messageMetadata);
    verify(this.dlmsDeviceRepository, never()).findByDeviceIdentification(deviceIdentification);
    verify(this.macGenerationService, never()).calculateMac(any(), any(), any());
    verify(this.firmwareFileCachingRepository, times(1)).retrieve(firmwareIdentification);
    verify(this.firmwareImageIdentifierCachingRepository, times(1)).retrieve(firmwareIdentification);
    this.assertImageTransferRelatedInteractionWithConnection();
}
Also used : UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Test(org.junit.jupiter.api.Test)

Example 94 with DlmsDevice

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

the class FindEventsCommandExecutorTest method createDlmsDevice.

private DlmsDevice createDlmsDevice(final Protocol protocol) {
    final DlmsDevice device = new DlmsDevice();
    device.setDeviceIdentification("123456789012");
    device.setProtocol(protocol);
    return device;
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)

Example 95 with DlmsDevice

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

the class ClearAlarmRegisterCommandExecutorTest method assertForTwoRegisters.

void assertForTwoRegisters(final String protocol, final String protocolVersion) throws ProtocolAdapterException, IOException {
    final DlmsDevice dlmsDevice = new DlmsDevice(protocol + " " + protocolVersion + " device");
    dlmsDevice.setProtocol(protocol, protocolVersion);
    when(this.dlmsObjectConfigService.getAttributeAddress(dlmsDevice, DlmsObjectType.ALARM_REGISTER_1, null)).thenReturn(new AttributeAddress(InterfaceClass.DATA.id(), OBIS_CODE_ALARM_REGISTER_1, DataAttribute.VALUE.attributeId()));
    when(this.dlmsObjectConfigService.findAttributeAddress(dlmsDevice, DlmsObjectType.ALARM_REGISTER_2, null)).thenReturn(Optional.of(new AttributeAddress(InterfaceClass.DATA.id(), OBIS_CODE_ALARM_REGISTER_2, DataAttribute.VALUE.attributeId())));
    when(this.connectionManager.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
    when(this.connectionManager.getConnection()).thenReturn(this.dlmsConnection);
    when(this.dlmsConnection.set(this.setParameterArgumentCaptor.capture())).thenReturn(AccessResultCode.SUCCESS);
    this.executor.execute(this.connectionManager, dlmsDevice, this.dto, this.messageMetadata);
    assertThat(this.setParameterArgumentCaptor.getAllValues()).hasSize(2);
    SetParameter setParameter = this.setParameterArgumentCaptor.getAllValues().get(0);
    assertThat(((Number) setParameter.getData().getValue()).longValue()).isEqualTo(ALARM_CODE);
    final AttributeAddress attributeAddress = setParameter.getAttributeAddress();
    assertThat(attributeAddress.getInstanceId().asDecimalString()).isEqualTo(OBIS_CODE_ALARM_REGISTER_1);
    assertThat(attributeAddress.getClassId()).isEqualTo(CLASS_ID_CLEAR_ALARM_REGISTER);
    setParameter = this.setParameterArgumentCaptor.getAllValues().get(1);
    assertThat(((Number) setParameter.getData().getValue()).longValue()).isEqualTo(ALARM_CODE);
    final AttributeAddress attributeAddress2 = setParameter.getAttributeAddress();
    assertThat(attributeAddress2.getInstanceId().asDecimalString()).isEqualTo(OBIS_CODE_ALARM_REGISTER_2);
    assertThat(attributeAddress2.getClassId()).isEqualTo(CLASS_ID_CLEAR_ALARM_REGISTER);
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) SetParameter(org.openmuc.jdlms.SetParameter)

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