Skip to content

Commit 476d594

Browse files
committed
Merge pull request #221 from ajkannan/add-testing-subpackages
Add testing subpackages
2 parents 2171251 + c7059ae commit 476d594

7 files changed

Lines changed: 89 additions & 6 deletions

File tree

gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalGcdHelper.java renamed to gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/LocalGcdHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.google.gcloud.datastore;
17+
package com.google.gcloud.datastore.testing;
1818

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
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+
/**
18+
* A testing helper for Google Cloud Datastore.
19+
*
20+
* <p>A simple usage example:
21+
* <p>Before the test:
22+
* <pre> {@code
23+
* LocalGcdHelper gcdHelper = LocalGcdHelper.start(PROJECT_ID, PORT_NUMBER);
24+
* DatastoreOptions options = DatastoreOptions.builder()
25+
* .projectId(PROJECT_ID)
26+
* .host("localhost:8080")
27+
* .build();
28+
* Datastore localDatastore = DatastoreFactory.instance().get(options);
29+
* } </pre>
30+
*
31+
* <p>After the test:
32+
* <pre> {@code
33+
* gcdHelper.stop();
34+
* } </pre>
35+
*
36+
* @see <a href="https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/TESTING.md#testing-code-that-uses-datastore">
37+
* gcloud-java tools for testing</a>
38+
*/
39+
package com.google.gcloud.datastore.testing;

gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreOptionsTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static org.junit.Assert.assertSame;
2323
import static org.junit.Assert.assertTrue;
2424

25+
import com.google.gcloud.datastore.testing.LocalGcdHelper;
2526
import com.google.gcloud.spi.DatastoreRpc;
2627
import com.google.gcloud.spi.DatastoreRpcFactory;
2728

gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.google.gcloud.datastore.StructuredQuery.OrderBy;
3434
import com.google.gcloud.datastore.StructuredQuery.Projection;
3535
import com.google.gcloud.datastore.StructuredQuery.PropertyFilter;
36+
import com.google.gcloud.datastore.testing.LocalGcdHelper;
3637
import com.google.gcloud.spi.DatastoreRpc;
3738
import com.google.gcloud.spi.DatastoreRpc.DatastoreRpcException.Reason;
3839
import com.google.gcloud.spi.DatastoreRpcFactory;

gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelper.java renamed to gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.google.gcloud.storage;
17+
package com.google.gcloud.storage.testing;
1818

1919
import com.google.common.collect.ImmutableMap;
2020
import com.google.gcloud.AuthCredentials;
21+
import com.google.gcloud.storage.BlobInfo;
2122
import com.google.gcloud.RetryParams;
22-
import com.google.gcloud.storage.RemoteGcsHelper.Option.KeyFromClasspath;
23+
import com.google.gcloud.storage.Storage;
24+
import com.google.gcloud.storage.StorageException;
25+
import com.google.gcloud.storage.StorageOptions;
26+
import com.google.gcloud.storage.testing.RemoteGcsHelper.Option.KeyFromClasspath;
2327

2428
import java.io.FileInputStream;
2529
import java.io.FileNotFoundException;
@@ -54,7 +58,7 @@ private RemoteGcsHelper(StorageOptions options) {
5458
}
5559

5660
/**
57-
* Returns a {@StorageOptions} object to be used for testing.
61+
* Returns a {@link StorageOptions} object to be used for testing.
5862
*/
5963
public StorageOptions options() {
6064
return options;
@@ -99,7 +103,7 @@ public static String generateBucketName() {
99103
* @param keyPath path to the JSON key to be used for running the tests
100104
* @param options creation options
101105
* @return A {@code RemoteGcsHelper} object for the provided options.
102-
* @throws com.google.gcloud.storage.RemoteGcsHelper.GcsHelperException if the file pointed by
106+
* @throws com.google.gcloud.storage.testing.RemoteGcsHelper.GcsHelperException if the file pointed by
103107
* {@code keyPath} does not exist
104108
*/
105109
public static RemoteGcsHelper create(String projectId, String keyPath, Option... options)
@@ -145,7 +149,7 @@ public static RemoteGcsHelper create(String projectId, String keyPath, Option...
145149
*
146150
* @param options creation options
147151
* @return A {@code RemoteGcsHelper} object for the provided options.
148-
* @throws com.google.gcloud.storage.RemoteGcsHelper.GcsHelperException if environment variables
152+
* @throws com.google.gcloud.storage.testing.RemoteGcsHelper.GcsHelperException if environment variables
149153
* {@code GCLOUD_TESTS_PROJECT_ID} and {@code GCLOUD_TESTS_KEY} are not set or if the file
150154
* pointed by {@code GCLOUD_TESTS_KEY} does not exist
151155
*/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
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+
/**
18+
* A testing helper for Google Cloud Storage.
19+
*
20+
* <p>A simple usage example:
21+
* <p>Before the test:
22+
* <pre> {@code
23+
* RemoteGcsHelper gcsHelper = RemoteGcsHelper.create(PROJECT_ID, "/path/to/JSON/key.json");
24+
* Storage storage = StorageFactory.instance().get(gcsHelper.options());
25+
* String bucket = RemoteGcsHelper.generateBucketName();
26+
* storage.create(BucketInfo.of(bucket));
27+
* } </pre>
28+
*
29+
* <p>After the test:
30+
* <pre> {@code
31+
* RemoteGcsHelper.forceDelete(storage, bucket, 5, TimeUnit.SECONDS);
32+
* } </pre>
33+
*
34+
* @see <a href="https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/TESTING.md#testing-code-that-uses-storage">
35+
* gcloud-java tools for testing</a>
36+
*/
37+
package com.google.gcloud.storage.testing;

gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static org.junit.Assert.fail;
2525

2626
import com.google.common.collect.ImmutableList;
27+
import com.google.gcloud.storage.testing.RemoteGcsHelper;
2728

2829
import java.io.ByteArrayInputStream;
2930
import java.io.IOException;

0 commit comments

Comments
 (0)