コード例 #1
0
  @Test
  public void testListOwnedContainers() throws Exception {
    String containerPrefix = getContainerName();
    try {
      Set<ContainerMetadata> response = getApi().listContainers();
      assertNotNull(response);
      long initialContainerCount = response.size();
      assertTrue(initialContainerCount >= 0);

      // Create test containers
      String[] containerNames = {
        containerPrefix + ".testListOwnedContainers1", containerPrefix + ".testListOwnedContainers2"
      };
      assertTrue(getApi().createContainer(containerNames[0]));
      assertTrue(getApi().createContainer(containerNames[1]));

      // Test default listing
      response = getApi().listContainers();
      // assertEquals(response.size(), initialContainerCount + 2);// if the
      // containers already
      // exist, this will fail

      // Test listing with options
      response =
          getApi()
              .listContainers(
                  ListContainerOptions.Builder.afterMarker(
                          containerNames[0].substring(0, containerNames[0].length() - 1))
                      .maxResults(1));
      assertEquals(response.size(), 1);
      assertEquals(Iterables.get(response, 0).getName(), containerNames[0]);

      response =
          getApi()
              .listContainers(
                  ListContainerOptions.Builder.afterMarker(containerNames[0]).maxResults(1));
      assertEquals(response.size(), 1);
      assertEquals(Iterables.get(response, 0).getName(), containerNames[1]);

      // Cleanup and test containers have been removed
      assertTrue(getApi().deleteContainerIfEmpty(containerNames[0]));
      assertTrue(getApi().deleteContainerIfEmpty(containerNames[1]));
      response = getApi().listContainers();
      // assertEquals(response.size(), initialContainerCount + 2);// if the
      // containers already
      // exist, this will fail
    } finally {
      returnContainer(containerPrefix);
    }
  }
コード例 #2
0
  @Test
  public void testPutContainers() throws Exception {
    String containerName = getContainerName();
    try {
      String containerName1 = containerName + ".hello";
      assertTrue(getApi().createContainer(containerName1));
      // List only the container just created, using a marker with the
      // container name less 1 char
      Set<ContainerMetadata> response =
          getApi()
              .listContainers(
                  ListContainerOptions.Builder.afterMarker(
                          containerName1.substring(0, containerName1.length() - 1))
                      .maxResults(1));
      assertNotNull(response);
      assertEquals(response.size(), 1);
      assertEquals(Iterables.get(response, 0).getName(), containerName + ".hello");

      String containerName2 = containerName + "?should-be-illegal-question-char";
      assert getApi().createContainer(containerName2);

      assert getApi().createContainer(containerName + "/illegal-slash-char");

      assertTrue(getApi().deleteContainerIfEmpty(containerName1));
      assertTrue(getApi().deleteContainerIfEmpty(containerName2));
    } finally {
      returnContainer(containerName);
    }
  }