expose constructor for blobbuilderimpl

This commit is contained in:
Adrian Cole 2011-04-04 22:35:22 -07:00
parent f322931755
commit d69d31a5d2
2 changed files with 49 additions and 50 deletions

View File

@ -41,6 +41,7 @@ import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobBuilder;
import org.jclouds.blobstore.domain.internal.BlobBuilderImpl;
import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.encryption.internal.JCECrypto;
import org.jclouds.filesystem.predicates.validators.internal.FilesystemBlobKeyValidatorImpl;
import org.jclouds.filesystem.predicates.validators.internal.FilesystemContainerNameValidatorImpl;
import org.jclouds.filesystem.strategy.FilesystemStorageStrategy;
@ -76,7 +77,11 @@ public class FilesystemStorageStrategyImplTest {
storageStrategy = new FilesystemStorageStrategyImpl(new Provider<BlobBuilder>() {
@Override
public BlobBuilder get() {
return new BlobBuilderImpl();
try {
return new BlobBuilderImpl(new JCECrypto());
} catch (Exception e) {
return null;
}
}
}, TestUtils.TARGET_BASE_DIR, new FilesystemContainerNameValidatorImpl(), new FilesystemBlobKeyValidatorImpl());
@ -139,9 +144,8 @@ public class FilesystemStorageStrategyImplTest {
public void testDeleteDirectory() throws IOException {
TestUtils.createContainerAsDirectory(CONTAINER_NAME);
TestUtils.createBlobsInContainer(
CONTAINER_NAME,
new String[] { TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev3" + FS, ".txt"),
TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] {
TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev3" + FS, ".txt"),
TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev4" + FS, ".jpg") });
// delete directory in different ways
@ -158,9 +162,8 @@ public class FilesystemStorageStrategyImplTest {
TestUtils.directoryExists(TARGET_CONTAINER_NAME, true);
// delete the directory and all the files inside
TestUtils.createBlobsInContainer(
CONTAINER_NAME,
new String[] { TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev3" + FS, ".txt"),
TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] {
TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev3" + FS, ".txt"),
TestUtils.createRandomBlobKey("lev1" + FS + "lev2" + FS + "lev4" + FS, ".jpg") });
storageStrategy.deleteDirectory(CONTAINER_NAME, null);
TestUtils.directoryExists(TARGET_CONTAINER_NAME, false);
@ -208,9 +211,8 @@ public class FilesystemStorageStrategyImplTest {
public void testClearContainer() throws IOException {
storageStrategy.createContainer(CONTAINER_NAME);
Set<String> blobs = TestUtils.createBlobsInContainer(
CONTAINER_NAME,
new String[] { TestUtils.createRandomBlobKey("clean_container-", ".jpg"),
Set<String> blobs = TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] {
TestUtils.createRandomBlobKey("clean_container-", ".jpg"),
TestUtils.createRandomBlobKey("bf" + FS + "sd" + FS + "as" + FS + "clean_container-", ".jpg") });
// test if file exits
for (String blob : blobs) {
@ -238,9 +240,8 @@ public class FilesystemStorageStrategyImplTest {
public void testClearContainerAndThenDeleteContainer() throws IOException {
storageStrategy.createContainer(CONTAINER_NAME);
Set<String> blobs = TestUtils.createBlobsInContainer(
CONTAINER_NAME,
new String[] { TestUtils.createRandomBlobKey("clean_container-", ".jpg"),
Set<String> blobs = TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] {
TestUtils.createRandomBlobKey("clean_container-", ".jpg"),
TestUtils.createRandomBlobKey("bf" + FS + "sd" + FS + "as" + FS + "clean_container-", ".jpg") });
// test if file exits
for (String blob : blobs) {
@ -402,7 +403,11 @@ public class FilesystemStorageStrategyImplTest {
new Provider<BlobBuilder>() {
@Override
public BlobBuilder get() {
return new BlobBuilderImpl();
try {
return new BlobBuilderImpl(new JCECrypto());
} catch (Exception e) {
return null;
}
}
}, absoluteBasePath, new FilesystemContainerNameValidatorImpl(), new FilesystemBlobKeyValidatorImpl());
TestUtils.cleanDirectoryContent(absoluteContainerPath);
@ -436,9 +441,8 @@ public class FilesystemStorageStrategyImplTest {
public void testRemoveBlob() throws IOException {
storageStrategy.createContainer(CONTAINER_NAME);
Set<String> blobKeys = TestUtils.createBlobsInContainer(
CONTAINER_NAME,
new String[] { TestUtils.createRandomBlobKey("removeBlob-", ".jpg"),
Set<String> blobKeys = TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] {
TestUtils.createRandomBlobKey("removeBlob-", ".jpg"),
TestUtils.createRandomBlobKey("removeBlob-", ".jpg"),
TestUtils.createRandomBlobKey("346" + FS + "g3sx2" + FS + "removeBlob-", ".jpg"),
TestUtils.createRandomBlobKey("346" + FS + "g3sx2" + FS + "removeBlob-", ".jpg") });
@ -478,9 +482,8 @@ public class FilesystemStorageStrategyImplTest {
// create blobs
storageStrategy.createContainer(CONTAINER_NAME);
Set<String> createBlobKeys = TestUtils.createBlobsInContainer(
CONTAINER_NAME,
new String[] { TestUtils.createRandomBlobKey("GetBlobKeys-", ".jpg"),
Set<String> createBlobKeys = TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] {
TestUtils.createRandomBlobKey("GetBlobKeys-", ".jpg"),
TestUtils.createRandomBlobKey("GetBlobKeys-", ".jpg"),
TestUtils.createRandomBlobKey("563" + FS + "g3sx2" + FS + "removeBlob-", ".jpg"),
TestUtils.createRandomBlobKey("563" + FS + "g3sx2" + FS + "removeBlob-", ".jpg") });

View File

@ -26,10 +26,8 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
import javax.annotation.Nullable;
import javax.inject.Inject;
import org.jclouds.blobstore.domain.Blob;
@ -40,20 +38,23 @@ import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.io.payloads.PhantomPayload;
import com.google.common.base.Throwables;
import com.google.common.collect.Maps;
/**
* @author Adrian Cole
*/
public class BlobBuilderImpl implements BlobBuilder {
private final Crypto crypto;
@Inject
public BlobBuilderImpl(Crypto crypto) {
this.crypto = checkNotNull(crypto, "crypto");
}
private Payload payload;
private String name;
private Map<String, String> userMetadata = Maps.newLinkedHashMap();
private StorageType type = StorageType.BLOB;
@Inject
private Crypto crypto;
@Override
public BlobBuilder name(String name) {
@ -129,15 +130,10 @@ public class BlobBuilderImpl implements BlobBuilder {
private final Payload payload;
private MessageDigest digest;
public PayloadBlobBuilderImpl(BlobBuilder builder, Payload payload, @Nullable Crypto crypto) {
public PayloadBlobBuilderImpl(BlobBuilder builder, Payload payload, Crypto crypto) {
this.builder = checkNotNull(builder, "builder");
this.payload = checkNotNull(payload, "payload");
try {
this.digest = crypto != null ? crypto.md5() : MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
Throwables.propagate(e);
this.digest = null;
}
this.digest = checkNotNull(crypto, "crypto").md5();
}
@Override