Search in sources :

Example 21 with Value

use of com.google.api.ads.admanager.jaxws.v202205.Value in project java-firestore by googleapis.

the class DocumentReferenceTest method updateNestedDocument.

@Test
public void updateNestedDocument() throws Exception {
    doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    Map<String, Object> nestedObject = new HashMap<>();
    nestedObject.put("a", "b");
    nestedObject.put("c.d", "e");
    nestedObject.put("f.g.h", "i");
    Map<String, Value> expandedObject = new HashMap<>();
    expandedObject.put("a", string("b"));
    expandedObject.put("c", object("d", string("e")));
    expandedObject.put("f", object("g", object("h", string("i"))));
    documentReference.update(nestedObject).get();
    CommitRequest expectedCommit = commit(update(expandedObject, new ArrayList<>(nestedObject.keySet())));
    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) ArrayList(java.util.ArrayList) CommitResponse(com.google.firestore.v1.CommitResponse) Test(org.junit.Test)

Example 22 with Value

use of com.google.api.ads.admanager.jaxws.v202205.Value in project java-firestore by googleapis.

the class DocumentReferenceTest method updateNestedMap.

@Test
public void updateNestedMap() throws Exception {
    doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    documentReference.update("a.b", "foo", "a.c", FieldValue.delete()).get();
    Map<String, Value> nestedUpdate = new HashMap<>();
    Value.Builder valueProto = Value.newBuilder();
    valueProto.getMapValueBuilder().putFields("b", Value.newBuilder().setStringValue("foo").build());
    nestedUpdate.put("a", valueProto.build());
    CommitRequest expectedCommit = commit(update(nestedUpdate, Arrays.asList("a.b", "a.c")));
    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 23 with Value

use of com.google.api.ads.admanager.jaxws.v202205.Value in project java-firestore by googleapis.

the class DocumentReferenceTest method deserializeCustomList.

@Test
public void deserializeCustomList() throws ExecutionException, InterruptedException {
    ImmutableMap CUSTOM_LIST_PROTO = ImmutableMap.<String, Value>builder().put("fooList", Value.newBuilder().setArrayValue(ArrayValue.newBuilder().addValues(Value.newBuilder().setMapValue(MapValue.newBuilder().putAllFields(SINGLE_FIELD_PROTO)).build())).build()).build();
    doAnswer(getAllResponse(CUSTOM_LIST_PROTO)).when(firestoreMock).streamRequest(getAllCapture.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any());
    DocumentSnapshot snapshot = documentReference.get().get();
    LocalFirestoreHelper.CustomList customList = snapshot.toObject(LocalFirestoreHelper.CustomList.class);
    assertEquals(FOO_LIST, customList.fooList);
    assertEquals(SINGLE_FIELD_OBJECT, customList.fooList.get(0));
}
Also used : Value(com.google.firestore.v1.Value) MapValue(com.google.firestore.v1.MapValue) ArrayValue(com.google.firestore.v1.ArrayValue) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 24 with Value

use of com.google.api.ads.admanager.jaxws.v202205.Value in project java-firestore by googleapis.

the class DocumentReferenceTest method deleteField.

@Test
public void deleteField() throws Exception {
    doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    documentReference.update("foo", "bar", "bar.foo", FieldValue.delete()).get();
    Value.Builder emptyMap = Value.newBuilder();
    emptyMap.getMapValueBuilder();
    Map<String, Value> fieldMap = new HashMap<>();
    fieldMap.put("foo", string("bar"));
    CommitRequest expectedCommit = commit(update(fieldMap, Arrays.asList("foo", "bar.foo")));
    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 25 with Value

use of com.google.api.ads.admanager.jaxws.v202205.Value in project java-firestore by googleapis.

the class DocumentReferenceTest method updateWithDotsInFieldName.

@Test
public void updateWithDotsInFieldName() throws Exception {
    doReturn(SINGLE_WRITE_COMMIT_RESPONSE).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
    documentReference.update(map("a.b.c", map("d.e", "foo"))).get();
    Map<String, Value> nestedUpdate = new HashMap<>();
    Value.Builder valueProto = Value.newBuilder();
    valueProto.getMapValueBuilder().putFields("d.e", Value.newBuilder().setStringValue("foo").build());
    Value.Builder cProto = Value.newBuilder();
    cProto.getMapValueBuilder().putFields("c", valueProto.build());
    Value.Builder bProto = Value.newBuilder();
    bProto.getMapValueBuilder().putFields("b", cProto.build());
    nestedUpdate.put("a", bProto.build());
    CommitRequest expectedCommit = commit(update(nestedUpdate, Arrays.asList("a.b.c")));
    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)

Aggregations

Test (org.junit.Test)126 Value (com.google.firestore.v1.Value)108 ArrayValue (com.google.firestore.v1.ArrayValue)73 LinkedHashSet (java.util.LinkedHashSet)71 ObjectValue (com.google.firebase.firestore.model.ObjectValue)53 NullValue (com.google.protobuf.NullValue)50 MapValue (com.google.firestore.v1.MapValue)47 ArrayList (java.util.ArrayList)30 HashMap (java.util.HashMap)24 Value (com.google.datastore.v1.Value)20 Map (java.util.Map)19 TableFieldSchema (com.google.api.services.bigquery.model.TableFieldSchema)17 List (java.util.List)17 Record (org.apache.avro.generic.GenericData.Record)16 SchemaAndRecord (org.apache.beam.sdk.io.gcp.bigquery.SchemaAndRecord)16 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)16 Set (java.util.Set)14 TestUtil.wrapObject (com.google.firebase.firestore.testutil.TestUtil.wrapObject)13 Nullable (androidx.annotation.Nullable)10 Value (com.google.privacy.dlp.v2.Value)9