use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-firestore by googleapis.
the class DocumentReferenceTest method createDocument.
@Test
public void createDocument() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
documentReference.create(SINGLE_FIELD_MAP).get();
documentReference.create(SINGLE_FIELD_OBJECT).get();
CommitRequest expectedCommit = commit(create(SINGLE_FIELD_PROTO));
List<CommitRequest> commitRequests = commitCapture.getAllValues();
assertCommitEquals(expectedCommit, commitRequests.get(0));
assertCommitEquals(expectedCommit, commitRequests.get(1));
}
use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-firestore by googleapis.
the class DocumentReferenceTest method updateDocument.
@Test
public void updateDocument() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
documentReference.update(SINGLE_FIELD_MAP);
documentReference.update("foo", "bar").get();
CommitRequest expectedCommit = commit(update(SINGLE_FIELD_PROTO, Collections.singletonList("foo")));
for (CommitRequest request : commitCapture.getAllValues()) {
assertCommitEquals(expectedCommit, request);
}
}
use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-firestore by googleapis.
the class DocumentReferenceTest method updateDocumentWithTwoFields.
@Test
public void updateDocumentWithTwoFields() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
documentReference.update("a", "b", "c", "d").get();
CommitRequest expectedCommit = commit(update(map("a", Value.newBuilder().setStringValue("b").build(), "c", Value.newBuilder().setStringValue("d").build()), Arrays.asList("a", "c")));
assertCommitEquals(expectedCommit, commitCapture.getValue());
}
use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-firestore by googleapis.
the class WriteBatchTest method createDocumentWithValue.
@Test
public void createDocumentWithValue() throws Exception {
doReturn(commitResponse(2, 0)).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
batch.create(documentReference, LocalFirestoreHelper.SINGLE_FIELD_PROTO).create(documentReference, LocalFirestoreHelper.SINGLE_FIELD_OBJECT);
assertEquals(2, batch.getMutationsSize());
List<WriteResult> writeResults = batch.commit().get();
List<Write> writes = new ArrayList<>();
for (int i = 0; i < writeResults.size(); ++i) {
assertEquals(Timestamp.ofTimeSecondsAndNanos(i, i), writeResults.get(i).getUpdateTime());
writes.add(create(LocalFirestoreHelper.SINGLE_FIELD_PROTO));
}
CommitRequest commitRequest = commitCapture.getValue();
assertEquals(commit(writes.toArray(new Write[] {})), commitRequest);
}
use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-firestore by googleapis.
the class FirestoreClientTest method commitTest.
@Test
public void commitTest() throws Exception {
CommitResponse expectedResponse = CommitResponse.newBuilder().addAllWriteResults(new ArrayList<WriteResult>()).setCommitTime(Timestamp.newBuilder().build()).build();
mockFirestore.addResponse(expectedResponse);
String database = "database1789464955";
List<Write> writes = new ArrayList<>();
CommitResponse actualResponse = client.commit(database, writes);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockFirestore.getRequests();
Assert.assertEquals(1, actualRequests.size());
CommitRequest actualRequest = ((CommitRequest) actualRequests.get(0));
Assert.assertEquals(database, actualRequest.getDatabase());
Assert.assertEquals(writes, actualRequest.getWritesList());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations