Search in sources :

Example 1 with ListDatabasesPagedResponse

use of com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabasesPagedResponse in project java-spanner by googleapis.

the class MockDatabaseAdminServiceImplTest method listDatabases.

@Test
public void listDatabases() {
    createTestDb();
    ListDatabasesPagedResponse response = client.listDatabases(TEST_PARENT);
    List<String> databases = new ArrayList<>();
    for (Database db : response.iterateAll()) {
        databases.add(db.getName());
    }
    assertThat(databases).containsExactly(TEST_DB_NAME);
}
Also used : ListDatabasesPagedResponse(com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabasesPagedResponse) ArrayList(java.util.ArrayList) Database(com.google.spanner.admin.database.v1.Database) Test(org.junit.Test)

Example 2 with ListDatabasesPagedResponse

use of com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabasesPagedResponse in project java-spanner by googleapis.

the class DatabaseAdminClientTest method listDatabasesTest2.

@Test
public void listDatabasesTest2() throws Exception {
    Database responsesElement = Database.newBuilder().build();
    ListDatabasesResponse expectedResponse = ListDatabasesResponse.newBuilder().setNextPageToken("").addAllDatabases(Arrays.asList(responsesElement)).build();
    mockDatabaseAdmin.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListDatabasesPagedResponse pagedListResponse = client.listDatabases(parent);
    List<Database> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getDatabasesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListDatabasesRequest actualRequest = ((ListDatabasesRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListDatabasesPagedResponse(com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabasesPagedResponse) Database(com.google.spanner.admin.database.v1.Database) ByteString(com.google.protobuf.ByteString) ListDatabasesResponse(com.google.spanner.admin.database.v1.ListDatabasesResponse) ListDatabasesRequest(com.google.spanner.admin.database.v1.ListDatabasesRequest) Test(org.junit.Test)

Example 3 with ListDatabasesPagedResponse

use of com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabasesPagedResponse in project java-spanner by googleapis.

the class DatabaseAdminClientTest method listDatabasesTest.

@Test
public void listDatabasesTest() throws Exception {
    Database responsesElement = Database.newBuilder().build();
    ListDatabasesResponse expectedResponse = ListDatabasesResponse.newBuilder().setNextPageToken("").addAllDatabases(Arrays.asList(responsesElement)).build();
    mockDatabaseAdmin.addResponse(expectedResponse);
    InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
    ListDatabasesPagedResponse pagedListResponse = client.listDatabases(parent);
    List<Database> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getDatabasesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListDatabasesRequest actualRequest = ((ListDatabasesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : InstanceName(com.google.spanner.admin.database.v1.InstanceName) AbstractMessage(com.google.protobuf.AbstractMessage) ListDatabasesPagedResponse(com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabasesPagedResponse) Database(com.google.spanner.admin.database.v1.Database) ListDatabasesResponse(com.google.spanner.admin.database.v1.ListDatabasesResponse) ListDatabasesRequest(com.google.spanner.admin.database.v1.ListDatabasesRequest) Test(org.junit.Test)

Aggregations

ListDatabasesPagedResponse (com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabasesPagedResponse)3 Database (com.google.spanner.admin.database.v1.Database)3 Test (org.junit.Test)3 AbstractMessage (com.google.protobuf.AbstractMessage)2 ListDatabasesRequest (com.google.spanner.admin.database.v1.ListDatabasesRequest)2 ListDatabasesResponse (com.google.spanner.admin.database.v1.ListDatabasesResponse)2 ByteString (com.google.protobuf.ByteString)1 InstanceName (com.google.spanner.admin.database.v1.InstanceName)1 ArrayList (java.util.ArrayList)1