use of org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto in project open-smart-grid-platform by OSGP.
the class BundleServiceTest method shouldHandleActionsWithoutPreviousResult.
@Test
public void shouldHandleActionsWithoutPreviousResult() {
final BundleMessagesRequestDto bundleMessagesRequest = new BundleMessagesRequestDto(Arrays.asList(this.createAction(this.builder.makePeriodicMeterReadsRequestDataDto(), null)));
final BundleMessagesRequestDto result = this.bundleService.callExecutors(null, new DlmsDevice(), bundleMessagesRequest, this.messageMetadata);
verify(this.bundleCommandExecutorMap).getCommandExecutor(PeriodicMeterReadsRequestDataDto.class);
assertThat(result.getAllResponses().size()).isOne();
assertThat(result.getAllResponses().get(0)).isNotNull();
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto 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.BundleMessagesRequestDto in project open-smart-grid-platform by OSGP.
the class BundleService method handleBundle.
@Transactional(value = "transactionManager")
public void handleBundle(final MessageMetadata messageMetadata, final BundleMessageRequest bundleMessageRequest) throws FunctionalException {
LOGGER.info("handleBundle request for organisationIdentification: {} for deviceIdentification: {}", messageMetadata.getOrganisationIdentification(), messageMetadata.getDeviceIdentification());
final SmartMeter smartMeter = this.domainHelperService.findSmartMeter(messageMetadata.getDeviceIdentification());
final BundleMessagesRequestDto requestDto = this.actionMapperService.mapAllActions(bundleMessageRequest, smartMeter);
LOGGER.info("Sending request message to core.");
this.osgpCoreRequestMessageSender.send(requestDto, messageMetadata.builder().withIpAddress(smartMeter.getIpAddress()).withNetworkSegmentIds(smartMeter.getBtsId(), smartMeter.getCellId()).build());
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto in project open-smart-grid-platform by OSGP.
the class BundleResponseMessageProcessor method handleMessage.
@Override
protected void handleMessage(final MessageMetadata deviceMessageMetadata, final ResponseMessage responseMessage, final OsgpException osgpException) throws FunctionalException {
final BundleMessagesRequestDto bundleMessagesResponseDto = (BundleMessagesRequestDto) responseMessage.getDataObject();
this.bundleService.handleBundleResponse(deviceMessageMetadata, responseMessage.getResult(), osgpException, bundleMessagesResponseDto);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto in project open-smart-grid-platform by OSGP.
the class BundleMessageProcessorTest method prepareBundleServiceMockWithRequestAndResponse.
private void prepareBundleServiceMockWithRequestAndResponse(final ActionResponseDto response) throws JMSException {
final ActionDto action = new ActionDto(new ClearAlarmRegisterRequestDto());
action.setResponse(response);
final BundleMessagesRequestDto request = new BundleMessagesRequestDto(Arrays.asList(action));
when(this.message.getObject()).thenReturn(request);
when(this.bundleService.callExecutors(same(this.dlmsConnectionManager), same(this.dlmsDevice), same(request), any(MessageMetadata.class))).thenReturn(request);
}
Aggregations