Search in sources :

Example 1 with RestDefinition

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);
}
Also used : RestDefinition(org.apache.camel.model.rest.RestDefinition) Test(org.junit.Test)

Example 2 with RestDefinition

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();
}
Also used : SwaggerConfig(com.wordnik.swagger.config.SwaggerConfig) RestDefinition(org.apache.camel.model.rest.RestDefinition) ApiListing(com.wordnik.swagger.model.ApiListing) Test(org.junit.Test)

Example 3 with RestDefinition

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);
}
Also used : ToDefinition(org.apache.camel.model.ToDefinition) RestDefinition(org.apache.camel.model.rest.RestDefinition) Test(org.junit.Test)

Example 4 with RestDefinition

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);
}
Also used : ToDefinition(org.apache.camel.model.ToDefinition) RestDefinition(org.apache.camel.model.rest.RestDefinition) Test(org.junit.Test)

Example 5 with RestDefinition

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);
}
Also used : CamelContext(org.apache.camel.CamelContext) RestDefinition(org.apache.camel.model.rest.RestDefinition) RestsDefinition(org.apache.camel.model.rest.RestsDefinition)

Aggregations

RestDefinition (org.apache.camel.model.rest.RestDefinition)38 ToDefinition (org.apache.camel.model.ToDefinition)10 Test (org.junit.Test)10 RestsDefinition (org.apache.camel.model.rest.RestsDefinition)5 RouteDefinition (org.apache.camel.model.RouteDefinition)4 Swagger (io.swagger.models.Swagger)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 FromDefinition (org.apache.camel.model.FromDefinition)2 InterceptFromDefinition (org.apache.camel.model.InterceptFromDefinition)2 GetVerbDefinition (org.apache.camel.model.rest.GetVerbDefinition)2 RestContainer (org.apache.camel.model.rest.RestContainer)2 VerbDefinition (org.apache.camel.model.rest.VerbDefinition)2 RestConfiguration (org.apache.camel.spi.RestConfiguration)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1