Search in sources :

Example 1 with ActionDto

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

the class BundleServiceTest method makeActions.

private List<ActionDto> makeActions() {
    final List<ActionDto> actions = new ArrayList<>();
    actions.add(new ActionDto(this.builder.makeActualMeterReadsDataDtoAction()));
    actions.add(new ActionDto(this.builder.makeActualPowerQualityRequestDto()));
    actions.add(new ActionDto(this.builder.makePeriodicMeterReadsGasRequestDataDto()));
    actions.add(new ActionDto(this.builder.makePeriodicMeterReadsRequestDataDto()));
    actions.add(new ActionDto(this.builder.makeSpecialDaysRequestDataDto()));
    actions.add(new ActionDto(this.builder.makeReadAlarmRegisterDataDto()));
    actions.add(new ActionDto(this.builder.makeGetAdministrativeStatusDataDto()));
    actions.add(new ActionDto(this.builder.makeAdministrativeStatusTypeDataDto()));
    actions.add(new ActionDto(this.builder.makeActivityCalendarDataDto()));
    actions.add(new ActionDto(this.builder.makeFindEventsQueryDto()));
    actions.add(new ActionDto(this.builder.makeGMeterInfoDto()));
    actions.add(new ActionDto(this.builder.makeSetAlarmNotificationsRequestDataDto()));
    actions.add(new ActionDto(this.builder.makeSetConfigurationObjectRequestDataDto()));
    actions.add(new ActionDto(this.builder.makeSetPushSetupAlarmRequestDataDto()));
    actions.add(new ActionDto(this.builder.makeSetPushSetupSmsRequestDataDto()));
    actions.add(new ActionDto(this.builder.makeSynchronizeTimeRequestDataDto()));
    actions.add(new ActionDto(this.builder.makeGetAllAttributeValuesRequestDto()));
    actions.add(new ActionDto(this.builder.makeGetFirmwareVersionRequestDataDto()));
    return actions;
}
Also used : ArrayList(java.util.ArrayList) ActionDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionDto)

Example 2 with ActionDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionDto 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.");
    }
}
Also used : BundleMessagesRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto) FindEventsRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FindEventsRequestDto) ActionDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionDto) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException) Test(org.junit.jupiter.api.Test)

Example 3 with ActionDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionDto 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);
}
Also used : BundleMessagesRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ActionDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionDto) ClearAlarmRegisterRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ClearAlarmRegisterRequestDto)

Example 4 with ActionDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionDto 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 5 with ActionDto

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

the class BundleServiceTest method createAction.

private ActionDto createAction(final ActionRequestDto actionRequestDto, final ActionResponseDto actionResponseDto) {
    final ActionDto action = new ActionDto(actionRequestDto);
    action.setResponse(actionResponseDto);
    return action;
}
Also used : ActionDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionDto)

Aggregations

ActionDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionDto)8 BundleMessagesRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto)5 Test (org.junit.jupiter.api.Test)3 ArrayList (java.util.ArrayList)2 FindEventsRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.FindEventsRequestDto)2 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)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