Search in sources :

Example 26 with ProtocolAdapterException

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);
    });
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) Test(org.junit.jupiter.api.Test)

Example 27 with ProtocolAdapterException

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);
    });
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) ArrayList(java.util.ArrayList) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) Test(org.junit.jupiter.api.Test)

Example 28 with ProtocolAdapterException

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());
    }
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 29 with ProtocolAdapterException

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);
}
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 30 with ProtocolAdapterException

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);
}
Also used : FirmwareFile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.firmware.firmwarefile.FirmwareFile) IOException(java.io.IOException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Aggregations

ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)95 DataObject (org.openmuc.jdlms.datatypes.DataObject)32 Test (org.junit.jupiter.api.Test)22 AccessResultCode (org.openmuc.jdlms.AccessResultCode)15 GetResult (org.openmuc.jdlms.GetResult)15 AttributeAddress (org.openmuc.jdlms.AttributeAddress)14 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)10 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)9 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)9 BitString (org.openmuc.jdlms.datatypes.BitString)7 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)7 ObisCode (org.openmuc.jdlms.ObisCode)6 SetParameter (org.openmuc.jdlms.SetParameter)5 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)5 DateTime (org.joda.time.DateTime)4 DlmsObjectType (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType)4 ConfigurationFlagsDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto)4 Date (java.util.Date)3 List (java.util.List)3