Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add system tests to Translate sample.
  • Loading branch information
tswast committed Oct 26, 2016
commit 5da7970f221cd4524e59deddc81b42795b1b4902
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void main(String... args) throws Exception {
Storage storage = StorageOptions.defaultInstance().service();

// The name for the new bucket
String bucketName = args[0];
String bucketName = args[0]; // "my-new-bucket";

// Creates the new bucket
Bucket bucket = storage.create(BucketInfo.of(bucketName));
Expand Down
28 changes: 28 additions & 0 deletions translate/cloud-client/README.md
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 14 additions & 0 deletions translate/cloud-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,19 @@
<artifactId>google-cloud-translate</artifactId>
<version>0.4.0</version>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>0.30</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
public class QuickstartSample {
public static void main(String... args) throws Exception {
// Instantiates a client
Translate translate = TranslateOptions.builder().apiKey("YOUR_API_KEY").build().service();
Translate translate =
TranslateOptions.builder()
.apiKey(args[0]) // .apiKey("YOUR_API_KEY")
.build()
.service();

// The text to translate
String text = "Hello, world!";
Expand Down
Original file line number Diff line number Diff line change
@@ -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]