* .
*/
public void testSetSourceValueCosDpValueUnion() {
int keyId = 1;
CosDpValueUnion value = new CosDpValueUnion();
DataPointImpl datapoint = null;
int status = 0;
long updateTs = Calendar.getInstance().getTimeInMillis();
// TODO: check for datastore notification!
// set with null value
datapoint = new DataPointImpl(EDataPointType.TYPE_REAL,
CosDpValueTypeEnum.TypeBoolean);
datapoint.keyId = keyId++;
datapoint.name = "real-boolean";
//initial state
Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertEquals(0, datapoint.getTimestamp());
//set without timestamp update
status = datapoint.setSourceValue(null, false);
Assert.assertEquals(-1, status);
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertEquals(0, datapoint.getTimestamp());
//set with timestamp update
status = datapoint.setSourceValue(null, true);
Assert.assertEquals(-1, status);
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// REAL datapoint
// real-boolean datapoint
datapoint = new DataPointImpl(EDataPointType.TYPE_REAL,
CosDpValueTypeEnum.TypeBoolean);
datapoint.keyId = keyId++;
datapoint.name = "real-boolean";
// initial value
Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// set without timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.boolValue(true);
status = datapoint.setSourceValue(value, false);
Assert.assertEquals(1, status);
// source value is updated, source timestamp is not updated
Assert.assertEquals(true, datapoint.getSourceValue().boolValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
// output value/timestamp is synchronized with source value/timestamp
Assert.assertEquals(true, datapoint.getValue().boolValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
// set with timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.boolValue(false);
status = datapoint.setSourceValue(value, true);
Assert.assertEquals(1, status);
// source value is updated, source timestamp is set to current time
Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
// ouput value/timestamp is synchronized with source value/timestamp
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
//TODO: check for the same value
// real-number datapoint
datapoint = new DataPointImpl(EDataPointType.TYPE_REAL,
CosDpValueTypeEnum.TypeNumber);
datapoint.keyId = keyId++;
datapoint.name = "real-number";
// initial value
Assert.assertEquals(0, datapoint.getSourceValue().longValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(0, datapoint.getValue().longValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// set without timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.longValue(11);
status = datapoint.setSourceValue(value, false);
Assert.assertEquals(1, status);
// source value is updated, source timestamp is not updated
Assert.assertEquals(11, datapoint.getSourceValue().longValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
// output value/timestamp is synchronized with source value/timestamp
Assert.assertEquals(11, datapoint.getValue().longValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
// set with timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.longValue(15);
status = datapoint.setSourceValue(value, true);
Assert.assertEquals(1, status);
// source value is updated, source timestamp is set to current time
Assert.assertEquals(15, datapoint.getSourceValue().longValue());
Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
// output value/timestamp is synchronized with source value/timestamp
Assert.assertEquals(15, datapoint.getValue().longValue());
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
//TODO: check for the same value
//TODO: check for engineering conversion
//TODO: check for deadband
// real-unsigned datapoint
datapoint = new DataPointImpl(EDataPointType.TYPE_REAL,
CosDpValueTypeEnum.TypeUnsigned);
datapoint.keyId = keyId++;
datapoint.name = "real-unsigned";
// initial value
Assert.assertEquals(0, datapoint.getSourceValue().unsignedValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(0, datapoint.getValue().unsignedValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// set without timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.unsignedValue(11);
status = datapoint.setSourceValue(value, false);
Assert.assertEquals(1, status);
Assert.assertEquals(11, datapoint.getSourceValue().unsignedValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(11, datapoint.getValue().unsignedValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
// set with timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.longValue(15);
status = datapoint.setSourceValue(value, true);
Assert.assertEquals(1, status);
Assert.assertEquals(15, datapoint.getSourceValue().unsignedValue());
Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
Assert.assertEquals(15, datapoint.getValue().unsignedValue());
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
//TODO: check for the same value
//TODO: check for engineering conversion
//TODO: check for deadband
// real-double datapoint
datapoint = new DataPointImpl(EDataPointType.TYPE_REAL,
CosDpValueTypeEnum.TypeDouble);
datapoint.keyId = keyId++;
datapoint.name = "real-double";
// initial value
Assert.assertEquals(0.0, datapoint.getSourceValue().dblValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(0.0, datapoint.getValue().dblValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// set without timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.dblValue(11.5);
status = datapoint.setSourceValue(value, false);
Assert.assertEquals(1, status);
Assert.assertEquals(11.5, datapoint.getSourceValue().dblValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(11.5, datapoint.getValue().dblValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
// set with timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.dblValue(15.7);
status = datapoint.setSourceValue(value, true);
Assert.assertEquals(1, status);
Assert.assertEquals(15.7, datapoint.getSourceValue().dblValue());
Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
Assert.assertEquals(15.7, datapoint.getValue().dblValue());
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
//TODO: check for the same value
//TODO: check for engineering conversion
//TODO: check for deadband
// real-string datapoint
datapoint = new DataPointImpl(EDataPointType.TYPE_REAL,
CosDpValueTypeEnum.TypeString);
datapoint.keyId = keyId++;
datapoint.name = "real-string";
// initial value
Assert.assertTrue(datapoint.getSourceValue().charValue().compareTo("") == 0);
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
Assert.assertEquals(0, datapoint.getTimestamp());
// set without timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.charValue("Test");
status = datapoint.setSourceValue(value, false);
Assert.assertEquals(1, status);
Assert.assertTrue(datapoint.getSourceValue().charValue().compareTo("Test") == 0);
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertTrue(datapoint.getValue().charValue().compareTo("Test") == 0);
Assert.assertEquals(0, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
// set with timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.charValue("TestTest");
status = datapoint.setSourceValue(value, true);
Assert.assertEquals(1, status);
Assert.assertTrue(datapoint.getSourceValue().charValue().compareTo("TestTest") == 0);
Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
Assert.assertTrue(datapoint.getValue().charValue().compareTo("Test") == 0);
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
//TODO: check for the same value
// VIRTUAL datapoint
//TODO: implement proper;y
// virtual-boolean datapoint
datapoint = new DataPointImpl(EDataPointType.TYPE_VIRTUAL,
CosDpValueTypeEnum.TypeBoolean);
datapoint.keyId = keyId++;
datapoint.name = "virtual-boolean";
//initial value
Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertEquals(0, datapoint.getTimestamp());
//set value (with timestamp)
value.boolValue(true);
status = datapoint.setSourceValue(value, true);
Assert.assertEquals(-1, status);
Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// virtual-number datapoint
datapoint = new DataPointImpl(EDataPointType.TYPE_VIRTUAL,
CosDpValueTypeEnum.TypeNumber);
datapoint.keyId = keyId++;
datapoint.name = "virtual-number";
//initial value
Assert.assertEquals(0, datapoint.getSourceValue().longValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(0, datapoint.getValue().longValue());
Assert.assertEquals(0, datapoint.getTimestamp());
//set value (with timestamp)
value.longValue(11);
status = datapoint.setSourceValue(value, true);
Assert.assertEquals(-1, status);
Assert.assertEquals(0, datapoint.getSourceValue().longValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(0, datapoint.getValue().longValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// virtual-unsigned datapoint
datapoint = new DataPointImpl(EDataPointType.TYPE_VIRTUAL,
CosDpValueTypeEnum.TypeUnsigned);
datapoint.keyId = keyId++;
datapoint.name = "virtual-unsigned";
//initial value
Assert.assertEquals(0, datapoint.getSourceValue().unsignedValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(0, datapoint.getValue().unsignedValue());
Assert.assertEquals(0, datapoint.getTimestamp());
//set value (with timestamp)
value.unsignedValue(11);
status = datapoint.setSourceValue(value, true);
Assert.assertEquals(-1, status);
Assert.assertEquals(0, datapoint.getSourceValue().unsignedValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(0, datapoint.getValue().unsignedValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// virtual-double datapoint
datapoint = new DataPointImpl(EDataPointType.TYPE_VIRTUAL,
CosDpValueTypeEnum.TypeDouble);
datapoint.keyId = keyId++;
datapoint.name = "virtual-double";
//initial value
Assert.assertEquals(0.0, datapoint.getSourceValue().dblValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(0.0, datapoint.getValue().dblValue());
Assert.assertEquals(0, datapoint.getTimestamp());
//set value (with timestamp)
value.dblValue(11.5);
status = datapoint.setSourceValue(value, true);
Assert.assertEquals(-1, status);
Assert.assertEquals(0.0, datapoint.getSourceValue().dblValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(0.0, datapoint.getValue().dblValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// virtual-string datapoint
datapoint = new DataPointImpl(EDataPointType.TYPE_VIRTUAL,
CosDpValueTypeEnum.TypeString);
datapoint.keyId = keyId++;
datapoint.name = "virtual-string";
//initial state
Assert.assertTrue(datapoint.getSourceValue().charValue().compareTo("") == 0);
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
Assert.assertEquals(0, datapoint.getTimestamp());
//set value with timestamp
value.charValue("Test");
status = datapoint.setSourceValue(value, true);
Assert.assertEquals(-1, status);
Assert.assertTrue(datapoint.getSourceValue().charValue().compareTo("") == 0);
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
Assert.assertEquals(0, datapoint.getTimestamp());
// CALCULATED datapoint
// calculated-boolean datapoint
datapoint = new DataPointImpl(EDataPointType.TYPE_CALCULATED,
CosDpValueTypeEnum.TypeBoolean);
datapoint.keyId = keyId++;
datapoint.name = "calculated-boolean";
// initial value
Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// set without timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.boolValue(true);
status = datapoint.setSourceValue(value, false);
Assert.assertEquals(1, status);
Assert.assertEquals(true, datapoint.getSourceValue().boolValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(true, datapoint.getValue().boolValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
// set with timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.boolValue(false);
status = datapoint.setSourceValue(value, true);
Assert.assertEquals(1, status);
Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
// calculated-number datapoint
datapoint = new DataPointImpl(EDataPointType.TYPE_CALCULATED,
CosDpValueTypeEnum.TypeNumber);
datapoint.keyId = keyId++;
datapoint.name = "calculated-number";
// initial value
Assert.assertEquals(0, datapoint.getSourceValue().longValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(0, datapoint.getValue().longValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// set without timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.longValue(11);
status = datapoint.setSourceValue(value, false);
Assert.assertEquals(1, status);
Assert.assertEquals(11, datapoint.getSourceValue().longValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(11, datapoint.getValue().longValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
// set with timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.longValue(15);
status = datapoint.setSourceValue(value, true);
Assert.assertEquals(1, status);
Assert.assertEquals(15, datapoint.getSourceValue().longValue());
Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
Assert.assertEquals(15, datapoint.getValue().longValue());
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
// calculated-unsigned datapoint
datapoint = new DataPointImpl(EDataPointType.TYPE_CALCULATED,
CosDpValueTypeEnum.TypeUnsigned);
datapoint.keyId = keyId++;
datapoint.name = "calculated-unsigned";
// initial value
Assert.assertEquals(0, datapoint.getSourceValue().unsignedValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(0, datapoint.getValue().unsignedValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// set without timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.unsignedValue(11);
status = datapoint.setSourceValue(value, false);
Assert.assertEquals(1, status);
Assert.assertEquals(11, datapoint.getSourceValue().unsignedValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(11, datapoint.getValue().unsignedValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
// set with timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.longValue(15);
status = datapoint.setSourceValue(value, true);
Assert.assertEquals(1, status);
Assert.assertEquals(15, datapoint.getSourceValue().unsignedValue());
Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
Assert.assertEquals(15, datapoint.getValue().unsignedValue());
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
// calculated-double datapoint
datapoint = new DataPointImpl(EDataPointType.TYPE_CALCULATED,
CosDpValueTypeEnum.TypeDouble);
datapoint.keyId = keyId++;
datapoint.name = "calculated-double";
// initial value
Assert.assertEquals(0.0, datapoint.getSourceValue().dblValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(0.0, datapoint.getValue().dblValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// set without timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.dblValue(11.5);
status = datapoint.setSourceValue(value, false);
Assert.assertEquals(1, status);
Assert.assertEquals(11.5, datapoint.getSourceValue().dblValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(11.5, datapoint.getValue().dblValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
// set with timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.dblValue(15.7);
status = datapoint.setSourceValue(value, true);
Assert.assertEquals(1, status);
Assert.assertEquals(15.7, datapoint.getSourceValue().dblValue());
Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
Assert.assertEquals(15.7, datapoint.getValue().dblValue());
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
// calculated-string datapoint
datapoint = new DataPointImpl(EDataPointType.TYPE_CALCULATED,
CosDpValueTypeEnum.TypeString);
datapoint.keyId = keyId++;
datapoint.name = "calculated-string";
// initial value
Assert.assertTrue(datapoint.getSourceValue().charValue().compareTo("") == 0);
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
Assert.assertEquals(0, datapoint.getTimestamp());
// set without timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.charValue("Test");
status = datapoint.setSourceValue(value, false);
Assert.assertEquals(1, status);
Assert.assertTrue(datapoint.getSourceValue().charValue().compareTo("Test") == 0);
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertTrue(datapoint.getValue().charValue().compareTo("Test") == 0);
Assert.assertEquals(0, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
// set with timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.charValue("TestTest");
status = datapoint.setSourceValue(value, true);
Assert.assertEquals(1, status);
Assert.assertTrue(datapoint.getSourceValue().charValue().compareTo("TestTest") == 0);
Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
Assert.assertTrue(datapoint.getValue().charValue().compareTo("Test") == 0);
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
// METER datapoint
// Meter datapoint is only supported for number/unsigned datatype
// meter-boolean datapoint (not supported. reset to number type)
// meter-number datapoint
datapoint = new DataPointImpl(EDataPointType.TYPE_METER,
CosDpValueTypeEnum.TypeNumber);
datapoint.keyId = keyId++;
datapoint.name = "meter-number";
// initial value
Assert.assertEquals(0, datapoint.getSourceValue().longValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(0, datapoint.getValue().longValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// set without timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.longValue(11);
status = datapoint.setSourceValue(value, false);
Assert.assertEquals(1, status);
Assert.assertEquals(11, datapoint.getSourceValue().longValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(11, datapoint.getValue().longValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
// set with timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.longValue(15);
status = datapoint.setSourceValue(value, true);
Assert.assertEquals(1, status);
Assert.assertEquals(26, datapoint.getSourceValue().longValue());
Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
Assert.assertEquals(26, datapoint.getValue().longValue());
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
//TODO: check for reading rollover
//TODO: check for datapoint rollover
// meter-unsigned datapoint
datapoint = new DataPointImpl(EDataPointType.TYPE_METER,
CosDpValueTypeEnum.TypeUnsigned);
datapoint.keyId = keyId++;
datapoint.name = "real-unsigned";
// initial value
Assert.assertEquals(0, datapoint.getSourceValue().unsignedValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(0, datapoint.getValue().unsignedValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// set without timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.unsignedValue(11);
status = datapoint.setSourceValue(value, false);
Assert.assertEquals(1, status);
Assert.assertEquals(11, datapoint.getSourceValue().unsignedValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(11, datapoint.getValue().unsignedValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
// set with timestamp
updateTs = Calendar.getInstance().getTimeInMillis();
value.longValue(15);
status = datapoint.setSourceValue(value, true);
Assert.assertEquals(1, status);
Assert.assertEquals(26, datapoint.getSourceValue().unsignedValue());
Assert.assertTrue(datapoint.getSourceTimestamp() >= updateTs);
Assert.assertEquals(26, datapoint.getValue().unsignedValue());
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() >= updateTs);
//TODO: check for reading rollover
//TODO: check for datapoint rollover
// meter-double datapoint (not supported. reset to number type)
// meter-string datapoint (not supported. reset to number type)
// OUTPUT datapoint
// Output datapoint is only supported for boolean/number datatype
// output-boolean datapoint
datapoint = new DataPointImpl(EDataPointType.TYPE_OUTPUT,
CosDpValueTypeEnum.TypeBoolean);
datapoint.keyId = keyId++;
datapoint.name = "output-boolean";
//initial value
Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertEquals(0, datapoint.getTimestamp());
//set value (with timestamp)
value.boolValue(true);
status = datapoint.setSourceValue(value, true);
Assert.assertEquals(-1, status);
Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertEquals(0, datapoint.getTimestamp());
// output-number datapoint
datapoint = new DataPointImpl(EDataPointType.TYPE_OUTPUT,
CosDpValueTypeEnum.TypeNumber);
datapoint.keyId = keyId++;
datapoint.name = "output-number";
//initial value
Assert.assertEquals(0, datapoint.getSourceValue().longValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(0, datapoint.getValue().longValue());
Assert.assertEquals(0, datapoint.getTimestamp());
//set value (with timestamp)
value.longValue(11);
status = datapoint.setSourceValue(value, true);
Assert.assertEquals(-1, status);
Assert.assertEquals(0, datapoint.getSourceValue().longValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(0, datapoint.getValue().longValue());