use of org.apache.camel.Processor in project camel by apache.
the class FromRestGetCorsTest method testCors.
public void testCors() throws Exception {
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
getMockEndpoint("mock:update").expectedMessageCount(1);
Exchange out = template.request("seda:post-say-bye", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("I was here");
}
});
assertNotNull(out);
assertEquals(out.getOut().getHeader("Access-Control-Allow-Origin"), RestConfiguration.CORS_ACCESS_CONTROL_ALLOW_ORIGIN);
assertEquals(out.getOut().getHeader("Access-Control-Allow-Methods"), RestConfiguration.CORS_ACCESS_CONTROL_ALLOW_METHODS);
assertEquals(out.getOut().getHeader("Access-Control-Allow-Headers"), RestConfiguration.CORS_ACCESS_CONTROL_ALLOW_HEADERS);
assertEquals(out.getOut().getHeader("Access-Control-Max-Age"), RestConfiguration.CORS_ACCESS_CONTROL_MAX_AGE);
assertMockEndpointsSatisfied();
}
use of org.apache.camel.Processor in project camel by apache.
the class FromRestGetHttpErrorCodeTest method testFromRestModel.
public void testFromRestModel() throws Exception {
String out = template.requestBody("seda:get-say-bye", "I was here", String.class);
assertEquals("Bye World", out);
Exchange reply = template.request("seda:get-say-bye", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("Kaboom");
}
});
assertNotNull(reply);
assertEquals(404, reply.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
assertEquals("text/plain", reply.getOut().getHeader(Exchange.CONTENT_TYPE));
}
use of org.apache.camel.Processor in project camel by apache.
the class FromRestGetCorsAllowCredentialsTest method testCorsWithOrigin.
public void testCorsWithOrigin() throws Exception {
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
getMockEndpoint("mock:update").expectedMessageCount(1);
Exchange out = template.request("seda:post-say-bye", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader("Origin", "mydomain");
exchange.getIn().setBody("I was here");
}
});
assertNotNull(out);
assertEquals(RestConfiguration.CORS_ACCESS_CONTROL_ALLOW_METHODS, out.getOut().getHeader("Access-Control-Allow-Methods"));
assertEquals(RestConfiguration.CORS_ACCESS_CONTROL_ALLOW_HEADERS, out.getOut().getHeader("Access-Control-Allow-Headers"));
assertEquals(RestConfiguration.CORS_ACCESS_CONTROL_MAX_AGE, out.getOut().getHeader("Access-Control-Max-Age"));
assertEquals("true", out.getOut().getHeader("Access-Control-Allow-Credentials"));
assertEquals("mydomain", out.getOut().getHeader("Access-Control-Allow-Origin"));
assertMockEndpointsSatisfied();
}
use of org.apache.camel.Processor in project camel by apache.
the class FromRestGetCorsAllowCredentialsTest method testCorsWithoutOrigin.
public void testCorsWithoutOrigin() throws Exception {
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
getMockEndpoint("mock:update").expectedMessageCount(1);
Exchange out = template.request("seda:post-say-bye", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("I was here");
}
});
assertNotNull(out);
assertEquals(RestConfiguration.CORS_ACCESS_CONTROL_ALLOW_ORIGIN, out.getOut().getHeader("Access-Control-Allow-Origin"));
assertEquals(RestConfiguration.CORS_ACCESS_CONTROL_ALLOW_METHODS, out.getOut().getHeader("Access-Control-Allow-Methods"));
assertEquals(RestConfiguration.CORS_ACCESS_CONTROL_ALLOW_HEADERS, out.getOut().getHeader("Access-Control-Allow-Headers"));
assertEquals(RestConfiguration.CORS_ACCESS_CONTROL_MAX_AGE, out.getOut().getHeader("Access-Control-Max-Age"));
assertEquals("true", out.getOut().getHeader("Access-Control-Allow-Credentials"));
assertMockEndpointsSatisfied();
}
use of org.apache.camel.Processor in project camel by apache.
the class CamelContextAddRouteDefinitionsFromXmlTest method testAddRouteDefinitionsFromXml3.
public void testAddRouteDefinitionsFromXml3() throws Exception {
RouteDefinition route = loadRoute("route3.xml");
assertNotNull(route);
assertEquals("foo", route.getId());
assertEquals(0, context.getRoutes().size());
context.addRouteDefinition(route);
assertEquals(1, context.getRoutes().size());
assertTrue("Route should be started", context.getRouteStatus("foo").isStarted());
getMockEndpoint("mock:foo").whenExchangeReceived(2, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.setException(new IllegalArgumentException("Damn"));
}
});
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:handled").expectedBodiesReceived("Bye World");
template.sendBody("direct:start", "Hello World");
template.sendBody("direct:start", "Bye World");
assertMockEndpointsSatisfied();
}
Aggregations