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);
}
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);
});
}
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);
});
}
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);
});
}
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);
});
}
Aggregations