public void testCreateZoneWhenResponseIs2xxAnd404() {
    GlobalZoneApi client =
        requestSendsResponse(
            createZone,
            HttpResponse.builder()
                .statusCode(200)
                .payload(payloadFromResource("/createzoneresponse.json"))
                .build());

    assertEquals(
        client.createZone("test-zone", NetworkType.BASIC, "8.8.8.8", "10.10.10.10"),
        Zone.builder()
            .id("6")
            .name("test-zone")
            .DNS(ImmutableList.of("8.8.8.8"))
            .internalDNS(ImmutableList.of("10.10.10.10"))
            .networkType(NetworkType.BASIC)
            .securityGroupsEnabled(true)
            .allocationState(AllocationState.ENABLED)
            .zoneToken("7b6e27df-30a6-3024-9d8b-7971a3127f64")
            .dhcpProvider("DhcpServer")
            .build());

    client = requestSendsResponse(createZone, HttpResponse.builder().statusCode(404).build());
    assertNull(client.createZone("test-zone", NetworkType.BASIC, "8.8.8.8", "10.10.10.10"));
  }
  @Test(enabled = true)
  public void testReboot() {

    URI vAppRebootUri = URI.create(endpoint + "/vApp/" + vAppId + "/power/action/reboot");

    HttpRequest vAppEntityRequest =
        HttpRequest.builder()
            .method("GET")
            .endpoint(URI.create(endpoint + "/entity/" + vAppUrn))
            .addHeader("Accept", "*/*")
            .addHeader("x-vcloud-authorization", token)
            .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
            .build();

    HttpResponse vAppEntityResponse =
        HttpResponse.builder()
            .payload(
                payloadFromResourceWithContentType(
                    "/vapp/vAppEntity.xml", VCloudDirectorMediaType.ENTITY))
            .statusCode(200)
            .build();

    HttpRequest vAppRebootRequest =
        HttpRequest.builder()
            .method("POST")
            .endpoint(vAppRebootUri)
            .addHeader("Accept", "application/vnd.vmware.vcloud.task+xml")
            .addHeader("x-vcloud-authorization", token)
            .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + token)
            .build();

    HttpResponse vAppRebootResponse =
        HttpResponse.builder()
            .payload(
                payloadFromResourceWithContentType(
                    "/vapp/vAppRebootTask.xml", VCloudDirectorMediaType.TASK))
            .statusCode(200)
            .build();

    VCloudDirectorApi vCloudDirectorApi =
        requestsSendResponses(
            loginRequest, sessionResponse,
            vAppEntityRequest, vAppEntityResponse,
            vAppRebootRequest, vAppRebootResponse);

    Task actual = vCloudDirectorApi.getVAppApi().reboot(vAppUrn);
    Task expected = rebootTask();

    assertEquals(actual, expected);
  }
示例#3
0
  public void testListTenants() {
    ServiceApi api =
        requestsSendResponses(
                keystoneAuthWithUsernameAndPasswordAndTenantName,
                responseWithKeystoneAccess,
                authenticatedGET().endpoint(endpoint + "/v2.0/tenants").build(),
                HttpResponse.builder()
                    .statusCode(200)
                    .payload(
                        payloadFromResourceWithContentType("/tenant_list.json", APPLICATION_JSON))
                    .build())
            .getServiceApi();
    Set<? extends Tenant> tenants = api.listTenants();
    assertNotNull(tenants);
    assertFalse(tenants.isEmpty());

    Set<Tenant> expected =
        ImmutableSet.of(
            Tenant.builder()
                .name("demo")
                .id("05d1dc7af71646deba64cfc17b81bec0")
                .enabled(true)
                .build(),
            Tenant.builder()
                .name("admin")
                .id("7aa2e17ec29f44d193c48feaba0852cc")
                .enabled(true)
                .build());

    assertEquals(tenants, expected);
  }
示例#4
0
  public void testGrantUserFail() {
    URI endpoint =
        URI.create(
            "http://172.16.0.1:8776/v1/3456/instances/instanceId-1234-5678/users/dbuser1/databases");
    UserApi api =
        requestsSendResponses(
                keystoneAuthWithUsernameAndPasswordAndTenantName,
                responseWithKeystoneAccess,
                authenticatedGET()
                    .endpoint(
                        endpoint) // bad naming convention, you should not be able to change the
                                  // method to POST
                    .method("PUT")
                    .payload(
                        payloadFromResourceWithContentType(
                            "/user_grant_request.json", MediaType.APPLICATION_JSON))
                    .build(),
                HttpResponse.builder().statusCode(404).build() // response
                )
            .getUserApi("RegionOne", "instanceId-1234-5678");

    List<String> databases = Lists.newArrayList();
    databases.add("databaseC");
    databases.add("databaseD");

    boolean result = api.grant("dbuser1", databases);
    assertFalse(result);
  }
  public void testUpdateDomainWhenResponseIs2xx() {
    GlobalDomainClient client =
        requestSendsResponse(
            HttpRequest.builder()
                .method("GET")
                .endpoint(
                    URI.create(
                        "http://localhost:8080/client/api?response=json&"
                            + "command=updateDomain&id=10&name=test-2&apiKey=identity&signature=5t1eUf2Eyf%2FaB6qt%2BqIj%2BmcwFIo%3D"))
                .addHeader("Accept", "application/json")
                .build(),
            HttpResponse.builder()
                .statusCode(200)
                .payload(payloadFromResource("/updatedomainresponse.json"))
                .build());

    assertEquals(
        client.updateDomain("10", name("test-2")),
        Domain.builder()
            .id("10")
            .name("test-2")
            .level(1)
            .parentDomainId("1")
            .parentDomainName("ROOT")
            .hasChild(false)
            .build());
  }
  public void testCreateDomainWhenResponseIs2xx() {
    GlobalDomainClient client =
        requestSendsResponse(
            HttpRequest.builder()
                .method("GET")
                .endpoint(
                    URI.create(
                        "http://localhost:8080/client/api?response=json&command=createDomain&"
                            + "name=test&apiKey=identity&signature=6cxzEo7h63G0hgTTMLm4lGsSDK8%3D"))
                .addHeader("Accept", "application/json")
                .build(),
            HttpResponse.builder()
                .statusCode(200)
                .payload(payloadFromResource("/createdomainresponse.json"))
                .build());

    assertEquals(
        client.createDomain("test"),
        Domain.builder()
            .id("10")
            .name("test")
            .level(1)
            .parentDomainId("1")
            .parentDomainName("ROOT")
            .hasChild(false)
            .build());
  }
  @Override
  protected HttpResponse invoke(Request nativeRequest) throws IOException, InterruptedException {
    OkHttpClient requestScopedClient = globalClient.clone();
    requestScopedClient.setProxy(proxyForURI.apply(nativeRequest.uri()));

    Response response = requestScopedClient.newCall(nativeRequest).execute();

    HttpResponse.Builder<?> builder = HttpResponse.builder();
    builder.statusCode(response.code());
    builder.message(response.message());

    Builder<String, String> headerBuilder = ImmutableMultimap.builder();
    Headers responseHeaders = response.headers();
    for (String header : responseHeaders.names()) {
      headerBuilder.putAll(header, responseHeaders.values(header));
    }

    ImmutableMultimap<String, String> headers = headerBuilder.build();

    if (response.code() == 204 && response.body() != null) {
      response.body().close();
    } else {
      Payload payload = newInputStreamPayload(response.body().byteStream());
      contentMetadataCodec.fromHeaders(payload.getContentMetadata(), headers);
      builder.payload(payload);
    }

    builder.headers(filterOutContentHeaders(headers));

    return builder.build();
  }
  private void assertCodeMakes(
      String method,
      URI uri,
      int statusCode,
      String message,
      String contentType,
      String content,
      Class<? extends Exception> expected) {

    SoftLayerErrorHandler function =
        Guice.createInjector().getInstance(SoftLayerErrorHandler.class);

    HttpCommand command = createMock(HttpCommand.class);
    HttpRequest request = HttpRequest.builder().method(method).endpoint(uri).build();
    HttpResponse response =
        HttpResponse.builder().statusCode(statusCode).message(message).payload(content).build();
    response.getPayload().getContentMetadata().setContentType(contentType);

    expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
    command.setException(classEq(expected));

    replay(command);

    function.handleError(command, response);

    verify(command);
  }
  @Test
  void testMultipartDoesntAttemptToParseETagIntoMD5() throws Exception {
    HttpResponse http =
        HttpResponse.builder()
            .statusCode(400)
            .message("boa")
            .payload("")
            .addHeader(S3Headers.USER_METADATA_PREFIX + "foo", "bar")
            .addHeader(HttpHeaders.LAST_MODIFIED, lastModified)
            .addHeader(HttpHeaders.ETAG, "\"abcd-1\"")
            .addHeader(HttpHeaders.CACHE_CONTROL, "cacheControl")
            .build();
    http.getPayload().getContentMetadata().setContentLength(1025l);
    http.getPayload().getContentMetadata().setContentDisposition("contentDisposition");
    http.getPayload().getContentMetadata().setContentEncoding("encoding");
    http.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_OCTET_STREAM);

    MutableObjectMetadata response = parser.apply(http);

    MutableObjectMetadataImpl expects = new MutableObjectMetadataImpl();
    expects.setCacheControl("cacheControl");
    expects.getContentMetadata().setContentDisposition("contentDisposition");
    expects.getContentMetadata().setContentEncoding("encoding");
    expects.getContentMetadata().setContentType(MediaType.APPLICATION_OCTET_STREAM);
    expects.getContentMetadata().setContentLength(1025l);
    expects.setETag("\"abcd-1\"");
    expects.setKey("key");
    expects.setLastModified(now);
    expects.setOwner(null);
    expects.setStorageClass(StorageClass.STANDARD);
    expects.setUserMetadata(userMetadata);
    assertEquals(response, expects);
  }
示例#10
0
  public void testListLimits() {
    URI endpoint = URI.create("https://dns.api.rackspacecloud.com/v1.0/123123/limits");
    LimitApi api =
        requestsSendResponses(
                rackspaceAuthWithUsernameAndApiKey,
                responseWithAccess,
                authenticatedGET().endpoint(endpoint).build(),
                HttpResponse.builder()
                    .statusCode(200)
                    .payload(payloadFromResource("/limit-list.json"))
                    .build())
            .getLimitApi();

    Limits limits = api.list();
    assertEquals(limits.getAbsoluteLimits().get("records per domain"), Integer.valueOf(500));
    assertEquals(limits.getAbsoluteLimits().get("domains"), Integer.valueOf(500));
    assertEquals(Iterables.size(limits.getRateLimits()), 2);

    RateLimit statusRateLimit =
        Iterables.tryFind(limits.getRateLimits(), isStatusRateLimit()).orNull();
    assertEquals(statusRateLimit.getRegex(), ".*/v\\d+\\.\\d+/(\\d+/status).*");
    assertEquals(Iterables.get(statusRateLimit.getLimits(), 0).getVerb(), "GET");
    assertEquals(Iterables.get(statusRateLimit.getLimits(), 0).getValue(), 5);
    assertEquals(
        Iterables.get(statusRateLimit.getLimits(), 0).getRemaining().get(), Integer.valueOf(5));
    assertEquals(Iterables.get(statusRateLimit.getLimits(), 0).getUnit(), "SECOND");
  }
  public void testAllocateWithPoolNameWhenResponseIs2xx() throws Exception {
    HttpRequest createFloatingIP =
        HttpRequest.builder()
            .method("POST")
            .endpoint(
                "https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips")
            .addHeader("Accept", "application/json")
            .addHeader("X-Auth-Token", authToken)
            .payload(payloadFromStringWithContentType("{\"pool\":\"myPool\"}", "application/json"))
            .build();

    HttpResponse createFloatingIPResponse =
        HttpResponse.builder()
            .statusCode(200)
            .payload(payloadFromResource("/floatingip_details.json"))
            .build();

    NovaApi apiWhenFloatingIPsExist =
        requestsSendResponses(
            keystoneAuthWithUsernameAndPasswordAndTenantName,
            responseWithKeystoneAccess,
            extensionsOfNovaRequest,
            extensionsOfNovaResponse,
            createFloatingIP,
            createFloatingIPResponse);

    assertEquals(
        apiWhenFloatingIPsExist
            .getFloatingIPExtensionForZone("az-1.region-a.geo-1")
            .get()
            .allocateFromPool("myPool")
            .toString(),
        new ParseFloatingIPTest().expected().toString());
  }
  public void testAllocateWhenResponseIs404() throws Exception {
    HttpRequest createFloatingIP =
        HttpRequest.builder()
            .method("POST")
            .endpoint(
                "https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips")
            .addHeader("Accept", "application/json")
            .addHeader("X-Auth-Token", authToken)
            .payload(payloadFromStringWithContentType("{}", "application/json"))
            .build();

    HttpResponse createFloatingIPResponse = HttpResponse.builder().statusCode(404).build();

    NovaApi apiWhenNoServersExist =
        requestsSendResponses(
            keystoneAuthWithUsernameAndPasswordAndTenantName,
            responseWithKeystoneAccess,
            extensionsOfNovaRequest,
            extensionsOfNovaResponse,
            createFloatingIP,
            createFloatingIPResponse);

    assertNull(
        apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().create());
  }
  public void testListFloatingIPsWhenResponseIs404() throws Exception {
    HttpRequest list =
        HttpRequest.builder()
            .method("GET")
            .endpoint(
                "https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips")
            .addHeader("Accept", "application/json")
            .addHeader("X-Auth-Token", authToken)
            .build();

    HttpResponse listResponse = HttpResponse.builder().statusCode(404).build();

    NovaApi apiWhenNoServersExist =
        requestsSendResponses(
            keystoneAuthWithUsernameAndPasswordAndTenantName,
            responseWithKeystoneAccess,
            extensionsOfNovaRequest,
            extensionsOfNovaResponse,
            list,
            listResponse);

    assertTrue(
        apiWhenNoServersExist
            .getFloatingIPExtensionForZone("az-1.region-a.geo-1")
            .get()
            .list()
            .isEmpty());
  }
  public void testListSnapshotsInDetail() {
    URI endpoint =
        URI.create("http://172.16.0.1:8776/v1/50cdb4c60374463198695d9f798fa34d/snapshots/detail");
    SnapshotApi api =
        requestsSendResponses(
                keystoneAuthWithUsernameAndPasswordAndTenantName,
                responseWithKeystoneAccess,
                authenticatedGET().endpoint(endpoint).build(),
                HttpResponse.builder()
                    .statusCode(200)
                    .payload(payloadFromResource("/snapshot_list_details.json"))
                    .build())
            .getSnapshotApiForZone("RegionOne");

    Set<? extends Snapshot> snapshots = api.listInDetail().toSet();
    assertEquals(snapshots, ImmutableSet.of(testSnapshot()));

    // double-check individual fields
    Snapshot snappy = Iterables.getOnlyElement(snapshots);
    assertEquals(snappy.getId(), "67d03df1-ce5d-4ba7-adbe-492ceb80170b");
    assertEquals(snappy.getVolumeId(), "ea6f70ef-2784-40b9-9d14-d7f33c507c3f");
    assertEquals(snappy.getStatus(), Volume.Status.AVAILABLE);
    assertEquals(snappy.getDescription(), "jclouds test snapshot");
    assertEquals(snappy.getName(), "jclouds-test-snapshot");
    assertEquals(snappy.getSize(), 1);
  }
  @Test(expectedExceptions = AuthorizationException.class)
  public void testCreateSnapshotFail() {
    URI endpoint =
        URI.create("http://172.16.0.1:8776/v1/50cdb4c60374463198695d9f798fa34d/snapshots");
    SnapshotApi api =
        requestsSendResponses(
                keystoneAuthWithUsernameAndPasswordAndTenantName,
                responseWithKeystoneAccess,
                authenticatedGET()
                    .endpoint(endpoint)
                    .method("POST")
                    .payload(
                        payloadFromResourceWithContentType(
                            "/snapshot_create.json", MediaType.APPLICATION_JSON))
                    .build(),
                HttpResponse.builder().statusCode(401).build())
            .getSnapshotApiForZone("RegionOne");

    CreateSnapshotOptions options =
        CreateSnapshotOptions.Builder.name("jclouds-test-snapshot")
            .description("jclouds test snapshot")
            .force();

    api.create("ea6f70ef-2784-40b9-9d14-d7f33c507c3f", options);
  }
  public void testApplyInputStreamDetails() throws UnknownHostException {
    InputStream is = getClass().getResourceAsStream("/test_list_images_detail.json");

    UnwrapOnlyJsonValue<List<Image>> parser =
        i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Image>>>() {}));
    List<Image> response =
        parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());

    assertEquals(response.get(0).getId(), 2);
    assertEquals(response.get(0).getName(), "CentOS 5.2");
    assertEquals(
        response.get(0).getCreated(), dateService.iso8601SecondsDateParse("2010-08-10T12:00:00Z"));
    assertEquals(response.get(0).getProgress(), null);
    assertEquals(response.get(0).getServerId(), null);
    assertEquals(response.get(0).getStatus(), ImageStatus.ACTIVE);
    assertEquals(
        response.get(0).getUpdated(), dateService.iso8601SecondsDateParse("2010-10-10T12:00:00Z"));

    assertEquals(response.get(1).getId(), 743);
    assertEquals(response.get(1).getName(), "My Server Backup");
    assertEquals(
        response.get(1).getCreated(),
        dateService.iso8601SecondsDateParse("2009-07-07T09:56:16-05:00"));
    ;
    assertEquals(response.get(1).getProgress(), Integer.valueOf(80));
    assertEquals(response.get(1).getServerId(), Integer.valueOf(12));
    assertEquals(response.get(1).getStatus(), ImageStatus.SAVING);
    assertEquals(
        response.get(1).getUpdated(), dateService.iso8601SecondsDateParse("2010-10-10T12:00:00Z"));
  }
  public void testDescribeVolumesWithNovaEC2Status() {
    ElasticBlockStoreApi client =
        requestsSendResponses(
                describeAvailabilityZonesRequest,
                describeAvailabilityZonesResponse,
                HttpRequest.builder()
                    .method("POST")
                    .endpoint("http://localhost:8773/services/Cloud/")
                    .addHeader("Host", "localhost:8773")
                    .payload(
                        payloadFromStringWithContentType(
                            "Action=DescribeVolumes&Signature=AvRznSzGExM%2Buaj2JJj66wq4v4f%2BakicyLooRDtC0t0%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2009-04-04&AWSAccessKeyId=identity",
                            "application/x-www-form-urlencoded"))
                    .build(),
                HttpResponse.builder()
                    .statusCode(200)
                    .payload(payloadFromResource("/nova_ec2_describe_volumes.xml"))
                    .build())
            .getElasticBlockStoreApi()
            .get();

    Set<Volume> expected =
        ImmutableSet.of(
            Volume.builder()
                .status(Volume.Status.AVAILABLE)
                .availabilityZone("nova")
                .region("nova")
                .id("vol-00000007")
                .size(1)
                .attachments(Attachment.builder().region("nova").build())
                .createTime(dateService.iso8601SecondsDateParse("2012-04-10T10:39:52Z"))
                .build());

    assertEquals(client.describeVolumesInRegion("nova"), expected);
  }
  @Test(expectedExceptions = ResourceNotFoundException.class)
  public void testCreateInstanceFail() {
    URI endpoint = URI.create("http://172.16.0.1:8776/v1/3456/instances");
    InstanceApi api =
        requestsSendResponses(
                keystoneAuthWithUsernameAndPasswordAndTenantName,
                responseWithKeystoneAccess,
                authenticatedGET()
                    .endpoint(
                        endpoint) // bad naming convention, you should not be able to change the
                                  // method to POST
                    .method("POST")
                    .payload(
                        payloadFromResourceWithContentType(
                            "/instance_create_request.json", MediaType.APPLICATION_JSON))
                    .build(),
                HttpResponse.builder()
                    .statusCode(404)
                    .payload(payloadFromResource("/instance_create.json"))
                    .build() // response
                )
            .getInstanceApi("RegionOne");

    api.create("1", 2, "json_rack_instance");
  }
  public void testListArchivesWhenReponseIs2xx() throws Exception {
    ArchiveApi api =
        requestSendsResponse(
                HttpRequest.builder()
                    .method("POST")
                    .endpoint("https://api.glesys.com/archive/list/format/json")
                    .addHeader("Accept", "application/json")
                    .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
                    .build(),
                HttpResponse.builder()
                    .statusCode(200)
                    .payload(payloadFromResource("/archive_list.json"))
                    .build())
            .getArchiveApi();

    Set<Archive> expected =
        ImmutableSet.of(
            Archive.builder()
                .username("xxxxx_test1")
                .freeSize("20 GB")
                .totalSize("30 GB")
                .locked(false)
                .build());

    assertEquals(api.list().toSet(), expected);
  }
  public void testDeleteAndSaveSnapshotWhenResponseIs2xx() throws Exception {
    HttpRequest delete =
        HttpRequest.builder()
            .method("POST")
            .endpoint("https://rds.us-east-1.amazonaws.com/")
            .addHeader("Host", "rds.us-east-1.amazonaws.com")
            .payload(
                payloadFromStringWithContentType(
                    "Action=DeleteDBInstance"
                        + "&DBInstanceIdentifier=id"
                        + "&FinalDBSnapshotIdentifier=snap"
                        + "&Signature=aKuG1%2FYbZAzUFdAZTjke1LYRfR5JU86UxDt%2BtwdPJwE%3D"
                        + "&SignatureMethod=HmacSHA256"
                        + "&SignatureVersion=2"
                        + "&Timestamp=2009-11-08T15%3A54%3A08.897Z"
                        + "&Version=2012-04-23"
                        + "&AWSAccessKeyId=identity",
                    "application/x-www-form-urlencoded"))
            .build();
    HttpResponse deleteResponse =
        HttpResponse.builder()
            .statusCode(200)
            .payload(payloadFromResourceWithContentType("/delete_instance.xml", "text/xml"))
            .build();

    RDSApi apiWhenExist = requestSendsResponse(delete, deleteResponse);

    apiWhenExist.getInstanceApi().deleteAndSaveSnapshot("id", "snap");
  }
  public void testListServersWhenResponseIs2xx() throws Exception {
    HttpRequest listServers =
        HttpRequest.builder()
            .method("GET")
            .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers")
            .addHeader("Accept", "application/json")
            .addHeader("X-Auth-Token", authToken)
            .build();

    HttpResponse listServersResponse =
        HttpResponse.builder()
            .statusCode(200)
            .payload(payloadFromResource("/server_list.json"))
            .build();

    NovaApi apiWhenServersExist =
        requestsSendResponses(
            keystoneAuthWithAccessKeyAndSecretKeyAndTenantId,
            responseWithKeystoneAccess,
            listServers,
            listServersResponse);

    assertEquals(
        apiWhenServersExist.getConfiguredZones(),
        ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));

    assertEquals(
        apiWhenServersExist.getServerApiForZone("az-1.region-a.geo-1").list().concat().toString(),
        new ParseServerListTest().expected().toString());
  }
  public void testListTypesByNamesWhenResponseIs2xx() throws Exception {
    HttpRequest listWithOptions =
        HttpRequest.builder()
            .method("POST")
            .endpoint("https://elasticloadbalancing.us-east-1.amazonaws.com/")
            .addHeader("Host", "elasticloadbalancing.us-east-1.amazonaws.com")
            .payload(
                payloadFromStringWithContentType(
                    "Action=DescribeLoadBalancerPolicyTypes"
                        + "&PolicyTypeNames.member.1=moo"
                        + "&Signature=cX8twwn2E6%2B7V3CGZ4ac69NhyolJLsV1nzpQl3wQXW8%3D"
                        + "&SignatureMethod=HmacSHA256"
                        + "&SignatureVersion=2"
                        + "&Timestamp=2009-11-08T15%3A54%3A08.897Z"
                        + "&Version=2012-06-01"
                        + "&AWSAccessKeyId=identity",
                    "application/x-www-form-urlencoded"))
            .build();

    HttpResponse listWithOptionsResponse =
        HttpResponse.builder()
            .statusCode(200)
            .payload(payloadFromResourceWithContentType("/describe_policy_types.xml", "text/xml"))
            .build();

    ELBApi apiWhenWithOptionsExist = requestSendsResponse(listWithOptions, listWithOptionsResponse);

    assertEquals(
        apiWhenWithOptionsExist.getPolicyApi().listTypes(ImmutableSet.of("moo")).toString(),
        new DescribeLoadBalancerPolicyTypesResponseTest().expected().toString());
  }
  public void testListWithOptionsWhenResponseIs2xx() throws Exception {
    HttpRequest listWithOptions =
        HttpRequest.builder()
            .method("POST")
            .endpoint("https://elasticloadbalancing.us-east-1.amazonaws.com/")
            .addHeader("Host", "elasticloadbalancing.us-east-1.amazonaws.com")
            .payload(
                payloadFromStringWithContentType(
                    "Action=DescribeLoadBalancerPolicies"
                        + "&LoadBalancerName=moo"
                        + "&Signature=c8PG1b5wI5YMU0motVEo5Mz7d5w8gy8u51kfCR6SnRI%3D"
                        + "&SignatureMethod=HmacSHA256"
                        + "&SignatureVersion=2"
                        + "&Timestamp=2009-11-08T15%3A54%3A08.897Z"
                        + "&Version=2012-06-01"
                        + "&AWSAccessKeyId=identity",
                    "application/x-www-form-urlencoded"))
            .build();

    HttpResponse listWithOptionsResponse =
        HttpResponse.builder()
            .statusCode(200)
            .payload(payloadFromResourceWithContentType("/describe_policies.xml", "text/xml"))
            .build();

    ELBApi apiWhenWithOptionsExist = requestSendsResponse(listWithOptions, listWithOptionsResponse);

    assertEquals(
        apiWhenWithOptionsExist.getPolicyApi().list(loadBalancerName("moo")).toString(),
        new DescribeLoadBalancerPoliciesResponseTest().expected().toString());
  }
  public void testListWithOptionsWhenResponseIs2xx() throws Exception {
    HttpRequest listWithOptions =
        HttpRequest.builder()
            .method("POST")
            .endpoint("https://rds.us-east-1.amazonaws.com/")
            .addHeader("Host", "rds.us-east-1.amazonaws.com")
            .payload(
                payloadFromStringWithContentType(
                    "Action=DescribeDBInstances"
                        + "&Marker=MARKER"
                        + "&Signature=TFW8vaU2IppmBey0ZHttbWz4rMFh%2F5ACWl6Xyt58sQU%3D"
                        + "&SignatureMethod=HmacSHA256"
                        + "&SignatureVersion=2"
                        + "&Timestamp=2009-11-08T15%3A54%3A08.897Z"
                        + "&Version=2012-04-23"
                        + "&AWSAccessKeyId=identity",
                    "application/x-www-form-urlencoded"))
            .build();

    HttpResponse listWithOptionsResponse =
        HttpResponse.builder()
            .statusCode(200)
            .payload(payloadFromResourceWithContentType("/describe_instances.xml", "text/xml"))
            .build();

    RDSApi apiWhenWithOptionsExist = requestSendsResponse(listWithOptions, listWithOptionsResponse);

    assertEquals(
        apiWhenWithOptionsExist.getInstanceApi().list(afterMarker("MARKER")).toString(),
        new DescribeDBInstancesResponseTest().expected().toString());
  }
  public BaseGlanceExpectTest() {
    provider = "openstack-glance";
    keystoneAuthWithUsernameAndPassword =
        KeystoneFixture.INSTANCE.initialAuthWithUsernameAndPasswordAndTenantName(
            identity, credential);
    keystoneAuthWithAccessKeyAndSecretKey =
        KeystoneFixture.INSTANCE.initialAuthWithAccessKeyAndSecretKeyAndTenantName(
            identity, credential);

    authToken = KeystoneFixture.INSTANCE.getAuthToken();
    responseWithKeystoneAccess = KeystoneFixture.INSTANCE.responseWithAccess();
    // now, createContext arg will need tenant prefix
    identity = KeystoneFixture.INSTANCE.getTenantName() + ":" + identity;
    // version negotiation
    versionNegotiationRequest =
        HttpRequest.builder()
            .method("GET")
            .endpoint("https://glance.jclouds.org:9292/")
            .addHeader(RegionToEndpointNegotiateVersion.VERSION_NEGOTIATION_HEADER, "true")
            .build();
    versionNegotiationResponse =
        HttpResponse.builder()
            .statusCode(300)
            .message("HTTP/1.1 300 Multiple Choices")
            .payload(
                payloadFromResourceWithContentType(
                    "/glanceVersionResponse.json", "application/json"))
            .build();
  }
  public void testCreateKeyWhenResponseIs202() throws Exception {
    HttpRequest create =
        HttpRequest.builder()
            .method("POST")
            .endpoint(URI.create("https://api.joyentcloud.com/my/keys"))
            .headers(
                ImmutableMultimap.<String, String>builder()
                    .put("X-Api-Version", "~6.5")
                    .put("Accept", "application/json")
                    .put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
                    .build())
            .payload(
                payloadFromStringWithContentType(
                    "{\"name\":\"rsa\",\"key\":\"ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0A5Pf5Cq...\"}",
                    "application/json"))
            .build();

    HttpResponse createResponse =
        HttpResponse.builder()
            .statusCode(202)
            .message("HTTP/1.1 202 Accepted")
            .payload(
                payloadFromResourceWithContentType("/key.json", "application/json; charset=UTF-8"))
            .build();

    JoyentCloudClient clientWithNewKey =
        requestsSendResponses(getDatacenters, getDatacentersResponse, create, createResponse);

    assertEquals(
        clientWithNewKey.getKeyClient().create(new ParseKeyTest().expected()).toString(),
        new ParseKeyTest().expected().toString());
  }
  public void testGetWhenResponseIs404() throws Exception {

    HttpResponse getResponse = HttpResponse.builder().statusCode(404).build();

    ELBApi apiWhenDontExist = requestSendsResponse(get, getResponse);

    assertNull(apiWhenDontExist.getPolicyApi().get("name"));
  }
  public void testListTypesWhenResponseIs404() throws Exception {

    HttpResponse listResponse = HttpResponse.builder().statusCode(404).build();

    ELBApi apiWhenDontExist = requestSendsResponse(listTypes, listResponse);

    apiWhenDontExist.getPolicyApi().listTypes();
  }
  public void testDeleteWhenResponseIs404() throws Exception {

    HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build();

    RDSApi apiWhenDontExist = requestSendsResponse(delete, deleteResponse);

    apiWhenDontExist.getInstanceApi().delete("id");
  }
  public void testListKeysWhenResponseIs404() {
    HttpResponse listResponse = HttpResponse.builder().statusCode(404).build();

    JoyentCloudClient listWhenNone =
        requestsSendResponses(getDatacenters, getDatacentersResponse, list, listResponse);

    assertEquals(listWhenNone.getKeyClient().list(), ImmutableSet.of());
  }