Search in sources :

Example 86 with Processor

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();
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor)

Example 87 with Processor

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));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor)

Example 88 with Processor

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();
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor)

Example 89 with Processor

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();
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor)

Example 90 with Processor

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();
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteDefinition(org.apache.camel.model.RouteDefinition) JAXBException(javax.xml.bind.JAXBException)

Aggregations

Processor (org.apache.camel.Processor)1467 Exchange (org.apache.camel.Exchange)1368 Test (org.junit.Test)634 RouteBuilder (org.apache.camel.builder.RouteBuilder)543 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)164 Message (org.apache.camel.Message)119 ArrayList (java.util.ArrayList)65 HashMap (java.util.HashMap)64 IOException (java.io.IOException)55 CamelExecutionException (org.apache.camel.CamelExecutionException)52 Endpoint (org.apache.camel.Endpoint)46 Map (java.util.Map)45 File (java.io.File)38 List (java.util.List)34 Producer (org.apache.camel.Producer)33 DefaultExchange (org.apache.camel.impl.DefaultExchange)29 SendProcessor (org.apache.camel.processor.SendProcessor)26 AggregationStrategy (org.apache.camel.processor.aggregate.AggregationStrategy)26 CountDownLatch (java.util.concurrent.CountDownLatch)24 Expression (org.apache.camel.Expression)24