You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2008/12/02 19:41:40 UTC

svn commit: r722561 - in /activemq/camel/trunk/components/camel-spring-javaconfig/src: main/java/org/apache/camel/spring/javaconfig/ test/java/org/apache/camel/spring/javaconfig/examples/ test/java/org/apache/camel/spring/javaconfig/patterns/ test/java...

Author: jstrachan
Date: Tue Dec  2 10:41:40 2008
New Revision: 722561

URL: http://svn.apache.org/viewvc?rev=722561&view=rev
Log:
added mostly working version of Spring JavaConfig - though it requires the current snapshot (or 1.0.0.M5 when its out) due to http://jira.springframework.org/browse/SJC-248

Added:
    activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/
      - copied from r722552, activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/examples/
    activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/package-info.java   (with props)
    activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/JavaConfigWithNestedConfigClassTest.java   (with props)
    activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/package-info.java   (with props)
Removed:
    activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/examples/
    activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterConfig.java
Modified:
    activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/CamelConfiguration.java
    activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java
    activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/JavaConfigWithPostProcessorTest.java

Modified: activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/CamelConfiguration.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/CamelConfiguration.java?rev=722561&r1=722560&r2=722561&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/CamelConfiguration.java (original)
+++ activemq/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/CamelConfiguration.java Tue Dec  2 10:41:40 2008
@@ -18,6 +18,7 @@
 package org.apache.camel.spring.javaconfig;
 
 import org.apache.camel.Routes;
+import org.apache.camel.CamelContext;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.spring.CamelBeanPostProcessor;
 import org.apache.camel.spring.SpringCamelContext;
@@ -25,6 +26,7 @@
 import org.springframework.beans.factory.BeanInitializationException;
 import org.springframework.config.java.annotation.Bean;
 import org.springframework.config.java.annotation.Configuration;
+import org.springframework.config.java.support.ConfigurationSupport;
 
 import java.util.List;
 
@@ -36,11 +38,18 @@
  * @version $Revision: 1.1 $
  */
 @Configuration
-public abstract class CamelConfiguration    {
+public abstract class CamelConfiguration extends ConfigurationSupport {
 
     @Bean
     public CamelBeanPostProcessor camelBeanPostProcessor() throws Exception {
-        return new CamelBeanPostProcessor(){
+        CamelBeanPostProcessor answer = new CamelBeanPostProcessor();
+
+        CamelContext camelContext = getBean(CamelContext.class);
+        // lets lookup a bean
+        answer.setCamelContext((SpringCamelContext) camelContext);
+        return answer;
+/*
+        {
             @Override
             public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
                 try {
@@ -57,13 +66,14 @@
                 }
             }
         };
+*/
     }
 
     /**
      * Returns the CamelContext
      */
     @Bean
-    public SpringCamelContext camelContext() throws Exception {
+    public CamelContext camelContext() throws Exception {
         SpringCamelContext camelContext = new SpringCamelContext();
         List<RouteBuilder> routes = routes();
         for (Routes route : routes) {
@@ -76,7 +86,7 @@
     /**
      * Returns the list of routes to use in this configuration
      */
-    @Bean
+    //@Bean
     public abstract List<RouteBuilder> routes();
 
 }

Modified: activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java?rev=722561&r1=722552&r2=722561&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java (original)
+++ activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/FilterTest.java Tue Dec  2 10:41:40 2008
@@ -15,41 +15,38 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.spring.javaconfig.examples;
+package org.apache.camel.spring.javaconfig.patterns;
 
 import org.apache.camel.EndpointInject;
 import org.apache.camel.Produce;
 import org.apache.camel.ProducerTemplate;
-import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
+import org.springframework.config.java.annotation.Bean;
+import org.springframework.config.java.annotation.Configuration;
 import org.springframework.config.java.test.JavaConfigContextLoader;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests;
-import org.springframework.beans.factory.annotation.Autowired;
 
 /**
  * @version $Revision: 1.1 $
  */
-@ContextConfiguration(locations = "org.apache.camel.spring.javaconfig.examples.FilterConfig", loader = JavaConfigContextLoader.class)
+@ContextConfiguration(locations = "org.apache.camel.spring.javaconfig.patterns.FilterTest$ContextConfig", loader = JavaConfigContextLoader.class)
 public class FilterTest extends AbstractJUnit38SpringContextTests {
 
-    @Autowired
-    protected CamelContext camelContext;
+    @EndpointInject(uri = "mock:result")
+    protected MockEndpoint resultEndpoint;
 
     @Produce(uri = "direct:start")
     protected ProducerTemplate template;
 
-    @EndpointInject(uri = "mock:result")
-    protected MockEndpoint resultEndpoint;
-
     public void testSendMatchingMessage() throws Exception {
-        assertNotNull("No injection for camelContext", camelContext);
-        assertNotNull("No Camel injection for template", template);
-        assertNotNull("No Camel injection for resultEndpoint", resultEndpoint);
+        String expectedBody = "<matched/>";
 
-        resultEndpoint.expectedMessageCount(1);
+        resultEndpoint.expectedBodiesReceived(expectedBody);
 
-        template.sendBodyAndHeader("direct:start", "<matched/>", "foo", "bar");
+        template.sendBodyAndHeader(expectedBody, "foo", "bar");
 
         resultEndpoint.assertIsSatisfied();
     }
@@ -57,10 +54,22 @@
     public void testSendNotMatchingMessage() throws Exception {
         resultEndpoint.expectedMessageCount(0);
 
-        template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo", "notMatchedHeaderValue");
+        template.sendBodyAndHeader("<notMatched/>", "foo", "notMatchedHeaderValue");
 
         resultEndpoint.assertIsSatisfied();
     }
 
 
+    @Configuration
+    public static class ContextConfig extends SingleRouteCamelConfiguration {
+        @Bean
+        public RouteBuilder route() {
+            return new RouteBuilder() {
+                public void configure() {
+                    from("direct:start").filter(header("foo").isEqualTo("bar")).to("mock:result");
+                }
+            };
+        }
+    }
+
 }

Added: activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/package-info.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/package-info.java?rev=722561&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/package-info.java (added)
+++ activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/package-info.java Tue Dec  2 10:41:40 2008
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+
+/**
+ * Example pattern test cases using Spring Test with JavaConfig
+ */
+package org.apache.camel.spring.javaconfig.patterns;
+

Propchange: activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/patterns/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/JavaConfigWithNestedConfigClassTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/JavaConfigWithNestedConfigClassTest.java?rev=722561&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/JavaConfigWithNestedConfigClassTest.java (added)
+++ activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/JavaConfigWithNestedConfigClassTest.java Tue Dec  2 10:41:40 2008
@@ -0,0 +1,55 @@
+/**
+ *
+ * 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.javaconfig.test;
+
+import org.springframework.config.java.annotation.Bean;
+import org.springframework.config.java.annotation.Configuration;
+import org.springframework.config.java.plugin.context.AnnotationDrivenConfig;
+import org.springframework.config.java.test.JavaConfigContextLoader;
+import org.springframework.stereotype.Component;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+@ContextConfiguration(locations = "org.apache.camel.spring.javaconfig.test.JavaConfigWithNestedConfigClassTest$ContextConfig", loader = JavaConfigContextLoader.class)
+@AnnotationDrivenConfig
+@Component
+public class JavaConfigWithNestedConfigClassTest extends AbstractJUnit38SpringContextTests implements Cheese {
+    private boolean doCheeseCalled;
+
+    public void testPostProcessorInjectsMe() throws Exception {
+        assertEquals("doCheese() should be called", true, doCheeseCalled);
+
+    }
+
+    public void doCheese() {
+        System.out.println("doCheese called!");
+        doCheeseCalled = true;
+    }
+
+    @Configuration
+    public static class ContextConfig {
+        @Bean
+        public MyPostProcessor myPostProcessor() {
+            return new MyPostProcessor();
+        }
+    }
+
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/JavaConfigWithNestedConfigClassTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/JavaConfigWithPostProcessorTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/JavaConfigWithPostProcessorTest.java?rev=722561&r1=722560&r2=722561&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/JavaConfigWithPostProcessorTest.java (original)
+++ activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/JavaConfigWithPostProcessorTest.java Tue Dec  2 10:41:40 2008
@@ -21,12 +21,14 @@
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.config.java.test.JavaConfigContextLoader;
 import org.springframework.config.java.plugin.context.AnnotationDrivenConfig;
+import org.springframework.stereotype.Component;
 
 /**
  * @version $Revision: 1.1 $
  */
 @ContextConfiguration(locations = "org.apache.camel.spring.javaconfig.test.MyConfig", loader = JavaConfigContextLoader.class)
 @AnnotationDrivenConfig
+@Component
 public class JavaConfigWithPostProcessorTest extends AbstractJUnit38SpringContextTests implements Cheese {
     private boolean doCheeseCalled;
 

Added: activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/package-info.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/package-info.java?rev=722561&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/package-info.java (added)
+++ activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/package-info.java Tue Dec  2 10:41:40 2008
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+
+/**
+ * Tests the behaviour of Spring JavaConfig with Spring-Test
+ */
+package org.apache.camel.spring.javaconfig.test;
+

Propchange: activemq/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/test/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native