You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2011/04/24 15:01:29 UTC

svn commit: r1096322 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/model/ components/camel-spring/src/test/java/org/apache/camel/spring/processor/ components/camel-spring/src/test/resources/org/apache/camel/spring/processor/

Author: davsclaus
Date: Sun Apr 24 13:01:29 2011
New Revision: 1096322

URL: http://svn.apache.org/viewvc?rev=1096322&view=rev
Log:
CAMEL-3896: Filter EIP now validates it has child output on startup. That helps in XML DSL where end user may mis configure it.

Added:
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringFilterNoChildTest.java   (with props)
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/filterNoChild.xml   (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/FilterDefinition.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/FilterDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/FilterDefinition.java?rev=1096322&r1=1096321&r2=1096322&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/FilterDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/FilterDefinition.java Sun Apr 24 13:01:29 2011
@@ -21,7 +21,7 @@ import javax.xml.bind.annotation.XmlAcce
 import javax.xml.bind.annotation.XmlRootElement;
 
 import org.apache.camel.Predicate;
-import org.apache.camel.builder.ExpressionClause;
+import org.apache.camel.Processor;
 import org.apache.camel.model.language.ExpressionDefinition;
 import org.apache.camel.processor.FilterProcessor;
 import org.apache.camel.spi.RouteContext;
@@ -62,13 +62,11 @@ public class FilterDefinition extends Ex
         return createFilterProcessor(routeContext);
     }
     
-    // Fluent API
-    //-------------------------------------------------------------------------
-    /**
-     * Set the expression that this FilterType will use
-     * @return the builder
-     */
-    public ExpressionClause<? extends FilterDefinition> expression() {
-        return ExpressionClause.createAndSetExpression(this);
+    @Override
+    protected FilterProcessor createFilterProcessor(RouteContext routeContext) throws Exception {
+        // filter EIP should have child outputs
+        Processor childProcessor = this.createChildProcessor(routeContext, true);
+        return new FilterProcessor(getExpression().createPredicate(routeContext), childProcessor);
     }
+
 }

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringFilterNoChildTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringFilterNoChildTest.java?rev=1096322&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringFilterNoChildTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringFilterNoChildTest.java Sun Apr 24 13:01:29 2011
@@ -0,0 +1,53 @@
+/**
+ * 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.FailedToCreateRouteException;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version 
+ */
+public class SpringFilterNoChildTest extends SpringTestSupport {
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        try {
+            ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("org/apache/camel/spring/processor/filterNoChild.xml");
+            fail("Should thrown an exception");
+        } catch (RuntimeCamelException e) {
+            FailedToCreateRouteException cause = assertIsInstanceOf(FailedToCreateRouteException.class, e.getCause());
+            IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, cause.getCause());
+            assertEquals("Definition has no children on Filter[xpath{$foo = 'bar'} -> []]", iae.getMessage());
+        }
+        return null;
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        // must override as there is no valid spring xml file
+        createApplicationContext();
+    }
+
+    public void testFilterNoOutput() throws Exception {
+        // noop
+    }
+
+}

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

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

Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/filterNoChild.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/filterNoChild.xml?rev=1096322&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/filterNoChild.xml (added)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/filterNoChild.xml Sun Apr 24 13:01:29 2011
@@ -0,0 +1,35 @@
+<?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.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+  <camelContext xmlns="http://camel.apache.org/schema/spring">
+    <route>
+      <from uri="direct:start"/>
+      <filter>
+        <xpath>$foo = 'bar'</xpath>
+      </filter>
+      <to uri="mock:result"/>
+    </route>
+  </camelContext>
+
+</beans>

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/filterNoChild.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/filterNoChild.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/filterNoChild.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml