Examples of FilesClient


Examples of com.rackspacecloud.client.cloudfiles.FilesClient

    assertEquals("baz", client.getAccount());
       
  }

  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

Examples of com.rackspacecloud.client.cloudfiles.FilesClient

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

  public void testLogin() {
    FilesClient client = new FilesClient();
   
    try {
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
    } catch (Exception e) {
      fail(e.getMessage());
    }
   
    // Now try a failed login
    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

Examples of com.rackspacecloud.client.cloudfiles.FilesClient

  }
 
  public void testAccountInfo() {
    String containerName = createTempContainerName("byte-array");
    String filename = makeFileName("accountinfo");
    FilesClient client = new FilesClient();
    try {
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
     
      // 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));
     
      // 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

Examples of com.rackspacecloud.client.cloudfiles.FilesClient

    }    
  }
 
  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);
      client.useSnet();
      assertTrue(client.usingSnet());
      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

Examples of com.rackspacecloud.client.cloudfiles.FilesClient

      f.delete();
    }
  }

  public void testContainerCreation() {
    FilesClient client = new FilesClient();
    try {
      client.useSnet();
      assertTrue(client.usingSnet());
      assertTrue(client.login());
      String containerName = createTempContainerName("");
     
      // 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));
     
      // 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

Examples of com.rackspacecloud.client.cloudfiles.FilesClient

    } catch (Exception e) {
      fail(e.getMessage());
    }
  }
  public void testSnetToggle() {
    FilesClient client = new FilesClient();
    try {
      assertTrue(client.login());
      client.useSnet();
      assertTrue(client.usingSnet());
      String containerName = createTempContainerName("");
     
      // Make sure it's not there
      assertFalse(client.containerExists(containerName));
     
      // Add it
      client.createContainer(containerName);
      client.usePublic();
      assertFalse(client.usingSnet());
      // 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

Examples of com.rackspacecloud.client.cloudfiles.FilesClient

    }//catch ( IOException err)
  }

  public static void getContainerObjects (File localFolder, String containerName) throws IOException, HttpException, FilesAuthorizationException, NoSuchAlgorithmException, FilesException
  {
    FilesClient client = new FilesClient();
    if ( client.login() )
    {
      if (client.containerExists(containerName))
      {
        List<FilesObject> objects = client.listObjects(containerName);
        for (FilesObject obj: objects)
        {
          System.out.println ("\t"+StringUtils.rightPad(obj.getName (), 35)+ obj.getSizeString());
          File localFile = new File ( FilenameUtils.concat(localFolder.getAbsolutePath(), obj.getName()) );
          obj.writeObjectToFile (localFile);
View Full Code Here

Examples of com.rackspacecloud.client.cloudfiles.FilesClient

   * @throws NoSuchAlgorithmException
   * @throws FilesException
   */
  private static void copyToCreateContainerIfNeeded (File file, String mimeType,String containerName) throws IOException, HttpException, NoSuchAlgorithmException, FilesException
  {
    FilesClient client = new FilesClient();
    if ( client.login() )
    {
      if (client.containerExists(containerName))
      {
        logger.info ("Copying files to "+containerName);
        copyTo (file, mimeType, containerName);
      }
      else
      {
        logger.warn("The  container: "+containerName+" does not exist.  Creating it first before placing objects into it.");
        System.out.println ("The  container: "+containerName+" does not exist.  Creating it first before placing objects into it.");
        client.createContainer(containerName);
        copyTo (file, mimeType, containerName);   
      }

    }
  }
View Full Code Here

Examples of com.rackspacecloud.client.cloudfiles.FilesClient

   * @throws NoSuchAlgorithmException
   * @throws FilesException
   */
  private static void copyTo (File file, String mimeType,String containerName) throws IOException, HttpException, NoSuchAlgorithmException, FilesException
  {
    FilesClient client = new FilesClient();
    if ( client.login() )
    {
      if (client.containerExists(containerName))
        client.storeObject(containerName, file, mimeType);               
      else
      {
        logger.info("The  container: "+containerName+" does not exist.  Create it first before placing objects into it.");
        System.out.println ("The  container: "+containerName+" does not exist.  Create it first before placing objects into it.");
        System.exit (0);
View Full Code Here

Examples of com.rackspacecloud.client.cloudfiles.FilesClient

   

  }
 
  private boolean doLogin(final String username, final String password) throws Exception {   
    client = new FilesClient(username, password);
    return client.login();   
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.