jeudi 2 juin 2016

Assert exchange property set in Camel after calling external mocked service

I'm trying to write a Unit Test for camel to check if an exchange property was correctly set based on the response of the external mocked service. However I can get the property after the call as I can't access the original exchange after mocked external service has been called.

public class OutputManagerTest extends CamelBlueprintTestSupport {

@Override
protected String getBlueprintDescriptor() {
    return "/OSGI-INF/blueprint/blueprint-camel.xml,/OSGI-INF/blueprint/blueprint-beans.xml";
}

@Override
public boolean isUseAdviceWith() {
    return true;
}

@Override
public String isMockEndpointsAndSkip() {
    return "wmq:.*|jetty:.*";
}
@Test
public void testCallAndPropertyIsSet() throws Exception {
    getMockEndpoint("mock:jetty:http:localhost").expectedBodiesReceived(context.getTypeConverter().convertTo(String.class, new File("src/test/resources/requests/Request.xml")));
    getMockEndpoint("mock:jetty:http:localhost").returnReplyBody(new Expression() {
        @Override
        public <T> T evaluate(Exchange exchange, Class<T> aClass) {
            return context.getTypeConverter().convertTo(aClass, new File("src/test/resources/requests/Response.xml"));
        }
    });
    template.sendBody("direct:route1", context.getTypeConverter().convertTo(String.class, new File("src/test/resources/requests/ValidRequest.xml")));
    getMockEndpoint("mock:jetty:http:localhost").expectedBodiesReceived();
    //How to assert exchange property 'Property1' has been set?
}

Blueprint camel route:

<route id="rav">
        <from uri="direct:route1"/>
        <to uri="velocity:templates/RequestTemplate.vm"/>
        <to uri="jetty:?bridgeEndpoint=true"/>
        <setProperty propertyName="Property1">
            <xpath resultType="java.lang.String">/soapenv:Envelope/soapenv:Body/namespace:element/text()</xpath>
        </setProperty>
    </route>

Thanks in advance, Vladimir.

Aucun commentaire:

Enregistrer un commentaire