Author: hadrian
Date: Wed Sep 24 09:56:39 2008
New Revision: 698652

URL: http://svn.apache.org/viewvc?rev=698652&view=rev
Log:
CAMEL-325.  Added Spring test.  Added logging for iteration count.

Added:
    
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringLoopTest.java
    
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/loop.xml
Modified:
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/LoopProcessor.java
    
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/LoopTest.java

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/LoopProcessor.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/LoopProcessor.java?rev=698652&r1=698651&r2=698652&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/LoopProcessor.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/LoopProcessor.java
 Wed Sep 24 09:56:39 2008
@@ -20,6 +20,8 @@
 import org.apache.camel.Expression;
 import org.apache.camel.Processor;
 import org.apache.camel.util.ExchangeHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * The processor which sends messages in a loop.
@@ -27,6 +29,8 @@
  * @version $Revision: $
  */
 public class LoopProcessor extends DelegateProcessor {
+    private static final Log LOG = LogFactory.getLog(LoopProcessor.class);
+    
     private Expression<Exchange> expression;
 
     public LoopProcessor(Expression<Exchange> expression, Processor processor) 
{
@@ -41,7 +45,8 @@
         String text = ExchangeHelper.convertToType(exchange, String.class, 
expression.evaluate(exchange));
         Integer value = ExchangeHelper.convertToType(exchange, Integer.class, 
text);
         int count = value != null ? value.intValue() : 0;
-        while (count-- > 0) {
+        for (int i = 0; i < count; i++) {
+            LOG.debug("LoopProcessor: iteration #" + i);
             super.process(exchange);
         }
     }

Modified: 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/LoopTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/LoopTest.java?rev=698652&r1=698651&r2=698652&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/LoopTest.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/LoopTest.java
 Wed Sep 24 09:56:39 2008
@@ -38,6 +38,13 @@
         performLoopTest("direct:c", 4);
     }
 
+    public void testLoopAsBlock() throws Exception {
+       MockEndpoint lastEndpoint = resolveMandatoryEndpoint("mock:last", 
MockEndpoint.class);
+        lastEndpoint.expectedMessageCount(1);
+        performLoopTest("direct:d", 2);
+        lastEndpoint.assertIsSatisfied();
+    }
+
     private void performLoopTest(String endpointUri, int expectedIterations) 
throws InterruptedException {
         resultEndpoint.expectedMessageCount(expectedIterations);
         template.sendBodyAndHeader(endpointUri, "<hello 
times='4'>world!</hello>", "loop", "6");
@@ -64,6 +71,9 @@
                 // START SNIPPET: ex3
                 
from("direct:c").loop().xpath("/hello/@times").to("mock:result");
                 // END SNIPPET: ex3
+                // START SNIPPET: ex4
+                
from("direct:d").loop(2).to("mock:result").end().to("mock:last");
+                // END SNIPPET: ex4
             }
         };
     }

Added: 
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringLoopTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringLoopTest.java?rev=698652&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringLoopTest.java
 (added)
+++ 
activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringLoopTest.java
 Wed Sep 24 09:56:39 2008
@@ -0,0 +1,32 @@
+/**
+ * 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 static 
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.processor.LoopTest;
+
+/**
+ * @version $Revision:  $
+ */
+public class SpringLoopTest extends LoopTest {
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        return createSpringCamelContext(this, 
"org/apache/camel/spring/processor/loop.xml");
+    }
+}

Added: 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/loop.xml
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/loop.xml?rev=698652&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/loop.xml
 (added)
+++ 
activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/loop.xml
 Wed Sep 24 09:56:39 2008
@@ -0,0 +1,67 @@
+<?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
+    ">
+
+  <camelContext id="camel" 
xmlns="http://activemq.apache.org/camel/schema/spring";>
+    <!-- START SNIPPET: ex -->
+    <route>
+      <from uri="direct:a"/>
+      <loop>
+        <constant>8</constant>
+        <to uri="mock:result"/>
+      </loop>
+    </route>
+    <!-- END SNIPPET: ex -->
+ 
+    <!-- START SNIPPET: ex2 -->
+    <route>
+      <from uri="direct:b"/>
+      <loop>
+        <header>loop</header>
+        <to uri="mock:result"/>
+      </loop>
+    </route>
+    <!-- START SNIPPET: ex2 -->
+ 
+    <!-- START SNIPPET: ex3 -->        
+    <route>
+      <from uri="direct:c"/>
+      <loop>
+        <xpath>/hello/@times</xpath>
+        <to uri="mock:result"/>
+      </loop>
+    </route>
+    <!-- START SNIPPET: ex3 -->    
+
+    <!-- START SNIPPET: ex4 -->        
+    <route>
+      <from uri="direct:d"/>
+      <loop>
+        <constant>2</constant>
+        <to uri="mock:result"/>
+      </loop>
+      <to uri="mock:last"/>
+    </route>
+    <!-- START SNIPPET: ex4 -->    
+  </camelContext>
+</beans>


Reply via email to