/**
*
*/
package tst.scada.da;
import java.util.Calendar;
import tcg.scada.cos.CosDpQualityEnum;
import tcg.scada.cos.CosDpValueStruct;
import tcg.scada.cos.CosDpValueTypeEnum;
import tcg.scada.cos.CosDpValueUnion;
import tcg.scada.da.RealDataPoint;
import tcg.scada.da.EDataPointType;
import junit.framework.Assert;
/**
* Unit test for real datapoint.
*
* @author Yoga
*
*/
public class RealDataPointTest extends DataPointTest
{
protected void setUp() throws java.lang.Exception
{
}
/**
* Test method for constructor.
*
* <p>
* Validated functions: </ul>
* <li>{@link tcg.scada.da.RealDataPoint#DataPoint(CosDpValueTypeEnum)}</li>
* </ul>
* </p>
*/
public void testConstructor()
{
int keyId = 1;
DataPointImpl datapoint = null;
// real-boolean datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeBoolean);
datapoint.keyId = keyId++;
datapoint.name = "real-boolean";
Assert.assertEquals(EDataPointType.TYPE_REAL, datapoint.getType());
Assert.assertEquals(CosDpValueTypeEnum.TypeBoolean, datapoint
.getInternalDataType());
Assert.assertEquals(keyId - 1, datapoint.getKeyId());
Assert.assertTrue(datapoint.getName().compareTo("real-boolean") == 0);
// source value/quality/timestamp initial value
Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getSourceQuality());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
// output value/quality/timestamp initial value
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getQuality());
Assert.assertEquals(0, datapoint.getTimestamp());
// update timestamp
Assert.assertEquals(0, datapoint.getUpdateTimestamp());
// real-number datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeNumber);
datapoint.keyId = keyId++;
datapoint.name = "real-number";
Assert.assertEquals(EDataPointType.TYPE_REAL, datapoint.getType());
Assert.assertEquals(CosDpValueTypeEnum.TypeNumber, datapoint
.getInternalDataType());
Assert.assertEquals(keyId - 1, datapoint.getKeyId());
Assert.assertTrue(datapoint.getName().compareTo("real-number") == 0);
// source value/quality/timestamp initial value
Assert.assertEquals(0, datapoint.getSourceValue().longValue());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getSourceQuality());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
// output value/quality/timestamp initial value
Assert.assertEquals(0, datapoint.getValue().longValue());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getQuality());
Assert.assertEquals(0, datapoint.getTimestamp());
// update timestamp
Assert.assertEquals(0, datapoint.getUpdateTimestamp());
// real-unsigned datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeUnsigned);
datapoint.keyId = keyId++;
datapoint.name = "real-unsigned";
Assert.assertEquals(EDataPointType.TYPE_REAL, datapoint.getType());
Assert.assertEquals(CosDpValueTypeEnum.TypeUnsigned, datapoint
.getInternalDataType());
Assert.assertEquals(keyId - 1, datapoint.getKeyId());
Assert.assertTrue(datapoint.getName().compareTo("real-unsigned") == 0);
// source value/quality/timestamp initial value
Assert.assertEquals(0, datapoint.getSourceValue().unsignedValue());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getSourceQuality());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
// output value/quality/timestamp initial value
Assert.assertEquals(0, datapoint.getValue().unsignedValue());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getQuality());
Assert.assertEquals(0, datapoint.getTimestamp());
// update timestamp
Assert.assertEquals(0, datapoint.getUpdateTimestamp());
// real-double datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeDouble);
datapoint.keyId = keyId++;
datapoint.name = "real-double";
Assert.assertEquals(EDataPointType.TYPE_REAL, datapoint.getType());
Assert.assertEquals(CosDpValueTypeEnum.TypeDouble, datapoint
.getInternalDataType());
Assert.assertEquals(keyId - 1, datapoint.getKeyId());
Assert.assertTrue(datapoint.getName().compareTo("real-double") == 0);
// source value/quality/timestamp initial value
Assert.assertEquals(0.0, datapoint.getSourceValue().dblValue());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getSourceQuality());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
// output value/quality/timestamp initial value
Assert.assertEquals(0.0, datapoint.getValue().dblValue());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getQuality());
Assert.assertEquals(0, datapoint.getTimestamp());
// update timestamp
Assert.assertEquals(0, datapoint.getUpdateTimestamp());
// real-string datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeString);
datapoint.keyId = keyId++;
datapoint.name = "real-string";
Assert.assertEquals(EDataPointType.TYPE_REAL, datapoint.getType());
Assert.assertEquals(CosDpValueTypeEnum.TypeString, datapoint
.getInternalDataType());
Assert.assertEquals(keyId - 1, datapoint.getKeyId());
Assert.assertTrue(datapoint.getName().compareTo("real-string") == 0);
// source value/quality/timestamp initial value
Assert.assertNotNull(datapoint.getSourceValue().charValue());
Assert.assertTrue(datapoint.getSourceValue().charValue().isEmpty());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getSourceQuality());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
// output value/quality/timestamp initial value
Assert.assertNotNull(datapoint.getValue().charValue());
Assert.assertTrue(datapoint.getValue().charValue().isEmpty());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getQuality());
Assert.assertEquals(0, datapoint.getTimestamp());
// update timestamp
Assert.assertEquals(0, datapoint.getUpdateTimestamp());
}
/**
* Test method for
* {@link tcg.scada.da.DataPoint#setBooleanSourceValue(boolean, boolean)}.
*/
public void testSetBooleanSourceValue()
{
int keyId = 1;
// CosDpValueUnion value = new CosDpValueUnion();
DataPointImpl datapoint = null;
int status = 0;
long updateTs = Calendar.getInstance().getTimeInMillis();
// TODO: check for datastore notification!
// real-boolean datapoint
datapoint = new DataPointImpl(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());
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set without timestamp
status = datapoint.setBooleanSourceValue(true, 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);
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set with timestamp
status = datapoint.setBooleanSourceValue(false, 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(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
status = datapoint.setBooleanSourceValue(true, false);
Assert.assertEquals(-1, status);
// real-unsigned datapoint
datapoint = new DataPointImpl(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
status = datapoint.setBooleanSourceValue(true, false);
Assert.assertEquals(-1, status);
// real-double datapoint
datapoint = new DataPointImpl(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
status = datapoint.setBooleanSourceValue(true, false);
Assert.assertEquals(-1, status);
// real-string datapoint
datapoint = new DataPointImpl(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
status = datapoint.setBooleanSourceValue(true, false);
Assert.assertEquals(-1, status);
}
/**
* Test method for {@link tcg.scada.da.DataPoint#setBooleanValue(boolean)}.
*/
public void testSetBooleanValue()
{
int keyId = 1;
DataPointImpl datapoint = null;
int status = 0;
// TODO: check for datastore notification!
// REAL datapoint
// real-boolean datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeBoolean);
datapoint.keyId = keyId++;
datapoint.name = "real-boolean";
// initial value
Assert.assertEquals(false, datapoint.getValue().boolValue());
// set with new value
status = datapoint.setBooleanValue(true);
Assert.assertEquals(-1, status);
Assert.assertEquals(false, datapoint.getValue().boolValue());
// real-number datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeNumber);
datapoint.keyId = keyId++;
datapoint.name = "real-number";
// initial value
Assert.assertEquals(0, datapoint.getValue().longValue());
// set with new value
status = datapoint.setBooleanValue(true);
Assert.assertEquals(-1, status);
Assert.assertEquals(0, datapoint.getValue().longValue());
// real-unsigned datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeUnsigned);
datapoint.keyId = keyId++;
datapoint.name = "real-unsigned";
// initial value
Assert.assertEquals(0, datapoint.getValue().unsignedValue());
// set with new value
status = datapoint.setBooleanValue(true);
Assert.assertEquals(-1, status);
Assert.assertEquals(0, datapoint.getValue().unsignedValue());
// real-double datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeDouble);
datapoint.keyId = keyId++;
datapoint.name = "real-double";
// initial value
Assert.assertEquals(0.0, datapoint.getValue().dblValue());
// set with new value
status = datapoint.setBooleanValue(true);
Assert.assertEquals(-1, status);
Assert.assertEquals(0.0, datapoint.getValue().dblValue());
// real-string datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeString);
datapoint.keyId = keyId++;
datapoint.name = "real-string";
// initial value
Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
// set with new value
status = datapoint.setBooleanValue(true);
Assert.assertEquals(-1, status);
Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
}
/**
* Test method for
* {@link tcg.scada.da.DataPoint#setDoubleSourceValue(double, boolean)}.
*/
public void testSetDoubleSourceValue()
{
int keyId = 1;
DataPointImpl datapoint = null;
int status = 0;
long updateTs = Calendar.getInstance().getTimeInMillis();
// TODO: check for datastore notification!
// real-boolean datapoint
datapoint = new DataPointImpl(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
status = datapoint.setDoubleSourceValue(15.1, false);
Assert.assertEquals(-1, status);
// real-number datapoint
datapoint = new DataPointImpl(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
status = datapoint.setDoubleSourceValue(15.1, false);
Assert.assertEquals(-1, status);
// real-unsigned datapoint
datapoint = new DataPointImpl(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
status = datapoint.setDoubleSourceValue(15.1, false);
Assert.assertEquals(-1, status);
// real-double datapoint
datapoint = new DataPointImpl(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());
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set without timestamp
status = datapoint.setDoubleSourceValue(11.5, 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);
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set with timestamp
status = datapoint.setDoubleSourceValue(15.7, 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
// real-string datapoint
datapoint = new DataPointImpl(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
status = datapoint.setDoubleSourceValue(15.1, false);
Assert.assertEquals(-1, status);
}
/**
* Test method for {@link tcg.scada.da.DataPoint#setDoubleValue(double)}.
*/
public void testSetDoubleValue()
{
int keyId = 1;
DataPointImpl datapoint = null;
int status = 0;
// TODO: check for datastore notification!
// REAL datapoint
// real-boolean datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeBoolean);
datapoint.keyId = keyId++;
datapoint.name = "real-boolean";
// initial value
Assert.assertEquals(false, datapoint.getValue().boolValue());
// set with new value
status = datapoint.setDoubleValue(11.5);
Assert.assertEquals(-1, status);
Assert.assertEquals(false, datapoint.getValue().boolValue());
// real-number datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeNumber);
datapoint.keyId = keyId++;
datapoint.name = "real-number";
// initial value
Assert.assertEquals(0, datapoint.getValue().longValue());
// set with new value
status = datapoint.setDoubleValue(11.5);
Assert.assertEquals(-1, status);
Assert.assertEquals(0, datapoint.getValue().longValue());
// real-unsigned datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeUnsigned);
datapoint.keyId = keyId++;
datapoint.name = "real-unsigned";
// initial value
Assert.assertEquals(0, datapoint.getValue().unsignedValue());
// set with new value
status = datapoint.setDoubleValue(11.5);
Assert.assertEquals(-1, status);
Assert.assertEquals(0, datapoint.getValue().unsignedValue());
// real-double datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeDouble);
datapoint.keyId = keyId++;
datapoint.name = "real-double";
// initial value
Assert.assertEquals(0.0, datapoint.getValue().dblValue());
// set with new value
status = datapoint.setDoubleValue(11.5);
Assert.assertEquals(-1, status);
Assert.assertEquals(0.0, datapoint.getValue().dblValue());
// real-string datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeString);
datapoint.keyId = keyId++;
datapoint.name = "real-string";
// initial value
Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
// set with new value
status = datapoint.setDoubleValue(11.5);
Assert.assertEquals(-1, status);
Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
}
/**
* Test method for scan inhibit.
*
* <p>
* Validated functions:
* <ul>
* <li>{@link tcg.scada.da.DataPoint#setInhibit()}</li>
* <li>{@link tcg.scada.da.DataPoint#removeInhibit()}</li>
* <li>{@link tcg.scada.da.DataPoint#setSourceValue(CosDpValueStruct)}</li>
* <li>
* {@link tcg.scada.da.DataPoint#setSourceValue(CosDpValueUnion, boolean)}</li>
* <li>
* {@link tcg.scada.da.DataPoint#setBooleanSourceValue(boolean, boolean)}</li>
* <li>{@link tcg.scada.da.DataPoint#setNumberSourceValue(int, boolean)}</li>
* <li>{@link tcg.scada.da.DataPoint#setUnsignedSourceValue(int, boolean)}</li>
* <li>{@link tcg.scada.da.DataPoint#setDoubleSourceValue(double, boolean)}</li>
* <li>{@link tcg.scada.da.DataPoint#setStringSourceValue(string, boolean)}</li>
* <li>
* {@link tcg.scada.da.DataPoint#setStringSourceQuality(string, boolean)}</li>
* </ul>
* </p>
*/
public void testInhibit()
{
int keyId = 1;
DataPointImpl datapoint = null;
boolean boolStatus = false;
int intStatus = 0;
long updateTs = Calendar.getInstance().getTimeInMillis();
long sourceTs = updateTs;
long outputTs = updateTs;
CosDpValueUnion value = new CosDpValueUnion();
// TODO: check for datastore notification!
// REAL datapoint
// real-boolean datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeBoolean);
datapoint.keyId = keyId++;
datapoint.name = "real-boolean";
// initial value
Assert.assertEquals(false, datapoint.isInhibit());
Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getSourceQuality());
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertEquals(0, datapoint.getTimestamp());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getQuality());
Assert.assertEquals(0, datapoint.getUpdateTimestamp());
// set the quality to good for easier testing
intStatus = datapoint.setSourceQuality(CosDpQualityEnum.QualityGood, false);
Assert.assertEquals(1, intStatus);
Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint.getSourceQuality());
Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint.getQuality());
sourceTs = datapoint.getSourceTimestamp();
outputTs = datapoint.getTimestamp();
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set the inhibit flag
boolStatus = datapoint.setInhibit();
Assert.assertEquals(true, boolStatus);
// inhibit flag is set
Assert.assertEquals(true, datapoint.isInhibit());
// no update on source value/quality/timestamp
Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
Assert.assertTrue(datapoint.getSourceTimestamp() == sourceTs);
Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint
.getSourceQuality());
// output quality is set to QualityInhibit
// output timestamp is set to current time
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertTrue(datapoint.getTimestamp() > updateTs);
Assert.assertEquals(CosDpQualityEnum.QualityInhibit, 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 with new value with timestamp update
intStatus = datapoint.setBooleanSourceValue(true, true);
Assert.assertEquals(1, intStatus);
// source value is updated, source timestamp is updated to current time
Assert.assertEquals(true, datapoint.getSourceValue().boolValue());
Assert.assertTrue(datapoint.getSourceTimestamp() > sourceTs);
Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint
.getSourceQuality());
// no update on output value/quality/timestamp
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertTrue(datapoint.getTimestamp() == outputTs);
Assert.assertEquals(CosDpQualityEnum.QualityInhibit, datapoint
.getQuality());
// update timestamp is updated to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
// TODO: check for datapoint notification
sourceTs = datapoint.getSourceTimestamp();
outputTs = datapoint.getTimestamp();
updateTs = datapoint.getUpdateTimestamp();
sleep(1);
// re-inhibit (succeed but datapoint is not updated)
boolStatus = datapoint.setInhibit();
Assert.assertEquals(true, boolStatus);
// no update on source value/quality/timestamp
Assert.assertEquals(true, datapoint.getSourceValue().boolValue());
Assert.assertEquals(sourceTs, datapoint.getSourceTimestamp());
Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint
.getSourceQuality());
// no update on output value/quality/timestamp
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertEquals(outputTs, datapoint.getTimestamp());
Assert.assertEquals(CosDpQualityEnum.QualityInhibit, datapoint
.getQuality());
// update timestamp is not updated
Assert.assertEquals(updateTs, datapoint.getUpdateTimestamp());
// 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 = datapoint.setSourceQuality(CosDpQualityEnum.QualityBad,
true);
Assert.assertEquals(1, intStatus);
// source quality is updated, source timestamp is updated to current
// time
Assert.assertEquals(true, datapoint.getSourceValue().boolValue());
Assert.assertTrue(datapoint.getSourceTimestamp() > sourceTs);
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getSourceQuality());
// no update on output value/quality/timestamp
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertTrue(datapoint.getTimestamp() == outputTs);
Assert.assertEquals(CosDpQualityEnum.QualityInhibit, datapoint
.getQuality());
// update timestamp is updated to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
// TODO: check for datapoint notification
sourceTs = datapoint.getSourceTimestamp();
outputTs = datapoint.getTimestamp();
updateTs = datapoint.getUpdateTimestamp();
sleep(1);
// set override (mutually exclusive)
value.boolValue(true);
boolStatus = datapoint.setOverride(value);
Assert.assertEquals(false, boolStatus);
Assert.assertEquals(true, datapoint.isInhibit());
Assert.assertEquals(false, datapoint.isOverride());
// inhibit and override state is mutually exclusive
Assert.assertEquals(true, datapoint.isInhibit());
Assert.assertEquals(false, datapoint.isOverride());
// source value/quality/timestamp is not updated
Assert.assertEquals(true, datapoint.getSourceValue().boolValue());
Assert.assertTrue(datapoint.getSourceTimestamp() == updateTs);
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getSourceQuality());
// no update on output value/quality/timestamp
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertTrue(datapoint.getTimestamp() == outputTs);
Assert.assertEquals(CosDpQualityEnum.QualityInhibit, datapoint
.getQuality());
// update-timestamp is not updated
Assert.assertTrue(datapoint.getUpdateTimestamp() == updateTs);
/*
// pre-test
sourceTs = datapoint.getSourceTimestamp();
outputTs = datapoint.getTimestamp();
updateTs = datapoint.getUpdateTimestamp();
datastore.resetEvent();
// set new source timestamp
intStatus = datapoint.setSourceTimestamp(123456);
CPPUNIT_ASSERT_EQUAL(1, intStatus);
// source timestamp is updated
CPPUNIT_ASSERT_EQUAL(true, datapoint.getSourceValue().boolValue());
CPPUNIT_ASSERT_EQUAL(123456, datapoint.getSourceTimestamp());
CPPUNIT_ASSERT_EQUAL(QualityBad, datapoint.getSourceQuality());
// no update on output value/quality/timestamp
CPPUNIT_ASSERT_EQUAL(false, datapoint.getValue().boolValue());
CPPUNIT_ASSERT(datapoint.getTimestamp() == outputTs);
CPPUNIT_ASSERT_EQUAL(QualityInhibit, datapoint.getQuality());
// update-timestamp is not updated
CPPUNIT_ASSERT(datapoint.getUpdateTimestamp() == updateTs);
// check datastore notification
CPPUNIT_ASSERT_EQUAL((int)EVT_SOURCE_TIMESTAMP_CHANGE, datastore.getDataPointEvent());
*/
sourceTs = datapoint.getSourceTimestamp();
outputTs = Calendar.getInstance().getTimeInMillis();
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// remove inhibit
boolStatus = datapoint.removeInhibit();
Assert.assertEquals(true, boolStatus);
// inhibit flag is removed
Assert.assertEquals(false, datapoint.isInhibit());
// source value/quality/timestamp is not updated
Assert.assertEquals(true, datapoint.getSourceValue().boolValue());
Assert.assertTrue(datapoint.getSourceTimestamp() == sourceTs);
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getSourceQuality());
// output value/quality/timestamp is synchronized with source
// value/quality/timestamp
Assert.assertTrue(datapoint.getSourceValue().boolValue() == datapoint
.getValue().boolValue());
Assert.assertTrue(datapoint.getSourceTimestamp() == datapoint
.getTimestamp());
Assert.assertTrue(datapoint.getSourceQuality() == datapoint
.getQuality());
// update-timestamp is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
// TODO: check for datapoint notification
}
/**
* Test method for
* {@link tcg.scada.da.DataPoint#setNumberSourceValue(int, boolean)}.
*/
public void testSetNumberSourceValue()
{
int keyId = 1;
DataPointImpl datapoint = null;
int status = 0;
long updateTs = Calendar.getInstance().getTimeInMillis();
// TODO: check for datastore notification!
// real-boolean datapoint
datapoint = new DataPointImpl(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
status = datapoint.setNumberSourceValue(10, false);
Assert.assertEquals(-1, status);
// real-number datapoint
datapoint = new DataPointImpl(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());
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set without timestamp
status = datapoint.setNumberSourceValue(11, 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);
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set with timestamp
status = datapoint.setNumberSourceValue(15, 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
// real-unsigned datapoint
datapoint = new DataPointImpl(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
status = datapoint.setNumberSourceValue(15, false);
Assert.assertEquals(-1, status);
// real-double datapoint
datapoint = new DataPointImpl(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
status = datapoint.setNumberSourceValue(-11, false);
Assert.assertEquals(-1, status);
// real-string datapoint
datapoint = new DataPointImpl(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
status = datapoint.setNumberSourceValue(15, false);
Assert.assertEquals(-1, status);
}
/**
* Test method for {@link tcg.scada.da.DataPoint#setNumberValue(int)}.
*/
public void testSetNumberValue()
{
int keyId = 1;
DataPointImpl datapoint = null;
int status = 0;
// TODO: check for datastore notification!
// REAL datapoint
// real-boolean datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeBoolean);
datapoint.keyId = keyId++;
datapoint.name = "real-boolean";
// initial value
Assert.assertEquals(false, datapoint.getValue().boolValue());
// set with new value
status = datapoint.setNumberValue(11);
Assert.assertEquals(-1, status);
Assert.assertEquals(false, datapoint.getValue().boolValue());
// real-number datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeNumber);
datapoint.keyId = keyId++;
datapoint.name = "real-number";
// initial value
Assert.assertEquals(0, datapoint.getValue().longValue());
// set with new value
status = datapoint.setNumberValue(11);
Assert.assertEquals(-1, status);
Assert.assertEquals(0, datapoint.getValue().longValue());
// real-unsigned datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeUnsigned);
datapoint.keyId = keyId++;
datapoint.name = "real-unsigned";
// initial value
Assert.assertEquals(0, datapoint.getValue().unsignedValue());
// set with new value
status = datapoint.setNumberValue(11);
Assert.assertEquals(-1, status);
Assert.assertEquals(0, datapoint.getValue().unsignedValue());
// real-double datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeDouble);
datapoint.keyId = keyId++;
datapoint.name = "real-double";
// initial value
Assert.assertEquals(0.0, datapoint.getValue().dblValue());
// set with new value
status = datapoint.setNumberValue(11);
Assert.assertEquals(-1, status);
Assert.assertEquals(0.0, datapoint.getValue().dblValue());
// real-string datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeString);
datapoint.keyId = keyId++;
datapoint.name = "real-string";
// initial value
Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
// set with new value
status = datapoint.setNumberValue(11);
Assert.assertEquals(-1, status);
Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
}
/**
* Test method for datapoint override.
*
* <p>
* Validated functions:
* <ul>
* <li>{@link tcg.scada.da.DataPoint#setOverride(CosDpValueUnion)}</li>
* <li>{@link tcg.scada.da.DataPoint#removeOverride()}</li>
* <li>{@link tcg.scada.da.DataPoint#setSourceValue(CosDpValueStruct)}</li>
* <li>
* {@link tcg.scada.da.DataPoint#setSourceValue(CosDpValueUnion, boolean)}</li>
* <li>
* {@link tcg.scada.da.DataPoint#setBooleanSourceValue(boolean, boolean)}</li>
* <li>{@link tcg.scada.da.DataPoint#setNumberSourceValue(int, boolean)}</li>
* <li>{@link tcg.scada.da.DataPoint#setUnsignedSourceValue(int, boolean)}</li>
* <li>{@link tcg.scada.da.DataPoint#setDoubleSourceValue(double, boolean)}</li>
* <li>{@link tcg.scada.da.DataPoint#setStringSourceValue(string, boolean)}</li>
* <li>
* {@link tcg.scada.da.DataPoint#setStringSourceQuality(string, boolean)}</li>
* </ul>
* </p>
*/
public void testOverride()
{
int keyId = 1;
DataPointImpl datapoint = null;
boolean boolStatus = false;
int intStatus = 0;
long updateTs = Calendar.getInstance().getTimeInMillis();
long outputTs = updateTs;
long sourceTs = updateTs;
CosDpValueUnion value = new CosDpValueUnion();
// TODO: check for datastore notification!
// real-boolean datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeNumber);
datapoint.keyId = keyId++;
datapoint.name = "real-number";
// 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());
Assert.assertEquals(0, datapoint.getUpdateTimestamp());
// set the quality to good for easier testing
intStatus = datapoint.setSourceQuality(CosDpQualityEnum.QualityGood, false);
Assert.assertEquals(1, intStatus);
Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint.getSourceQuality());
Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint.getQuality());
sourceTs = Calendar.getInstance().getTimeInMillis();
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(0, datapoint.getSourceValue().longValue());
Assert.assertEquals(0, 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 with timestamp update
intStatus = datapoint.setNumberSourceValue(-20, true);
Assert.assertEquals(1, intStatus);
// source value is updated, source timestamp is updated to current time
Assert.assertEquals(-20, 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(-20, 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 = datapoint.getSourceTimestamp();
updateTs = datapoint.getUpdateTimestamp();
outputTs = datapoint.getTimestamp();
sleep(1);
// set inhibit (mutually exclusive)
boolStatus = datapoint.setInhibit();
Assert.assertEquals(false, boolStatus);
Assert.assertEquals(false, datapoint.isInhibit());
Assert.assertEquals(true, datapoint.isOverride());
// no update on source value/quality/timestamp
Assert.assertEquals(-20, datapoint.getSourceValue().longValue());
Assert.assertTrue(datapoint.getSourceTimestamp() == sourceTs);
Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint
.getSourceQuality());
// no update on output value/quality/timestamp
Assert.assertEquals(110, datapoint.getValue().longValue());
Assert.assertTrue(datapoint.getTimestamp() == outputTs);
Assert.assertEquals(CosDpQualityEnum.QualityOverride, datapoint
.getQuality());
// update-timestamp is not updated
Assert.assertTrue(datapoint.getUpdateTimestamp() == updateTs);
// TODO: check for datapoint notification
sourceTs = Calendar.getInstance().getTimeInMillis();
updateTs = Calendar.getInstance().getTimeInMillis();
outputTs = datapoint.getTimestamp();
sleep(1);
// set new quality with timestamp update
intStatus = datapoint.setSourceQuality(CosDpQualityEnum.QualityBad,
true);
Assert.assertEquals(1, intStatus);
// source quality is updated, source timestamp is updated to current
// time
Assert.assertEquals(-20, datapoint.getSourceValue().longValue());
Assert.assertTrue(datapoint.getSourceTimestamp() > sourceTs);
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getSourceQuality());
// no update on output value/quality/timestamp
Assert.assertEquals(110, 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 = datapoint.getTimestamp();
sleep(1);
// remove override
boolStatus = datapoint.removeOverride();
Assert.assertEquals(true, boolStatus);
// override flag is removed
Assert.assertEquals(false, datapoint.isOverride());
// source value/quality/timestamp is not updated
Assert.assertEquals(-20, datapoint.getSourceValue().longValue());
Assert.assertTrue(datapoint.getSourceTimestamp() == sourceTs);
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getSourceQuality());
// output value/quality/timestamp is synchronized with source
// value/quality/timestamp
Assert.assertTrue(datapoint.getSourceValue().longValue() == datapoint
.getValue().longValue());
Assert.assertTrue(datapoint.getSourceTimestamp() == datapoint
.getTimestamp());
Assert.assertTrue(datapoint.getSourceQuality() == datapoint
.getQuality());
// update-timestamp is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
// TODO: check for datapoint notification
}
/**
* Test method for
* {@link tcg.scada.da.DataPoint#setSourceQuality(tcg.scada.cos.CosDpQualityEnum, boolean)}
* .
*/
public void testSetSourceQuality()
{
int keyId = 1;
DataPointImpl datapoint = null;
int status = 0;
long updateTs = Calendar.getInstance().getTimeInMillis();
// TODO: check for datastore notification!
// real-number datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeNumber);
datapoint.keyId = keyId++;
datapoint.name = "real-number";
// initial value
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getQuality());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getQuality());
Assert.assertEquals(0, datapoint.getTimestamp());
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set without timestamp
status = datapoint.setSourceQuality(CosDpQualityEnum.QualityGood, false);
Assert.assertEquals(1, status);
// source value is updated, source timestamp is not updated
Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint
.getSourceQuality());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
// output value/timestamp is synchronized with source value/timestamp
Assert.assertEquals(CosDpQualityEnum.QualityGood, datapoint
.getQuality());
Assert.assertEquals(0, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set with timestamp
status = datapoint.setSourceQuality(CosDpQualityEnum.QualityBad, true);
Assert.assertEquals(1, status);
// source value is updated, source timestamp is set to current time
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getSourceQuality());
Assert.assertTrue(datapoint.getSourceTimestamp() > updateTs);
// output value/timestamp is synchronized with source value/timestamp
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getQuality());
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint
.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
// TODO: check for the same value
}
/**
* Test method for {@link tcg.scada.da.DataPoint#setSourceTimestamp(long)}.
*/
public void testSetSourceTimestamp()
{
int keyId = 1;
DataPointImpl datapoint = null;
int status = 0;
long updateTs = Calendar.getInstance().getTimeInMillis();
// TODO: check for datastore notification!
// real-number datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeNumber);
datapoint.keyId = keyId++;
datapoint.name = "real-number";
// initial value
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(0, datapoint.getTimestamp());
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set new timestamp
status = datapoint.setSourceTimestamp(123456);
Assert.assertEquals(1, status);
// source timestamp is updated
Assert.assertEquals(123456, datapoint.getSourceTimestamp());
// output timestamp is synchronized with source timestamp
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint
.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
updateTs = datapoint.getUpdateTimestamp();
sleep(1);
// set the same timestamp
status = datapoint.setSourceTimestamp(123456);
Assert.assertEquals(0, status);
// source timestamp is not updated
Assert.assertEquals(123456, datapoint.getSourceTimestamp());
// output timestamp is not updated
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint
.getTimestamp());
// update-time is not updated
Assert.assertTrue(datapoint.getUpdateTimestamp() == updateTs);
}
/**
* Test method for
* {@link tcg.scada.da.DataPoint#setSourceValue(tcg.scada.cos.CosDpValueUnion, boolean)}
* .
*/
public void testSetSourceValue()
{
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(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(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());
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set without timestamp
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);
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set with timestamp
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(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());
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set without timestamp
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);
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set with timestamp
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
// real-unsigned datapoint
datapoint = new DataPointImpl(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());
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set without timestamp
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);
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set with timestamp
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
// real-double datapoint
datapoint = new DataPointImpl(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());
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set without timestamp
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);
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set with timestamp
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
// real-string datapoint
datapoint = new DataPointImpl(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());
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set without timestamp
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);
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set with timestamp
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("TestTest") == 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
}
/**
* Test method for
* {@link tcg.scada.da.DataPoint#setSourceValue(tcg.scada.cos.CosDpValueStruct)}
* .
*/
public void testSetSourceValueCosDpValueStruct()
{
int keyId = 1;
CosDpValueStruct value = new CosDpValueStruct();
value.value = new CosDpValueUnion();
value.quality = CosDpQualityEnum.QualityGood;
DataPointImpl datapoint = null;
int status = 0;
long updateTs = Calendar.getInstance().getTimeInMillis();
// TODO: check for datastore notification!
// set with null value
datapoint = new DataPointImpl(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(CosDpValueTypeEnum.TypeBoolean);
datapoint.keyId = keyId++;
datapoint.name = "real-boolean";
// initial value
Assert.assertEquals(false, datapoint.getSourceValue().boolValue());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getSourceQuality());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(false, datapoint.getValue().boolValue());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getQuality());
Assert.assertEquals(0, datapoint.getTimestamp());
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set new value/new quality/new timestamp
value.value.boolValue(true);
value.quality = CosDpQualityEnum.QualityGood;
value.timestamp = 123456;
status = datapoint.setSourceValue(value);
Assert.assertEquals(1, status);
// source value/source quality/source timestamp is updated
Assert.assertEquals(value.quality, datapoint.getSourceQuality());
Assert.assertEquals(value.value.boolValue(), datapoint.getSourceValue()
.boolValue());
Assert.assertEquals(value.timestamp, datapoint.getSourceTimestamp());
// output value/timestamp is synchronized with source value/timestamp
Assert.assertEquals(value.quality, datapoint.getQuality());
Assert.assertEquals(value.value.boolValue(), datapoint.getValue()
.boolValue());
Assert.assertEquals(value.timestamp, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set new value
value.value.boolValue(false);
value.quality = CosDpQualityEnum.QualityGood;
value.timestamp = 123456;
status = datapoint.setSourceValue(value);
Assert.assertEquals(1, status);
// source value/source quality/source timestamp is updated
Assert.assertEquals(value.quality, datapoint.getSourceQuality());
Assert.assertEquals(value.value.boolValue(), datapoint.getSourceValue()
.boolValue());
Assert.assertEquals(value.timestamp, datapoint.getSourceTimestamp());
// output value/timestamp is synchronized with source value/timestamp
Assert.assertEquals(value.quality, datapoint.getQuality());
Assert.assertEquals(value.value.boolValue(), datapoint.getValue()
.boolValue());
Assert.assertEquals(value.timestamp, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
// real-number datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeNumber);
datapoint.keyId = keyId++;
datapoint.name = "real-number";
// initial value
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());
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set new value/new quality/new timestamp
value.value.longValue(15);
value.quality = CosDpQualityEnum.QualityGood;
value.timestamp = 123456;
status = datapoint.setSourceValue(value);
Assert.assertEquals(1, status);
// source value/source quality/source timestamp is updated
Assert.assertEquals(value.quality, datapoint.getSourceQuality());
Assert.assertEquals(value.value.longValue(), datapoint.getSourceValue()
.longValue());
Assert.assertEquals(value.timestamp, datapoint.getSourceTimestamp());
// output value/timestamp is synchronized with source value/timestamp
Assert.assertEquals(value.quality, datapoint.getQuality());
Assert.assertEquals(value.value.longValue(), datapoint.getValue()
.longValue());
Assert.assertEquals(value.timestamp, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set new value
value.value.longValue(-23);
value.quality = CosDpQualityEnum.QualityGood;
value.timestamp = 123456;
status = datapoint.setSourceValue(value);
Assert.assertEquals(1, status);
// source value/source quality/source timestamp is updated
Assert.assertEquals(value.quality, datapoint.getSourceQuality());
Assert.assertEquals(value.value.longValue(), datapoint.getSourceValue()
.longValue());
Assert.assertEquals(value.timestamp, datapoint.getSourceTimestamp());
// output value/timestamp is synchronized with source value/timestamp
Assert.assertEquals(value.quality, datapoint.getQuality());
Assert.assertEquals(value.value.longValue(), datapoint.getValue()
.longValue());
Assert.assertEquals(value.timestamp, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
// TODO: check for the same value
// real-unsigned datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeUnsigned);
datapoint.keyId = keyId++;
datapoint.name = "real-unsigned";
// initial value
Assert.assertEquals(0, datapoint.getSourceValue().unsignedValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getSourceQuality());
Assert.assertEquals(0, datapoint.getValue().unsignedValue());
Assert.assertEquals(0, datapoint.getTimestamp());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getQuality());
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set new value/new quality/new timestamp
value.value.unsignedValue(15);
value.quality = CosDpQualityEnum.QualityGood;
value.timestamp = 123456;
status = datapoint.setSourceValue(value);
Assert.assertEquals(1, status);
// source value/source quality/source timestamp is updated
Assert.assertEquals(value.quality, datapoint.getSourceQuality());
Assert.assertEquals(value.value.unsignedValue(), datapoint
.getSourceValue().unsignedValue());
Assert.assertEquals(value.timestamp, datapoint.getSourceTimestamp());
// output value/timestamp is synchronized with source value/timestamp
Assert.assertEquals(value.quality, datapoint.getQuality());
Assert.assertEquals(value.value.unsignedValue(), datapoint.getValue()
.unsignedValue());
Assert.assertEquals(value.timestamp, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set new value
value.value.unsignedValue(123);
value.quality = CosDpQualityEnum.QualityGood;
value.timestamp = 123456;
status = datapoint.setSourceValue(value);
Assert.assertEquals(1, status);
// source value/source quality/source timestamp is updated
Assert.assertEquals(value.quality, datapoint.getSourceQuality());
Assert.assertEquals(value.value.unsignedValue(), datapoint
.getSourceValue().unsignedValue());
Assert.assertEquals(value.timestamp, datapoint.getSourceTimestamp());
// output value/timestamp is synchronized with source value/timestamp
Assert.assertEquals(value.quality, datapoint.getQuality());
Assert.assertEquals(value.value.unsignedValue(), datapoint.getValue()
.unsignedValue());
Assert.assertEquals(value.timestamp, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
// TODO: check for the same value
// real-double datapoint
datapoint = new DataPointImpl(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(CosDpQualityEnum.QualityBad, datapoint
.getSourceQuality());
Assert.assertEquals(0.0, datapoint.getValue().dblValue());
Assert.assertEquals(0, datapoint.getTimestamp());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getQuality());
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set new value/new quality/new timestamp
value.value.dblValue(15.2);
value.quality = CosDpQualityEnum.QualityGood;
value.timestamp = 123456;
status = datapoint.setSourceValue(value);
Assert.assertEquals(1, status);
// source value/source quality/source timestamp is updated
Assert.assertEquals(value.quality, datapoint.getSourceQuality());
Assert.assertEquals(value.value.dblValue(), datapoint.getSourceValue()
.dblValue());
Assert.assertEquals(value.timestamp, datapoint.getSourceTimestamp());
// output value/timestamp is synchronized with source value/timestamp
Assert.assertEquals(value.quality, datapoint.getQuality());
Assert.assertEquals(value.value.dblValue(), datapoint.getValue()
.dblValue());
Assert.assertEquals(value.timestamp, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set new value
value.value.dblValue(123.5);
value.quality = CosDpQualityEnum.QualityGood;
value.timestamp = 123456;
status = datapoint.setSourceValue(value);
Assert.assertEquals(1, status);
// source value/source quality/source timestamp is updated
Assert.assertEquals(value.quality, datapoint.getSourceQuality());
Assert.assertEquals(value.value.dblValue(), datapoint.getSourceValue()
.dblValue());
Assert.assertEquals(value.timestamp, datapoint.getSourceTimestamp());
// output value/timestamp is synchronized with source value/timestamp
Assert.assertEquals(value.quality, datapoint.getQuality());
Assert.assertEquals(value.value.dblValue(), datapoint.getValue()
.dblValue());
Assert.assertEquals(value.timestamp, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
// TODO: check for the same value
// real-string datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeString);
datapoint.keyId = keyId++;
datapoint.name = "real-string";
// initial value
Assert.assertTrue(datapoint.getSourceValue().charValue()
.compareTo("") == 0);
Assert.assertEquals(0, datapoint.getSourceTimestamp());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getSourceQuality());
Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
Assert.assertEquals(0, datapoint.getTimestamp());
Assert.assertEquals(CosDpQualityEnum.QualityBad, datapoint
.getQuality());
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set new value/new quality/new timestamp
value.value.charValue("some-string");
value.quality = CosDpQualityEnum.QualityGood;
value.timestamp = 123456;
status = datapoint.setSourceValue(value);
Assert.assertEquals(1, status);
// source value/source quality/source timestamp is updated
Assert.assertEquals(value.quality, datapoint.getSourceQuality());
Assert.assertTrue(datapoint.getSourceValue().charValue().compareTo(
value.value.charValue()) == 0);
Assert.assertEquals(value.timestamp, datapoint.getSourceTimestamp());
// output value/timestamp is synchronized with source value/timestamp
Assert.assertEquals(value.quality, datapoint.getQuality());
Assert.assertTrue(datapoint.getValue().charValue().compareTo(
value.value.charValue()) == 0);
Assert.assertEquals(value.timestamp, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set new value
value.value.charValue("another-string");
value.quality = CosDpQualityEnum.QualityGood;
value.timestamp = 123456;
status = datapoint.setSourceValue(value);
Assert.assertEquals(1, status);
// source value/source quality/source timestamp is updated
Assert.assertEquals(value.quality, datapoint.getSourceQuality());
Assert.assertTrue(datapoint.getSourceValue().charValue().compareTo(
value.value.charValue()) == 0);
Assert.assertEquals(value.timestamp, datapoint.getSourceTimestamp());
// output value/timestamp is synchronized with source value/timestamp
Assert.assertEquals(value.quality, datapoint.getQuality());
Assert.assertTrue(datapoint.getValue().charValue().compareTo(
value.value.charValue()) == 0);
Assert.assertEquals(value.timestamp, datapoint.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
// TODO: check for the same value
}
/**
* Test method for
* {@link tcg.scada.da.DataPoint#setStringSourceValue(java.lang.String, boolean)}
* .
*/
public void testSetStringSourceValue()
{
int keyId = 1;
DataPointImpl datapoint = null;
int status = 0;
long updateTs = Calendar.getInstance().getTimeInMillis();
// TODO: check for datastore notification!
// real-boolean datapoint
datapoint = new DataPointImpl(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
status = datapoint.setStringSourceValue("some-string", false);
Assert.assertEquals(-1, status);
// real-number datapoint
datapoint = new DataPointImpl(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
status = datapoint.setStringSourceValue("some-string", false);
Assert.assertEquals(-1, status);
// real-unsigned datapoint
datapoint = new DataPointImpl(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
status = datapoint.setStringSourceValue("some-string", false);
Assert.assertEquals(-1, status);
// real-double datapoint
datapoint = new DataPointImpl(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
status = datapoint.setStringSourceValue("some-string", false);
Assert.assertEquals(-1, status);
// real-string datapoint
datapoint = new DataPointImpl(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());
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set without timestamp
status = datapoint.setStringSourceValue("Test", 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);
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set with timestamp
status = datapoint.setStringSourceValue("TestTest", true);
Assert.assertEquals(1, status);
Assert.assertTrue(datapoint.getSourceValue().charValue().compareTo(
"TestTest") == 0);
Assert.assertTrue(datapoint.getSourceTimestamp() > updateTs);
Assert.assertTrue(datapoint.getValue().charValue()
.compareTo("TestTest") == 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
}
/**
* Test method for
* {@link tcg.scada.da.DataPoint#setStringValue(java.lang.String)}.
*/
public void testSetStringValue()
{
int keyId = 1;
DataPointImpl datapoint = null;
int status = 0;
// TODO: check for datastore notification!
// REAL datapoint
// real-boolean datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeBoolean);
datapoint.keyId = keyId++;
datapoint.name = "real-boolean";
// initial value
Assert.assertEquals(false, datapoint.getValue().boolValue());
// set with new value
status = datapoint.setStringValue("Test");
Assert.assertEquals(-1, status);
Assert.assertEquals(false, datapoint.getValue().boolValue());
// real-number datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeNumber);
datapoint.keyId = keyId++;
datapoint.name = "real-number";
// initial value
Assert.assertEquals(0, datapoint.getValue().longValue());
// set with new value
status = datapoint.setStringValue("Test");
Assert.assertEquals(-1, status);
Assert.assertEquals(0, datapoint.getValue().longValue());
// real-unsigned datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeUnsigned);
datapoint.keyId = keyId++;
datapoint.name = "real-unsigned";
// initial value
Assert.assertEquals(0, datapoint.getValue().unsignedValue());
// set with new value
status = datapoint.setStringValue("Test");
Assert.assertEquals(-1, status);
Assert.assertEquals(0, datapoint.getValue().unsignedValue());
// real-double datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeDouble);
datapoint.keyId = keyId++;
datapoint.name = "real-double";
// initial value
Assert.assertEquals(0.0, datapoint.getValue().dblValue());
// set with new value
status = datapoint.setStringValue("Test");
Assert.assertEquals(-1, status);
Assert.assertEquals(0.0, datapoint.getValue().dblValue());
// real-string datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeString);
datapoint.keyId = keyId++;
datapoint.name = "real-string";
// initial value
Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
// set with new value
status = datapoint.setStringValue("Test");
Assert.assertEquals(-1, status);
Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
}
// /**
// * Test method for
// * {@link tcg.scada.da.DataPoint#setSubsystem(tcg.scada.da.ISubsystem)}.
// */
// public void testSetSubsystem() {
// fail("Not yet implemented"); // TODO
// }
/**
* Test method for
* {@link tcg.scada.da.DataPoint#setUnsignedSourceValue(int, boolean)}.
*/
public void testSetUnsignedSourceValue()
{
int keyId = 1;
DataPointImpl datapoint = null;
int status = 0;
long updateTs = Calendar.getInstance().getTimeInMillis();
// TODO: check for datastore notification!
// real-boolean datapoint
datapoint = new DataPointImpl(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
status = datapoint.setUnsignedSourceValue(11, false);
Assert.assertEquals(-1, status);
// real-number datapoint
datapoint = new DataPointImpl(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
status = datapoint.setUnsignedSourceValue(11, false);
Assert.assertEquals(-1, status);
// real-unsigned datapoint
datapoint = new DataPointImpl(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());
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set without timestamp
status = datapoint.setUnsignedSourceValue(11, 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);
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set with timestamp
status = datapoint.setUnsignedSourceValue(15, 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
// real-double datapoint
datapoint = new DataPointImpl(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
status = datapoint.setUnsignedSourceValue(11, false);
Assert.assertEquals(-1, status);
// real-string datapoint
datapoint = new DataPointImpl(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
status = datapoint.setUnsignedSourceValue(11, false);
Assert.assertEquals(-1, status);
}
/**
* Test method for {@link tcg.scada.da.DataPoint#setUnsignedValue(int)}.
*/
public void testSetUnsignedValue()
{
int keyId = 1;
DataPointImpl datapoint = null;
int status = 0;
// TODO: check for datastore notification!
// real-boolean datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeBoolean);
datapoint.keyId = keyId++;
datapoint.name = "real-boolean";
// initial value
Assert.assertEquals(false, datapoint.getValue().boolValue());
// set with new value
status = datapoint.setUnsignedValue(11);
Assert.assertEquals(-1, status);
Assert.assertEquals(false, datapoint.getValue().boolValue());
// real-number datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeNumber);
datapoint.keyId = keyId++;
datapoint.name = "real-number";
// initial value
Assert.assertEquals(0, datapoint.getValue().longValue());
// set with new value
status = datapoint.setUnsignedValue(11);
Assert.assertEquals(-1, status);
Assert.assertEquals(0, datapoint.getValue().longValue());
// real-unsigned datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeUnsigned);
datapoint.keyId = keyId++;
datapoint.name = "real-unsigned";
// initial value
Assert.assertEquals(0, datapoint.getValue().unsignedValue());
// set with new value
status = datapoint.setUnsignedValue(11);
Assert.assertEquals(-1, status);
Assert.assertEquals(0, datapoint.getValue().unsignedValue());
// real-double datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeDouble);
datapoint.keyId = keyId++;
datapoint.name = "real-double";
// initial value
Assert.assertEquals(0.0, datapoint.getValue().dblValue());
// set with new value
status = datapoint.setUnsignedValue(11);
Assert.assertEquals(-1, status);
Assert.assertEquals(0.0, datapoint.getValue().dblValue());
// real-string datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeString);
datapoint.keyId = keyId++;
datapoint.name = "real-string";
// initial value
Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
// set with new value
status = datapoint.setUnsignedValue(11);
Assert.assertEquals(-1, status);
Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
}
/**
* Test method for
* {@link tcg.scada.da.DataPoint#setValue(tcg.scada.cos.CosDpValueUnion)}.
*/
public void testSetValue()
{
int keyId = 1;
CosDpValueUnion value = new CosDpValueUnion();
DataPointImpl datapoint = null;
int status = 0;
// TODO: check for datastore notification!
// set with null value
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeBoolean);
datapoint.keyId = keyId++;
datapoint.name = "real-boolean";
Assert.assertEquals(false, datapoint.getValue().boolValue());
status = datapoint.setValue(null);
Assert.assertEquals(-1, status);
Assert.assertEquals(false, datapoint.getValue().boolValue());
// REAL datapoint
// real-boolean datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeBoolean);
datapoint.keyId = keyId++;
datapoint.name = "real-boolean";
// initial value
Assert.assertEquals(false, datapoint.getValue().boolValue());
// set with new value
value.boolValue(true);
status = datapoint.setValue(value);
Assert.assertEquals(-1, status);
Assert.assertEquals(false, datapoint.getValue().boolValue());
// real-number datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeNumber);
datapoint.keyId = keyId++;
datapoint.name = "real-number";
// initial value
Assert.assertEquals(0, datapoint.getValue().longValue());
// set with new value
value.longValue(10);
status = datapoint.setValue(value);
Assert.assertEquals(-1, status);
Assert.assertEquals(0, datapoint.getValue().longValue());
// real-unsigned datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeUnsigned);
datapoint.keyId = keyId++;
datapoint.name = "real-unsigned";
// initial value
Assert.assertEquals(0, datapoint.getValue().unsignedValue());
// set with new value
value.unsignedValue(10);
status = datapoint.setValue(value);
Assert.assertEquals(-1, status);
Assert.assertEquals(0, datapoint.getValue().unsignedValue());
// real-double datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeDouble);
datapoint.keyId = keyId++;
datapoint.name = "real-double";
// initial value
Assert.assertEquals(0.0, datapoint.getValue().dblValue());
// set with new value
value.dblValue(10);
status = datapoint.setValue(value);
Assert.assertEquals(-1, status);
Assert.assertEquals(0.0, datapoint.getValue().dblValue());
// real-string datapoint
datapoint = new DataPointImpl(CosDpValueTypeEnum.TypeString);
datapoint.keyId = keyId++;
datapoint.name = "real-string";
// initial value
Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
// set with new value
value.charValue("Test");
status = datapoint.setValue(value);
Assert.assertEquals(-1, status);
Assert.assertTrue(datapoint.getValue().charValue().compareTo("") == 0);
}
/**
* Test method for deadband check.
*
* <p>
* Validated functions:
* <ul>
* <li>{@link tcg.scada.da.DataPoint#setDeadBandValue(double)}</li>
* <li>{@link tcg.scada.da.DataPoint#setSourceValue(CosDpValueStruct)}</li>
* <li>
* {@link tcg.scada.da.DataPoint#setSourceValue(CosDpValueUnion, boolean)}</li>
* <li>{@link tcg.scada.da.DataPoint#setNumberSourceValue(int, boolean)}</li>
* <li>{@link tcg.scada.da.DataPoint#setUnsignedSourceValue(int, boolean)}</li>
* <li>{@link tcg.scada.da.DataPoint#setDoubleSourceValue(double, boolean)}</li>
* </ul>
* </p>
*/
public void testDeadBand()
{
int keyId = 1;
DataPointImpl datapoint = null;
int status = 0;
long updateTs = Calendar.getInstance().getTimeInMillis();
long sourceTs = Calendar.getInstance().getTimeInMillis();
long outputTs = Calendar.getInstance().getTimeInMillis();
// TODO: check for datastore notification!
// real-number datapoint
datapoint = new DataPointImpl(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 deadband value
double dblStatus = datapoint.setDeadBandValue(10.1);
Assert.assertEquals(10.0, round(dblStatus, 1));
sourceTs = datapoint.getSourceTimestamp();
updateTs = datapoint.getUpdateTimestamp();
outputTs = datapoint.getTimestamp();
sleep(1);
// set new value within deadband
status = datapoint.setNumberSourceValue(10, true);
Assert.assertEquals(0, status);
// source value is not updated, source timestamp is not updated
Assert.assertEquals(0, datapoint.getSourceValue().longValue());
Assert.assertEquals(sourceTs, datapoint.getSourceTimestamp());
// output value/timestamp is not updated
Assert.assertEquals(0, datapoint.getValue().longValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
// update-time is not updated
Assert.assertTrue(datapoint.getUpdateTimestamp() == updateTs);
sourceTs = Calendar.getInstance().getTimeInMillis();
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set new value outside deadband
status = datapoint.setNumberSourceValue(11, true);
Assert.assertEquals(1, status);
// source value is updated, source timestamp is set to current time
Assert.assertEquals(11, datapoint.getSourceValue().longValue());
Assert.assertTrue(datapoint.getSourceTimestamp() > sourceTs);
// output value/timestamp is synchronized
Assert.assertEquals(datapoint.getSourceValue().longValue(), datapoint
.getValue().longValue());
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint
.getSourceTimestamp());
// update-time is not updated
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
sourceTs = datapoint.getSourceTimestamp();
outputTs = datapoint.getTimestamp();
updateTs = datapoint.getUpdateTimestamp();
sleep(1);
// set new value within deadband
status = datapoint.setNumberSourceValue(1, true);
Assert.assertEquals(0, status);
// source value is not updated, source timestamp is not updated
Assert.assertEquals(11, datapoint.getSourceValue().longValue());
Assert.assertEquals(sourceTs, datapoint.getSourceTimestamp());
// output value/timestamp is not updated
Assert.assertEquals(11, datapoint.getValue().longValue());
Assert.assertEquals(outputTs, datapoint.getSourceTimestamp());
// update-time is not updated
Assert.assertTrue(datapoint.getUpdateTimestamp() == updateTs);
sourceTs = Calendar.getInstance().getTimeInMillis();
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set new value outside deadband
status = datapoint.setNumberSourceValue(0, true);
Assert.assertEquals(1, status);
// source value is updated, source timestamp is set to current time
Assert.assertEquals(0, datapoint.getSourceValue().longValue());
Assert.assertTrue(datapoint.getSourceTimestamp() > sourceTs);
// output value/timestamp is synchronized
Assert.assertEquals(datapoint.getSourceValue().longValue(), datapoint
.getValue().longValue());
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint
.getSourceTimestamp());
// update-time is not updated
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
// TODO: test setSourceValue(CosDpValueUnion)
// TODO: test setSourceValue(CosDpValueStruct)
// real-unsigned datapoint
datapoint = new DataPointImpl(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 deadband value
dblStatus = datapoint.setDeadBandValue(10.1);
Assert.assertEquals(10.0, round(dblStatus, 1));
sourceTs = datapoint.getSourceTimestamp();
updateTs = datapoint.getUpdateTimestamp();
outputTs = datapoint.getTimestamp();
sleep(1);
// set new value within deadband
status = datapoint.setUnsignedSourceValue(10, true);
Assert.assertEquals(0, status);
// source value is not updated, source timestamp is not updated
Assert.assertEquals(0, datapoint.getSourceValue().unsignedValue());
Assert.assertEquals(sourceTs, datapoint.getSourceTimestamp());
// output value/timestamp is not updated
Assert.assertEquals(0, datapoint.getValue().unsignedValue());
Assert.assertEquals(0, datapoint.getSourceTimestamp());
// update-time is not updated
Assert.assertTrue(datapoint.getUpdateTimestamp() == updateTs);
sourceTs = Calendar.getInstance().getTimeInMillis();
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set new value outside deadband
status = datapoint.setUnsignedSourceValue(11, true);
Assert.assertEquals(1, status);
// source value is updated, source timestamp is set to current time
Assert.assertEquals(11, datapoint.getSourceValue().unsignedValue());
Assert.assertTrue(datapoint.getSourceTimestamp() > sourceTs);
// output value/timestamp is synchronized
Assert.assertEquals(datapoint.getSourceValue().unsignedValue(),
datapoint.getValue().unsignedValue());
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint
.getSourceTimestamp());
// update-time is not updated
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
sourceTs = datapoint.getSourceTimestamp();
outputTs = datapoint.getTimestamp();
updateTs = datapoint.getUpdateTimestamp();
sleep(1);
// set new value within deadband
status = datapoint.setUnsignedSourceValue(1, true);
Assert.assertEquals(0, status);
// source value is not updated, source timestamp is not updated
Assert.assertEquals(11, datapoint.getSourceValue().unsignedValue());
Assert.assertEquals(sourceTs, datapoint.getSourceTimestamp());
// output value/timestamp is not updated
Assert.assertEquals(11, datapoint.getValue().unsignedValue());
Assert.assertEquals(outputTs, datapoint.getSourceTimestamp());
// update-time is not updated
Assert.assertTrue(datapoint.getUpdateTimestamp() == updateTs);
sourceTs = Calendar.getInstance().getTimeInMillis();
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set new value outside deadband
status = datapoint.setUnsignedSourceValue(0, true);
Assert.assertEquals(1, status);
// source value is updated, source timestamp is set to current time
Assert.assertEquals(0, datapoint.getSourceValue().unsignedValue());
Assert.assertTrue(datapoint.getSourceTimestamp() > sourceTs);
// output value/timestamp is synchronized
Assert.assertEquals(datapoint.getSourceValue().unsignedValue(),
datapoint.getValue().unsignedValue());
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint
.getSourceTimestamp());
// update-time is not updated
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
// TODO: test setSourceValue(CosDpValueUnion)
// TODO: test setSourceValue(CosDpValueStruct)
// real-double datapoint
datapoint = new DataPointImpl(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 deadband value
dblStatus = datapoint.setDeadBandValue(10.1);
Assert.assertEquals(10.1, round(dblStatus, 1));
sourceTs = datapoint.getSourceTimestamp();
updateTs = datapoint.getUpdateTimestamp();
outputTs = datapoint.getTimestamp();
sleep(1);
// set new value within deadband
status = datapoint.setDoubleSourceValue(10.1, true);
Assert.assertEquals(0, status);
// source value is not updated, source timestamp is not updated
Assert.assertEquals(0.0, datapoint.getSourceValue().dblValue());
Assert.assertEquals(sourceTs, datapoint.getSourceTimestamp());
// output value/timestamp is not updated
Assert.assertEquals(0.0, datapoint.getValue().dblValue());
Assert.assertEquals(outputTs, datapoint.getSourceTimestamp());
// update-time is not updated
Assert.assertTrue(datapoint.getUpdateTimestamp() == updateTs);
sourceTs = Calendar.getInstance().getTimeInMillis();
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set new value outside deadband
status = datapoint.setDoubleSourceValue(10.2, true);
Assert.assertEquals(1, status);
// source value is updated, source timestamp is set to current time
Assert.assertEquals(10.2, datapoint.getSourceValue().dblValue());
Assert.assertTrue(datapoint.getSourceTimestamp() > sourceTs);
// output value/timestamp is synchronized
Assert.assertEquals(datapoint.getSourceValue().dblValue(), datapoint
.getValue().dblValue());
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint
.getSourceTimestamp());
// update-time is not updated
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
sourceTs = datapoint.getSourceTimestamp();
outputTs = datapoint.getTimestamp();
updateTs = datapoint.getUpdateTimestamp();
sleep(1);
// set new value within deadband
status = datapoint.setDoubleSourceValue(0.1, true);
Assert.assertEquals(0, status);
// source value is not updated, source timestamp is not updated
Assert.assertEquals(10.2, datapoint.getSourceValue().dblValue());
Assert.assertEquals(sourceTs, datapoint.getSourceTimestamp());
// output value/timestamp is not updated
Assert.assertEquals(10.2, datapoint.getValue().dblValue());
Assert.assertEquals(outputTs, datapoint.getSourceTimestamp());
// update-time is not updated
Assert.assertTrue(datapoint.getUpdateTimestamp() == updateTs);
sourceTs = Calendar.getInstance().getTimeInMillis();
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set new value outside deadband
status = datapoint.setDoubleSourceValue(0.0, true);
Assert.assertEquals(1, status);
// source value is updated, source timestamp is set to current time
Assert.assertEquals(0.0, datapoint.getSourceValue().dblValue());
Assert.assertTrue(datapoint.getSourceTimestamp() > sourceTs);
// output value/timestamp is synchronized
Assert.assertEquals(datapoint.getSourceValue().dblValue(), datapoint
.getValue().dblValue());
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint
.getSourceTimestamp());
// update-time is not updated
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
// TODO: test setSourceValue(CosDpValueUnion)
// TODO: test setSourceValue(CosDpValueStruct)
}
/**
* Test method for engineering conversion.
*
* <p>
* Validated functions:
* <ul>
* <li>{@link tcg.scada.da.DataPoint#setEngineeringConversion(String)}</li>
* <li>{@link tcg.scada.da.DataPoint#setSourceValue(CosDpValueStruct)}</li>
* <li>
* {@link tcg.scada.da.DataPoint#setSourceValue(CosDpValueUnion, boolean)}</li>
* <li>{@link tcg.scada.da.DataPoint#setNumberSourceValue(int, boolean)}</li>
* <li>{@link tcg.scada.da.DataPoint#setUnsignedSourceValue(int, boolean)}</li>
* <li>{@link tcg.scada.da.DataPoint#setDoubleSourceValue(double, boolean)}</li>
* </ul>
* </p>
*/
public void testEngineeringConversion()
{
int keyId = 1;
DataPointImpl datapoint = null;
int status = 0;
long updateTs = Calendar.getInstance().getTimeInMillis();
// TODO: check for datastore notification!
// real-boolean datapoint
datapoint = new DataPointImpl(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 engineering conversion (not supported for boolean type at the
// moment)
boolean boolStatus = datapoint.setEngineeringConversion("true || x");
Assert.assertEquals(false, boolStatus);
// // set engineering conversion
// boolean boolStatus = datapoint.setEngineeringConversion("true || x");
// Assert.assertEquals(true, boolStatus);
//
// // set new value with timestamp
// updateTs = Calendar.getInstance().getTimeInMillis();
// status = datapoint.setBooleanSourceValue(false, true);
// Assert.assertEquals(1, status);
// // source value is updated, source timestamp is updated
// Assert.assertEquals(true, datapoint.getSourceValue().boolValue());
// Assert.assertTrue(datapoint.getSourceTimestamp() > updateTs);
// // output value/timestamp is synchronized with source value/timestamp
// Assert.assertEquals(true, datapoint.getValue().boolValue());
// Assert.assertEquals(datapoint.getSourceTimestamp(),
// datapoint.getTimestamp());
// // update-time is set to current time
// Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
// real-number datapoint
datapoint = new DataPointImpl(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 engineering conversion
boolStatus = datapoint.setEngineeringConversion("x - 5");
Assert.assertEquals(true, boolStatus);
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set new value with timestamp
status = datapoint.setNumberSourceValue(15, true);
Assert.assertEquals(1, status);
// source value is updated, source timestamp is set to current time
Assert.assertEquals(10, datapoint.getSourceValue().longValue());
Assert.assertTrue(datapoint.getSourceTimestamp() > updateTs);
// output value/timestamp is synchronized with source value/timestamp
Assert.assertEquals(10, datapoint.getValue().longValue());
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint
.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
// TODO: test setSourceValue(CosDpValueUnion)
// TODO: test setSourceValue(CosDpValueStruct)
// real-unsigned datapoint
datapoint = new DataPointImpl(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 engineering conversion
boolStatus = datapoint.setEngineeringConversion("x + 5");
Assert.assertEquals(true, boolStatus);
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set without timestamp
status = datapoint.setUnsignedSourceValue(11, true);
Assert.assertEquals(1, status);
// source value is updated, source timestamp is set to current time
Assert.assertEquals(16, datapoint.getSourceValue().unsignedValue());
Assert.assertTrue(datapoint.getSourceTimestamp() > updateTs);
// output value/output timestamp is synchronized
Assert.assertEquals(16, datapoint.getValue().unsignedValue());
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint
.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
// TODO: test setSourceValue(CosDpValueUnion)
// TODO: test setSourceValue(CosDpValueStruct)
// real-double datapoint
datapoint = new DataPointImpl(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 engineering conversion
boolStatus = datapoint.setEngineeringConversion("x + 5.1");
Assert.assertEquals(true, boolStatus);
updateTs = Calendar.getInstance().getTimeInMillis();
sleep(1);
// set with timestamp
status = datapoint.setDoubleSourceValue(15.7, true);
Assert.assertEquals(1, status);
// source value is updated, source timestamp is set to current time
Assert.assertEquals(20.8, round(datapoint.getSourceValue().dblValue(),
1));
Assert.assertTrue(datapoint.getSourceTimestamp() > updateTs);
// output value/output timestamp is synchronized
Assert.assertEquals(datapoint.getSourceValue().dblValue(), datapoint
.getValue().dblValue());
Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint
.getTimestamp());
// update-time is set to current time
Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
// TODO: test setSourceValue(CosDpValueUnion)
// TODO: test setSourceValue(CosDpValueStruct)
// real-string datapoint
datapoint = new DataPointImpl(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 engineering conversion (not supported for string type for the
// moment)
boolStatus = datapoint.setEngineeringConversion("x + \"-str\"");
Assert.assertEquals(false, boolStatus);
// // set engineering conversion
// boolStatus = datapoint.setEngineeringConversion("x + \"-str\"");
// Assert.assertEquals(true, boolStatus);
//
// // set with timestamp
// updateTs = Calendar.getInstance().getTimeInMillis();
// status = datapoint.setStringSourceValue("TestTest", true);
// Assert.assertEquals(1, status);
// //source value is updated, source timestamp is set to current time
// Assert.assertTrue(datapoint.getSourceValue().charValue().compareTo(
// "TestTest-str") == 0);
// Assert.assertTrue(datapoint.getSourceTimestamp() > updateTs);
// //output value/output timestamp is synchronized
// Assert
// .assertTrue(datapoint.getValue().charValue().compareTo("TestTest-str")
// == 0);
// Assert.assertEquals(datapoint.getSourceTimestamp(), datapoint
// .getTimestamp());
// // update-time is set to current time
// Assert.assertTrue(datapoint.getUpdateTimestamp() > updateTs);
}
/**
* Test method for alarm raising and alarm inhibit.
*
* <p>
* Validated functions:
* <ul>
* <li>{@link tcg.scada.da.DataPoint#setAlarmInhibit()}</li>
* <li>{@link tcg.scada.da.DataPoint#removeAlarmInhibit()}</li>
* <li>{@link tcg.scada.da.DataPoint#raiseAlarm()}</li>
* <li>{@link tcg.scada.da.DataPoint#normalizeAlarm()}</li>
* <li>{@link tcg.scada.da.DataPoint#acknowledgeAlarm()}</li>
* </ul>
* </p>
*/
public void testAlarm()
{
//fail("Not yet implemented"); // TODO
}
/**
* Test method for real point as meter source point.
*/
public void testAsMeterSourcePoint()
{
//TODO: test if inhibit and override trigger update in meter point
//fail("Not yet implemented"); // TODO
}
/**
* Test method for real point as expression parameter of a calculated point.
*/
public void testAsExpressionParam()
{
//TODO: test if inhibit and override trigger update in calculated point
//fail("Not yet implemented"); // TODO
}
/**
* Test method for real point as quality point.
*/
public void testAsQualityPoint()
{
//TODO: test if inhibit and override trigger update in child point
//fail("Not yet implemented"); // TODO
}
/**
* Helper class so that we can access the protected variable of DataPoint.
*
* @author Yoga
*
*/
static private class DataPointImpl extends RealDataPoint
{
DataPointImpl(CosDpValueTypeEnum inDataType)
{
super(inDataType);
}
}
}