Package com.rackspacecloud.client.cloudfiles

Examples of com.rackspacecloud.client.cloudfiles.FilesClient


    String filename = makeFileName("<object>");
    String fullPath = FilenameUtils.concat(SYSTEM_TMP.getAbsolutePath(), filename);
    logger.info("Test File Location: " + fullPath);
    try {
      byte randomData[] = makeRandomFile(fullPath);
      FilesClient client = new FilesClient();
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
     
      // Set up
      client.createContainer(containerName);
     
      // Store it
      logger.info("About to save: " + filename);
      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());
      assertEquals(NUMBER_RANDOM_BYTES, obj.getSize());
      assertEquals(md5Sum(randomData), obj.getMd5sum());
     
      // 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
     
      // Clean up
      client.deleteObject(containerName, filename);
      assertTrue(client.deleteContainer(containerName));
     
    }
    catch (Exception e) {
      fail(e.getMessage());
    }
View Full Code Here


  public void testContainerListingWithXML() {
    String containerName = createTempContainerName("<container>");
    String filename = makeFileName("</name></object>");
    try {
      byte randomData[] = makeRandomBytes();
      FilesClient client = new FilesClient();
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
     
      // Set up
      client.createContainer(containerName);
     
      // Store it
      logger.info("About to save: " + filename);
      assertTrue(client.storeObject(containerName, randomData, "application/octet-stream", filename, new HashMap<String,String>()));
       
      // 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());
      assertEquals(NUMBER_RANDOM_BYTES, obj.getSize());
      assertEquals(md5Sum(randomData), obj.getMd5sum());
     
      // 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
     
      // Clean up
      client.deleteObject(containerName, filename);
      assertTrue(client.deleteContainer(containerName));
     
    }
    catch (Exception e) {
      fail(e.getMessage());
    }
View Full Code Here

  public void testByteArraySaving() {
    String containerName = createTempContainerName("byte-array");
    String filename = makeFileName("bytearray");
    try {
      byte randomData[] = makeRandomBytes();
      FilesClient client = new FilesClient();
      // client.setUseETag(false);
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
     
      // Set up
      client.createContainer(containerName);
     
      // Store it
      assertTrue(client.storeObject(containerName, randomData, "application/octet-stream", filename, new HashMap<String,String>()));
     
      // 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());
     
      // 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
     
      // Clean up
      client.deleteObject(containerName, filename);
      assertTrue(client.deleteContainer(containerName));
     
    }
    catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
View Full Code Here

  public void testLineNoiseSaving() {
    String containerName = createTempContainerName("[]<>{}!@#$%^&*()_-+=|,.?");
    String filename = makeFileName("/[]<>{}!@#$%^&*()_-+=|,.?/");
    try {
      byte randomData[] = makeRandomBytes();
      FilesClient client = new FilesClient();
      // client.setUseETag(false);
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
     
      // Set up
      client.createContainer(containerName);
     
      // Store it
      assertTrue(client.storeObject(containerName, randomData, "application/octet-stream", filename, new HashMap<String,String>()));
     
      // 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());
     
      // 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
     
      // Clean up
      client.deleteObject(containerName, filename);
      assertTrue(client.deleteContainer(containerName));
     
    }
    catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
View Full Code Here

  public void testRequestEntitySaving() {
    String containerName = createTempContainerName("requst-entity");
    String filename = makeFileName("req-entity");
    try {
      byte randomData[] = makeRandomBytes();
      FilesClient client = new FilesClient();
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
     
      // Set up
      client.createContainer(containerName);
     
      // Store it
      assertTrue(client.storeObject(containerName, randomData, "test/content_type", filename, new HashMap<String,String>()));
     
      // 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("test/content_type", obj.getMimeType());
     
      // 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
     
      // Clean up
      client.deleteObject(containerName, filename);
      assertTrue(client.deleteContainer(containerName));
     
    }
    catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
View Full Code Here

  public void testObjectListing() {
    String containerName = createTempContainerName("object-listing-marker");
    try {
      byte randomData[] = makeRandomBytes();
      FilesClient client = new FilesClient();
      // client.setUseETag(false);
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
     
      // Set up
      client.createContainer(containerName);
     
      // Store it
      for (int i=0; i < 10; i++) {
        assertTrue(client.storeObject(containerName, randomData, "application/octet-stream", "testfile" + i + ".bogus", new HashMap<String,String>()));
      }
     
      // Make sure it's there
      List<FilesObject> objects = client.listObjects(containerName);
      assertEquals(10, objects.size());
      for (int i=0; i < 10; i++) {
        FilesObject obj = objects.get(i);
        assertEquals("testfile" + i + ".bogus", obj.getName());
        assertEquals("application/octet-stream", obj.getMimeType());
      }

      // Now do a limit
      objects = client.listObjects(containerName, 3);
      assertEquals(3, objects.size());
      for (int i=0; i < 3; i++) {
        FilesObject obj = objects.get(i);
        assertEquals("testfile" + i + ".bogus", obj.getName());
        assertEquals("application/octet-stream", obj.getMimeType());
      }
     
      // Now check out a marker
      objects = client.listObjects(containerName, 4, "testfile3.bogus");
      assertEquals(4, objects.size());
      for (int i=0; i < 4; i++) {
        FilesObject obj = objects.get(i);
        assertEquals("testfile" + (i + 4) + ".bogus", obj.getName());
        assertEquals("application/octet-stream", obj.getMimeType());
      }
     
      // Clean up
      for (int i=0; i < 10; i++) {
        client.deleteObject(containerName, "testfile" + i + ".bogus");
      }
      assertTrue(client.deleteContainer(containerName));
     
    }
    catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
View Full Code Here

    }   
  }

  public void testContainerListingWithLimitMarker() {
    try {
      FilesClient client = new FilesClient();
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
     
      // Populate our  account
      for (int i=0; i < 20; i++) {
        client.createContainer("test_container_" + i);
      }
     
      // Make sure it's there
      List<FilesContainer> originalContainers = client.listContainers();
      assertTrue(20 <=originalContainers.size());

      // Now do a limit
      List<FilesContainer> containers = client.listContainers(5);
      assertEquals(5, containers.size());
      for (int i=0; i < 5; i++) {
        FilesContainer container = containers.get(i);
        assertEquals(originalContainers.get(i).getName(), container.getName());
      }
     
      // Now check out a marker
      containers = client.listContainers(10, originalContainers.get(originalContainers.size() - 5).getName());
      assertEquals(4, containers.size());
      for (int i=0; i < 2; i++) {
        FilesContainer container = containers.get(i);
        assertEquals(originalContainers.get(originalContainers.size() - 4 + i).getName(), container.getName());
      }
     
      // Clean up
      for (int i=0; i < 20; i++) {
        assertTrue(client.deleteContainer("test_container_" + i));
     
    }
    catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
View Full Code Here

  public void testByteArraySavingWithCallback() {
    String containerName = createTempContainerName("byte-array");
    String filename = makeFileName("bytearray");
    try {
      byte randomData[] = makeRandomBytes(1024 * 100); // 100 K to make sure we do more with the callback
      FilesClient client = new FilesClient();
      // client.setUseETag(false);
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
     
      // Set up
      client.createContainer(containerName);
     
      // Store it
      TesterCallback callback = new TesterCallback();
      assertTrue(client.storeObject(containerName, randomData, "application/octet-stream", filename, new HashMap<String,String>(), callback));
     
      // Make sure it all got written
      assertEquals(randomData.length, callback.bytesSent);
      assertEquals(randomData.length/8192 + 1, callback.nCalls);
     
      // 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());
     
      // 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[randomData.length];
      int loc = 0;
      int bytesRead = 0;
      while ((bytesRead = is.read(otherData, loc, otherData.length - loc)) > 0) {
        loc += bytesRead;
      }
      assertArrayEquals(randomData, otherData);
      assertEquals(-1, is.read()); // Could hang if there's a bug on the other end
     
      // Clean up
      client.deleteObject(containerName, filename);
      assertTrue(client.deleteContainer(containerName));
     
    }
    catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
View Full Code Here

  public void testStreamedSaving() {
    String containerName = createTempContainerName("streamed");
    String filename = makeFileName("streamed");
    try {
      byte randomData[] = makeRandomBytes(1024 * 100); // 100 K to make sure it's interesting
      FilesClient client = new FilesClient();
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
     
      // Set up
      client.createContainer(containerName);
     
      // Store it
      assertNotNull(client.storeStreamedObject(containerName, new ByteArrayInputStream(randomData), "application/octet-stream", filename, new HashMap<String,String>()));
     
      // 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());
     
      // 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[randomData.length];
      int loc = 0;
      int bytesRead = 0;
      while ((bytesRead = is.read(otherData, loc, otherData.length - loc)) > 0) {
        loc += bytesRead;
      }
      assertArrayEquals(randomData, otherData);
      assertEquals(-1, is.read()); // Could hang if there's a bug on the other end
     
      // Clean up
      client.deleteObject(containerName, filename);
      assertTrue(client.deleteContainer(containerName));
     
    }
    catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
View Full Code Here

    private static Logger logger = Logger.getLogger(FilesClientTestCase.class);
  private static File SYSTEM_TMP = SystemUtils.getJavaIoTmpDir();
  private static int NUMBER_RANDOM_BYTES = 513;
 
  public void testConstructor() {
    FilesClient client = new FilesClient("foo", "bar", "baz");
   
    assertNotNull(client);
    assertEquals("foo", client.getUserName());
    assertEquals("bar", client.getPassword());
    assertEquals("baz", client.getAccount());
       
  }
View Full Code Here

TOP

Related Classes of com.rackspacecloud.client.cloudfiles.FilesClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.