public void testMoveTo() throws Exception {
// check if move is supported
if (!isMoveToSupp) {
shouldFail(new ConAction() {
public void run(BlobStoreConnection con) throws Exception {
Blob b = getBlob(con, createId("blobMoveTo1"), false);
b.moveTo(b.getId(), null);
}
}, UnsupportedOperationException.class, null);
return;
}
// set up
final URI id1 = createId("blobMoveTo1");
final URI id2 = createId("blobMoveTo2");
final URI id3 = createId("blobMoveTo3");
final URI id4 = createId("blobMoveTo4");
createBlob(id1, "foo", true);
createBlob(id4, "bar", true);
// move blob from id1 to id2
renameBlob(id1, id2, "foo", true);
// move from non-existent blob should fail
shouldFail(new ConAction() {
public void run(BlobStoreConnection con) throws Exception {
Blob ob = getBlob(con, id1, false);
ob.moveTo(id3, null);
}
}, MissingBlobException.class, id1);
getBlob(id1, null, true);
getBlob(id3, null, true);
// move to existing blob should fail
shouldFail(new ConAction() {
public void run(BlobStoreConnection con) throws Exception {
Blob ob = getBlob(con, id2, "foo");
ob.moveTo(id4, null);
}
}, DuplicateBlobException.class, id4);
getBlob(id2, "foo", true);
getBlob(id4, "bar", true);
// move a non-existent blob onto itself should fail
shouldFail(new ConAction() {
public void run(BlobStoreConnection con) throws Exception {
Blob b = getBlob(con, id1, false);
b.moveTo(id1, null);
}
}, MissingBlobException.class, id1);
getBlob(id1, null, true);
// move an existing blob onto itself should fail
shouldFail(new ConAction() {
public void run(BlobStoreConnection con) throws Exception {
Blob b = getBlob(con, id2, "foo");
b.moveTo(id2, null);
}
}, DuplicateBlobException.class, id2);
getBlob(id2, "foo", true);
// move to null
if (!isIdGenSupp) {
// move to null should fail
shouldFail(new ConAction() {
public void run(BlobStoreConnection con) throws Exception {
Blob b = getBlob(con, id2, "foo");
b.moveTo(null, null);
}
}, UnsupportedOperationException.class, null);
getBlob(id2, "foo", true);
} else {
// null id should work
runTests(new ConAction() {
public void run(BlobStoreConnection con) throws Exception {
Blob b = getBlob(con, id2, "foo");
Blob b2 = b.moveTo(null, null);
// undo for other tests
b2.moveTo(id2, null);
}
}, false);
}
// move to incompatible blob should fail
final URI inv = getInvalidId();
if (inv != null) {
shouldFail(new ConAction() {
public void run(BlobStoreConnection con) throws Exception {
Blob ob = getBlob(con, id2, "foo");
ob.moveTo(inv, null);
}
}, UnsupportedIdException.class, inv);
}
getBlob(id2, "foo", true);