private void initializeExpectedBlob(int optionsCalls) { expect(serviceMockReturnsOptions.getOptions()).andReturn(mockOptions).times(optionsCalls); replay(serviceMockReturnsOptions); expectedBlob = new Blob(serviceMockReturnsOptions, new BlobInfo.BuilderImpl(BLOB_INFO)); }
@Test public void testCreateFromStreamNoContentType() throws Exception { initializeExpectedBucket(5); BlobInfo info = BlobInfo.newBuilder("b", "n").build(); Blob expectedBlob = new Blob(serviceMockReturnsOptions, new BlobInfo.BuilderImpl(info)); byte[] content = {0xD, 0xE, 0xA, 0xD}; InputStream streamContent = new ByteArrayInputStream(content); expect(storage.getOptions()).andReturn(mockOptions); expect(storage.create(info, streamContent)).andReturn(expectedBlob); replay(storage); initializeBucket(); Blob blob = bucket.create("n", streamContent); assertEquals(expectedBlob, blob); }
@Test public void testCreateFromStream() throws Exception { initializeExpectedBucket(5); BlobInfo info = BlobInfo.newBuilder("b", "n").setContentType(CONTENT_TYPE).build(); Blob expectedBlob = new Blob(serviceMockReturnsOptions, new BlobInfo.BuilderImpl(info)); byte[] content = {0xD, 0xE, 0xA, 0xD}; InputStream streamContent = new ByteArrayInputStream(content); expect(storage.getOptions()).andReturn(mockOptions); expect(storage.create(info, streamContent)).andReturn(expectedBlob); replay(storage); initializeBucket(); Blob blob = bucket.create("n", streamContent, CONTENT_TYPE); assertEquals(expectedBlob, blob); }
@Test public void testCreateWithEncryptionKey() throws Exception { initializeExpectedBucket(5); BlobInfo info = BlobInfo.newBuilder(BlobId.of("b", "n")).setContentType(CONTENT_TYPE).build(); Blob expectedBlob = new Blob(serviceMockReturnsOptions, new BlobInfo.BuilderImpl(info)); byte[] content = {0xD, 0xE, 0xA, 0xD}; expect(storage.getOptions()).andReturn(mockOptions); expect(storage.create(info, content, Storage.BlobTargetOption.encryptionKey(KEY))) .andReturn(expectedBlob); replay(storage); initializeBucket(); Blob blob = bucket.create("n", content, CONTENT_TYPE, Bucket.BlobTargetOption.encryptionKey(KEY)); assertEquals(expectedBlob, blob); }
@Test public void testCreateFromStreamWithEncryptionKey() throws Exception { initializeExpectedBucket(5); BlobInfo info = BlobInfo.newBuilder(BlobId.of("b", "n")).setContentType(CONTENT_TYPE).build(); Blob expectedBlob = new Blob(serviceMockReturnsOptions, new BlobInfo.BuilderImpl(info)); byte[] content = {0xD, 0xE, 0xA, 0xD}; InputStream streamContent = new ByteArrayInputStream(content); expect(storage.getOptions()).andReturn(mockOptions); expect(storage.create(info, streamContent, Storage.BlobWriteOption.encryptionKey(KEY))) .andReturn(expectedBlob); replay(storage); initializeBucket(); Blob blob = bucket.create("n", streamContent, CONTENT_TYPE, Bucket.BlobWriteOption.encryptionKey(KEY)); assertEquals(expectedBlob, blob); }
@Test public void testCreateNotExists() throws Exception { initializeExpectedBucket(5); BlobInfo info = BlobInfo.newBuilder(BlobId.of("b", "n", 0L)).setContentType(CONTENT_TYPE).build(); Blob expectedBlob = new Blob(serviceMockReturnsOptions, new BlobInfo.BuilderImpl(info)); byte[] content = {0xD, 0xE, 0xA, 0xD}; expect(storage.getOptions()).andReturn(mockOptions); expect(storage.create(info, content, Storage.BlobTargetOption.generationMatch())) .andReturn(expectedBlob); replay(storage); initializeBucket(); Blob blob = bucket.create("n", content, CONTENT_TYPE, Bucket.BlobTargetOption.doesNotExist()); assertEquals(expectedBlob, blob); }
@Test public void testGet() throws Exception { initializeExpectedBucket(5); Blob expectedBlob = new Blob( serviceMockReturnsOptions, new BlobInfo.BuilderImpl(BlobInfo.newBuilder("b", "n").build())); expect(storage.getOptions()).andReturn(mockOptions); expect(storage.get(BlobId.of(expectedBucket.getName(), "n"), new Storage.BlobGetOption[0])) .andReturn(expectedBlob); replay(storage); initializeBucket(); Blob blob = bucket.get("n"); assertEquals(expectedBlob, blob); }
private void initializeBlob() { blob = new Blob(storage, new BlobInfo.BuilderImpl(BLOB_INFO)); }
@Before public void setUp() { rpcFactoryMock = createMock(StorageRpcFactory.class); storageRpcMock = createMock(StorageRpc.class); expect(rpcFactoryMock.create(anyObject(StorageOptions.class))).andReturn(storageRpcMock); replay(rpcFactoryMock); options = StorageOptions.newBuilder() .setProjectId("projectid") .setServiceRpcFactory(rpcFactoryMock) .setRetrySettings(ServiceOptions.getNoRetrySettings()) .build(); result = new Blob(options.getService(), new BlobInfo.BuilderImpl(RESULT_INFO)); }
@Test public void testCreate() throws Exception { initializeExpectedBucket(5); BlobInfo info = BlobInfo.newBuilder("b", "n").setContentType(CONTENT_TYPE).build(); Blob expectedBlob = new Blob(serviceMockReturnsOptions, new BlobInfo.BuilderImpl(info)); byte[] content = {0xD, 0xE, 0xA, 0xD}; expect(storage.getOptions()).andReturn(mockOptions); expect(storage.create(info, content)).andReturn(expectedBlob); replay(storage); initializeBucket(); Blob blob = bucket.create("n", content, CONTENT_TYPE); assertEquals(expectedBlob, blob); }
@Test public void testUpdate() throws Exception { initializeExpectedBlob(2); Blob expectedUpdatedBlob = expectedBlob.toBuilder().setCacheControl("c").build(); expect(storage.getOptions()).andReturn(mockOptions).times(2); expect(storage.update(eq(expectedUpdatedBlob), new Storage.BlobTargetOption[0])) .andReturn(expectedUpdatedBlob); replay(storage); initializeBlob(); Blob updatedBlob = new Blob(storage, new BlobInfo.BuilderImpl(expectedUpdatedBlob)); Blob actualUpdatedBlob = updatedBlob.update(); assertEquals(expectedUpdatedBlob, actualUpdatedBlob); }
/** Returns a {@code BlobInfo} builder where blob identity is set using the provided value. */ public static Builder newBuilder(BlobId blobId) { return new BuilderImpl(blobId); }
/** Returns a builder for the current blob. */ public Builder toBuilder() { return new BuilderImpl(this); }
@Test public void testCreateNoContentType() throws Exception { initializeExpectedBucket(5); BlobInfo info = BlobInfo.newBuilder("b", "n").build(); Blob expectedBlob = new Blob(serviceMockReturnsOptions, new BlobInfo.BuilderImpl(info)); byte[] content = {0xD, 0xE, 0xA, 0xD}; expect(storage.getOptions()).andReturn(mockOptions); expect(storage.create(info, content)).andReturn(expectedBlob); replay(storage); initializeBucket(); Blob blob = bucket.create("n", content); assertEquals(expectedBlob, blob); }
Builder(Blob blob) { this.storage = blob.getStorage(); this.infoBuilder = new BlobInfo.BuilderImpl(blob); }
@Test public void testUpdateBlobWithOptions() { BlobInfo updatedBlobInfo = BLOB_INFO1.toBuilder().setContentType("some-content-type").build(); EasyMock.expect(storageRpcMock.patch(updatedBlobInfo.toPb(), BLOB_TARGET_OPTIONS_UPDATE)) .andReturn(updatedBlobInfo.toPb()); EasyMock.replay(storageRpcMock); initializeService(); Blob blob = storage.update(updatedBlobInfo, BLOB_TARGET_METAGENERATION, BLOB_TARGET_PREDEFINED_ACL); assertEquals(new Blob(storage, new BlobInfo.BuilderImpl(updatedBlobInfo)), blob); }
@Test public void testUpdateBlob() { BlobInfo updatedBlobInfo = BLOB_INFO1.toBuilder().setContentType("some-content-type").build(); EasyMock.expect(storageRpcMock.patch(updatedBlobInfo.toPb(), EMPTY_RPC_OPTIONS)) .andReturn(updatedBlobInfo.toPb()); EasyMock.replay(storageRpcMock); initializeService(); Blob blob = storage.update(updatedBlobInfo); assertEquals(new Blob(storage, new BlobInfo.BuilderImpl(updatedBlobInfo)), blob); }
static Blob fromPb(Storage storage, StorageObject storageObject) { BlobInfo info = BlobInfo.fromPb(storageObject); return new Blob(storage, new BlobInfo.BuilderImpl(info)); } }
private void initializeServiceDependentObjects() { expectedBlob1 = new Blob(storage, new BlobInfo.BuilderImpl(BLOB_INFO1)); expectedBlob2 = new Blob(storage, new BlobInfo.BuilderImpl(BLOB_INFO2)); expectedBlob3 = new Blob(storage, new BlobInfo.BuilderImpl(BLOB_INFO3)); expectedBucket1 = new Bucket(storage, new BucketInfo.BuilderImpl(BUCKET_INFO1)); expectedBucket2 = new Bucket(storage, new BucketInfo.BuilderImpl(BUCKET_INFO2)); expectedBucket3 = new Bucket(storage, new BucketInfo.BuilderImpl(BUCKET_INFO3)); }
@Test public void testToBuilder() { expect(storage.getOptions()).andReturn(mockOptions).times(6); replay(storage); Blob fullBlob = new Blob(storage, new BlobInfo.BuilderImpl(FULL_BLOB_INFO)); assertEquals(fullBlob, fullBlob.toBuilder().build()); Blob simpleBlob = new Blob(storage, new BlobInfo.BuilderImpl(BLOB_INFO)); assertEquals(simpleBlob, simpleBlob.toBuilder().build()); Blob directory = new Blob(storage, new BlobInfo.BuilderImpl(DIRECTORY_INFO)); assertEquals(directory, directory.toBuilder().build()); }