From ea2adcc92bc7bcb162abdacfd0c31a9310b88ff8 Mon Sep 17 00:00:00 2001 From: dmitry-fa Date: Thu, 4 Jun 2020 10:45:50 +0300 Subject: [PATCH 1/3] feat: stub implementation of StorageRpc which could be used outside of the storage module for testing purposes --- .../storage/testing/StorageRpcTestBase.java | 505 ++++++++++++++ .../testing/StorageRpcTestBaseTest.java | 628 ++++++++++++++++++ 2 files changed, 1133 insertions(+) create mode 100644 google-cloud-storage/src/main/java/com/google/cloud/storage/testing/StorageRpcTestBase.java create mode 100644 google-cloud-storage/src/test/java/com/google/cloud/storage/testing/StorageRpcTestBaseTest.java diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/testing/StorageRpcTestBase.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/testing/StorageRpcTestBase.java new file mode 100644 index 000000000..5bfdc902b --- /dev/null +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/testing/StorageRpcTestBase.java @@ -0,0 +1,505 @@ +/* + * Copyright 2020 Google LLC + * + * 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. + */ + +package com.google.cloud.storage.testing; + +import com.google.api.services.storage.model.Bucket; +import com.google.api.services.storage.model.BucketAccessControl; +import com.google.api.services.storage.model.HmacKey; +import com.google.api.services.storage.model.HmacKeyMetadata; +import com.google.api.services.storage.model.Notification; +import com.google.api.services.storage.model.ObjectAccessControl; +import com.google.api.services.storage.model.Policy; +import com.google.api.services.storage.model.ServiceAccount; +import com.google.api.services.storage.model.StorageObject; +import com.google.api.services.storage.model.TestIamPermissionsResponse; +import com.google.cloud.Tuple; +import com.google.cloud.storage.spi.v1.RpcBatch; +import com.google.cloud.storage.spi.v1.StorageRpc; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.List; +import java.util.Map; + +/** + * A stub implementation of {@link StorageRpc} which could be used outside of the Storage module for + * testing purposes. All the methods are implemented either to return the default value or to throw + * an {@code UnsupportedOperationException}, depending on the boolean parameter given to create an + * instance. {@code new StorageRpcTestBase()} and {@code new StorageRpcTestBase(true)} create an + * instance with methods returning a value. {@code new StorageRpcTestBase(false)} creates an + * instance which methods throwing the exception. + */ +public class StorageRpcTestBase implements StorageRpc { + + private final boolean isImplemented; + + /** Creates an instance with methods returning the default value. */ + public StorageRpcTestBase() { + this(true); + } + + /** + * Creates an instance with methods either returning the default value or throwing {@code + * UnsupportedOperationException}, depending on the {@code isImplemented} parameter. + * + * @param isImplemented {@code true} to return a value, {@code false} to throw an exception. + */ + public StorageRpcTestBase(boolean isImplemented) { + this.isImplemented = isImplemented; + } + + @Override + public Bucket create(Bucket bucket, Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public StorageObject create(StorageObject object, InputStream content, Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public Tuple> list(Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public Tuple> list(String bucket, Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public Bucket get(Bucket bucket, Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public StorageObject get(StorageObject object, Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public Bucket patch(Bucket bucket, Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public StorageObject patch(StorageObject storageObject, Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public boolean delete(Bucket bucket, Map options) { + if (isImplemented) { + return false; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public boolean delete(StorageObject object, Map options) { + if (isImplemented) { + return false; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public RpcBatch createBatch() { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public StorageObject compose( + Iterable sources, StorageObject target, Map targetOptions) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public byte[] load(StorageObject storageObject, Map options) { + if (isImplemented) { + return new byte[0]; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public Tuple read( + StorageObject from, Map options, long position, int bytes) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public long read( + StorageObject from, Map options, long position, OutputStream outputStream) { + if (isImplemented) { + return 0; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public String open(StorageObject object, Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public String open(String signedURL) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public void write( + String uploadId, + byte[] toWrite, + int toWriteOffset, + long destOffset, + int length, + boolean last) { + if (isImplemented) { + return; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public RewriteResponse openRewrite(RewriteRequest rewriteRequest) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public RewriteResponse continueRewrite(RewriteResponse previousResponse) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public BucketAccessControl getAcl(String bucket, String entity, Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public boolean deleteAcl(String bucket, String entity, Map options) { + if (isImplemented) { + return false; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public BucketAccessControl createAcl(BucketAccessControl acl, Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public BucketAccessControl patchAcl(BucketAccessControl acl, Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public List listAcls(String bucket, Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public ObjectAccessControl getDefaultAcl(String bucket, String entity) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public boolean deleteDefaultAcl(String bucket, String entity) { + if (isImplemented) { + return false; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public ObjectAccessControl createDefaultAcl(ObjectAccessControl acl) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public ObjectAccessControl patchDefaultAcl(ObjectAccessControl acl) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public List listDefaultAcls(String bucket) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public ObjectAccessControl getAcl(String bucket, String object, Long generation, String entity) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public boolean deleteAcl(String bucket, String object, Long generation, String entity) { + if (isImplemented) { + return false; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public ObjectAccessControl createAcl(ObjectAccessControl acl) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public ObjectAccessControl patchAcl(ObjectAccessControl acl) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public List listAcls(String bucket, String object, Long generation) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public HmacKey createHmacKey(String serviceAccountEmail, Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public Tuple> listHmacKeys(Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public HmacKeyMetadata updateHmacKey(HmacKeyMetadata hmacKeyMetadata, Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public HmacKeyMetadata getHmacKey(String accessId, Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public void deleteHmacKey(HmacKeyMetadata hmacKeyMetadata, Map options) { + if (isImplemented) { + return; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public Policy getIamPolicy(String bucket, Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public Policy setIamPolicy(String bucket, Policy policy, Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public TestIamPermissionsResponse testIamPermissions( + String bucket, List permissions, Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public boolean deleteNotification(String bucket, String notification) { + if (isImplemented) { + return false; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public List listNotifications(String bucket) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public Notification createNotification(String bucket, Notification notification) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public Bucket lockRetentionPolicy(Bucket bucket, Map options) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } + + @Override + public ServiceAccount getServiceAccount(String projectId) { + if (isImplemented) { + return null; + } else { + throw new UnsupportedOperationException("Not implemented yet"); + } + } +} diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/testing/StorageRpcTestBaseTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/testing/StorageRpcTestBaseTest.java new file mode 100644 index 000000000..3f7d6ffb6 --- /dev/null +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/testing/StorageRpcTestBaseTest.java @@ -0,0 +1,628 @@ +/* + * Copyright 2020 Google LLC + * + * 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. + */ + +package com.google.cloud.storage.testing; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import com.google.api.services.storage.model.Bucket; +import com.google.api.services.storage.model.BucketAccessControl; +import com.google.api.services.storage.model.HmacKey; +import com.google.api.services.storage.model.HmacKeyMetadata; +import com.google.api.services.storage.model.Notification; +import com.google.api.services.storage.model.ObjectAccessControl; +import com.google.api.services.storage.model.Policy; +import com.google.api.services.storage.model.ServiceAccount; +import com.google.api.services.storage.model.StorageObject; +import com.google.api.services.storage.model.TestIamPermissionsResponse; +import com.google.cloud.Tuple; +import com.google.cloud.storage.spi.v1.RpcBatch; +import com.google.cloud.storage.spi.v1.StorageRpc; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class StorageRpcTestBaseTest { + + private StorageRpc valueInstance; + private StorageRpc exceptionInstance; + private RpcCall call; + + private static final Map OPTIONS = new HashMap<>(); + private static final Bucket BUCKET = new Bucket().setName("fake-bucket"); + private static final byte[] BYTES = {0, 1, 2, 3, 4, 5, 6, 7}; + private static final StorageObject OBJECT = + new StorageObject().setName("object name").setBucket("bucket name"); + + @Before + public void setUp() { + valueInstance = new StorageRpcTestBase(); + exceptionInstance = new StorageRpcTestBase(false); + call = null; + } + + @After + public void tearDown() { + assertNotNull(call); + verifyUnsupported(call); + verifyReturnValue(call); + } + + interface RpcCall { + V call(StorageRpc storageRpc); + } + + private void verifyUnsupported(RpcCall rpcCall) { + try { + rpcCall.call(exceptionInstance); + fail("UnsupportedOperationException expected"); + } catch (UnsupportedOperationException e) { + // expected + } + } + + private void verifyReturnValue(RpcCall rpcCall) { + Object value = rpcCall.call(valueInstance); + if (value instanceof Boolean) { + assertEquals(Boolean.FALSE, value); + } else if (value instanceof Long) { + assertEquals(new Long(0), value); + } else if (value instanceof byte[]) { + assertArrayEquals(new byte[0], (byte[]) value); + } else { + assertNull(value); + } + } + + @Test + public void testCreateBucket() { + call = + new RpcCall() { + @Override + public Bucket call(StorageRpc storageRpc) { + return storageRpc.create(BUCKET, OPTIONS); + } + }; + } + + @Test + public void testCreateObject() { + call = + new RpcCall() { + @Override + public StorageObject call(StorageRpc storageRpc) { + return storageRpc.create(OBJECT, new ByteArrayInputStream(BYTES), OPTIONS); + } + }; + } + + @Test + public void testList() { + call = + new RpcCall>>() { + @Override + public Tuple> call(StorageRpc storageRpc) { + return storageRpc.list(OPTIONS); + } + }; + } + + @Test + public void testListBucket() { + call = + new RpcCall>>() { + @Override + public Tuple> call(StorageRpc storageRpc) { + return storageRpc.list(BUCKET.getName(), OPTIONS); + } + }; + } + + @Test + public void testGetBucket() { + call = + new RpcCall() { + @Override + public Bucket call(StorageRpc storageRpc) { + return storageRpc.get(BUCKET, OPTIONS); + } + }; + } + + @Test + public void testGetObject() { + call = + new RpcCall() { + @Override + public StorageObject call(StorageRpc storageRpc) { + return storageRpc.get(OBJECT, OPTIONS); + } + }; + } + + @Test + public void testPatchBucket() { + call = + new RpcCall() { + @Override + public Bucket call(StorageRpc storageRpc) { + return storageRpc.patch(BUCKET, OPTIONS); + } + }; + } + + @Test + public void testPatchObject() { + call = + new RpcCall() { + @Override + public StorageObject call(StorageRpc storageRpc) { + return storageRpc.patch(OBJECT, OPTIONS); + } + }; + } + + @Test + public void testDeleteBucket() { + call = + new RpcCall() { + @Override + public Boolean call(StorageRpc storageRpc) { + return storageRpc.delete(BUCKET, OPTIONS); + } + }; + } + + @Test + public void testDeleteObject() { + call = + new RpcCall() { + @Override + public Boolean call(StorageRpc storageRpc) { + return storageRpc.delete(OBJECT, OPTIONS); + } + }; + } + + @Test + public void testCreateBatch() { + call = + new RpcCall() { + @Override + public RpcBatch call(StorageRpc storageRpc) { + return storageRpc.createBatch(); + } + }; + } + + @Test + public void testCompose() { + call = + new RpcCall() { + @Override + public StorageObject call(StorageRpc storageRpc) { + return storageRpc.compose(null, OBJECT, OPTIONS); + } + }; + } + + @Test + public void testLoad() { + call = + new RpcCall() { + @Override + public byte[] call(StorageRpc storageRpc) { + return storageRpc.load(OBJECT, OPTIONS); + } + }; + } + + @Test + public void testReadBytes() { + call = + new RpcCall>() { + @Override + public Tuple call(StorageRpc storageRpc) { + return storageRpc.read(OBJECT, OPTIONS, 0, 0); + } + }; + } + + @Test + public void testReadOutputStream() { + call = + new RpcCall() { + @Override + public Long call(StorageRpc storageRpc) { + return storageRpc.read(OBJECT, OPTIONS, 0, new ByteArrayOutputStream(100)); + } + }; + } + + @Test + public void testOpenObject() { + call = + new RpcCall() { + @Override + public String call(StorageRpc storageRpc) { + return storageRpc.open(OBJECT, OPTIONS); + } + }; + } + + @Test + public void testOpenSignedURL() { + call = + new RpcCall() { + @Override + public String call(StorageRpc storageRpc) { + return storageRpc.open("signedURL"); + } + }; + } + + @Test + public void testWrite() { + call = + new RpcCall() { + @Override + public Void call(StorageRpc storageRpc) { + storageRpc.write("uploadId", new byte[10], 1, 2L, 3, false); + return null; + } + }; + } + + @Test + public void testOpenRewrite() { + call = + new RpcCall() { + @Override + public StorageRpc.RewriteResponse call(StorageRpc storageRpc) { + return storageRpc.openRewrite(null); + } + }; + } + + @Test + public void testContinueRewrite() { + call = + new RpcCall() { + @Override + public StorageRpc.RewriteResponse call(StorageRpc storageRpc) { + return storageRpc.continueRewrite(null); + } + }; + } + + @Test + public void testGetAclBucket() { + call = + new RpcCall() { + @Override + public BucketAccessControl call(StorageRpc storageRpc) { + return storageRpc.getAcl("bucket", "entity", OPTIONS); + } + }; + } + + @Test + public void testGetAclObject() { + call = + new RpcCall() { + @Override + public ObjectAccessControl call(StorageRpc storageRpc) { + return storageRpc.getAcl("bucket", "object", 1L, "entity"); + } + }; + } + + @Test + public void testDeleteAclBucket() { + call = + new RpcCall() { + @Override + public Boolean call(StorageRpc storageRpc) { + return storageRpc.deleteAcl("bucketName", "entity", OPTIONS); + } + }; + } + + @Test + public void testDeleteAclObject() { + call = + new RpcCall() { + @Override + public Boolean call(StorageRpc storageRpc) { + return storageRpc.deleteAcl("bucketName", "object", 0L, "entity"); + } + }; + } + + @Test + public void testCreateAclBucket() { + call = + new RpcCall() { + @Override + public BucketAccessControl call(StorageRpc storageRpc) { + return storageRpc.createAcl(null, OPTIONS); + } + }; + } + + @Test + public void testCreateAclObject() { + call = + new RpcCall() { + @Override + public ObjectAccessControl call(StorageRpc storageRpc) { + return storageRpc.createAcl(null); + } + }; + } + + @Test + public void testPatchAclBucket() { + call = + new RpcCall() { + @Override + public ObjectAccessControl call(StorageRpc storageRpc) { + return storageRpc.createAcl(null); + } + }; + } + + @Test + public void testPatchAclObject() { + call = + new RpcCall() { + @Override + public ObjectAccessControl call(StorageRpc storageRpc) { + return storageRpc.patchAcl(null); + } + }; + } + + @Test + public void testListAclsBucket() { + call = + new RpcCall>() { + @Override + public List call(StorageRpc storageRpc) { + return storageRpc.listAcls("BUCKET_NAME", OPTIONS); + } + }; + } + + @Test + public void testListAclsObject() { + call = + new RpcCall>() { + @Override + public List call(StorageRpc storageRpc) { + return storageRpc.listAcls("BUCKET_NAME", "OBJECT_NAME", 100L); + } + }; + } + + @Test + public void testCreateHmacKey() { + call = + new RpcCall() { + @Override + public HmacKey call(StorageRpc storageRpc) { + return storageRpc.createHmacKey("account", OPTIONS); + } + }; + } + + @Test + public void testListHmacKeys() { + call = + new RpcCall>>() { + @Override + public Tuple> call(StorageRpc storageRpc) { + return storageRpc.listHmacKeys(OPTIONS); + } + }; + } + + @Test + public void testUpdateHmacKey() { + call = + new RpcCall() { + @Override + public HmacKeyMetadata call(StorageRpc storageRpc) { + return storageRpc.updateHmacKey(null, OPTIONS); + } + }; + } + + @Test + public void testGetHmacKey() { + call = + new RpcCall() { + @Override + public HmacKeyMetadata call(StorageRpc storageRpc) { + return storageRpc.getHmacKey("account", OPTIONS); + } + }; + } + + @Test + public void testDeleteHmacKey() { + call = + new RpcCall() { + @Override + public Void call(StorageRpc storageRpc) { + storageRpc.deleteHmacKey(null, OPTIONS); + return null; + } + }; + } + + @Test + public void testGetDefaultAcl() { + call = + new RpcCall() { + @Override + public ObjectAccessControl call(StorageRpc storageRpc) { + return storageRpc.getDefaultAcl("bucket", "entity"); + } + }; + } + + @Test + public void testDeleteDefaultAcl() { + call = + new RpcCall() { + @Override + public Boolean call(StorageRpc storageRpc) { + return storageRpc.deleteDefaultAcl("bucket", "entity"); + } + }; + } + + @Test + public void testCreateDefaultAcl() { + call = + new RpcCall() { + @Override + public ObjectAccessControl call(StorageRpc storageRpc) { + return storageRpc.createDefaultAcl(null); + } + }; + } + + @Test + public void testPatchDefaultAcl() { + call = + new RpcCall() { + @Override + public ObjectAccessControl call(StorageRpc storageRpc) { + return storageRpc.patchDefaultAcl(null); + } + }; + } + + @Test + public void testListDefaultAcls() { + call = + new RpcCall>() { + @Override + public List call(StorageRpc storageRpc) { + return storageRpc.listDefaultAcls("bucket"); + } + }; + } + + @Test + public void testGetIamPolicy() { + call = + new RpcCall() { + @Override + public Policy call(StorageRpc storageRpc) { + return storageRpc.getIamPolicy("bucket", OPTIONS); + } + }; + } + + @Test + public void testSetIamPolicy() { + call = + new RpcCall() { + @Override + public Policy call(StorageRpc storageRpc) { + return storageRpc.setIamPolicy("bucket", null, OPTIONS); + } + }; + } + + @Test + public void testTestIamPermissions() { + call = + new RpcCall() { + @Override + public TestIamPermissionsResponse call(StorageRpc storageRpc) { + return storageRpc.testIamPermissions("bucket", null, OPTIONS); + } + }; + } + + @Test + public void testDeleteNotification() { + call = + new RpcCall() { + @Override + public Boolean call(StorageRpc storageRpc) { + return storageRpc.deleteNotification("bucket", "entity"); + } + }; + } + + @Test + public void testListNotifications() { + call = + new RpcCall>() { + @Override + public List call(StorageRpc storageRpc) { + return storageRpc.listNotifications("bucket"); + } + }; + } + + @Test + public void testCreateNotification() { + call = + new RpcCall() { + @Override + public Notification call(StorageRpc storageRpc) { + return storageRpc.createNotification("bucket", null); + } + }; + } + + @Test + public void testLockRetentionPolicy() { + call = + new RpcCall() { + @Override + public Bucket call(StorageRpc storageRpc) { + return storageRpc.lockRetentionPolicy(BUCKET, OPTIONS); + } + }; + } + + @Test + public void testGetServiceAccount() { + call = + new RpcCall() { + @Override + public ServiceAccount call(StorageRpc storageRpc) { + return storageRpc.getServiceAccount("project"); + } + }; + } +} From 0d30a66cf46ca9b9dccd6515bf2fb9da8bf55519 Mon Sep 17 00:00:00 2001 From: dmitry-fa Date: Fri, 5 Jun 2020 18:38:52 +0300 Subject: [PATCH 2/3] feat: stub implementation of StorageRpc which could be used outside of the storage module for testing purposes --- .../cloud/storage/testing/StorageRpcTestBase.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/testing/StorageRpcTestBase.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/testing/StorageRpcTestBase.java index 5bfdc902b..48e55e243 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/testing/StorageRpcTestBase.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/testing/StorageRpcTestBase.java @@ -35,12 +35,12 @@ import java.util.Map; /** - * A stub implementation of {@link StorageRpc} which could be used outside of the Storage module for - * testing purposes. All the methods are implemented either to return the default value or to throw - * an {@code UnsupportedOperationException}, depending on the boolean parameter given to create an - * instance. {@code new StorageRpcTestBase()} and {@code new StorageRpcTestBase(true)} create an - * instance with methods returning a value. {@code new StorageRpcTestBase(false)} creates an - * instance which methods throwing the exception. + * A stub implementation of {@link StorageRpc} which can be used outside of the Storage module for + * testing purposes. All the methods either return the default value or throw an {@code + * UnsupportedOperationException}, depending on the boolean parameter given to create an instance. + * {@code new StorageRpcTestBase()} and {@code new StorageRpcTestBase(true)} create an instance with + * methods returning a value. {@code new StorageRpcTestBase(false)} creates an instance which + * methods throwing the exception. */ public class StorageRpcTestBase implements StorageRpc { @@ -55,7 +55,7 @@ public StorageRpcTestBase() { * Creates an instance with methods either returning the default value or throwing {@code * UnsupportedOperationException}, depending on the {@code isImplemented} parameter. * - * @param isImplemented {@code true} to return a value, {@code false} to throw an exception. + * @param isImplemented {@code true} to return a value, {@code false} to throw an exception */ public StorageRpcTestBase(boolean isImplemented) { this.isImplemented = isImplemented; From 1b95a56408aff6d7729c295d5e6f2e49c84a5512 Mon Sep 17 00:00:00 2001 From: dmitry-fa Date: Mon, 8 Jun 2020 15:28:45 +0300 Subject: [PATCH 3/3] feat: stub implementation of StorageRpc which could be used outside of the storage module for testing purposes --- .../storage/testing/StorageRpcTestBase.java | 311 ++----------- .../testing/StorageRpcTestBaseTest.java | 425 ++++++++---------- 2 files changed, 248 insertions(+), 488 deletions(-) diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/testing/StorageRpcTestBase.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/testing/StorageRpcTestBase.java index 48e55e243..6bd2d487e 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/testing/StorageRpcTestBase.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/testing/StorageRpcTestBase.java @@ -36,185 +36,96 @@ /** * A stub implementation of {@link StorageRpc} which can be used outside of the Storage module for - * testing purposes. All the methods either return the default value or throw an {@code - * UnsupportedOperationException}, depending on the boolean parameter given to create an instance. - * {@code new StorageRpcTestBase()} and {@code new StorageRpcTestBase(true)} create an instance with - * methods returning a value. {@code new StorageRpcTestBase(false)} creates an instance which - * methods throwing the exception. + * testing purposes. All the methods throw an {@code UnsupportedOperationException}. */ public class StorageRpcTestBase implements StorageRpc { - private final boolean isImplemented; - - /** Creates an instance with methods returning the default value. */ - public StorageRpcTestBase() { - this(true); - } - - /** - * Creates an instance with methods either returning the default value or throwing {@code - * UnsupportedOperationException}, depending on the {@code isImplemented} parameter. - * - * @param isImplemented {@code true} to return a value, {@code false} to throw an exception - */ - public StorageRpcTestBase(boolean isImplemented) { - this.isImplemented = isImplemented; - } - @Override public Bucket create(Bucket bucket, Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public StorageObject create(StorageObject object, InputStream content, Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public Tuple> list(Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public Tuple> list(String bucket, Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public Bucket get(Bucket bucket, Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public StorageObject get(StorageObject object, Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public Bucket patch(Bucket bucket, Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public StorageObject patch(StorageObject storageObject, Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public boolean delete(Bucket bucket, Map options) { - if (isImplemented) { - return false; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public boolean delete(StorageObject object, Map options) { - if (isImplemented) { - return false; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public RpcBatch createBatch() { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public StorageObject compose( Iterable sources, StorageObject target, Map targetOptions) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public byte[] load(StorageObject storageObject, Map options) { - if (isImplemented) { - return new byte[0]; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public Tuple read( StorageObject from, Map options, long position, int bytes) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public long read( StorageObject from, Map options, long position, OutputStream outputStream) { - if (isImplemented) { - return 0; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public String open(StorageObject object, Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public String open(String signedURL) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override @@ -225,281 +136,157 @@ public void write( long destOffset, int length, boolean last) { - if (isImplemented) { - return; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public RewriteResponse openRewrite(RewriteRequest rewriteRequest) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public RewriteResponse continueRewrite(RewriteResponse previousResponse) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public BucketAccessControl getAcl(String bucket, String entity, Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public boolean deleteAcl(String bucket, String entity, Map options) { - if (isImplemented) { - return false; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public BucketAccessControl createAcl(BucketAccessControl acl, Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public BucketAccessControl patchAcl(BucketAccessControl acl, Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public List listAcls(String bucket, Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public ObjectAccessControl getDefaultAcl(String bucket, String entity) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public boolean deleteDefaultAcl(String bucket, String entity) { - if (isImplemented) { - return false; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public ObjectAccessControl createDefaultAcl(ObjectAccessControl acl) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public ObjectAccessControl patchDefaultAcl(ObjectAccessControl acl) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public List listDefaultAcls(String bucket) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public ObjectAccessControl getAcl(String bucket, String object, Long generation, String entity) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public boolean deleteAcl(String bucket, String object, Long generation, String entity) { - if (isImplemented) { - return false; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public ObjectAccessControl createAcl(ObjectAccessControl acl) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public ObjectAccessControl patchAcl(ObjectAccessControl acl) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public List listAcls(String bucket, String object, Long generation) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public HmacKey createHmacKey(String serviceAccountEmail, Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public Tuple> listHmacKeys(Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public HmacKeyMetadata updateHmacKey(HmacKeyMetadata hmacKeyMetadata, Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public HmacKeyMetadata getHmacKey(String accessId, Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public void deleteHmacKey(HmacKeyMetadata hmacKeyMetadata, Map options) { - if (isImplemented) { - return; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public Policy getIamPolicy(String bucket, Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public Policy setIamPolicy(String bucket, Policy policy, Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public TestIamPermissionsResponse testIamPermissions( String bucket, List permissions, Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public boolean deleteNotification(String bucket, String notification) { - if (isImplemented) { - return false; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public List listNotifications(String bucket) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public Notification createNotification(String bucket, Notification notification) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public Bucket lockRetentionPolicy(Bucket bucket, Map options) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } @Override public ServiceAccount getServiceAccount(String projectId) { - if (isImplemented) { - return null; - } else { - throw new UnsupportedOperationException("Not implemented yet"); - } + throw new UnsupportedOperationException("Not implemented yet"); } } diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/testing/StorageRpcTestBaseTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/testing/StorageRpcTestBaseTest.java index 3f7d6ffb6..b798ad572 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/testing/StorageRpcTestBaseTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/testing/StorageRpcTestBaseTest.java @@ -16,10 +16,7 @@ package com.google.cloud.storage.testing; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; import com.google.api.services.storage.model.Bucket; @@ -40,16 +37,16 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.Callable; import org.junit.After; import org.junit.Before; import org.junit.Test; public class StorageRpcTestBaseTest { - private StorageRpc valueInstance; - private StorageRpc exceptionInstance; - private RpcCall call; + private Callable rpc; + private static final StorageRpc STORAGE_RPC = new StorageRpcTestBase(); private static final Map OPTIONS = new HashMap<>(); private static final Bucket BUCKET = new Bucket().setName("fake-bucket"); private static final byte[] BYTES = {0, 1, 2, 3, 4, 5, 6, 7}; @@ -58,238 +55,214 @@ public class StorageRpcTestBaseTest { @Before public void setUp() { - valueInstance = new StorageRpcTestBase(); - exceptionInstance = new StorageRpcTestBase(false); - call = null; + rpc = null; } @After - public void tearDown() { - assertNotNull(call); - verifyUnsupported(call); - verifyReturnValue(call); - } - - interface RpcCall { - V call(StorageRpc storageRpc); - } - - private void verifyUnsupported(RpcCall rpcCall) { + public void tearDown() throws Exception { + assertNotNull(rpc); try { - rpcCall.call(exceptionInstance); + rpc.call(); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException e) { // expected } } - private void verifyReturnValue(RpcCall rpcCall) { - Object value = rpcCall.call(valueInstance); - if (value instanceof Boolean) { - assertEquals(Boolean.FALSE, value); - } else if (value instanceof Long) { - assertEquals(new Long(0), value); - } else if (value instanceof byte[]) { - assertArrayEquals(new byte[0], (byte[]) value); - } else { - assertNull(value); - } - } - @Test public void testCreateBucket() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public Bucket call(StorageRpc storageRpc) { - return storageRpc.create(BUCKET, OPTIONS); + public Bucket call() { + return STORAGE_RPC.create(BUCKET, OPTIONS); } }; } @Test public void testCreateObject() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public StorageObject call(StorageRpc storageRpc) { - return storageRpc.create(OBJECT, new ByteArrayInputStream(BYTES), OPTIONS); + public StorageObject call() { + return STORAGE_RPC.create(OBJECT, new ByteArrayInputStream(BYTES), OPTIONS); } }; } @Test public void testList() { - call = - new RpcCall>>() { + rpc = + new Callable>>() { @Override - public Tuple> call(StorageRpc storageRpc) { - return storageRpc.list(OPTIONS); + public Tuple> call() { + return STORAGE_RPC.list(OPTIONS); } }; } @Test public void testListBucket() { - call = - new RpcCall>>() { + rpc = + new Callable>>() { @Override - public Tuple> call(StorageRpc storageRpc) { - return storageRpc.list(BUCKET.getName(), OPTIONS); + public Tuple> call() { + return STORAGE_RPC.list(BUCKET.getName(), OPTIONS); } }; } @Test public void testGetBucket() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public Bucket call(StorageRpc storageRpc) { - return storageRpc.get(BUCKET, OPTIONS); + public Bucket call() { + return STORAGE_RPC.get(BUCKET, OPTIONS); } }; } @Test public void testGetObject() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public StorageObject call(StorageRpc storageRpc) { - return storageRpc.get(OBJECT, OPTIONS); + public StorageObject call() { + return STORAGE_RPC.get(OBJECT, OPTIONS); } }; } @Test public void testPatchBucket() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public Bucket call(StorageRpc storageRpc) { - return storageRpc.patch(BUCKET, OPTIONS); + public Bucket call() { + return STORAGE_RPC.patch(BUCKET, OPTIONS); } }; } @Test public void testPatchObject() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public StorageObject call(StorageRpc storageRpc) { - return storageRpc.patch(OBJECT, OPTIONS); + public StorageObject call() { + return STORAGE_RPC.patch(OBJECT, OPTIONS); } }; } @Test public void testDeleteBucket() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public Boolean call(StorageRpc storageRpc) { - return storageRpc.delete(BUCKET, OPTIONS); + public Boolean call() { + return STORAGE_RPC.delete(BUCKET, OPTIONS); } }; } @Test public void testDeleteObject() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public Boolean call(StorageRpc storageRpc) { - return storageRpc.delete(OBJECT, OPTIONS); + public Boolean call() { + return STORAGE_RPC.delete(OBJECT, OPTIONS); } }; } @Test public void testCreateBatch() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public RpcBatch call(StorageRpc storageRpc) { - return storageRpc.createBatch(); + public RpcBatch call() { + return STORAGE_RPC.createBatch(); } }; } @Test public void testCompose() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public StorageObject call(StorageRpc storageRpc) { - return storageRpc.compose(null, OBJECT, OPTIONS); + public StorageObject call() { + return STORAGE_RPC.compose(null, OBJECT, OPTIONS); } }; } @Test public void testLoad() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public byte[] call(StorageRpc storageRpc) { - return storageRpc.load(OBJECT, OPTIONS); + public byte[] call() { + return STORAGE_RPC.load(OBJECT, OPTIONS); } }; } @Test public void testReadBytes() { - call = - new RpcCall>() { + rpc = + new Callable>() { @Override - public Tuple call(StorageRpc storageRpc) { - return storageRpc.read(OBJECT, OPTIONS, 0, 0); + public Tuple call() { + return STORAGE_RPC.read(OBJECT, OPTIONS, 0, 0); } }; } @Test public void testReadOutputStream() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public Long call(StorageRpc storageRpc) { - return storageRpc.read(OBJECT, OPTIONS, 0, new ByteArrayOutputStream(100)); + public Long call() { + return STORAGE_RPC.read(OBJECT, OPTIONS, 0, new ByteArrayOutputStream(100)); } }; } @Test public void testOpenObject() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public String call(StorageRpc storageRpc) { - return storageRpc.open(OBJECT, OPTIONS); + public String call() { + return STORAGE_RPC.open(OBJECT, OPTIONS); } }; } @Test public void testOpenSignedURL() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public String call(StorageRpc storageRpc) { - return storageRpc.open("signedURL"); + public String call() { + return STORAGE_RPC.open("signedURL"); } }; } @Test public void testWrite() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public Void call(StorageRpc storageRpc) { - storageRpc.write("uploadId", new byte[10], 1, 2L, 3, false); + public Void call() { + STORAGE_RPC.write("uploadId", new byte[10], 1, 2L, 3, false); return null; } }; @@ -297,187 +270,187 @@ public Void call(StorageRpc storageRpc) { @Test public void testOpenRewrite() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public StorageRpc.RewriteResponse call(StorageRpc storageRpc) { - return storageRpc.openRewrite(null); + public StorageRpc.RewriteResponse call() { + return STORAGE_RPC.openRewrite(null); } }; } @Test public void testContinueRewrite() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public StorageRpc.RewriteResponse call(StorageRpc storageRpc) { - return storageRpc.continueRewrite(null); + public StorageRpc.RewriteResponse call() { + return STORAGE_RPC.continueRewrite(null); } }; } @Test public void testGetAclBucket() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public BucketAccessControl call(StorageRpc storageRpc) { - return storageRpc.getAcl("bucket", "entity", OPTIONS); + public BucketAccessControl call() { + return STORAGE_RPC.getAcl("bucket", "entity", OPTIONS); } }; } @Test public void testGetAclObject() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public ObjectAccessControl call(StorageRpc storageRpc) { - return storageRpc.getAcl("bucket", "object", 1L, "entity"); + public ObjectAccessControl call() { + return STORAGE_RPC.getAcl("bucket", "object", 1L, "entity"); } }; } @Test public void testDeleteAclBucket() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public Boolean call(StorageRpc storageRpc) { - return storageRpc.deleteAcl("bucketName", "entity", OPTIONS); + public Boolean call() { + return STORAGE_RPC.deleteAcl("bucketName", "entity", OPTIONS); } }; } @Test public void testDeleteAclObject() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public Boolean call(StorageRpc storageRpc) { - return storageRpc.deleteAcl("bucketName", "object", 0L, "entity"); + public Boolean call() { + return STORAGE_RPC.deleteAcl("bucketName", "object", 0L, "entity"); } }; } @Test public void testCreateAclBucket() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public BucketAccessControl call(StorageRpc storageRpc) { - return storageRpc.createAcl(null, OPTIONS); + public BucketAccessControl call() { + return STORAGE_RPC.createAcl(null, OPTIONS); } }; } @Test public void testCreateAclObject() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public ObjectAccessControl call(StorageRpc storageRpc) { - return storageRpc.createAcl(null); + public ObjectAccessControl call() { + return STORAGE_RPC.createAcl(null); } }; } @Test public void testPatchAclBucket() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public ObjectAccessControl call(StorageRpc storageRpc) { - return storageRpc.createAcl(null); + public ObjectAccessControl call() { + return STORAGE_RPC.createAcl(null); } }; } @Test public void testPatchAclObject() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public ObjectAccessControl call(StorageRpc storageRpc) { - return storageRpc.patchAcl(null); + public ObjectAccessControl call() { + return STORAGE_RPC.patchAcl(null); } }; } @Test public void testListAclsBucket() { - call = - new RpcCall>() { + rpc = + new Callable>() { @Override - public List call(StorageRpc storageRpc) { - return storageRpc.listAcls("BUCKET_NAME", OPTIONS); + public List call() { + return STORAGE_RPC.listAcls("BUCKET_NAME", OPTIONS); } }; } @Test public void testListAclsObject() { - call = - new RpcCall>() { + rpc = + new Callable>() { @Override - public List call(StorageRpc storageRpc) { - return storageRpc.listAcls("BUCKET_NAME", "OBJECT_NAME", 100L); + public List call() { + return STORAGE_RPC.listAcls("BUCKET_NAME", "OBJECT_NAME", 100L); } }; } @Test public void testCreateHmacKey() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public HmacKey call(StorageRpc storageRpc) { - return storageRpc.createHmacKey("account", OPTIONS); + public HmacKey call() { + return STORAGE_RPC.createHmacKey("account", OPTIONS); } }; } @Test public void testListHmacKeys() { - call = - new RpcCall>>() { + rpc = + new Callable>>() { @Override - public Tuple> call(StorageRpc storageRpc) { - return storageRpc.listHmacKeys(OPTIONS); + public Tuple> call() { + return STORAGE_RPC.listHmacKeys(OPTIONS); } }; } @Test public void testUpdateHmacKey() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public HmacKeyMetadata call(StorageRpc storageRpc) { - return storageRpc.updateHmacKey(null, OPTIONS); + public HmacKeyMetadata call() { + return STORAGE_RPC.updateHmacKey(null, OPTIONS); } }; } @Test public void testGetHmacKey() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public HmacKeyMetadata call(StorageRpc storageRpc) { - return storageRpc.getHmacKey("account", OPTIONS); + public HmacKeyMetadata call() { + return STORAGE_RPC.getHmacKey("account", OPTIONS); } }; } @Test public void testDeleteHmacKey() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public Void call(StorageRpc storageRpc) { - storageRpc.deleteHmacKey(null, OPTIONS); + public Void call() { + STORAGE_RPC.deleteHmacKey(null, OPTIONS); return null; } }; @@ -485,143 +458,143 @@ public Void call(StorageRpc storageRpc) { @Test public void testGetDefaultAcl() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public ObjectAccessControl call(StorageRpc storageRpc) { - return storageRpc.getDefaultAcl("bucket", "entity"); + public ObjectAccessControl call() { + return STORAGE_RPC.getDefaultAcl("bucket", "entity"); } }; } @Test public void testDeleteDefaultAcl() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public Boolean call(StorageRpc storageRpc) { - return storageRpc.deleteDefaultAcl("bucket", "entity"); + public Boolean call() { + return STORAGE_RPC.deleteDefaultAcl("bucket", "entity"); } }; } @Test public void testCreateDefaultAcl() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public ObjectAccessControl call(StorageRpc storageRpc) { - return storageRpc.createDefaultAcl(null); + public ObjectAccessControl call() { + return STORAGE_RPC.createDefaultAcl(null); } }; } @Test public void testPatchDefaultAcl() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public ObjectAccessControl call(StorageRpc storageRpc) { - return storageRpc.patchDefaultAcl(null); + public ObjectAccessControl call() { + return STORAGE_RPC.patchDefaultAcl(null); } }; } @Test public void testListDefaultAcls() { - call = - new RpcCall>() { + rpc = + new Callable>() { @Override - public List call(StorageRpc storageRpc) { - return storageRpc.listDefaultAcls("bucket"); + public List call() { + return STORAGE_RPC.listDefaultAcls("bucket"); } }; } @Test public void testGetIamPolicy() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public Policy call(StorageRpc storageRpc) { - return storageRpc.getIamPolicy("bucket", OPTIONS); + public Policy call() { + return STORAGE_RPC.getIamPolicy("bucket", OPTIONS); } }; } @Test public void testSetIamPolicy() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public Policy call(StorageRpc storageRpc) { - return storageRpc.setIamPolicy("bucket", null, OPTIONS); + public Policy call() { + return STORAGE_RPC.setIamPolicy("bucket", null, OPTIONS); } }; } @Test public void testTestIamPermissions() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public TestIamPermissionsResponse call(StorageRpc storageRpc) { - return storageRpc.testIamPermissions("bucket", null, OPTIONS); + public TestIamPermissionsResponse call() { + return STORAGE_RPC.testIamPermissions("bucket", null, OPTIONS); } }; } @Test public void testDeleteNotification() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public Boolean call(StorageRpc storageRpc) { - return storageRpc.deleteNotification("bucket", "entity"); + public Boolean call() { + return STORAGE_RPC.deleteNotification("bucket", "entity"); } }; } @Test public void testListNotifications() { - call = - new RpcCall>() { + rpc = + new Callable>() { @Override - public List call(StorageRpc storageRpc) { - return storageRpc.listNotifications("bucket"); + public List call() { + return STORAGE_RPC.listNotifications("bucket"); } }; } @Test public void testCreateNotification() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public Notification call(StorageRpc storageRpc) { - return storageRpc.createNotification("bucket", null); + public Notification call() { + return STORAGE_RPC.createNotification("bucket", null); } }; } @Test public void testLockRetentionPolicy() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public Bucket call(StorageRpc storageRpc) { - return storageRpc.lockRetentionPolicy(BUCKET, OPTIONS); + public Bucket call() { + return STORAGE_RPC.lockRetentionPolicy(BUCKET, OPTIONS); } }; } @Test public void testGetServiceAccount() { - call = - new RpcCall() { + rpc = + new Callable() { @Override - public ServiceAccount call(StorageRpc storageRpc) { - return storageRpc.getServiceAccount("project"); + public ServiceAccount call() { + return STORAGE_RPC.getServiceAccount("project"); } }; }