From b220d889ca86b81d8d3badccd52215a9bf613529 Mon Sep 17 00:00:00 2001 From: kstyrc Date: Mon, 17 Mar 2014 23:57:15 +0100 Subject: [PATCH] JCLOUDS-184: Improving AzureBlob unit tests --- .../AzureBlobBlockUploadStrategyTest.java | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/strategy/AzureBlobBlockUploadStrategyTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/strategy/AzureBlobBlockUploadStrategyTest.java index e664b2aefa..615b3f4825 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/strategy/AzureBlobBlockUploadStrategyTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/strategy/AzureBlobBlockUploadStrategyTest.java @@ -17,6 +17,9 @@ package org.jclouds.azureblob.blobstore.strategy; +import com.google.common.base.Charsets; +import com.google.common.io.ByteSource; +import org.easymock.EasyMock; import org.jclouds.azureblob.AzureBlobClient; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.MutableBlobMetadata; @@ -25,19 +28,21 @@ import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl; import org.jclouds.io.MutableContentMetadata; import org.jclouds.io.Payload; import org.jclouds.io.PayloadSlicer; +import org.jclouds.io.Payloads; import org.jclouds.io.payloads.BaseMutableContentMetadata; -import org.jclouds.io.payloads.StringPayload; import org.testng.annotations.Test; -import static org.testng.Assert.assertEquals; import java.util.List; import static org.easymock.EasyMock.anyObject; import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.createNiceMock; import static org.easymock.EasyMock.eq; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.expectLastCall; import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.testng.Assert.assertEquals; @Test(groups = "unit", testName = "AzureBlobBlockUploadStrategyTest") public class AzureBlobBlockUploadStrategyTest { @@ -54,7 +59,8 @@ public class AzureBlobBlockUploadStrategyTest { metadata.setName(blobName); metadata.setContentMetadata(contentMetadata); Blob blob = new BlobImpl(metadata); - Payload payload = new StringPayload("ABCD"); + ByteSource bytes = ByteSource.wrap("ABCD".getBytes(Charsets.UTF_8)); + Payload payload = Payloads.newByteSourcePayload(bytes); payload.setContentMetadata(contentMetadata); blob.setPayload(payload); @@ -64,11 +70,36 @@ public class AzureBlobBlockUploadStrategyTest { expect(slicer.slice(payload, MultipartUploadStrategy.MAX_BLOCK_SIZE * 3, oneMB)).andReturn(payload); client.putBlock(eq(container), eq(blobName), anyObject(String.class), eq(payload)); expectLastCall().times(4); - expect(client.putBlockList(eq(container), eq(blobName), anyObject(List.class))).andReturn("Fake ETAG"); + expect(client.putBlockList(eq(container), eq(blobName), EasyMock.>anyObject())).andReturn("Fake ETAG"); AzureBlobBlockUploadStrategy strat = new AzureBlobBlockUploadStrategy(client, slicer); replay(slicer, client); String etag = strat.execute(container, blob); assertEquals(etag, "Fake ETAG"); + + verify(client); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testExceededContentLengthLimit() throws Exception { + String container = "test-container"; + String blobName = "test-blob"; + + AzureBlobClient client = createNiceMock(AzureBlobClient.class); + PayloadSlicer slicer = createNiceMock(PayloadSlicer.class); + + MutableBlobMetadata metadata = new MutableBlobMetadataImpl(); + MutableContentMetadata contentMetadata = new BaseMutableContentMetadata(); + contentMetadata.setContentLength(MultipartUploadStrategy.MAX_BLOCK_SIZE * MultipartUploadStrategy.MAX_NUMBER_OF_BLOCKS + 1); + metadata.setName(blobName); + metadata.setContentMetadata(contentMetadata); + Blob blob = new BlobImpl(metadata); + ByteSource bytes = ByteSource.wrap("ABCD".getBytes(Charsets.UTF_8)); + Payload payload = Payloads.newByteSourcePayload(bytes); + payload.setContentMetadata(contentMetadata); + blob.setPayload(payload); + + AzureBlobBlockUploadStrategy strat = new AzureBlobBlockUploadStrategy(client, slicer); + strat.execute(container, blob); } }