use of io.apiman.test.policies.Configuration 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.Configuration 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.Configuration 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());
}
use of io.apiman.test.policies.Configuration 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.Configuration 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\":"));
}
Aggregations