Search in sources :

Example 6 with BundleMessagesRequestDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto in project open-smart-grid-platform by OSGP.

the class BundleResponseMessageProcessor method handleError.

@Override
protected void handleError(final Exception e, final MessageMetadata deviceMessageMetadata, final ResponseMessage responseMessage) throws FunctionalException {
    final OsgpException osgpException = this.ensureOsgpException(e);
    final BundleMessagesRequestDto bundleMessagesResponseDto = (BundleMessagesRequestDto) responseMessage.getDataObject();
    final List<ActionDto> actionList = bundleMessagesResponseDto.getActionList();
    for (final ActionDto action : actionList) {
        if (action.getResponse() == null) {
            final List<FaultResponseParameterDto> parameterList = new ArrayList<>();
            final FaultResponseParameterDto deviceIdentificationParameter = new FaultResponseParameterDto("deviceIdentification", deviceMessageMetadata.getDeviceIdentification());
            parameterList.add(deviceIdentificationParameter);
            action.setResponse(this.faultResponseForException(e, parameterList, "Unable to handle request"));
        }
    }
    this.bundleService.handleBundleResponse(deviceMessageMetadata, responseMessage.getResult(), osgpException, bundleMessagesResponseDto);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) BundleMessagesRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto) FaultResponseParameterDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseParameterDto) ArrayList(java.util.ArrayList) ActionDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionDto)

Example 7 with BundleMessagesRequestDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto in project open-smart-grid-platform by OSGP.

the class BundleServiceTest method shouldHandleActionsWithResultContainingFaultResponseWithRetryableException.

@Test
public void shouldHandleActionsWithResultContainingFaultResponseWithRetryableException() {
    final ActionResponseDto faultResponse = this.createFaultResponse(true);
    final BundleMessagesRequestDto bundleMessagesRequest = new BundleMessagesRequestDto(Arrays.asList(this.createAction(this.builder.makePeriodicMeterReadsRequestDataDto(), faultResponse)));
    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();
}
Also used : BundleMessagesRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto) ActionResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionResponseDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Test(org.junit.jupiter.api.Test)

Example 8 with BundleMessagesRequestDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto in project open-smart-grid-platform by OSGP.

the class BundleServiceTest method shouldNotHandleActionsContainingResult.

@Test
public void shouldNotHandleActionsContainingResult() {
    final ActionResponseDto previousActionResponse = new ActionResponseDto();
    final BundleMessagesRequestDto bundleMessagesRequest = new BundleMessagesRequestDto(Arrays.asList(this.createAction(this.builder.makePeriodicMeterReadsRequestDataDto(), previousActionResponse)));
    final BundleMessagesRequestDto result = this.bundleService.callExecutors(null, new DlmsDevice(), bundleMessagesRequest, this.messageMetadata);
    verify(this.bundleCommandExecutorMap, never()).getCommandExecutor(PeriodicMeterReadsRequestDataDto.class);
    assertThat(result.getAllResponses().size()).isOne();
    assertThat(result.getAllResponses().get(0)).isEqualTo(previousActionResponse);
}
Also used : BundleMessagesRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto) ActionResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionResponseDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Test(org.junit.jupiter.api.Test)

Example 9 with BundleMessagesRequestDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto in project open-smart-grid-platform by OSGP.

the class BundleServiceTest method testException.

@Test
public void testException() {
    final List<ActionDto> actionDtoList = this.makeActions();
    final BundleMessagesRequestDto dto = new BundleMessagesRequestDto(actionDtoList);
    this.getStub(FindEventsRequestDto.class).failWith(new ProtocolAdapterException("simulate error"));
    final BundleMessagesRequestDto result = this.callExecutors(dto, this.messageMetadata);
    this.assertResult(result);
}
Also used : BundleMessagesRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto) FindEventsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FindEventsRequestDto) ActionDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) Test(org.junit.jupiter.api.Test)

Example 10 with BundleMessagesRequestDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto in project open-smart-grid-platform by OSGP.

the class BundleServiceTest method testHappyFlow.

@Test
public void testHappyFlow() {
    final List<ActionDto> actionDtoList = this.makeActions();
    final BundleMessagesRequestDto dto = new BundleMessagesRequestDto(actionDtoList);
    final BundleMessagesRequestDto result = this.callExecutors(dto, this.messageMetadata);
    this.assertResult(result);
}
Also used : BundleMessagesRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto) ActionDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionDto) Test(org.junit.jupiter.api.Test)

Aggregations

BundleMessagesRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto)11 Test (org.junit.jupiter.api.Test)6 ActionDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionDto)5 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)3 ActionResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionResponseDto)2 FindEventsRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.FindEventsRequestDto)2 ArrayList (java.util.ArrayList)1 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)1 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)1 ClearAlarmRegisterRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ClearAlarmRegisterRequestDto)1 FaultResponseParameterDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseParameterDto)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)1 Transactional (org.springframework.transaction.annotation.Transactional)1