@Test public void serializeDocumentReference() throws Exception { doReturn(SINGLE_WRITE_COMMIT_RESPONSE) .when(firestoreMock) .sendRequest( commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any()); documentReference.set(map("docRef", (Object) documentReference)).get(); Map<String, Value> documentReferenceFields = new HashMap<>(); documentReferenceFields.put( "docRef", Value.newBuilder().setReferenceValue(DOCUMENT_NAME).build()); assertCommitEquals(commit(set(documentReferenceFields)), commitCapture.getValue()); }
@Test public void deserializeDocumentReference() throws Exception { doAnswer( getAllResponse( map("docRef", Value.newBuilder().setReferenceValue(DOCUMENT_NAME).build()))) .when(firestoreMock) .streamRequest( getAllCapture.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any()); DocumentSnapshot snapshot = documentReference.get().get(); assertEquals(documentReference, snapshot.getData().get("docRef")); assertEquals(documentReference, snapshot.getReference()); }
@Test public void withDocumentIdFilter() throws Exception { doAnswer(queryResponse()) .when(firestoreMock) .streamRequest( runQuery.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any()); query.whereEqualTo(FieldPath.documentId(), "doc").get().get(); RunQueryRequest expectedRequest = query( filter( Operator.EQUAL, "__name__", Value.newBuilder().setReferenceValue(DOCUMENT_NAME).build())); assertEquals(expectedRequest, runQuery.getValue()); }
} else if (sanitizedObject instanceof DocumentReference) { DocumentReference docRef = (DocumentReference) sanitizedObject; return Value.newBuilder().setReferenceValue(docRef.getName()).build(); } else if (sanitizedObject instanceof Map) { MapValue.Builder res = MapValue.newBuilder();
} else if (sanitizedObject instanceof DocumentReference) { DocumentReference docRef = (DocumentReference) sanitizedObject; return Value.newBuilder().setReferenceValue(docRef.getName()).build(); } else if (sanitizedObject instanceof Map) { MapValue.Builder res = MapValue.newBuilder();
@Test public void withInequalityFilterForDocumentSnapshotCursor() throws Exception { doAnswer(queryResponse()) .when(firestoreMock) .streamRequest( runQuery.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any()); query .whereEqualTo("a", "b") .whereGreaterThanOrEqualTo("foo", "bar") .whereEqualTo("c", "d") .startAt(SINGLE_FIELD_SNAPSHOT) .get(); Value documentBoundary = Value.newBuilder().setReferenceValue(query.getResourcePath().toString() + "/doc").build(); RunQueryRequest queryRequest = query( filter(Operator.EQUAL, "a", "b"), filter(Operator.GREATER_THAN_OR_EQUAL), filter(Operator.EQUAL, "c", "d"), order("foo", Direction.ASCENDING), order("__name__", StructuredQuery.Direction.ASCENDING), startAt(true), startAt(documentBoundary, true)); assertEquals(queryRequest, runQuery.getValue()); }
@Test public void withStartAt() throws Exception { doAnswer(queryResponse()) .when(firestoreMock) .streamRequest( runQuery.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any()); query.orderBy("foo").orderBy(FieldPath.documentId()).startAt("bar", "foo").get().get(); Value documentBoundary = Value.newBuilder().setReferenceValue(query.getResourcePath().toString() + "/foo").build(); RunQueryRequest queryRequest = query( order("foo", StructuredQuery.Direction.ASCENDING), order("__name__", StructuredQuery.Direction.ASCENDING), startAt(true), startAt(documentBoundary, true)); assertEquals(queryRequest, runQuery.getValue()); }
@Test public void withExtractedDirectionForDocumentSnapshotCursor() throws Exception { doAnswer(queryResponse()) .when(firestoreMock) .streamRequest( runQuery.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any()); query.orderBy("foo", Query.Direction.DESCENDING).startAt(SINGLE_FIELD_SNAPSHOT).get(); Value documentBoundary = Value.newBuilder().setReferenceValue(query.getResourcePath().toString() + "/doc").build(); RunQueryRequest queryRequest = query( order("foo", Direction.DESCENDING), order("__name__", StructuredQuery.Direction.DESCENDING), startAt(true), startAt(documentBoundary, true)); assertEquals(queryRequest, runQuery.getValue()); }
@Test public void withEqualityFilterForDocumentSnapshotCursor() throws Exception { doAnswer(queryResponse()) .when(firestoreMock) .streamRequest( runQuery.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any()); query.whereEqualTo("foo", "bar").startAt(SINGLE_FIELD_SNAPSHOT).get(); Value documentBoundary = Value.newBuilder().setReferenceValue(query.getResourcePath().toString() + "/doc").build(); RunQueryRequest queryRequest = query( filter(Operator.EQUAL), order("__name__", StructuredQuery.Direction.ASCENDING), startAt(documentBoundary, true)); assertEquals(queryRequest, runQuery.getValue()); }
@Test public void withDocumentSnapshotCursor() throws Exception { doAnswer(queryResponse()) .when(firestoreMock) .streamRequest( runQuery.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any()); query.startAt(SINGLE_FIELD_SNAPSHOT).get(); Value documentBoundary = Value.newBuilder().setReferenceValue(query.getResourcePath().toString() + "/doc").build(); RunQueryRequest queryRequest = query( order("__name__", StructuredQuery.Direction.ASCENDING), startAt(documentBoundary, true)); assertEquals(queryRequest, runQuery.getValue()); }
@Test public void withDocumentIdAndDocumentSnapshotCursor() throws Exception { doAnswer(queryResponse()) .when(firestoreMock) .streamRequest( runQuery.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any()); query.orderBy(FieldPath.documentId()).startAt(SINGLE_FIELD_SNAPSHOT).get(); Value documentBoundary = Value.newBuilder().setReferenceValue(query.getResourcePath().toString() + "/doc").build(); RunQueryRequest queryRequest = query( order("__name__", StructuredQuery.Direction.ASCENDING), startAt(documentBoundary, true)); assertEquals(queryRequest, runQuery.getValue()); }
private Value referenceValue(String r) { return Value.newBuilder().setReferenceValue(r).build(); }