Search in sources :

Example 76 with CommitRequest

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

the class DocumentReferenceTest method setWithArrayUnion.

@Test
public void setWithArrayUnion() throws Exception {
    doReturn(FIELD_TRANSFORM_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    documentReference.set(map("foo", FieldValue.arrayUnion("bar", map("foo", "baz")))).get();
    CommitRequest set = commit(set(Collections.emptyMap()), transform("foo", arrayUnion(string("bar"), object("foo", string("baz")))));
    CommitRequest commitRequest = commitCapture.getValue();
    assertCommitEquals(set, commitRequest);
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Example 77 with CommitRequest

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

the class DocumentReferenceTest method createWithServerTimestamp.

@Test
public void createWithServerTimestamp() throws Exception {
    doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    documentReference.create(LocalFirestoreHelper.SERVER_TIMESTAMP_MAP).get();
    documentReference.create(LocalFirestoreHelper.SERVER_TIMESTAMP_OBJECT).get();
    CommitRequest create = commit(create(Collections.emptyMap()), transform("foo", serverTimestamp(), "inner.bar", serverTimestamp()));
    List<CommitRequest> commitRequests = commitCapture.getAllValues();
    assertCommitEquals(create, commitRequests.get(0));
    assertCommitEquals(create, commitRequests.get(1));
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Example 78 with CommitRequest

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

the class DocumentReferenceTest method mergeWithServerTimestamps.

@Test
public void mergeWithServerTimestamps() throws Exception {
    doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    documentReference.set(LocalFirestoreHelper.SERVER_TIMESTAMP_MAP, SetOptions.mergeFields("inner.bar")).get();
    documentReference.set(LocalFirestoreHelper.SERVER_TIMESTAMP_OBJECT, SetOptions.mergeFields("inner.bar")).get();
    CommitRequest set = commit(set(SERVER_TIMESTAMP_PROTO, new ArrayList<>()), transform("inner.bar", serverTimestamp()));
    List<CommitRequest> commitRequests = commitCapture.getAllValues();
    assertCommitEquals(set, commitRequests.get(0));
    assertCommitEquals(set, commitRequests.get(1));
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) ArrayList(java.util.ArrayList) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Example 79 with CommitRequest

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

the class DocumentReferenceTest method setWithIncrement.

@Test
public void setWithIncrement() throws Exception {
    doReturn(FIELD_TRANSFORM_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    documentReference.set(map("integer", FieldValue.increment(1), "double", FieldValue.increment(1.1))).get();
    CommitRequest set = commit(set(Collections.emptyMap()), transform("integer", increment(Value.newBuilder().setIntegerValue(1).build()), "double", increment(Value.newBuilder().setDoubleValue(1.1).build())));
    CommitRequest commitRequest = commitCapture.getValue();
    assertCommitEquals(set, commitRequest);
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Example 80 with CommitRequest

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

the class DocumentReferenceTest method setWithServerTimestamp.

@Test
public void setWithServerTimestamp() throws Exception {
    doReturn(FIELD_TRANSFORM_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    documentReference.set(LocalFirestoreHelper.SERVER_TIMESTAMP_MAP).get();
    documentReference.set(LocalFirestoreHelper.SERVER_TIMESTAMP_OBJECT).get();
    CommitRequest set = commit(set(SERVER_TIMESTAMP_PROTO), transform("foo", serverTimestamp(), "inner.bar", serverTimestamp()));
    List<CommitRequest> commitRequests = commitCapture.getAllValues();
    assertCommitEquals(set, commitRequests.get(0));
    assertCommitEquals(set, commitRequests.get(1));
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)85 CommitRequest (com.google.spanner.v1.CommitRequest)47 CommitRequest (com.google.firestore.v1.CommitRequest)40 CommitResponse (com.google.firestore.v1.CommitResponse)40 ArrayList (java.util.ArrayList)26 Connection (java.sql.Connection)23 ByteString (com.google.protobuf.ByteString)14 ExecuteSqlRequest (com.google.spanner.v1.ExecuteSqlRequest)12 SQLException (java.sql.SQLException)12 Statement (java.sql.Statement)12 CopyManager (org.postgresql.copy.CopyManager)11 BaseConnection (org.postgresql.core.BaseConnection)11 ExecuteBatchDmlRequest (com.google.spanner.v1.ExecuteBatchDmlRequest)10 ArrayValue (com.google.firestore.v1.ArrayValue)9 MapValue (com.google.firestore.v1.MapValue)9 Value (com.google.firestore.v1.Value)9 Write (com.google.firestore.v1.Write)9 StringReader (java.io.StringReader)9 HashMap (java.util.HashMap)9 AbstractMessage (com.google.protobuf.AbstractMessage)8