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;
}
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();
}
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();
}
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;
}
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);
}
Aggregations