use of io.apiman.test.policies.BackEndApi in project apiman-plugins by apiman.
the class TransformationPolicyTest method transformClientXmlRequesttToJson.
@Test
@Configuration("{\"clientFormat\": \"XML\", \"serverFormat\": \"JSON\"}")
@BackEndApi(ConsumeJsonBackEndApi.class)
public void transformClientXmlRequesttToJson() throws Throwable {
String xml = "<a><b>test</b></a>";
PolicyTestRequest request = PolicyTestRequest.build(PolicyTestRequestType.POST, "/some/resource");
request.header("Content-Type", "application/xml");
request.header("Content-Length", String.valueOf(xml.getBytes("UTF-8").length));
request.body(xml);
send(request);
}
use of io.apiman.test.policies.BackEndApi in project apiman-plugins by apiman.
the class TransformationPolicyTest method transformServerEchoXmlResponseToJson.
@Test
@Configuration("{\"clientFormat\": \"JSON\", \"serverFormat\": \"XML\"}")
@BackEndApi(ProduceEchoXmlResponseBackend.class)
public void transformServerEchoXmlResponseToJson() throws Throwable {
PolicyTestRequest request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/some/resource");
PolicyTestResponse response = send(request);
assertEquals("application/json", response.header("Content-Type"));
assertNull(response.header("Content-Length"));
assertTrue(response.body().startsWith("{\"echoResponse\":"));
}
use of io.apiman.test.policies.BackEndApi in project apiman by apiman.
the class TransferQuotaPolicyTest method testDownloadLimitNoHeaderConfig.
@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());
}
}
use of io.apiman.test.policies.BackEndApi in project apiman by apiman.
the class TransferQuotaPolicyTest method testDownloadLimit.
@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());
}
}
use of io.apiman.test.policies.BackEndApi in project apiman by apiman.
the class TransferQuotaPolicyTest method testDownloadLimitEmptyHeaderConfig.
@Test
@Configuration("{" + " \"limit\" : 1000," + " \"direction\" : \"download\"," + " \"granularity\" : \"Api\"," + " \"period\" : \"Day\"," + " \"headerRemaining\" : \"\"," + " \"headerLimit\" : \"\"," + " \"headerReset\" : \"\"" + "}")
@BackEndApi(DownloadTestBackEndApi.class)
public void testDownloadLimitEmptyHeaderConfig() 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());
}
}
Aggregations