Search in sources :

Example 1 with BundleMessagesRequestDto

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();
}
Also used : BundleMessagesRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Test(org.junit.jupiter.api.Test)

Example 2 with BundleMessagesRequestDto

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.");
    }
}
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 BundleMessagesRequestDto

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());
}
Also used : BundleMessagesRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with BundleMessagesRequestDto

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);
}
Also used : BundleMessagesRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto)

Example 5 with BundleMessagesRequestDto

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);
}
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)

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