Hi,
I am using Camel 2.11, and I have the following unit test that uses Mock end
point.
In the last assert in method testRedirect :
Assert.assertEquals("foo", nameAct);
nameAct is null.
I must have done somethin silly and I can see why the above assert fails.
I would be grateful if some kind soul could point out my mistake.
public class HttpRedirectTest extends CamelTestSupport{
@Override
protected RouteBuilder[] createRouteBuilders() throws Exception {
RouteBuilder myBuilderRB = new RouteBuilder() {
@Override
public void configure() throws Exception {
from("jetty:http://localhost:8081/test?matchOnUriPrefix=true")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
Message messageIn = exchange.getIn();
HttpServletRequest request =
messageIn.getBody(HttpServletRequest.class);
String label=request.getParameter("label");
exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 302);
exchange.getOut().setHeader("location",
"http://localhost:8088/test?name=" + label);
}
});
from("jetty:http://localhost:8088/test?matchOnUriPrefix=true")
.process( new Processor(){
public void process(Exchange exchange) throws
Exception {
HttpServletRequest request =
exchange.getIn().getBody(HttpServletRequest.class);
log.info("request=" +request.getPathInfo());
log.info("name=" +
request.getParameter("name"));
}
})
.to("mock:redirect");
}
};
return new RouteBuilder[] { myBuilderRB };
}
@Test
public void testRedirect() throws InterruptedException {
MockEndpoint redirectMock = getMockEndpoint("mock:redirect");
redirectMock.expectedMessageCount(1);
template.send("http://localhost:8081/test", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(
Exchange.HTTP_QUERY,
String.format("label=foo"));
}
});
redirectMock.assertIsSatisfied();
List<Exchange> exchanges = redirectMock.getReceivedExchanges();
assertEquals(1, exchanges.size());
Exchange exchange0 = exchanges.get(0);
Message messageIn = exchange0.getIn();
HttpServletRequest request = messageIn
.getBody(HttpServletRequest.class);
String nameAct = request.getParameter("name");
Assert.assertEquals("foo", nameAct); // Failed wwith nameAct=null
}
}
-------------------
Thanks in advance for any assistance !
Shing