Search in sources :

Example 21 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class GetActualPowerQualityCommandExecutorTest method testOtherReasonResult.

@Test
void testOtherReasonResult() throws ProtocolAdapterException {
    this.actualPowerQualityRequestDto = new ActualPowerQualityRequestDto("PRIVATE");
    final List<GetActualPowerQualityCommandExecutor.PowerQualityObjectMetadata> metadatas = GetActualPowerQualityCommandExecutor.getMetadatasPrivate();
    doReturn(this.generateMockedResult(metadatas, AccessResultCode.OTHER_REASON)).when(this.dlmsHelper).getAndCheck(eq(this.conn), eq(this.dlmsDevice), eq("retrieve actual power quality"), any(AttributeAddress.class));
    assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> {
        new GetActualPowerQualityCommandExecutor(this.dlmsHelper).execute(this.conn, this.dlmsDevice, this.actualPowerQualityRequestDto, this.messageMetadata);
    });
}
Also used : ActualPowerQualityRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualPowerQualityRequestDto) AttributeAddress(org.openmuc.jdlms.AttributeAddress) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) PowerQualityObjectMetadata(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.misc.GetActualPowerQualityCommandExecutor.PowerQualityObjectMetadata) Test(org.junit.jupiter.api.Test)

Example 22 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class FirmwareFileTest method testMisfitMbusDeviceIdentificationNumber.

@Test
public void testMisfitMbusDeviceIdentificationNumber() throws IOException, ProtocolAdapterException {
    final FirmwareFile firmwareFile = this.createPartialWildcardFirmwareFile("FFFF0000");
    final String reversedWildcard = "0000FFFF";
    final String identificationNumber = "00010000";
    final String misfittingMbusDeviceIdentificationNumber = IdentificationNumber.fromTextualRepresentation(identificationNumber).getTextualRepresentation();
    final Exception exception = assertThrows(ProtocolAdapterException.class, () -> {
        firmwareFile.setMbusDeviceIdentificationNumber(misfittingMbusDeviceIdentificationNumber);
    });
    assertThat(exception).hasMessage("M-Bus Device Identification Number (%s) does not fit the range of Identification Numbers supported by this Firmware File (%s)", identificationNumber, reversedWildcard.toLowerCase());
}
Also used : IOException(java.io.IOException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.jupiter.api.Test)

Example 23 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class DataObjectToOutageListConverter method convert.

public List<OutageDto> convert(final DataObject source) throws ProtocolAdapterException {
    final List<OutageDto> eventList = new ArrayList<>();
    if (source == null) {
        throw new ProtocolAdapterException("DataObject should not be null");
    }
    final List<DataObject> dataObjects = source.getValue();
    for (final DataObject dataObject : dataObjects) {
        eventList.add(this.getOutageDto(dataObject));
    }
    return eventList;
}
Also used : DataObject(org.openmuc.jdlms.datatypes.DataObject) OutageDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.OutageDto) ArrayList(java.util.ArrayList) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 24 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class GetConfigurationObjectServiceDsmr4Test method getConfigurationObjectFlagsNotBitString.

@Test
public void getConfigurationObjectFlagsNotBitString() 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);
    final DataObject flags = mock(DataObject.class);
    // flags is not a BitString
    when(flags.isBitString()).thenReturn(false);
    elements.add(flags);
    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 25 with ProtocolAdapterException

use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.

the class GetConfigurationObjectServiceDsmr4Test method getConfigurationObjectGprsModeNull.

@Test
public void getConfigurationObjectGprsModeNull() 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<>();
    // gprs mode is null
    elements.add(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)

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