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