camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Willem Jiang <willem.ji...@gmail.com>
Subject Re: svn commit: r936869 [1/2] - in /camel/trunk: camel-core/src/main/java/org/apache/camel/model/ camel-core/src/main/java/org/apache/camel/processor/ camel-core/src/main/java/org/apache/camel/processor/aggregate/ camel-core/src/test/java/org/apache/camel/...
Date Fri, 23 Apr 2010 00:46:12 GMT
Hi Claus,

I don't think the PolicyPerRouteTest works as it should be.
If the Policy set to be per route, all the processors in this route 
should be wrapped with the Policy processor and foo should be invoked 3 
times.

Willem

davsclaus@apache.org wrote:
> Author: davsclaus
> Date: Thu Apr 22 14:29:34 2010
> New Revision: 936869
> 
> URL: http://svn.apache.org/viewvc?rev=936869&view=rev
> Log:
> CAMEL-2665, CAMEL-2666, CAMEL-2667: Policy can now be used per processor. Model definitions
now check on startup if required children is missing to prevent mis configuration. Policy
is now handle correctly with lifecycle by WrapProcessor.
> 

> Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/PolicyPerRouteTest.java
> URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/PolicyPerRouteTest.java?rev=936869&view=auto
> ==============================================================================
> --- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/PolicyPerRouteTest.java
(added)
> +++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/PolicyPerRouteTest.java
Thu Apr 22 14:29:34 2010
> @@ -0,0 +1,98 @@
> +/**
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements.  See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License.  You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +package org.apache.camel.processor;
> +
> +import org.apache.camel.ContextTestSupport;
> +import org.apache.camel.Exchange;
> +import org.apache.camel.Processor;
> +import org.apache.camel.builder.RouteBuilder;
> +import org.apache.camel.impl.JndiRegistry;
> +import org.apache.camel.spi.Policy;
> +import org.apache.camel.spi.RouteContext;
> +
> +/**
> + * @version $Revision$
> + */
> +public class PolicyPerRouteTest extends ContextTestSupport {
> +
> +    public void testPolicy() throws Exception {
> +        getMockEndpoint("mock:foo").expectedMessageCount(1);
> +        getMockEndpoint("mock:foo").expectedHeaderReceived("foo", "was wrapped");
> +        getMockEndpoint("mock:bar").expectedMessageCount(1);
> +        getMockEndpoint("mock:bar").expectedHeaderReceived("foo", "was wrapped");
> +        getMockEndpoint("mock:result").expectedMessageCount(1);
> +        getMockEndpoint("mock:result").expectedHeaderReceived("foo", "was wrapped");
> +
> +        template.sendBody("direct:start", "Hello World");
> +
> +        assertMockEndpointsSatisfied();
> +
> +        MyPolicy foo = context.getRegistry().lookup("foo", MyPolicy.class);
> +
> +        assertEquals("Should only be invoked 1 time", 1, foo.getInvoked());
> +    }
> +
> +    @Override
> +    protected JndiRegistry createRegistry() throws Exception {
> +        JndiRegistry jndi = super.createRegistry();
> +        jndi.bind("foo", new MyPolicy("foo"));
> +        return jndi;
> +    }
> +
> +    @Override
> +    protected RouteBuilder createRouteBuilder() throws Exception {
> +        return new RouteBuilder() {
> +            @Override
> +            public void configure() throws Exception {
> +                // START SNIPPET: e1
> +                from("direct:start")
> +                    // wraps the entire route in the same policy
> +                    .policy("foo")
> +                        .to("mock:foo")
> +                        .to("mock:bar")
> +                        .to("mock:result");
> +                // END SNIPPET: e1
> +            }
> +        };
> +    }
> +
> +    public static class MyPolicy implements Policy {
> +
> +        private final String name;
> +        private int invoked;
> +
> +        public MyPolicy(String name) {
> +            this.name = name;
> +        }
> +
> +        public Processor wrap(RouteContext routeContext, final Processor processor)
{
> +            return new Processor() {
> +                public void process(Exchange exchange) throws Exception {
> +                    invoked++;
> +
> +                    exchange.getIn().setHeader(name, "was wrapped");
> +                    // let the original processor continue routing
> +                    processor.process(exchange);
> +                }
> +            };
> +        }
> +
> +        public int getInvoked() {
> +            return invoked;
> +        }
> +    }
> +}
> \ No newline at end of file
> 
> Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/PolicyPerRouteTest.java
> ------------------------------------------------------------------------------
>     svn:eol-style = native
> 
> Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/PolicyPerRouteTest.java
> ------------------------------------------------------------------------------
>     svn:keywords = Rev Date
> 

Mime
View raw message