Java 类org.apache.camel.model.ToDefinition 实例源码

项目:Camel    文件:AdviceWithTypeTest.java   
public void testBefore() throws Exception {
    // START SNIPPET: e3
    context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
        @Override
        public void configure() throws Exception {
            // weave the type in the route and remove it
            // and insert the following route path before the adviced node
            weaveByType(ToDefinition.class).before().transform(constant("Bye World"));
        }
    });
    // END SNIPPET: e3

    getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");

    template.sendBody("direct:start", "World");

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:AdviceWithTypeTest.java   
public void testAfter() throws Exception {
    // START SNIPPET: e4
    context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
        @Override
        public void configure() throws Exception {
            // weave the type in the route and remove it
            // and insert the following route path after the adviced node
            weaveByType(ToDefinition.class).after().transform(constant("Bye World"));
        }
    });
    // END SNIPPET: e4

    getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");

    Object out = template.requestBody("direct:start", "World");
    assertEquals("Bye World", out);

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:CustomInterceptorRouteWithChildOutputTest.java   
public void testCustomInterceptor() throws Exception {
    getMockEndpoint("mock:child").expectedMessageCount(3);
    getMockEndpoint("mock:result").expectedMessageCount(1);

    template.sendBody("direct:start", "A,B,C");

    assertMockEndpointsSatisfied();

    assertEquals(4, myInterceptor.getDefs().size());
    assertIsInstanceOf(LogDefinition.class, myInterceptor.getDefs().get(0));
    assertIsInstanceOf(ToDefinition.class, myInterceptor.getDefs().get(1));
    assertEquals("mock:child", myInterceptor.getDefs().get(1).getLabel());
    assertIsInstanceOf(SplitDefinition.class, myInterceptor.getDefs().get(2));
    assertIsInstanceOf(ToDefinition.class, myInterceptor.getDefs().get(3));
    assertEquals("mock:result", myInterceptor.getDefs().get(3).getLabel());
}
项目:Camel    文件:CustomProcessorFactoryTest.java   
public Processor createProcessor(RouteContext routeContext, ProcessorDefinition<?> definition) throws Exception {
    if (definition instanceof SplitDefinition) {
        // add additional output to the splitter
        SplitDefinition split = (SplitDefinition) definition;
        split.addOutput(new ToDefinition("mock:extra"));
    }

    if (definition instanceof SetBodyDefinition) {
        SetBodyDefinition set = (SetBodyDefinition) definition;
        set.setExpression(new ConstantExpression("body was altered"));
    }

    // return null to let the default implementation create the processor, we just wanted to alter the definition
    // before the processor was created
    return null;
}
项目:Camel    文件:FromRestUriPrefixTest.java   
public void testFromRestModel() throws Exception {
    assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());

    assertEquals(1, context.getRestDefinitions().size());
    RestDefinition rest = context.getRestDefinitions().get(0);
    assertNotNull(rest);
    assertEquals("/say/", rest.getPath());
    assertEquals(3, rest.getVerbs().size());
    assertEquals("/hello", rest.getVerbs().get(0).getUri());
    assertEquals("/bye", rest.getVerbs().get(1).getUri());
    assertEquals("/hi", rest.getVerbs().get(2).getUri());
    ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
    assertEquals("direct:hello", to.getUri());
    to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(1).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-hi", "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);
}
项目:camelinaction2    文件:WeaveByTypeSelectFirstTest.java   
@Test
public void testWeaveByTypeSelectFirst() throws Exception {
    RouteDefinition route = context.getRouteDefinition("quotes");
    route.adviceWith(context, new AdviceWithRouteBuilder() {
        @Override
        public void configure() throws Exception {
            // find the send to and select the first which gets replaced
            weaveByType(ToDefinition.class).selectFirst().replace().to("mock:line");
        }
    });

    context.start();

    getMockEndpoint("mock:line").expectedBodiesReceived("camel rules", "donkey is bad");
    getMockEndpoint("mock:combined").expectedMessageCount(1);
    getMockEndpoint("mock:combined").message(0).body().isInstanceOf(List.class);

    template.sendBody("seda:quotes", "Camel Rules,Donkey is Bad");

    assertMockEndpointsSatisfied();
}
项目:fabric8-forge    文件:CamelModelHelper.java   
public static String getUri(ToDefinition input) {
    String key = input.getUri();
    if (Strings2.isEmpty(key)) {
        String ref = input.getRef();
        if (!Strings2.isEmpty(ref)) {
            return "ref:" + ref;
        }
    }
    return key;
}
项目:fabric8-forge    文件:CamelModelHelper.java   
public static String getExchangePattern(ToDefinition input) {
    String pattern = input.getPattern() != null ? input.getPattern().name() : null;
    if (Strings2.isEmpty(pattern)) {
        return null;
    }
    return pattern;
}
项目:Camel    文件:VerbDefinition.java   
public ToDefinition getTo() {
    if (to != null) {
        return to;
    } else if (toOrRoute instanceof ToDefinition) {
        return (ToDefinition) toOrRoute;
    } else {
        return null;
    }
}
项目:Camel    文件:TraceInitIdOnAllNodesTest.java   
public void testInitIdsOnAllNodes() throws Exception {
    getMockEndpoint("mock:camel").expectedBodiesReceived("Hello Camel");
    getMockEndpoint("mock:other").expectedBodiesReceived("Hello World");
    getMockEndpoint("mock:end").expectedMessageCount(2);

    template.sendBody("direct:start", "Hello Camel");
    template.sendBody("direct:start", "Hello World");

    assertMockEndpointsSatisfied();

    RouteDefinition route = context.getRouteDefinitions().get(0);
    assertNotNull(route);

    ChoiceDefinition choice = (ChoiceDefinition) route.getOutputs().get(0);
    assertEquals("choice1", choice.getId());

    WhenDefinition when = (WhenDefinition) choice.getOutputs().get(0);
    assertEquals("when1", when.getId());

    LogDefinition log1 = (LogDefinition) when.getOutputs().get(0);
    assertEquals("log1", log1.getId());

    ToDefinition to1 = (ToDefinition) when.getOutputs().get(1);
    assertEquals("camel", to1.getId());

    OtherwiseDefinition other = (OtherwiseDefinition) choice.getOutputs().get(1);
    assertEquals("otherwise1", other.getId());

    LogDefinition log2 = (LogDefinition) other.getOutputs().get(0);
    assertEquals("log2", log2.getId());

    ToDefinition to2 = (ToDefinition) other.getOutputs().get(1);
    assertEquals("to1", to2.getId());

    ToDefinition to3 = (ToDefinition) other.getOutputs().get(2);
    assertEquals("foo", to3.getId());

    ToDefinition to4 = (ToDefinition) route.getOutputs().get(1);
    assertEquals("end", to4.getId());
}
项目:Camel    文件:DebugTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();

    breakpoint = new BreakpointSupport() {
        public void beforeProcess(Exchange exchange, Processor processor, ProcessorDefinition<?> definition) {
            String body = exchange.getIn().getBody(String.class);
            logs.add("Breakpoint at " + definition + " with body: " + body);
        }

        public void onEvent(Exchange exchange, EventObject event, ProcessorDefinition<?> definition) {
            String body = exchange.getIn().getBody(String.class);
            logs.add("Breakpoint event " + event.getClass().getSimpleName() + " with body: " + body);
        }
    };

    camelCondition = new ConditionSupport() {
        public boolean matchProcess(Exchange exchange, Processor processor, ProcessorDefinition<?> definition) {
            return body().contains("Camel").matches(exchange);
        }
    };

    mockCondition = new ConditionSupport() {
        public boolean matchProcess(Exchange exchange, Processor processor, ProcessorDefinition<?> definition) {
            // match when sending to mocks
            if (definition instanceof ToDefinition) {
                ToDefinition to = (ToDefinition) definition;
                return to.getUriOrRef().startsWith("mock");
            }
            return false;
        }
    };

    doneCondition = new ConditionSupport() {
        @Override
        public boolean matchEvent(Exchange exchange, EventObject event) {
            return event instanceof ExchangeCompletedEvent;
        }
    };
}
项目:Camel    文件:FromRestApiTest.java   
public void testFromRestModel() throws Exception {
    assertEquals(1, 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("log:hello", to.getUri());

    // should be 2 routes
    assertEquals(2, context.getRoutes().size());
}
项目:Camel    文件:FromRestGetEndPathTest.java   
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(1));
    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);
}
项目:Camel    文件:FromRestGetEmbeddedRouteTest.java   
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(1));
    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(1));
    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);
}
项目:Camel    文件:FromRestUriPrefixTest.java   
@Test
public void testFromRestModel() throws Exception {
    assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());

    assertEquals(1, context.getRestDefinitions().size());
    RestDefinition rest = context.getRestDefinitions().get(0);
    assertNotNull(rest);
    assertEquals("/say/", rest.getPath());
    assertEquals(3, rest.getVerbs().size());
    assertEquals("/hello", rest.getVerbs().get(0).getUri());
    assertEquals("/bye", rest.getVerbs().get(1).getUri());
    assertEquals("/hi", rest.getVerbs().get(2).getUri());
    ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
    assertEquals("direct:hello", to.getUri());
    to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(1).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-hi", "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);
}
项目:Camel    文件:RestRefTest.java   
@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);
}
项目:Camel    文件:FromRestGetEmbeddedRouteTest.java   
@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(1));
    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(1));
    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);
}
项目:Camel    文件:RestRefTest.java   
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);
}
项目:camel-dynamic-loadbalancer    文件:MBeanRouteStatisticsCollector.java   
/**
 * Get the uri from the processor (NOTE: Current impl uses reflection, so could fail easily)
 *
 * @param current
 * @return
 */
private String getUriFromProcessor(Processor current) {
    String uri = "";

    //NOTE: What if camel uses different 'Channels', this wont work.
    // How can i get the URI from the processor in a nice way?

    if (current instanceof DefaultChannel) {
        DefaultChannel currentChannel = (DefaultChannel)current;

        Object outputValue = null;
        try {
            //NOTE: Shouldnt really be using reflection...but dont know what class i can use
            Field outputField = FieldUtils.getField(DefaultChannel.class, "childDefinition", true);
            outputValue = FieldUtils.readField(outputField, currentChannel, true);
        } catch (IllegalAccessException ex) {
            LOG.error("Cannot access 'childDefinition' on {} because: {}", current, ExceptionUtils.getStackTrace(ex));
        }

        //NOTE: What if the definition isnt a To, its another type...
        if (outputValue != null && outputValue instanceof ToDefinition) {
            ToDefinition to = (ToDefinition)outputValue;

            uri = normalizeUri(to.getUri());
        }
    }

    if (uri.isEmpty()) {
        throw new IllegalStateException("Could not get URI from processor '" + current + "'");
    }

    return uri;
}
项目:cleverbus    文件:TestUtils.java   
/**
 * Replaces calling TO {@link AsynchConstants#URI_ASYNCH_IN_MSG} with processor that creates OK response.
 * <p/>
 * Useful when you want to test input (IN) route of asynchronous process.
 *
 * @param builder the advice builder
 */
public static final void replaceToAsynch(AdviceWithRouteBuilder builder) {
    // remove AsynchInMessageRoute.URI_ASYNCH_IN_MSG
    builder.weaveByType(ToDefinition.class).replace().process(new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
            // creates OK response
            CallbackResponse callbackResponse = new CallbackResponse();
            callbackResponse.setStatus(ConfirmationTypes.OK);

            exchange.getIn().setBody(callbackResponse);
        }
    });
}
项目:fuse-bxms-integ    文件:KiePolicy.java   
public Processor wrap(RouteContext routeContext, Processor processor) {
    RouteDefinition routeDef = routeContext.getRoute();

    ToDefinition toKie = getKieNode(routeDef);

    Processor returnedProcessor;
    if (toKie != null) {
        returnedProcessor = new KieProcess(toKie.getUri(), processor);
    } else {
        returnedProcessor = processor;
    }
    return returnedProcessor;
}
项目:fuse-bxms-integ    文件:KiePolicy.java   
private ToDefinition getKieNode(RouteDefinition routeDef) {
    ToDefinition toDrools = null;
    for (ProcessorDefinition<?> child : routeDef.getOutputs()) {
        toDrools = getKieNode(child);
        if (toDrools != null) {
            break;
        }
    }
    return toDrools;
}
项目:fuse-bxms-integ    文件:KiePolicy.java   
private ToDefinition getKieNode(ProcessorDefinition nav) {
    if (!nav.getOutputs().isEmpty()) {
        List<ProcessorDefinition<?>> children = nav.getOutputs();
        for (ProcessorDefinition child : children) {
            if (child instanceof ToDefinition) {
                ToDefinition to = (ToDefinition)child;
                if (to.getUri().trim().startsWith("kie:")) {
                    return to;
                }
            }
            getKieNode(child);
        }
    }
    return null;
}
项目:fabric8-forge    文件:CamelModelUtilsTest.java   
@Test
public void testPatternNameTo() {
    ToDefinition node = new ToDefinition();
    assertEquals("to", CamelModelHelper.getPatternName(node));
}
项目:Camel    文件:VerbDefinition.java   
public void setTo(ToDefinition to) {
    this.to = to;
    this.toD = null;
    this.toOrRoute = to;
}
项目:Camel    文件:FromRestGetTest.java   
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());

    assertEquals(2, rest.getVerbs().get(0).getParams().size());
    assertEquals(RestParamType.header, rest.getVerbs().get(0).getParams().get(0).getType());
    assertEquals(RestParamType.query, rest.getVerbs().get(0).getParams().get(1).getType());

    assertEquals("header param description1", rest.getVerbs().get(0).getParams().get(0).getDescription());
    assertEquals("header param description2", rest.getVerbs().get(0).getParams().get(1).getDescription());

    assertEquals("integer", rest.getVerbs().get(0).getParams().get(0).getDataType());
    assertEquals("string", rest.getVerbs().get(0).getParams().get(1).getDataType());
    assertEquals(Arrays.asList("1", "2", "3", "4"), rest.getVerbs().get(0).getParams().get(0).getAllowableValues());
    assertEquals(Arrays.asList("a", "b", "c", "d"), rest.getVerbs().get(0).getParams().get(1).getAllowableValues());
    assertEquals("1", rest.getVerbs().get(0).getParams().get(0).getDefaultValue());
    assertEquals("b", rest.getVerbs().get(0).getParams().get(1).getDefaultValue());

    assertEquals(null, rest.getVerbs().get(0).getParams().get(0).getCollectionFormat());
    assertEquals(CollectionFormat.multi, rest.getVerbs().get(0).getParams().get(1).getCollectionFormat());

    assertEquals("header_count", rest.getVerbs().get(0).getParams().get(0).getName());
    assertEquals("header_letter", rest.getVerbs().get(0).getParams().get(1).getName());
    assertEquals(Boolean.TRUE, rest.getVerbs().get(0).getParams().get(0).getRequired());
    assertEquals(Boolean.FALSE, rest.getVerbs().get(0).getParams().get(1).getRequired());

    assertEquals("300", rest.getVerbs().get(0).getResponseMsgs().get(0).getCode());
    assertEquals("rate", rest.getVerbs().get(0).getResponseMsgs().get(0).getHeaders().get(0).getName());
    assertEquals("Rate limit", rest.getVerbs().get(0).getResponseMsgs().get(0).getHeaders().get(0).getDescription());
    assertEquals("integer", rest.getVerbs().get(0).getResponseMsgs().get(0).getHeaders().get(0).getDataType());
    assertEquals("error", rest.getVerbs().get(0).getResponseMsgs().get(1).getCode());
    assertEquals("test msg", rest.getVerbs().get(0).getResponseMsgs().get(0).getMessage());
    assertEquals(Integer.class.getCanonicalName(), rest.getVerbs().get(0).getResponseMsgs().get(0).getResponseModel());

    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);
}
项目:Camel    文件:FromRestGetTest.java   
@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).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());

    assertEquals(2, rest.getVerbs().get(0).getParams().size());
    assertEquals(RestParamType.header, rest.getVerbs().get(0).getParams().get(0).getType());
    assertEquals(RestParamType.query, rest.getVerbs().get(0).getParams().get(1).getType());

    assertEquals("header param description1", rest.getVerbs().get(0).getParams().get(0).getDescription());
    assertEquals("header param description2", rest.getVerbs().get(0).getParams().get(1).getDescription());

    assertEquals("integer", rest.getVerbs().get(0).getParams().get(0).getDataType());
    assertEquals("string", rest.getVerbs().get(0).getParams().get(1).getDataType());
    assertEquals(Arrays.asList("1", "2", "3", "4"), rest.getVerbs().get(0).getParams().get(0).getAllowableValues());
    assertEquals(Arrays.asList("a", "b", "c", "d"), rest.getVerbs().get(0).getParams().get(1).getAllowableValues());
    assertEquals("1", rest.getVerbs().get(0).getParams().get(0).getDefaultValue());
    assertEquals("b", rest.getVerbs().get(0).getParams().get(1).getDefaultValue());

    assertEquals(null, rest.getVerbs().get(0).getParams().get(0).getCollectionFormat());
    assertEquals(CollectionFormat.multi, rest.getVerbs().get(0).getParams().get(1).getCollectionFormat());

    assertEquals("header_count", rest.getVerbs().get(0).getParams().get(0).getName());
    assertEquals("header_letter", rest.getVerbs().get(0).getParams().get(1).getName());
    assertEquals(Boolean.TRUE, rest.getVerbs().get(0).getParams().get(0).getRequired());
    assertEquals(Boolean.FALSE, rest.getVerbs().get(0).getParams().get(1).getRequired());

    assertEquals("300", rest.getVerbs().get(0).getResponseMsgs().get(0).getCode());
    assertEquals("rate", rest.getVerbs().get(0).getResponseMsgs().get(0).getHeaders().get(0).getName());
    assertEquals("Rate limit", rest.getVerbs().get(0).getResponseMsgs().get(0).getHeaders().get(0).getDescription());
    assertEquals("integer", rest.getVerbs().get(0).getResponseMsgs().get(0).getHeaders().get(0).getDataType());
    assertEquals("test msg", rest.getVerbs().get(0).getResponseMsgs().get(0).getMessage());
    assertEquals(Integer.class.getCanonicalName(), rest.getVerbs().get(0).getResponseMsgs().get(0).getResponseModel());

    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);
}
项目:camel-dynamic-loadbalancer    文件:MBeanRouteStatisticsCollectorTest.java   
@Test
public void queryGets1ValueBack() throws Exception {
    setupManagementStrategy();

    Set<ObjectName> objectNames = new HashSet<ObjectName>();
    objectNames.add(new ObjectName("org.apache.camel:type=routes,name=route1,*"));
    objectNames.add(new ObjectName("org.apache.camel:type=routes,name=route2,*"));

    MBeanServer mBeanServerMocked = Mockito.mock(MBeanServer.class);
    provideRouteStats(mBeanServerMocked, objectNames);
    provideAllRoutes(mBeanServerMocked, objectNames);

    //TODO: update as failing test

    DirectComponent component = new DirectComponent();
    component.setCamelContext(context);

    DefaultChannel processor1 = new DefaultChannel();
    processor1.setChildDefinition(new ToDefinition(new DirectEndpoint("direct:lb1", component)));

    DefaultChannel processor2 = new DefaultChannel();
    processor2.setChildDefinition(new ToDefinition(new DirectEndpoint("direct:lb2", component)));

    List<Processor> processors = new LinkedList<Processor>();
    processors.add(processor1);
    processors.add(processor2);

    MBeanRouteStatisticsCollector collector = new MBeanRouteStatisticsCollector(context, mBeanServerMocked, "route", false, false);
    List<RouteStatistics> stats = collector.query(processors, createExchange());

    Assert.assertNotNull(stats);
    Assert.assertEquals(2, stats.size());

    RouteStatistics first = stats.get(0);
    Assert.assertEquals(new Long(1), new Long(first.getInflightExchange()));
    Assert.assertEquals(new Long(20L), new Long(first.getMeanProcessingTime()));
    Assert.assertEquals(new Long(30L), new Long(first.getLastProcessingTime()));
    Assert.assertEquals("1", first.getLoad01());
    Assert.assertEquals("5", first.getLoad05());
    Assert.assertEquals("15", first.getLoad15());
}
项目:switchyard    文件:CamelActivator.java   
private void verifyRouteDefinitions(List<RouteDefinition> routeDefinitions, CamelComponentImplementationModel ccim) throws Exception {
    // service name & namespace
    // TODO what happens when we have multiple services?
    String serviceName = ccim.getComponent().getServices().get(0).getName();
    String compositeNs = ccim.getComponent().getComposite().getTargetNamespace();
    // number of switchyard:// consumers/from statements
    int serviceConsumer = 0;
    for (RouteDefinition routeDefinition : routeDefinitions) {
        if (routeDefinition.getInputs().isEmpty()) {
            throw CamelComponentMessages.MESSAGES.mustHaveAtLeastOneInput();
        }
        for (FromDefinition fromDefinition : routeDefinition.getInputs()) {

            URI from = URI.create(this.getCamelContext().resolvePropertyPlaceholders(fromDefinition.getUri()));
            if (from.getScheme().equals(CamelConstants.SWITCHYARD_COMPONENT_NAME)) {
                if (serviceConsumer > 0) {
                    throw CamelComponentMessages.MESSAGES.onlyOneSwitchYardInputPerImpl();
                }
                String authority = from.getAuthority();

                if (!serviceName.equals(authority)) {
                    throw CamelComponentMessages.MESSAGES.implementationConsumerDoesNotMatchService(serviceName);
                }
                serviceConsumer++;
            }
        }

        List<ProcessorDefinition<?>> outputs = routeDefinition.getOutputs();
        for (ProcessorDefinition<?> processorDefinition : outputs) {
            if (processorDefinition instanceof ToDefinition) {
                ToDefinition to = (ToDefinition) processorDefinition;
                URI componentUri = null;
                if (to.getRef() != null) {
                    componentUri = URI.create(getCamelContext().getRegistry().lookupByNameAndType(to.getRef(), Endpoint.class).getEndpointUri());
                } else if (to.getUri() != null) {
                    componentUri = URI.create(this.getCamelContext().resolvePropertyPlaceholders(to.getUri()));
                } else {
                    throw CamelComponentMessages.MESSAGES.couldNotResolveToEndpointUri(to.toString());
                }
                if (componentUri.getScheme().equals(CamelConstants.SWITCHYARD_COMPONENT_NAME)) {
                    final String referenceName = componentUri.getAuthority();
                    final QName refServiceName = new QName(compositeNs, referenceName);
                    if (!containsServiceRef(ccim.getComponent().getReferences(), referenceName)) {
                        throw CamelComponentMessages.MESSAGES.couldNotFindServiceReference(referenceName, to.toString());
                    }

                    QName qualifiedRefName = ComponentNames.qualify(
                            ccim.getComponent().getQName(), refServiceName);
                    final ServiceReference service = getServiceDomain().getServiceReference(qualifiedRefName);
                    if (service == null) {
                        throw CamelComponentMessages.MESSAGES.couldNotFindServiceName(qualifiedRefName.toString(), to.toString());
                    }
                }
            }
        }
    }
    if (serviceConsumer != 1) {
        throw CamelComponentMessages.MESSAGES.cannotCreateComponentImpl();
    }
}