use of org.openmuc.framework.data.Flag in project OpenMUC by isc-konstanz.
the class FromJson method convertRecord.
public static Record convertRecord(RestRecord rrc, ValueType type) throws ClassCastException {
Object value = rrc.getValue();
Flag flag = rrc.getFlag();
Value retValue = null;
if (value != null) {
retValue = convertValue(value, type);
}
if (flag == null) {
return new Record(retValue, rrc.getTimestamp());
} else {
return new Record(retValue, rrc.getTimestamp(), rrc.getFlag());
}
}
use of org.openmuc.framework.data.Flag in project OpenMUC by isc-konstanz.
the class OpenmucParserServiceImplTest method serializeDoubleValue.
@Test
void serializeDoubleValue() throws SerializationException {
String controlString = "{\"timestamp\":1582722316,\"flag\":\"VALID\",\"value\":3.0}";
Value doubleValue = new DoubleValue(3.0);
long timestamp = 1582722316;
Flag flag = Flag.VALID;
Record record = new Record(doubleValue, timestamp, flag);
byte[] serializedRecord = parserService.serialize(record, new SerializationContainerTest());
String serializedJson = new String(serializedRecord);
assertEquals(controlString, serializedJson);
}
use of org.openmuc.framework.data.Flag in project OpenMUC by isc-konstanz.
the class OpenmucParserServiceImplTest method serializeStringValue.
@Test
void serializeStringValue() throws SerializationException {
String controlString = "{\"timestamp\":1582722316,\"flag\":\"VALID\",\"value\":\"test\"}";
Value doubleValue = new StringValue("test");
long timestamp = 1582722316;
Flag flag = Flag.VALID;
Record record = new Record(doubleValue, timestamp, flag);
byte[] serializedRecord = parserService.serialize(record, new SerializationContainerTest());
String serializedJson = new String(serializedRecord);
assertEquals(controlString, serializedJson);
}
use of org.openmuc.framework.data.Flag in project OpenMUC by isc-konstanz.
the class OpenmucParserServiceImplTest method serializeByteArrayValue.
@Test
void serializeByteArrayValue() throws SerializationException {
String controlString = "{\"timestamp\":1582722316,\"flag\":\"VALID\",\"value\":\"dGVzdA==\"}";
Value byteArrayValue = new ByteArrayValue("test".getBytes());
long timestamp = 1582722316;
Flag flag = Flag.VALID;
Record record = new Record(byteArrayValue, timestamp, flag);
byte[] serializedRecord = parserService.serialize(record, new SerializationContainerTest());
String serializedJson = new String(serializedRecord);
assertEquals(controlString, serializedJson);
}
use of org.openmuc.framework.data.Flag in project OpenMUC by isc-konstanz.
the class DriverConnectionTest method testReadThrowsIOException.
@Test
public void testReadThrowsIOException() throws Exception {
MBusConnection con = mock(MBusConnection.class);
VariableDataStructure vds = new VariableDataStructure(NZR_ANSWER, 6, NZR_ANSWER.length - 6, null, null);
vds.decode();
when(con.read(anyInt())).thenThrow(new IOException());
ConnectionInterface serialIntervace = new ConnectionInterface(con, "/dev/ttyS100:5", delay, interfaces);
serialIntervace.increaseConnectionCounter();
String[] deviceAddressTokens = { "/dev/ttyS100", "5" };
int address = Integer.parseInt(deviceAddressTokens[1]);
DriverConnection driverCon = new DriverConnection(serialIntervace, address, null, delay);
List<ChannelRecordContainer> records = Arrays.asList(newChannelRecordContainer("04:03"));
driverCon.read(records, null, null);
Flag actualFlag = records.get(0).getRecord().getFlag();
assertEquals(Flag.DRIVER_ERROR_TIMEOUT, actualFlag);
}
Aggregations