Search in sources :

Example 16 with Target

use of com.google.firestore.v1.Target in project firebase-android-sdk by firebase.

the class RemoteSerializerTest method testEncodesReadTime.

@Test
public void testEncodesReadTime() {
    Query q = Query.atPath(ResourcePath.fromString("docs"));
    TargetData targetData = new TargetData(q.toTarget(), 1, 2, QueryPurpose.LISTEN).withResumeToken(ByteString.EMPTY, version(4000000));
    Target actual = serializer.encodeTarget(targetData);
    StructuredQuery.Builder structuredQueryBuilder = StructuredQuery.newBuilder().addFrom(CollectionSelector.newBuilder().setCollectionId("docs")).addOrderBy(defaultKeyOrder());
    QueryTarget.Builder queryBuilder = QueryTarget.newBuilder().setParent("projects/p/databases/d/documents").setStructuredQuery(structuredQueryBuilder);
    Target expected = Target.newBuilder().setQuery(queryBuilder).setTargetId(1).setReadTime(Timestamp.newBuilder().setSeconds(4)).build();
    assertEquals(expected, actual);
    assertEquals(serializer.decodeQueryTarget(serializer.encodeQueryTarget(q.toTarget())), q.toTarget());
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) StructuredQuery(com.google.firestore.v1.StructuredQuery) QueryTarget(com.google.firestore.v1.Target.QueryTarget) DocumentsTarget(com.google.firestore.v1.Target.DocumentsTarget) Target(com.google.firestore.v1.Target) QueryTarget(com.google.firestore.v1.Target.QueryTarget) StructuredQuery(com.google.firestore.v1.StructuredQuery) Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 17 with Target

use of com.google.firestore.v1.Target in project firebase-android-sdk by firebase.

the class RemoteSerializerTest method testEncodesSortOrdersDescending.

@Test
public void testEncodesSortOrdersDescending() {
    Query q = Query.atPath(ResourcePath.fromString("rooms/1/messages/10/attachments")).orderBy(orderBy("prop", "desc"));
    Target actual = serializer.encodeTarget(wrapTargetData(q));
    StructuredQuery.Builder structuredQueryBuilder = StructuredQuery.newBuilder().addFrom(CollectionSelector.newBuilder().setCollectionId("attachments")).addOrderBy(Order.newBuilder().setDirection(Direction.DESCENDING).setField(FieldReference.newBuilder().setFieldPath("prop"))).addOrderBy(Order.newBuilder().setDirection(Direction.DESCENDING).setField(FieldReference.newBuilder().setFieldPath(DocumentKey.KEY_FIELD_NAME)));
    QueryTarget.Builder queryBuilder = QueryTarget.newBuilder().setParent("projects/p/databases/d/documents/rooms/1/messages/10").setStructuredQuery(structuredQueryBuilder);
    Target expected = Target.newBuilder().setQuery(queryBuilder).setTargetId(1).setResumeToken(ByteString.EMPTY).build();
    assertEquals(expected, actual);
    assertEquals(serializer.decodeQueryTarget(serializer.encodeQueryTarget(q.toTarget())), q.toTarget());
}
Also used : StructuredQuery(com.google.firestore.v1.StructuredQuery) QueryTarget(com.google.firestore.v1.Target.QueryTarget) DocumentsTarget(com.google.firestore.v1.Target.DocumentsTarget) Target(com.google.firestore.v1.Target) QueryTarget(com.google.firestore.v1.Target.QueryTarget) StructuredQuery(com.google.firestore.v1.StructuredQuery) Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 18 with Target

use of com.google.firestore.v1.Target in project firebase-android-sdk by firebase.

the class RemoteSerializerTest method testEncodesSingleFilterAtFirstLevelCollections.

@Test
public void testEncodesSingleFilterAtFirstLevelCollections() {
    Query q = Query.atPath(ResourcePath.fromString("docs")).filter(filter("prop", "<", 42));
    Target actual = serializer.encodeTarget(wrapTargetData(q));
    StructuredQuery.Builder structuredQueryBuilder = StructuredQuery.newBuilder().addFrom(CollectionSelector.newBuilder().setCollectionId("docs")).setWhere(Filter.newBuilder().setFieldFilter(StructuredQuery.FieldFilter.newBuilder().setField(FieldReference.newBuilder().setFieldPath("prop")).setOp(Operator.LESS_THAN).setValue(Value.newBuilder().setIntegerValue(42)))).addOrderBy(Order.newBuilder().setField(FieldReference.newBuilder().setFieldPath("prop")).setDirection(Direction.ASCENDING)).addOrderBy(defaultKeyOrder());
    QueryTarget.Builder queryBuilder = QueryTarget.newBuilder().setParent("projects/p/databases/d/documents").setStructuredQuery(structuredQueryBuilder);
    Target expected = Target.newBuilder().setQuery(queryBuilder).setTargetId(1).setResumeToken(ByteString.EMPTY).build();
    assertEquals(expected, actual);
    assertEquals(serializer.decodeQueryTarget(serializer.encodeQueryTarget(q.toTarget())), q.toTarget());
}
Also used : StructuredQuery(com.google.firestore.v1.StructuredQuery) QueryTarget(com.google.firestore.v1.Target.QueryTarget) DocumentsTarget(com.google.firestore.v1.Target.DocumentsTarget) Target(com.google.firestore.v1.Target) QueryTarget(com.google.firestore.v1.Target.QueryTarget) StructuredQuery(com.google.firestore.v1.StructuredQuery) Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 19 with Target

use of com.google.firestore.v1.Target in project firebase-android-sdk by firebase.

the class RemoteSerializerTest method testEncodesBounds.

@Test
public void testEncodesBounds() {
    Query q = Query.atPath(ResourcePath.fromString("docs")).startAt(bound(/* inclusive= */
    true, refValue(databaseId, key("foo/bar")))).endAt(bound(/* inclusive= */
    true, refValue(databaseId, key("foo/baz"))));
    Target actual = serializer.encodeTarget(wrapTargetData(q));
    StructuredQuery.Builder structuredQueryBuilder = StructuredQuery.newBuilder().addFrom(CollectionSelector.newBuilder().setCollectionId("docs")).addOrderBy(defaultKeyOrder()).setStartAt(Cursor.newBuilder().setBefore(true).addValues(Value.newBuilder().setReferenceValue("projects/p/databases/d/documents/foo/bar"))).setEndAt(Cursor.newBuilder().setBefore(false).addValues(Value.newBuilder().setReferenceValue("projects/p/databases/d/documents/foo/baz")));
    QueryTarget.Builder queryBuilder = QueryTarget.newBuilder().setParent("projects/p/databases/d/documents").setStructuredQuery(structuredQueryBuilder);
    Target expected = Target.newBuilder().setQuery(queryBuilder).setTargetId(1).setResumeToken(ByteString.EMPTY).build();
    assertEquals(expected, actual);
    assertEquals(serializer.decodeQueryTarget(serializer.encodeQueryTarget(q.toTarget())), q.toTarget());
}
Also used : StructuredQuery(com.google.firestore.v1.StructuredQuery) QueryTarget(com.google.firestore.v1.Target.QueryTarget) DocumentsTarget(com.google.firestore.v1.Target.DocumentsTarget) Target(com.google.firestore.v1.Target) QueryTarget(com.google.firestore.v1.Target.QueryTarget) StructuredQuery(com.google.firestore.v1.StructuredQuery) Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 20 with Target

use of com.google.firestore.v1.Target in project firebase-android-sdk by firebase.

the class RemoteSerializerTest method testEncodesNestedAncestorQueries.

@Test
public void testEncodesNestedAncestorQueries() {
    Query q = Query.atPath(ResourcePath.fromString("rooms/1/messages/10/attachments"));
    Target actual = serializer.encodeTarget(wrapTargetData(q));
    StructuredQuery.Builder structuredQueryBuilder = StructuredQuery.newBuilder().addFrom(CollectionSelector.newBuilder().setCollectionId("attachments")).addOrderBy(defaultKeyOrder());
    QueryTarget queryBuilder = QueryTarget.newBuilder().setParent("projects/p/databases/d/documents/rooms/1/messages/10").setStructuredQuery(structuredQueryBuilder).build();
    Target expected = Target.newBuilder().setQuery(queryBuilder).setTargetId(1).setResumeToken(ByteString.EMPTY).build();
    assertEquals(expected, actual);
    assertEquals(serializer.decodeQueryTarget(serializer.encodeQueryTarget(q.toTarget())), q.toTarget());
}
Also used : StructuredQuery(com.google.firestore.v1.StructuredQuery) QueryTarget(com.google.firestore.v1.Target.QueryTarget) DocumentsTarget(com.google.firestore.v1.Target.DocumentsTarget) Target(com.google.firestore.v1.Target) QueryTarget(com.google.firestore.v1.Target.QueryTarget) StructuredQuery(com.google.firestore.v1.StructuredQuery) Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Aggregations

StructuredQuery (com.google.firestore.v1.StructuredQuery)14 QueryTarget (com.google.firestore.v1.Target.QueryTarget)14 Test (org.junit.Test)14 Query (com.google.firebase.firestore.core.Query)13 Target (com.google.firestore.v1.Target)13 DocumentsTarget (com.google.firestore.v1.Target.DocumentsTarget)13 FieldIndex (com.google.firebase.firestore.model.FieldIndex)4 Value (com.google.firestore.v1.Value)4 TargetData (com.google.firebase.firestore.local.TargetData)3 Nullable (androidx.annotation.Nullable)2 Target (com.github.zhenwei.core.asn1.x509.Target)2 TargetInformation (com.github.zhenwei.core.asn1.x509.TargetInformation)2 Targets (com.github.zhenwei.core.asn1.x509.Targets)2 DocumentKey (com.google.firebase.firestore.model.DocumentKey)2 Status (io.grpc.Status)2 ArrayList (java.util.ArrayList)2 ASN1InputStream (com.github.zhenwei.core.asn1.ASN1InputStream)1 DEROctetString (com.github.zhenwei.core.asn1.DEROctetString)1 Extension (com.github.zhenwei.core.asn1.x509.Extension)1 X509AttributeCertificateHolder (com.github.zhenwei.pkix.cert.X509AttributeCertificateHolder)1