use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class RunNotificationIT method testRunNotification.
@Test
public void testRunNotification() throws IOException {
String query = "SELECT CURRENT_TIMESTAMP() as current_time, @run_time as intended_run_time, " + "@run_date as intended_run_date, 17 as some_integer";
String destinationTableName = "MY_DESTINATION_TABLE_" + UUID.randomUUID().toString().substring(0, 8) + "_{run_date}";
Map<String, Value> params = new HashMap<>();
params.put("query", Value.newBuilder().setStringValue(query).build());
params.put("destination_table_name_template", Value.newBuilder().setStringValue(destinationTableName).build());
params.put("write_disposition", Value.newBuilder().setStringValue("WRITE_TRUNCATE").build());
params.put("partitioning_field", Value.newBuilder().setStringValue("").build());
TransferConfig transferConfig = TransferConfig.newBuilder().setDestinationDatasetId(datasetName).setDisplayName(displayName).setDataSourceId("scheduled_query").setParams(Struct.newBuilder().putAllFields(params).build()).setSchedule("every 24 hours").setNotificationPubsubTopic(formattedTopicName).build();
RunNotification.runNotification(PROJECT_ID, transferConfig);
String result = bout.toString();
name = result.substring(result.indexOf(":") + 1, result.length() - 1);
assertThat(result).contains("Scheduled query with run notification created successfully");
assertThat(bout.toString()).contains(name);
}
use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class UpdateCredentialsIT method testUpdateCredentials.
@Test
public void testUpdateCredentials() throws IOException {
TransferConfig transferConfig = TransferConfig.newBuilder().setName(CONFIG_NAME).build();
FieldMask updateMask = FieldMaskUtil.fromString("service_account_name");
UpdateCredentials.updateCredentials(transferConfig, SERVICE_ACCOUNT, updateMask);
assertThat(bout.toString()).contains("Credentials updated successfully");
}
use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class DataTransferServiceClientTest method listTransferConfigsTest3.
@Test
public void listTransferConfigsTest3() throws Exception {
TransferConfig responsesElement = TransferConfig.newBuilder().build();
ListTransferConfigsResponse expectedResponse = ListTransferConfigsResponse.newBuilder().setNextPageToken("").addAllTransferConfigs(Arrays.asList(responsesElement)).build();
mockDataTransferService.addResponse(expectedResponse);
String parent = "parent-995424086";
ListTransferConfigsPagedResponse pagedListResponse = client.listTransferConfigs(parent);
List<TransferConfig> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getTransferConfigsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockDataTransferService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListTransferConfigsRequest actualRequest = ((ListTransferConfigsRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class DataTransferServiceClientTest method listTransferConfigsTest2.
@Test
public void listTransferConfigsTest2() throws Exception {
TransferConfig responsesElement = TransferConfig.newBuilder().build();
ListTransferConfigsResponse expectedResponse = ListTransferConfigsResponse.newBuilder().setNextPageToken("").addAllTransferConfigs(Arrays.asList(responsesElement)).build();
mockDataTransferService.addResponse(expectedResponse);
ProjectName parent = ProjectName.of("[PROJECT]");
ListTransferConfigsPagedResponse pagedListResponse = client.listTransferConfigs(parent);
List<TransferConfig> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getTransferConfigsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockDataTransferService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListTransferConfigsRequest actualRequest = ((ListTransferConfigsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class DataTransferServiceClientTest method listTransferConfigsTest.
@Test
public void listTransferConfigsTest() throws Exception {
TransferConfig responsesElement = TransferConfig.newBuilder().build();
ListTransferConfigsResponse expectedResponse = ListTransferConfigsResponse.newBuilder().setNextPageToken("").addAllTransferConfigs(Arrays.asList(responsesElement)).build();
mockDataTransferService.addResponse(expectedResponse);
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
ListTransferConfigsPagedResponse pagedListResponse = client.listTransferConfigs(parent);
List<TransferConfig> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getTransferConfigsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockDataTransferService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListTransferConfigsRequest actualRequest = ((ListTransferConfigsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations