Search in sources :

Example 1 with SessionName

use of com.google.cloud.dialogflow.v2.SessionName in project java-spanner by googleapis.

the class SpannerClientTest method getSessionExceptionTest.

@Test
public void getSessionExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockSpanner.addException(exception);
    try {
        SessionName name = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
        client.getSession(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 2 with SessionName

use of com.google.cloud.dialogflow.v2.SessionName in project java-spanner by googleapis.

the class SpannerClientTest method deleteSessionTest.

@Test
public void deleteSessionTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockSpanner.addResponse(expectedResponse);
    SessionName name = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
    client.deleteSession(name);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteSessionRequest actualRequest = ((DeleteSessionRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) DeleteSessionRequest(com.google.spanner.v1.DeleteSessionRequest) AbstractMessage(com.google.protobuf.AbstractMessage) SessionName(com.google.spanner.v1.SessionName) Test(org.junit.Test)

Example 3 with SessionName

use of com.google.cloud.dialogflow.v2.SessionName in project java-spanner by googleapis.

the class SpannerClientTest method beginTransactionTest.

@Test
public void beginTransactionTest() throws Exception {
    Transaction expectedResponse = Transaction.newBuilder().setId(ByteString.EMPTY).setReadTimestamp(Timestamp.newBuilder().build()).build();
    mockSpanner.addResponse(expectedResponse);
    SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
    TransactionOptions options = TransactionOptions.newBuilder().build();
    Transaction actualResponse = client.beginTransaction(session, options);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    BeginTransactionRequest actualRequest = ((BeginTransactionRequest) actualRequests.get(0));
    Assert.assertEquals(session.toString(), actualRequest.getSession());
    Assert.assertEquals(options, actualRequest.getOptions());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Transaction(com.google.spanner.v1.Transaction) TransactionOptions(com.google.spanner.v1.TransactionOptions) BeginTransactionRequest(com.google.spanner.v1.BeginTransactionRequest) SessionName(com.google.spanner.v1.SessionName) Test(org.junit.Test)

Example 4 with SessionName

use of com.google.cloud.dialogflow.v2.SessionName in project java-spanner by googleapis.

the class SpannerClientTest method rollbackTest.

@Test
public void rollbackTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockSpanner.addResponse(expectedResponse);
    SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
    ByteString transactionId = ByteString.EMPTY;
    client.rollback(session, transactionId);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    RollbackRequest actualRequest = ((RollbackRequest) actualRequests.get(0));
    Assert.assertEquals(session.toString(), actualRequest.getSession());
    Assert.assertEquals(transactionId, actualRequest.getTransactionId());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) ByteString(com.google.protobuf.ByteString) RollbackRequest(com.google.spanner.v1.RollbackRequest) SessionName(com.google.spanner.v1.SessionName) Test(org.junit.Test)

Example 5 with SessionName

use of com.google.cloud.dialogflow.v2.SessionName in project java-spanner by googleapis.

the class SpannerClientTest method commitTest2.

@Test
public void commitTest2() throws Exception {
    CommitResponse expectedResponse = CommitResponse.newBuilder().setCommitTimestamp(Timestamp.newBuilder().build()).setCommitStats(CommitResponse.CommitStats.newBuilder().build()).build();
    mockSpanner.addResponse(expectedResponse);
    SessionName session = SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]");
    TransactionOptions singleUseTransaction = TransactionOptions.newBuilder().build();
    List<Mutation> mutations = new ArrayList<>();
    CommitResponse actualResponse = client.commit(session, singleUseTransaction, mutations);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CommitRequest actualRequest = ((CommitRequest) actualRequests.get(0));
    Assert.assertEquals(session.toString(), actualRequest.getSession());
    Assert.assertEquals(singleUseTransaction, actualRequest.getSingleUseTransaction());
    Assert.assertEquals(mutations, actualRequest.getMutationsList());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : CommitRequest(com.google.spanner.v1.CommitRequest) AbstractMessage(com.google.protobuf.AbstractMessage) TransactionOptions(com.google.spanner.v1.TransactionOptions) ArrayList(java.util.ArrayList) CommitResponse(com.google.spanner.v1.CommitResponse) Mutation(com.google.spanner.v1.Mutation) SessionName(com.google.spanner.v1.SessionName) 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 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