You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2008/11/10 19:09:22 UTC
svn commit: r712712 - in /activemq/camel/trunk:
camel-core/src/test/java/org/apache/camel/processor/
components/camel-spring/src/test/java/org/apache/camel/spring/processor/
components/camel-spring/src/test/resources/org/apache/camel/spring/processor/
Author: janstey
Date: Mon Nov 10 10:09:22 2008
New Revision: 712712
URL: http://svn.apache.org/viewvc?rev=712712&view=rev
Log:
CAMEL-1071 - Add test case for normalizer EIP
Added:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MyNormalizer.java (with props)
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/NormalizerTest.java (with props)
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringNormalizerTest.java (with props)
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/normalizer.xml (with props)
Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MyNormalizer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MyNormalizer.java?rev=712712&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MyNormalizer.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MyNormalizer.java Mon Nov 10 10:09:22 2008
@@ -0,0 +1,37 @@
+/**
+ * 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.Exchange;
+import org.apache.camel.language.XPath;
+
+// START SNIPPET: example
+public class MyNormalizer {
+ public void employeeToPerson(Exchange exchange, @XPath("/employee/name/text()") String name) {
+ exchange.getOut().setBody(createPerson(name));
+ }
+
+ public void customerToPerson(Exchange exchange, @XPath("/customer/@name") String name) {
+ exchange.getOut().setBody(createPerson(name));
+ }
+
+ private String createPerson(String name) {
+ return "<person name=\"" + name + "\"/>";
+ }
+}
+// END SNIPPET: example
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MyNormalizer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/NormalizerTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/NormalizerTest.java?rev=712712&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/NormalizerTest.java (added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/NormalizerTest.java Mon Nov 10 10:09:22 2008
@@ -0,0 +1,82 @@
+/**
+ * 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 javax.naming.Context;
+
+import org.apache.camel.Body;
+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.component.mock.MockEndpoint;
+import org.apache.camel.language.XPath;
+import org.apache.camel.util.jndi.JndiContext;
+import static org.apache.camel.component.mock.MockEndpoint.expectsMessageCount;
+
+public class NormalizerTest extends ContextTestSupport {
+ protected MockEndpoint result;
+ protected MyNormalizer myNormalizer = new MyNormalizer();
+
+ public void testSendToFirstWhen() throws Exception {
+ String employeeBody1 = "<employee><name>Jon</name></employee>";
+ String employeeBody2 = "<employee><name>Hadrian</name></employee>";
+ String employeeBody3 = "<employee><name>Claus</name></employee>";
+ String customerBody = "<customer name=\"James\"/>";
+
+ // expect only one person named Jon
+ result.expectedMessageCount(1);
+ result.expectedBodiesReceived("<person name=\"Jon\"/>");
+
+ template.sendBody("direct:start", employeeBody1);
+ template.sendBody("direct:start", employeeBody2);
+ template.sendBody("direct:start", employeeBody3);
+ template.sendBody("direct:start", customerBody);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ result = getMockEndpoint("mock:result");
+ }
+
+ @Override
+ protected Context createJndiContext() throws Exception {
+ JndiContext answer = new JndiContext();
+ answer.bind("normalizer", myNormalizer);
+ return answer;
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ // START SNIPPET: example
+ // before we can filter, we need to normalize the incoming messages
+ from("direct:start").choice()
+ .when().xpath("/employee").to("bean:normalizer?method=employeeToPerson").to("seda:queue")
+ .when().xpath("/customer").to("bean:normalizer?method=customerToPerson").to("seda:queue");
+
+ // filter the normalized messages
+ from("seda:queue").filter().xpath("/person[@name='Jon']").to("mock:result");
+ // END SNIPPET: example
+ }
+ };
+ }
+}
Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/NormalizerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringNormalizerTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringNormalizerTest.java?rev=712712&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringNormalizerTest.java (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringNormalizerTest.java Mon Nov 10 10:09:22 2008
@@ -0,0 +1,28 @@
+/**
+ * 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.processor;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.processor.NormalizerTest;
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringNormalizerTest extends NormalizerTest {
+ protected CamelContext createCamelContext() throws Exception {
+ return createSpringCamelContext(this, "org/apache/camel/spring/processor/normalizer.xml");
+ }
+}
Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringNormalizerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/normalizer.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/normalizer.xml?rev=712712&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/normalizer.xml (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/normalizer.xml Mon Nov 10 10:09:22 2008
@@ -0,0 +1,54 @@
+<?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.5.xsd
+ http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+ ">
+
+ <!-- START SNIPPET: example -->
+ <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <choice>
+ <when>
+ <xpath>/employee</xpath>
+ <to uri="bean:normalizer?method=employeeToPerson"/>
+ <to uri="seda:queue"/>
+ </when>
+ <when>
+ <xpath>/customer</xpath>
+ <to uri="bean:normalizer?method=customerToPerson"/>
+ <to uri="seda:queue"/>
+ </when>
+ </choice>
+ </route>
+ <route>
+ <from uri="seda:queue"/>
+ <filter>
+ <xpath>/person[@name='Jon']</xpath>
+ <to uri="mock:result"/>
+ </filter>
+ </route>
+ </camelContext>
+
+ <bean id="normalizer" class="org.apache.camel.processor.MyNormalizer"/>
+ <!-- END SNIPPET: example -->
+
+</beans>
Propchange: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/normalizer.xml
------------------------------------------------------------------------------
svn:eol-style = native