Repository: camel Updated Branches: refs/heads/master ffb3fd5cb -> 5a4d715a1
Added unit test for testing copyTo option in camel-mail. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5a4d715a Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5a4d715a Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5a4d715a Branch: refs/heads/master Commit: 5a4d715a1b065a3598ad0ef85b98da81f438c0b5 Parents: ffb3fd5 Author: Claus Ibsen <davscl...@apache.org> Authored: Wed Jan 7 08:19:12 2015 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Jan 7 08:22:04 2015 +0100 ---------------------------------------------------------------------- .../camel/component/mail/MailCopyToTest.java | 79 ++++++++++++++++++++ .../camel/component/mail/mock/MyMockFolder.java | 40 ++++++++++ .../camel/component/mail/mock/MyMockStore.java | 61 +++++++++++++++ .../test/resources/META-INF/javamail.providers | 5 ++ parent/pom.xml | 2 +- 5 files changed, 186 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/5a4d715a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailCopyToTest.java ---------------------------------------------------------------------- diff --git a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailCopyToTest.java b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailCopyToTest.java new file mode 100644 index 0000000..7de350e --- /dev/null +++ b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailCopyToTest.java @@ -0,0 +1,79 @@ +/** + * 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.mail; + +import javax.mail.Folder; +import javax.mail.Message; +import javax.mail.Store; +import javax.mail.internet.MimeMessage; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; +import org.jvnet.mock_javamail.Mailbox; + +/** + * Unit test for copyTo. + */ +public class MailCopyToTest extends CamelTestSupport { + + @Override + public void setUp() throws Exception { + prepareMailbox(); + super.setUp(); + } + + @Test + public void testCopyTo() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(5); + + assertMockEndpointsSatisfied(); + + assertEquals(0, Mailbox.get("jones@localhost").getNewMessageCount()); + assertEquals(5, Mailbox.get("backup-jones@localhost").getNewMessageCount()); + } + + private void prepareMailbox() throws Exception { + // connect to mailbox + Mailbox.clearAll(); + JavaMailSender sender = new DefaultJavaMailSender(); + Store store = sender.getSession().getStore("pop3"); + store.connect("localhost", 25, "jones", "secret"); + Folder folder = store.getFolder("INBOX"); + folder.open(Folder.READ_WRITE); + folder.expunge(); + + // inserts 5 new messages + Message[] messages = new Message[5]; + for (int i = 0; i < 5; i++) { + messages[i] = new MimeMessage(sender.getSession()); + messages[i].setText("Message " + i); + } + folder.appendMessages(messages); + folder.close(true); + } + + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from("imap://jones@localhost?password=secret©To=backup").to("mock:result"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/5a4d715a/components/camel-mail/src/test/java/org/apache/camel/component/mail/mock/MyMockFolder.java ---------------------------------------------------------------------- diff --git a/components/camel-mail/src/test/java/org/apache/camel/component/mail/mock/MyMockFolder.java b/components/camel-mail/src/test/java/org/apache/camel/component/mail/mock/MyMockFolder.java new file mode 100644 index 0000000..bea014d --- /dev/null +++ b/components/camel-mail/src/test/java/org/apache/camel/component/mail/mock/MyMockFolder.java @@ -0,0 +1,40 @@ +/** + * 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.mail.mock; + +import org.jvnet.mock_javamail.Mailbox; +import org.jvnet.mock_javamail.MockFolder; +import org.jvnet.mock_javamail.MockStore; + +public class MyMockFolder extends MockFolder { + + private String name; + + public MyMockFolder(MockStore store, Mailbox mailbox, String name) { + super(store, mailbox); + this.name = name; + } + + public String getName() { + return name; + } + + public String getFullName() { + return name; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/5a4d715a/components/camel-mail/src/test/java/org/apache/camel/component/mail/mock/MyMockStore.java ---------------------------------------------------------------------- diff --git a/components/camel-mail/src/test/java/org/apache/camel/component/mail/mock/MyMockStore.java b/components/camel-mail/src/test/java/org/apache/camel/component/mail/mock/MyMockStore.java new file mode 100644 index 0000000..75a02e6 --- /dev/null +++ b/components/camel-mail/src/test/java/org/apache/camel/component/mail/mock/MyMockStore.java @@ -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.component.mail.mock; + +import java.util.HashMap; +import java.util.Map; +import javax.mail.Folder; +import javax.mail.MessagingException; +import javax.mail.Session; +import javax.mail.URLName; + +import org.jvnet.mock_javamail.Aliases; +import org.jvnet.mock_javamail.Mailbox; +import org.jvnet.mock_javamail.MockStore; + +public class MyMockStore extends MockStore { + + private Map<String, Folder> folders = new HashMap<String, Folder>(); + private String address; + + public MyMockStore(Session session, URLName urlname) { + super(session, urlname); + } + + @Override + protected boolean protocolConnect(String host, int port, String user, String password) throws MessagingException { + address = user + '@' + host; + return super.protocolConnect(host, port, user, password); + } + + @Override + public Folder getFolder(String name) throws MessagingException { + if ("INBOX".equals(name)) { + return super.getFolder(name); + } + + Folder folder = folders.get(name); + if (folder == null) { + // need a new mailbox as its a sub folder + String adr = name + "-" + address; + Mailbox mailbox = Mailbox.get(Aliases.getInstance().resolve(adr)); + folder = new MyMockFolder(this, mailbox, name); + folders.put(name, folder); + } + return folder; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/5a4d715a/components/camel-mail/src/test/resources/META-INF/javamail.providers ---------------------------------------------------------------------- diff --git a/components/camel-mail/src/test/resources/META-INF/javamail.providers b/components/camel-mail/src/test/resources/META-INF/javamail.providers new file mode 100644 index 0000000..cbf1a54 --- /dev/null +++ b/components/camel-mail/src/test/resources/META-INF/javamail.providers @@ -0,0 +1,5 @@ +# See http://java.sun.com/products/javamail/javadocs/javax/mail/Session.html + +protocol=smtp; type=transport; class=org.jvnet.mock_javamail.MockTransport; vendor=java.net mock-javamail project; +protocol=pop3; type=store; class=org.jvnet.mock_javamail.MockStore; vendor=java.net mock-javamail project; +protocol=imap; type=store; class=org.apache.camel.component.mail.mock.MyMockStore; vendor=java.net mock-javamail project; http://git-wip-us.apache.org/repos/asf/camel/blob/5a4d715a/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index 9c8b12b..ee34be9 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -332,7 +332,7 @@ <mina-version>1.1.7</mina-version> <mina2-version>2.0.9</mina2-version> <minimal-json-version>0.9.1</minimal-json-version> - <mock-javamail-version>1.7</mock-javamail-version> + <mock-javamail-version>1.9</mock-javamail-version> <mockito-version>1.9.5</mockito-version> <mongo-java-driver-version>2.12.4</mongo-java-driver-version> <mqtt-client-version>1.10</mqtt-client-version>