From d736a73f3ca794b38f6c0ed69c67710460070079 Mon Sep 17 00:00:00 2001 From: Renaud Paquay Date: Fri, 18 Nov 2011 18:01:28 -0800 Subject: [PATCH] Replace magic string with boolean options Issue #43 --- .../blob/implementation/BlobRestProxy.java | 10 ++++- .../blob/models/ListBlobBlocksOptions.java | 21 ++++++--- .../blob/BlobServiceIntegrationTest.java | 45 +++++++++++++++++-- 3 files changed, 65 insertions(+), 11 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java index 4f6f4a182902e..aa4ab0da8e605 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java @@ -810,7 +810,15 @@ public ListBlobBlocksResult listBlobBlocks(String container, String blob, ListBl throws ServiceException { WebResource webResource = getResource(options).path(container).path(blob).queryParam("comp", "blocklist"); webResource = addOptionalQueryParam(webResource, "snapshot", options.getSnapshot()); - webResource = addOptionalQueryParam(webResource, "blocklisttype", options.getListType()); + if (options.isCommittedList() && options.isUncommittedList()) { + webResource = addOptionalQueryParam(webResource, "blocklisttype", "all"); + } + else if (options.isCommittedList()) { + webResource = addOptionalQueryParam(webResource, "blocklisttype", "committed"); + } + else if (options.isUncommittedList()) { + webResource = addOptionalQueryParam(webResource, "blocklisttype", "uncommitted"); + } Builder builder = webResource.header("x-ms-version", API_VERSION); builder = addOptionalHeader(builder, "x-ms-lease-id", options.getLeaseId()); diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/models/ListBlobBlocksOptions.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/models/ListBlobBlocksOptions.java index 33eb6b47e54d2..4c26fd7d34cf4 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/models/ListBlobBlocksOptions.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/models/ListBlobBlocksOptions.java @@ -1,10 +1,10 @@ package com.microsoft.windowsazure.services.blob.models; - public class ListBlobBlocksOptions extends BlobServiceOptions { private String leaseId; private String snapshot; - private String listType; // "committed", "uncommitted", "all" + private boolean committedList; + private boolean uncommittedList; public String getLeaseId() { return leaseId; @@ -24,12 +24,21 @@ public ListBlobBlocksOptions setSnapshot(String snapshot) { return this; } - public String getListType() { - return listType; + public boolean isCommittedList() { + return committedList; + } + + public ListBlobBlocksOptions setCommittedList(boolean committedList) { + this.committedList = committedList; + return this; + } + + public boolean isUncommittedList() { + return uncommittedList; } - public ListBlobBlocksOptions setListType(String listType) { - this.listType = listType; + public ListBlobBlocksOptions setUncommittedList(boolean uncommittedList) { + this.uncommittedList = uncommittedList; return this; } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/BlobServiceIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/BlobServiceIntegrationTest.java index 98579bb4ed56d..d4e20814401da 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/BlobServiceIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/BlobServiceIntegrationTest.java @@ -738,8 +738,8 @@ public void listBlobBlocksWorks() throws Exception { service.createBlobBlock(container, blob, "124", new ByteArrayInputStream(new byte[512])); service.createBlobBlock(container, blob, "125", new ByteArrayInputStream(new byte[195])); - ListBlobBlocksResult result = service.listBlobBlocks(container, blob, - new ListBlobBlocksOptions().setListType("all")); + ListBlobBlocksResult result = service.listBlobBlocks(container, blob, new ListBlobBlocksOptions() + .setCommittedList(true).setUncommittedList(true)); // Assert assertNotNull(result); @@ -758,6 +758,43 @@ public void listBlobBlocksWorks() throws Exception { assertEquals(195, result.getUncommittedBlocks().get(2).getBlockLength()); } + @Test + public void listBlobBlocksWithOptionsWorks() throws Exception { + // Arrange + Configuration config = createConfiguration(); + BlobContract service = config.create(BlobContract.class); + + // Act + String container = TEST_CONTAINER_FOR_BLOBS; + String blob = "test14"; + service.createBlockBlob(container, blob, null); + service.createBlobBlock(container, blob, "123", new ByteArrayInputStream(new byte[256])); + + BlockList blockList = new BlockList(); + blockList.addUncommittedEntry("123"); + service.commitBlobBlocks(container, blob, blockList); + + service.createBlobBlock(container, blob, "124", new ByteArrayInputStream(new byte[512])); + service.createBlobBlock(container, blob, "125", new ByteArrayInputStream(new byte[195])); + + ListBlobBlocksResult result1 = service.listBlobBlocks(container, blob, new ListBlobBlocksOptions() + .setCommittedList(true).setUncommittedList(true)); + ListBlobBlocksResult result2 = service.listBlobBlocks(container, blob, + new ListBlobBlocksOptions().setCommittedList(true)); + ListBlobBlocksResult result3 = service.listBlobBlocks(container, blob, + new ListBlobBlocksOptions().setUncommittedList(true)); + + // Assert + assertEquals(1, result1.getCommittedBlocks().size()); + assertEquals(2, result1.getUncommittedBlocks().size()); + + assertEquals(1, result2.getCommittedBlocks().size()); + assertEquals(0, result2.getUncommittedBlocks().size()); + + assertEquals(0, result3.getCommittedBlocks().size()); + assertEquals(2, result3.getUncommittedBlocks().size()); + } + @Test public void commitBlobBlocksWorks() throws Exception { // Arrange @@ -779,8 +816,8 @@ public void commitBlobBlocksWorks() throws Exception { blockList.addUncommittedEntry(blockId1).addLatestEntry(blockId3); service.commitBlobBlocks(container, blob, blockList); - ListBlobBlocksResult result = service.listBlobBlocks(container, blob, - new ListBlobBlocksOptions().setListType("all")); + ListBlobBlocksResult result = service.listBlobBlocks(container, blob, new ListBlobBlocksOptions() + .setCommittedList(true).setUncommittedList(true)); // Assert assertNotNull(result);