@Test
    @Configuration("{" +
            "  \"limit\" : 1000," +
            "  \"direction\" : \"download\"," +
            "  \"granularity\" : \"Api\"," +
            "  \"period\" : \"Day\"," +
            "  \"headerRemaining\" : \"X-DBytes-Remaining\"," +
            "  \"headerLimit\" : \"X-DBytes-Limit\"," +
            "  \"headerReset\" : \"X-DBytes-Reset\"" +
            "}")
    @BackEndApi(DownloadTestBackEndApi.class)
    public void testDownloadLimit() 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-DBytes-Remaining"));
        Assert.assertEquals("1000", response.header("X-DBytes-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());
        }
    }
Unit test.

@author eric.wittmann@redhat.com
gateway/engine/policies/src/test/java/io/apiman/gateway/engine/policies/TransferQuotaPolicyTest.java