use of org.apache.camel.model.rest.RestDefinition 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.rest.RestDefinition 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.rest.RestDefinition in project camel by apache.
the class AbstractLocalCamelController method getRestModelAsXml.
public String getRestModelAsXml(String camelContextName) throws Exception {
CamelContext context = this.getLocalCamelContext(camelContextName);
if (context == null) {
return null;
}
List<RestDefinition> rests = context.getRestDefinitions();
if (rests == null || rests.isEmpty()) {
return null;
}
// use a rests definition to dump the rests
RestsDefinition def = new RestsDefinition();
def.setRests(rests);
return ModelHelper.dumpModelAsXml(null, def);
}
use of org.apache.camel.model.rest.RestDefinition in project camel by apache.
the class RestRefTest method testRestRefTest.
public void testRestRefTest() throws Exception {
assertEquals(2 + 3, 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.rest.RestDefinition in project camel by apache.
the class RestSwaggerReader method read.
/**
* Read the REST-DSL definition's and parse that as a Swagger model representation
*
* @param rests the rest-dsl
* @param route optional route path to filter the rest-dsl to only include from the chose route
* @param config the swagger configuration
* @param classResolver class resolver to use
* @return the swagger model
*/
public Swagger read(List<RestDefinition> rests, String route, BeanConfig config, String camelContextId, ClassResolver classResolver) {
Swagger swagger = new Swagger();
for (RestDefinition rest : rests) {
if (ObjectHelper.isNotEmpty(route) && !route.equals("/")) {
// filter by route
if (!rest.getPath().equals(route)) {
continue;
}
}
parse(swagger, rest, camelContextId, classResolver);
}
// configure before returning
swagger = config.configure(swagger);
return swagger;
}
Aggregations