use of org.opensmartgridplatform.dto.valueobjects.smartmetering.FindEventsRequestDto in project open-smart-grid-platform by OSGP.
the class ManagementService method findEvents.
// === FIND EVENTS ===
public EventMessageDataResponseDto findEvents(final DlmsConnectionManager conn, final DlmsDevice device, final FindEventsRequestList findEventsQueryMessageDataContainer, final MessageMetadata messageMetadata) throws ProtocolAdapterException {
final List<EventDto> events = new ArrayList<>();
log.info("findEvents setting up connection with meter {}", device.getDeviceIdentification());
for (final FindEventsRequestDto findEventsQuery : findEventsQueryMessageDataContainer.getFindEventsQueryList()) {
log.info("findEventsQuery.eventLogCategory: {}, findEventsQuery.from: {}, findEventsQuery.until: {}", findEventsQuery.getEventLogCategory().toString(), findEventsQuery.getFrom(), findEventsQuery.getUntil());
events.addAll(this.findEventsCommandExecutor.execute(conn, device, findEventsQuery, messageMetadata));
}
return new EventMessageDataResponseDto(events);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.FindEventsRequestDto in project open-smart-grid-platform by OSGP.
the class FindEventsCommandExecutorTest method testRetrievalOfAuxiliaryLogEvents.
@Test
void testRetrievalOfAuxiliaryLogEvents() throws ProtocolAdapterException, IOException {
// SETUP
this.findEventsRequestDto = new FindEventsRequestDto(EventLogCategoryDto.AUXILIARY_EVENT_LOG, DateTime.now().minusDays(70), DateTime.now());
when(this.getResult.getResultCode()).thenReturn(AccessResultCode.SUCCESS);
when(this.getResult.getResultData()).thenReturn(this.resultData);
when(this.resultData.getValue()).thenReturn(this.generateDataObjectsAuxiliary());
// CALL
final List<EventDto> events = this.executor.execute(this.conn, this.DLMS_DEVICE_5_1, this.findEventsRequestDto, this.messageMetadata);
// VERIFY
assertThat(events.size()).isEqualTo(34);
int firstEventCode = 33664;
for (final EventDto event : events) {
assertThat(event.getEventCode()).isEqualTo(firstEventCode++);
}
verify(this.dlmsHelper, times(events.size())).convertDataObjectToDateTime(any(DataObject.class));
verify(this.conn).getDlmsMessageListener();
verify(this.conn).getConnection();
verify(this.dlmsConnection).get(any(AttributeAddress.class));
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.FindEventsRequestDto in project open-smart-grid-platform by OSGP.
the class FindEventsCommandExecutorTest method before.
@BeforeEach
public void before() throws ProtocolAdapterException, IOException {
final DataObject fromDate = mock(DataObject.class);
final DataObject toDate = mock(DataObject.class);
this.messageMetadata = MessageMetadata.newBuilder().withCorrelationUid("123456").build();
this.findEventsRequestDto = new FindEventsRequestDto(EventLogCategoryDto.POWER_QUALITY_EVENT_LOG, DateTime.now().minusDays(70), DateTime.now());
final DataObjectToEventListConverter dataObjectToEventListConverter = new DataObjectToEventListConverter(this.dlmsHelper);
final DlmsObjectConfigService dlmsObjectConfigService = new DlmsObjectConfigService(this.dlmsHelper, new DlmsObjectConfigConfiguration().getDlmsObjectConfigs());
this.executor = new FindEventsCommandExecutor(this.dlmsHelper, dataObjectToEventListConverter, dlmsObjectConfigService);
when(this.dlmsHelper.asDataObject(this.findEventsRequestDto.getFrom())).thenReturn(fromDate);
when(this.dlmsHelper.asDataObject(this.findEventsRequestDto.getUntil())).thenReturn(toDate);
when(this.dlmsHelper.convertDataObjectToDateTime(any(DataObject.class))).thenReturn(new CosemDateTimeDto());
when(this.conn.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener);
when(this.conn.getConnection()).thenReturn(this.dlmsConnection);
when(this.dlmsConnection.get(any(AttributeAddress.class))).thenReturn(this.getResult);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.FindEventsRequestDto in project open-smart-grid-platform by OSGP.
the class BundleServiceTest method testConnectionException.
/**
* Tests the retry mechanism works in the adapter-protocol. In the first run a ConnectionException
* is thrown while executing the {@link FindEventsRequestDto}. In the second attempt (when the
* connection is restored again) the rest of the actions are executed.
*
* @throws ProtocolAdapterException is not thrown in this test
*/
@Test
public void testConnectionException() throws ProtocolAdapterException {
final List<ActionDto> actionDtoList = this.makeActions();
final BundleMessagesRequestDto dto = new BundleMessagesRequestDto(actionDtoList);
// Set the point where to throw the ConnectionException
this.getStub(FindEventsRequestDto.class).failWithRuntimeException(new ConnectionException("Connection Exception thrown!"));
try {
// Execute all the actions
this.callExecutors(dto, this.messageMetadata);
fail("A ConnectionException should be thrown");
} catch (final ConnectionException connectionException) {
// The execution is stopped. The number of responses is equal to the
// actions performed before the point the exception is thrown. See
// also the order of the ArrayList in method 'makeActions'.
assertThat(dto.getAllResponses().size()).isEqualTo(9);
}
// Reset the point where the exception was thrown.
this.getStub(FindEventsRequestDto.class).failWithRuntimeException(null);
try {
// Execute the remaining actions
this.callExecutors(dto, this.messageMetadata);
assertThat(actionDtoList.size()).isEqualTo(dto.getAllResponses().size());
} catch (final ConnectionException connectionException) {
fail("A ConnectionException should not have been thrown.");
}
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.FindEventsRequestDto 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);
});
}
Aggregations