You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2010/06/21 08:46:45 UTC

svn commit: r956447 - in /camel/trunk/camel-core/src/test/java/org/apache/camel/processor/resequencer: MyFileNameExpression.java ResequencerFileNameTest.java

Author: ningjiang
Date: Mon Jun 21 03:01:18 2010
New Revision: 956447

URL: http://svn.apache.org/viewvc?rev=956447&view=rev
Log:
CAMEL-1371 Added test on the Resequencer to show how to set the customer expression from comparator

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/resequencer/MyFileNameExpression.java   (with props)
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/resequencer/ResequencerFileNameTest.java   (with props)

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/resequencer/MyFileNameExpression.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/resequencer/MyFileNameExpression.java?rev=956447&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/resequencer/MyFileNameExpression.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/resequencer/MyFileNameExpression.java Mon Jun 21 03:01:18 2010
@@ -0,0 +1,43 @@
+/**
+ * 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.resequencer;
+
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
+
+public class MyFileNameExpression implements Expression {
+    
+    public String getFileName(Exchange exchange) {
+        return exchange.getIn().getBody(String.class);
+    }
+    
+    public Object evaluate(Exchange exchange) {
+        String fileName = getFileName(exchange);
+        String[] files = fileName.split("-D");
+        Long answer = Long.parseLong(files[0]) * 1000 + Long.parseLong(files[1]);
+        return answer;
+    }
+    
+
+    public <T> T evaluate(Exchange exchange, Class<T> type) {
+        Object result = evaluate(exchange);
+        return exchange.getContext().getTypeConverter().convertTo(type, result);
+    }
+
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/resequencer/MyFileNameExpression.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/resequencer/MyFileNameExpression.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/resequencer/ResequencerFileNameTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/resequencer/ResequencerFileNameTest.java?rev=956447&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/resequencer/ResequencerFileNameTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/resequencer/ResequencerFileNameTest.java Mon Jun 21 03:01:18 2010
@@ -0,0 +1,61 @@
+/**
+ * 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.resequencer;
+
+import java.util.List;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Route;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.EventDrivenConsumerRoute;
+import org.apache.camel.management.JmxSystemPropertyKeys;
+import org.apache.camel.processor.interceptor.StreamCaching;
+
+/**
+ * @version $Revision$
+ */
+public class ResequencerFileNameTest extends ContextTestSupport {
+    protected MockEndpoint resultEndpoint;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        resultEndpoint = getMockEndpoint("mock:result");
+    }
+    
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                // START SNIPPET: example
+                from("direct:start").resequence(new MyFileNameExpression()).stream().to("mock:result");
+                // END SNIPPET: example
+            }
+        };
+    }
+
+    public void testStreamResequence() throws Exception {
+        resultEndpoint.expectedBodiesReceived("20090612-D001", "20090612-D003", "20090612-D002", "20090615-D001");
+        template.requestBody("direct:start", "20090612-D003");
+        template.requestBody("direct:start", "20090612-D001");
+        Thread.sleep(2000);
+        template.requestBody("direct:start", "20090615-D001");
+        template.requestBody("direct:start", "20090612-D002");
+        resultEndpoint.assertIsSatisfied();
+    }
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/resequencer/ResequencerFileNameTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/resequencer/ResequencerFileNameTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date