Search in sources :

Example 16 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 17 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 18 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)

Example 19 with RestDefinition

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

Example 20 with RestDefinition

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;
}
Also used : RestDefinition(org.apache.camel.model.rest.RestDefinition) Swagger(io.swagger.models.Swagger)

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