From 2e3042c106800ea15b2fe2bfaf117555e17b8f4a Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Wed, 7 Oct 2015 15:55:30 -0700 Subject: [PATCH 1/3] Move testing helpers to subpackages within their service's src/main/ packages --- .../datastore/testing}/LocalGcdHelper.java | 2 +- .../datastore/testing/package-info.java | 37 +++++++++++++++++++ .../datastore/DatastoreOptionsTest.java | 1 + .../gcloud/datastore/DatastoreTest.java | 1 + .../storage/testing}/RemoteGcsHelper.java | 10 +++-- .../gcloud/storage/testing/package-info.java | 35 ++++++++++++++++++ .../google/gcloud/storage/ITStorageTest.java | 1 + 7 files changed, 83 insertions(+), 4 deletions(-) rename gcloud-java-datastore/src/{test/java/com/google/gcloud/datastore => main/java/com/google/gcloud/datastore/testing}/LocalGcdHelper.java (99%) create mode 100644 gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/package-info.java rename gcloud-java-storage/src/{test/java/com/google/gcloud/storage => main/java/com/google/gcloud/storage/testing}/RemoteGcsHelper.java (94%) create mode 100644 gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalGcdHelper.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/LocalGcdHelper.java similarity index 99% rename from gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalGcdHelper.java rename to gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/LocalGcdHelper.java index 0e0e726a7fba..e9cd54a7dc95 100644 --- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalGcdHelper.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/LocalGcdHelper.java @@ -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; diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/package-info.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/package-info.java new file mode 100644 index 000000000000..f53e50aac27c --- /dev/null +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/package-info.java @@ -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 Datastore. + * + *

A simple usage example: + *

 {@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);
+ * 
+ * // Do tests
+ * 
+ * gcdHelper.stop();
+ * } 
+ * + * @see + * gcloud-java tools for testing + */ +package com.google.gcloud.datastore.testing; diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreOptionsTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreOptionsTest.java index b3365876773e..f9200b3327e1 100644 --- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreOptionsTest.java +++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreOptionsTest.java @@ -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; diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java index e5f632d0fe14..0bef237ee48a 100644 --- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java +++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java @@ -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; diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelper.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java similarity index 94% rename from gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelper.java rename to gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java index f4c9b22a47b5..31c38a4048e3 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelper.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java @@ -14,11 +14,15 @@ * 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.RemoteGcsHelper.Option.KeyFromClasspath; +import com.google.gcloud.storage.BlobInfo; +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; @@ -96,7 +100,7 @@ public static String generateBucketName() { * * @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 */ diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java new file mode 100644 index 000000000000..32923bd180ef --- /dev/null +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java @@ -0,0 +1,35 @@ +/* + * 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. + * + *

A simple usage example, after setting the required environment variables (see the link below): + *

 {@code
+ * RemoteGcsHelper gcsHelper = RemoteGcsHelper.create();
+ * Storage storage = StorageFactory.instance().get(gcsHelper.options());
+ * String bucket = RemoteGcsHelper.generateBucketName();
+ * storage.create(BucketInfo.of(bucket));
+ * 
+ * // Do tests
+ * 
+ * RemoteGcsHelper.forceDelete(storage, bucket, 5, TimeUnit.SECONDS);
+ * } 
+ * + * @see + * gcloud-java tools for testing + */ +package com.google.gcloud.storage.testing; \ No newline at end of file diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java index d2056e8cbbb1..424bb061cf74 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java @@ -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; From bfae66745c8aee8d1eb9fe18feb2873c8307415e Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Wed, 7 Oct 2015 16:15:23 -0700 Subject: [PATCH 2/3] Fix javadoc link --- .../java/com/google/gcloud/storage/testing/RemoteGcsHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java index 31c38a4048e3..60cad7032178 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java @@ -57,7 +57,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; From d8478d7f445682488bcfc60a57be392e299146a1 Mon Sep 17 00:00:00 2001 From: Ajay Kannan Date: Thu, 8 Oct 2015 08:53:12 -0700 Subject: [PATCH 3/3] Update examples in package-info --- .../gcloud/datastore/testing/package-info.java | 8 +++++--- .../gcloud/storage/testing/package-info.java | 16 +++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/package-info.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/package-info.java index f53e50aac27c..9d20b3c7ffd8 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/package-info.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/package-info.java @@ -18,6 +18,7 @@ * A testing helper for Google Cloud Datastore. * *

A simple usage example: + *

Before the test: *

 {@code
  * LocalGcdHelper gcdHelper = LocalGcdHelper.start(PROJECT_ID, PORT_NUMBER);
  * DatastoreOptions options = DatastoreOptions.builder()
@@ -25,13 +26,14 @@
  *     .host("localhost:8080")
  *     .build();
  * Datastore localDatastore = DatastoreFactory.instance().get(options);
+ * } 
* - * // Do tests - * + *

After the test: + *

 {@code
  * gcdHelper.stop();
  * } 
* - * @see + * @see * gcloud-java tools for testing */ package com.google.gcloud.datastore.testing; diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java index 32923bd180ef..eca45b4b6306 100644 --- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java +++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java @@ -17,19 +17,21 @@ /** * A testing helper for Google Cloud Storage. * - *

A simple usage example, after setting the required environment variables (see the link below): + *

A simple usage example: + *

Before the test: *

 {@code
- * RemoteGcsHelper gcsHelper = RemoteGcsHelper.create();
+ * 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));
- * 
- * // Do tests
- * 
+ * } 
+ * + *

After the test: + *

 {@code
  * RemoteGcsHelper.forceDelete(storage, bucket, 5, TimeUnit.SECONDS);
  * } 
* - * @see + * @see * gcloud-java tools for testing */ -package com.google.gcloud.storage.testing; \ No newline at end of file +package com.google.gcloud.storage.testing;