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 2012/01/09 14:46:58 UTC
svn commit: r1229147 - in
/camel/trunk/camel-core/src/test/java/org/apache/camel:
component/file/AntPathMatcherGenericFileFilterTest.java
util/AntPathMatcherTest.java
Author: davsclaus
Date: Mon Jan 9 13:46:58 2012
New Revision: 1229147
URL: http://svn.apache.org/viewvc?rev=1229147&view=rev
Log:
CAMEL-4779: Added missing tests from patch.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/AntPathMatcherGenericFileFilterTest.java (with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/util/AntPathMatcherTest.java (with props)
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/AntPathMatcherGenericFileFilterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/AntPathMatcherGenericFileFilterTest.java?rev=1229147&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/AntPathMatcherGenericFileFilterTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/AntPathMatcherGenericFileFilterTest.java Mon Jan 9 13:46:58 2012
@@ -0,0 +1,112 @@
+/**
+ * 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.component.file;
+
+import java.io.File;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+
+/**
+ * Unit tests for {@link AntPathMatcherGenericFileFilter}.
+ */
+public class AntPathMatcherGenericFileFilterTest extends ContextTestSupport {
+
+ @Override
+ protected void setUp() throws Exception {
+ deleteDirectory("target/files");
+ super.setUp();
+ }
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ jndi.bind("filter", new AntPathMatcherGenericFileFilter<File>("**/c*"));
+ return jndi;
+ }
+
+ public void testInclude() throws Exception {
+
+ template.sendBodyAndHeader("file://target/files/ant-path-1/x/y/z", "Hello World", Exchange.FILE_NAME, "report.txt");
+
+ MockEndpoint mock = getMockEndpoint("mock:result1");
+ mock.expectedBodiesReceived("Hello World");
+
+ assertMockEndpointsSatisfied();
+ oneExchangeDone.matchesMockWaitTime();
+ }
+
+ public void testExclude() throws Exception {
+
+ template.sendBodyAndHeader("file://target/files/ant-path-2/x/y/z", "Hello World 1", Exchange.FILE_NAME, "report.bak");
+ template.sendBodyAndHeader("file://target/files/ant-path-2/x/y/z", "Hello World 2", Exchange.FILE_NAME, "report.txt");
+
+ MockEndpoint mock = getMockEndpoint("mock:result2");
+ mock.expectedBodiesReceived("Hello World 2");
+
+ assertMockEndpointsSatisfied();
+ oneExchangeDone.matchesMockWaitTime();
+ }
+
+ public void testIncludesAndExcludes() throws Exception {
+
+ template.sendBodyAndHeader("file://target/files/ant-path-3/x/y/z", "Hello World 1", Exchange.FILE_NAME, "a.pdf");
+ template.sendBodyAndHeader("file://target/files/ant-path-3/x/y/z", "Hello World 2", Exchange.FILE_NAME, "m.pdf");
+ template.sendBodyAndHeader("file://target/files/ant-path-3/x/y/z", "Hello World 3", Exchange.FILE_NAME, "b.txt");
+ template.sendBodyAndHeader("file://target/files/ant-path-3/x/y/z", "Hello World 4", Exchange.FILE_NAME, "m.txt");
+ template.sendBodyAndHeader("file://target/files/ant-path-3/x/y/z", "Hello World 5", Exchange.FILE_NAME, "b.bak");
+ template.sendBodyAndHeader("file://target/files/ant-path-3/x/y/z", "Hello World 6", Exchange.FILE_NAME, "m.bak");
+
+ MockEndpoint mock = getMockEndpoint("mock:result3");
+ mock.expectedBodiesReceived("Hello World 2", "Hello World 4");
+
+ assertMockEndpointsSatisfied();
+ oneExchangeDone.matchesMockWaitTime();
+ }
+
+ public void testIncludesAndExcludesAndFilter() throws Exception {
+
+ template.sendBodyAndHeader("file://target/files/ant-path-4/x/y/z", "Hello World 1", Exchange.FILE_NAME, "a.txt");
+ template.sendBodyAndHeader("file://target/files/ant-path-4/x/y/z", "Hello World 2", Exchange.FILE_NAME, "b.txt");
+ template.sendBodyAndHeader("file://target/files/ant-path-4/x/y/z", "Hello World 3", Exchange.FILE_NAME, "c.txt");
+
+ MockEndpoint mock = getMockEndpoint("mock:result4");
+ mock.expectedBodiesReceived("Hello World 3");
+
+ assertMockEndpointsSatisfied();
+ oneExchangeDone.matchesMockWaitTime();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+
+ from("file://target/files/ant-path-1?recursive=true&antInclude=**/*.txt").convertBodyTo(String.class).to("mock:result1");
+
+ from("file://target/files/ant-path-2?recursive=true&antExclude=**/*.bak").convertBodyTo(String.class).to("mock:result2");
+
+ from("file://target/files/ant-path-3?recursive=true&antInclude=**/*.pdf,**/*.txt&antExclude=**/a*,**/b*").convertBodyTo(String.class).to("mock:result3");
+
+ from("file://target/files/ant-path-4?recursive=true&antInclude=**/*.txt&antExclude=**/a*&filter=#filter").convertBodyTo(String.class).to("mock:result4");
+ }
+ };
+ }
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/AntPathMatcherGenericFileFilterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/AntPathMatcherGenericFileFilterTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/util/AntPathMatcherTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/AntPathMatcherTest.java?rev=1229147&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/util/AntPathMatcherTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/util/AntPathMatcherTest.java Mon Jan 9 13:46:58 2012
@@ -0,0 +1,42 @@
+/**
+ * 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.util;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for {@link AntPathMatcher}.
+ */
+public class AntPathMatcherTest extends TestCase {
+
+ public void test() {
+ AntPathMatcher matcher = new AntPathMatcher();
+ assertTrue(matcher.match("*.txt", "blah.txt"));
+ assertFalse(matcher.match("*.txt", "foo/blah.txt"));
+ assertTrue(matcher.match("???.txt", "abc.txt"));
+ assertTrue(matcher.match("abc.t?t", "abc.tnt"));
+ assertFalse(matcher.match("???.txt", "abcd.txt"));
+ assertTrue(matcher.match("**/*.txt", "blah.txt"));
+ assertTrue(matcher.match("**/*.txt", "foo/blah.txt"));
+ assertTrue(matcher.match("**/*.txt", "foo/bar/blah.txt"));
+ assertTrue(matcher.match("foo/**/*.txt", "foo/bar/blah.txt"));
+ assertTrue(matcher.match("foo/**/*.??", "foo/bar/blah.gz"));
+ assertTrue(matcher.match("foo/**/*.txt", "foo/blah.txt"));
+ assertFalse(matcher.match("foo/**/*.txt", "blah/blah.txt"));
+ }
+
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/util/AntPathMatcherTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/util/AntPathMatcherTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date