diff --git a/bigquery/cloud-client/README.md b/bigquery/cloud-client/README.md index 1046596da9e..d067a8389d5 100644 --- a/bigquery/cloud-client/README.md +++ b/bigquery/cloud-client/README.md @@ -22,6 +22,10 @@ You can then run a given `ClassName` via: -DpropertyName=propertyValue \ -Dexec.args="any arguments to the app" +### Creating a new dataset (using the quickstart sample) + + mvn exec:java -Dexec.mainClass=com.example.bigquery.QuickstartSample + ### Running a synchronous query mvn exec:java -Dexec.mainClass=com.example.bigquery.SyncQuerySample \ diff --git a/bigquery/cloud-client/pom.xml b/bigquery/cloud-client/pom.xml index 680e3436154..887e1446cbb 100644 --- a/bigquery/cloud-client/pom.xml +++ b/bigquery/cloud-client/pom.xml @@ -50,7 +50,7 @@ com.google.truth truth - 0.29 + 0.30 test diff --git a/bigquery/cloud-client/src/main/java/com/example/bigquery/QuickstartSample.java b/bigquery/cloud-client/src/main/java/com/example/bigquery/QuickstartSample.java new file mode 100644 index 00000000000..aa727880cf9 --- /dev/null +++ b/bigquery/cloud-client/src/main/java/com/example/bigquery/QuickstartSample.java @@ -0,0 +1,44 @@ +/* + Copyright 2016, Google, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.example.bigquery; + +// [START bigquery_quickstart] +// Imports the Google Cloud client library +import com.google.cloud.bigquery.BigQuery; +import com.google.cloud.bigquery.BigQueryOptions; +import com.google.cloud.bigquery.Dataset; +import com.google.cloud.bigquery.DatasetInfo; + +public class QuickstartSample { + public static void main(String... args) throws Exception { + // Instantiates a client + BigQuery bigquery = BigQueryOptions.defaultInstance().service(); + + // The name for the new dataset + String datasetName = "my_new_dataset"; + + // Prepares a new dataset + Dataset dataset = null; + DatasetInfo datasetInfo = DatasetInfo.builder(datasetName).build(); + + // Creates the dataset + dataset = bigquery.create(datasetInfo); + + System.out.printf("Dataset %s created.%n", dataset.datasetId().dataset()); + } +} +// [END bigquery_quickstart] diff --git a/bigquery/cloud-client/src/test/java/com/example/bigquery/QuickstartSampleIT.java b/bigquery/cloud-client/src/test/java/com/example/bigquery/QuickstartSampleIT.java new file mode 100644 index 00000000000..9632de23bc6 --- /dev/null +++ b/bigquery/cloud-client/src/test/java/com/example/bigquery/QuickstartSampleIT.java @@ -0,0 +1,72 @@ +/* + Copyright 2016, Google, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.example.bigquery; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.cloud.bigquery.BigQuery; +import com.google.cloud.bigquery.BigQuery.DatasetDeleteOption; +import com.google.cloud.bigquery.BigQueryOptions; +import com.google.cloud.bigquery.DatasetId; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +/** + * Tests for quickstart sample. + */ +@RunWith(JUnit4.class) +@SuppressWarnings("checkstyle:abbreviationaswordinname") +public class QuickstartSampleIT { + private ByteArrayOutputStream bout; + private PrintStream out; + + private static final void deleteMyNewDataset() { + BigQuery bigquery = BigQueryOptions.defaultInstance().service(); + String datasetName = "my_new_dataset"; + DatasetId datasetId = DatasetId.of(datasetName); + DatasetDeleteOption deleteContents = DatasetDeleteOption.deleteContents(); + bigquery.delete(datasetId, deleteContents); + } + + @Before + public void setUp() { + deleteMyNewDataset(); + + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + deleteMyNewDataset(); + } + + @Test + public void testQuickstart() throws Exception { + QuickstartSample.main(); + String got = bout.toString(); + assertThat(got).contains("Dataset my_new_dataset created."); + } +} diff --git a/bigquery/cloud-client/src/test/java/com/example/bigquery/SyncQuerySampleTest.java b/bigquery/cloud-client/src/test/java/com/example/bigquery/SyncQuerySampleIT.java similarity index 95% rename from bigquery/cloud-client/src/test/java/com/example/bigquery/SyncQuerySampleTest.java rename to bigquery/cloud-client/src/test/java/com/example/bigquery/SyncQuerySampleIT.java index f606f2d9937..38359596e21 100644 --- a/bigquery/cloud-client/src/test/java/com/example/bigquery/SyncQuerySampleTest.java +++ b/bigquery/cloud-client/src/test/java/com/example/bigquery/SyncQuerySampleIT.java @@ -31,7 +31,8 @@ * Tests for synchronous query sample. */ @RunWith(JUnit4.class) -public class SyncQuerySampleTest { +@SuppressWarnings("checkstyle:abbreviationaswordinname") +public class SyncQuerySampleIT { private ByteArrayOutputStream bout; private PrintStream out; diff --git a/datastore/cloud-client/README.md b/datastore/cloud-client/README.md new file mode 100644 index 00000000000..26557f4e0ae --- /dev/null +++ b/datastore/cloud-client/README.md @@ -0,0 +1,26 @@ +# Getting Started with Cloud Datastore and the Google Cloud Client libraries + +[Google Cloud Datastore][Datastore] is a highly-scalable NoSQL database for your applications. +These sample Java applications demonstrate how to access the Datastore API using +the [Google Cloud Client Library for Java][google-cloud-java]. + +[Datastore]: https://cloud.google.com/datastore/ +[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java + +## Quickstart + +Install [Maven](http://maven.apache.org/). + +Build your project with: + + mvn clean package -DskipTests + +You can then run a given `ClassName` via: + + mvn exec:java -Dexec.mainClass=com.example.bigquery.ClassName \ + -DpropertyName=propertyValue \ + -Dexec.args="any arguments to the app" + +### Creating a new entity (using the quickstart sample) + + mvn exec:java -Dexec.mainClass=com.example.datastore.QuickstartSample diff --git a/datastore/cloud-client/pom.xml b/datastore/cloud-client/pom.xml new file mode 100644 index 00000000000..105ac0f8bb9 --- /dev/null +++ b/datastore/cloud-client/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + come.example.datastore + datastore-google-cloud-samples + jar + + + + doc-samples + com.google.cloud + 1.0.0 + ../.. + + + + 1.8 + 1.8 + UTF-8 + + + + + com.google.cloud + google-cloud-datastore + 0.4.0 + + + + + junit + junit + 4.12 + test + + + com.google.truth + truth + 0.30 + test + + + diff --git a/datastore/cloud-client/src/main/java/com/example/datastore/QuickstartSample.java b/datastore/cloud-client/src/main/java/com/example/datastore/QuickstartSample.java new file mode 100644 index 00000000000..1864a1e8f10 --- /dev/null +++ b/datastore/cloud-client/src/main/java/com/example/datastore/QuickstartSample.java @@ -0,0 +1,49 @@ +/* + Copyright 2016, Google, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.example.datastore; + +// [START datastore_quickstart] +// Imports the Google Cloud client library +import com.google.cloud.datastore.Datastore; +import com.google.cloud.datastore.DatastoreOptions; +import com.google.cloud.datastore.Entity; +import com.google.cloud.datastore.Key; + +public class QuickstartSample { + public static void main(String... args) throws Exception { + // Instantiates a client + Datastore datastore = DatastoreOptions.defaultInstance().service(); + + // The kind for the new entity + String kind = "Task"; + // The name/ID for the new entity + String name = "sampletask1"; + // The Cloud Datastore key for the new entity + Key taskKey = datastore.newKeyFactory().kind(kind).newKey(name); + + // Prepares the new entity + Entity task = Entity.builder(taskKey) + .set("description", "Buy milk") + .build(); + + // Saves the entity + datastore.put(task); + + System.out.printf("Saved %s: %s%n", task.key().name(), task.getString("description")); + } +} +// [END datastore_quickstart] diff --git a/datastore/cloud-client/src/test/java/com/example/datastore/QuickstartSampleIT.java b/datastore/cloud-client/src/test/java/com/example/datastore/QuickstartSampleIT.java new file mode 100644 index 00000000000..cd7d8adc00d --- /dev/null +++ b/datastore/cloud-client/src/test/java/com/example/datastore/QuickstartSampleIT.java @@ -0,0 +1,72 @@ +/* + Copyright 2016, Google, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.example.datastore; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.cloud.datastore.Datastore; +import com.google.cloud.datastore.DatastoreOptions; +import com.google.cloud.datastore.Key; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +/** + * Tests for quickstart sample. + */ +@RunWith(JUnit4.class) +@SuppressWarnings("checkstyle:abbreviationaswordinname") +public class QuickstartSampleIT { + private ByteArrayOutputStream bout; + private PrintStream out; + + private static final void deleteTestEntity() { + Datastore datastore = DatastoreOptions.defaultInstance().service(); + String kind = "Task"; + String name = "sampletask1"; + Key taskKey = datastore.newKeyFactory().kind(kind).newKey(name); + datastore.delete(taskKey); + } + + @Before + public void setUp() { + deleteTestEntity(); + + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + deleteTestEntity(); + } + + @Test + public void testQuickstart() throws Exception { + QuickstartSample.main(); + String got = bout.toString(); + assertThat(got).contains("Saved sampletask1: Buy milk"); + } +} +// [END datastore_quickstart] diff --git a/pom.xml b/pom.xml index a60ac7ad221..44728f0efeb 100644 --- a/pom.xml +++ b/pom.xml @@ -77,12 +77,13 @@ appengine/users appengine/xmpp bigquery + bigquery/cloud-client compute/cmdline compute/error-reporting compute/mailjet compute/sendgrid datastore - logging + datastore/cloud-client flexible/analytics flexible/async-rest flexible/cloudsql @@ -101,15 +102,20 @@ --> flexible/static-files flexible/twilio + language/analysis + logging monitoring/v2 monitoring/v3 + pubsub/cloud-client speech/grpc + storage/cloud-client storage/json-api storage/storage-transfer storage/xml-api/cmdline-sample storage/xml-api/serviceaccount-appengine-sample taskqueue/deferred - language/analysis + translate + translate/cloud-client unittests vision/face-detection vision/label diff --git a/pubsub/cloud-client/README.md b/pubsub/cloud-client/README.md new file mode 100644 index 00000000000..7c6ed464660 --- /dev/null +++ b/pubsub/cloud-client/README.md @@ -0,0 +1,27 @@ +# Getting Started with Cloud Pub/Sub and the Google Cloud Client libraries + +[Google Cloud Pub/Sub][pubsub] is a fully-managed real-time messaging service that allows you to +send and receive messages between independent applications. +These sample Java applications demonstrate how to access the Pub/Sub API using +the [Google Cloud Client Library for Java][google-cloud-java]. + +[pubsub]: https://cloud.google.com/pubsub/ +[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java + +## Quickstart + +Install [Maven](http://maven.apache.org/). + +Build your project with: + + mvn clean package -DskipTests + +You can then run a given `ClassName` via: + + mvn exec:java -Dexec.mainClass=com.example.pubsub.ClassName \ + -DpropertyName=propertyValue \ + -Dexec.args="any arguments to the app" + +### Creating a new topic (using the quickstart sample) + + mvn exec:java -Dexec.mainClass=com.example.pubsub.QuickstartSample diff --git a/pubsub/cloud-client/pom.xml b/pubsub/cloud-client/pom.xml new file mode 100644 index 00000000000..57be42e8713 --- /dev/null +++ b/pubsub/cloud-client/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + come.example.pubsub + pubsub-google-cloud-samples + jar + + + + doc-samples + com.google.cloud + 1.0.0 + ../.. + + + + 1.8 + 1.8 + UTF-8 + + + + + com.google.cloud + google-cloud-pubsub + 0.4.0 + + + + + junit + junit + 4.12 + test + + + com.google.truth + truth + 0.30 + test + + + diff --git a/pubsub/cloud-client/src/main/java/com/example/pubsub/QuickstartSample.java b/pubsub/cloud-client/src/main/java/com/example/pubsub/QuickstartSample.java new file mode 100644 index 00000000000..c5d97ed5087 --- /dev/null +++ b/pubsub/cloud-client/src/main/java/com/example/pubsub/QuickstartSample.java @@ -0,0 +1,40 @@ +/* + Copyright 2016, Google, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.example.pubsub; + +// [START pubsub_quickstart] +// Imports the Google Cloud client library +import com.google.cloud.pubsub.PubSub; +import com.google.cloud.pubsub.PubSubOptions; +import com.google.cloud.pubsub.Topic; +import com.google.cloud.pubsub.TopicInfo; + +public class QuickstartSample { + public static void main(String... args) throws Exception { + // Instantiates a client + PubSub pubsub = PubSubOptions.defaultInstance().service(); + + // The name for the new topic + String topicName = "my-new-topic"; + + // Creates the new topic + Topic topic = pubsub.create(TopicInfo.of(topicName)); + + System.out.printf("Topic %s created.%n", topic.name()); + } +} +// [END pubsub_quickstart] diff --git a/pubsub/cloud-client/src/test/java/com/example/pubsub/QuickstartSampleIT.java b/pubsub/cloud-client/src/test/java/com/example/pubsub/QuickstartSampleIT.java new file mode 100644 index 00000000000..a5adf198539 --- /dev/null +++ b/pubsub/cloud-client/src/test/java/com/example/pubsub/QuickstartSampleIT.java @@ -0,0 +1,69 @@ +/* + Copyright 2016, Google, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.example.pubsub; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.cloud.pubsub.PubSub; +import com.google.cloud.pubsub.PubSubOptions; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +/** + * Tests for quickstart sample. + */ +@RunWith(JUnit4.class) +@SuppressWarnings("checkstyle:abbreviationaswordinname") +public class QuickstartSampleIT { + private ByteArrayOutputStream bout; + private PrintStream out; + + private static final void deleteTestTopic() { + PubSub pubsub = PubSubOptions.defaultInstance().service(); + String topicName = "my-new-topic"; + pubsub.deleteTopic(topicName); + } + + @Before + public void setUp() { + deleteTestTopic(); + + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + deleteTestTopic(); + } + + @Test + public void testQuickstart() throws Exception { + QuickstartSample.main(); + String got = bout.toString(); + assertThat(got).contains("Topic my-new-topic created."); + } +} +// [END datastore_quickstart] diff --git a/secrets.env.EXAMPLE b/secrets.env.EXAMPLE new file mode 100644 index 00000000000..ce6f489c186 --- /dev/null +++ b/secrets.env.EXAMPLE @@ -0,0 +1,3 @@ +export AWS_ACCESS_KEY_ID=MY_KEY_ID +export AWS_SECRET_ACCESS_KEY=MY_ACCESS_KEY +export GOOGLE_API_KEY=MY_API_KEY diff --git a/secrets.env.enc b/secrets.env.enc index 3396fd83461..f0558306a88 100644 Binary files a/secrets.env.enc and b/secrets.env.enc differ diff --git a/storage/cloud-client/README.md b/storage/cloud-client/README.md new file mode 100644 index 00000000000..a6a53da067f --- /dev/null +++ b/storage/cloud-client/README.md @@ -0,0 +1,28 @@ +# Getting Started with Cloud Storage and the Google Cloud Client libraries + +[Google Cloud Storage][storage] is unified object storage for developers and enterprises, from live +data serving to data analytics/ML to data archival. +These sample Java applications demonstrate how to access the Cloud Storage API using +the [Google Cloud Client Library for Java][google-cloud-java]. + +[storage]: https://cloud.google.com/storage/ +[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java + +## Quickstart + +Install [Maven](http://maven.apache.org/). + +Build your project with: + + mvn clean package -DskipTests + +You can then run a given `ClassName` via: + + mvn exec:java -Dexec.mainClass=com.example.storage.ClassName \ + -DpropertyName=propertyValue \ + -Dexec.args="any arguments to the app" + +### Creating a new bucket (using the quickstart sample) + + mvn exec:java -Dexec.mainClass=com.example.storage.QuickstartSample \ + -Dexec.args="my-bucket-name" diff --git a/storage/cloud-client/pom.xml b/storage/cloud-client/pom.xml new file mode 100644 index 00000000000..a5ef11e6e90 --- /dev/null +++ b/storage/cloud-client/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + come.example.storage + storage-google-cloud-samples + jar + + + + doc-samples + com.google.cloud + 1.0.0 + ../.. + + + + 1.8 + 1.8 + UTF-8 + + + + + com.google.cloud + google-cloud-storage + 0.4.0 + + + + + junit + junit + 4.12 + test + + + com.google.truth + truth + 0.30 + test + + + diff --git a/storage/cloud-client/src/main/java/com/example/storage/QuickstartSample.java b/storage/cloud-client/src/main/java/com/example/storage/QuickstartSample.java new file mode 100644 index 00000000000..23a4155a585 --- /dev/null +++ b/storage/cloud-client/src/main/java/com/example/storage/QuickstartSample.java @@ -0,0 +1,40 @@ +/* + Copyright 2016, Google, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.example.storage; + +// [START storage_quickstart] +// Imports the Google Cloud client library +import com.google.cloud.storage.Bucket; +import com.google.cloud.storage.BucketInfo; +import com.google.cloud.storage.Storage; +import com.google.cloud.storage.StorageOptions; + +public class QuickstartSample { + public static void main(String... args) throws Exception { + // Instantiates a client + Storage storage = StorageOptions.defaultInstance().service(); + + // The name for the new bucket + String bucketName = args[0]; // "my-new-bucket"; + + // Creates the new bucket + Bucket bucket = storage.create(BucketInfo.of(bucketName)); + + System.out.printf("Bucket %s created.%n", bucket.name()); + } +} +// [END storage_quickstart] diff --git a/storage/cloud-client/src/test/java/com/example/storage/QuickstartSampleIT.java b/storage/cloud-client/src/test/java/com/example/storage/QuickstartSampleIT.java new file mode 100644 index 00000000000..3dd2b0ac69a --- /dev/null +++ b/storage/cloud-client/src/test/java/com/example/storage/QuickstartSampleIT.java @@ -0,0 +1,70 @@ +/* + Copyright 2016, Google, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.example.storage; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.cloud.storage.Storage; +import com.google.cloud.storage.StorageOptions; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.util.UUID; + +/** + * Tests for quickstart sample. + */ +@RunWith(JUnit4.class) +@SuppressWarnings("checkstyle:abbreviationaswordinname") +public class QuickstartSampleIT { + private String bucketName; + private ByteArrayOutputStream bout; + private PrintStream out; + + private static final void deleteBucket(String bucketName) { + Storage storage = StorageOptions.defaultInstance().service(); + storage.delete(bucketName); + } + + @Before + public void setUp() { + bucketName = "my-new-bucket-" + UUID.randomUUID().toString(); + + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + deleteBucket(bucketName); + } + + @Test + public void testQuickstart() throws Exception { + QuickstartSample.main(bucketName); + String got = bout.toString(); + assertThat(got).contains(String.format("Bucket %s created.", bucketName)); + } +} +// [END datastore_quickstart] diff --git a/translate/cloud-client/README.md b/translate/cloud-client/README.md new file mode 100644 index 00000000000..30e53275591 --- /dev/null +++ b/translate/cloud-client/README.md @@ -0,0 +1,28 @@ +# Getting Started with Google Translate API and the Google Cloud Client libraries + +[Google Translate API][translate] provides a simple programmatic interface for translating an +arbitrary string into any supported language. +These sample Java applications demonstrate how to access the Cloud Storage API using +the [Google Cloud Client Library for Java][google-cloud-java]. + +[translate]: https://cloud.google.com/translate/ +[google-cloud-java]: https://github.com/GoogleCloudPlatform/google-cloud-java + +## Quickstart + +Install [Maven](http://maven.apache.org/). + +Build your project with: + + mvn clean package -DskipTests + +You can then run a given `ClassName` via: + + mvn exec:java -Dexec.mainClass=com.example.translate.ClassName \ + -DpropertyName=propertyValue \ + -Dexec.args="any arguments to the app" + +### Translate a string (using the quickstart sample) + + mvn exec:java -Dexec.mainClass=com.example.translate.QuickstartSample \ + -Dexec.args="YOUR_API_KEY" diff --git a/translate/cloud-client/pom.xml b/translate/cloud-client/pom.xml new file mode 100644 index 00000000000..31cc2efe147 --- /dev/null +++ b/translate/cloud-client/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + come.example.translate + translate-google-cloud-samples + jar + + + + doc-samples + com.google.cloud + 1.0.0 + ../.. + + + + 1.8 + 1.8 + UTF-8 + + + + + com.google.cloud + google-cloud-translate + 0.4.0 + + + + + junit + junit + 4.12 + test + + + com.google.truth + truth + 0.30 + test + + + diff --git a/translate/cloud-client/src/main/java/com/example/translate/QuickstartSample.java b/translate/cloud-client/src/main/java/com/example/translate/QuickstartSample.java new file mode 100644 index 00000000000..75523d0dcaf --- /dev/null +++ b/translate/cloud-client/src/main/java/com/example/translate/QuickstartSample.java @@ -0,0 +1,50 @@ +/* + Copyright 2016, Google, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.example.translate; + +// [START translate_quickstart] +// Imports the Google Cloud client library +import com.google.cloud.translate.Translate; +import com.google.cloud.translate.Translate.TranslateOption; +import com.google.cloud.translate.TranslateOptions; +import com.google.cloud.translate.Translation; + +public class QuickstartSample { + public static void main(String... args) throws Exception { + // Instantiates a client + Translate translate = + TranslateOptions.builder() + .apiKey(args[0]) // .apiKey("YOUR_API_KEY") + .build() + .service(); + + // The text to translate + String text = "Hello, world!"; + + // Translates some text into Russian + Translation translation = + translate.translate( + text, + TranslateOption.sourceLanguage("en"), + TranslateOption.targetLanguage("ru")); + + + System.out.printf("Text: %s%n", text); + System.out.printf("Translation: %s%n", translation.translatedText()); + } +} +// [END translate_quickstart] diff --git a/translate/cloud-client/src/test/java/com/example/translate/QuickstartSampleIT.java b/translate/cloud-client/src/test/java/com/example/translate/QuickstartSampleIT.java new file mode 100644 index 00000000000..c91651b2a74 --- /dev/null +++ b/translate/cloud-client/src/test/java/com/example/translate/QuickstartSampleIT.java @@ -0,0 +1,65 @@ +/* + Copyright 2016, Google, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package com.example.translate; + +import static com.google.common.truth.Truth.assertThat; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +/** + * Tests for quickstart sample. + */ +@RunWith(JUnit4.class) +@SuppressWarnings("checkstyle:abbreviationaswordinname") +public class QuickstartSampleIT { + private ByteArrayOutputStream bout; + private PrintStream out; + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + } + + @Test + public void testQuickstart() throws Exception { + // Arrange + String apiKey = System.getenv("GOOGLE_API_KEY"); + + // Act + QuickstartSample.main(apiKey); + + // Assert + String got = bout.toString(); + assertThat(got).contains("Text: Hello, world!"); + assertThat(got).contains("Translation: "); + } +} +// [END datastore_quickstart] diff --git a/translate/pom.xml b/translate/pom.xml index 2eddfbdd0df..d04b0fe12b8 100644 --- a/translate/pom.xml +++ b/translate/pom.xml @@ -25,12 +25,15 @@ limitations under the License. 1.8 UTF-8 + + + doc-samples com.google.cloud - shared-configuration 1.0.0 - ../java-repo-tools + .. + com.google.cloud