use of org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseParameterDto 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);
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseParameterDto in project open-smart-grid-platform by OSGP.
the class BundleResponseMessageProcessorTest 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());
}
}
}
use of org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseParameterDto in project open-smart-grid-platform by OSGP.
the class FaultResponseConverter method createFaultResponseParameterList.
private List<FaultResponseParameter> createFaultResponseParameterList(final FaultResponseParametersDto faultResponseParametersDto) {
final List<FaultResponseParameter> faultResponseParameterList = new ArrayList<>();
for (final FaultResponseParameterDto parameterDto : faultResponseParametersDto.getParameterList()) {
final String key = parameterDto.getKey();
final String value = parameterDto.getValue();
final FaultResponseParameter parameter = new FaultResponseParameter(key, value);
faultResponseParameterList.add(parameter);
}
return faultResponseParameterList;
}
Aggregations