This folder contains examples of test apps for gcloud-java.
In order to run these tests, you will need to:
- Create a Google Developers Console project with the BigQuery, Datastore, and Storage JSON APIs enabled. Follow these instructions to get your project set up.
- Enable billing.
- Set up the local development environment by installing the Google Cloud SDK and running the following commands in command line:
gcloud auth loginandgcloud config set project [YOUR PROJECT ID]. - Ensure the version of gcloud-java you wish to test is correctly specified in the
pom.xmlfiles in theapp-engine-test-appandcommand-line-test-appfolders.
- Change "your-project-id" to your project ID in
src/main/webapp/WEB-INF/appengine-web.xml. - Run
mvn appengine:devserverto test locally andmvn appengine:updateto test the app in production. - Navigate to the URL where the app is deployed. Add the service you wish to test to the URL ("bigquery", "datastore", "resourcemanager", or "storage"). For example, to test datastore, navigate to
http://localhost:8080/datastore.
To run the command line test app on Compute Engine:
- Create a Compute Engine instance with the User Info, Big Query, Datastore, and Storage APIs (read write) enabled.
- Copy your the app to your instance using the Google Cloud SDK command:
gcloud compute copy-files test-apps/command-line-test-app [username@instance-name]:~
- Ensure that Maven and the Java 7 JDK are installed. Also check that the environment variable
JAVA_HOMEpoints to the Java 7 JDK. - Ensure that you have User Credentials available on your Compute Engine instance. These credentials are necessary to use Resource Manager. If you get authentication errors stemming from inadequate authentication scope during execution, you can copy your gcloud SDK credentials (usually located in the
~/.config/gclouddirectory) to your Compute Engine instance and set the GOOGLE_APPLICATION_CREDENTIALS environment variable as follows:export GOOGLE_APPLICATION_CREDENTIALS=<insert-credential-location>. - Run the app using Maven's exec plugin. Specify the service you wish to test as a command line parameter. Here is an example of running the storage test.
mvn clean compile exec:java \
-Dexec.mainClass="com.google.gcloud.tests.commandline.GcloudJavaCommandLineTest" \
-Dexec.args="storage"
Run the app using the same command line structure as for Compute Engine.
- Create JSON service account credentials and save the file as follows:
src/main/webapp/WEB-INF/lib/my-service-account-credentials.json. - Set the optional request parameters to specify your project ID and to use the JSON credentials file you created. Here's an example URL using datastore with project ID "my-project-id" that uses the JSON credentials file:
http://localhost:8080/datastore?project-id=my-project-id&credentials-file=true
- If you are testing authentication on Compute Engine or your own desktop, save the file in the application's base directory as
my-service-account-credentials.json. - Specify the authentication and project ID as command line arguments ("project-id=your-project-id" and "credentials-file=true", respectively). Here is an example of running the storage test that includes both the optional parameters.
mvn clean compile exec:java \
-Dexec.mainClass="com.google.gcloud.tests.commandline.GcloudJavaCommandLineTest" \
-Dexec.args="storage project-id=my-project-id credentials-file=true"
- You can also test the environment variables for setting the project ID and authentication. Do not specify project ID and credentials file using the command line parameters. Instead, set the environment variables
GCLOUD_PROJECT(to your project ID) andGOOGLE_APPLICATION_CREDENTIALS(to the location of your credentials file).
Apache 2.0 - See LICENSE for more information.