Search in sources :

Example 1 with NotInFilter

use of com.google.firebase.firestore.core.NotInFilter in project firebase-android-sdk by firebase.

the class RemoteSerializerTest method testNotInSerialization.

@Test
public void testNotInSerialization() {
    FieldFilter inputFilter = filter("field", "not-in", asList(42));
    StructuredQuery.Filter apiFilter = serializer.encodeUnaryOrFieldFilter(inputFilter);
    ArrayValue.Builder notInFilterValue = ArrayValue.newBuilder().addValues(Value.newBuilder().setIntegerValue(42));
    StructuredQuery.Filter expectedFilter = Filter.newBuilder().setFieldFilter(StructuredQuery.FieldFilter.newBuilder().setField(FieldReference.newBuilder().setFieldPath("field")).setOp(Operator.NOT_IN).setValue(Value.newBuilder().setArrayValue(notInFilterValue)).build()).build();
    assertEquals(expectedFilter, apiFilter);
    FieldFilter roundTripped = serializer.decodeFieldFilter(apiFilter.getFieldFilter());
    assertEquals(roundTripped, inputFilter);
    assertTrue(roundTripped instanceof NotInFilter);
}
Also used : StructuredQuery(com.google.firestore.v1.StructuredQuery) FieldFilter(com.google.firebase.firestore.core.FieldFilter) KeyFieldFilter(com.google.firebase.firestore.core.KeyFieldFilter) NotInFilter(com.google.firebase.firestore.core.NotInFilter) Filter(com.google.firestore.v1.StructuredQuery.Filter) ArrayValue(com.google.firestore.v1.ArrayValue) Test(org.junit.Test)

Example 2 with NotInFilter

use of com.google.firebase.firestore.core.NotInFilter in project firebase-android-sdk by firebase.

the class RemoteSerializerTest method testNotInWithNullSerialization.

@Test
public void testNotInWithNullSerialization() {
    List<Object> nullArray = new ArrayList<>();
    nullArray.add(null);
    FieldFilter inputFilter = filter("field", "not-in", nullArray);
    StructuredQuery.Filter apiFilter = serializer.encodeUnaryOrFieldFilter(inputFilter);
    ArrayValue.Builder notInFilterValue = ArrayValue.newBuilder().addValues(Value.newBuilder().setNullValue(NullValue.NULL_VALUE));
    StructuredQuery.Filter expectedFilter = Filter.newBuilder().setFieldFilter(StructuredQuery.FieldFilter.newBuilder().setField(FieldReference.newBuilder().setFieldPath("field")).setOp(Operator.NOT_IN).setValue(Value.newBuilder().setArrayValue(notInFilterValue)).build()).build();
    assertEquals(expectedFilter, apiFilter);
    FieldFilter roundTripped = serializer.decodeFieldFilter(apiFilter.getFieldFilter());
    assertEquals(roundTripped, inputFilter);
    assertTrue(roundTripped instanceof NotInFilter);
}
Also used : StructuredQuery(com.google.firestore.v1.StructuredQuery) FieldFilter(com.google.firebase.firestore.core.FieldFilter) KeyFieldFilter(com.google.firebase.firestore.core.KeyFieldFilter) ArrayList(java.util.ArrayList) NotInFilter(com.google.firebase.firestore.core.NotInFilter) Filter(com.google.firestore.v1.StructuredQuery.Filter) ArrayValue(com.google.firestore.v1.ArrayValue) Test(org.junit.Test)

Aggregations

FieldFilter (com.google.firebase.firestore.core.FieldFilter)2 KeyFieldFilter (com.google.firebase.firestore.core.KeyFieldFilter)2 NotInFilter (com.google.firebase.firestore.core.NotInFilter)2 ArrayValue (com.google.firestore.v1.ArrayValue)2 StructuredQuery (com.google.firestore.v1.StructuredQuery)2 Filter (com.google.firestore.v1.StructuredQuery.Filter)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1