@Test
    @Configuration("{" +
            "  \"limit\" : 100," +
            "  \"direction\" : \"upload\"," +
            "  \"granularity\" : \"Api\"," +
            "  \"period\" : \"Day\"," +
            "  \"headerRemaining\" : \"X-Bytes-Remaining\"," +
            "  \"headerLimit\" : \"X-Bytes-Limit\"," +
            "  \"headerReset\" : \"X-Bytes-Reset\"" +
            "}")
    public void testUploadLimit() throws Throwable {
        PolicyTestRequest request = PolicyTestRequest.build(PolicyTestRequestType.POST, "/some/resource");
        request.body("0123456789");

        PolicyTestResponse response = send(request);
        EchoResponse echo = response.entity(EchoResponse.class);
        Assert.assertNotNull(echo);
        Assert.assertEquals("90", response.header("X-Bytes-Remaining"));
        Assert.assertEquals("100", response.header("X-Bytes-Limit"));

        // Now try sending a few more times to get closer to the limit
        for (int i = 0; i < 9; i++) {
            response = send(request);
        }
        echo = response.entity(EchoResponse.class);
        Assert.assertNotNull(echo);
        Assert.assertEquals("0", response.header("X-Bytes-Remaining"));
        Assert.assertEquals("100", response.header("X-Bytes-Limit"));

        // 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