public void testList_NotExistingContainer() { // Testing list for a not existing container try { blobStore.list(CONTAINER_NAME); fail("Found a not existing container"); } catch (ContainerNotFoundException e) { // ok if arriver here } }
/** http://code.google.com/p/jclouds/issues/detail?id=992 */ public void testUseBucketWithUpperCaseName() throws Exception { String bucketName = CONTAINER_PREFIX + "-TestBucket"; String blobName = "TestBlob.txt"; StorageMetadata container = null; BlobStore store = view.getBlobStore(); // Create and use a valid bucket name with uppercase characters in the bucket name (US regions // only) try { store.createContainerInLocation(null, bucketName); for (StorageMetadata metadata : store.list()) { if (metadata.getName().equals(bucketName)) { container = metadata; break; } } assertNotNull(container); store.putBlob( bucketName, store.blobBuilder(blobName).payload("This is a test!").contentType("text/plain").build()); assertNotNull(store.getBlob(bucketName, blobName)); } finally { if (container != null) { store.deleteContainer(bucketName); } } // Try to create the same bucket successfully created above in one of the non-US regions to // ensure an error is // encountered as expected. Location location = null; for (Location pLocation : store.listAssignableLocations()) { if (!ImmutableSet.of(Region.US_STANDARD, Region.US_EAST_1, Region.US_WEST_1, Region.US_WEST_2) .contains(pLocation.getId())) { location = pLocation; break; } } try { store.createContainerInLocation(location, bucketName); fail("Should had failed because in non-US regions, mixed-case bucket names are invalid."); } catch (AWSResponseException e) { assertEquals("InvalidBucketName", e.getError().getCode()); } }
@Test void testToStorageMetadata() { assertNull(ToStorageMetadata.INSTANCE.apply(null)); BlobStore blobStore = getBlobStore(); blobStore.createContainerInLocation(null, "test"); blobStore.createDirectory("test", "one"); Set<StorageMetadata> storageMetadataSet = ImmutableSet.<StorageMetadata>builder() .addAll(transform(blobStore.list(), ToStorageMetadata.INSTANCE)) .build(); assertFalse(storageMetadataSet.isEmpty()); StorageMetadata representation = storageMetadataSet.iterator().next(); assertEquals("test", representation.getName()); }
/** Test of list method of the root context */ public void testList_Root() throws IOException { PageSet<? extends StorageMetadata> containersRetrieved; Set<String> containersCreated = Sets.newHashSet(); // Testing list with no containers containersRetrieved = blobStore.list(); assertTrue( containersRetrieved.isEmpty(), "List operation returns a not empty set of container"); // Testing list with some containers String[] containerNames = {"34343", "aaaa", "bbbbb"}; containersCreated = Sets.newHashSet(); for (String containerName : containerNames) { blobStore.createContainerInLocation(null, containerName); containersCreated.add(containerName); } containersRetrieved = blobStore.list(); assertEquals( containersCreated.size(), containersRetrieved.size(), "Different numbers of container"); for (StorageMetadata data : containersRetrieved) { String containerName = data.getName(); if (!containersCreated.remove(containerName)) { fail("Container list contains unexpected value [" + containerName + "]"); } } assertTrue(containersCreated.isEmpty(), "List operation doesn't return all values."); for (String containerName : containerNames) { // delete all creaded containers blobStore.deleteContainer(containerName); } containersRetrieved = blobStore.list(); assertTrue( containersRetrieved.isEmpty(), "List operation returns a not empty set of container"); }
private void checkForContainerContent( final String containerName, String inDirectory, Set<String> expectedBlobKeys) { ListContainerOptions options = ListContainerOptions.Builder.recursive(); if (null != inDirectory && !"".equals(inDirectory)) options.inDirectory(inDirectory); PageSet<? extends StorageMetadata> blobsRetrieved = blobStore.list(containerName, options); for (Iterator<? extends StorageMetadata> it = blobsRetrieved.iterator(); it.hasNext(); ) { // TODO: FluentIterable if (it.next().getType() != StorageType.BLOB) { it.remove(); } } // nothing expected if (null == expectedBlobKeys || 0 == expectedBlobKeys.size()) { assertTrue( blobsRetrieved.isEmpty(), "Wrong blob number retrieved in the container [" + containerName + "]"); return; } // copies values Set<String> expectedBlobKeysCopy = Sets.newHashSet(); for (String value : expectedBlobKeys) { expectedBlobKeysCopy.add(value); } assertEquals( blobsRetrieved.size(), expectedBlobKeysCopy.size(), "Wrong blob number retrieved in the container [" + containerName + "]"); for (StorageMetadata data : blobsRetrieved) { String blobName = data.getName(); if (!expectedBlobKeysCopy.remove(blobName)) { fail( "List for container [" + containerName + "] contains unexpected value [" + blobName + "]"); } } assertTrue( expectedBlobKeysCopy.isEmpty(), "List operation for container [" + containerName + "] doesn't return all values."); }