Search in sources :

Example 1 with ConnectionName

use of com.google.cloud.bigquery.connection.v1.ConnectionName in project java-bigqueryconnection by googleapis.

the class ConnectionServiceClientTest method getConnectionExceptionTest.

@Test
public void getConnectionExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockConnectionService.addException(exception);
    try {
        ConnectionName name = ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]");
        client.getConnection(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : ConnectionName(com.google.cloud.bigquery.connection.v1.ConnectionName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 2 with ConnectionName

use of com.google.cloud.bigquery.connection.v1.ConnectionName in project java-bigqueryconnection by googleapis.

the class ConnectionServiceClientTest method getConnectionTest.

@Test
public void getConnectionTest() throws Exception {
    Connection expectedResponse = Connection.newBuilder().setName(ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]").toString()).setFriendlyName("friendlyName461933014").setDescription("description-1724546052").setCreationTime(1932333101).setLastModifiedTime(-671513446).setHasCredential(true).build();
    mockConnectionService.addResponse(expectedResponse);
    ConnectionName name = ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]");
    Connection actualResponse = client.getConnection(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConnectionService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetConnectionRequest actualRequest = ((GetConnectionRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ConnectionName(com.google.cloud.bigquery.connection.v1.ConnectionName) AbstractMessage(com.google.protobuf.AbstractMessage) Connection(com.google.cloud.bigquery.connection.v1.Connection) GetConnectionRequest(com.google.cloud.bigquery.connection.v1.GetConnectionRequest) Test(org.junit.Test)

Example 3 with ConnectionName

use of com.google.cloud.bigquery.connection.v1.ConnectionName in project java-bigqueryconnection by googleapis.

the class UpdateConnection method updateConnection.

public static void updateConnection(String projectId, String location, String connectionId, Connection connection) throws IOException {
    try (ConnectionServiceClient client = ConnectionServiceClient.create()) {
        ConnectionName name = ConnectionName.of(projectId, location, connectionId);
        FieldMask updateMask = FieldMaskUtil.fromString("description");
        UpdateConnectionRequest request = UpdateConnectionRequest.newBuilder().setName(name.toString()).setConnection(connection).setUpdateMask(updateMask).build();
        Connection response = client.updateConnection(request);
        System.out.println("Connection updated successfully :" + response.getDescription());
    }
}
Also used : ConnectionName(com.google.cloud.bigquery.connection.v1.ConnectionName) ConnectionServiceClient(com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient) UpdateConnectionRequest(com.google.cloud.bigquery.connection.v1.UpdateConnectionRequest) Connection(com.google.cloud.bigquery.connection.v1.Connection) FieldMask(com.google.protobuf.FieldMask)

Example 4 with ConnectionName

use of com.google.cloud.bigquery.connection.v1.ConnectionName in project java-spring-boot-2021 by hocyadav.

the class GoogleBigQueryImpl method getConnection.

public static void getConnection(String projectId, String location, String connectionId) throws IOException {
    try (ConnectionServiceClient client = ConnectionServiceClient.create()) {
        ConnectionName name = ConnectionName.of(projectId, location, connectionId);
        GetConnectionRequest request = GetConnectionRequest.newBuilder().setName(name.toString()).build();
        Connection response = client.getConnection(request);
        System.out.println("Connection info retrieved successfully :" + response.getName());
    }
}
Also used : ConnectionName(com.google.cloud.bigquery.connection.v1.ConnectionName) ConnectionServiceClient(com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient) Connection(com.google.cloud.bigquery.connection.v1.Connection) GetConnectionRequest(com.google.cloud.bigquery.connection.v1.GetConnectionRequest)

Example 5 with ConnectionName

use of com.google.cloud.bigquery.connection.v1.ConnectionName in project java-bigqueryconnection by googleapis.

the class ConnectionServiceClientTest method deleteConnectionExceptionTest.

@Test
public void deleteConnectionExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockConnectionService.addException(exception);
    try {
        ConnectionName name = ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]");
        client.deleteConnection(name);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : ConnectionName(com.google.cloud.bigquery.connection.v1.ConnectionName) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Aggregations

ConnectionName (com.google.cloud.bigquery.connection.v1.ConnectionName)10 Connection (com.google.cloud.bigquery.connection.v1.Connection)6 Test (org.junit.Test)6 ConnectionServiceClient (com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient)4 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)3 DeleteConnectionRequest (com.google.cloud.bigquery.connection.v1.DeleteConnectionRequest)3 GetConnectionRequest (com.google.cloud.bigquery.connection.v1.GetConnectionRequest)3 AbstractMessage (com.google.protobuf.AbstractMessage)3 FieldMask (com.google.protobuf.FieldMask)3 StatusRuntimeException (io.grpc.StatusRuntimeException)3 UpdateConnectionRequest (com.google.cloud.bigquery.connection.v1.UpdateConnectionRequest)2 Empty (com.google.protobuf.Empty)1