use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class GetConfigurationObjectServiceDsmr4Test method getConfigurationObjectResultDataNotComplex.
@Test
public void getConfigurationObjectResultDataNotComplex() throws ProtocolAdapterException {
// SETUP
final DataObject nonComplex = mock(DataObject.class);
when(nonComplex.isComplex()).thenReturn(false);
when(this.getResult.getResultData()).thenReturn(nonComplex);
assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> {
// CALL
this.instance.getConfigurationObject(this.getResult);
});
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class GetConfigurationObjectServiceDsmr4Test method getConfigurationObjectFlagsNull.
@Test
public void getConfigurationObjectFlagsNull() throws ProtocolAdapterException {
// SETUP
final DataObject structure = mock(DataObject.class);
when(structure.isComplex()).thenReturn(true);
when(this.getResult.getResultData()).thenReturn(structure);
final List<DataObject> elements = new ArrayList<>();
final DataObject gprsMode = mock(DataObject.class);
when(gprsMode.isNumber()).thenReturn(true);
when(gprsMode.getValue()).thenReturn(42);
elements.add(gprsMode);
// flags is null
elements.add(null);
when(structure.getValue()).thenReturn(elements);
assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> {
// CALL
this.instance.getConfigurationObject(this.getResult);
});
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class GetFirmwareFileResponseMessageProcessor method handleMessage.
@Override
protected Serializable handleMessage(final DlmsConnectionManager conn, final DlmsDevice device, final Serializable response) throws OsgpException {
if (!(response instanceof ResponseMessage)) {
throw new ProtocolAdapterException("Invalid response type, expected ResponseMessage object.");
}
final ResponseMessage responseMessage = (ResponseMessage) response;
if (ResponseMessageResultType.OK.equals(responseMessage.getResult())) {
final FirmwareFileDto firmwareFileDto = (FirmwareFileDto) responseMessage.getDataObject();
final MessageMetadata messageMetadata = this.messageMetadataFromResponseMessage(responseMessage);
return this.firmwareService.updateFirmware(conn, device, firmwareFileDto, messageMetadata);
} else {
throw new ProtocolAdapterException("Get Firmware File failed.", responseMessage.getOsgpException());
}
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException 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.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class MacGenerationServiceTest method assertExceptionContainsMessageOnCalculateMac.
private void assertExceptionContainsMessageOnCalculateMac(final Class<? extends Exception> exceptionClass, final byte[] malformedFirmwareFile, final String partOfExceptionMessage, final String deviceIdentification) throws ProtocolAdapterException {
final FirmwareFile firmwareFile = new FirmwareFile(malformedFirmwareFile);
firmwareFile.setMbusDeviceIdentificationNumber(deviceIdentification.substring(7, 15));
final Exception exception = assertThrows(exceptionClass, () -> {
this.macGenerationService.calculateMac(messageMetadata, deviceIdentification, firmwareFile);
});
assertThat(exception).hasMessageContaining(partOfExceptionMessage);
}
Aggregations