Search in sources :

Example 36 with TransferConfig

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);
}
Also used : HashMap(java.util.HashMap) Value(com.google.protobuf.Value) TransferConfig(com.google.cloud.bigquery.datatransfer.v1.TransferConfig) Test(org.junit.Test)

Example 37 with TransferConfig

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");
}
Also used : TransferConfig(com.google.cloud.bigquery.datatransfer.v1.TransferConfig) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 38 with TransferConfig

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListTransferConfigsPagedResponse(com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient.ListTransferConfigsPagedResponse) Test(org.junit.Test)

Example 39 with TransferConfig

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListTransferConfigsPagedResponse(com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient.ListTransferConfigsPagedResponse) Test(org.junit.Test)

Example 40 with TransferConfig

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListTransferConfigsPagedResponse(com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient.ListTransferConfigsPagedResponse) Test(org.junit.Test)

Aggregations

TransferConfig (com.google.cloud.bigquery.datatransfer.v1.TransferConfig)49 Value (com.google.protobuf.Value)22 HashMap (java.util.HashMap)22 DataTransferServiceClient (com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient)21 ApiException (com.google.api.gax.rpc.ApiException)19 CreateTransferConfigRequest (com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest)16 ProjectName (com.google.cloud.bigquery.datatransfer.v1.ProjectName)16 Test (org.junit.Test)13 FieldMask (com.google.protobuf.FieldMask)9 UpdateTransferConfigRequest (com.google.cloud.bigquery.datatransfer.v1.UpdateTransferConfigRequest)4 ListTransferConfigsPagedResponse (com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient.ListTransferConfigsPagedResponse)3 AbstractMessage (com.google.protobuf.AbstractMessage)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 PrintStream (java.io.PrintStream)3 Before (org.junit.Before)3 ServiceAccountCredentials (com.google.auth.oauth2.ServiceAccountCredentials)1 GetTransferConfigRequest (com.google.cloud.bigquery.datatransfer.v1.GetTransferConfigRequest)1