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);
}
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);
}
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;
}
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);
}
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);
}
Aggregations