Skip to content

Commit

Permalink
Merge pull request #221 from ajkannan/add-testing-subpackages
Browse files Browse the repository at this point in the history
Add testing subpackages
  • Loading branch information
aozarov committed Oct 8, 2015
2 parents 2171251 + c7059ae commit 476d594
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.google.gcloud.datastore;
package com.google.gcloud.datastore.testing;

import static java.nio.charset.StandardCharsets.UTF_8;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
* 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.
*/

/**
* A testing helper for Google Cloud Datastore.
*
* <p>A simple usage example:
* <p>Before the test:
* <pre> {@code
* LocalGcdHelper gcdHelper = LocalGcdHelper.start(PROJECT_ID, PORT_NUMBER);
* DatastoreOptions options = DatastoreOptions.builder()
* .projectId(PROJECT_ID)
* .host("localhost:8080")
* .build();
* Datastore localDatastore = DatastoreFactory.instance().get(options);
* } </pre>
*
* <p>After the test:
* <pre> {@code
* gcdHelper.stop();
* } </pre>
*
* @see <a href="https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/TESTING.md#testing-code-that-uses-datastore">
* gcloud-java tools for testing</a>
*/
package com.google.gcloud.datastore.testing;
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import com.google.gcloud.datastore.testing.LocalGcdHelper;
import com.google.gcloud.spi.DatastoreRpc;
import com.google.gcloud.spi.DatastoreRpcFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.google.gcloud.datastore.StructuredQuery.OrderBy;
import com.google.gcloud.datastore.StructuredQuery.Projection;
import com.google.gcloud.datastore.StructuredQuery.PropertyFilter;
import com.google.gcloud.datastore.testing.LocalGcdHelper;
import com.google.gcloud.spi.DatastoreRpc;
import com.google.gcloud.spi.DatastoreRpc.DatastoreRpcException.Reason;
import com.google.gcloud.spi.DatastoreRpcFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
* limitations under the License.
*/

package com.google.gcloud.storage;
package com.google.gcloud.storage.testing;

import com.google.common.collect.ImmutableMap;
import com.google.gcloud.AuthCredentials;
import com.google.gcloud.storage.BlobInfo;
import com.google.gcloud.RetryParams;
import com.google.gcloud.storage.RemoteGcsHelper.Option.KeyFromClasspath;
import com.google.gcloud.storage.Storage;
import com.google.gcloud.storage.StorageException;
import com.google.gcloud.storage.StorageOptions;
import com.google.gcloud.storage.testing.RemoteGcsHelper.Option.KeyFromClasspath;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -54,7 +58,7 @@ private RemoteGcsHelper(StorageOptions options) {
}

/**
* Returns a {@StorageOptions} object to be used for testing.
* Returns a {@link StorageOptions} object to be used for testing.
*/
public StorageOptions options() {
return options;
Expand Down Expand Up @@ -99,7 +103,7 @@ public static String generateBucketName() {
* @param keyPath path to the JSON key to be used for running the tests
* @param options creation options
* @return A {@code RemoteGcsHelper} object for the provided options.
* @throws com.google.gcloud.storage.RemoteGcsHelper.GcsHelperException if the file pointed by
* @throws com.google.gcloud.storage.testing.RemoteGcsHelper.GcsHelperException if the file pointed by
* {@code keyPath} does not exist
*/
public static RemoteGcsHelper create(String projectId, String keyPath, Option... options)
Expand Down Expand Up @@ -145,7 +149,7 @@ public static RemoteGcsHelper create(String projectId, String keyPath, Option...
*
* @param options creation options
* @return A {@code RemoteGcsHelper} object for the provided options.
* @throws com.google.gcloud.storage.RemoteGcsHelper.GcsHelperException if environment variables
* @throws com.google.gcloud.storage.testing.RemoteGcsHelper.GcsHelperException if environment variables
* {@code GCLOUD_TESTS_PROJECT_ID} and {@code GCLOUD_TESTS_KEY} are not set or if the file
* pointed by {@code GCLOUD_TESTS_KEY} does not exist
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
* 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.
*/

/**
* A testing helper for Google Cloud Storage.
*
* <p>A simple usage example:
* <p>Before the test:
* <pre> {@code
* RemoteGcsHelper gcsHelper = RemoteGcsHelper.create(PROJECT_ID, "/path/to/JSON/key.json");
* Storage storage = StorageFactory.instance().get(gcsHelper.options());
* String bucket = RemoteGcsHelper.generateBucketName();
* storage.create(BucketInfo.of(bucket));
* } </pre>
*
* <p>After the test:
* <pre> {@code
* RemoteGcsHelper.forceDelete(storage, bucket, 5, TimeUnit.SECONDS);
* } </pre>
*
* @see <a href="https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/TESTING.md#testing-code-that-uses-storage">
* gcloud-java tools for testing</a>
*/
package com.google.gcloud.storage.testing;
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.junit.Assert.fail;

import com.google.common.collect.ImmutableList;
import com.google.gcloud.storage.testing.RemoteGcsHelper;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand Down

0 comments on commit 476d594

Please sign in to comment.