Search in sources :

Example 21 with SessionName

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.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) TransactionOptions(com.google.spanner.v1.TransactionOptions) StatusRuntimeException(io.grpc.StatusRuntimeException) SessionName(com.google.spanner.v1.SessionName) Test(org.junit.Test)

Example 22 with SessionName

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.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ByteString(com.google.protobuf.ByteString) StatusRuntimeException(io.grpc.StatusRuntimeException) SessionName(com.google.spanner.v1.SessionName) Test(org.junit.Test)

Example 23 with SessionName

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.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) SessionName(com.google.spanner.v1.SessionName) Test(org.junit.Test)

Example 24 with SessionName

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()));
}
Also used : GetSessionRequest(com.google.spanner.v1.GetSessionRequest) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) SessionName(com.google.spanner.v1.SessionName) Session(com.google.spanner.v1.Session) Test(org.junit.Test)

Example 25 with SessionName

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());
    }
}
Also used : InputStream(java.io.InputStream) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) SessionsSettings(com.google.cloud.dialogflow.v2.SessionsSettings) ServiceAccountCredentials(com.google.auth.oauth2.ServiceAccountCredentials)

Aggregations

Test (org.junit.Test)14 SessionName (com.google.spanner.v1.SessionName)12 AbstractMessage (com.google.protobuf.AbstractMessage)8 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)6 QueryInput (com.google.cloud.dialogflow.v2.QueryInput)6 StatusRuntimeException (io.grpc.StatusRuntimeException)6 QueryResult (com.google.cloud.dialogflow.v2.QueryResult)5 SessionName (com.google.cloud.dialogflow.v2.SessionName)5 SessionsClient (com.google.cloud.dialogflow.v2.SessionsClient)5 DetectIntentResponse (com.google.cloud.dialogflow.v2.DetectIntentResponse)4 ByteString (com.google.protobuf.ByteString)4 Mutation (com.google.spanner.v1.Mutation)4 TransactionOptions (com.google.spanner.v1.TransactionOptions)4 DetectIntentRequest (com.google.cloud.dialogflow.v2.DetectIntentRequest)3 TextInput (com.google.cloud.dialogflow.v2.TextInput)3 ArrayList (java.util.ArrayList)3 QueryInput (com.google.cloud.dialogflow.cx.v3beta1.QueryInput)2 QueryResult (com.google.cloud.dialogflow.cx.v3beta1.QueryResult)2 SessionName (com.google.cloud.dialogflow.cx.v3beta1.SessionName)2 SessionsClient (com.google.cloud.dialogflow.cx.v3beta1.SessionsClient)2