Search in sources :

Example 1 with CollectionGroupName

use of com.google.firestore.admin.v1.CollectionGroupName in project java-firestore by googleapis.

the class FirestoreAdminClientTest method createIndexExceptionTest.

@Test
public void createIndexExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockFirestoreAdmin.addException(exception);
    try {
        CollectionGroupName parent = CollectionGroupName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]");
        Index index = Index.newBuilder().build();
        client.createIndexAsync(parent, index).get();
        Assert.fail("No exception raised");
    } catch (ExecutionException e) {
        Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
        InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
        Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Index(com.google.firestore.admin.v1.Index) CollectionGroupName(com.google.firestore.admin.v1.CollectionGroupName) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 2 with CollectionGroupName

use of com.google.firestore.admin.v1.CollectionGroupName in project java-firestore by googleapis.

the class FirestoreAdminClientTest method listFieldsExceptionTest.

@Test
public void listFieldsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockFirestoreAdmin.addException(exception);
    try {
        CollectionGroupName parent = CollectionGroupName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]");
        client.listFields(parent);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) CollectionGroupName(com.google.firestore.admin.v1.CollectionGroupName) Test(org.junit.Test)

Example 3 with CollectionGroupName

use of com.google.firestore.admin.v1.CollectionGroupName in project java-firestore by googleapis.

the class FirestoreAdminClientTest method listIndexesTest.

@Test
public void listIndexesTest() throws Exception {
    Index responsesElement = Index.newBuilder().build();
    ListIndexesResponse expectedResponse = ListIndexesResponse.newBuilder().setNextPageToken("").addAllIndexes(Arrays.asList(responsesElement)).build();
    mockFirestoreAdmin.addResponse(expectedResponse);
    CollectionGroupName parent = CollectionGroupName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]");
    ListIndexesPagedResponse pagedListResponse = client.listIndexes(parent);
    List<Index> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getIndexesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockFirestoreAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListIndexesRequest actualRequest = ((ListIndexesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListIndexesResponse(com.google.firestore.admin.v1.ListIndexesResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Index(com.google.firestore.admin.v1.Index) CollectionGroupName(com.google.firestore.admin.v1.CollectionGroupName) ListIndexesRequest(com.google.firestore.admin.v1.ListIndexesRequest) ListIndexesPagedResponse(com.google.cloud.firestore.v1.FirestoreAdminClient.ListIndexesPagedResponse) Test(org.junit.Test)

Example 4 with CollectionGroupName

use of com.google.firestore.admin.v1.CollectionGroupName in project java-firestore by googleapis.

the class FirestoreAdminClientTest method createIndexTest.

@Test
public void createIndexTest() throws Exception {
    Index expectedResponse = Index.newBuilder().setName(IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]").toString()).addAllFields(new ArrayList<Index.IndexField>()).build();
    Operation resultOperation = Operation.newBuilder().setName("createIndexTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockFirestoreAdmin.addResponse(resultOperation);
    CollectionGroupName parent = CollectionGroupName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]");
    Index index = Index.newBuilder().build();
    Index actualResponse = client.createIndexAsync(parent, index).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockFirestoreAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateIndexRequest actualRequest = ((CreateIndexRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(index, actualRequest.getIndex());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) Index(com.google.firestore.admin.v1.Index) Operation(com.google.longrunning.Operation) CollectionGroupName(com.google.firestore.admin.v1.CollectionGroupName) CreateIndexRequest(com.google.firestore.admin.v1.CreateIndexRequest) Test(org.junit.Test)

Example 5 with CollectionGroupName

use of com.google.firestore.admin.v1.CollectionGroupName in project java-firestore by googleapis.

the class FirestoreAdminClientTest method listFieldsTest.

@Test
public void listFieldsTest() throws Exception {
    Field responsesElement = Field.newBuilder().build();
    ListFieldsResponse expectedResponse = ListFieldsResponse.newBuilder().setNextPageToken("").addAllFields(Arrays.asList(responsesElement)).build();
    mockFirestoreAdmin.addResponse(expectedResponse);
    CollectionGroupName parent = CollectionGroupName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]");
    ListFieldsPagedResponse pagedListResponse = client.listFields(parent);
    List<Field> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getFieldsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockFirestoreAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListFieldsRequest actualRequest = ((ListFieldsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Field(com.google.firestore.admin.v1.Field) ListFieldsPagedResponse(com.google.cloud.firestore.v1.FirestoreAdminClient.ListFieldsPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ListFieldsResponse(com.google.firestore.admin.v1.ListFieldsResponse) ListFieldsRequest(com.google.firestore.admin.v1.ListFieldsRequest) CollectionGroupName(com.google.firestore.admin.v1.CollectionGroupName) Test(org.junit.Test)

Aggregations

CollectionGroupName (com.google.firestore.admin.v1.CollectionGroupName)6 Test (org.junit.Test)6 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)3 Index (com.google.firestore.admin.v1.Index)3 AbstractMessage (com.google.protobuf.AbstractMessage)3 StatusRuntimeException (io.grpc.StatusRuntimeException)3 ListFieldsPagedResponse (com.google.cloud.firestore.v1.FirestoreAdminClient.ListFieldsPagedResponse)1 ListIndexesPagedResponse (com.google.cloud.firestore.v1.FirestoreAdminClient.ListIndexesPagedResponse)1 CreateIndexRequest (com.google.firestore.admin.v1.CreateIndexRequest)1 Field (com.google.firestore.admin.v1.Field)1 ListFieldsRequest (com.google.firestore.admin.v1.ListFieldsRequest)1 ListFieldsResponse (com.google.firestore.admin.v1.ListFieldsResponse)1 ListIndexesRequest (com.google.firestore.admin.v1.ListIndexesRequest)1 ListIndexesResponse (com.google.firestore.admin.v1.ListIndexesResponse)1 Operation (com.google.longrunning.Operation)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1