Search in sources :

Example 1 with GetIndexRequest

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

the class DatastoreAdminClientTest method getIndexExceptionTest.

@Test
public void getIndexExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDatastoreAdmin.addException(exception);
    try {
        GetIndexRequest request = GetIndexRequest.newBuilder().setProjectId("projectId-894832108").setIndexId("indexId1943291277").build();
        client.getIndex(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) GetIndexRequest(com.google.datastore.admin.v1.GetIndexRequest) Test(org.junit.Test)

Example 2 with GetIndexRequest

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

the class DatastoreAdminClientTest method getIndexTest.

@Test
public void getIndexTest() throws Exception {
    Index expectedResponse = Index.newBuilder().setProjectId("projectId-894832108").setIndexId("indexId1943291277").setKind("kind3292052").addAllProperties(new ArrayList<Index.IndexedProperty>()).build();
    mockDatastoreAdmin.addResponse(expectedResponse);
    GetIndexRequest request = GetIndexRequest.newBuilder().setProjectId("projectId-894832108").setIndexId("indexId1943291277").build();
    Index actualResponse = client.getIndex(request);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDatastoreAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetIndexRequest actualRequest = ((GetIndexRequest) actualRequests.get(0));
    Assert.assertEquals(request.getProjectId(), actualRequest.getProjectId());
    Assert.assertEquals(request.getIndexId(), actualRequest.getIndexId());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) GetIndexRequest(com.google.datastore.admin.v1.GetIndexRequest) Index(com.google.datastore.admin.v1.Index) Test(org.junit.Test)

Example 3 with GetIndexRequest

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

the class FirestoreAdminClientTest method getIndexTest2.

@Test
public void getIndexTest2() throws Exception {
    Index expectedResponse = Index.newBuilder().setName(IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]").toString()).addAllFields(new ArrayList<Index.IndexField>()).build();
    mockFirestoreAdmin.addResponse(expectedResponse);
    String name = "name3373707";
    Index actualResponse = client.getIndex(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockFirestoreAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetIndexRequest actualRequest = ((GetIndexRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) GetIndexRequest(com.google.firestore.admin.v1.GetIndexRequest) Index(com.google.firestore.admin.v1.Index) Test(org.junit.Test)

Example 4 with GetIndexRequest

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

the class FirestoreAdminClientTest method getIndexTest.

@Test
public void getIndexTest() throws Exception {
    Index expectedResponse = Index.newBuilder().setName(IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]").toString()).addAllFields(new ArrayList<Index.IndexField>()).build();
    mockFirestoreAdmin.addResponse(expectedResponse);
    IndexName name = IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]");
    Index actualResponse = client.getIndex(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockFirestoreAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetIndexRequest actualRequest = ((GetIndexRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : IndexName(com.google.firestore.admin.v1.IndexName) AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) GetIndexRequest(com.google.firestore.admin.v1.GetIndexRequest) Index(com.google.firestore.admin.v1.Index) Test(org.junit.Test)

Example 5 with GetIndexRequest

use of com.google.firestore.admin.v1.GetIndexRequest in project grpc-gcp-java by GoogleCloudPlatform.

the class GetIndex method getIndexCall.

public void getIndexCall() {
    System.out.println("\n :: Getting an Index :: \n");
    FirestoreAdminBlockingStub blockingStub = new GRPCFirebaseAdminClientFactory().createFirebaseAdminClient().getBlockingStub();
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter Index Name: ");
    String indexName = "projects/firestoretestclient/databases/(default)/indexes/" + sc.next();
    GetIndexRequest getIndexRequest = GetIndexRequest.newBuilder().setName(indexName).build();
    Index index;
    try {
        index = blockingStub.getIndex(getIndexRequest);
    } catch (Exception e) {
        System.out.println("Error during call: " + e.getMessage() + e.getCause());
        return;
    }
    DrawIndex di = new DrawIndex();
    di.drawIndex(index);
    Menu menu = new Menu();
    menu.draw();
}
Also used : Scanner(java.util.Scanner) FirestoreAdminBlockingStub(com.google.firestore.admin.v1beta1.FirestoreAdminGrpc.FirestoreAdminBlockingStub) DrawIndex(org.roguewave.grpc.util.gfx.DrawIndex) GetIndexRequest(com.google.firestore.admin.v1beta1.GetIndexRequest) Index(com.google.firestore.admin.v1beta1.Index) DrawIndex(org.roguewave.grpc.util.gfx.DrawIndex) Menu(org.roguewave.grpc.util.gfx.Menu) GRPCFirebaseAdminClientFactory(org.roguewave.grpc.util.GRPCFirebaseAdminClientFactory)

Aggregations

Test (org.junit.Test)4 AbstractMessage (com.google.protobuf.AbstractMessage)3 ArrayList (java.util.ArrayList)3 GetIndexRequest (com.google.datastore.admin.v1.GetIndexRequest)2 GetIndexRequest (com.google.firestore.admin.v1.GetIndexRequest)2 Index (com.google.firestore.admin.v1.Index)2 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)1 Index (com.google.datastore.admin.v1.Index)1 IndexName (com.google.firestore.admin.v1.IndexName)1 FirestoreAdminBlockingStub (com.google.firestore.admin.v1beta1.FirestoreAdminGrpc.FirestoreAdminBlockingStub)1 GetIndexRequest (com.google.firestore.admin.v1beta1.GetIndexRequest)1 Index (com.google.firestore.admin.v1beta1.Index)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 Scanner (java.util.Scanner)1 GRPCFirebaseAdminClientFactory (org.roguewave.grpc.util.GRPCFirebaseAdminClientFactory)1 DrawIndex (org.roguewave.grpc.util.gfx.DrawIndex)1 Menu (org.roguewave.grpc.util.gfx.Menu)1