Search in sources :

Example 1 with TestScalarFieldAccess

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

the class QueryExpressionTest method testOneOfThemEqualsValue.

@ParameterizedTest(name = "testOneOfThemEqualsValue [emptyMode = {0}]")
@EnumSource(Field.OneOfThemEmptyMode.class)
public void testOneOfThemEqualsValue(Field.OneOfThemEmptyMode emptyMode) throws Exception {
    final TestScalarFieldAccess oneRepeatedValue = TestScalarFieldAccess.newBuilder().addRepeatMe("fishes").build();
    final QueryComponent component = field("repeat_me").oneOfThem(emptyMode).equalsValue("fishes");
    component.validate(TestScalarFieldAccess.getDescriptor());
    final Boolean eval = evaluate(component, oneRepeatedValue);
    assertEquals(Boolean.TRUE, eval);
}
Also used : TestScalarFieldAccess(com.apple.foundationdb.record.metadata.ExpressionTestsProto.TestScalarFieldAccess) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with TestScalarFieldAccess

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

the class QueryExpressionTest method testOr.

@Test
public void testOr() throws Exception {
    final TestScalarFieldAccess val = TestScalarFieldAccess.newBuilder().build();
    assertNull(evaluate(or(FALSE, NULL), val));
    // Use equals here, because assertTrue/False would throw nullPointerException if or() returns null
    assertEquals(true, evaluate(or(FALSE, TRUE), val));
    assertEquals(true, evaluate(or(TRUE, FALSE), val));
    assertEquals(false, evaluate(or(FALSE, FALSE), val));
    assertEquals(true, evaluate(or(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 3 with TestScalarFieldAccess

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

the class QueryExpressionTest method testOneOfThemEqualsNoValues.

@ParameterizedTest(name = "testOneOfThemEqualsNoValues [emptyMode = {0}]")
@EnumSource(Field.OneOfThemEmptyMode.class)
public void testOneOfThemEqualsNoValues(Field.OneOfThemEmptyMode emptyMode) throws Exception {
    final TestScalarFieldAccess noRepeatedValues = TestScalarFieldAccess.newBuilder().build();
    final QueryComponent component = field("repeat_me").oneOfThem(emptyMode).equalsValue("fishes");
    component.validate(TestScalarFieldAccess.getDescriptor());
    final Boolean eval = evaluate(component, noRepeatedValues);
    assertEquals(emptyMode == Field.OneOfThemEmptyMode.EMPTY_UNKNOWN ? null : Boolean.FALSE, eval);
}
Also used : TestScalarFieldAccess(com.apple.foundationdb.record.metadata.ExpressionTestsProto.TestScalarFieldAccess) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with TestScalarFieldAccess

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

the class QueryExpressionTest method testNot.

@Test
public void testNot() throws Exception {
    final TestScalarFieldAccess val = TestScalarFieldAccess.newBuilder().build();
    assertNull(evaluate(not(NULL), val));
    assertEquals(true, evaluate(not(FALSE), val));
    assertEquals(false, evaluate(not(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 5 with TestScalarFieldAccess

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

the class QueryExpressionTest method testParameterComparisonsSimple.

@Test
public void testParameterComparisonsSimple() throws Exception {
    final TestScalarFieldAccess rec = TestScalarFieldAccess.newBuilder().setField("abc").build();
    final QueryComponent equalsP1 = new FieldWithComparison("field", new Comparisons.ParameterComparison(Comparisons.Type.EQUALS, "p1"));
    final QueryComponent notEqualsP2 = new FieldWithComparison("field", new Comparisons.ParameterComparison(Comparisons.Type.NOT_EQUALS, "p2"));
    final Bindings b1 = Bindings.newBuilder().set("p1", "abc").set("p2", "xyz").build();
    assertTrue(evaluate(equalsP1, b1, rec));
    assertTrue(evaluate(notEqualsP2, b1, rec));
    final Bindings b2 = Bindings.newBuilder().set("p1", "foo").set("p2", "bar").build();
    assertFalse(evaluate(equalsP1, b2, rec));
    assertTrue(evaluate(notEqualsP2, b2, rec));
}
Also used : TestScalarFieldAccess(com.apple.foundationdb.record.metadata.ExpressionTestsProto.TestScalarFieldAccess) Bindings(com.apple.foundationdb.record.Bindings) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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