Пример #1
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");
  }