camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r758208 - in /camel/trunk/components/camel-spring-javaconfig/src: main/java/org/apache/camel/spring/javaconfig/Main.java test/java/org/apache/camel/spring/javaconfig/ContextConfig.java test/java/org/apache/camel/spring/javaconfig/MainTest.java
Date Wed, 25 Mar 2009 10:41:07 GMT
Author: ningjiang
Date: Wed Mar 25 10:41:04 2009
New Revision: 758208

URL: http://svn.apache.org/viewvc?rev=758208&view=rev
Log:
CAMEL-1485 created a Main class for camel-spring-javaconfig

Added:
    camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/Main.java
  (with props)
    camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/ContextConfig.java
  (with props)
    camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/MainTest.java
  (with props)

Added: camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/Main.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/Main.java?rev=758208&view=auto
==============================================================================
--- camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/Main.java
(added)
+++ camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/Main.java
Wed Mar 25 10:41:04 2009
@@ -0,0 +1,107 @@
+/**
+ * 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;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.camel.util.ObjectHelper;
+import org.springframework.config.java.context.JavaConfigApplicationContext;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.AbstractApplicationContext;
+
+/**
+ * The Main class which takes the spring java config parameter
+ */
+public class Main extends org.apache.camel.spring.Main {
+    
+    private String basedPackages = "org.apache.camel.spring.javaconfig";
+    
+    private String configClassesString;
+    
+    public Main() {
+
+        addOption(new ParameterOption("bp", "basedPackages",
+            "Sets the based packages of spring java config ApplicationContext", "basedPackages")
{
+            protected void doProcess(String arg, String parameter, LinkedList<String>
remainingArgs) {
+                setBasedPackages(parameter);
+            }
+        });
+
+        addOption(new ParameterOption("cc", "configClasses",
+            "Sets the config Class of spring java config ApplicationContext", "configureClasses")
{
+            protected void doProcess(String arg, String parameter, LinkedList<String>
remainingArgs) {
+                setConfigClassesString(parameter);
+            }
+        });
+
+    }
+    
+    public void setBasedPackages(String config) {
+        basedPackages = config;
+    }
+    
+    public String getBasedPackages() {
+        return basedPackages;
+    }
+    
+    public void setConfigClassesString(String config) {
+        configClassesString = config;
+    }
+    
+    public String getConfigClassesString() {
+        return configClassesString;
+    }
+    
+    private Class<?>[] getConfigClasses(String configureClasses) {
+        List<Class<?>> answer = new ArrayList<Class<?>>();
+        String[] classes =  configureClasses.split(";");
+        for (String className :  classes) {
+            Class<?> configClass = ObjectHelper.loadClass(className);
+            if (configClass != null) {
+                answer.add(configClass);
+            } 
+        }
+        return answer.toArray(new Class<?>[answer.size()]);
+    }
+        
+    protected AbstractApplicationContext createDefaultApplicationContext() {
+        ApplicationContext parentContext = getParentApplicationContext();
+        JavaConfigApplicationContext jcApplicationContext = new JavaConfigApplicationContext();
+        if (parentContext != null) {
+            jcApplicationContext.setParent(parentContext);
+        }
+        if (getConfigClassesString() != null) {
+            Class<?>[] configClasses = getConfigClasses(getConfigClassesString());
+            for (Class<?> cls : configClasses) {
+                jcApplicationContext.addConfigClass(cls);
+            }
+        }
+        if (getBasedPackages() != null) {
+            String[] basePackages = getBasedPackages().split(";");
+            for (String basePackage : basePackages) {
+                jcApplicationContext.addBasePackage(basePackage);
+            }
+        }
+        jcApplicationContext.refresh();
+        return jcApplicationContext;
+        
+    }
+
+}

Propchange: camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/Main.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring-javaconfig/src/main/java/org/apache/camel/spring/javaconfig/Main.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/ContextConfig.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/ContextConfig.java?rev=758208&view=auto
==============================================================================
--- camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/ContextConfig.java
(added)
+++ camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/ContextConfig.java
Wed Mar 25 10:41:04 2009
@@ -0,0 +1,33 @@
+/**
+ * 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;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.springframework.config.java.annotation.Bean;
+import org.springframework.config.java.annotation.Configuration;
+
+@Configuration
+public 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");
+            }
+        };
+    }
+}

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

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

Added: camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/MainTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/MainTest.java?rev=758208&view=auto
==============================================================================
--- camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/MainTest.java
(added)
+++ camel/trunk/components/camel-spring-javaconfig/src/test/java/org/apache/camel/spring/javaconfig/MainTest.java
Wed Mar 25 10:41:04 2009
@@ -0,0 +1,65 @@
+/**
+ * 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;
+
+import junit.framework.TestCase;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.SpringCamelContext;
+import org.springframework.context.ApplicationContext;
+
+public class MainTest extends TestCase {
+    public void  testOptions() throws Exception {
+        CamelContext context = createCamelContext(new String[]{"-bp", "org.apache.camel.spring.javaconfig"});
+        runTests(context);
+        
+        context = createCamelContext(new String[] {"-cc", "org.apache.camel.spring.javaconfig.ContextConfig"});
+        runTests(context);
+    }
+        
+    private CamelContext createCamelContext(String[] options) throws Exception {
+        Main main = new Main();        
+        main.parseArguments(options);
+        ApplicationContext applicationContext = main.createDefaultApplicationContext();
+        CamelContext  context = SpringCamelContext.springCamelContext(applicationContext);
+        return context;        
+    }
+       
+    
+    private void runTests(CamelContext context) throws Exception {
+        MockEndpoint resultEndpoint = (MockEndpoint) context.getEndpoint("mock:result");
+        ProducerTemplate template = context.createProducerTemplate();
+        
+        String expectedBody = "<matched/>";
+
+        resultEndpoint.expectedBodiesReceived(expectedBody);
+
+        template.sendBodyAndHeader("direct:start", expectedBody, "foo", "bar");
+
+        resultEndpoint.assertIsSatisfied();
+        
+        resultEndpoint.reset();
+        
+        resultEndpoint.expectedMessageCount(0);
+
+        template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo", "notMatchedHeaderValue");
+
+        resultEndpoint.assertIsSatisfied();
+    }
+
+}

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

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



Mime
View raw message