use of com.google.cloud.bigquery.connection.v1.CreateConnectionRequest in project java-bigqueryconnection by googleapis.
the class ConnectionServiceClientTest method createConnectionTest.
@Test
public void createConnectionTest() 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);
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
Connection connection = Connection.newBuilder().build();
String connectionId = "connectionId1923106969";
Connection actualResponse = client.createConnection(parent, connection, connectionId);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockConnectionService.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateConnectionRequest actualRequest = ((CreateConnectionRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(connection, actualRequest.getConnection());
Assert.assertEquals(connectionId, actualRequest.getConnectionId());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.bigquery.connection.v1.CreateConnectionRequest in project java-bigqueryconnection by googleapis.
the class CreateConnection method createConnection.
public static void createConnection(String projectId, String location, String connectionId, Connection connection) throws IOException {
try (ConnectionServiceClient client = ConnectionServiceClient.create()) {
LocationName parent = LocationName.of(projectId, location);
CreateConnectionRequest request = CreateConnectionRequest.newBuilder().setParent(parent.toString()).setConnection(connection).setConnectionId(connectionId).build();
Connection response = client.createConnection(request);
System.out.println("Connection created successfully :" + response.getName());
}
}
use of com.google.cloud.bigquery.connection.v1.CreateConnectionRequest in project java-bigqueryconnection by googleapis.
the class ConnectionServiceClientTest method createConnectionTest2.
@Test
public void createConnectionTest2() 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 parent = "parent-995424086";
Connection connection = Connection.newBuilder().build();
String connectionId = "connectionId1923106969";
Connection actualResponse = client.createConnection(parent, connection, connectionId);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockConnectionService.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateConnectionRequest actualRequest = ((CreateConnectionRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertEquals(connection, actualRequest.getConnection());
Assert.assertEquals(connectionId, actualRequest.getConnectionId());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.bigquery.connection.v1.CreateConnectionRequest in project java-bigqueryconnection by googleapis.
the class ITSystemTest method setUp.
@Before
public void setUp() throws IOException {
client = ConnectionServiceClient.create();
// create a temporary connection to be deleted
String instanceId = String.format("%s:%s:%s", PROJECT_ID, REGION, MY_SQL_INSTANCE);
CloudSqlCredential cloudSqlCredential = CloudSqlCredential.newBuilder().setUsername(DB_USER).setPassword(DB_PWD).build();
CloudSqlProperties cloudSqlProperties = CloudSqlProperties.newBuilder().setType(CloudSqlProperties.DatabaseType.MYSQL).setDatabase(MY_SQL_DATABASE).setInstanceId(instanceId).setCredential(cloudSqlCredential).build();
CreateConnectionRequest request = CreateConnectionRequest.newBuilder().setParent(PARENT).setConnection(Connection.newBuilder().setCloudSql(cloudSqlProperties).build()).setConnectionId(CONNECTION_ID).build();
connection = client.createConnection(request);
}
use of com.google.cloud.bigquery.connection.v1.CreateConnectionRequest in project java-bigqueryconnection by googleapis.
the class CreateAwsConnection method createAwsConnection.
public static void createAwsConnection(String projectId, String location, String connectionId, Connection connection) throws IOException {
try (ConnectionServiceClient client = ConnectionServiceClient.create()) {
LocationName parent = LocationName.of(projectId, location);
CreateConnectionRequest request = CreateConnectionRequest.newBuilder().setParent(parent.toString()).setConnection(connection).setConnectionId(connectionId).build();
Connection response = client.createConnection(request);
AwsAccessRole role = response.getAws().getAccessRole();
System.out.println("Aws connection created successfully : Aws userId :" + role.getIamRoleId() + " Aws externalId :" + role.getIdentity());
}
}
Aggregations