Search in sources :

Example 21 with SessionName

use of com.google.cloud.dialogflow.v2beta1.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 22 with SessionName

use of com.google.cloud.dialogflow.v2beta1.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 23 with SessionName

use of com.google.cloud.dialogflow.v2beta1.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)

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 StatusRuntimeException (io.grpc.StatusRuntimeException)6 QueryInput (com.google.cloud.dialogflow.v2.QueryInput)5 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 ArrayList (java.util.ArrayList)4 DetectIntentRequest (com.google.cloud.dialogflow.v2.DetectIntentRequest)3 TextInput (com.google.cloud.dialogflow.v2.TextInput)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