activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r533971 - in /activemq/camel/trunk/camel-spring/src/test: java/org/apache/camel/spring/CustomProcessorWithNamespacesTest.java java/org/apache/camel/spring/example/MyProcessor.java resources/org/apache/camel/spring/routingUsingProcessor.xml
Date Tue, 01 May 2007 08:51:30 GMT
Author: jstrachan
Date: Tue May  1 01:51:29 2007
New Revision: 533971

URL: http://svn.apache.org/viewvc?view=rev&rev=533971
Log:
added a test case demonstrating a route with a custom processor

Added:
    activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/CustomProcessorWithNamespacesTest.java
  (with props)
    activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/example/MyProcessor.java
  (with props)
    activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingProcessor.xml
  (with props)

Added: activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/CustomProcessorWithNamespacesTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/CustomProcessorWithNamespacesTest.java?view=auto&rev=533971
==============================================================================
--- activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/CustomProcessorWithNamespacesTest.java
(added)
+++ activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/CustomProcessorWithNamespacesTest.java
Tue May  1 01:51:29 2007
@@ -0,0 +1,81 @@
+/**
+ *
+ * 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;
+
+import org.apache.camel.TestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Message;
+import org.apache.camel.Route;
+import org.apache.camel.spring.example.MyProcessor;
+import org.apache.camel.util.CamelClient;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.util.List;
+
+/**
+ * @version $Revision: 521586 $
+ */
+public class CustomProcessorWithNamespacesTest extends TestSupport {
+    protected String body = "<hello>world!</hello>";
+    protected AbstractXmlApplicationContext applicationContext;
+
+    public void testXMLRouteLoading() throws Exception {
+        applicationContext = createApplicationContext();
+
+        SpringCamelContext context = (SpringCamelContext) applicationContext.getBean("camel");
+        assertValidContext(context);
+
+        // now lets send a message
+        CamelClient<Exchange> client = new CamelClient<Exchange>(context);
+        client.send("direct:start", new Processor<Exchange>() {
+            public void process(Exchange exchange) {
+                Message in = exchange.getIn();
+                in.setHeader("name", "James");
+                in.setBody(body);
+            }
+        });
+
+        List list = MyProcessor.getExchanges();
+        assertEquals("Should have received a single exchange: " + list, 1, list.size());
+    }
+
+    protected void assertValidContext(SpringCamelContext context) {
+        assertNotNull("No context found!", context);
+
+        List<Route> routes = context.getRoutes();
+        assertNotNull("Should have some routes defined", routes);
+        assertEquals("Number of routes defined", 1, routes.size());
+        Route route = routes.get(0);
+        log.debug("Found route: " + route);
+    }
+
+    protected ClassPathXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/spring/routingUsingProcessor.xml");
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        if (applicationContext != null) {
+            applicationContext.destroy();
+        }
+    }
+}

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

Added: activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/example/MyProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/example/MyProcessor.java?view=auto&rev=533971
==============================================================================
--- activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/example/MyProcessor.java
(added)
+++ activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/example/MyProcessor.java
Tue May  1 01:51:29 2007
@@ -0,0 +1,50 @@
+/**
+ *
+ * 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.example;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class MyProcessor implements Processor<Exchange> {
+    private static List exchanges = new CopyOnWriteArrayList();
+
+    private String name = "James";
+
+    public static List getExchanges() {
+        return exchanges;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void process(Exchange exchange) {
+        exchange.getIn().setHeader("name", getName());
+        exchanges.add(exchange);
+    }
+}

Propchange: activemq/camel/trunk/camel-spring/src/test/java/org/apache/camel/spring/example/MyProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingProcessor.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingProcessor.xml?view=auto&rev=533971
==============================================================================
--- activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingProcessor.xml
(added)
+++ activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingProcessor.xml
Tue May  1 01:51:29 2007
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+       http://activemq.apache.org/camel/schema/camel-1.0.xsd http://activemq.apache.org/camel/schema/camel-1.0.xsd
+    ">
+
+  <!-- START SNIPPET: example -->
+  <bean id="camel" class="org.apache.camel.spring.CamelContextFactoryBean">
+    <property name="routeBuilder">
+	    <routeBuilder xmlns="http://activemq.apache.org/camel/schema/camel-1.0.xsd">
+	       <route>
+	         <from uri="direct:start"/>
+	         <process ref="#myProcessor"/>
+	       </route>
+	    </routeBuilder>
+    </property>
+  </bean>
+
+  <bean id="myProcessor" class="org.apache.camel.spring.example.MyProcessor"/>
+  <!-- END SNIPPET: example -->
+  
+</beans>

Propchange: activemq/camel/trunk/camel-spring/src/test/resources/org/apache/camel/spring/routingUsingProcessor.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message