FindEventsCommandExecutor extends AbstractCommandExecutor<FindEventsRequestDto, List<EventDto>> { @Override public List<EventDto> execute(final DlmsConnectionManager conn, final DlmsDevice device, final FindEventsRequestDto findEventsQuery) throws ProtocolAdapterException { final SelectiveAccessDescription selectiveAccessDescription = this .getSelectiveAccessDescription(findEventsQuery.getFrom(), findEventsQuery.getUntil()); final AttributeAddress eventLogBuffer = new AttributeAddress(CLASS_ID, EVENT_LOG_CATEGORY_OBISCODE_MAP.get(findEventsQuery.getEventLogCategory()), ATTRIBUTE_ID, selectiveAccessDescription); conn.getDlmsMessageListener().setDescription( "RetrieveEvents for " + findEventsQuery.getEventLogCategory() + " from " + findEventsQuery.getFrom() + " until " + findEventsQuery.getUntil() + ", retrieve attribute: " + JdlmsObjectToStringUtil .describeAttributes(eventLogBuffer)); final GetResult getResult; try { getResult = conn.getConnection().get(eventLogBuffer); } catch (final IOException e) { throw new ConnectionException(e); } if (getResult == null) { throw new ProtocolAdapterException( "No GetResult received while retrieving event register " + findEventsQuery.getEventLogCategory()); } if (!AccessResultCode.SUCCESS.equals(getResult.getResultCode())) { LOGGER.info("Result of getting events for {} is {}", findEventsQuery.getEventLogCategory(), getResult.getResultCode()); throw new ProtocolAdapterException( "Getting the events for " + findEventsQuery.getEventLogCategory() + " from the meter resulted in: " + getResult.getResultCode()); } final DataObject resultData = getResult.getResultData(); return this.dataObjectToEventListConverter.convert(resultData, findEventsQuery.getEventLogCategory()); } @Autowired  FindEventsCommandExecutor(final DlmsHelper dlmsHelper,
            final DataObjectToEventListConverter dataObjectToEventListConverter); @Override ActionResponseDto asBundleResponse(final List<EventDto> executionResult); @Override List<EventDto> execute(final DlmsConnectionManager conn, final DlmsDevice device,
            final FindEventsRequestDto findEventsQuery);  }
@Test public void testRetrievalOfPowerQualityEvents() throws ProtocolAdapterException { when(this.getResult.getResultCode()).thenReturn(AccessResultCode.SUCCESS); when(this.getResult.getResultData()).thenReturn(this.resultData); when(this.resultData.getValue()).thenReturn(this.generateDataObjects()); final FindEventsCommandExecutor executor = new FindEventsCommandExecutor(this.dlmsHelper, this.dataObjectToEventListConverter); final List<EventDto> events = executor.execute(this.conn, this.dlmsDevice, this.findEventsRequestDto); assertThat(events.size()).isEqualTo(13); int firstEventCode = 77; for (final EventDto event : events) { assertThat(event.getEventCode()).isEqualTo(firstEventCode++); } verify(this.dlmsHelper, times(events.size())).convertDataObjectToDateTime(any(DataObject.class)); }
@Test public void testOtherReasonResult() throws ProtocolAdapterException { when(this.getResult.getResultCode()).thenReturn(AccessResultCode.OTHER_REASON); assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> { new FindEventsCommandExecutor(this.dlmsHelper, this.dataObjectToEventListConverter).execute(this.conn, this.dlmsDevice, this.findEventsRequestDto); }); }
@Test public void testEmptyGetResult() throws ProtocolAdapterException, IOException { when(this.dlmsConnection.get(any(AttributeAddress.class))).thenReturn(null); assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> { new FindEventsCommandExecutor(this.dlmsHelper, this.dataObjectToEventListConverter).execute(this.conn, this.dlmsDevice, this.findEventsRequestDto); }); }