@Test
  @Configuration(
      "{"
          + "  \"limit\" : 1000,"
          + "  \"direction\" : \"download\","
          + "  \"granularity\" : \"Api\","
          + "  \"period\" : \"Minute\""
          + "}")
  @BackEndApi(DownloadTestBackEndApi.class)
  public void testDownloadLimitNoHeaderConfig() throws Throwable {
    PolicyTestRequest request =
        PolicyTestRequest.build(PolicyTestRequestType.GET, "/some/resource");
    request.header("X-Payload-Size", "389");

    PolicyTestResponse response = send(request);
    Assert.assertNotNull(response.body());
    Assert.assertEquals("1000", response.header("X-TransferQuota-Remaining"));
    Assert.assertEquals("1000", response.header("X-TransferQuota-Limit"));

    send(request);
    send(request);

    // Now if we try it one more time, we'll get a failure!
    try {
      send(request);
      Assert.fail("Expected a policy failure!");
    } catch (PolicyFailureError e) {
      PolicyFailure failure = e.getFailure();
      Assert.assertEquals(PolicyFailureCodes.BYTE_QUOTA_EXCEEDED, failure.getFailureCode());
      Assert.assertEquals("Transfer quota exceeded.", failure.getMessage());
      Assert.assertEquals(429, failure.getResponseCode());
    }
  }
  @Test
  @Configuration(
      "{"
          + "  \"limit\" : 500,"
          + "  \"direction\" : \"both\","
          + "  \"granularity\" : \"Api\","
          + "  \"period\" : \"Day\","
          + "  \"headerRemaining\" : \"X-Bytes-Remaining\","
          + "  \"headerLimit\" : \"X-Bytes-Limit\","
          + "  \"headerReset\" : \"X-Bytes-Reset\""
          + "}")
  @BackEndApi(DownloadTestBackEndApi.class)
  public void testBothLimit() throws Throwable {
    PolicyTestRequest request =
        PolicyTestRequest.build(PolicyTestRequestType.PUT, "/some/resource");
    request.header("X-Payload-Size", "50");
    byte[] data = new byte[50];
    Arrays.fill(data, (byte) 80);
    request.body(new String(data));

    PolicyTestResponse response = send(request);
    Assert.assertNotNull(response.body());
    Assert.assertEquals("450", response.header("X-Bytes-Remaining"));
    Assert.assertEquals("500", response.header("X-Bytes-Limit"));

    send(request);
    send(request);
    send(request);
    send(request);

    // Now if we try it one more time, we'll get a failure!
    try {
      send(request);
      Assert.fail("Expected a policy failure!");
    } catch (PolicyFailureError e) {
      PolicyFailure failure = e.getFailure();
      Assert.assertEquals(PolicyFailureCodes.BYTE_QUOTA_EXCEEDED, failure.getFailureCode());
      Assert.assertEquals("Transfer quota exceeded.", failure.getMessage());
      Assert.assertEquals(429, failure.getResponseCode());
    }
  }