Search in sources :

Example 51 with DataObject

use of org.openmuc.jdlms.datatypes.DataObject in project open-smart-grid-platform by OSGP.

the class SetConfigurationObjectCommandExecutorSmr5IT method execute.

@Test
public void execute() throws IOException, ProtocolAdapterException {
    // SETUP
    // configurationToSet: ------1---10101-
    // GPRS operation mode is not part of the ConfigurationObject in SMR5
    final GprsOperationModeTypeDto gprsMode = null;
    final ConfigurationObjectDto configurationToSet = this.createConfigurationObjectDto(gprsMode, this.createFlagDto(ConfigurationFlagTypeDto.HLS_5_ON_P_3_ENABLE, true), this.createFlagDto(ConfigurationFlagTypeDto.DIRECT_ATTACH_AT_POWER_ON, true), this.createFlagDto(ConfigurationFlagTypeDto.HLS_6_ON_P3_ENABLE, false), this.createFlagDto(ConfigurationFlagTypeDto.HLS_7_ON_P3_ENABLE, true), this.createFlagDto(ConfigurationFlagTypeDto.HLS_6_ON_P0_ENABLE, false), this.createFlagDto(ConfigurationFlagTypeDto.HLS_7_ON_P0_ENABLE, true));
    // flagsOnDevice: 0000000001110100
    final byte[] flagsOnDevice = this.createFlagBytes(ConfigurationFlagTypeDto.HLS_5_ON_PO_ENABLE, ConfigurationFlagTypeDto.DIRECT_ATTACH_AT_POWER_ON, ConfigurationFlagTypeDto.HLS_6_ON_P3_ENABLE, ConfigurationFlagTypeDto.HLS_6_ON_P0_ENABLE);
    // result of merging configurationToSet and flagsOnDevice
    final byte firstExpectedByte = this.asByte("00000010");
    final byte secondExpectedByte = this.asByte("01101010");
    final DataObject deviceData = this.createBitStringData(flagsOnDevice);
    when(this.getResult.getResultData()).thenReturn(deviceData);
    final DlmsDevice device = new DlmsDevice();
    device.setProtocol(Protocol.SMR_5_0_0);
    // CALL
    final AccessResultCode result = this.instance.execute(this.conn, device, configurationToSet, this.messageMetadata);
    // VERIFY
    assertThat(result).isEqualTo(AccessResultCode.SUCCESS);
    final BitString configurationFlags = this.captureSetParameterBitStringData();
    final byte[] flagsSentToDevice = configurationFlags.getBitString();
    assertThat(flagsSentToDevice[0]).isEqualTo(firstExpectedByte);
    assertThat(flagsSentToDevice[1]).isEqualTo(secondExpectedByte);
}
Also used : GprsOperationModeTypeDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GprsOperationModeTypeDto) DataObject(org.openmuc.jdlms.datatypes.DataObject) BitString(org.openmuc.jdlms.datatypes.BitString) ConfigurationObjectDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationObjectDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) AccessResultCode(org.openmuc.jdlms.AccessResultCode) Test(org.junit.jupiter.api.Test)

Example 52 with DataObject

use of org.openmuc.jdlms.datatypes.DataObject 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 53 with DataObject

use of org.openmuc.jdlms.datatypes.DataObject 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)

Example 54 with DataObject

use of org.openmuc.jdlms.datatypes.DataObject 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 55 with DataObject

use of org.openmuc.jdlms.datatypes.DataObject 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)

Aggregations

DataObject (org.openmuc.jdlms.datatypes.DataObject)176 ArrayList (java.util.ArrayList)46 AttributeAddress (org.openmuc.jdlms.AttributeAddress)36 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)34 Test (org.junit.jupiter.api.Test)31 GetResult (org.openmuc.jdlms.GetResult)23 SelectiveAccessDescription (org.openmuc.jdlms.SelectiveAccessDescription)16 DateTime (org.joda.time.DateTime)15 CosemDateTime (org.openmuc.jdlms.datatypes.CosemDateTime)14 SetParameter (org.openmuc.jdlms.SetParameter)12 DlmsObject (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject)11 BitString (org.openmuc.jdlms.datatypes.BitString)10 ObisCode (org.openmuc.jdlms.ObisCode)9 IOException (java.io.IOException)8 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)7 GetResultImpl (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.testutil.GetResultImpl)6 List (java.util.List)5 MethodResultCode (org.openmuc.jdlms.MethodResultCode)5 AttributeAddressForProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.AttributeAddressForProfile)5 DlmsProfile (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsProfile)5