Search in sources :

Example 1 with ClassAdTime

use of org.apache.asterix.external.classad.ClassAdTime in project asterixdb by apache.

the class ClassAdUnitTester method testValue.

/*********************************************************************
     * Function: test_value
     * Purpose: Test the Value class.
     *
     * @throws HyracksDataException
     *********************************************************************/
public static void testValue(Parameters parameters, Results results, ClassAdObjectPool objectPool) throws HyracksDataException {
    Value v = new Value(objectPool);
    boolean isExpectedType;
    System.out.println("Testing the Value class...");
    test("New value is undefined", (v.isUndefinedValue()), "test_value 1", results);
    test("New value isn't boolean", !(v.isBooleanValue()), "test_value 2", results);
    test("GetType gives UNDEFINED_VALUE", (v.getType() == ValueType.UNDEFINED_VALUE), "test_value 3", results);
    v.setErrorValue();
    test("Is error value", (v.isErrorValue()), "test_value 4", results);
    test("GetType gives ERROR_VALUE", (v.getType() == ValueType.ERROR_VALUE), "test_value 5", results);
    MutableBoolean b = new MutableBoolean();
    v.setBooleanValue(true);
    isExpectedType = v.isBooleanValue(b);
    test("Value is not undefined", !(v.isUndefinedValue()), "Value is not undefined", results);
    test("Value is boolean", (v.isBooleanValue()), "Value is boolean", results);
    test("Try 2: New value is boolean", (isExpectedType == true), "Try 2: New value is boolean", results);
    test("Boolean is true", (b.booleanValue() == true), "Boolean is true", results);
    test("GetType gives BOOLEAN_VALUE", (v.getType() == ValueType.BOOLEAN_VALUE), "GetType gives BOOLEAN_VALUE", results);
    AMutableDouble r = new AMutableDouble(0.0);
    v.setRealValue(1.0);
    isExpectedType = v.isRealValue(r);
    test("Value is real", isExpectedType, results);
    test("Real is 1.0", (r.getDoubleValue() == 1.0), results);
    test("GetType gives REAL_VALUE", (v.getType() == ValueType.REAL_VALUE), results);
    test("Real is a number", v.isNumber(), results);
    AMutableInt64 i = new AMutableInt64(0);
    v.setIntegerValue(1);
    isExpectedType = v.isIntegerValue(i);
    test("Value is integer", isExpectedType, results);
    test("Integer is 1", (i.getLongValue() == 1), results);
    test("GetType gives INTEGER_VALUE", (v.getType() == ValueType.INTEGER_VALUE), results);
    test("Integer is a number", v.isNumber(), results);
    AMutableCharArrayString s = new AMutableCharArrayString();
    v.setStringValue("Robert-Houdin");
    isExpectedType = v.isStringValue(s);
    test("Value is String", isExpectedType, results);
    test("String is 'Robert-Houdin'", (0 == s.compareTo("Robert-Houdin")), results);
    test("GetType gives STRING_VALUE", (v.getType() == ValueType.STRING_VALUE), results);
    ClassAdTime at = new ClassAdTime(10, 36000000);
    v.setAbsoluteTimeValue(at);
    at.setValue(0);
    at.setTimeZone(0);
    isExpectedType = v.isAbsoluteTimeValue(at);
    test("Value is absolute time", isExpectedType, results);
    test("Absolute time is 10, 0", (10 == at.getTime() && 36000000 == at.getOffset()), results);
    test("GetType gives ABSOLUTE_TIME_VALUE", (v.getType() == ValueType.ABSOLUTE_TIME_VALUE), results);
    ClassAdTime rt = new ClassAdTime(10, false);
    v.setRelativeTimeValue(10);
    isExpectedType = v.isRelativeTimeValue(rt);
    test("Value is relative time", isExpectedType, results);
    test("Relative time is 10", (10 == rt.getRelativeTime()), results);
    test("GetType gives RELATIVE_TIME_VALUE", (v.getType() == ValueType.RELATIVE_TIME_VALUE), results);
    ExprList l = new ExprList(objectPool);
    ExprList ll = new ExprList(objectPool);
    v.setListValue(l);
    isExpectedType = v.isListValue(ll);
    test("Value is list value", isExpectedType, results);
    test("List value is correct", l.equals(ll), results);
    test("GetType gives LIST_VALUE", (v.getType() == ValueType.LIST_VALUE), results);
    ExprList sl = new ExprList(true, objectPool);
    ll = new ExprList(true, objectPool);
    v.setListValue(sl);
    isExpectedType = v.isListValue(ll);
    test("Value is list value", isExpectedType, results);
    test("List value is correct", sl.equals(ll), results);
    test("GetType gives SLIST_VALUE", (v.getType() == ValueType.SLIST_VALUE), results);
    ClassAd c = new ClassAd(objectPool);
    c.insertAttr("test_int", 10);
    ClassAd cc = new ClassAd(objectPool);
    v.setClassAdValue(c);
    isExpectedType = v.isClassAdValue(cc);
    test("Value is ClassAd value", isExpectedType, results);
    test("ClassAd value is correct", c.equals(cc), results);
    test("GetType gives CLASSAD_VALUE", (v.getType() == ValueType.CLASSAD_VALUE), results);
    return;
}
Also used : ClassAd(org.apache.asterix.external.classad.ClassAd) ClassAdTime(org.apache.asterix.external.classad.ClassAdTime) ExprList(org.apache.asterix.external.classad.ExprList) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) AMutableDouble(org.apache.asterix.om.base.AMutableDouble) Value(org.apache.asterix.external.classad.Value) AMutableInt64(org.apache.asterix.om.base.AMutableInt64) AMutableCharArrayString(org.apache.asterix.external.classad.AMutableCharArrayString)

Aggregations

AMutableCharArrayString (org.apache.asterix.external.classad.AMutableCharArrayString)1 ClassAd (org.apache.asterix.external.classad.ClassAd)1 ClassAdTime (org.apache.asterix.external.classad.ClassAdTime)1 ExprList (org.apache.asterix.external.classad.ExprList)1 Value (org.apache.asterix.external.classad.Value)1 AMutableDouble (org.apache.asterix.om.base.AMutableDouble)1 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)1 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)1