Skip to content
Permalink
Browse files
JCLOUDS-457: Multiple fixes
This commit addresses some problems found in the code:

- Now VaultMetadata returns a copy of the creation date instead
of their own instance.

- Added a checkNotNull for PaginatedVaultCollection iterable.

- Added a test for listVaults with an empty list of vaults.
  • Loading branch information
rcoedo authored and gaul committed Jun 27, 2014
1 parent ac5e48f commit 9113ce56249fb505d81153b09d4f2c5e83b7660d
Showing 4 changed files with 20 additions and 3 deletions.
@@ -16,6 +16,8 @@
*/
package org.jclouds.glacier.domain;

import static com.google.common.base.Preconditions.checkNotNull;

import java.beans.ConstructorProperties;
import java.util.Iterator;

@@ -37,7 +39,7 @@ public class PaginatedVaultCollection extends IterableWithMarker<VaultMetadata>

@ConstructorProperties({ "VaultList", "Marker" })
public PaginatedVaultCollection(Iterable<VaultMetadata> vaults, String marker) {
this.vaults = vaults;
this.vaults = checkNotNull(vaults, "vaults");
this.marker = marker;
}

@@ -51,7 +51,7 @@ public VaultMetadata(String vaultName, String vaultARN, Date creationDate, @Null
long numberOfArchives, long sizeInBytes) {
this.vaultName = checkNotNull(vaultName, "vaultName");
this.vaultARN = checkNotNull(vaultARN, "vaultARN");
this.creationDate = checkNotNull(creationDate, "creationDate");
this.creationDate = (Date) checkNotNull(creationDate, "creationDate").clone();
this.lastInventoryDate = lastInventoryDate;
this.numberOfArchives = numberOfArchives;
this.sizeInBytes = sizeInBytes;
@@ -66,7 +66,7 @@ public String getVaultARN() {
}

public Date getCreationDate() {
return creationDate;
return (Date) creationDate.clone();
}

public Date getLastInventoryDate() {
@@ -185,6 +185,17 @@ public void testListVaults() throws InterruptedException, IOException {
assertEquals(server.takeRequest().getRequestLine(), "GET /-/vaults " + HTTP);
}

@Test
public void testListVaultsWithEmptyList() throws InterruptedException, IOException {
MockResponse mr = buildBaseResponse(200);
mr.addHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8);
mr.setBody(getResponseBody("/json/listVaultsWithEmptyListResponseBody.json"));
mr.addHeader(HttpHeaders.CONTENT_LENGTH, mr.getBody().length);
server.enqueue(mr);

assertTrue(client.listVaults().isEmpty());
}

@Test
public void testListVaultsWithQueryParams() throws InterruptedException, IOException {
MockResponse mr = buildBaseResponse(200);
@@ -0,0 +1,4 @@
{
"Marker": null,
"VaultList": []
}

0 comments on commit 9113ce5

Please sign in to comment.