Search in sources :

Example 26 with Value

use of com.google.firestore.v1beta1.Value in project java-firestore by googleapis.

the class DocumentReferenceTest method updateWithDotsInFieldName.

@Test
public void updateWithDotsInFieldName() throws Exception {
    doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    documentReference.update(map("a.b.c", map("d.e", "foo"))).get();
    Map<String, Value> nestedUpdate = new HashMap<>();
    Value.Builder valueProto = Value.newBuilder();
    valueProto.getMapValueBuilder().putFields("d.e", Value.newBuilder().setStringValue("foo").build());
    Value.Builder cProto = Value.newBuilder();
    cProto.getMapValueBuilder().putFields("c", valueProto.build());
    Value.Builder bProto = Value.newBuilder();
    bProto.getMapValueBuilder().putFields("b", cProto.build());
    nestedUpdate.put("a", bProto.build());
    CommitRequest expectedCommit = commit(update(nestedUpdate, Arrays.asList("a.b.c")));
    assertCommitEquals(expectedCommit, commitCapture.getValue());
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) HashMap(java.util.HashMap) Value(com.google.firestore.v1.Value) MapValue(com.google.firestore.v1.MapValue) ArrayValue(com.google.firestore.v1.ArrayValue) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Example 27 with Value

use of com.google.firestore.v1beta1.Value in project java-firestore by googleapis.

the class DocumentReferenceTest method setNestedMapWithMerge.

@Test
public void setNestedMapWithMerge() throws Exception {
    doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    documentReference.set(NESTED_CLASS_OBJECT, SetOptions.mergeFields("first", "second")).get();
    Map<String, Value> nestedUpdate = new HashMap<>();
    Value.Builder nestedProto = Value.newBuilder();
    nestedProto.getMapValueBuilder().putAllFields(SINGLE_FIELD_PROTO);
    nestedUpdate.put("first", nestedProto.build());
    nestedProto.getMapValueBuilder().putAllFields(ALL_SUPPORTED_TYPES_PROTO);
    nestedUpdate.put("second", nestedProto.build());
    CommitRequest expectedCommit = commit(set(nestedUpdate, Arrays.asList("first", "second")));
    assertCommitEquals(expectedCommit, commitCapture.getValue());
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) HashMap(java.util.HashMap) Value(com.google.firestore.v1.Value) MapValue(com.google.firestore.v1.MapValue) ArrayValue(com.google.firestore.v1.ArrayValue) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Example 28 with Value

use of com.google.firestore.v1beta1.Value in project java-firestore by googleapis.

the class QueryTest method withDocumentSnapshotCursor.

@Test
public void withDocumentSnapshotCursor() {
    doAnswer(queryResponse()).when(firestoreMock).streamRequest(runQuery.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any());
    query.startAt(SINGLE_FIELD_SNAPSHOT).get();
    Value documentBoundary = reference(DOCUMENT_NAME);
    RunQueryRequest queryRequest = query(order("__name__", StructuredQuery.Direction.ASCENDING), startAt(documentBoundary, true));
    assertEquals(queryRequest, runQuery.getValue());
}
Also used : RunQueryRequest(com.google.firestore.v1.RunQueryRequest) Value(com.google.firestore.v1.Value) ArrayValue(com.google.firestore.v1.ArrayValue) Test(org.junit.Test)

Example 29 with Value

use of com.google.firestore.v1beta1.Value in project java-firestore by googleapis.

the class QueryTest method notInQueriesWithReferenceArray.

@Test
public void notInQueriesWithReferenceArray() throws Exception {
    doAnswer(queryResponse()).when(firestoreMock).streamRequest(runQuery.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any());
    query.whereNotIn(FieldPath.documentId(), Arrays.asList("doc", firestoreMock.document("coll/doc"))).get().get();
    Value value = Value.newBuilder().setArrayValue(ArrayValue.newBuilder().addValues(reference(DOCUMENT_NAME)).addValues(reference(DOCUMENT_NAME)).build()).build();
    RunQueryRequest expectedRequest = query(filter(Operator.NOT_IN, "__name__", value));
    assertEquals(expectedRequest, runQuery.getValue());
}
Also used : RunQueryRequest(com.google.firestore.v1.RunQueryRequest) Value(com.google.firestore.v1.Value) ArrayValue(com.google.firestore.v1.ArrayValue) Test(org.junit.Test)

Example 30 with Value

use of com.google.firestore.v1beta1.Value in project java-firestore by googleapis.

the class QueryTest method withDocumentReferenceCursor.

@Test
public void withDocumentReferenceCursor() {
    doAnswer(queryResponse()).when(firestoreMock).streamRequest(runQuery.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any());
    DocumentReference documentCursor = firestoreMock.document(DOCUMENT_PATH);
    Value documentValue = reference(DOCUMENT_NAME);
    query.startAt(documentCursor).get();
    RunQueryRequest queryRequest = query(order("__name__", StructuredQuery.Direction.ASCENDING), startAt(documentValue, true));
    assertEquals(queryRequest, runQuery.getValue());
}
Also used : RunQueryRequest(com.google.firestore.v1.RunQueryRequest) Value(com.google.firestore.v1.Value) ArrayValue(com.google.firestore.v1.ArrayValue) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)126 Value (com.google.firestore.v1.Value)108 ArrayValue (com.google.firestore.v1.ArrayValue)73 LinkedHashSet (java.util.LinkedHashSet)71 ObjectValue (com.google.firebase.firestore.model.ObjectValue)53 NullValue (com.google.protobuf.NullValue)50 MapValue (com.google.firestore.v1.MapValue)47 ArrayList (java.util.ArrayList)30 HashMap (java.util.HashMap)25 Value (com.google.datastore.v1.Value)20 Map (java.util.Map)20 TableFieldSchema (com.google.api.services.bigquery.model.TableFieldSchema)17 List (java.util.List)17 Record (org.apache.avro.generic.GenericData.Record)16 SchemaAndRecord (org.apache.beam.sdk.io.gcp.bigquery.SchemaAndRecord)16 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)16 Set (java.util.Set)14 TestUtil.wrapObject (com.google.firebase.firestore.testutil.TestUtil.wrapObject)13 Nullable (androidx.annotation.Nullable)10 Value (com.google.privacy.dlp.v2.Value)9