/** Test that BlobRequestSigner creates expected URIs. */
  public void testBlobRequestSigner() throws Exception {
    String containerName = "container";
    String blobName = "blob";
    URI endPoint =
        new URI(
            "http",
            "localhost",
            String.format("/transient/%s/%s", containerName, blobName),
            /*fragment=*/ null);
    BlobRequestSigner signer = context.getSigner();
    HttpRequest request;
    HttpRequest expected;

    request = signer.signGetBlob(containerName, blobName);
    expected =
        HttpRequest.builder()
            .method("GET")
            .endpoint(endPoint)
            .headers(request.getHeaders())
            .build();
    assertEquals(expected, request);

    request = signer.signRemoveBlob(containerName, blobName);
    expected =
        HttpRequest.builder()
            .method("DELETE")
            .endpoint(endPoint)
            .headers(request.getHeaders())
            .build();
    assertEquals(expected, request);

    Blob blob = blobStore.blobBuilder(blobName).forSigning().build();
    request = signer.signPutBlob(containerName, blob);
    expected =
        HttpRequest.builder()
            .method("PUT")
            .endpoint(endPoint)
            .headers(request.getHeaders())
            .payload(new PhantomPayload())
            .build();
    assertEquals(expected, request);
  }
  public void testSignRemoveBlob()
      throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
          NoSuchMethodException, IOException {
    HttpRequest request = signer.signRemoveBlob("container", "name");

    assertRequestLineEquals(request, "DELETE http://storageUrl/container/name HTTP/1.1");
    assertNonPayloadHeadersEqual(request, "X-Auth-Token: testtoken\n");
    assertPayloadEquals(request, null, null, false);

    assertEquals(request.getFilters().size(), 0);
  }
  public void testSignGetBlob()
      throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
          NoSuchMethodException, IOException {
    HttpRequest request = signer.signGetBlob("container", "name");

    assertRequestLineEquals(
        request, "GET https://accesspoint.atmosonline.com/rest/namespace/container/name HTTP/1.1");
    assertNonPayloadHeadersEqual(
        request,
        "Accept: */*\nDate: Thu, 05 Jun 2008 16:38:19 GMT\nx-emc-signature: Mhe5tqaKv04BlMvEjreNKkHHxzk=\nx-emc-uid: identity\n");
    assertPayloadEquals(request, null, null, false);

    assertEquals(request.getFilters().size(), 0);
  }
  public void testSignPutBlob()
      throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
          NoSuchMethodException, IOException {
    Blob blob = blobFactory.create(null);
    blob.getMetadata().setName("name");
    blob.setPayload("");
    blob.getPayload().getContentMetadata().setContentLength(2l);
    blob.getPayload().getContentMetadata().setContentMD5(new byte[] {0, 2, 4, 8});
    blob.getPayload().getContentMetadata().setContentType("text/plain");

    HttpRequest request = signer.signPutBlob("container", blob);

    assertRequestLineEquals(request, "PUT http://storageUrl/container/name HTTP/1.1");
    assertNonPayloadHeadersEqual(request, "X-Auth-Token: testtoken\n");
    assertContentHeadersEqual(
        request, "text/plain", null, null, null, (long) 2l, new byte[] {0, 2, 4, 8});

    assertEquals(request.getFilters().size(), 0);
  }
  public void testSignPutBlob()
      throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
          NoSuchMethodException, IOException {
    Blob blob = blobFactory.create(null);
    blob.getMetadata().setName("name");
    blob.setPayload("");
    blob.getPayload().getContentMetadata().setContentLength(2l);
    blob.getPayload().getContentMetadata().setContentMD5(new byte[] {0, 2, 4, 8});
    blob.getPayload().getContentMetadata().setContentType("text/plain");

    HttpRequest request = signer.signPutBlob("container", blob);

    assertRequestLineEquals(
        request, "POST https://accesspoint.atmosonline.com/rest/namespace/container/name HTTP/1.1");
    assertNonPayloadHeadersEqual(
        request,
        "Accept: */*\nDate: Thu, 05 Jun 2008 16:38:19 GMT\nx-emc-signature: aLpB1oQaCA27AXT6Nzam7s0f0pI=\nx-emc-uid: identity\n");

    assertContentHeadersEqual(
        request, "text/plain", null, null, null, (long) 2l, new byte[] {0, 2, 4, 8});

    assertEquals(request.getFilters().size(), 0);
  }