Search in sources :

Example 1 with BackEndApi

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"));
}
Also used : PolicyTestResponse(io.apiman.test.policies.PolicyTestResponse) PolicyFailureError(io.apiman.test.policies.PolicyFailureError) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IPolicyTestBackEndApi(io.apiman.test.policies.IPolicyTestBackEndApi) BackEndApi(io.apiman.test.policies.BackEndApi) Configuration(io.apiman.test.policies.Configuration) Test(org.junit.Test) ApimanPolicyTest(io.apiman.test.policies.ApimanPolicyTest)

Example 2 with BackEndApi

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"));
}
Also used : PolicyTestResponse(io.apiman.test.policies.PolicyTestResponse) PolicyFailureError(io.apiman.test.policies.PolicyFailureError) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IPolicyTestBackEndApi(io.apiman.test.policies.IPolicyTestBackEndApi) BackEndApi(io.apiman.test.policies.BackEndApi) Configuration(io.apiman.test.policies.Configuration) Test(org.junit.Test) ApimanPolicyTest(io.apiman.test.policies.ApimanPolicyTest)

Example 3 with BackEndApi

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());
}
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 4 with BackEndApi

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);
}
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 5 with BackEndApi

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());
}
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)15 BackEndApi (io.apiman.test.policies.BackEndApi)15 Configuration (io.apiman.test.policies.Configuration)15 Test (org.junit.Test)15 PolicyTestResponse (io.apiman.test.policies.PolicyTestResponse)13 PolicyTestRequest (io.apiman.test.policies.PolicyTestRequest)12 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 IPolicyTestBackEndApi (io.apiman.test.policies.IPolicyTestBackEndApi)7 PolicyFailureError (io.apiman.test.policies.PolicyFailureError)7 PolicyFailure (io.apiman.gateway.engine.beans.PolicyFailure)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3