use of com.google.spanner.admin.instance.v1.InstanceName in project java-spanner by googleapis.
the class DatabaseAdminClientTest method listDatabaseOperationsTest.
@Test
public void listDatabaseOperationsTest() throws Exception {
Operation responsesElement = Operation.newBuilder().build();
ListDatabaseOperationsResponse expectedResponse = ListDatabaseOperationsResponse.newBuilder().setNextPageToken("").addAllOperations(Arrays.asList(responsesElement)).build();
mockDatabaseAdmin.addResponse(expectedResponse);
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
ListDatabaseOperationsPagedResponse pagedListResponse = client.listDatabaseOperations(parent);
List<Operation> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getOperationsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListDatabaseOperationsRequest actualRequest = ((ListDatabaseOperationsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.admin.instance.v1.InstanceName 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()));
}
use of com.google.spanner.admin.instance.v1.InstanceName in project java-spanner by googleapis.
the class InstanceAdminClientTest method getInstanceExceptionTest.
@Test
public void getInstanceExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockInstanceAdmin.addException(exception);
try {
InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
client.getInstance(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
Aggregations