filename = makeFileName("\u00f1\u00efcode-test-\u03de");
String fullPath = FilenameUtils.concat(SYSTEM_TMP.getAbsolutePath(), filename);
logger.info("Test File Location: " + fullPath);
try {
byte randomData[] = makeRandomFile(fullPath);
FilesClient client = new FilesClient(FilesUtil.getProperty("username"), FilesUtil.getProperty("password"), FilesUtil.getProperty("account"));
client.useSnet();
assertTrue(client.usingSnet());
assertTrue(client.login());
// Set up
client.createContainer(containerName);
// Store it
assertNotNull(client.storeObjectAs(containerName, new File(fullPath), "application/octet-stream", filename));
// Make sure it's there
List<FilesObject> objects = client.listObjects(containerName);
assertEquals(1, objects.size());
FilesObject obj = objects.get(0);
assertEquals(filename, obj.getName());
assertEquals("application/octet-stream", obj.getMimeType());
assertNotNull(obj.getMetaData());
// Make sure the data is correct
assertArrayEquals(randomData, client.getObject(containerName, filename));
// Make sure the data is correct as a stream
InputStream is = client.getObjectAsStream(containerName, filename);
byte otherData[] = new byte[NUMBER_RANDOM_BYTES];
is.read(otherData);
assertArrayEquals(randomData, otherData);
assertEquals(-1, is.read()); // Could hang if there's a bug on the other end
// Make sure we can get the container info
assertNotNull(client.getContainerInfo(containerName));
// Clean up
client.deleteObject(containerName, filename);
assertTrue(client.deleteContainer(containerName));
}
catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());