Search in sources :

Example 1 with UpdateConnectionRequest

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

the class ConnectionServiceClientTest method updateConnectionTest2.

@Test
public void updateConnectionTest2() 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);
    String name = "name3373707";
    Connection connection = Connection.newBuilder().build();
    FieldMask updateMask = FieldMask.newBuilder().build();
    Connection actualResponse = client.updateConnection(name, connection, updateMask);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConnectionService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    UpdateConnectionRequest actualRequest = ((UpdateConnectionRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertEquals(connection, actualRequest.getConnection());
    Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Connection(com.google.cloud.bigquery.connection.v1.Connection) UpdateConnectionRequest(com.google.cloud.bigquery.connection.v1.UpdateConnectionRequest) ByteString(com.google.protobuf.ByteString) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 2 with UpdateConnectionRequest

use of com.google.cloud.bigquery.connection.v1.UpdateConnectionRequest 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 3 with UpdateConnectionRequest

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

the class ConnectionServiceClientTest method updateConnectionTest.

@Test
public void updateConnectionTest() 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 connection = Connection.newBuilder().build();
    FieldMask updateMask = FieldMask.newBuilder().build();
    Connection actualResponse = client.updateConnection(name, connection, updateMask);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConnectionService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    UpdateConnectionRequest actualRequest = ((UpdateConnectionRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertEquals(connection, actualRequest.getConnection());
    Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
    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) UpdateConnectionRequest(com.google.cloud.bigquery.connection.v1.UpdateConnectionRequest) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 4 with UpdateConnectionRequest

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

the class ITSystemTest method testUpdateConnection.

@Test
public void testUpdateConnection() {
    String description = "MY_DESCRIPTION";
    FieldMask updateMask = FieldMaskUtil.fromString("description");
    UpdateConnectionRequest request = UpdateConnectionRequest.newBuilder().setName(connection.getName()).setConnection(Connection.newBuilder().setDescription(description).build()).setUpdateMask(updateMask).build();
    Connection actualConnection = client.updateConnection(request);
    assertEquals(description, actualConnection.getDescription());
}
Also used : UpdateConnectionRequest(com.google.cloud.bigquery.connection.v1.UpdateConnectionRequest) Connection(com.google.cloud.bigquery.connection.v1.Connection) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Aggregations

Connection (com.google.cloud.bigquery.connection.v1.Connection)4 UpdateConnectionRequest (com.google.cloud.bigquery.connection.v1.UpdateConnectionRequest)4 FieldMask (com.google.protobuf.FieldMask)4 Test (org.junit.Test)3 ConnectionName (com.google.cloud.bigquery.connection.v1.ConnectionName)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 ConnectionServiceClient (com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient)1 ByteString (com.google.protobuf.ByteString)1