camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r792166 - in /camel/trunk: camel-core/src/test/java/org/apache/camel/processor/ components/camel-spring/src/main/java/org/apache/camel/spring/spi/ components/camel-spring/src/test/java/org/apache/camel/spring/ components/camel-spring/src/te...
Date Wed, 08 Jul 2009 14:42:27 GMT
Author: davsclaus
Date: Wed Jul  8 14:42:27 2009
New Revision: 792166

URL: http://svn.apache.org/viewvc?rev=792166&view=rev
Log:
CAMEL-1811: SpringInject capable of doing constructor injection again as in 2.0m1.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliverWithExceptionAndFaultTest.java
  (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/CamelRouteBuilderTest.java
  (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/MyOtherRoute.java
  (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/MyRoute.java
  (with props)
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/routebuilder/
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/routebuilder/camelRouteBuilder.xml
      - copied, changed from r792042, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/postprocessor/camelCustomPostProcessorOnRouteBuilderTest.xml
Modified:
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringInjector.java
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/SpringTestSupport.java

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliverWithExceptionAndFaultTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliverWithExceptionAndFaultTest.java?rev=792166&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliverWithExceptionAndFaultTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliverWithExceptionAndFaultTest.java
Wed Jul  8 14:42:27 2009
@@ -0,0 +1,95 @@
+/**
+ * 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;
+
+/**
+ * @version $Revision$
+ */
+public class RedeliverWithExceptionAndFaultTest extends ContextTestSupport {
+
+    private static int counter;
+
+    public void testOk() throws Exception {
+        counter = 0;
+
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        String out = template.requestBody("direct:start", "Hello World", String.class);
+        assertEquals("Bye World", out);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testTransientAndPersistentError() throws Exception {
+        counter = 0;
+
+        getMockEndpoint("mock:result").expectedMessageCount(0);
+
+        String out = template.requestBody("direct:start", "Boom", String.class);
+        assertEquals("Persistent error", out);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testTransientAndPersistentErrorWithExchange() throws Exception {
+        counter = 0;
+
+        getMockEndpoint("mock:result").expectedMessageCount(0);
+
+        Exchange out = template.request("direct:start", new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody("Boom");
+            }
+        });
+        assertTrue("Should be failed", out.isFailed());
+        assertNull("No exception", out.getException());
+        assertEquals("Persistent error", out.getFault().getBody());
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                errorHandler(defaultErrorHandler().maximumRedeliveries(5).redeliverDelay(0));
+
+                from("direct:start")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            counter++;
+                            if (counter < 3) {
+                                throw new IllegalArgumentException("Try again");
+                            }
+
+                            if (exchange.getIn().getBody().equals("Boom")) {
+                                exchange.getFault().setBody("Persistent error");
+                            } else {
+                                exchange.getOut().setBody("Bye World");
+                            }
+                        }
+                    }).to("mock:result");
+            }
+        };
+    }
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliverWithExceptionAndFaultTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RedeliverWithExceptionAndFaultTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringInjector.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringInjector.java?rev=792166&r1=792165&r2=792166&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringInjector.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringInjector.java
Wed Jul  8 14:42:27 2009
@@ -18,6 +18,7 @@
 
 import org.apache.camel.IsSingleton;
 import org.apache.camel.spi.Injector;
+import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
 import org.springframework.context.ConfigurableApplicationContext;
 
 /**
@@ -27,13 +28,15 @@
  */
 public class SpringInjector implements Injector {
     private final ConfigurableApplicationContext applicationContext;
+    private int autowireMode = AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR;
+    private boolean dependencyCheck;
 
     public SpringInjector(ConfigurableApplicationContext applicationContext) {
         this.applicationContext = applicationContext;
     }
 
     public <T> T newInstance(Class<T> type) {
-        Object value = applicationContext.getBeanFactory().createBean(type);
+        Object value = applicationContext.getBeanFactory().createBean(type, autowireMode,
dependencyCheck);
         return type.cast(value);
     }
 
@@ -47,4 +50,19 @@
         return newInstance(type);
     }
 
+    public int getAutowireMode() {
+        return autowireMode;
+    }
+
+    public void setAutowireMode(int autowireMode) {
+        this.autowireMode = autowireMode;
+    }
+
+    public boolean isDependencyCheck() {
+        return dependencyCheck;
+    }
+
+    public void setDependencyCheck(boolean dependencyCheck) {
+        this.dependencyCheck = dependencyCheck;
+    }
 }

Modified: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/SpringTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/SpringTestSupport.java?rev=792166&r1=792165&r2=792166&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/SpringTestSupport.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/SpringTestSupport.java
Wed Jul  8 14:42:27 2009
@@ -101,7 +101,7 @@
     }
 
     /**
-     * Template method used to exclude {@link org.apache.camel.Routes} from the test time
context
+     * Template method used to exclude {@link org.apache.camel.Route} from the test time
context
      * route scanning
      *
      * @return Class[] the classes to be excluded from test time context route scanning
@@ -112,7 +112,7 @@
     }
 
     /**
-     * Template method used to exclude a {@link org.apache.camel.Routes} from the test camel
context
+     * Template method used to exclude a {@link org.apache.camel.Route} from the test camel
context
      */
     protected Class excludeRoute() {
         return null;

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/CamelRouteBuilderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/CamelRouteBuilderTest.java?rev=792166&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/CamelRouteBuilderTest.java
(added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/CamelRouteBuilderTest.java
Wed Jul  8 14:42:27 2009
@@ -0,0 +1,42 @@
+/**
+ * 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.spring.routebuilder;
+
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision$
+ */
+public class CamelRouteBuilderTest extends SpringTestSupport {
+
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/spring/routebuilder/camelRouteBuilder.xml");
+    }
+
+    public void testShouldProcessAnnotatedFields() throws Exception {
+        getMockEndpoint("mock:a").expectedMessageCount(1);
+        getMockEndpoint("mock:b").expectedMessageCount(1);
+
+        template.sendBody("direct:a", "Hello World");
+        template.sendBody("direct:b", "Bye World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+}

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/CamelRouteBuilderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/CamelRouteBuilderTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/MyOtherRoute.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/MyOtherRoute.java?rev=792166&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/MyOtherRoute.java
(added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/MyOtherRoute.java
Wed Jul  8 14:42:27 2009
@@ -0,0 +1,41 @@
+/**
+ * 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.spring.routebuilder;
+
+import org.apache.camel.spring.SpringRouteBuilder;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.CamelContext;
+
+/**
+ * @version $Revision$
+ */
+public class MyOtherRoute extends SpringRouteBuilder implements CamelContextAware {
+
+    private CamelContext ctx;
+
+    public void configure() throws Exception {
+        System.out.println(getContext());
+        from("direct:b").to("mock:b");
+    }
+
+    public void setCamelContext(CamelContext context) {
+        this.ctx = context;
+        if (!"foo".equals(context.getName())) {
+            throw new IllegalArgumentException("Should be named foo");
+        }
+    }
+}

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/MyOtherRoute.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/MyOtherRoute.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/MyRoute.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/MyRoute.java?rev=792166&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/MyRoute.java
(added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/MyRoute.java
Wed Jul  8 14:42:27 2009
@@ -0,0 +1,39 @@
+/**
+ * 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.spring.routebuilder;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spring.SpringRouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class MyRoute extends SpringRouteBuilder {
+
+    private CamelContext ctx;
+
+    public MyRoute(CamelContext context) {
+        this.ctx = context;
+        if (!"foo".equals(context.getName())) {
+            throw new IllegalArgumentException("Should be named foo");
+        }
+    }
+
+    public void configure() throws Exception {
+        from("direct:a").to("mock:a");
+    }
+}

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/MyRoute.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/routebuilder/MyRoute.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/routebuilder/camelRouteBuilder.xml
(from r792042, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/postprocessor/camelCustomPostProcessorOnRouteBuilderTest.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/routebuilder/camelRouteBuilder.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/routebuilder/camelRouteBuilder.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/postprocessor/camelCustomPostProcessorOnRouteBuilderTest.xml&r1=792042&r2=792166&rev=792166&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/postprocessor/camelCustomPostProcessorOnRouteBuilderTest.xml
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/routebuilder/camelRouteBuilder.xml
Wed Jul  8 14:42:27 2009
@@ -23,10 +23,8 @@
             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
             http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
 
-    <context:component-scan base-package="org.apache.camel.spring.postprocessor"/>
-
-    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
-        <package>org.apache.camel.spring.postprocessor</package>
+    <camelContext id="foo" xmlns="http://camel.apache.org/schema/spring">
+        <package>org.apache.camel.spring.routebuilder</package>
     </camelContext>
 
 </beans>
\ No newline at end of file



Mime
View raw message