Search in sources :

Example 6 with TestScalarFieldAccess

use of com.apple.foundationdb.record.metadata.ExpressionTestsProto.TestScalarFieldAccess in project fdb-record-layer by FoundationDB.

the class QueryExpressionTest method testAnd.

@Test
public void testAnd() throws Exception {
    final TestScalarFieldAccess val = TestScalarFieldAccess.newBuilder().build();
    assertNull(evaluate(and(TRUE, NULL), val));
    // Use equals here, because assertTrue/False would throw nullPointerException if and() returns null
    assertEquals(true, evaluate(and(TRUE, TRUE), val));
    assertEquals(false, evaluate(and(TRUE, FALSE), val));
    assertEquals(false, evaluate(and(NULL, FALSE), val));
    assertNull(evaluate(and(NULL, TRUE), val));
}
Also used : TestScalarFieldAccess(com.apple.foundationdb.record.metadata.ExpressionTestsProto.TestScalarFieldAccess) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with TestScalarFieldAccess

use of com.apple.foundationdb.record.metadata.ExpressionTestsProto.TestScalarFieldAccess in project fdb-record-layer by FoundationDB.

the class QueryExpressionTest method testParameterComparison.

protected void testParameterComparison(String name, String field, Object val1, Comparisons.Type type, Object val2, Boolean expected) throws Exception {
    if (type.isUnary()) {
        assertThrows(name, RecordCoreException.class, () -> new Comparisons.ParameterComparison(type, "fooParam"));
        return;
    }
    final TestScalarFieldAccess rec = createRecord(field, val1).build();
    try {
        final Comparisons.Comparison comparison = new Comparisons.ParameterComparison(type, "fooParam");
        final QueryComponent qc = new FieldWithComparison(field, comparison);
        final Bindings bindings = Bindings.newBuilder().set("fooParam", val2).build();
        if (val1 != null && val2 != null && (type == Comparisons.Type.IN && !(val2 instanceof List) || type.name().startsWith("TEXT_"))) {
            assertThrows(name, RecordCoreException.class, () -> evaluate(qc, bindings, rec));
        } else {
            assertEquals(expected, evaluate(qc, bindings, rec), name);
        }
    } catch (Exception e) {
        throw new AssertionError(name + " Threw: " + e.getMessage(), e);
    }
}
Also used : TestScalarFieldAccess(com.apple.foundationdb.record.metadata.ExpressionTestsProto.TestScalarFieldAccess) ArrayList(java.util.ArrayList) List(java.util.List) Bindings(com.apple.foundationdb.record.Bindings) RecordCoreException(com.apple.foundationdb.record.RecordCoreException)

Aggregations

TestScalarFieldAccess (com.apple.foundationdb.record.metadata.ExpressionTestsProto.TestScalarFieldAccess)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Test (org.junit.jupiter.api.Test)4 Bindings (com.apple.foundationdb.record.Bindings)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1