Search in sources :

Example 71 with DlmsDevice

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

the class ClearMBusStatusOnAllChannelsCommandExecutorTest method testExecuteObjectNotFound.

@Test
void testExecuteObjectNotFound() throws ProtocolAdapterException {
    when(this.dlmsObjectConfigService.getAttributeAddress(any(), any(), any())).thenThrow(new ProtocolAdapterException("Object not found"));
    final DlmsDevice dlmsDevice = new DlmsDevice();
    dlmsDevice.setProtocol("SMR", "5.0.0");
    assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> {
        this.executor.execute(this.connectionManager, dlmsDevice, this.dto, this.messageMetadata);
    });
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) Test(org.junit.jupiter.api.Test)

Example 72 with DlmsDevice

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

the class DeviceConverterTest method converted.

private DlmsDevice converted(final SmartMeteringDeviceDto dto) {
    final DlmsDevice dlmsDevice = new DlmsDevice();
    dlmsDevice.setDeviceIdentification(dto.getDeviceIdentification());
    dlmsDevice.setCommunicationMethod(dto.getCommunicationMethod());
    dlmsDevice.setCommunicationProvider(dto.getCommunicationProvider());
    dlmsDevice.setIccId(dto.getIccId());
    dlmsDevice.setHls3Active(dto.isHls3Active());
    dlmsDevice.setHls4Active(dto.isHls4Active());
    dlmsDevice.setHls5Active(dto.isHls5Active());
    dlmsDevice.setMbusIdentificationNumber(dto.getMbusIdentificationNumber());
    dlmsDevice.setMbusManufacturerIdentification(dto.getMbusManufacturerIdentification());
    dlmsDevice.setProtocol(dto.getProtocolName(), dto.getProtocolVersion());
    return dlmsDevice;
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)

Example 73 with DlmsDevice

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

the class DeviceKeyProcessingServiceTest method testKeyProcessRunning.

@Test
public void testKeyProcessRunning() throws DeviceKeyProcessAlreadyRunningException {
    final DlmsDevice dlmsDevice = new DlmsDevice();
    dlmsDevice.setDeviceIdentification(DEVICE_IDENTIFICATION);
    dlmsDevice.setKeyProcessingStartTime(Instant.now());
    when(this.dlmsDeviceRepository.findByDeviceIdentification(DEVICE_IDENTIFICATION)).thenReturn(dlmsDevice);
    when(this.dlmsDeviceRepository.setProcessingStartTime(eq(DEVICE_IDENTIFICATION), any(Instant.class))).thenReturn(0);
    assertThrows(DeviceKeyProcessAlreadyRunningException.class, () -> {
        this.deviceKeyProcessingService.startProcessing(DEVICE_IDENTIFICATION);
    });
}
Also used : Instant(java.time.Instant) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Test(org.junit.jupiter.api.Test)

Example 74 with DlmsDevice

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

the class DeviceKeyProcessingServiceTest method testPreviousKeyProcessTimedOut.

@Test
public void testPreviousKeyProcessTimedOut() {
    final DlmsDevice dlmsDevice = new DlmsDevice();
    dlmsDevice.setDeviceIdentification(DEVICE_IDENTIFICATION);
    dlmsDevice.setKeyProcessingStartTime(Instant.now().minus(this.deviceKeyProcessingService.getDeviceKeyProcessingTimeout()));
    when(this.dlmsDeviceRepository.findByDeviceIdentification(DEVICE_IDENTIFICATION)).thenReturn(dlmsDevice);
    when(this.dlmsDeviceRepository.setProcessingStartTime(eq(DEVICE_IDENTIFICATION), any(Instant.class))).thenReturn(1);
    assertDoesNotThrow(() -> this.deviceKeyProcessingService.startProcessing(DEVICE_IDENTIFICATION));
}
Also used : Instant(java.time.Instant) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Test(org.junit.jupiter.api.Test)

Example 75 with DlmsDevice

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

the class InstallationServiceTest method addGMeter.

@Test
void addGMeter() throws FunctionalException {
    // GIVEN
    final SmartMeteringDeviceDto deviceDto = new SmartMeteringDeviceDto();
    deviceDto.setDeviceIdentification(this.deviceIdentification);
    deviceDto.setMasterKey(new byte[0]);
    deviceDto.setAuthenticationKey(new byte[0]);
    deviceDto.setGlobalEncryptionUnicastKey(new byte[0]);
    deviceDto.setMbusDefaultKey(new byte[16]);
    final DlmsDevice dlmsDevice = new DlmsDevice();
    when(this.installationMapper.map(deviceDto, DlmsDevice.class)).thenReturn(dlmsDevice);
    when(this.dlmsDeviceRepository.save(dlmsDevice)).thenReturn(dlmsDevice);
    when(this.rsaEncrypter.decrypt(any())).thenReturn(new byte[16]);
    // WHEN
    this.testService.addMeter(this.messageMetadata, deviceDto);
    // THEN
    verify(this.secretManagementService, times(1)).storeNewKeys(eq(this.messageMetadata), eq(this.deviceIdentification), any());
    verify(this.secretManagementService, times(1)).activateNewKeys(eq(this.messageMetadata), eq(this.deviceIdentification), any());
}
Also used : SmartMeteringDeviceDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SmartMeteringDeviceDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) 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