use of com.google.firestore.admin.v1.DatabaseName in project java-spanner by googleapis.
the class SpannerClientTest method createSessionTest.
@Test
public void createSessionTest() throws Exception {
Session expectedResponse = Session.newBuilder().setName(SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString()).putAllLabels(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).setApproximateLastUseTime(Timestamp.newBuilder().build()).build();
mockSpanner.addResponse(expectedResponse);
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
Session actualResponse = client.createSession(database);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockSpanner.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateSessionRequest actualRequest = ((CreateSessionRequest) actualRequests.get(0));
Assert.assertEquals(database.toString(), actualRequest.getDatabase());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.firestore.admin.v1.DatabaseName in project java-spanner by googleapis.
the class SpannerClientTest method listSessionsExceptionTest.
@Test
public void listSessionsExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockSpanner.addException(exception);
try {
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
client.listSessions(database);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.firestore.admin.v1.DatabaseName in project java-spanner by googleapis.
the class SpannerClientTest method listSessionsTest.
@Test
public void listSessionsTest() throws Exception {
Session responsesElement = Session.newBuilder().build();
ListSessionsResponse expectedResponse = ListSessionsResponse.newBuilder().setNextPageToken("").addAllSessions(Arrays.asList(responsesElement)).build();
mockSpanner.addResponse(expectedResponse);
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
ListSessionsPagedResponse pagedListResponse = client.listSessions(database);
List<Session> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getSessionsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockSpanner.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListSessionsRequest actualRequest = ((ListSessionsRequest) actualRequests.get(0));
Assert.assertEquals(database.toString(), actualRequest.getDatabase());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.firestore.admin.v1.DatabaseName in project java-firestore by googleapis.
the class FirestoreAdminClientTest method exportDocumentsTest.
@Test
public void exportDocumentsTest() throws Exception {
ExportDocumentsResponse expectedResponse = ExportDocumentsResponse.newBuilder().setOutputUriPrefix("outputUriPrefix499858205").build();
Operation resultOperation = Operation.newBuilder().setName("exportDocumentsTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
mockFirestoreAdmin.addResponse(resultOperation);
DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
ExportDocumentsResponse actualResponse = client.exportDocumentsAsync(name).get();
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockFirestoreAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
ExportDocumentsRequest actualRequest = ((ExportDocumentsRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.firestore.admin.v1.DatabaseName in project java-spanner by googleapis.
the class DatabaseAdminGaxTest method getDatabaseTest.
@Test
public void getDatabaseTest() {
Exception exception = setupException();
DatabaseName name2 = DatabaseName.of(PROJECT, INSTANCE, "DATABASE");
com.google.spanner.admin.database.v1.Database expectedResponse = com.google.spanner.admin.database.v1.Database.newBuilder().setName(name2.toString()).build();
if (exceptionAtCall == 0) {
mockDatabaseAdmin.addException(exception);
}
mockDatabaseAdmin.addResponse(expectedResponse);
if (exceptionAtCall == 1) {
mockDatabaseAdmin.addException(exception);
}
mockDatabaseAdmin.addResponse(expectedResponse);
for (int i = 0; i < 2; i++) {
Database actualResponse = client.getDatabase(INSTANCE, "DATABASE");
Assert.assertEquals(name2.toString(), actualResponse.getId().getName());
}
List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
Assert.assertEquals(2, actualRequests.size());
}
Aggregations