use of com.google.cloud.dialogflow.v2.SessionName in project java-spanner by googleapis.
the class SpannerClientTest method beginTransactionExceptionTest.
@Test
public void beginTransactionExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockSpanner.addException(exception);
try {
SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
TransactionOptions options = TransactionOptions.newBuilder().build();
client.beginTransaction(session, options);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.cloud.dialogflow.v2.SessionName in project java-spanner by googleapis.
the class SpannerClientTest method rollbackExceptionTest.
@Test
public void rollbackExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockSpanner.addException(exception);
try {
SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
ByteString transactionId = ByteString.EMPTY;
client.rollback(session, transactionId);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.cloud.dialogflow.v2.SessionName in project java-spanner by googleapis.
the class SpannerClientTest method deleteSessionExceptionTest.
@Test
public void deleteSessionExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockSpanner.addException(exception);
try {
SessionName name = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
client.deleteSession(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.cloud.dialogflow.v2.SessionName in project java-spanner by googleapis.
the class SpannerClientTest method getSessionTest.
@Test
public void getSessionTest() 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);
SessionName name = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
Session actualResponse = client.getSession(name);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockSpanner.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetSessionRequest actualRequest = ((GetSessionRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.dialogflow.v2.SessionName in project MobileDicomViewer by awholeneworld.
the class MainActivity method setUpBot.
private void setUpBot() {
try {
// json name
InputStream stream = this.getResources().openRawResource(R.raw.dicomviewer);
GoogleCredentials credentials = GoogleCredentials.fromStream(stream).createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform"));
String projectId = ((ServiceAccountCredentials) credentials).getProjectId();
SessionsSettings.Builder settingsBuilder = SessionsSettings.newBuilder();
SessionsSettings sessionsSettings = settingsBuilder.setCredentialsProvider(FixedCredentialsProvider.create(credentials)).build();
sessionsClient = SessionsClient.create(sessionsSettings);
sessionName = SessionName.of(projectId, uuid);
Log.d(TAG, "projectId : " + projectId);
} catch (Exception e) {
Log.d(TAG, "setUpBot: " + e.getMessage());
}
}
Aggregations