use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class GetPeriodicMeterReadsCommandExecutorTest method testExecuteObjectNotFound.
@Test
void testExecuteObjectNotFound() {
// SETUP
final PeriodicMeterReadsRequestDto request = new PeriodicMeterReadsRequestDto(PeriodTypeDto.DAILY, this.fromDateTime.toDate(), this.toDateTime.toDate(), ChannelDto.ONE);
when(this.dlmsObjectConfigService.findAttributeAddressForProfile(any(), any(), any(), any(), any(), any())).thenReturn(Optional.empty());
// CALL
try {
this.executor.execute(this.connectionManager, this.device, request, this.messageMetadata);
fail("When no matching object is found, then execute should fail");
} catch (final ProtocolAdapterException e) {
assertThat(e.getMessage()).isEqualTo("No address found for " + DlmsObjectType.DAILY_LOAD_PROFILE);
}
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class GetPeriodicMeterReadsGasCommandExecutorTest method testExecuteObjectNotFound.
@Test
public void testExecuteObjectNotFound() {
// SETUP
final PeriodicMeterReadsRequestDto request = new PeriodicMeterReadsRequestDto(PeriodTypeDto.DAILY, this.fromDateTime.toDate(), this.toDateTime.toDate(), ChannelDto.ONE);
when(this.dlmsObjectConfigService.findAttributeAddressForProfile(any(), any(), any(), any(), any(), any())).thenReturn(Optional.empty());
// CALL
try {
this.executor.execute(this.connectionManager, this.device, request, this.messageMetadata);
fail("When no matching object is found, then execute should fail");
} catch (final ProtocolAdapterException e) {
assertThat(e.getMessage()).isEqualTo("No address found for " + DlmsObjectType.DAILY_LOAD_PROFILE);
}
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class FindEventsCommandExecutorTest method testRetrievalOfEventsFromPowerQualityExtendedEventLogThrowsExceptionWhenNotSupportedByDevice.
@Test
void testRetrievalOfEventsFromPowerQualityExtendedEventLogThrowsExceptionWhenNotSupportedByDevice() throws ProtocolAdapterException, IOException {
this.findEventsRequestDto = new FindEventsRequestDto(EventLogCategoryDto.POWER_QUALITY_EXTENDED_EVENT_LOG, DateTime.now().minusDays(70), DateTime.now());
assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> {
this.executor.execute(this.conn, this.DLMS_DEVICE_5_0, this.findEventsRequestDto, this.messageMetadata);
});
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class SetActivityCalendarCommandExecutorTest method testSetActivityCalendarWithActivationFailure.
@Test
void testSetActivityCalendarWithActivationFailure() throws ProtocolAdapterException, IOException {
// SETUP
final String errorMessage = "Activation failure";
when(this.conn.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
when(this.conn.getConnection()).thenReturn(this.dlmsConnection);
when(this.dlmsConnection.set(any(SetParameter.class))).thenReturn(AccessResultCode.SUCCESS);
when(this.activationExecutor.execute(this.conn, this.DLMS_DEVICE, null, this.messageMetadata)).thenThrow(new ProtocolAdapterException(errorMessage));
final ActivityCalendarDto activityCalendar = this.createDefaultActivityCalendar();
// CALL
final Throwable thrown = catchThrowable(() -> this.executor.execute(this.conn, this.DLMS_DEVICE, activityCalendar, this.messageMetadata));
// VERIFY
assertThat(thrown).isInstanceOf(ProtocolAdapterException.class).hasMessageContaining(errorMessage);
this.activityCalendarValidator.verify(() -> ActivityCalendarValidator.validate(activityCalendar), times(1));
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class SetRandomisationSettingsCommandExecutorTest method testUnknownAttribute.
@Test
public void testUnknownAttribute() throws ProtocolAdapterException {
// SETUP
when(this.dlmsObjectConfigService.getAttributeAddress(this.device, DlmsObjectType.RANDOMISATION_SETTINGS, null)).thenThrow(new ProtocolAdapterException("unknown"));
assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> {
// CALL
this.executor.execute(this.dlmsConnectionManager, this.device, this.dataDto, this.messageMetadata);
});
}
Aggregations