Package com.rackspacecloud.client.cloudfiles

Examples of com.rackspacecloud.client.cloudfiles.FilesClient


    } catch (Exception e) {
      fail(e.getMessage());
    }
  }
  public void testContainerNotThereDeletion() {
    FilesClient client = new FilesClient();
    try {
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
      String containerName = createTempContainerName("I'mNotHere!");
     
      // Make sure it's not there
      assertFalse(client.containerExists(containerName));
     
      boolean exceptionThrown = false;
      try {
        client.deleteContainer(containerName);
        fail("Exception not thrown");
      }
      catch (FilesNotFoundException fnfe) {
        exceptionThrown = true;
      }
      assertTrue (exceptionThrown);
     
      // Make still not there
      assertFalse(client.containerExists(containerName));
     

    } catch (Exception e) {
      fail(e.getMessage());
    }
View Full Code Here


      fail(e.getMessage());
    }
  }
 
  public void testContainerCreationWithSpaces() {
    FilesClient client = new FilesClient();
    try {
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
      String containerName = createTempContainerName("with space+and+plus");
     
      // Make sure it's not there
      assertFalse(client.containerExists(containerName));
     
      // Add it
      client.createContainer(containerName);
     
      // See that it's there
      assertTrue(client.containerExists(containerName));
      assertNotNull(client.getContainerInfo(containerName));
     
      // Try Adding it again
      try {
        client.createContainer(containerName);
        fail("Allowed duplicate container creation");
      }
      catch (FilesContainerExistsException fcee) {
        // Pass this case
      }
     
      // See that it's still there
      assertTrue(client.containerExists(containerName));
     
      boolean found = false;
      List<FilesContainer> containers = client.listContainers();
      for (FilesContainer cont : containers) {
        // logger.warn(cont.getName());
        if(containerName.equals(cont.getName())) found = true;
      }
      assertTrue(found);
     
     
      // Delete it
      assertTrue(client.deleteContainer(containerName));
     
      // Make sure it's gone
      assertFalse(client.containerExists(containerName));
     

    } catch (Exception e) {
      fail(e.getMessage());
    }
View Full Code Here

      fail(e.getMessage());
    }
  }
 
  public void testContainerInfoListing() {
    FilesClient client = new FilesClient();
    try {
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
      String containerName = createTempContainerName("<container with\u1422 spaces>");
     
      // Make sure it's not there
      assertFalse(client.containerExists(containerName));
     
      // Add it
      client.createContainer(containerName);
     
      // See that it's there
      assertTrue(client.containerExists(containerName));
      assertNotNull(client.getContainerInfo(containerName));
     
      // Try Adding it again
      try {
        client.createContainer(containerName);
        fail("Allowed duplicate container creation");
      }
      catch (FilesContainerExistsException fcee) {
        // Hooray!
      }
     
      // See that it's still there
      assertTrue(client.containerExists(containerName));
     
      boolean found = false;
      List<FilesContainerInfo> containers = client.listContainersInfo();
      for (FilesContainerInfo info : containers) {
        if(containerName.equals(info.getName())) {
          found = true;
          assertEquals(0, info.getTotalSize());
          assertEquals(0, info.getObjectCount());
        }
      }
      assertTrue(found);
     
     
      // Delete it
      assertTrue(client.deleteContainer(containerName));
     
      // Make sure it's gone
      assertFalse(client.containerExists(containerName));
     

    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
View Full Code Here

      fail(e.getMessage());
    }
  }
 
  public void testUserAgent() {
    FilesClient client = new FilesClient();
    assertEquals(FilesConstants.USER_AGENT, client.getUserAgent());
    client.setUserAgent("Java-Test-User-Agent");
    assertEquals("Java-Test-User-Agent", client.getUserAgent());
    try {
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
      String containerName = createTempContainerName("user-agent");
     
      // Make sure it's not there
      assertFalse(client.containerExists(containerName));
     
      // Add it
      client.createContainer(containerName);
     
      // See that it's there
      assertTrue(client.containerExists(containerName));
      assertNotNull(client.getContainerInfo(containerName));
     
      // Delete it
      assertTrue(client.deleteContainer(containerName));
     
      // Make sure it's gone
      assertFalse(client.containerExists(containerName));
     

    } catch (Exception e) {
      fail(e.getMessage());
    }
View Full Code Here

      fail(e.getMessage());
    }
  }
 
  public void testContainerNameNoSlashes() {
    FilesClient client = new FilesClient();
    try {
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
      String containerName = createTempContainerName("/");
     
      // Make sure they're not there
      assertFalse(client.containerExists(containerName));
     
      // Try to add it
      boolean exceptionThrown = false;
      try {
        client.createContainer(containerName);
        fail("Should not have been able to create container: " + containerName);
      }
      catch (FilesInvalidNameException fine) {
        exceptionThrown = true;
      }
View Full Code Here

    String filename = makeFileName("random");
    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());
     
      // 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

    String fullPath = FilenameUtils.concat(SYSTEM_TMP.getAbsolutePath(), filename);
    String otherFileName = "Bob";
    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", otherFileName));
     
      // Make sure it's there
      List<FilesObject> objects = client.listObjects(containerName);
      assertEquals(1, objects.size());
      FilesObject obj = objects.get(0);
      assertEquals("Bob", obj.getName());
      assertEquals("application/octet-stream", obj.getMimeType());
     
      // Make sure the data is correct
      assertArrayEquals(randomData, client.getObject(containerName, otherFileName));
     
      // Make sure the data is correct as a stream
      InputStream is = client.getObjectAsStream(containerName, otherFileName);
      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, otherFileName);
      assertTrue(client.deleteContainer(containerName));
     
    }
    catch (Exception e) {
      fail(e.getMessage());
    }
View Full Code Here

    String filename = makeFileName("random");
    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);
      TesterCallback callback = new TesterCallback();
      assertNotNull(client.storeObjectAs(containerName, new File(fullPath), "application/octet-stream", filename, callback));
     
      // Make sure the callback was called
      assertEquals(randomData.length, callback.bytesSent);
      assertEquals(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[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();
      if (e.getCause() != null) e.getCause().printStackTrace();
View Full Code Here

    String filename = makeFileName("random-with-meta");
    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
      HashMap<String,String> meta = new HashMap<String,String>();
      meta.put("Foo", "bar");
      meta.put("Uni", "\u0169\u00f1\u00efcode-test");
      meta.put("Width", "336");
      meta.put("Height", "183");
      assertNotNull(client.storeObjectAs(containerName, new File(fullPath), "application/octet-stream", filename, meta));
     
      // 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
     
      // Make sure the metadata is correct
      FilesObjectMetaData metadata = client.getObjectMetaData(containerName, filename);
      assertNotNull(metadata);
      Map<String,String> serverMetadata = metadata.getMetaData();
      assertEquals(meta.size(), serverMetadata.size());
      for(String key : meta.keySet()) {
        assertTrue(serverMetadata.containsKey(key));
        assertEquals(meta.get(key), serverMetadata.get(key));
      }
     
      // Clean up
      client.deleteObject(containerName, filename);
      assertTrue(client.deleteContainer(containerName));
     
    }
    catch (FilesException e) {
      e.printStackTrace();
      fail(e.getHttpStatusMessage() + ":" + e.getMessage());
View Full Code Here

    String filename = makeFileName("etagless");
    String fullPath = FilenameUtils.concat(SYSTEM_TMP.getAbsolutePath(), filename);
    logger.info("Test File Location: " + fullPath);
    try {
      byte randomData[] = makeRandomFile(fullPath);
      FilesClient client = new FilesClient();
      assertTrue(client.getUseETag());
      client.setUseETag(false);
      assertFalse(client.getUseETag());
      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());
     
      // 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

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.