Search in sources :

Example 81 with CommitRequest

use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-firestore by googleapis.

the class DocumentReferenceTest method updateWithServerTimestamp.

@Test
public void updateWithServerTimestamp() throws Exception {
    doReturn(FIELD_TRANSFORM_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    documentReference.update(LocalFirestoreHelper.SERVER_TIMESTAMP_MAP).get();
    CommitRequest update = commit(update(Collections.emptyMap(), Collections.singletonList("inner")), transform("foo", serverTimestamp(), "inner.bar", serverTimestamp()));
    assertCommitEquals(update, commitCapture.getValue());
    documentReference.update("foo", FieldValue.serverTimestamp(), "inner.bar", FieldValue.serverTimestamp());
    update = commit(update(Collections.emptyMap(), new ArrayList<>(), UPDATE_PRECONDITION), transform("foo", serverTimestamp(), "inner.bar", serverTimestamp()));
    assertCommitEquals(update, commitCapture.getValue());
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Example 82 with CommitRequest

use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-firestore by googleapis.

the class DocumentReferenceTest method setDocumentWithNestedMerge.

@Test
public void setDocumentWithNestedMerge() 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.foo")).get();
    documentReference.set(NESTED_CLASS_OBJECT, SetOptions.mergeFields(Arrays.asList("first.foo"))).get();
    documentReference.set(NESTED_CLASS_OBJECT, SetOptions.mergeFieldPaths(Arrays.asList(FieldPath.of("first", "foo")))).get();
    Map<String, Value> nestedUpdate = new HashMap<>();
    Value.Builder nestedProto = Value.newBuilder();
    nestedProto.getMapValueBuilder().putAllFields(SINGLE_FIELD_PROTO);
    nestedUpdate.put("first", nestedProto.build());
    CommitRequest expectedCommit = commit(set(nestedUpdate, Arrays.asList("first.foo")));
    for (int i = 0; i < 3; ++i) {
        assertCommitEquals(expectedCommit, commitCapture.getAllValues().get(i));
    }
}
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 83 with CommitRequest

use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-firestore by googleapis.

the class DocumentReferenceTest method deleteNestedFieldUsingFieldPath.

@Test
public void deleteNestedFieldUsingFieldPath() throws Exception {
    doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    FieldPath path = FieldPath.of("a.b", "c.d");
    documentReference.update(path, FieldValue.delete()).get();
    CommitRequest expectedCommit = commit(update(Collections.emptyMap(), Collections.singletonList("`a.b`.`c.d`")));
    assertEquals(expectedCommit, commitCapture.getValue());
}
Also used : CommitRequest(com.google.firestore.v1.CommitRequest) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Example 84 with CommitRequest

use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-firestore by googleapis.

the class DocumentReferenceTest method extractFieldMaskFromMerge.

@Test
public void extractFieldMaskFromMerge() throws Exception {
    doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    documentReference.set(NESTED_CLASS_OBJECT, SetOptions.merge()).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());
    List<String> updateMask = Arrays.asList("first.foo", "second.arrayValue", "second.bytesValue", "second.dateValue", "second.doubleValue", "second.falseValue", "second.foo", "second.geoPointValue", "second.infValue", "second.longValue", "second.nanValue", "second.negInfValue", "second.nullValue", "second.objectValue.foo", "second.timestampValue", "second.trueValue", "second.model.foo");
    CommitRequest expectedCommit = commit(set(nestedUpdate, updateMask));
    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 85 with CommitRequest

use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-firestore by googleapis.

the class WriteBatchTest method updateDocumentWithPOJO.

@Test
public void updateDocumentWithPOJO() throws Exception {
    doReturn(commitResponse(1, 0)).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    batch.update(documentReference, "foo", UPDATE_SINGLE_FIELD_OBJECT);
    assertEquals(1, batch.getMutationsSize());
    List<WriteResult> writeResults = batch.commit().get();
    assertEquals(1, writeResults.size());
    CommitRequest actual = commitCapture.getValue();
    CommitRequest expected = commit(update(UPDATED_SINGLE_FIELD_PROTO, Collections.singletonList("foo")));
    assertEquals(expected, actual);
}
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