Package com.rackspacecloud.client.cloudfiles

Examples of com.rackspacecloud.client.cloudfiles.FilesClient


    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");
   
    assertNotNull(client);
    assertEquals("foo", client.getUserName());
    assertEquals("bar", client.getPassword());
       
  }
View Full Code Here


    assertEquals("bar", client.getPassword());
       
  }

  public void testNoArgConstructor() {
    FilesClient client = new FilesClient();
   
    assertNotNull(client);
    assertEquals(FilesUtil.getProperty("username"), client.getUserName());
    assertEquals(FilesUtil.getProperty("password"), client.getPassword());
    assertEquals(FilesUtil.getProperty("account"), client.getAccount());
  }
View Full Code Here

    assertEquals(FilesUtil.getProperty("password"), client.getPassword());
    assertEquals(FilesUtil.getProperty("account"), client.getAccount());
  }

  public void testLogin() {
    FilesClient client = new FilesClient();
   
    try {
      assertTrue(client.login());
    } catch (Exception e) {
      fail(e.getMessage());
    }
   
    // Now try a failed login
    // Note: This causes a warning from DefaultHttpClient along these lines:
    //       13 Dec 2010 15:46:26 WARN  impl.client.DefaultHttpClient - Authentication error: Unable to respond to any of these challenges: {}
    //       It's just trying a little too hard to be helpful. 
    client = new FilesClient(FilesUtil.getProperty("username"),
                    FilesUtil.getProperty("password") + " this is a bogus password",
                    FilesUtil.getProperty("account"));
    try {
      assertFalse(client.login());
    } catch (Exception e) {
      fail(e.getMessage());
    }
  }
View Full Code Here

  }
 
  public void testAccountInfo() {
    String containerName = createTempContainerName("acct-info");
    String filename = makeFileName("accountinfo");
    FilesClient client = new FilesClient();
    try {
      assertTrue(client.login());
     
      // Make sure it's not there
      assertFalse(client.containerExists(containerName));
     
      // Add it
      //logger.error(client.getStorageURL());
      client.createContainer(containerName);
     
      // See that it's there
      assertTrue(client.containerExists(containerName));
      assertNotNull(client.getContainerInfo(containerName));
     
      // Add some data
      byte randomData[] = makeRandomBytes();
      assertTrue(client.storeObject(containerName, randomData, "application/octet-stream", filename, new HashMap<String,String>()));
     
      // Do the test if we have an account
      if (FilesUtil.getProperty("account") != null) {
        FilesAccountInfo info = client.getAccountInfo();
        assertTrue(info.getContainerCount() > 0);
        assertTrue(info.getBytesUsed() >= randomData.length);
      }
     
      // Clean up
      client.deleteObject(containerName, filename);
      assertTrue(client.deleteContainer(containerName));
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }    
  }
View Full Code Here

    }    
  }
 
  public void testMultipleFilesNotThere() {
      // Tests to make sure we're releasing connections with 404's
    FilesClient client = new FilesClient();
    String filename = makeFileName("random");
    String fullPath = FilenameUtils.concat(SYSTEM_TMP.getAbsolutePath(), filename);
    try {
      byte[] content = makeRandomFile(fullPath);
      assertTrue(client.login());
      String containerName = createTempContainerName("file-not-there");
      client.createContainer(containerName);
     
      String[] names =  new String[10];
      for(int i=0; i < 10; ++i) names[i] = "File" + (i + 1) + ".txt";
      for(int i=0; i < 5; ++i)      
        assertNotNull(client.storeObjectAs(containerName, new File(fullPath), "application/octet-stream", names[i]));

            for (int i = 0; i < 10; i++) {
                String fileName = names[i];

                byte[] retrievedContent = null;
                try {
                    retrievedContent = client.getObject(containerName, fileName);
                    assertArrayEquals(content, retrievedContent);
                } catch(FilesNotFoundException ex) {
                    assertTrue(i >= 5);
                }
            }
       // Cleanup
      for(int i=0; i < 5; ++i)      
        client.deleteObject(containerName, names[i]);
      client.deleteContainer(containerName);

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

      f.delete();
    }
  }

  public void testContainerCreation() {
    FilesClient client = new FilesClient();
    try {
      assertTrue(client.login());
      String containerName = createTempContainerName("container");
     
      // Make sure it's not there
      assertFalse(client.containerExists(containerName));
     
      // Add it
      //logger.error("Creating the container");
      client.createContainer(containerName);
      //logger.error("URL:\n" + client.getStorageURL() + "/" + containerName + "\n");
      //Thread.sleep(10000);
     
      // 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));
     
      // 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 testAlternateLoginMethod() {
    FilesClient client = new FilesClient();
    try {
      assertTrue(client.login());
      String containerName = createTempContainerName("container");
     
      // Make sure it's not there
      assertFalse(client.containerExists(containerName));
     
      // Add it
      //logger.error("Creating the container");
      client.createContainer(containerName);
      //logger.error("URL:\n" + client.getStorageURL() + "/" + containerName + "\n");
      Thread.sleep(1000);
     
      // See that it's there
      assertTrue(client.containerExists(containerName));
      assertNotNull(client.getContainerInfo(containerName));
     
      // Create a new Client
      FilesClient newClient = new FilesClient();
      newClient.login(client.getAuthToken(), client.getStorageURL(), client.getCdnManagementURL());
     
      // See that it's still there
      assertTrue(newClient.containerExists(containerName));
      assertNotNull(newClient.getContainerInfo(containerName));
     
      // Try Adding it again
      try {
        newClient.createContainer(containerName);
        fail("Allowed duplicate container creation");
      }
      catch (FilesContainerExistsException fcee) {
        // Hooray!
      }
     
      // See that it's still there
      assertTrue(newClient.containerExists(containerName));
     
      // Delete it
      assertTrue(newClient.deleteContainer(containerName));
     
      // Make sure it's gone
      assertFalse(newClient.containerExists(containerName));
     

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

      fail(e.getMessage());
    }
  }
 
  public void testContainerNotThereDeletion() {
    FilesClient client = new FilesClient();
    try {
      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 {
      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) {
      e.printStackTrace();
      fail(e.getMessage());
View Full Code Here

      fail(e.getMessage());
    }
  }
 
  public void testContainerInfoListing() {
    FilesClient client = new FilesClient();
    try {
      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

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.