Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit 6c52fa8

Browse files
docs(samples): migrate samples into client (#177)
1 parent 7d618e2 commit 6c52fa8

File tree

4 files changed

+126
-1
lines changed

4 files changed

+126
-1
lines changed

pom.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,19 @@
184184
<link>https://developers.google.com/protocol-buffers/docs/reference/java/</link>
185185
<link>https://googleapis.dev/java/google-auth-library/latest/</link>
186186
<link>https://googleapis.dev/java/gax/latest/</link>
187-
<link>https://googleapis.github.io/api-common-java/${google.api-common.version}/apidocs/</link>
187+
<link>https://googleapis.github.io/api-common-java/</link>
188188
</links>
189189
</configuration>
190190
</plugin>
191191
</plugins>
192192
</reporting>
193+
194+
<profiles>
195+
<profile>
196+
<id>include-samples</id>
197+
<modules>
198+
<module>samples</module>
199+
</modules>
200+
</profile>
201+
</profiles>
193202
</project>

samples/snippets/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
</dependency>
4545
<!-- [END bigquerydatatransfer_install_with_bom] -->
4646

47+
<!-- Test dependencies -->
4748
<dependency>
4849
<groupId>junit</groupId>
4950
<artifactId>junit</artifactId>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2018 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.bigquerydatatransfer;
18+
19+
// [START bigquerydatatransfer_quickstart]
20+
// Imports the Google Cloud client library
21+
22+
import com.google.cloud.bigquery.datatransfer.v1.DataSource;
23+
import com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient;
24+
import com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient.ListDataSourcesPagedResponse;
25+
import com.google.cloud.bigquery.datatransfer.v1.ListDataSourcesRequest;
26+
27+
public class QuickstartSample {
28+
/**
29+
* List available data sources for the BigQuery Data Transfer service.
30+
*/
31+
public static void main(String... args) throws Exception {
32+
// Sets your Google Cloud Platform project ID.
33+
// String projectId = "YOUR_PROJECT_ID";
34+
String projectId = args[0];
35+
36+
// Instantiate a client. If you don't specify credentials when constructing a client, the
37+
// client library will look for credentials in the environment, such as the
38+
// GOOGLE_APPLICATION_CREDENTIALS environment variable.
39+
try (DataTransferServiceClient client = DataTransferServiceClient.create()) {
40+
// Request the list of available data sources.
41+
String parent = String.format("projects/%s", projectId);
42+
ListDataSourcesRequest request =
43+
ListDataSourcesRequest.newBuilder()
44+
.setParent(parent)
45+
.build();
46+
ListDataSourcesPagedResponse response = client.listDataSources(request);
47+
48+
// Print the results.
49+
System.out.println("Supported Data Sources:");
50+
for (DataSource dataSource : response.iterateAll()) {
51+
System.out.println(dataSource.getDisplayName());
52+
System.out.printf("\tID: %s%n", dataSource.getDataSourceId());
53+
System.out.printf("\tFull path: %s%n", dataSource.getName());
54+
System.out.printf("\tDescription: %s%n", dataSource.getDescription());
55+
}
56+
}
57+
}
58+
}
59+
// [END bigquerydatatransfer_quickstart]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2018 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.bigquerydatatransfer;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
21+
import java.io.ByteArrayOutputStream;
22+
import java.io.PrintStream;
23+
import org.junit.After;
24+
import org.junit.Before;
25+
import org.junit.Test;
26+
import org.junit.runner.RunWith;
27+
import org.junit.runners.JUnit4;
28+
29+
/** Tests for quickstart sample. */
30+
@RunWith(JUnit4.class)
31+
@SuppressWarnings("checkstyle:abbreviationaswordinname")
32+
public class QuickstartSampleIT {
33+
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
34+
35+
private ByteArrayOutputStream bout;
36+
private PrintStream out;
37+
38+
@Before
39+
public void setUp() {
40+
bout = new ByteArrayOutputStream();
41+
out = new PrintStream(bout);
42+
System.setOut(out);
43+
}
44+
45+
@After
46+
public void tearDown() {
47+
System.setOut(null);
48+
}
49+
50+
@Test
51+
public void testQuickstart() throws Exception {
52+
QuickstartSample.main(PROJECT_ID);
53+
String got = bout.toString();
54+
assertThat(got).contains("Supported Data Sources:");
55+
}
56+
}

0 commit comments

Comments
 (0)