Search in sources :

Example 16 with Configuration

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());
}
Also used : PolicyTestRequest(io.apiman.test.policies.PolicyTestRequest) PolicyTestResponse(io.apiman.test.policies.PolicyTestResponse) ProduceXmlBackEndApi(io.apiman.plugins.transformation_policy.backend.ProduceXmlBackEndApi) ProduceJsonBackEndApi(io.apiman.plugins.transformation_policy.backend.ProduceJsonBackEndApi) ProduceComplexJsonBackEndApi(io.apiman.plugins.transformation_policy.backend.ProduceComplexJsonBackEndApi) BackEndApi(io.apiman.test.policies.BackEndApi) ConsumeJsonBackEndApi(io.apiman.plugins.transformation_policy.backend.ConsumeJsonBackEndApi) ConsumeXmlBackEndApi(io.apiman.plugins.transformation_policy.backend.ConsumeXmlBackEndApi) Configuration(io.apiman.test.policies.Configuration) ApimanPolicyTest(io.apiman.test.policies.ApimanPolicyTest) Test(org.junit.Test)

Example 17 with Configuration

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);
}
Also used : PolicyTestRequest(io.apiman.test.policies.PolicyTestRequest) ProduceXmlBackEndApi(io.apiman.plugins.transformation_policy.backend.ProduceXmlBackEndApi) ProduceJsonBackEndApi(io.apiman.plugins.transformation_policy.backend.ProduceJsonBackEndApi) ProduceComplexJsonBackEndApi(io.apiman.plugins.transformation_policy.backend.ProduceComplexJsonBackEndApi) BackEndApi(io.apiman.test.policies.BackEndApi) ConsumeJsonBackEndApi(io.apiman.plugins.transformation_policy.backend.ConsumeJsonBackEndApi) ConsumeXmlBackEndApi(io.apiman.plugins.transformation_policy.backend.ConsumeXmlBackEndApi) Configuration(io.apiman.test.policies.Configuration) ApimanPolicyTest(io.apiman.test.policies.ApimanPolicyTest) Test(org.junit.Test)

Example 18 with Configuration

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());
}
Also used : PolicyTestRequest(io.apiman.test.policies.PolicyTestRequest) PolicyTestResponse(io.apiman.test.policies.PolicyTestResponse) ProduceXmlBackEndApi(io.apiman.plugins.transformation_policy.backend.ProduceXmlBackEndApi) ProduceJsonBackEndApi(io.apiman.plugins.transformation_policy.backend.ProduceJsonBackEndApi) ProduceComplexJsonBackEndApi(io.apiman.plugins.transformation_policy.backend.ProduceComplexJsonBackEndApi) BackEndApi(io.apiman.test.policies.BackEndApi) ConsumeJsonBackEndApi(io.apiman.plugins.transformation_policy.backend.ConsumeJsonBackEndApi) ConsumeXmlBackEndApi(io.apiman.plugins.transformation_policy.backend.ConsumeXmlBackEndApi) Configuration(io.apiman.test.policies.Configuration) ApimanPolicyTest(io.apiman.test.policies.ApimanPolicyTest) Test(org.junit.Test)

Example 19 with Configuration

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);
}
Also used : PolicyTestRequest(io.apiman.test.policies.PolicyTestRequest) ProduceXmlBackEndApi(io.apiman.plugins.transformation_policy.backend.ProduceXmlBackEndApi) ProduceJsonBackEndApi(io.apiman.plugins.transformation_policy.backend.ProduceJsonBackEndApi) ProduceComplexJsonBackEndApi(io.apiman.plugins.transformation_policy.backend.ProduceComplexJsonBackEndApi) BackEndApi(io.apiman.test.policies.BackEndApi) ConsumeJsonBackEndApi(io.apiman.plugins.transformation_policy.backend.ConsumeJsonBackEndApi) ConsumeXmlBackEndApi(io.apiman.plugins.transformation_policy.backend.ConsumeXmlBackEndApi) Configuration(io.apiman.test.policies.Configuration) ApimanPolicyTest(io.apiman.test.policies.ApimanPolicyTest) Test(org.junit.Test)

Example 20 with Configuration

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\":"));
}
Also used : PolicyTestRequest(io.apiman.test.policies.PolicyTestRequest) PolicyTestResponse(io.apiman.test.policies.PolicyTestResponse) ProduceXmlBackEndApi(io.apiman.plugins.transformation_policy.backend.ProduceXmlBackEndApi) ProduceJsonBackEndApi(io.apiman.plugins.transformation_policy.backend.ProduceJsonBackEndApi) ProduceComplexJsonBackEndApi(io.apiman.plugins.transformation_policy.backend.ProduceComplexJsonBackEndApi) BackEndApi(io.apiman.test.policies.BackEndApi) ConsumeJsonBackEndApi(io.apiman.plugins.transformation_policy.backend.ConsumeJsonBackEndApi) ConsumeXmlBackEndApi(io.apiman.plugins.transformation_policy.backend.ConsumeXmlBackEndApi) Configuration(io.apiman.test.policies.Configuration) ApimanPolicyTest(io.apiman.test.policies.ApimanPolicyTest) Test(org.junit.Test)

Aggregations

ApimanPolicyTest (io.apiman.test.policies.ApimanPolicyTest)51 Configuration (io.apiman.test.policies.Configuration)51 Test (org.junit.Test)51 PolicyTestRequest (io.apiman.test.policies.PolicyTestRequest)40 PolicyTestResponse (io.apiman.test.policies.PolicyTestResponse)39 PolicyFailureError (io.apiman.test.policies.PolicyFailureError)24 EchoResponse (io.apiman.test.common.mock.EchoResponse)23 PolicyFailure (io.apiman.gateway.engine.beans.PolicyFailure)19 BackEndApi (io.apiman.test.policies.BackEndApi)15 ConsumeJsonBackEndApi (io.apiman.plugins.transformation_policy.backend.ConsumeJsonBackEndApi)8 ConsumeXmlBackEndApi (io.apiman.plugins.transformation_policy.backend.ConsumeXmlBackEndApi)8 ProduceComplexJsonBackEndApi (io.apiman.plugins.transformation_policy.backend.ProduceComplexJsonBackEndApi)8 ProduceJsonBackEndApi (io.apiman.plugins.transformation_policy.backend.ProduceJsonBackEndApi)8 ProduceXmlBackEndApi (io.apiman.plugins.transformation_policy.backend.ProduceXmlBackEndApi)8 HashSet (java.util.HashSet)8 IPolicyTestBackEndApi (io.apiman.test.policies.IPolicyTestBackEndApi)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 PrintStream (java.io.PrintStream)4 TimeoutConfigBean (io.apiman.plugins.timeoutpolicy.beans.TimeoutConfigBean)1