Refine search
@Test public void serializeBasicTypes() throws Exception { doReturn(SINGLE_WRITE_COMMIT_RESPONSE) .when(firestoreMock) .sendRequest( commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any()); documentReference.set(ALL_SUPPORTED_TYPES_MAP).get(); documentReference.set(ALL_SUPPORTED_TYPES_OBJECT).get(); CommitRequest expectedCommit = commit(set(ALL_SUPPORTED_TYPES_PROTO)); assertCommitEquals(expectedCommit, commitCapture.getAllValues().get(0)); assertCommitEquals(expectedCommit, commitCapture.getAllValues().get(1)); }
@Test public void setDocument() throws Exception { Map<String, Object> nanNullMap = new HashMap<>(); nanNullMap.put("nan", Double.NaN); nanNullMap.put("null", null); randomDoc.set(nanNullMap).get(); DocumentSnapshot documentSnapshot = randomDoc.get().get(); assertEquals((Double) Double.NaN, documentSnapshot.getDouble("nan")); assertEquals(null, documentSnapshot.get("null")); }
@Test public void setDocumentWithEmptyMerge() throws Exception { doReturn(SINGLE_WRITE_COMMIT_RESPONSE) .when(firestoreMock) .sendRequest( commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any()); documentReference.set(map(), SetOptions.merge()).get(); assertCommitEquals( commit(set(Collections.<String, Value>emptyMap(), Collections.<String>emptyList())), commitCapture.getValue()); }
@Test public void addDocument() throws Exception { DocumentReference documentReference = randomColl.add(SINGLE_FIELD_MAP).get(); assertEquals(20, documentReference.getId().length()); DocumentSnapshot documentSnapshot = documentReference.get().get(); assertEquals(SINGLE_FIELD_OBJECT, documentSnapshot.toObject(SingleField.class)); }
@Test public void testReloadAsyncNull() throws ExecutionException, InterruptedException { initializeExpectedSink(1); expect(logging.getOptions()).andReturn(mockOptions); expect(logging.getSinkAsync(NAME)).andReturn(ApiFutures.<Sink>immediateFuture(null)); replay(logging); initializeSink(); assertNull(sink.reloadAsync().get()); }
@Test public void testDeleteAsyncFalse() throws ExecutionException, InterruptedException { initializeExpectedMetric(1); expect(logging.getOptions()).andReturn(mockOptions); expect(logging.deleteMetricAsync(NAME)).andReturn(ApiFutures.immediateFuture(false)); replay(logging); initializeMetric(); assertFalse(metric.deleteAsync().get()); }
@Test public void testDeleteAsyncFalse() throws ExecutionException, InterruptedException { initializeExpectedSink(1); expect(logging.getOptions()).andReturn(mockOptions); expect(logging.deleteSinkAsync(NAME)).andReturn(ApiFutures.immediateFuture(false)); replay(logging); initializeSink(); assertFalse(sink.deleteAsync().get()); }
@Test public void testDeleteAsyncTrue() throws ExecutionException, InterruptedException { initializeExpectedMetric(1); expect(logging.getOptions()).andReturn(mockOptions); expect(logging.deleteMetricAsync(NAME)).andReturn(ApiFutures.immediateFuture(true)); replay(logging); initializeMetric(); assertTrue(metric.deleteAsync().get()); }
@Test public void testReloadAsyncNull() throws ExecutionException, InterruptedException { initializeExpectedMetric(1); expect(logging.getOptions()).andReturn(mockOptions); expect(logging.getMetricAsync(NAME)).andReturn(ApiFutures.<Metric>immediateFuture(null)); replay(logging); initializeMetric(); assertNull(metric.reloadAsync().get()); }
@Test public void updateDocument() throws Exception { AllSupportedTypes expectedResult = new AllSupportedTypes(); WriteResult writeResult = randomDoc.set(ALL_SUPPORTED_TYPES_MAP).get(); DocumentSnapshot documentSnapshot = randomDoc.get().get(); assertEquals(expectedResult, documentSnapshot.toObject(AllSupportedTypes.class)); randomDoc.update(Precondition.updatedAt(writeResult.getUpdateTime()), "foo", "updated").get(); documentSnapshot = randomDoc.get().get(); expectedResult.foo = "updated"; assertEquals(expectedResult, documentSnapshot.toObject(AllSupportedTypes.class)); }
@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 getAllWithFieldMask() throws Exception { DocumentReference ref = randomColl.document("doc1"); ref.set(ALL_SUPPORTED_TYPES_MAP).get(); List<DocumentSnapshot> documentSnapshots = firestore.getAll(new DocumentReference[] {ref}, FieldMask.of("foo")).get(); assertEquals(map("foo", "bar"), documentSnapshots.get(0).getData()); }
@Test public void mergeDocumentWithServerTimestamp() throws Exception { Map<String, Object> originalMap = LocalFirestoreHelper.<String, Object>map("a", "b"); Map<String, Object> updateMap = map("c", (Object) FieldValue.serverTimestamp()); randomDoc.set(originalMap).get(); randomDoc.set(updateMap, SetOptions.merge()).get(); DocumentSnapshot documentSnapshot = randomDoc.get().get(); assertEquals("b", documentSnapshot.getString("a")); assertNotNull(documentSnapshot.getDate("c")); }
@Test public void testDeleteSinkAsync_Null() throws ExecutionException, InterruptedException { DeleteSinkRequest request = DeleteSinkRequest.newBuilder().setSinkName(SINK_NAME_PB).build(); ApiFuture<Empty> response = ApiFutures.immediateFuture(null); EasyMock.expect(loggingRpcMock.delete(request)).andReturn(response); EasyMock.replay(rpcFactoryMock, loggingRpcMock); logging = options.getService(); assertFalse(logging.deleteSinkAsync(SINK_NAME).get()); }
@Test public void testDeleteMetricAsync_Null() throws ExecutionException, InterruptedException { DeleteLogMetricRequest request = DeleteLogMetricRequest.newBuilder().setMetricName(METRIC_NAME_PB).build(); ApiFuture<Empty> response = ApiFutures.immediateFuture(null); EasyMock.expect(loggingRpcMock.delete(request)).andReturn(response); EasyMock.replay(rpcFactoryMock, loggingRpcMock); logging = options.getService(); assertFalse(logging.deleteMetricAsync(METRIC_NAME).get()); }
@Test public void testGetSinkAsync_Null() throws ExecutionException, InterruptedException { ApiFuture<LogSink> response = ApiFutures.immediateFuture(null); GetSinkRequest request = GetSinkRequest.newBuilder().setSinkName(SINK_NAME_PB).build(); EasyMock.expect(loggingRpcMock.get(request)).andReturn(response); EasyMock.replay(rpcFactoryMock, loggingRpcMock); logging = options.getService(); assertNull(logging.getSinkAsync(SINK_NAME).get()); }