CosDpValueUnion value = new CosDpValueUnion();
// TODO: check for datastore notification!
// create source datapoint
RealDataPoint source = new RealDataPoint(CosDpValueTypeEnum.TypeNumber);
source.keyId = keyId++;
source.name = "source-datapoint";
// set the source datapoint's value
intStatus = source.setNumberSourceValue(100, false);
Assert.assertEquals(1, intStatus);
Assert.assertEquals(100, source.getValue().longValue());
// set source point quality to good
intStatus = source.setSourceQuality(CosDpQualityEnum.QualityGood, false);
Assert.assertEquals(1, intStatus);
Assert.assertEquals(CosDpQualityEnum.QualityGood, source.getSourceQuality());
Assert.assertEquals(CosDpQualityEnum.QualityGood, source.getQuality());
// create list of datapoint
DataPointList dpList = new DataPointList();
dpList.add(source);
// real-boolean datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeNumber);
datapoint.keyId = keyId++;
datapoint.name = "real-number";
// set reading rollover to understandable value
intStatus = datapoint.setReadingRollOver(1000);
Assert.assertEquals(1000, intStatus);
Assert.assertEquals(1000, datapoint.getReadingRollOver());
// initial value
Assert.assertEquals(false, datapoint.isOverride());
Assert.assertEquals(0, datapoint.getSourceValue().longValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getSourceQuality());
Assert.assertEquals(0, datapoint.getValue().longValue());
Assert.assertEquals(0, datapoint.getTimestamp());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getQuality());
// last meter reading
Assert.assertEquals(0, datapoint.getLastMeterReading());
Assert.assertEquals(0, datapoint.getUpdateTimestamp());
sourceTs = Calendar.getInstance().getTimeInMillis();
outputTs = datapoint.getTimestamp();
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set meter source point
boolStatus = datapoint.setMeterSourcePoint(source);
Assert.assertEquals(true, boolStatus);
// source quality is set to good, source timestamp is set to current
// time
Assert.assertTrue(datapoint.getSourceTimestamp() > sourceTs);
Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint
.getSourceQuality());
Assert.assertEquals(100, datapoint.getSourceValue().longValue());
// output quality/output timestamp is synchronized
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint
.getTimestamp());
Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint
.getQuality());
Assert.assertEquals(100, datapoint.getValue().longValue());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
sourceTs = Calendar.getInstance().getTimeInMillis();
outputTs = datapoint.getTimestamp();
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set new reading value (normal accumulation)
intStatus = source.setNumberSourceValue(130, false);
Assert.assertEquals(1, intStatus);
Assert.assertEquals(130, source.getValue().longValue());
// source quality is set to good, source timestamp is set to current
// time
Assert.assertTrue(datapoint.getSourceTimestamp() > sourceTs);
Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint
.getSourceQuality());
Assert.assertEquals(130, datapoint.getSourceValue().longValue());
// output quality/output timestamp is synchronized
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint
.getTimestamp());
Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint
.getQuality());
Assert.assertEquals(130, datapoint.getValue().longValue());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
sourceTs = datapoint.getSourceTimestamp();
updateTs = Calendar.getInstance().getTimeInMillis();
outputTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set override (bool value)
value.longValue(10);
boolStatus = datapoint.setOverride(value);
Assert.assertEquals(true, boolStatus);
// override flag is set
Assert.assertEquals(true, datapoint.isOverride());
// no update on source value/quality/timestamp
Assert.assertEquals(130, datapoint.getSourceValue().longValue());
Assert.assertEquals(sourceTs, datapoint.getSourceTimestamp());
Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint
.getSourceQuality());
// output quality is set to QualityOverride, output value set to
// override value
// output timestamp set to current time
Assert.assertEquals(10, datapoint.getValue().longValue());
Assert.assertTrue(datapoint.getTimestamp() > outputTs);
Assert.assertEquals(CosDpQualityEnum.QualityOverride, datapoint
.getQuality());
// update-timestamp is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
// TODO: check for datapoint notification
sourceTs = Calendar.getInstance().getTimeInMillis();
updateTs = Calendar.getInstance().getTimeInMillis();
outputTs = datapoint.getTimestamp();
sleep(1);
// set source value (rollover value)
intStatus = source.setNumberSourceValue(50, false);
Assert.assertEquals(1, intStatus);
Assert.assertEquals(50, source.getValue().longValue());
// source value is updated, source timestamp is updated to current time
Assert.assertEquals(1050, datapoint.getSourceValue().longValue());
Assert.assertTrue(datapoint.getSourceTimestamp() > sourceTs);
Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint
.getSourceQuality());
// no update on output value/quality/timestamp
Assert.assertEquals(10, datapoint.getValue().longValue());
Assert.assertTrue(datapoint.getTimestamp() == outputTs);
Assert.assertEquals(CosDpQualityEnum.QualityOverride, datapoint
.getQuality());
// update timestamp is updated to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
// TODO: check for datapoint notification
sourceTs = datapoint.getSourceTimestamp();
updateTs = Calendar.getInstance().getTimeInMillis();
outputTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// re-override with new value (succed with override value updated)
value.longValue(110);
boolStatus = datapoint.setOverride(value);
Assert.assertEquals(true, boolStatus);
// no update on source value/quality/timestamp
Assert.assertEquals(1050, datapoint.getSourceValue().longValue());
Assert.assertTrue(datapoint.getSourceTimestamp() == sourceTs);
Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint
.getSourceQuality());
// output value is updated with new override value, output timestamp is
// set to current time
Assert.assertEquals(110, datapoint.getValue().longValue());
Assert.assertTrue(datapoint.getTimestamp() > outputTs);
Assert.assertEquals(CosDpQualityEnum.QualityOverride, datapoint
.getQuality());
// update-timestamp is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
// TODO: check for datapoint notification
sourceTs = Calendar.getInstance().getTimeInMillis();
outputTs = datapoint.getTimestamp();
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set new quality with timestamp update
intStatus = source.setSourceQuality(CosDpQualityEnum.QualityBad, false);
Assert.assertEquals(1, intStatus);
Assert.assertEquals(CosDpQualityEnum.QualityBad, source.getQuality());
// source quality is updated, source timestamp is updated to current
// time
Assert.assertEquals(1050, datapoint.getSourceValue().longValue());
Assert.assertTrue(datapoint.getSourceTimestamp() > sourceTs);
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint