Search in sources :

Example 1 with ListBackupsPagedResponse

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

the class DatabaseAdminClientTest method listBackupsTest2.

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

Example 2 with ListBackupsPagedResponse

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

the class MockDatabaseAdminServiceImplTest method listBackups.

@Test
public void listBackups() {
    createTestDb();
    createTestBackup();
    ListBackupsPagedResponse response = client.listBackups(TEST_PARENT);
    List<String> backups = new ArrayList<>();
    for (Backup bck : response.iterateAll()) {
        backups.add(bck.getName());
    }
    assertThat(backups).containsExactly(TEST_BCK_NAME);
}
Also used : Backup(com.google.spanner.admin.database.v1.Backup) ArrayList(java.util.ArrayList) ListBackupsPagedResponse(com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupsPagedResponse) Test(org.junit.Test)

Example 3 with ListBackupsPagedResponse

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

the class DatabaseAdminClientTest method listBackupsTest.

@Test
public void listBackupsTest() throws Exception {
    Backup responsesElement = Backup.newBuilder().build();
    ListBackupsResponse expectedResponse = ListBackupsResponse.newBuilder().setNextPageToken("").addAllBackups(Arrays.asList(responsesElement)).build();
    mockDatabaseAdmin.addResponse(expectedResponse);
    InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
    ListBackupsPagedResponse pagedListResponse = client.listBackups(parent);
    List<Backup> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getBackupsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListBackupsRequest actualRequest = ((ListBackupsRequest) 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) Backup(com.google.spanner.admin.database.v1.Backup) ListBackupsRequest(com.google.spanner.admin.database.v1.ListBackupsRequest) ListBackupsResponse(com.google.spanner.admin.database.v1.ListBackupsResponse) ListBackupsPagedResponse(com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupsPagedResponse) Test(org.junit.Test)

Aggregations

ListBackupsPagedResponse (com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListBackupsPagedResponse)3 Backup (com.google.spanner.admin.database.v1.Backup)3 Test (org.junit.Test)3 AbstractMessage (com.google.protobuf.AbstractMessage)2 ListBackupsRequest (com.google.spanner.admin.database.v1.ListBackupsRequest)2 ListBackupsResponse (com.google.spanner.admin.database.v1.ListBackupsResponse)2 ByteString (com.google.protobuf.ByteString)1 InstanceName (com.google.spanner.admin.database.v1.InstanceName)1 ArrayList (java.util.ArrayList)1