Search in sources :

Example 1 with FaultResponseParameterDto

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

the class BundleResponseMessageProcessorTest method technicalExceptionDetailsAreIncludedInFaultResponse.

@Test
public void technicalExceptionDetailsAreIncludedInFaultResponse() throws Exception {
    final FunctionalExceptionType functionalException = FunctionalExceptionType.UNSUPPORTED_DEVICE_ACTION;
    final ComponentType component = ComponentType.PROTOCOL_DLMS;
    final String message = "java.net.ConnectException: Connection refused";
    final Throwable cause = new RuntimeException(message);
    final Exception exception = new FunctionalException(functionalException, component, cause);
    this.parameters.add(new FaultResponseParameterDto("deviceIdentification", "ESIM9999999999999"));
    final FaultResponseDto faultResponse = this.processor.faultResponseForException(exception, this.parameters, this.defaultMessage);
    this.assertResponse(faultResponse, functionalException.getCode(), functionalException.name(), component.name(), cause.getClass().getName(), message, this.parameters);
}
Also used : ComponentType(org.opensmartgridplatform.shared.exceptionhandling.ComponentType) FaultResponseParameterDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseParameterDto) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) FaultResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseDto) FunctionalExceptionType(org.opensmartgridplatform.shared.exceptionhandling.FunctionalExceptionType) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) Test(org.junit.jupiter.api.Test)

Example 2 with FaultResponseParameterDto

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

the class FaultResponseConverter method createFaultResponseParameterList.

private List<FaultResponseParameterDto> createFaultResponseParameterList(final FaultResponseParameters faultResponseParameters) {
    final List<FaultResponseParameterDto> faultResponseParameterList = new ArrayList<>();
    for (final FaultResponseParameter parameter : faultResponseParameters.getParameterList()) {
        final String key = parameter.getKey();
        final String value = parameter.getValue();
        final FaultResponseParameterDto parameterDto = new FaultResponseParameterDto(key, value);
        faultResponseParameterList.add(parameterDto);
    }
    return faultResponseParameterList;
}
Also used : FaultResponseParameterDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseParameterDto) FaultResponseParameter(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.FaultResponseParameter) ArrayList(java.util.ArrayList)

Example 3 with FaultResponseParameterDto

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

the class BundleService method addFaultResponse.

private void addFaultResponse(final ActionDto action, final Exception exception, final String defaultMessage, final DlmsDevice device) {
    final List<FaultResponseParameterDto> parameterList = new ArrayList<>();
    final FaultResponseParameterDto deviceIdentificationParameter = new FaultResponseParameterDto(DEVICE_IDENTIFICATION, device.getDeviceIdentification());
    parameterList.add(deviceIdentificationParameter);
    final FaultResponseDto faultResponse = this.faultResponseForException(exception, parameterList, defaultMessage);
    action.setResponse(faultResponse);
}
Also used : FaultResponseParameterDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseParameterDto) ArrayList(java.util.ArrayList) FaultResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseDto)

Example 4 with FaultResponseParameterDto

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

the class BundleServiceTest method exceptionDetailsWithDefaultComponentInFaultResponse.

@Test
public void exceptionDetailsWithDefaultComponentInFaultResponse() throws Exception {
    final String message = "Unexpected null/unspecified value for M-Bus Capture Time";
    final Exception exception = new ProtocolAdapterException(message);
    this.parameters.add(new FaultResponseParameterDto("deviceIdentification", "ESIM1400000000123"));
    this.parameters.add(new FaultResponseParameterDto("gasDeviceIdentification", "ESIMG140000000841"));
    this.parameters.add(new FaultResponseParameterDto("channel", "3"));
    final String defaultMessage = "Unable to handle request";
    final FaultResponseDto faultResponse = this.bundleService.faultResponseForException(exception, this.parameters, defaultMessage);
    this.assertResponse(faultResponse, null, defaultMessage, this.defaultComponent.name(), exception.getClass().getName(), message, this.parameters);
}
Also used : FaultResponseParameterDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseParameterDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) FaultResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException) Test(org.junit.jupiter.api.Test)

Example 5 with FaultResponseParameterDto

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

the class BundleServiceTest method assertResponse.

public void assertResponse(final FaultResponseDto actualResponse, final Integer expectedCode, final String expectedMessage, final String expectedComponent, final String expectedInnerException, final String expectedInnerMessage, final List<FaultResponseParameterDto> expectedParameterList) {
    assertThat(actualResponse).withFailMessage("FaultResponse").isNotNull();
    /*
     * Fault Response should not contain the result fields for a generic
     * Action Response, and the result should always be NOT OK.
     */
    assertThat(actualResponse.getException()).withFailMessage("exception").isNull();
    assertThat(actualResponse.getResultString()).withFailMessage("resultString").isNull();
    assertThat(actualResponse.getResult()).withFailMessage("result").isEqualTo(OsgpResultTypeDto.NOT_OK);
    assertThat(actualResponse.getCode()).withFailMessage("code").isEqualTo(expectedCode);
    assertThat(actualResponse.getMessage()).withFailMessage("message").isEqualTo(expectedMessage);
    assertThat(actualResponse.getComponent()).withFailMessage("component").isEqualTo(expectedComponent);
    assertThat(actualResponse.getInnerException()).withFailMessage("innerException").isEqualTo(expectedInnerException);
    assertThat(actualResponse.getInnerMessage()).withFailMessage("innerMessage").isEqualTo(expectedInnerMessage);
    if (expectedParameterList == null || expectedParameterList.isEmpty()) {
        assertThat(actualResponse.getFaultResponseParameters()).withFailMessage("parameters").isNull();
    } else {
        assertThat(actualResponse.getFaultResponseParameters()).withFailMessage("parameters").isNotNull();
        final List<FaultResponseParameterDto> actualParameterList = actualResponse.getFaultResponseParameters().getParameterList();
        assertThat(actualParameterList).withFailMessage("parameter list").isNotNull();
        final int numberOfParameters = expectedParameterList.size();
        assertThat(actualParameterList.size()).withFailMessage("number of parameters").isEqualTo(numberOfParameters);
        for (int i = 0; i < numberOfParameters; i++) {
            final FaultResponseParameterDto expectedParameter = expectedParameterList.get(i);
            final FaultResponseParameterDto actualParameter = actualParameterList.get(i);
            final int parameterNumber = i + 1;
            assertThat(actualParameter.getKey()).withFailMessage("parameter key " + parameterNumber).isEqualTo(expectedParameter.getKey());
            assertThat(actualParameter.getValue()).withFailMessage("parameter value " + parameterNumber).isEqualTo(expectedParameter.getValue());
        }
    }
}
Also used : FaultResponseParameterDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseParameterDto)

Aggregations

FaultResponseParameterDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseParameterDto)8 ArrayList (java.util.ArrayList)4 FaultResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseDto)3 Test (org.junit.jupiter.api.Test)2 FaultResponseParameter (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.FaultResponseParameter)2 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)1 ActionDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionDto)1 BundleMessagesRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto)1 ComponentType (org.opensmartgridplatform.shared.exceptionhandling.ComponentType)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 FunctionalExceptionType (org.opensmartgridplatform.shared.exceptionhandling.FunctionalExceptionType)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)1