mirror of https://github.com/apache/jclouds.git
Issue 75: cleaned up context bulding and added logging
git-svn-id: http://jclouds.googlecode.com/svn/trunk@1638 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
2d68a4e748
commit
cf8fa7aa33
|
@ -36,11 +36,13 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.rackspace.cloudfiles.domain.AccountMetadata;
|
||||
import org.jclouds.rackspace.cloudfiles.domain.CFObject;
|
||||
import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata;
|
||||
import org.jclouds.rackspace.cloudfiles.options.ListContainerOptions;
|
||||
import org.jclouds.rackspace.cloudfiles.reference.CloudFilesHeaders;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
|
@ -55,11 +57,16 @@ public class CloudFilesConnectionLiveTest {
|
|||
protected static final String sysRackspaceKey = System.getProperty(PROPERTY_RACKSPACE_KEY);
|
||||
|
||||
private String bucketPrefix = System.getProperty("user.name") + ".cfint";
|
||||
CloudFilesConnection connection;
|
||||
|
||||
@BeforeGroups(groups = { "live" })
|
||||
public void setupConnection() {
|
||||
connection = CloudFilesContextBuilder.newBuilder(sysRackspaceUser, sysRackspaceKey)
|
||||
.withModule(new Log4JLoggingModule()).withJsonDebug().buildContext().getConnection();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListOwnedContainers() throws Exception {
|
||||
CloudFilesConnection connection = CloudFilesContextBuilder.newBuilder(sysRackspaceUser,
|
||||
sysRackspaceKey).withJsonDebug().buildContext().getConnection();
|
||||
List<ContainerMetadata> response = connection.listOwnedContainers();
|
||||
assertNotNull(response);
|
||||
long initialContainerCount = response.size();
|
||||
|
@ -80,8 +87,6 @@ public class CloudFilesConnectionLiveTest {
|
|||
|
||||
@Test
|
||||
public void testHeadAccountMetadata() throws Exception {
|
||||
CloudFilesConnection connection = CloudFilesContextBuilder.newBuilder(sysRackspaceUser,
|
||||
sysRackspaceKey).withJsonDebug().buildContext().getConnection();
|
||||
AccountMetadata metadata = connection.getAccountMetadata();
|
||||
assertNotNull(metadata);
|
||||
long initialContainerCount = metadata.getContainerCount();
|
||||
|
@ -98,9 +103,6 @@ public class CloudFilesConnectionLiveTest {
|
|||
|
||||
@Test
|
||||
public void testDeleteContainer() throws Exception {
|
||||
CloudFilesConnection connection = CloudFilesContextBuilder.newBuilder(sysRackspaceUser,
|
||||
sysRackspaceKey).withJsonDebug().buildContext().getConnection();
|
||||
|
||||
assertTrue(connection.deleteContainerIfEmpty("does-not-exist"));
|
||||
|
||||
String containerName = bucketPrefix + ".testDeleteContainer";
|
||||
|
@ -110,8 +112,6 @@ public class CloudFilesConnectionLiveTest {
|
|||
|
||||
@Test
|
||||
public void testPutContainers() throws Exception {
|
||||
CloudFilesConnection connection = CloudFilesContextBuilder.newBuilder(sysRackspaceUser,
|
||||
sysRackspaceKey).withJsonDebug().buildContext().getConnection();
|
||||
String containerName1 = bucketPrefix + ".hello";
|
||||
assertTrue(connection.putContainer(containerName1));
|
||||
// List only the container just created, using a marker with the container name less 1 char
|
||||
|
@ -143,8 +143,6 @@ public class CloudFilesConnectionLiveTest {
|
|||
|
||||
@Test
|
||||
public void testPutAndDeleteObjects() throws Exception {
|
||||
CloudFilesConnection connection = CloudFilesContextBuilder.newBuilder(sysRackspaceUser,
|
||||
sysRackspaceKey).withJsonDebug().buildContext().getConnection();
|
||||
String containerName = bucketPrefix + ".testPutAndDeleteObjects";
|
||||
String data = "Here is my data";
|
||||
|
||||
|
@ -157,10 +155,10 @@ public class CloudFilesConnectionLiveTest {
|
|||
object.getMetadata().setContentType("text/plain");
|
||||
// TODO: Metadata values aren't being stored by CF, but the names are. Odd...
|
||||
object.getMetadata().getUserMetadata().put(
|
||||
CloudFilesHeaders.USER_METADATA_PREFIX + "metadata", "metadata-value");
|
||||
CloudFilesHeaders.USER_METADATA_PREFIX + "metadata", "metadata-value");
|
||||
byte[] md5 = connection.putObject(containerName, object).get(10, TimeUnit.SECONDS);
|
||||
assertEquals(HttpUtils.toHexString(md5),
|
||||
HttpUtils.toHexString(object.getMetadata().getETag()));
|
||||
assertEquals(HttpUtils.toHexString(md5), HttpUtils
|
||||
.toHexString(object.getMetadata().getETag()));
|
||||
// TODO: Get and confirm data
|
||||
|
||||
// Test with invalid ETag (as if object's data was corrupted in transit)
|
||||
|
@ -171,7 +169,7 @@ public class CloudFilesConnectionLiveTest {
|
|||
connection.putObject(containerName, object).get(10, TimeUnit.SECONDS);
|
||||
} catch (Throwable e) {
|
||||
assertEquals(e.getCause().getClass(), HttpResponseException.class);
|
||||
assertEquals(((HttpResponseException)e.getCause()).getResponse().getStatusCode(), 422);
|
||||
assertEquals(((HttpResponseException) e.getCause()).getResponse().getStatusCode(), 422);
|
||||
}
|
||||
|
||||
// Test chunked/streamed upload with data of "unknown" length
|
||||
|
|
Loading…
Reference in New Issue