You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by do...@apache.org on 2013/08/21 18:35:18 UTC
svn commit: r1516205 [7/9] - in /james/hupa/trunk: ./
client/src/main/java/org/apache/hupa/
client/src/main/java/org/apache/hupa/client/
client/src/main/java/org/apache/hupa/client/gin/
client/src/main/java/org/apache/hupa/client/mvp/ client/src/main/j...
Added: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/CreateFolderHandlerTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/CreateFolderHandlerTest.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/CreateFolderHandlerTest.java (added)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/CreateFolderHandlerTest.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,83 @@
+/****************************************************************
+ * 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.hupa.server.handler;
+
+import net.customware.gwt.dispatch.shared.ActionException;
+
+import org.apache.hupa.server.HupaGuiceTestCase;
+import org.apache.hupa.server.mock.MockIMAPFolder;
+import org.apache.hupa.server.mock.MockIMAPStore;
+import org.apache.hupa.shared.SConsts;
+import org.apache.hupa.shared.data.IMAPFolder;
+import org.apache.hupa.shared.exception.InvalidSessionException;
+import org.apache.hupa.shared.rpc.CreateFolder;
+
+import javax.mail.Folder;
+import javax.mail.MessagingException;
+
+public class CreateFolderHandlerTest extends HupaGuiceTestCase {
+
+ public void testCreate() throws MessagingException {
+ IMAPFolder folder = createFolder();
+ MockIMAPStore store = (MockIMAPStore) storeCache.get(testUser);
+ Folder f1 = store.getFolder(folder.getFullName());
+ assertFalse("not exists",f1.exists());
+
+ try {
+ createFolderHandler.execute(new CreateFolder(folder), null);
+ Folder f = store.getFolder(folder.getFullName());
+ assertTrue("exists",f.exists());
+ } catch (ActionException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ public void testDuplicateFolder() throws MessagingException {
+ IMAPFolder folder = createFolder();
+ MockIMAPStore store = (MockIMAPStore) storeCache.get(testUser);
+ Folder f1 = store.getFolder(folder.getFullName());
+ f1.create(Folder.HOLDS_FOLDERS);
+ try {
+ createFolderHandler.execute(new CreateFolder(folder), null);
+ fail("Folder already exists");
+ } catch (ActionException e) {
+ }
+ }
+
+ public void testInvalidSessionId() {
+ httpSession.removeAttribute(SConsts.USER_SESS_ATTR);
+ IMAPFolder folder = createFolder();
+ try {
+ createFolderHandler.execute(new CreateFolder(folder), null);
+ fail("Invalid session");
+ } catch (InvalidSessionException e) {
+ } catch (ActionException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ private IMAPFolder createFolder() {
+ IMAPFolder folder = new IMAPFolder();
+ folder.setFullName("NewFolder");
+ folder.setDelimiter(String.valueOf(MockIMAPFolder.SEPARATOR));
+ return folder;
+ }
+}
Added: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/DeleteFolderHandlerTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/DeleteFolderHandlerTest.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/DeleteFolderHandlerTest.java (added)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/DeleteFolderHandlerTest.java Wed Aug 21 16:35:16 2013
@@ -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.hupa.server.handler;
+
+import net.customware.gwt.dispatch.shared.ActionException;
+
+import org.apache.hupa.server.HupaGuiceTestCase;
+import org.apache.hupa.server.mock.MockIMAPFolder;
+import org.apache.hupa.server.mock.MockIMAPStore;
+import org.apache.hupa.shared.SConsts;
+import org.apache.hupa.shared.data.IMAPFolder;
+import org.apache.hupa.shared.exception.InvalidSessionException;
+import org.apache.hupa.shared.rpc.DeleteFolder;
+
+import javax.mail.Folder;
+import javax.mail.MessagingException;
+
+public class DeleteFolderHandlerTest extends HupaGuiceTestCase {
+
+ public void testDelete() throws MessagingException {
+ IMAPFolder folder = createFolder();
+ MockIMAPStore store = (MockIMAPStore) storeCache.get(testUser);
+ Folder f1 = store.getFolder(folder.getFullName());
+ f1.create(Folder.HOLDS_FOLDERS);
+ try {
+ deleteFolderHandler.execute(new DeleteFolder(folder), null);
+ Folder f = store.getFolder(folder.getFullName());
+ assertFalse("not exists",f.exists());
+ } catch (ActionException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ public void testDeleteNonExistFolder() throws MessagingException {
+ IMAPFolder folder = createFolder();
+ try {
+ deleteFolderHandler.execute(new DeleteFolder(folder), null);
+ fail("Folder should not exist");
+ } catch (ActionException e) {
+ }
+ }
+
+ public void testInvalidSessionId() {
+ httpSession.removeAttribute(SConsts.USER_SESS_ATTR);
+ IMAPFolder folder = createFolder();
+ try {
+ deleteFolderHandler.execute(new DeleteFolder(folder), null);
+ fail("Invalid session");
+ } catch (InvalidSessionException e) {
+ } catch (ActionException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ private IMAPFolder createFolder() {
+ IMAPFolder folder = new IMAPFolder();
+ folder.setFullName("NewFolder");
+ folder.setDelimiter(String.valueOf(MockIMAPFolder.SEPARATOR));
+ return folder;
+ }
+}
Added: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/DeleteMessageByUidHandlerTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/DeleteMessageByUidHandlerTest.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/DeleteMessageByUidHandlerTest.java (added)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/DeleteMessageByUidHandlerTest.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,98 @@
+/****************************************************************
+ * 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.hupa.server.handler;
+
+import net.customware.gwt.dispatch.shared.ActionException;
+
+import org.apache.hupa.server.HupaGuiceTestCase;
+import org.apache.hupa.server.mock.MockIMAPFolder;
+import org.apache.hupa.server.mock.MockIMAPStore;
+import org.apache.hupa.shared.data.IMAPFolder;
+import org.apache.hupa.shared.rpc.DeleteMessageByUid;
+
+import java.util.ArrayList;
+
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
+public class DeleteMessageByUidHandlerTest extends HupaGuiceTestCase {
+
+ public void testDeleteFolderNotExists() throws MessagingException {
+ IMAPFolder folder = new IMAPFolder();
+ folder.setFullName("NOT_EXISTS");
+ DeleteMessageByUid action = new DeleteMessageByUid(folder,new ArrayList<Long>());
+ try {
+ deleteMessageByUidHandler.execute(action, null);
+ fail("Folder should not exists!");
+ } catch (ActionException e) {
+ }
+ }
+
+ public void testDeleteFolderExistsAndNotTrash() throws MessagingException {
+ IMAPFolder folder = new IMAPFolder();
+ folder.setFullName("EXISTS");
+ MockIMAPStore store = (MockIMAPStore) storeCache.get(testUser);
+ store.clear();
+
+ MockIMAPFolder f = (MockIMAPFolder)store.getFolder(folder.getFullName());
+ f.create(Folder.HOLDS_FOLDERS);
+ f.addMessages(new Message[] { new MimeMessage(session), new MimeMessage(session), new MimeMessage(session)});
+ ArrayList<Long> uids = new ArrayList<Long>();
+ uids.add(0l);
+ uids.add(2l);
+ DeleteMessageByUid action = new DeleteMessageByUid(folder, uids);
+
+ MockIMAPFolder f3 = (MockIMAPFolder) store.getFolder(testUser.getSettings().getTrashFolderName());
+ assertFalse("Trash folder already exists", f3.exists());
+ try {
+ deleteMessageByUidHandler.execute(action, null);
+ assertEquals("Only 1 message left", 1, f.getMessageCount());
+
+ MockIMAPFolder f2 = (MockIMAPFolder) store.getFolder(testUser.getSettings().getTrashFolderName());
+ assertTrue("Trash folder created",f2.exists());
+ assertEquals("2 messages moved", 2, f2.getMessageCount());
+ } catch (ActionException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ public void testDeleteFolderExistsAndIsTrash() throws MessagingException {
+ IMAPFolder folder = new IMAPFolder();
+ folder.setFullName(testUser.getSettings().getTrashFolderName());
+ MockIMAPStore store = (MockIMAPStore) storeCache.get(testUser);
+
+ MockIMAPFolder f = (MockIMAPFolder)store.getFolder(folder.getFullName());
+ f.addMessages(new Message[] { new MimeMessage(session), new MimeMessage(session), new MimeMessage(session)});
+ ArrayList<Long> uids = new ArrayList<Long>();
+ uids.add(0l);
+ uids.add(2l);
+ DeleteMessageByUid action = new DeleteMessageByUid(folder, uids);
+ try {
+ deleteMessageByUidHandler.execute(action, null);
+ assertEquals("Only 1 message left", 1, f.getMessageCount());
+ } catch (ActionException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+}
Added: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/FetchFoldersHandlerTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/FetchFoldersHandlerTest.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/FetchFoldersHandlerTest.java (added)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/FetchFoldersHandlerTest.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,142 @@
+/****************************************************************
+ * 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.hupa.server.handler;
+
+import net.customware.gwt.dispatch.shared.ActionException;
+
+import org.apache.hupa.server.HupaGuiceTestCase;
+import org.apache.hupa.server.mock.MockIMAPFolder;
+import org.apache.hupa.server.mock.MockIMAPStore;
+import org.apache.hupa.shared.SConsts;
+import org.apache.hupa.shared.data.IMAPFolder;
+import org.apache.hupa.shared.exception.InvalidSessionException;
+import org.apache.hupa.shared.rpc.FetchFolders;
+import org.apache.hupa.shared.rpc.FetchFoldersResult;
+
+import java.util.List;
+
+import javax.mail.Folder;
+import javax.mail.MessagingException;
+
+public class FetchFoldersHandlerTest extends HupaGuiceTestCase {
+
+
+ public void setUp() throws Exception {
+ super.setUp();
+ MockIMAPStore store = (MockIMAPStore) storeCache.get(testUser);
+ store.clear();
+ }
+
+ public void testInvalidSessionId() {
+ httpSession.removeAttribute(SConsts.USER_SESS_ATTR);
+ try {
+ fetchFoldersHandler.execute(new FetchFolders(), null);
+ fail("Invalid session");
+ } catch (InvalidSessionException e) {
+ } catch (ActionException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ public void testNoFolders() {
+ httpSession.setAttribute(SConsts.USER_SESS_ATTR, testUser);
+ try {
+ FetchFoldersResult result = fetchFoldersHandler.execute(new FetchFolders(), null);
+ assertTrue(result.getFolders().isEmpty());
+ } catch (ActionException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+
+// Skip test because
+// MockIMAPFolder somehow doesn't creates subfolders, but put all created folders
+// as main folder using as name the lates after the separator:
+// 'WHATEVER.XXX.AAA' will result in a fullname 'AAA', what is wrong.
+//
+// public void testFoundFolders() throws MessagingException {
+// httpSession.setAttribute(SConsts.USER_SESS_ATTR, testUser);
+//
+// store.getFolder("WHATEVER").create(Folder.HOLDS_FOLDERS);
+// store.getFolder("WHATEVER.XXX").create(Folder.HOLDS_FOLDERS);
+// store.getFolder("WHATEVER.XXX.AAA").create(Folder.HOLDS_FOLDERS);
+// store.getFolder("WHATEVER.XXX.AAA.111").create(Folder.HOLDS_FOLDERS);
+// store.getFolder("WHATEVER.XXX.AAA.222").create(Folder.HOLDS_FOLDERS);
+// store.getFolder("WHATEVER.XXX.BBB").create(Folder.HOLDS_FOLDERS);
+// store.getFolder("WHATEVER.YYY").create(Folder.HOLDS_FOLDERS);
+// store.getFolder("WHATEVER.YYY.AAA").create(Folder.HOLDS_FOLDERS);
+// store.getFolder("WHATEVER.YYY.BBB").create(Folder.HOLDS_FOLDERS);
+// store.getFolder("WHATEVER1").create(Folder.HOLDS_FOLDERS);
+// try {
+// FetchFoldersResult result = fetchFoldersHandler.execute(new FetchFolders(), null);
+//
+// System.out.println(result.toString());
+//
+// List<IMAPFolder> folders = result.getFolders();
+// assertFalse(folders.isEmpty());
+//
+// // 2 different main folders, everything else are subfolders
+// assertEquals(2, folders.size());
+//
+// // WHATEVER
+// assertEquals("WHATEVER",folders.get(0).getFullName());
+//
+// // WHATEVER1
+// assertEquals("WHATEVER1",folders.get(1).getFullName());
+//
+// // WHATEVER.XXX
+// assertEquals("WHATEVER" + MockIMAPFolder.SEPARATOR + "XXX",
+// folders.get(0).getChildIMAPFolders().get(0).getFullName());
+//
+// // WHATEVER.XXX.AAA
+// assertEquals("WHATEVER" + MockIMAPFolder.SEPARATOR + "XXX" + MockIMAPFolder.SEPARATOR + "AAA",
+// folders.get(0).getChildIMAPFolders().get(0).getChildIMAPFolders().get(0).getFullName());
+//
+// // WHATEVER.XXX.AAA.111
+// assertEquals("WHATEVER" + MockIMAPFolder.SEPARATOR + "XXX" + MockIMAPFolder.SEPARATOR + "AAA" + MockIMAPFolder.SEPARATOR + "111",
+// folders.get(0).getChildIMAPFolders().get(0).getChildIMAPFolders().get(0).getChildIMAPFolders().get(0).getFullName());
+//
+// // WHATEVER.XXX.AAA.222
+// assertEquals("WHATEVER" + MockIMAPFolder.SEPARATOR + "XXX" + MockIMAPFolder.SEPARATOR + "AAA" + MockIMAPFolder.SEPARATOR + "222",
+// folders.get(0).getChildIMAPFolders().get(0).getChildIMAPFolders().get(0).getChildIMAPFolders().get(1).getFullName());
+//
+// // WHATEVER.XXX.BBB
+// assertEquals("WHATEVER" + MockIMAPFolder.SEPARATOR + "XXX" + MockIMAPFolder.SEPARATOR + "BBB",
+// folders.get(0).getChildIMAPFolders().get(0).getChildIMAPFolders().get(1).getFullName());
+//
+// // WHATEVER.YYY
+// assertEquals("WHATEVER" + MockIMAPFolder.SEPARATOR + "YYY",
+// folders.get(0).getChildIMAPFolders().get(1).getFullName());
+//
+// // WHATEVER.YYY.AAA
+// assertEquals("WHATEVER" + MockIMAPFolder.SEPARATOR + "YYY" + MockIMAPFolder.SEPARATOR + "AAA",
+// folders.get(0).getChildIMAPFolders().get(1).getChildIMAPFolders().get(0).getFullName());
+//
+// // WHATEVER.YYY.BBB
+// assertEquals("WHATEVER" + MockIMAPFolder.SEPARATOR + "YYY" + MockIMAPFolder.SEPARATOR + "BBB",
+// folders.get(0).getChildIMAPFolders().get(1).getChildIMAPFolders().get(1).getFullName());
+// } catch (ActionException e) {
+// e.printStackTrace();
+// fail();
+// }
+// }
+}
Added: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/FetchMessagesHandlerTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/FetchMessagesHandlerTest.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/FetchMessagesHandlerTest.java (added)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/FetchMessagesHandlerTest.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,106 @@
+/****************************************************************
+ * 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.hupa.server.handler;
+
+import org.apache.hupa.server.HupaGuiceTestCase;
+import org.apache.hupa.server.mock.MockIMAPFolder;
+import org.apache.hupa.shared.data.IMAPFolder;
+import org.apache.hupa.shared.rpc.FetchMessages;
+import org.apache.hupa.shared.rpc.FetchMessagesResult;
+
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+
+import javax.mail.Flags;
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.Flags.Flag;
+import javax.mail.internet.MimeMessage;
+
+public class FetchMessagesHandlerTest extends HupaGuiceTestCase {
+
+ public void testConvert() throws Exception {
+ MockIMAPFolder f = (MockIMAPFolder)store.getFolder("WHATEVER");
+ f.create(Folder.HOLDS_MESSAGES);
+
+ ByteArrayInputStream is = new ByteArrayInputStream("From: a@foo.com\nTo: b@foo.com\nSubject: something\n\ndata".getBytes());
+ MimeMessage m1 = new MimeMessage(session, is);
+ is = new ByteArrayInputStream("From: =?ISO-8859-1?Q?Manolo_Pe=F1a?= <pe...@foo.com>\nTo: b@foo.com\nSubject: something\n\ndata".getBytes());
+ MimeMessage m2 = new MimeMessage(session, is);
+ is = new ByteArrayInputStream("From: a@foo.com\nTo: b@foo.com\nSubject: =?ISO-8859-1?Q?Monta=F1a?=\n\ndata".getBytes());
+ MimeMessage m3 = new MimeMessage(session, is);
+
+ ArrayList<org.apache.hupa.shared.data.Message> msgs = fetchMessagesHandler.convert(2, f, new Message[]{m1, m2, m3});
+ assertEquals(2, msgs.size());
+
+ msgs = fetchMessagesHandler.convert(10, f, new Message[]{m1, m2, m3});
+ assertEquals(3, msgs.size());
+
+ msgs = fetchMessagesHandler.convert(10, f, new Message[]{m2});
+ assertEquals("Manolo Pe\u00F1a <pe...@foo.com>", msgs.get(0).getFrom());
+
+ msgs = fetchMessagesHandler.convert(10, f, new Message[]{m3});
+ assertEquals("Monta\u00F1a", msgs.get(0).getSubject());
+ }
+
+ public void testFetchMessages() throws Exception {
+
+ MockIMAPFolder serverfolder = (MockIMAPFolder)store.getFolder("WHATEVER");
+ serverfolder.create(Folder.HOLDS_MESSAGES);
+
+ IMAPFolder clientfolder = new IMAPFolder("WHATEVER");
+ FetchMessagesResult result = fetchMessagesHandler.execute(new FetchMessages(clientfolder, 0, 10, "*"), null);
+ assertEquals(0, result.getRealCount());
+
+ ByteArrayInputStream is = new ByteArrayInputStream("From: a@foo.com\nTo: b@foo.com\nSubject: something\n\ndata".getBytes());
+ MimeMessage msg = new MimeMessage(session, is);
+ serverfolder.addMessages(new Message[]{msg});
+ result = fetchMessagesHandler.execute(new FetchMessages(clientfolder, 0, 10, "something"), null);
+ assertEquals(1, result.getRealCount());
+ assertEquals(1, result.getMessages().size());
+
+ result = fetchMessagesHandler.execute(new FetchMessages(clientfolder, 0, 10, null), null);
+ assertEquals(1, result.getRealCount());
+ assertEquals(1, result.getMessages().size());
+
+ is = new ByteArrayInputStream("From: a@foo.com\nTo: b@foo.com\nSubject: something\n\ndata".getBytes());
+ msg = new MimeMessage(session, is);
+ serverfolder.appendMessages(new Message[]{msg});
+
+ result = fetchMessagesHandler.execute(new FetchMessages(clientfolder, 0, 10, "*"), null);
+ assertEquals(2, result.getRealCount());
+ assertEquals(2, result.getMessages().size());
+
+ result = fetchMessagesHandler.execute(new FetchMessages(clientfolder, 0, 10, null), null);
+ assertEquals(2, serverfolder.getMessageCount());
+ assertEquals(2, serverfolder.getUnreadMessageCount());
+ assertEquals(2, result.getRealCount());
+ assertEquals(2, result.getMessages().size());
+ assertEquals(2, result.getMessages().size());
+
+ msg.setFlags(new Flags(Flag.SEEN), true);
+ assertEquals(1, serverfolder.getUnreadMessageCount());
+
+ serverfolder.appendMessages(new Message[]{msg});
+ result = fetchMessagesHandler.execute(new FetchMessages(clientfolder, 0, 10, "*"), null);
+ assertEquals(3, result.getRealCount());
+ assertEquals(1, result.getRealUnreadCount());
+ }
+}
Added: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/FowardMessageHandlerTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/FowardMessageHandlerTest.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/FowardMessageHandlerTest.java (added)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/FowardMessageHandlerTest.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,71 @@
+/****************************************************************
+ * 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.hupa.server.handler;
+
+import javax.mail.Message;
+
+import org.apache.hupa.server.FileItemRegistry;
+import org.apache.hupa.server.HupaGuiceTestCase;
+import org.apache.hupa.server.mock.MockIMAPFolder;
+import org.apache.hupa.server.mock.MockIMAPStore;
+import org.apache.hupa.server.utils.TestUtils;
+import org.apache.hupa.shared.data.IMAPFolder;
+import org.apache.hupa.shared.data.SMTPMessage;
+import org.apache.hupa.shared.rpc.ForwardMessage;
+
+import com.sun.mail.imap.IMAPStore;
+
+public class FowardMessageHandlerTest extends HupaGuiceTestCase {
+
+ public void testForwardMessage() throws Exception {
+ IMAPStore store = storeCache.get(testUser);
+
+ FileItemRegistry registry = injector.getInstance(FileItemRegistry.class);
+
+ MockIMAPFolder sentbox = (MockIMAPFolder) store.getFolder(MockIMAPStore.MOCK_SENT_FOLDER);
+ assertTrue(sentbox.getMessages().length == 0);
+
+ MockIMAPFolder inbox = (MockIMAPFolder) store.getFolder(MockIMAPStore.MOCK_INBOX_FOLDER);
+ assertTrue(inbox.getMessages().length >= 0);
+
+ Message message = TestUtils.createMockMimeMessage(session, 2);
+ inbox.appendMessages(new Message[]{message});
+ long msgUid = inbox.getUID(message);
+ message = inbox.getMessageByUID(msgUid);
+ assertNotNull(message);
+
+ IMAPFolder ifolder = new IMAPFolder(inbox.getFullName());
+ SMTPMessage smtpmsg = TestUtils.createMockSMTPMessage(registry, 2);
+ ForwardMessage action = new ForwardMessage(smtpmsg, ifolder, msgUid);
+
+ message = forwardMessageHandler.createMessage(session, action);
+ message = forwardMessageHandler.fillBody(message, action);
+
+ String expected = "multipart/mixed\n"
+ + " multipart/alternative\n"
+ + " text/plain\n"
+ + " text/html\n"
+ + " mock/attachment => file_1.bin\n"
+ + " mock/attachment => file_2.bin\n";
+
+ assertEquals(expected, TestUtils.summaryzeContent(message).toString());
+ }
+
+}
Added: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/GetMessageDetailsHandlerTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/GetMessageDetailsHandlerTest.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/GetMessageDetailsHandlerTest.java (added)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/GetMessageDetailsHandlerTest.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,210 @@
+/****************************************************************
+ * 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.hupa.server.handler;
+
+import com.sun.mail.imap.IMAPFolder;
+import com.sun.mail.imap.IMAPStore;
+
+import org.apache.hupa.server.HupaGuiceTestCase;
+import org.apache.hupa.server.utils.TestUtils;
+import org.apache.hupa.shared.SConsts;
+import org.apache.hupa.shared.data.MessageDetails;
+
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.internet.MimeMessage;
+
+public class GetMessageDetailsHandlerTest extends HupaGuiceTestCase {
+
+ public void testTextDocumentToHtml() throws Exception {
+ String msg = "...\nhttp://www.example.com/path/action.do;s=1;a=2?p=abcd\n...";
+ String res = getDetailsHandler.txtDocumentToHtml(msg, "aFolder", 9999l);
+ assertNotSame(msg, res);
+ assertTrue(res.contains("onClick=\"openLink('http://"));
+
+ msg = "...\nnobody@subdomain.the-domain.org\n...";
+ res = getDetailsHandler.txtDocumentToHtml(msg, "aFolder", 9999l);
+ assertNotSame(msg, res);
+ assertTrue(res.contains("onClick=\"mailTo('nobody@"));
+
+ res = getDetailsHandler.txtDocumentToHtml("", "aFolder", 9999l);
+ assertTrue(res.length()==0);
+
+ msg = "...<atag>...";
+ res = getDetailsHandler.txtDocumentToHtml(msg, "aFolder", 9999l);
+ assertNotSame(msg, res);
+ assertEquals("...<atag>...", res);
+ }
+
+ public void testFilterHtmlDocument() throws Exception {
+ String msg = "<div>...\nhttp://whatever\n...</div>";
+ String res = getDetailsHandler.txtDocumentToHtml(msg, "aFolder", 9999l);
+ assertNotSame(msg, res);
+ assertTrue(res.contains("onClick=\"openLink('http://whatever"));
+
+ msg = "...\n<a\nhref=https://www.example.com/path/action.do;s=1;a=2?p=abcd\n...";
+ res = getDetailsHandler.filterHtmlDocument(msg, "aFolder", 9999l);
+ assertNotSame(msg, res);
+ assertTrue(res.contains("onClick=\"openLink('https://"));
+
+ msg = "...\n<a\nhref=mailTo:nobody@subdomain.the-domain.org\n...";
+ res = getDetailsHandler.filterHtmlDocument(msg, "aFolder", 9999l);
+ assertNotSame(msg, res);
+ assertTrue(res.contains("onClick=\"mailTo('nobody@"));
+
+ msg = "...\n...<img \n src=\"cid:1.1934304663@web28309.mail.ukl.yahoo.com\" width=200\n....";
+ res = getDetailsHandler.filterHtmlDocument(msg, "aFolder", 9999l);
+ assertNotSame(msg, res);
+ assertEquals("...\n...<img \n src='" +
+ SConsts.HUPA + SConsts.SERVLET_DOWNLOAD + "?"
+ + SConsts.PARAM_FOLDER + "=aFolder&"
+ + SConsts.PARAM_UID + "=9999&"
+ + SConsts.PARAM_NAME + "=1.1934304663@web28309.mail.ukl.yahoo.com' name='cid:1.1934304663@web28309.mail.ukl.yahoo.com' width=200\n....", res);
+
+ msg = "\n\n.... <Script \ntype=\"whatever\"\n>\nalert('hello');\n</script > ---\n\n";
+ res = getDetailsHandler.filterHtmlDocument(msg, "aFolder", 9999l);
+ assertNotSame(msg, res);
+
+ msg = "\n\n.... <a \nid=\"whatever\"\nonclick=\"alert('hello');\"\n</a > ---\n\n";
+ res = getDetailsHandler.filterHtmlDocument(msg, "aFolder", 9999l);
+ assertNotSame(msg, res);
+
+ msg = "\n\n.... <style \ntype=\"whatever\"\n>\n.a{};\n</Style > ---\n\n";
+ res = getDetailsHandler.filterHtmlDocument(msg, "aFolder", 9999l);
+ assertNotSame(msg, res);
+
+ res = getDetailsHandler.filterHtmlDocument("", "aFolder", 9999l);
+ assertTrue(res.length()==0);
+ }
+
+ public void testRegexEmailsInsideTagAttributes() {
+ String msg, res;
+ msg = ".. <a href=\"http://whatever?param1=whatever&email= dock@example.com¶m3\">..</a> ..";
+ res = getDetailsHandler.filterHtmlDocument(msg, "aFolder", 9999l);
+ assertFalse(res.contains("mailTo("));
+
+ msg = ".. <a href=bla > http://whatever?param1=whatever&email=dock@example.com¶m3 </a> ..";
+ res = getDetailsHandler.filterHtmlDocument(msg, "aFolder", 9999l);
+ assertFalse(res.contains("mailTo("));
+ assertFalse(res.contains("openLink("));
+
+ // FIXME: disabled until we improve performance parsing
+ // msg = ".. <div > http://whatever?param1=whatever&email=dock@example.com¶m3 <p> ..";
+ // res = getDetailsHandler.filterHtmlDocument(msg, "aFolder", 9999l);
+ // assertFalse(res.contains("mailTo("));
+ // assertTrue(res.contains("openLink("));
+
+ msg = "http://accounts.myspace.com.deaaaf.me.uk/msp/index.php?fuseaction=update&code=78E2BL6-EKY5L893K4MHSA-74ESO-D743U41GYB18J-FA18EI698V4M&email=somehone@somewere.com";
+ res = getDetailsHandler.txtDocumentToHtml(msg, "aFolder", 9999l);
+ assertFalse(res.contains("mailTo("));
+ assertTrue(res.contains("openLink("));
+ }
+
+ public void testFilterHtml_LargeBody_Performance() throws Exception {
+ // messages with large bodies should be processed fast
+ long start = System.currentTimeMillis();
+ loadMessageDetails("8.msg");
+ long end = System.currentTimeMillis();
+ assertTrue("Large message bodies should be filtered fast", (end - start) < 1000);
+ }
+
+ private MessageDetails loadMessageDetails(String msgFile) throws Exception {
+ return getDetailsHandler.mimeToDetails(TestUtils.loadMessageFromFile(session,msgFile), "theFolder", 9999l);
+ }
+
+ public void testMessageDetails_textPlain() throws Exception {
+ MessageDetails details = loadMessageDetails("0.msg");
+ assertTrue(details.getText().contains("demo message"));
+ }
+
+ public void testMessageDetails_multiparMixed() throws Exception {
+ MessageDetails details = loadMessageDetails("1.msg");
+ assertEquals(1, details.getMessageAttachments().size());
+ assertTrue(details.getText().contains("Regards"));
+ }
+
+ public void testMessageDetails_multiparAlternative() throws Exception {
+ MessageDetails details = loadMessageDetails("2.msg");
+ assertEquals(0, details.getMessageAttachments().size());
+ assertTrue(details.getText().length() > 0);
+ }
+
+ public void testMessageDetails_charsetIso() throws Exception {
+ MimeMessage message = TestUtils.loadMessageFromFile(session,"3.msg");
+ String from = message.getFrom()[0].toString();
+ assertTrue(from.contains("\u00AE"));
+
+ MessageDetails details = loadMessageDetails("3.msg");
+ assertEquals(0, details.getMessageAttachments().size());
+ assertTrue(details.getText().length() > 0);
+ }
+
+ public void testMessageDetails_textHtml() throws Exception {
+ MessageDetails details = loadMessageDetails("4.msg");
+ assertTrue(details.getText().length() > 0);
+ }
+
+ public void testMessageDetails_multiparMixed_multipartAlternative() throws Exception {
+ MessageDetails details = loadMessageDetails("6.msg");
+ assertEquals(1, details.getMessageAttachments().size());
+ assertTrue(details.getText().length() > 0);
+ }
+
+ public void testMessageDetails_multiparMixed_multipartAlternative_textAttachment() throws Exception {
+ MessageDetails details = loadMessageDetails("10.msg");
+ assertEquals(1, details.getMessageAttachments().size());
+ assertTrue(details.getText().contains("<span>"));
+ }
+
+ public void testMessageDetails_html_with_inline_images() throws Exception {
+ IMAPStore store = storeCache.get(testUser);
+
+ IMAPFolder serverfolder = (IMAPFolder)store.getFolder("WHATEVER");
+ serverfolder.create(Folder.HOLDS_MESSAGES);
+
+ MimeMessage msg = TestUtils.loadMessageFromFile(session,"7.msg");
+ serverfolder.addMessages(new Message[]{msg});
+
+ org.apache.hupa.shared.data.IMAPFolder clientfolder = new org.apache.hupa.shared.data.IMAPFolder("WHATEVER");
+ MessageDetails details = getDetailsHandler.exposeMessage(testUser, clientfolder, 0);
+
+ // inline images have to be downloaded from the server
+ assertTrue(details.getText().contains("img src=\'" +
+ SConsts.HUPA + SConsts.SERVLET_DOWNLOAD + "?" +
+ SConsts.PARAM_FOLDER + "=WHATEVER&" +
+ SConsts.PARAM_UID + "=0&" +
+ SConsts.PARAM_NAME + "=1.1934304663@web28309.mail.ukl.yahoo.com'"));
+
+ // inline images are not in the message list
+ assertEquals(0, details.getMessageAttachments().size());
+
+ }
+
+ public void testMessageDetails_links() throws Exception {
+ MessageDetails details = loadMessageDetails("2.msg");
+
+ String html = getDetailsHandler.filterHtmlDocument(details.getText(), "foldername", 111l);
+ assertFalse(html.contains("<script>"));
+ assertFalse(html.contains("<style>"));
+ assertTrue(html.contains("<a onClick=\"openLink('http://code.google.com/intl/es/webtoolkit/');return false;\" href=\"http://code.google.com/intl/es/webtoolkit/\""));
+ assertTrue(html.contains("<a onClick=\"mailTo('donald@example.com');return false;\" href=\"mailto:donald@example.com\""));
+ }
+
+}
Added: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/HandlersTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/HandlersTest.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/HandlersTest.java (added)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/HandlersTest.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,102 @@
+/****************************************************************
+ * 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.hupa.server.handler;
+
+import com.google.inject.Module;
+
+import com.sun.mail.imap.IMAPStore;
+
+import net.customware.gwt.dispatch.shared.ActionException;
+
+import org.apache.hupa.server.HupaGuiceTestCase;
+import org.apache.hupa.server.guice.GuiceServerTestModule;
+import org.apache.hupa.shared.data.IMAPFolder;
+import org.apache.hupa.shared.rpc.CreateFolder;
+import org.apache.hupa.shared.rpc.DeleteFolder;
+import org.apache.hupa.shared.rpc.FetchFolders;
+import org.apache.hupa.shared.rpc.FetchFoldersResult;
+
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+
+public class HandlersTest extends HupaGuiceTestCase {
+
+ /*
+ These tests should work with Courier, Gmail and any other real IMAP implementations
+ If you want to run these tests against your IMAP server do this:
+ 1.- Change properties and classes to do integration tests and
+ 2.- Be sure the user and password are set correctly
+ */
+ class MyModule extends GuiceServerTestModule {
+ public MyModule() {
+ // properties = courierProperties;
+ // properties = gmailProperties;
+ // logClass = LogProvider.class;
+ }
+ }
+
+ @Override
+ protected Module[] getModules() {
+ return new Module[]{new MyModule()};
+ }
+
+ public void testLoginAndFetchFolders() {
+ try {
+ org.apache.hupa.shared.rpc.LoginUser l = new org.apache.hupa.shared.rpc.LoginUser(testUser.getName(),testUser.getPassword());
+ loginUser.execute(l, null);
+ FetchFoldersResult result = fetchFoldersHandler.execute(new FetchFolders(), null);
+ assertNotNull(result);
+ } catch (ActionException e) {
+ e.printStackTrace();
+ fail("Shouldn't throw an exception");
+ }
+ }
+
+ public void testCreateAndDeleteFolder() throws MessagingException {
+ IMAPStore store = storeCache.get(testUser);
+
+ String folderName = testUser.getSettings().getInboxFolderName() + store.getDefaultFolder().getSeparator() + "newFolder";
+ IMAPFolder sFolder = new IMAPFolder();
+ sFolder.setFullName(folderName);
+
+ Folder f1 = store.getFolder(sFolder.getFullName());
+ assertFalse("not exists", f1.exists());
+
+ try {
+ createFolderHandler.execute(new CreateFolder(sFolder), null);
+ Folder f = store.getFolder(sFolder.getFullName());
+ assertTrue("exists", f.exists());
+ assertFalse("Not opened", f.isOpen());
+ f.open(Folder.READ_WRITE);
+ assertTrue("opened", f.isOpen());
+
+ Message[] msgs = f.getMessages();
+ assertEquals(0, msgs.length);
+
+ deleteFolderHandler.execute(new DeleteFolder(sFolder), null);
+ f = store.getFolder(sFolder.getFullName());
+ assertFalse("not exists",f.exists());
+
+ } catch (ActionException e) {
+ e.printStackTrace();
+ fail("Shouldn't throw an exception ");
+ }
+ }
+}
Copied: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/IdleHandlerTest.java (from r1516164, james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java)
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/IdleHandlerTest.java?p2=james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/IdleHandlerTest.java&p1=james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java&r1=1516164&r2=1516205&rev=1516205&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/IdleHandlerTest.java Wed Aug 21 16:35:16 2013
@@ -16,14 +16,24 @@
* specific language governing permissions and limitations *
* under the License. *
****************************************************************/
+package org.apache.hupa.server.handler;
-package org.apache.hupa.shared.exception;
+import net.customware.gwt.dispatch.shared.ActionException;
-public class InvalidSessionException extends HupaException{
+import org.apache.hupa.server.HupaGuiceTestCase;
+import org.apache.hupa.shared.rpc.Idle;
+import org.apache.hupa.shared.rpc.IdleResult;
- private static final long serialVersionUID = 995112620968798947L;
+public class IdleHandlerTest extends HupaGuiceTestCase {
- public InvalidSessionException(String message) {
- super(message);
+ public void testIdle() {
+ Idle action = new Idle();
+ try {
+ IdleResult result = idleHandler.execute(action, null);
+ assertNotNull(result);
+ } catch (ActionException e) {
+ e.printStackTrace();
+ fail();
+ }
}
}
Added: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/LoginUserHandlerTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/LoginUserHandlerTest.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/LoginUserHandlerTest.java (added)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/LoginUserHandlerTest.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,55 @@
+/****************************************************************
+ * 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.hupa.server.handler;
+
+import net.customware.gwt.dispatch.shared.ActionException;
+
+import org.apache.hupa.server.HupaGuiceTestCase;
+import org.apache.hupa.shared.SConsts;
+import org.apache.hupa.shared.data.User;
+import org.apache.hupa.shared.rpc.LoginUser;
+import org.apache.hupa.shared.rpc.LoginUserResult;
+
+public class LoginUserHandlerTest extends HupaGuiceTestCase {
+
+ public void testInvalidLogin() {
+ httpSession.setAttribute("Attribute", "Value");
+ try {
+ loginUser.execute(new LoginUser("invalid","invalid"), null);
+ fail("Should throw an exception");
+ } catch (ActionException e) {
+ }
+ assertNull("No user should be stored in session", httpSession.getAttribute(SConsts.USER_SESS_ATTR));
+ assertNull("Attributes should be removed", httpSession.getAttribute("Attribute"));
+ }
+
+ public void testValidLogin() {
+ try {
+ LoginUserResult result = loginUser.execute(new LoginUser(testUser.getName(), testUser.getPassword()), null);
+ User u = result.getUser();
+ assertEquals("Authenticated", true, u.getAuthenticated());
+ assertEquals("Authenticated", testUser.getName(), u.getName());
+ assertEquals("Authenticated", testUser.getPassword(), u.getPassword());
+ assertEquals("User stored in session", u, httpSession.getAttribute(SConsts.USER_SESS_ATTR));
+ } catch (ActionException e) {
+ e.printStackTrace();
+ fail("Should throw an exception");
+ }
+ }
+}
Copied: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/LogoutUserHandlerTest.java (from r1516164, james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java)
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/LogoutUserHandlerTest.java?p2=james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/LogoutUserHandlerTest.java&p1=james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java&r1=1516164&r2=1516205&rev=1516205&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/LogoutUserHandlerTest.java Wed Aug 21 16:35:16 2013
@@ -1,29 +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.hupa.shared.exception;
-
-public class InvalidSessionException extends HupaException{
-
- private static final long serialVersionUID = 995112620968798947L;
-
- public InvalidSessionException(String message) {
- super(message);
- }
-}
+/****************************************************************
+ * 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.hupa.server.handler;
+
+import net.customware.gwt.dispatch.shared.ActionException;
+
+import org.apache.hupa.server.HupaGuiceTestCase;
+import org.apache.hupa.shared.SConsts;
+import org.apache.hupa.shared.rpc.LogoutUser;
+import org.apache.hupa.shared.rpc.LogoutUserResult;
+
+public class LogoutUserHandlerTest extends HupaGuiceTestCase {
+
+ public void testLogout() {
+ try {
+ httpSession.setAttribute("Attribute", "Value");
+ LogoutUserResult result = logoutUser.execute(new LogoutUser(), null);
+ assertFalse("Not authenticated anymore", result.getUser().getAuthenticated());
+ assertNull("User should be removed", httpSession.getAttribute(SConsts.USER_SESS_ATTR));
+ assertNull("Attributes should be removed", httpSession.getAttribute("Attribute"));
+ } catch (ActionException e) {
+ e.printStackTrace();
+ fail();
+ }
+
+ }
+}
Added: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/ReplyMessageHandlerTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/ReplyMessageHandlerTest.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/ReplyMessageHandlerTest.java (added)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/handler/ReplyMessageHandlerTest.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,83 @@
+/****************************************************************
+ * 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.hupa.server.handler;
+
+import javax.mail.Message;
+
+import org.apache.hupa.server.FileItemRegistry;
+import org.apache.hupa.server.HupaGuiceTestCase;
+import org.apache.hupa.server.mock.MockIMAPFolder;
+import org.apache.hupa.server.mock.MockIMAPStore;
+import org.apache.hupa.server.utils.SessionUtils;
+import org.apache.hupa.server.utils.TestUtils;
+import org.apache.hupa.shared.data.IMAPFolder;
+import org.apache.hupa.shared.data.SMTPMessage;
+import org.apache.hupa.shared.rpc.ReplyMessage;
+
+import com.sun.mail.imap.IMAPStore;
+
+public class ReplyMessageHandlerTest extends HupaGuiceTestCase {
+
+ public void testForwardMessage() throws Exception {
+ IMAPStore store = storeCache.get(testUser);
+
+ FileItemRegistry registry = SessionUtils.getSessionRegistry(logger, httpSession);
+
+ MockIMAPFolder sentbox = (MockIMAPFolder) store.getFolder(MockIMAPStore.MOCK_SENT_FOLDER);
+ assertTrue(sentbox.getMessages().length == 0);
+
+ MockIMAPFolder inbox = (MockIMAPFolder) store.getFolder(MockIMAPStore.MOCK_INBOX_FOLDER);
+ assertTrue(inbox.getMessages().length >= 0);
+
+ // Create a mime message with 2 attachments and 1 inline image, and put it in the inbox
+ Message message = TestUtils.createMockMimeMessage(session, 2);
+ TestUtils.addMockAttachment(message, "inlineImage.jpg", true);
+
+ inbox.appendMessages(new Message[]{message});
+ long msgUid = inbox.getUID(message);
+ message = inbox.getMessageByUID(msgUid);
+ assertNotNull(message);
+
+ String expected = "multipart/mixed\n"
+ + " multipart/alternative\n"
+ + " text/plain\n"
+ + " text/html\n"
+ + " mock/attachment => file_1.bin\n"
+ + " mock/attachment => file_2.bin\n"
+ + " image/mock => inlineImage.jpg\n";
+ assertEquals(expected, TestUtils.summaryzeContent(message).toString());
+
+ // Create a reply user action with an uploaded message
+ SMTPMessage smtpmsg = TestUtils.createMockSMTPMessage(registry, 1);
+ ReplyMessage action = new ReplyMessage(smtpmsg, new IMAPFolder(inbox.getFullName()), msgUid);
+
+ message = reMsgHndl.createMessage(session, action);
+ message = reMsgHndl.fillBody(message, action);
+
+ // The final message has to include the file uploaded by the user and the inline image
+ expected = "multipart/mixed\n"
+ + " multipart/alternative\n"
+ + " text/plain\n"
+ + " text/html\n"
+ + " image/mock => inlineImage.jpg\n"
+ + " mock/attachment => uploadedFile_1.bin\n";
+
+ assertEquals(expected, TestUtils.summaryzeContent(message).toString());
+ }
+}
Copied: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/mock/MockImapFolderTest.java (from r1516164, james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java)
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/mock/MockImapFolderTest.java?p2=james/hupa/trunk/server/src/test/java/org/apache/hupa/server/mock/MockImapFolderTest.java&p1=james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java&r1=1516164&r2=1516205&rev=1516205&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/mock/MockImapFolderTest.java Wed Aug 21 16:35:16 2013
@@ -16,14 +16,31 @@
* specific language governing permissions and limitations *
* under the License. *
****************************************************************/
+package org.apache.hupa.server.mock;
-package org.apache.hupa.shared.exception;
+import java.net.URL;
-public class InvalidSessionException extends HupaException{
+import javax.mail.Folder;
+import javax.mail.Message;
- private static final long serialVersionUID = 995112620968798947L;
+import org.apache.hupa.server.HupaGuiceTestCase;
- public InvalidSessionException(String message) {
- super(message);
+public class MockImapFolderTest extends HupaGuiceTestCase {
+
+ public void testReadMessageFile() throws Exception {
+ URL url = Thread.currentThread().getContextClassLoader().getResource(MockIMAPFolder.MOCK_MESSAGES_LOCATION + "0.msg");
+ assertNotNull("There aren't message files for demo mode, check that the files mime/\\d.msg are in your classpath", url);
+ }
+
+ public void testLoadMessageFiles() throws Exception {
+ MockIMAPStore store = new MockIMAPStore(session, null);
+ MockIMAPFolder folder = new MockIMAPFolder("WHATEVER", store);
+ folder.create(Folder.HOLDS_MESSAGES);
+ folder.loadDemoMessages(session);
+ assertTrue(folder.getMessages().length > 0);
+ for (Message m: folder.getMessages()) {
+ assertEquals(m, folder.getMessageByUID(folder.getUID(m)));
+ }
}
+
}
Added: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/preferences/InImapUserPreferencesStorageTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/preferences/InImapUserPreferencesStorageTest.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/preferences/InImapUserPreferencesStorageTest.java (added)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/preferences/InImapUserPreferencesStorageTest.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,260 @@
+/****************************************************************
+ * 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.hupa.server.preferences;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Properties;
+
+import javax.mail.Flags;
+import javax.mail.Folder;
+import javax.mail.Session;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.logging.Log;
+import org.apache.hupa.server.HupaGuiceTestCase;
+import org.apache.hupa.server.IMAPStoreCache;
+import org.apache.hupa.server.guice.GuiceServerTestModule;
+import org.apache.hupa.server.guice.demo.DemoGuiceServerModule.DemoIMAPStoreCache;
+import org.apache.hupa.server.guice.providers.DefaultUserSettingsProvider;
+import org.apache.hupa.server.guice.providers.JavaMailSessionProvider;
+import org.apache.hupa.server.handler.AbstractSendMessageHandler;
+import org.apache.hupa.server.handler.ContactsHandler;
+import org.apache.hupa.server.handler.CreateFolderHandler;
+import org.apache.hupa.server.handler.DeleteFolderHandler;
+import org.apache.hupa.server.handler.DeleteMessageByUidHandler;
+import org.apache.hupa.server.handler.FetchFoldersHandler;
+import org.apache.hupa.server.handler.FetchMessagesHandler;
+import org.apache.hupa.server.handler.ForwardMessageHandler;
+import org.apache.hupa.server.handler.GetMessageDetailsHandler;
+import org.apache.hupa.server.handler.IdleHandler;
+import org.apache.hupa.server.handler.LoginUserHandler;
+import org.apache.hupa.server.handler.LogoutUserHandler;
+import org.apache.hupa.server.handler.ReplyMessageHandler;
+import org.apache.hupa.server.handler.SendMessageHandler;
+import org.apache.hupa.server.mock.MockConstants;
+import org.apache.hupa.server.mock.MockHttpSessionProvider;
+import org.apache.hupa.server.mock.MockIMAPStore;
+import org.apache.hupa.server.mock.MockLogProvider;
+import org.apache.hupa.server.utils.ConfigurationProperties;
+import org.apache.hupa.server.utils.SessionUtils;
+import org.apache.hupa.server.utils.TestUtils;
+import org.apache.hupa.shared.data.IMAPFolder;
+import org.apache.hupa.shared.data.SMTPMessage;
+import org.apache.hupa.shared.data.Settings;
+import org.apache.hupa.shared.data.User;
+import org.apache.hupa.shared.rpc.Contacts;
+import org.apache.hupa.shared.rpc.FetchMessages;
+import org.apache.hupa.shared.rpc.FetchMessagesResult;
+import org.apache.hupa.shared.rpc.SendMessage;
+
+import com.google.inject.Module;
+import com.google.inject.Singleton;
+import com.google.inject.name.Names;
+import com.sun.mail.imap.IMAPStore;
+
+public class InImapUserPreferencesStorageTest extends HupaGuiceTestCase {
+
+ /*
+ These tests should work with Courier, Gmail and any other real IMAP implementation.
+ So, if you wanted to run these tests against your IMAP server do this:
+ - Set the correct properties.
+ - Be sure the user and password are set correctly
+ - Comment the delay
+ */
+ static class MyModule extends GuiceServerTestModule {
+ public MyModule() {
+ // Select a valid imap provider, comment all to use Mock
+ // properties = courierProperties;
+ // properties = gmailProperties;
+ // properties = jamesProperties;
+
+ // Uncomment to use production logger
+ // logClass = LogProvider.class;
+
+ // Change the default delay to run test faster
+ InImapUserPreferencesStorage.IMAP_SAVE_DELAY = 400;
+ }
+
+ @Override
+ protected void configureHandlers() {
+ Properties p = MockConstants.mockProperties;
+ ConfigurationProperties.validateProperties(p);
+ Names.bindProperties(binder(), p);
+
+ bind(Session.class).toProvider(JavaMailSessionProvider.class);
+ bind(HttpSession.class).toProvider(MockHttpSessionProvider.class);
+ bind(Settings.class).toProvider(DefaultUserSettingsProvider.class).in(Singleton.class);
+ bind(Log.class).toProvider(MockLogProvider.class).in(Singleton.class);
+
+ bind(IMAPStore.class).to(MockIMAPStore.class);
+ bind(IMAPStoreCache.class).to(DemoIMAPStoreCache.class).in(Singleton.class);
+
+ bind(LoginUserHandler.class);
+ bind(LogoutUserHandler.class);
+ bind(IdleHandler.class);
+
+ bind(FetchFoldersHandler.class);
+ bind(CreateFolderHandler.class);
+ bind(DeleteFolderHandler.class);
+ bind(FetchMessagesHandler.class);
+ bind(DeleteMessageByUidHandler.class);
+ bind(GetMessageDetailsHandler.class);
+ bind(AbstractSendMessageHandler.class).to(SendMessageHandler.class);
+ bind(SendMessageHandler.class);
+ bind(ReplyMessageHandler.class);
+ bind(ForwardMessageHandler.class);
+
+ bindHandler(Contacts.class, ContactsHandler.class);
+ bindHandler(SendMessage.class, SendMessageHandler.class);
+
+ bind(UserPreferencesStorage.class).to(InImapUserPreferencesStorage.class);
+
+ bind(User.class).to(TestUser.class).in(Singleton.class);
+ }
+ }
+
+ @Override
+ protected Module[] getModules() {
+ return new Module[]{new MyModule()};
+ }
+
+ /**
+ * Delete all messages in user's dratfs folder
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ Folder f = storeCache.get(testUser).getFolder(testUser.getSettings().getDraftsFolderName());
+ if (f.exists() && f.getMessageCount() > 0) {
+ f.open(Folder.READ_WRITE);
+ f.setFlags(f.getMessages(), new Flags(Flags.Flag.DELETED), true);
+ f.close(true);
+ }
+ }
+
+ public void testAnySerializableObjectCanBeSavedInIMAP() throws Exception {
+ IMAPStore store = storeCache.get(testUser);
+ String folderName = testUser.getSettings().getInboxFolderName() + store.getDefaultFolder().getSeparator() + "aFolder";
+ String magicSubject = "magicSubject";
+ Object objectOne = new String("a serializable object");
+ Object objectTwo = new String("another serializable object");
+
+ // Remove the folder if exist
+ Folder f = store.getFolder(folderName);
+ if (f.exists()) {
+ f.delete(true);
+ }
+
+ // Check saving an object when the folder doesnt exist
+ Object o = InImapUserPreferencesStorage.readUserPreferencesFromIMAP(logger, testUser, store, folderName, magicSubject);
+ assertNull(o);
+
+ InImapUserPreferencesStorage.saveUserPreferencesInIMAP(logger, testUser, session, store, folderName, magicSubject, objectOne);
+
+ Folder folder = store.getFolder(folderName);
+ assertNotNull(folder);
+ assertEquals(1, folder.getMessageCount());
+
+ o = InImapUserPreferencesStorage.readUserPreferencesFromIMAP(logger, testUser, store, folderName, magicSubject);
+ assertNotNull(o);
+ assertEquals(objectOne, o);
+
+ // Check saving an object when the folder already exist
+ InImapUserPreferencesStorage.saveUserPreferencesInIMAP(logger, testUser, session, store, folderName, magicSubject, objectTwo);
+ folder = store.getFolder(folderName);
+ assertEquals(1, folder.getMessageCount());
+ o = InImapUserPreferencesStorage.readUserPreferencesFromIMAP(logger, testUser, store, folderName, magicSubject);
+ assertEquals(objectTwo, o);
+
+ // Remove the folder
+ store.getFolder(folderName).delete(true);
+ }
+
+ public void testFetchMessagesFillsTheContactsListAndItIsSavedAsynchronously() throws Exception {
+ IMAPStore store = storeCache.get(testUser);
+ String folderName = testUser.getSettings().getDraftsFolderName();
+
+ // Setup deletes all Drafts messages and contacts in session
+ assertEquals(0, userPreferences.getContacts().length);
+ Folder folder = store.getFolder(folderName);
+ if (folder.exists())
+ assertTrue(folder.getMessageCount() == 0);
+
+ // Fetch inbox messages
+ IMAPFolder cFolder = new IMAPFolder(testUser.getSettings().getInboxFolderName());
+ FetchMessagesResult result = fetchMessagesHandler.execute(new FetchMessages(cFolder, 0, 10, null), null);
+
+ // Could be possible that there insn't any message in inbox
+ if (result.getRealCount() > 0) {
+ int contactsCount = userPreferences.getContacts().length;
+ assertTrue(contactsCount > 0);
+
+ // The imap is saved asynchronously after a delay, so the folder exists after a while
+ folder = store.getFolder(folderName);
+ if (folder.exists())
+ assertTrue(folder.getMessageCount() == 0);
+
+ Thread.sleep(InImapUserPreferencesStorage.IMAP_SAVE_DELAY + 500);
+ folder = store.getFolder(folderName);
+ assertNotNull(folder);
+ assertTrue(folder.exists());
+ assertEquals(1, folder.getMessageCount());
+
+ // When data is deleted from session, contacts came from imap
+ httpSession.removeAttribute(InImapUserPreferencesStorage.USER_ATTR);
+ assertEquals(contactsCount, userPreferences.getContacts().length );
+ }
+ }
+
+ public void testSendMessagesAddContactsToList() throws Exception {
+ // Setup deletes all Drafts messages and contacts in session
+ assertEquals(0, userPreferences.getContacts().length);
+
+ // Send an email to only one email
+ SMTPMessage smtpmsg = TestUtils.createMockSMTPMessage(SessionUtils.getSessionRegistry(logger, httpSession), 2);
+ smtpmsg.setFrom(testUser.getName());
+ smtpmsg.setTo(new ArrayList<String>(Arrays.asList(testUser.getName())));
+ smtpmsg.setCc(new ArrayList<String>());
+ smtpmsg.setBcc(new ArrayList<String>());
+ SendMessage action = new SendMessage(smtpmsg);
+ sendMessageHandler.execute(action, null);
+
+ // The email has to be added to the contact list
+ assertEquals(1, userPreferences.getContacts().length);
+
+ // The imap is saved asynchronously after a delay, so the folder exists after a while
+ String folderName = testUser.getSettings().getDraftsFolderName();
+ Folder folder = store.getFolder(folderName);
+ folder = store.getFolder(folderName);
+ if (folder.exists())
+ assertTrue(folder.getMessageCount() == 0);
+
+ Thread.sleep(InImapUserPreferencesStorage.IMAP_SAVE_DELAY + 500);
+ folder = store.getFolder(folderName);
+ assertNotNull(folder);
+ assertTrue(folder.exists());
+ assertEquals(1, folder.getMessageCount());
+
+ // When data is deleted from session, contacts came from imap
+ httpSession.removeAttribute(InImapUserPreferencesStorage.USER_ATTR);
+ assertEquals(1, userPreferences.getContacts().length);
+ }
+
+}
Added: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/preferences/InSessionUserPreferencesStorageTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/preferences/InSessionUserPreferencesStorageTest.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/preferences/InSessionUserPreferencesStorageTest.java (added)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/preferences/InSessionUserPreferencesStorageTest.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,64 @@
+/****************************************************************
+ * 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.hupa.server.preferences;
+
+import org.apache.hupa.server.HupaGuiceTestCase;
+import org.apache.hupa.server.handler.FetchFoldersHandler;
+import org.apache.hupa.server.handler.FetchMessagesHandler;
+import org.apache.hupa.server.utils.SessionUtils;
+import org.apache.hupa.server.utils.TestUtils;
+import org.apache.hupa.shared.data.IMAPFolder;
+import org.apache.hupa.shared.data.SMTPMessage;
+import org.apache.hupa.shared.rpc.FetchFolders;
+import org.apache.hupa.shared.rpc.FetchMessages;
+import org.apache.hupa.shared.rpc.FetchMessagesResult;
+import org.apache.hupa.shared.rpc.SendMessage;
+
+public class InSessionUserPreferencesStorageTest extends HupaGuiceTestCase {
+
+ public void setUp() throws Exception {
+ super.setUp();
+ httpSession.removeAttribute(InImapUserPreferencesStorage.CONTACTS_ATTR);
+ }
+
+ public void testFetchMessagesFillsContactsList() throws Exception {
+ assertEquals(0, userPreferences.getContacts().length);
+
+ FetchFoldersHandler fetchFoldersHandler = injector.getInstance(FetchFoldersHandler.class);
+ fetchFoldersHandler.execute(new FetchFolders(), null);
+
+ IMAPFolder folder = new IMAPFolder(testUser.getSettings().getInboxFolderName());
+ FetchMessagesHandler fetchMessagesHandler = injector.getInstance(FetchMessagesHandler.class);
+ FetchMessagesResult result = fetchMessagesHandler.execute(new FetchMessages(folder, 0, 10, null), null);
+
+ assertTrue(result.getRealCount()>1);
+ }
+
+ public void testSendMessagesAddContactsToList() throws Exception {
+ assertEquals(0, userPreferences.getContacts().length);
+
+ SMTPMessage smtpmsg = TestUtils.createMockSMTPMessage(SessionUtils.getSessionRegistry(logger, httpSession), 2);
+ SendMessage action = new SendMessage(smtpmsg);
+ sendMessageHandler.execute(action, null);
+
+ assertEquals(3, userPreferences.getContacts().length);
+ }
+
+}
Copied: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/servlet/DownloadAttachmentServletTest.java (from r1516164, james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java)
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/servlet/DownloadAttachmentServletTest.java?p2=james/hupa/trunk/server/src/test/java/org/apache/hupa/server/servlet/DownloadAttachmentServletTest.java&p1=james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java&r1=1516164&r2=1516205&rev=1516205&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/exception/InvalidSessionException.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/servlet/DownloadAttachmentServletTest.java Wed Aug 21 16:35:16 2013
@@ -17,13 +17,30 @@
* under the License. *
****************************************************************/
-package org.apache.hupa.shared.exception;
+package org.apache.hupa.server.servlet;
-public class InvalidSessionException extends HupaException{
+import org.apache.hupa.server.HupaGuiceTestCase;
+import org.apache.hupa.server.utils.MessageUtils;
+import org.apache.hupa.server.utils.TestUtils;
- private static final long serialVersionUID = 995112620968798947L;
+import javax.mail.Part;
+import javax.mail.internet.MimeMessage;
- public InvalidSessionException(String message) {
- super(message);
+
+public class DownloadAttachmentServletTest extends HupaGuiceTestCase {
+
+ public void testDownloadAttachmentByName() throws Exception {
+ MimeMessage message = TestUtils.loadMessageFromFile(session, "7.msg");
+ Part part = MessageUtils.handleMultiPart(logger, message
+ .getContent(), "Image.4FB480B138F7456382ABBD1EE7B0748A");
+ assertNotNull(part);
}
+
+ public void testDownloadAttachmentByContentId() throws Exception {
+ MimeMessage message = TestUtils.loadMessageFromFile(session, "7.msg");
+ Part part = MessageUtils.handleMultiPart(logger, message
+ .getContent(), "1.1934304663@web28309.mail.ukl.yahoo.com");
+ assertNotNull(part);
+ }
+
}
Added: james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/data/AbstractMessage.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/data/AbstractMessage.java?rev=1516205&view=auto
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/data/AbstractMessage.java (added)
+++ james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/data/AbstractMessage.java Wed Aug 21 16:35:16 2013
@@ -0,0 +1,128 @@
+/****************************************************************
+ * 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.hupa.shared.data;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+
+public class AbstractMessage implements Serializable{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 5208272852772006815L;
+ private String from;
+ private String subject;
+ private String replyto;
+ private ArrayList<String> to;
+ private ArrayList<String> cc;
+ private boolean hasAttachment;
+
+ public String toString() {
+ StringBuffer toList = new StringBuffer("");
+ if (to != null)
+ for (String s: to)
+ toList.append(s).append(" ");
+
+ StringBuffer ccList = new StringBuffer("");
+ if (cc != null)
+ for (String s: cc)
+ ccList.append(s).append(" ");
+
+ return "From='" + from
+ + "' To='" + toList.toString()
+ + "' CC='" + ccList.toString()
+ + "' ReplyTo='" + (replyto == null ? "": replyto)
+ + "' Subject='" + subject
+ + "' Attachments=" + hasAttachment;
+ }
+
+
+ public boolean hasAttachment() {
+ return hasAttachment;
+ }
+
+ public void setHasAttachments(boolean hasAttachments) {
+ this.hasAttachment = hasAttachments;
+ }
+
+ /**
+ * Set the From: header field
+ *
+ * @param from
+ */
+ public void setFrom(String from) {
+ this.from = from;
+ }
+
+ /**
+ * Return the From: header field
+ *
+ * @return from
+ */
+ public String getFrom() {
+ return from;
+ }
+
+
+ public void setCc(ArrayList<String> cc) {
+ this.cc = cc;
+ }
+
+ public ArrayList<String> getCc() {
+ return cc;
+ }
+
+ /**
+ * Set the Subject: header field
+ *
+ * @param subject
+ */
+ public void setSubject(String subject) {
+ this.subject = subject;
+ }
+
+ /**
+ * Return the Subject: header field
+ *
+ * @return subject
+ */
+ public String getSubject() {
+ return subject;
+ }
+
+ public ArrayList<String> getTo() {
+ return to;
+ }
+
+ public void setTo(ArrayList<String> to) {
+ this.to = to;
+ }
+
+ public String getReplyto() {
+ return replyto;
+ }
+
+ public void setReplyto(String replyto) {
+ this.replyto = replyto;
+ }
+
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org