JCLOUDS-184: Improving AzureBlob unit tests

This commit is contained in:
kstyrc 2014-03-17 23:57:15 +01:00 committed by Everett Toews
parent ad66752811
commit b220d889ca
1 changed files with 35 additions and 4 deletions

View File

@ -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.<List<String>>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);
}
}