use of org.apache.camel.model.rest.RestDefinition in project camel by apache.
the class DefaultCamelSwaggerServletTest method testServlet.
@Test
public void testServlet() throws Exception {
DefaultCamelSwaggerServlet servlet = new DefaultCamelSwaggerServlet();
Buffer<RestDefinition> list = servlet.getRestDefinitions(null);
assertEquals(1, list.size());
RestDefinition rest = list.iterator().next();
checkRestDefinition(rest);
// get the RestDefinition by using the camel context id
list = servlet.getRestDefinitions(context.getName());
assertEquals(1, list.size());
rest = list.iterator().next();
checkRestDefinition(rest);
RestDefinition rest2 = context.getRestDefinitions().get(0);
checkRestDefinition(rest2);
}
use of org.apache.camel.model.rest.RestDefinition in project camel by apache.
the class RestSwaggerReaderTest method testReaderRead.
@Test
public void testReaderRead() throws Exception {
RestDefinition rest = context.getRestDefinitions().get(0);
assertNotNull(rest);
SwaggerConfig config = new SwaggerConfig();
config.setBasePath("http://localhost:8080/api");
RestSwaggerReader reader = new RestSwaggerReader();
Option<ApiListing> option = reader.read(rest, config);
assertNotNull(option);
ApiListing listing = option.get();
assertNotNull(listing);
String json = JsonSerializer.asJson(listing);
log.info(json);
assertTrue(json.contains("\"basePath\":\"http://localhost:8080/api\""));
assertTrue(json.contains("\"resourcePath\":\"/hello\""));
assertTrue(json.contains("\"method\":\"GET\""));
assertTrue(json.contains("\"nickname\":\"getHelloHi\""));
context.stop();
}
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);
}
Aggregations