use of io.apiman.test.policies.BackEndApi in project apiman-plugins by apiman.
the class TimeoutPolicyTest method shouldExecute_onSimpleConfiguration.
/**
* Control the normal execution
*/
@Test
@Configuration("{\"timeoutConnect\" : \"1\", \"timeoutRead\" : \"2\" }")
@BackEndApi(EndPointPropertiesEcho.class)
public void shouldExecute_onSimpleConfiguration() throws PolicyFailureError, Throwable {
// WHEN Execute the policy
PolicyTestResponse response = null;
try {
response = send(PolicyTestRequest.build(PolicyTestRequestType.GET, "/some/resource"));
} catch (PolicyFailureError ex) {
fail("Configuration error");
}
// THEN timeouts are set
HashMap<?, ?> responseMap = new ObjectMapper().readValue(response.body(), HashMap.class);
assertEquals("timeoutConnect", "1", responseMap.get("timeouts.connect"));
assertEquals("timeoutRead", "2", responseMap.get("timeouts.read"));
}
use of io.apiman.test.policies.BackEndApi in project apiman-plugins by apiman.
the class TimeoutPolicyTest method shouldsettingNothing_onNoValue.
/**
* Execute with no value
*/
@Test
@Configuration("{}")
@BackEndApi(EndPointPropertiesEcho.class)
public void shouldsettingNothing_onNoValue() throws PolicyFailureError, Throwable {
// WHEN Execute the policy
PolicyTestResponse response = null;
try {
response = send(PolicyTestRequest.build(PolicyTestRequestType.GET, "/some/resource"));
} catch (PolicyFailureError ex) {
fail("Configuration error");
}
// THEN timeouts are not set
HashMap<?, ?> responseMap = new ObjectMapper().readValue(response.body(), HashMap.class);
assertFalse("timeoutConnect", responseMap.containsKey("timeouts.connect"));
assertFalse("timeoutRead", responseMap.containsKey("timeouts.read"));
}
use of io.apiman.test.policies.BackEndApi in project apiman-plugins by apiman.
the class TransformationPolicyTest method keepServerXmlResponseAsXml.
@Test
@Configuration("{\"clientFormat\": \"XML\", \"serverFormat\": \"XML\"}")
@BackEndApi(ProduceXmlBackEndApi.class)
public void keepServerXmlResponseAsXml() throws Throwable {
PolicyTestRequest request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/some/resource");
PolicyTestResponse response = send(request);
String expectedResponse = "<name>apiman</name>";
assertEquals("application/xml", response.header("Content-Type"));
assertEquals(String.valueOf(expectedResponse.getBytes("UTF-8").length), response.header("Content-Length"));
assertEquals(expectedResponse, response.body());
}
use of io.apiman.test.policies.BackEndApi in project apiman-plugins by apiman.
the class TransformationPolicyTest method transformClientJsonRequestToXml.
@Test
@Configuration("{\"clientFormat\": \"JSON\", \"serverFormat\": \"XML\"}")
@BackEndApi(ConsumeXmlBackEndApi.class)
public void transformClientJsonRequestToXml() throws Throwable {
String json = "{\"name\":\"apiman\"}";
PolicyTestRequest request = PolicyTestRequest.build(PolicyTestRequestType.POST, "/some/resource");
request.header("Content-Type", "application/json");
request.header("Content-Length", String.valueOf(json.getBytes("UTF-8").length));
request.body(json);
send(request);
}
use of io.apiman.test.policies.BackEndApi in project apiman-plugins by apiman.
the class TransformationPolicyTest method transformComplexServerJsonResponseToXml.
@Test
@Configuration("{\"clientFormat\": \"XML\", \"serverFormat\": \"JSON\"}")
@BackEndApi(ProduceComplexJsonBackEndApi.class)
public void transformComplexServerJsonResponseToXml() throws Throwable {
PolicyTestRequest request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/some/resource");
PolicyTestResponse response = send(request);
String expectedResponse = "<root><property-1>value-1</property-1><array-1>10</array-1><array-1>5</array-1><array-1>3</array-1><array-1>12</array-1><property-2>value-2</property-2><object-1><p1>v1</p1><p2>v2</p2></object-1></root>";
assertEquals("application/xml", response.header("Content-Type"));
assertNull(response.header("Content-Length"));
assertEquals(expectedResponse, response.body());
}
Aggregations