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 a4a87f8d8153..1e154e3f8eea 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 @@ -16,20 +16,17 @@ 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.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; import java.io.InputStream; import java.io.IOException; -import java.util.Map; import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; @@ -134,29 +131,14 @@ public static RemoteGcsHelper create(String projectId, InputStream keyStream) * * @param projectId id of the project to be used for running the tests * @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.testing.RemoteGcsHelper.GcsHelperException if the file * pointed by {@code keyPath} does not exist */ - public static RemoteGcsHelper create(String projectId, String keyPath, Option... options) + public static RemoteGcsHelper create(String projectId, String keyPath) throws GcsHelperException { - boolean keyFromClassPath = false; - Map, Option> optionsMap = Option.asImmutableMap(options); - if (optionsMap.containsKey(KeyFromClasspath.class)) { - keyFromClassPath = - ((KeyFromClasspath) optionsMap.get(KeyFromClasspath.class)).keyFromClasspath(); - } try { - InputStream keyFileStream; - if (keyFromClassPath) { - keyFileStream = RemoteGcsHelper.class.getResourceAsStream(keyPath); - if (keyFileStream == null) { - throw new FileNotFoundException(keyPath + " not found in classpath"); - } - } else { - keyFileStream = new FileInputStream(keyPath); - } + InputStream keyFileStream = new FileInputStream(keyPath); return create(projectId, keyFileStream); } catch (FileNotFoundException ex) { if (log.isLoggable(Level.WARNING)) { @@ -175,13 +157,12 @@ public static RemoteGcsHelper create(String projectId, String keyPath, Option... * Creates a {@code RemoteGcsHelper} object. Project id and path to JSON key are read from two * environment variables: {@code GCLOUD_TESTS_PROJECT_ID} and {@code GCLOUD_TESTS_KEY}. * - * @param options creation options * @return A {@code RemoteGcsHelper} object for the provided options. * @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 */ - public static RemoteGcsHelper create(Option... options) throws GcsHelperException { + public static RemoteGcsHelper create() throws GcsHelperException { String projectId = System.getenv(PROJECT_ID_ENV_VAR); String keyPath = System.getenv(PRIVATE_KEY_ENV_VAR); if (projectId == null) { @@ -198,7 +179,7 @@ public static RemoteGcsHelper create(Option... options) throws GcsHelperExceptio } throw new GcsHelperException(message); } - return create(projectId, keyPath, options); + return create(projectId, keyPath); } private static class DeleteBucketTask implements Callable { @@ -231,42 +212,6 @@ public Boolean call() throws Exception { } } - public static abstract class Option implements java.io.Serializable { - - private static final long serialVersionUID = 8849118657896662369L; - - public static final class KeyFromClasspath extends Option { - - private static final long serialVersionUID = -5506049413185246821L; - - private final boolean keyFromClasspath; - - public KeyFromClasspath(boolean keyFromClasspath) { - this.keyFromClasspath = keyFromClasspath; - } - - public boolean keyFromClasspath() { - return keyFromClasspath; - } - } - - Option() { - // package protected - } - - public static KeyFromClasspath keyFromClassPath() { - return new KeyFromClasspath(true); - } - - static Map, Option> asImmutableMap(Option... options) { - ImmutableMap.Builder, Option> builder = ImmutableMap.builder(); - for (Option option : options) { - builder.put(option.getClass(), option); - } - return builder.build(); - } - } - public static class GcsHelperException extends RuntimeException { private static final long serialVersionUID = -7756074894502258736L; diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelperTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelperTest.java index 2be228623dde..3cd67701e92b 100644 --- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelperTest.java +++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelperTest.java @@ -166,11 +166,4 @@ public void testCreateNoKey() { thrown.expectMessage(KEY_PATH + " (No such file or directory)"); RemoteGcsHelper.create(PROJECT_ID, KEY_PATH); } - - @Test - public void testCreateNoKeyWithOption() { - thrown.expect(RemoteGcsHelper.GcsHelperException.class); - thrown.expectMessage(KEY_PATH + " not found in classpath"); - RemoteGcsHelper.create(PROJECT_ID, KEY_PATH, RemoteGcsHelper.Option.keyFromClassPath()); - } }