Search in sources :

Example 1 with ToDefinition

use of org.apache.camel.model.ToDefinition in project camel by apache.

the class FromRestGetEmbeddedRouteTest method testFromRestModel.

@Test
public void testFromRestModel() throws Exception {
    assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
    assertEquals(2, context.getRestDefinitions().size());
    RestDefinition rest = context.getRestDefinitions().get(0);
    assertNotNull(rest);
    assertEquals("/say/hello", rest.getPath());
    assertEquals(1, rest.getVerbs().size());
    ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(0));
    assertEquals("mock:hello", to.getUri());
    rest = context.getRestDefinitions().get(1);
    assertNotNull(rest);
    assertEquals("/say/bye", rest.getPath());
    assertEquals(2, rest.getVerbs().size());
    assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
    to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(0));
    assertEquals("mock:bye", to.getUri());
    // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
    getMockEndpoint("mock:update").expectedMessageCount(1);
    template.sendBody("seda:post-say-bye", "I was here");
    assertMockEndpointsSatisfied();
    String out = template.requestBody("seda:get-say-hello", "Me", String.class);
    assertEquals("Hello World", out);
    String out2 = template.requestBody("seda:get-say-bye", "Me", String.class);
    assertEquals("Bye World", out2);
}
Also used : ToDefinition(org.apache.camel.model.ToDefinition) RestDefinition(org.apache.camel.model.rest.RestDefinition) Test(org.junit.Test)

Example 2 with ToDefinition

use of org.apache.camel.model.ToDefinition in project camel by apache.

the class RestRefTest method testRestRefTest.

@Test
public void testRestRefTest() throws Exception {
    assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
    assertEquals(2, context.getRestDefinitions().size());
    RestDefinition rest = context.getRestDefinitions().get(0);
    assertNotNull(rest);
    assertEquals("/say/hello", rest.getPath());
    assertEquals(1, rest.getVerbs().size());
    ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
    assertEquals("direct:hello", to.getUri());
    rest = context.getRestDefinitions().get(1);
    assertNotNull(rest);
    assertEquals("/say/bye", rest.getPath());
    assertEquals(2, rest.getVerbs().size());
    assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
    to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
    assertEquals("direct:bye", to.getUri());
    // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
    getMockEndpoint("mock:update").expectedMessageCount(1);
    template.sendBody("seda:post-say-bye", "I was here");
    assertMockEndpointsSatisfied();
    String out = template.requestBody("seda:get-say-hello", "Me", String.class);
    assertEquals("Hello World", out);
    String out2 = template.requestBody("seda:get-say-bye", "Me", String.class);
    assertEquals("Bye World", out2);
}
Also used : ToDefinition(org.apache.camel.model.ToDefinition) RestDefinition(org.apache.camel.model.rest.RestDefinition) Test(org.junit.Test)

Example 3 with ToDefinition

use of org.apache.camel.model.ToDefinition in project camel by apache.

the class RestDefinition method to.

/**
     * Routes directly to the given static endpoint.
     * <p/>
     * If you need additional routing capabilities, then use {@link #route()} instead.
     *
     * @param uri the uri of the endpoint
     * @return this builder
     */
public RestDefinition to(String uri) {
    // add to last verb
    if (getVerbs().isEmpty()) {
        throw new IllegalArgumentException("Must add verb first, such as get/post/delete");
    }
    ToDefinition to = new ToDefinition(uri);
    VerbDefinition verb = getVerbs().get(getVerbs().size() - 1);
    verb.setTo(to);
    return this;
}
Also used : ToDefinition(org.apache.camel.model.ToDefinition)

Example 4 with ToDefinition

use of org.apache.camel.model.ToDefinition in project camel by apache.

the class FromRestGetEmbeddedRouteTest method testFromRestModel.

public void testFromRestModel() throws Exception {
    assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
    assertEquals(2, context.getRestDefinitions().size());
    RestDefinition rest = context.getRestDefinitions().get(0);
    assertNotNull(rest);
    assertEquals("/say/hello", rest.getPath());
    assertEquals(1, rest.getVerbs().size());
    ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(0));
    assertEquals("mock:hello", to.getUri());
    rest = context.getRestDefinitions().get(1);
    assertNotNull(rest);
    assertEquals("/say/bye", rest.getPath());
    assertEquals(2, rest.getVerbs().size());
    assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
    to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(0));
    assertEquals("mock:bye", to.getUri());
    // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
    getMockEndpoint("mock:update").expectedMessageCount(1);
    template.sendBody("seda:post-say-bye", "I was here");
    assertMockEndpointsSatisfied();
    String out = template.requestBody("seda:get-say-hello", "Me", String.class);
    assertEquals("Hello World", out);
    String out2 = template.requestBody("seda:get-say-bye", "Me", String.class);
    assertEquals("Bye World", out2);
}
Also used : ToDefinition(org.apache.camel.model.ToDefinition) RestDefinition(org.apache.camel.model.rest.RestDefinition)

Example 5 with ToDefinition

use of org.apache.camel.model.ToDefinition in project camel by apache.

the class FromRestGetEndPathTest method testFromRestModel.

public void testFromRestModel() throws Exception {
    assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
    assertEquals(2, context.getRestDefinitions().size());
    RestDefinition rest = context.getRestDefinitions().get(0);
    assertNotNull(rest);
    assertEquals("/say/hello", rest.getPath());
    assertEquals(1, rest.getVerbs().size());
    ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
    assertEquals("direct:hello", to.getUri());
    rest = context.getRestDefinitions().get(1);
    assertNotNull(rest);
    assertEquals("/say/bye", rest.getPath());
    assertEquals(2, rest.getVerbs().size());
    assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
    to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(0));
    assertEquals("direct:bye", to.getUri());
    // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
    getMockEndpoint("mock:update").expectedMessageCount(1);
    template.sendBody("seda:post-say-bye", "I was here");
    assertMockEndpointsSatisfied();
    String out = template.requestBody("seda:get-say-hello", "Me", String.class);
    assertEquals("Hello World", out);
    String out2 = template.requestBody("seda:get-say-bye", "Me", String.class);
    assertEquals("Bye World", out2);
}
Also used : ToDefinition(org.apache.camel.model.ToDefinition) RestDefinition(org.apache.camel.model.rest.RestDefinition)

Aggregations

ToDefinition (org.apache.camel.model.ToDefinition)14 RestDefinition (org.apache.camel.model.rest.RestDefinition)10 Test (org.junit.Test)4 Exchange (org.apache.camel.Exchange)2 ChoiceDefinition (org.apache.camel.model.ChoiceDefinition)2 LogDefinition (org.apache.camel.model.LogDefinition)2 OtherwiseDefinition (org.apache.camel.model.OtherwiseDefinition)2 RouteDefinition (org.apache.camel.model.RouteDefinition)2 WhenDefinition (org.apache.camel.model.WhenDefinition)2 EventObject (java.util.EventObject)1 List (java.util.List)1 Attribute (javax.management.Attribute)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 Processor (org.apache.camel.Processor)1 BacklogTracerEventMessage (org.apache.camel.api.management.mbean.BacklogTracerEventMessage)1 BreakpointSupport (org.apache.camel.impl.BreakpointSupport)1 ConditionSupport (org.apache.camel.impl.ConditionSupport)1 ExchangeCompletedEvent (org.apache.camel.management.event.ExchangeCompletedEvent)1