activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r530436 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/builder/FromBuilder.java test/java/org/apache/camel/builder/InterceptorBuilderTest.java test/java/org/apache/camel/component/pojo/PojoRouteTest.java
Date Thu, 19 Apr 2007 14:51:21 GMT
Author: chirino
Date: Thu Apr 19 07:51:19 2007
New Revision: 530436

URL: http://svn.apache.org/viewvc?view=rev&rev=530436
Log:
- Made the fluent api .intercept(..) method call easier to use. No need to call the subsequent
.target() now.
- added a InterceptorBuilderTest.java that checks that interceptors are called in the right
order.

Added:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/InterceptorBuilderTest.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java?view=diff&rev=530436&r1=530435&r2=530436
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/FromBuilder.java
Thu Apr 19 07:51:19 2007
@@ -241,11 +241,11 @@
     }
 
     @Fluent
-    public InterceptorBuilder<E> intercept(@FluentArg("interceptor")InterceptorProcessor<E>
interceptor) {
+    public FromBuilder<E> intercept(@FluentArg("interceptor")InterceptorProcessor<E>
interceptor) {
         InterceptorBuilder<E> answer = new InterceptorBuilder<E>(this);
         answer.add(interceptor);
         addProcessBuilder(answer);
-        return answer;
+        return answer.target();
     }
 
     // Properties

Added: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/InterceptorBuilderTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/InterceptorBuilderTest.java?view=auto&rev=530436
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/InterceptorBuilderTest.java
(added)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/InterceptorBuilderTest.java
Thu Apr 19 07:51:19 2007
@@ -0,0 +1,90 @@
+/*
+ * 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.builder;
+
+import java.util.ArrayList;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Producer;
+import org.apache.camel.TestSupport;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.processor.InterceptorProcessor;
+
+/**
+ * @version $Revision: 530102 $
+ */
+public class InterceptorBuilderTest extends TestSupport {
+
+
+    /**
+     * Validates that interceptors are executed in the right order.
+     * @throws Exception
+     */
+    public void testRouteWithInterceptor() throws Exception {
+
+        CamelContext container = new DefaultCamelContext();
+        final ArrayList<String> order = new ArrayList<String>();
+
+        final InterceptorProcessor<Exchange> interceptor1 = new InterceptorProcessor<Exchange>()
{
+        	@Override
+        	public void process(Exchange exchange) {
+        		order.add("START:1");
+        		super.process(exchange);
+        		order.add("END:1");
+        	}
+        };
+        final InterceptorProcessor<Exchange> interceptor2 = new InterceptorProcessor<Exchange>()
{
+        	@Override
+        	public void process(Exchange exchange) {
+        		order.add("START:2");
+        		super.process(exchange);
+        		order.add("END:2");
+        	}
+        };
+
+        RouteBuilder<Exchange> builder = new RouteBuilder<Exchange>() {
+            public void configure() {
+                from("direct:a")
+                        .intercept()
+                        .add(interceptor1)
+                        .add(interceptor2)
+                        .target().to("direct:d");
+            }
+        };        
+        container.addRoutes(builder);
+        container.start();
+        
+        Endpoint<Exchange> endpoint = container.resolveEndpoint("direct:a");
+        Exchange exchange = endpoint.createExchange();
+        Producer<Exchange> producer = endpoint.createProducer();
+        producer.process(exchange);
+        
+        
+        ArrayList<String> expected = new ArrayList<String>();
+        expected.add("START:1");
+        expected.add("START:2");
+        expected.add("END:2");
+        expected.add("END:1");
+        
+        System.out.println("Interceptor invocation order:"+order);
+        assertEquals(expected, order);
+        
+    }
+
+}

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java?view=diff&rev=530436&r1=530435&r2=530436
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/pojo/PojoRouteTest.java
Thu Apr 19 07:51:19 2007
@@ -50,7 +50,7 @@
         // lets add some routes
         container.addRoutes(new RouteBuilder() {
             public void configure() {
-                from("pojo:hello").intercept(tracingInterceptor).target().to("pojo:bye");
+                from("pojo:hello").intercept(tracingInterceptor).to("pojo:bye");
             }
         });
 



Mime
View raw message