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 ma...@apache.org on 2014/03/20 09:16:10 UTC
svn commit: r1579559 [16/23] - in /james/hupa/trunk: ./ client/
client/src/main/java/com/google/web/bindery/requestfactory/server/
client/src/main/java/org/apache/hupa/
client/src/main/java/org/apache/hupa/client/
client/src/main/java/org/apache/hupa/c...
Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/HupaGuiceTestCase.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/HupaGuiceTestCase.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/HupaGuiceTestCase.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/HupaGuiceTestCase.java Thu Mar 20 08:16:02 2014
@@ -55,19 +55,19 @@ import com.sun.mail.imap.IMAPStore;
public class HupaGuiceTestCase {
protected Injector injector = Guice.createInjector(getModules());
-
- protected CreateFolderService createFolderService;
- protected FetchFoldersService fetchFoldersService;
- protected FetchMessagesService fetchMessagesService;
- protected DeleteFolderService deleteFolderService;
- protected DeleteMessageByUidService deleteMessageByUidService;
- protected GetMessageDetailsServiceImpl getMessageDetailsService;
- protected LoginUserService loginUserService;
- protected LogoutUserService logoutUserService;
- protected SendReplyMessageServiceImpl sendReplyMessageService;
- protected SendMessageBaseServiceImpl sendMessageService;
-
- protected Log logger;
+
+ protected CreateFolderService createFolderService;
+ protected FetchFoldersService fetchFoldersService;
+ protected FetchMessagesService fetchMessagesService;
+ protected DeleteFolderService deleteFolderService;
+ protected DeleteMessageByUidService deleteMessageByUidService;
+ protected GetMessageDetailsServiceImpl getMessageDetailsService;
+ protected LoginUserService loginUserService;
+ protected LogoutUserService logoutUserService;
+ protected SendReplyMessageServiceImpl sendReplyMessageService;
+ protected SendMessageBaseServiceImpl sendMessageService;
+
+ protected Log logger;
protected IMAPStoreCache storeCache;
protected User testUser;
protected UserPreferencesStorage userPreferences;
@@ -77,26 +77,26 @@ public class HupaGuiceTestCase {
protected Module[] getModules() {
return new Module[]{new GuiceServerTestModule()};
}
-
+
protected FileItemRegistry registry;
-
+
@Before
public void setUp(){
try {
- createFolderService = injector.getInstance(CreateFolderServiceImpl.class);
- fetchFoldersService = injector.getInstance(FetchFoldersServiceImpl.class);
- fetchMessagesService = injector.getInstance(FetchMessagesServiceImpl.class);
- deleteFolderService = injector.getInstance(DeleteFolderServiceImpl.class);
- deleteMessageByUidService = injector.getInstance(DeleteMessageByUidServiceImpl.class);
- getMessageDetailsService = injector.getInstance(GetMessageDetailsServiceImpl.class);
- loginUserService = injector.getInstance(LoginUserServiceImpl.class);
- logoutUserService = injector.getInstance(LogoutUserServiceImpl.class);
- sendReplyMessageService = injector.getInstance(SendReplyMessageServiceImpl.class);
- sendMessageService = injector.getInstance(SendMessageBaseServiceImpl.class);
-
- logger = injector.getInstance(Log.class);
+ createFolderService = injector.getInstance(CreateFolderServiceImpl.class);
+ fetchFoldersService = injector.getInstance(FetchFoldersServiceImpl.class);
+ fetchMessagesService = injector.getInstance(FetchMessagesServiceImpl.class);
+ deleteFolderService = injector.getInstance(DeleteFolderServiceImpl.class);
+ deleteMessageByUidService = injector.getInstance(DeleteMessageByUidServiceImpl.class);
+ getMessageDetailsService = injector.getInstance(GetMessageDetailsServiceImpl.class);
+ loginUserService = injector.getInstance(LoginUserServiceImpl.class);
+ logoutUserService = injector.getInstance(LogoutUserServiceImpl.class);
+ sendReplyMessageService = injector.getInstance(SendReplyMessageServiceImpl.class);
+ sendMessageService = injector.getInstance(SendMessageBaseServiceImpl.class);
+
+ logger = injector.getInstance(Log.class);
storeCache = injector.getInstance(IMAPStoreCache.class);
userPreferences = injector.getInstance(UserPreferencesStorage.class);
@@ -109,7 +109,7 @@ public class HupaGuiceTestCase {
registry = SessionUtils.getSessionRegistry(logger, httpSession);
} catch (Exception e) {
- e.printStackTrace();
+ e.printStackTrace();
}
}
}
Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/GuiceServerTestModule.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/GuiceServerTestModule.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/GuiceServerTestModule.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/GuiceServerTestModule.java Thu Mar 20 08:16:02 2014
@@ -98,8 +98,8 @@ public class GuiceServerTestModule exten
protected Class<? extends UserPreferencesStorage> userPreferencesStorageClass = InSessionUserPreferencesStorage.class;
protected Class<? extends Provider<Log>> logProviderClass = MockLogProvider.class;
protected Properties properties = MockConstants.mockProperties;
- @Override
- protected void configure() {
+ @Override
+ protected void configure() {
ConfigurationProperties.validateProperties(properties);
Names.bindProperties(binder(), properties);
@@ -108,7 +108,7 @@ public class GuiceServerTestModule exten
bind(Settings.class).toProvider(DefaultUserSettingsProvider.class);
bind(Log.class).toProvider(logProviderClass).in(Singleton.class);
-
+
if (properties == MockConstants.mockProperties) {
bind(IMAPStoreCache.class).to(DemoIMAPStoreCache.class).in(
Singleton.class);
@@ -120,67 +120,67 @@ public class GuiceServerTestModule exten
bind(MailHeaderImpl.class);
-
- bind(UserImpl.class);
- bind(ImapFolder.class).to(ImapFolderImpl.class);
- bind(TagImpl.class);
- bind(MessageDetailsImpl.class);
- bind(MessageAttachmentImpl.class);
- bind(SmtpMessageImpl.class);
-
- bind(CreateFolderAction.class).to(CreateFolderActionImpl.class);
- bind(GenericResultImpl.class);
- bind(FetchMessagesActionImpl.class);
- bind(FetchMessagesResultImpl.class);
-// bind(CreateFolderActionImpl.class);
- bind(DeleteFolderActionImpl.class);
- bind(RenameFolderActionImpl.class);
- bind(DeleteMessageAllActionImpl.class);
- bind(DeleteMessageByUidActionImpl.class);
- bind(GetMessageDetailsActionImpl.class);
- bind(GetMessageDetailsResultImpl.class);
- bind(SendMessageActionImpl.class);
- bind(SendForwardMessageActionImpl.class);
- bind(SendReplyMessageActionImpl.class);
- bind(GetMessageRawActionImpl.class);
- bind(GetMessageRawResultImpl.class);
- bind(LogoutUserActionImpl.class);
- bind(MoveMessageActionImpl.class);
- bind(SetFlagActionImpl.class);
-
-
-
- bind(CheckSessionServiceImpl.class);
- bind(LoginUserServiceImpl.class);
- bind(ImapFolderServiceImpl.class);
- bind(FetchFoldersServiceImpl.class);
- bind(FetchMessagesServiceImpl.class);
- bind(CreateFolderServiceImpl.class);
- bind(DeleteFolderServiceImpl.class);
- bind(RenameFolderServiceImpl.class);
- bind(DeleteMessageAllServiceImpl.class);
- bind(DeleteMessageByUidServiceImpl.class);
- bind(GetMessageDetailsServiceImpl.class);
- bind(SendMessageBaseServiceImpl.class);
- bind(SendForwardMessageServiceImpl.class);
- bind(SendReplyMessageServiceImpl.class);
- bind(GetMessageRawServiceImpl.class);
- bind(LogoutUserServiceImpl.class);
- bind(MoveMessageServiceImpl.class);
- bind(SetFlagServiceImpl.class);
-
+
+ bind(UserImpl.class);
+ bind(ImapFolder.class).to(ImapFolderImpl.class);
+ bind(TagImpl.class);
+ bind(MessageDetailsImpl.class);
+ bind(MessageAttachmentImpl.class);
+ bind(SmtpMessageImpl.class);
+
+ bind(CreateFolderAction.class).to(CreateFolderActionImpl.class);
+ bind(GenericResultImpl.class);
+ bind(FetchMessagesActionImpl.class);
+ bind(FetchMessagesResultImpl.class);
+// bind(CreateFolderActionImpl.class);
+ bind(DeleteFolderActionImpl.class);
+ bind(RenameFolderActionImpl.class);
+ bind(DeleteMessageAllActionImpl.class);
+ bind(DeleteMessageByUidActionImpl.class);
+ bind(GetMessageDetailsActionImpl.class);
+ bind(GetMessageDetailsResultImpl.class);
+ bind(SendMessageActionImpl.class);
+ bind(SendForwardMessageActionImpl.class);
+ bind(SendReplyMessageActionImpl.class);
+ bind(GetMessageRawActionImpl.class);
+ bind(GetMessageRawResultImpl.class);
+ bind(LogoutUserActionImpl.class);
+ bind(MoveMessageActionImpl.class);
+ bind(SetFlagActionImpl.class);
+
+
+
+ bind(CheckSessionServiceImpl.class);
+ bind(LoginUserServiceImpl.class);
+ bind(ImapFolderServiceImpl.class);
+ bind(FetchFoldersServiceImpl.class);
+ bind(FetchMessagesServiceImpl.class);
+ bind(CreateFolderServiceImpl.class);
+ bind(DeleteFolderServiceImpl.class);
+ bind(RenameFolderServiceImpl.class);
+ bind(DeleteMessageAllServiceImpl.class);
+ bind(DeleteMessageByUidServiceImpl.class);
+ bind(GetMessageDetailsServiceImpl.class);
+ bind(SendMessageBaseServiceImpl.class);
+ bind(SendForwardMessageServiceImpl.class);
+ bind(SendReplyMessageServiceImpl.class);
+ bind(GetMessageRawServiceImpl.class);
+ bind(LogoutUserServiceImpl.class);
+ bind(MoveMessageServiceImpl.class);
+ bind(SetFlagServiceImpl.class);
+
bind(FetchFoldersService.class).to(FetchFoldersServiceImpl.class);
bind(DownloadAttachmentServlet.class).in(Singleton.class);
bind(UploadAttachmentServlet.class).in(Singleton.class);
bind(MessageSourceServlet.class).in(Singleton.class);
-
+
bind(UserPreferencesStorage.class).to(userPreferencesStorageClass);
bind(User.class).to(TestUser.class).in(Singleton.class);
-
- }
-
+
+ }
+
@Provides
protected Properties getProperties() {
System.out.println("getProperties");
Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/ServerModulTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/ServerModulTest.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/ServerModulTest.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/guice/ServerModulTest.java Thu Mar 20 08:16:02 2014
@@ -36,9 +36,9 @@ import org.junit.Test;
public class ServerModulTest {
private String tmpDir = System.getProperty("java.io.tmpdir");
// private GuiceServerModule module = new GuiceServerModule(tmpDir);
-
+
private String configDir = GuiceListener.CONFIG_DIR_IN_WAR;
-
+
@Before
public void setUp() {
@@ -48,7 +48,7 @@ public class ServerModulTest {
f.deleteOnExit();
f.mkdirs();
}
-
+
@Test
public void testLoadProperties() throws Exception {
String fileName = tmpDir + File.separator +"foo.properties";
@@ -63,7 +63,7 @@ public class ServerModulTest {
@Test
public void testLoadPropertiesWithEmptyFile() throws Exception {
GuiceListener sconfig = new GuiceListener();
-
+
File tmp = File.createTempFile("foo", ".properties");
tmp.deleteOnExit();
@@ -96,7 +96,7 @@ public class ServerModulTest {
lines.add(e.getKey() + " = " + e.getValue());
}
FileUtils.writeLines(tmp, lines);
-
+
System.setProperty(GuiceListener.SYS_PROP_CONFIG_FILE, tmp.getAbsolutePath());
p = new GuiceListener().loadProperties();
Assert.assertNotNull(p);
Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/integration/StoreBugTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/integration/StoreBugTest.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/integration/StoreBugTest.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/integration/StoreBugTest.java Thu Mar 20 08:16:02 2014
@@ -1,251 +1,251 @@
-/****************************************************************
- * 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.integration;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Properties;
-
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.mail.Session;
-
-import junit.framework.Assert;
-
-import org.apache.hupa.server.InMemoryIMAPStoreCache;
-import org.apache.hupa.server.mock.MockIMAPStore;
-import org.apache.hupa.server.mock.MockLog;
-import org.apache.hupa.shared.data.UserImpl;
-import org.apache.hupa.shared.domain.User;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import com.sun.mail.imap.IMAPFolder;
-import com.sun.mail.imap.IMAPStore;
-
-public class StoreBugTest {
-
- static final String imapServer = "imap.gmail.com";
- static final int imapPort = 993;
- static final String imapUser = "nobody@gmail.com";
- static final String imapPass = "******";
- static final boolean isSSl = true;
- static final String truststore = "";
- static final String truststorePassword = "";
-
- static int nthreads = 5;
- static int threadTimeout = 15000;
-
- Session session = Session.getDefaultInstance(new Properties(), null);
- static InMemoryIMAPStoreCache cache = new InMemoryIMAPStoreCache(new MockLog(), 2, 60000, false, truststore, truststorePassword, false);
- static User user = new UserImpl() {
- {setName(imapUser); setPassword(imapPass);}
- };
-
- @Test
- public void testMockIMAPStore() throws Exception {
- TestThread[] threads = testIMAPStoreIdle(getStore(true), "Mock-Inbox", 100);
- Assert.assertNotNull(threads);
- Assert.assertFalse(getThreadsSpentTime(threads).contains("-1"));
- }
-
- @Test @Ignore
- public void testIMAPStoreIdleHungs() throws Exception {
- IMAPStore store = null;
- try {
- store = getStore(false);
- } catch (Exception e) {
- Throwable t = e;
- while (e.getCause() != null) t = e.getCause();
- String msg = t.getClass().getName() + " " + t.getMessage();
- System.out.println("Skipping integration test: " + msg);
- return;
- }
- TestThread[] threads = testIMAPStoreIdle(store, "INBOX", 30000);
- if (threads == null)
- return;
- System.out.println(getThreadsSpentTime(threads));
- Assert.assertTrue(getThreadsSpentTime(threads).contains("-1"));
- }
-
- public TestThread[] testIMAPStoreIdle(final IMAPStore store, final String folder, int timeout) throws Exception {
- // Start the threads
- TestThread[] threads = new TestThread[nthreads];
- for (int i = 0; i<nthreads; i++) {
- TestThread t = new TestThread(){
- void execute() throws Exception {
- store.idle();
- executeSomeFolderOperations(store, folder);
- }
- };
- threads[i] = t;
- t.start();
- }
-
- // wait until all threads have finished
- waitForThreads(threads, timeout);
- return threads;
- }
-
- @Test @Ignore
- public void testInMemoryImapStoreCacheDoesntHung() throws Exception {
- try {
- cache.get(user);
- } catch (Exception e) {
- Throwable t = e;
- while (e.getCause() != null) t = e.getCause();
- String msg = t.getClass().getName() + " " + t.getMessage();
- System.out.println("Skipping integration test: " + msg);
- return;
- }
-
- // Start the threads
- TestThread[] threads = new TestThread[10];
- for (int i = 0; i<threads.length; i++) {
- TestThread t = new TestThread(){
- void execute() throws Exception {
- IMAPStore store = cache.get(user);
- String folder = "INBOX";
- executeSomeFolderOperations(store, folder);
- }
- };
- threads[i] = t;
- t.start();
- }
-
- // wait until all threads have finished
- waitForThreads(threads, 30000);
-
- Assert.assertFalse(getThreadsSpentTime(threads).contains("-1"));
- }
-
- private abstract class TestThread extends Thread {
- public long spent_millisecs = -1;
- abstract void execute() throws Exception;
- public void run() {
- try {
- long start = System.nanoTime();
- execute();
- long end = System.nanoTime();
- long diff_nanosecs = end - start;
- long diff_millsecs = diff_nanosecs/1000000;
- spent_millisecs = diff_millsecs;
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
- private void executeSomeFolderOperations(IMAPStore store, String folder) throws MessagingException, IOException {
- final IMAPFolder inbox = (IMAPFolder) store.getFolder(folder);
- inbox.open(IMAPFolder.READ_WRITE);
- // count the number of messages in the inbox
- int count = inbox.getMessageCount();
- // get the list of messages
- Message[] messages = inbox.getMessages(1, count);
- // get a randomly selected message in the list
- Message msg = messages[getRandom(1, count)];
- // download the message from the server
- long uid = inbox.getUID(msg);
- Message message = inbox.getMessageByUID(uid);
- // write it to a null stream
- message.writeTo(devNull);
- }
-
- // Create a new imap store connection (mock or real)
- private IMAPStore getStore(boolean mock) throws Exception {
- IMAPStore store = null;
- if (mock) {
- store = new MockIMAPStore(session);
- } else {
- // Configure session
- session.setDebug(false);
- Properties props = session.getProperties();
- props.setProperty("mail.mime.decodetext.strict", "false");
- props.setProperty("mail.imap.connectionpoolsize", 2 + "");
- props.setProperty("mail.imap.connectionpooltimeout", 30000 + "");
- props.setProperty("mail.imaps.connectionpoolsize", 2 + "");
- props.setProperty("mail.imaps.connectionpooltimeout", 30000 + "");
- System.setProperty("mail.mime.decodetext.strict", "false");
- // Create the imap connection
- store = (IMAPStore)session.getStore(isSSl ? "imaps" : "imap");
- store.connect(imapServer, imapPort, imapUser, imapPass);
- }
- return store;
- }
-
- @SuppressWarnings("deprecation")
- void waitForThreads(TestThread[] threads, int timeout) throws Exception {
- long start = System.currentTimeMillis();
- while(true) {
- boolean done = true;
- long ellapsed = System.currentTimeMillis() - start;
- for (TestThread t : threads) {
- t.join(1);
- if (t.isAlive())
- done = false;
-
- if (ellapsed > timeout) {
- t.stop();
- t.interrupt();
- }
- if (ellapsed > (timeout + 4000)) {
- System.out.println("It seems there are locked threads.");
- return;
- }
- }
- if (done)
- break;
- Thread.sleep(100);
- }
- }
-
- String getThreadsStatus(TestThread[] threads){
- String ret = "";
- for (TestThread t : threads) {
- if (t.isAlive())
- ret += " ACT";
- else if (t.isInterrupted())
- ret += " INT";
- else if (t.spent_millisecs < 0)
- ret += " ERR";
- else
- ret += " OK ";
- }
- return ret;
- }
-
- String getThreadsSpentTime(TestThread[] threads){
- String ret = "";
- for (TestThread t : threads)
- ret += " " + t.spent_millisecs;
- return ret;
- }
-
- int getRandom(int floor, int ceil) {
- return floor + (int)(Math.random() * Math.abs(ceil -floor));
- }
-
- OutputStream devNull = new OutputStream() {
- public void write(int b) throws IOException {
- }
- };
-
-}
+/****************************************************************
+ * 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.integration;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Properties;
+
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+
+import junit.framework.Assert;
+
+import org.apache.hupa.server.InMemoryIMAPStoreCache;
+import org.apache.hupa.server.mock.MockIMAPStore;
+import org.apache.hupa.server.mock.MockLog;
+import org.apache.hupa.shared.data.UserImpl;
+import org.apache.hupa.shared.domain.User;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import com.sun.mail.imap.IMAPFolder;
+import com.sun.mail.imap.IMAPStore;
+
+public class StoreBugTest {
+
+ static final String imapServer = "imap.gmail.com";
+ static final int imapPort = 993;
+ static final String imapUser = "nobody@gmail.com";
+ static final String imapPass = "******";
+ static final boolean isSSl = true;
+ static final String truststore = "";
+ static final String truststorePassword = "";
+
+ static int nthreads = 5;
+ static int threadTimeout = 15000;
+
+ Session session = Session.getDefaultInstance(new Properties(), null);
+ static InMemoryIMAPStoreCache cache = new InMemoryIMAPStoreCache(new MockLog(), 2, 60000, false, truststore, truststorePassword, false);
+ static User user = new UserImpl() {
+ {setName(imapUser); setPassword(imapPass);}
+ };
+
+ @Test
+ public void testMockIMAPStore() throws Exception {
+ TestThread[] threads = testIMAPStoreIdle(getStore(true), "Mock-Inbox", 100);
+ Assert.assertNotNull(threads);
+ Assert.assertFalse(getThreadsSpentTime(threads).contains("-1"));
+ }
+
+ @Test @Ignore
+ public void testIMAPStoreIdleHungs() throws Exception {
+ IMAPStore store = null;
+ try {
+ store = getStore(false);
+ } catch (Exception e) {
+ Throwable t = e;
+ while (e.getCause() != null) t = e.getCause();
+ String msg = t.getClass().getName() + " " + t.getMessage();
+ System.out.println("Skipping integration test: " + msg);
+ return;
+ }
+ TestThread[] threads = testIMAPStoreIdle(store, "INBOX", 30000);
+ if (threads == null)
+ return;
+ System.out.println(getThreadsSpentTime(threads));
+ Assert.assertTrue(getThreadsSpentTime(threads).contains("-1"));
+ }
+
+ public TestThread[] testIMAPStoreIdle(final IMAPStore store, final String folder, int timeout) throws Exception {
+ // Start the threads
+ TestThread[] threads = new TestThread[nthreads];
+ for (int i = 0; i<nthreads; i++) {
+ TestThread t = new TestThread(){
+ void execute() throws Exception {
+ store.idle();
+ executeSomeFolderOperations(store, folder);
+ }
+ };
+ threads[i] = t;
+ t.start();
+ }
+
+ // wait until all threads have finished
+ waitForThreads(threads, timeout);
+ return threads;
+ }
+
+ @Test @Ignore
+ public void testInMemoryImapStoreCacheDoesntHung() throws Exception {
+ try {
+ cache.get(user);
+ } catch (Exception e) {
+ Throwable t = e;
+ while (e.getCause() != null) t = e.getCause();
+ String msg = t.getClass().getName() + " " + t.getMessage();
+ System.out.println("Skipping integration test: " + msg);
+ return;
+ }
+
+ // Start the threads
+ TestThread[] threads = new TestThread[10];
+ for (int i = 0; i<threads.length; i++) {
+ TestThread t = new TestThread(){
+ void execute() throws Exception {
+ IMAPStore store = cache.get(user);
+ String folder = "INBOX";
+ executeSomeFolderOperations(store, folder);
+ }
+ };
+ threads[i] = t;
+ t.start();
+ }
+
+ // wait until all threads have finished
+ waitForThreads(threads, 30000);
+
+ Assert.assertFalse(getThreadsSpentTime(threads).contains("-1"));
+ }
+
+ private abstract class TestThread extends Thread {
+ public long spent_millisecs = -1;
+ abstract void execute() throws Exception;
+ public void run() {
+ try {
+ long start = System.nanoTime();
+ execute();
+ long end = System.nanoTime();
+ long diff_nanosecs = end - start;
+ long diff_millsecs = diff_nanosecs/1000000;
+ spent_millisecs = diff_millsecs;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private void executeSomeFolderOperations(IMAPStore store, String folder) throws MessagingException, IOException {
+ final IMAPFolder inbox = (IMAPFolder) store.getFolder(folder);
+ inbox.open(IMAPFolder.READ_WRITE);
+ // count the number of messages in the inbox
+ int count = inbox.getMessageCount();
+ // get the list of messages
+ Message[] messages = inbox.getMessages(1, count);
+ // get a randomly selected message in the list
+ Message msg = messages[getRandom(1, count)];
+ // download the message from the server
+ long uid = inbox.getUID(msg);
+ Message message = inbox.getMessageByUID(uid);
+ // write it to a null stream
+ message.writeTo(devNull);
+ }
+
+ // Create a new imap store connection (mock or real)
+ private IMAPStore getStore(boolean mock) throws Exception {
+ IMAPStore store = null;
+ if (mock) {
+ store = new MockIMAPStore(session);
+ } else {
+ // Configure session
+ session.setDebug(false);
+ Properties props = session.getProperties();
+ props.setProperty("mail.mime.decodetext.strict", "false");
+ props.setProperty("mail.imap.connectionpoolsize", 2 + "");
+ props.setProperty("mail.imap.connectionpooltimeout", 30000 + "");
+ props.setProperty("mail.imaps.connectionpoolsize", 2 + "");
+ props.setProperty("mail.imaps.connectionpooltimeout", 30000 + "");
+ System.setProperty("mail.mime.decodetext.strict", "false");
+ // Create the imap connection
+ store = (IMAPStore)session.getStore(isSSl ? "imaps" : "imap");
+ store.connect(imapServer, imapPort, imapUser, imapPass);
+ }
+ return store;
+ }
+
+ @SuppressWarnings("deprecation")
+ void waitForThreads(TestThread[] threads, int timeout) throws Exception {
+ long start = System.currentTimeMillis();
+ while(true) {
+ boolean done = true;
+ long ellapsed = System.currentTimeMillis() - start;
+ for (TestThread t : threads) {
+ t.join(1);
+ if (t.isAlive())
+ done = false;
+
+ if (ellapsed > timeout) {
+ t.stop();
+ t.interrupt();
+ }
+ if (ellapsed > (timeout + 4000)) {
+ System.out.println("It seems there are locked threads.");
+ return;
+ }
+ }
+ if (done)
+ break;
+ Thread.sleep(100);
+ }
+ }
+
+ String getThreadsStatus(TestThread[] threads){
+ String ret = "";
+ for (TestThread t : threads) {
+ if (t.isAlive())
+ ret += " ACT";
+ else if (t.isInterrupted())
+ ret += " INT";
+ else if (t.spent_millisecs < 0)
+ ret += " ERR";
+ else
+ ret += " OK ";
+ }
+ return ret;
+ }
+
+ String getThreadsSpentTime(TestThread[] threads){
+ String ret = "";
+ for (TestThread t : threads)
+ ret += " " + t.spent_millisecs;
+ return ret;
+ }
+
+ int getRandom(int floor, int ceil) {
+ return floor + (int)(Math.random() * Math.abs(ceil -floor));
+ }
+
+ OutputStream devNull = new OutputStream() {
+ public void write(int b) throws IOException {
+ }
+ };
+
+}
Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/CreateFolderServiceTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/CreateFolderServiceTest.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/CreateFolderServiceTest.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/CreateFolderServiceTest.java Thu Mar 20 08:16:02 2014
@@ -38,23 +38,23 @@ import org.junit.Test;
public class CreateFolderServiceTest extends HupaGuiceTestCase {
- @Test public void create() throws MessagingException {
- ImapFolder folder = createFolder();
- MockIMAPStore store = (MockIMAPStore) storeCache.get(testUser);
- Folder f1 = store.getFolder(folder.getFullName());
- assertFalse("not exists", f1.exists());
- try {
- createFolderService.create(new CreateFolderActionImpl(folder));
- Folder f = store.getFolder(folder.getFullName());
- assertTrue("exists", f.exists());
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
+ @Test public void create() throws MessagingException {
+ ImapFolder folder = createFolder();
+ MockIMAPStore store = (MockIMAPStore) storeCache.get(testUser);
+ Folder f1 = store.getFolder(folder.getFullName());
+ assertFalse("not exists", f1.exists());
+ try {
+ createFolderService.create(new CreateFolderActionImpl(folder));
+ Folder f = store.getFolder(folder.getFullName());
+ assertTrue("exists", f.exists());
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
- @Test public void duplicateFolder() throws MessagingException {
- ImapFolder folder = createFolder();
+ @Test public void duplicateFolder() throws MessagingException {
+ ImapFolder folder = createFolder();
MockIMAPStore store = (MockIMAPStore) storeCache.get(testUser);
Folder f1 = store.getFolder(folder.getFullName());
f1.create(Folder.HOLDS_FOLDERS);
@@ -63,26 +63,26 @@ public class CreateFolderServiceTest ext
fail("Folder already exists");
} catch (Exception e) {
}
- }
- @Test public void invalidSessionId(){
+ }
+ @Test public void invalidSessionId(){
httpSession.removeAttribute(SConsts.USER_SESS_ATTR);
ImapFolder folder = createFolder();
try {
- createFolderService.create(new CreateFolderActionImpl(folder));
+ createFolderService.create(new CreateFolderActionImpl(folder));
fail("Invalid session");
} catch (InvalidSessionException e) {
} catch (Exception e) {
e.printStackTrace();
fail();
}
-
- }
- private ImapFolder createFolder() {
- ImapFolder folder = new ImapFolderImpl();
- folder.setFullName("NewFolder");
- folder.setDelimiter(String.valueOf(MockIMAPFolder.SEPARATOR));
- return folder;
- }
+ }
+
+ private ImapFolder createFolder() {
+ ImapFolder folder = new ImapFolderImpl();
+ folder.setFullName("NewFolder");
+ folder.setDelimiter(String.valueOf(MockIMAPFolder.SEPARATOR));
+ return folder;
+ }
}
Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/DeleteFolderServiceTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/DeleteFolderServiceTest.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/DeleteFolderServiceTest.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/DeleteFolderServiceTest.java Thu Mar 20 08:16:02 2014
@@ -52,16 +52,16 @@ public class DeleteFolderServiceTest ext
fail();
}
}
-
+
@Test public void deleteNonExistFolder() throws MessagingException {
- ImapFolder folder = createFolder();
+ ImapFolder folder = createFolder();
try {
deleteFolderService.delete(new DeleteFolderActionImpl(folder));
fail("Folder should not exist");
} catch (HupaException e) {
- }
+ }
}
-
+
@Test public void invalidSessionId() throws MessagingException {
httpSession.removeAttribute(SConsts.USER_SESS_ATTR);
ImapFolder folder = createFolder();
@@ -74,9 +74,9 @@ public class DeleteFolderServiceTest ext
fail();
}
}
-
+
private ImapFolder createFolder() {
- ImapFolder folder = new ImapFolderImpl();
+ ImapFolder folder = new ImapFolderImpl();
folder.setFullName("NewFolder");
folder.setDelimiter(String.valueOf(MockIMAPFolder.SEPARATOR));
return folder;
Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/DeleteMessageByUidServiceTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/DeleteMessageByUidServiceTest.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/DeleteMessageByUidServiceTest.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/DeleteMessageByUidServiceTest.java Thu Mar 20 08:16:02 2014
@@ -42,7 +42,7 @@ import org.apache.hupa.shared.exception.
import org.junit.Test;
public class DeleteMessageByUidServiceTest extends HupaGuiceTestCase {
-
+
@Test public void deleteFolderNotExists() throws MessagingException {
ImapFolder folder = new ImapFolderImpl();
folder.setFullName("NOT_EXISTS");
@@ -53,9 +53,9 @@ public class DeleteMessageByUidServiceTe
} catch (HupaException e) {
}
}
-
+
@Test public void deleteFolderExistsAndNotTrash() throws MessagingException {
- ImapFolder folder = new ImapFolderImpl();
+ ImapFolder folder = new ImapFolderImpl();
folder.setFullName("EXISTS");
MockIMAPStore store = (MockIMAPStore) storeCache.get(testUser);
store.clear();
@@ -73,7 +73,7 @@ public class DeleteMessageByUidServiceTe
try {
deleteMessageByUidService.delete(action);
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());
@@ -82,12 +82,12 @@ public class DeleteMessageByUidServiceTe
fail();
}
}
-
+
@Test public void deleteFolderExistsAndIsTrash() throws MessagingException {
ImapFolder folder = new ImapFolderImpl();
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>();
Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/FetchFolderServiceTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/FetchFolderServiceTest.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/FetchFolderServiceTest.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/FetchFolderServiceTest.java Thu Mar 20 08:16:02 2014
@@ -37,32 +37,32 @@ import org.junit.Test;
public class FetchFolderServiceTest extends HupaGuiceTestCase {
- @Test public void invalidSessionId() {
- httpSession.removeAttribute(SConsts.USER_SESS_ATTR);
- try {
- fetchFoldersService.fetch(new ImapFolderImpl(), false);
- fail("Invalid session");
- } catch (InvalidSessionException e) {
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
+ @Test public void invalidSessionId() {
+ httpSession.removeAttribute(SConsts.USER_SESS_ATTR);
+ try {
+ fetchFoldersService.fetch(new ImapFolderImpl(), false);
+ fail("Invalid session");
+ } catch (InvalidSessionException e) {
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
- @Test public void noFolders() {
- httpSession.setAttribute(SConsts.USER_SESS_ATTR, testUser);
- try {
- List<ImapFolder> folders = fetchFoldersService.fetch(null, false);
- assertTrue(folders.isEmpty());
- } catch (Exception e) {
- e.printStackTrace();
- fail();
- }
- }
+ @Test public void noFolders() {
+ httpSession.setAttribute(SConsts.USER_SESS_ATTR, testUser);
+ try {
+ List<ImapFolder> folders = fetchFoldersService.fetch(null, false);
+ assertTrue(folders.isEmpty());
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
- @Before public void setup() throws MessagingException {
- MockIMAPStore store = (MockIMAPStore) storeCache.get(testUser);
- store.clear();
- }
+ @Before public void setup() throws MessagingException {
+ MockIMAPStore store = (MockIMAPStore) storeCache.get(testUser);
+ store.clear();
+ }
}
Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/FetchMessagesServiceTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/FetchMessagesServiceTest.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/FetchMessagesServiceTest.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/FetchMessagesServiceTest.java Thu Mar 20 08:16:02 2014
@@ -41,52 +41,52 @@ import org.apache.hupa.shared.exception.
import org.junit.Test;
public class FetchMessagesServiceTest extends HupaGuiceTestCase {
- @Test public void convert() throws MessagingException{
- MockIMAPFolder f = (MockIMAPFolder)store.getFolder("WHATEVER");
+ @Test public void convert() throws MessagingException{
+ MockIMAPFolder f = (MockIMAPFolder)store.getFolder("WHATEVER");
f.create(Folder.HOLDS_MESSAGES);
-
+
ByteArrayInputStream is = new ByteArrayInputStream("From: \"a b c\"<aa...@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>\" <b...@foo.com>\nSubject: =?ISO-8859-1?Q?Monta=F1a?=\n\ndata".getBytes());
MimeMessage m3 = new MimeMessage(session, is);
-
+
List<org.apache.hupa.shared.domain.Message> msgs = fetchMessagesService.convert(2, f, new Message[]{m1, m2, m3});
assertEquals(2, msgs.size());
-
+
msgs = fetchMessagesService.convert(10, f, new Message[]{m1, m2, m3});
assertEquals(3, msgs.size());
-
+
msgs = fetchMessagesService.convert(10, f, new Message[]{m1});
assertEquals("a b c <aa...@foo.com>", msgs.get(0).getFrom());
msgs = fetchMessagesService.convert(10, f, new Message[]{m2});
assertEquals("Manolo Pe\u00F1a <pe...@foo.com>", msgs.get(0).getFrom());
-
+
msgs = fetchMessagesService.convert(10, f, new Message[]{m3});
assertEquals("Monta\u00F1a", msgs.get(0).getSubject());
assertEquals("b@foo.com <b...@foo.com>", msgs.get(0).getTo().get(0));
}
-
+
@Test public void fetchMessages() throws HupaException, MessagingException {
- MockIMAPFolder serverfolder = (MockIMAPFolder)store.getFolder("WHATEVER");
+ MockIMAPFolder serverfolder = (MockIMAPFolder)store.getFolder("WHATEVER");
serverfolder.create(Folder.HOLDS_MESSAGES);
-
+
ImapFolder clientfolder = new ImapFolderImpl("WHATEVER");
FetchMessagesResult result = fetchMessagesService.fetch(new FetchMessagesActionImpl(clientfolder, 0, 10, "*"));
assertEquals(0, result.getRealCount());
-
+
ByteArrayInputStream is = new ByteArrayInputStream("From: a@foo.com\nTo: b@foo.com\nSubject: something\n\ndata 1".getBytes());
MimeMessage msg = new MimeMessage(session, is);
serverfolder.addMessages(new Message[]{msg});
result = fetchMessagesService.fetch(new FetchMessagesActionImpl(clientfolder, 0, 10, "something"));
assertEquals(1, result.getRealCount());
assertEquals(1, result.getMessages().size());
-
+
result = fetchMessagesService.fetch(new FetchMessagesActionImpl(clientfolder, 0, 10, null));
assertEquals(1, result.getRealCount());
assertEquals(1, result.getMessages().size());
@@ -94,24 +94,24 @@ public class FetchMessagesServiceTest ex
is = new ByteArrayInputStream("From: a@foo.com\nTo: b@foo.com\nSubject: something\n\ndata 2".getBytes());
msg = new MimeMessage(session, is);
serverfolder.appendMessages(new Message[]{msg});
-
+
result = fetchMessagesService.fetch(new FetchMessagesActionImpl(clientfolder, 0, 10, "data"));
assertEquals(2, result.getRealCount());
assertEquals(2, result.getMessages().size());
-
+
result = fetchMessagesService.fetch(new FetchMessagesActionImpl(clientfolder, 0, 10, "data 2"));
assertEquals(1, result.getRealCount());
-
+
result = fetchMessagesService.fetch(new FetchMessagesActionImpl(clientfolder, 0, 10, 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 = fetchMessagesService.fetch(new FetchMessagesActionImpl(clientfolder, 0, 10, "data"));
assertEquals(3, result.getRealCount());
Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/GetMessageDetailServiceTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/GetMessageDetailServiceTest.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/GetMessageDetailServiceTest.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/GetMessageDetailServiceTest.java Thu Mar 20 08:16:02 2014
@@ -44,15 +44,15 @@ public class GetMessageDetailServiceTest
String res = getMessageDetailsService.txtDocumentToHtml(msg, "aFolder", 9999l);
assertNotSame(msg, res);
assertTrue(res.contains("onClick=\"openLink('http://"));
-
+
msg = "...\nnobody@subdomain.the-domain.org\n...";
res = getMessageDetailsService.txtDocumentToHtml(msg, "aFolder", 9999l);
assertNotSame(msg, res);
assertTrue(res.contains("onClick=\"mailTo('nobody@"));
-
+
res = getMessageDetailsService.txtDocumentToHtml("", "aFolder", 9999l);
assertTrue(res.length()==0);
-
+
msg = "...<atag>...";
res = getMessageDetailsService.txtDocumentToHtml(msg, "aFolder", 9999l);
assertNotSame(msg, res);
@@ -64,7 +64,7 @@ public class GetMessageDetailServiceTest
String res = getMessageDetailsService.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 = getMessageDetailsService.filterHtmlDocument(msg, "aFolder", 9999l);
assertNotSame(msg, res);
@@ -78,12 +78,12 @@ public class GetMessageDetailServiceTest
msg = "...\n...<img \n src=\"cid:1.1934304663@web28309.mail.ukl.yahoo.com\" width=200\n....";
res = getMessageDetailsService.filterHtmlDocument(msg, "aFolder", 9999l);
assertNotSame(msg, res);
- assertEquals("...\n...<img \n src='" +
- SConsts.HUPA + SConsts.SERVLET_DOWNLOAD + "?mode=inline&"
- + SConsts.PARAM_FOLDER + "=aFolder&"
+ assertEquals("...\n...<img \n src='" +
+ SConsts.HUPA + SConsts.SERVLET_DOWNLOAD + "?mode=inline&"
+ + 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 = getMessageDetailsService.filterHtmlDocument(msg, "aFolder", 9999l);
assertNotSame(msg, res);
@@ -95,7 +95,7 @@ public class GetMessageDetailServiceTest
msg = "\n\n.... <style \ntype=\"whatever\"\n>\n.a{};\n</Style > ---\n\n";
res = getMessageDetailsService.filterHtmlDocument(msg, "aFolder", 9999l);
assertNotSame(msg, res);
-
+
res = getMessageDetailsService.filterHtmlDocument("", "aFolder", 9999l);
assertTrue(res.length()==0);
}
@@ -116,7 +116,7 @@ public class GetMessageDetailServiceTest
// 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 = getMessageDetailsService.txtDocumentToHtml(msg, "aFolder", 9999l);
assertFalse(res.contains("mailTo("));
@@ -124,17 +124,17 @@ public class GetMessageDetailServiceTest
}
@Test public void testFilterHtml_LargeBody_Performance() throws Exception {
- // messages with large bodies should be processed fast
- long start = System.currentTimeMillis();
+ // 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 getMessageDetailsService.mimeToDetails(TestUtils.loadMessageFromFile(session,msgFile), "theFolder", 9999l, testUser);
}
-
+
@Test public void testMessageDetails_textPlain() throws Exception {
MessageDetails details = loadMessageDetails("0.msg");
assertTrue(details.getText().contains("demo message"));
@@ -151,12 +151,12 @@ public class GetMessageDetailServiceTest
assertEquals(0, details.getMessageAttachments().size());
assertTrue(details.getText().length() > 0);
}
-
+
@Test 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);
@@ -166,41 +166,41 @@ public class GetMessageDetailServiceTest
MessageDetails details = loadMessageDetails("4.msg");
assertTrue(details.getText().length() > 0);
}
-
+
@Test public void testMessageDetails_multiparMixed_multipartAlternative() throws Exception {
MessageDetails details = loadMessageDetails("6.msg");
assertEquals(1, details.getMessageAttachments().size());
assertTrue(details.getText().length() > 0);
}
-
+
@Test public void testMessageDetails_multiparMixed_multipartAlternative_textAttachment() throws Exception {
MessageDetails details = loadMessageDetails("10.msg");
assertEquals(1, details.getMessageAttachments().size());
assertTrue(details.getText().contains("<span>"));
}
-
+
@Test public void testMessageDetails_html_with_inline_images() throws Exception {
IMAPStore store = storeCache.get(testUser);
-
- IMAPFolder serverfolder = (IMAPFolder)store.getFolder("WHATEVER");
+
+ 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.domain.ImapFolder clientfolder = new org.apache.hupa.shared.data.ImapFolderImpl("WHATEVER");
MessageDetails details = getMessageDetailsService.exposeMessage(testUser, clientfolder, 0);
-
+
// inline images have to be downloaded from the server
- assertTrue(details.getText().contains("img src=\'" +
+ assertTrue(details.getText().contains("img src=\'" +
SConsts.HUPA + SConsts.SERVLET_DOWNLOAD + "?mode=inline&" +
- SConsts.PARAM_FOLDER + "=WHATEVER&" +
- SConsts.PARAM_UID + "=0&" +
+ 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());
-
+
}
@Test public void testMessageDetails_links() throws Exception {
@@ -212,7 +212,7 @@ public class GetMessageDetailServiceTest
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\""));
}
-
+
@Test public void testMessageDetails_ecs_crypt() throws Exception {
MessageDetails details = loadMessageDetails("12.msg");
assertEquals("Secure Hello world<br>", details.getText());
Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/LoginUserServiceTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/LoginUserServiceTest.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/LoginUserServiceTest.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/LoginUserServiceTest.java Thu Mar 20 08:16:02 2014
@@ -32,7 +32,7 @@ import org.apache.hupa.shared.exception.
import org.junit.Test;
public class LoginUserServiceTest extends HupaGuiceTestCase {
-
+
@Test public void invalidLogin() throws MessagingException {
httpSession.setAttribute("Attribute", "Value");
try {
@@ -43,7 +43,7 @@ public class LoginUserServiceTest extend
assertNull("No user should be stored in session", httpSession.getAttribute(SConsts.USER_SESS_ATTR));
assertNull("Attributes should be removed", httpSession.getAttribute("Attribute"));
}
-
+
@Test public void validLogin() throws MessagingException {
try {
System.out.println(testUser.getName() + " " + testUser.getPassword());
Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/LogoutUserServiceTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/LogoutUserServiceTest.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/LogoutUserServiceTest.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/LogoutUserServiceTest.java Thu Mar 20 08:16:02 2014
@@ -30,7 +30,7 @@ import org.apache.hupa.shared.exception.
import org.junit.Test;
public class LogoutUserServiceTest extends HupaGuiceTestCase {
-
+
@Test public void logout() {
try {
httpSession.setAttribute("Attribute", "Value");
@@ -42,6 +42,6 @@ public class LogoutUserServiceTest exten
e.printStackTrace();
fail();
}
-
+
}
}
Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/SendMessageServiceTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/SendMessageServiceTest.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/SendMessageServiceTest.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/SendMessageServiceTest.java Thu Mar 20 08:16:02 2014
@@ -40,11 +40,11 @@ import com.google.inject.Module;
import com.sun.mail.imap.IMAPFolder;
public class SendMessageServiceTest extends HupaGuiceTestCase {
-
+
static final String imapUser = "mcdodot@gmail.com";
static final String imapPass = "5234manolito";
final private boolean useMock = true;
-
+
@Override
protected Module[] getModules() {
if (useMock ) {
@@ -57,15 +57,15 @@ public class SendMessageServiceTest exte
}}};
}
}
-
+
@Test
public void testSendMessage() throws Exception {
IMAPFolder folder = (IMAPFolder) store.getFolder(testUser.getSettings().getSentFolderName());
folder.open(Folder.READ_ONLY);
long count = folder.getMessageCount();
-
+
FileItemRegistry registry = SessionUtils.getSessionRegistry(logger, httpSession);
-
+
// Create a reply user action with an uploaded message
SmtpMessage smtpmsg = TestUtils.createMockSMTPMessage(registry, 1);
SendMessageActionImpl action = new SendMessageActionImpl(smtpmsg);
@@ -75,14 +75,14 @@ public class SendMessageServiceTest exte
smtpmsg.setBcc(Arrays.<String>asList());
smtpmsg.setFrom(imapUser);
smtpmsg.setSubject(subject);
-
+
Message message = sendMessageService.createMessage(session, action);
message = sendMessageService.fillBody(message, action);
-
+
sendMessageService.send(action);
-
+
Assert.assertTrue(count < folder.getMessageCount());
}
-
-
+
+
}
Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/SendReplyMessageServiceTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/SendReplyMessageServiceTest.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/SendReplyMessageServiceTest.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/service/SendReplyMessageServiceTest.java Thu Mar 20 08:16:02 2014
@@ -49,7 +49,7 @@ public class SendReplyMessageServiceTest
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);
@@ -59,12 +59,12 @@ public class SendReplyMessageServiceTest
// 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"
@@ -73,14 +73,14 @@ public class SendReplyMessageServiceTest
+ " 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);
SendReplyMessageAction action = new SendReplyMessageActionImpl(smtpmsg, new ImapFolderImpl(inbox.getFullName()), msgUid);
-
+
message = sendReplyMessageService.createMessage(session, action);
message = sendReplyMessageService.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"
@@ -88,7 +88,7 @@ public class SendReplyMessageServiceTest
+ " text/html\n"
+ " image/mock => inlineImage.jpg\n"
+ " mock/attachment => uploadedFile_1.bin\n";
-
+
assertEquals(expected, TestUtils.summaryzeContent(message).toString());
}
}
Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/MessageUtilsTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/MessageUtilsTest.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/MessageUtilsTest.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/MessageUtilsTest.java Thu Mar 20 08:16:02 2014
@@ -31,7 +31,7 @@ import org.apache.hupa.server.HupaGuiceT
import org.junit.Test;
public class MessageUtilsTest extends HupaGuiceTestCase {
-
+
@Test public void extractMessageAttachments() throws Exception {
Message message = TestUtils.createMockMimeMessage(session, 2);
List<BodyPart> parts = MessageUtils.extractMessageAttachments(logger, message.getContent());
@@ -40,32 +40,32 @@ public class MessageUtilsTest extends Hu
@Test public void extractInlineAttachments() throws Exception {
Message message = TestUtils.createMockMimeMessage(session, 1);
-
+
List<BodyPart> attachments = MessageUtils.extractMessageAttachments(logger, message.getContent());
List<BodyPart> inlineImgs = MessageUtils.extractInlineImages(logger, message.getContent());
assertEquals(1, attachments.size());
assertEquals(0, inlineImgs.size());
-
+
TestUtils.addMockAttachment(message, "mfile.bin", false);
-
+
attachments = MessageUtils.extractMessageAttachments(logger, message.getContent());
inlineImgs = MessageUtils.extractInlineImages(logger, message.getContent());
assertEquals(2, attachments.size());
assertEquals(0, inlineImgs.size());
TestUtils.addMockAttachment(message, "mfile.jpg", true);
-
+
attachments = MessageUtils.extractMessageAttachments(logger, message.getContent());
inlineImgs = MessageUtils.extractInlineImages(logger, message.getContent());
assertEquals(3, attachments.size());
assertEquals(1, inlineImgs.size());
}
-
+
@Test public void getRecipients () throws Exception {
String encodedEmail = "=?ISO-8859-1?Q?Manolo_Pe=F1a?= <he...@hupa.org>";
String decodedEmail = MessageUtils.decodeText(encodedEmail);
assertFalse(encodedEmail.equals(decodedEmail));
-
+
Address[] addr = MessageUtils.getRecipients(encodedEmail, decodedEmail);
assertEquals(addr[0].toString(), addr[1].toString());
}
Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/RegexPatternsTest.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/RegexPatternsTest.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/RegexPatternsTest.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/RegexPatternsTest.java Thu Mar 20 08:16:02 2014
@@ -22,7 +22,7 @@ package org.apache.hupa.server.utils;
import junit.framework.TestCase;
public class RegexPatternsTest extends TestCase {
-
+
public void testRegexHtml() {
String txt, res;
txt = "<!'https://www.aaa.1:#@%/;$()~_?+-=\\.&<br/>";
@@ -61,12 +61,12 @@ public class RegexPatternsTest extends T
txt = ".. <img\nsrc='cid:abcd'\nwhatever=/>click</a\n> ..";
res = RegexPatterns.replaceAll(txt, RegexPatterns.regex_inlineImg, RegexPatterns.repl_inlineImg);
assertNotSame(txt, res);
-
+
res = RegexPatterns.replaceAll(txt, RegexPatterns.regex_revertInlineImg, RegexPatterns.repl_revertInlineImg);
assertEquals(txt, res);
}
-
+
public void testRegexBadTags() {
String txt, res;
txt = "<html><head>h<tag></head><body>.<style>..</style>.<script type=>//</script></body>.</html>";
@@ -86,7 +86,7 @@ public class RegexPatternsTest extends T
res = RegexPatterns.replaceAllRecursive(txt, RegexPatterns.regex_badAttrs, RegexPatterns.repl_badAttrs);
assertEquals("... <div attr=a attr=b attr=c /> ...", res);
}
-
+
public void testRegexHtmlLinks() {
String txt, res;
txt = ".. <a href=\"http://whatever\">..</a> ..";
@@ -96,30 +96,30 @@ public class RegexPatternsTest extends T
txt = "-- <div> .. <img src=\"http://whatever\"/> .. </div>";
res = RegexPatterns.replaceAll(txt, RegexPatterns.regex_orphandHttpLinks, RegexPatterns.repl_orphandHttpLinks);
assertEquals(txt, res);
-
+
txt = "-- <div> .. \"http://whatever\" .. </div>";
res = RegexPatterns.replaceAll(txt, RegexPatterns.regex_orphandHttpLinks, RegexPatterns.repl_orphandHttpLinks);
assertEquals("-- <div> .. \"<a href=\"http://whatever\">http://whatever</a>\" .. </div>", res);
res = RegexPatterns.replaceAll(res, RegexPatterns.regex_existingHttpLinks, RegexPatterns.repl_existingHttpLinks);
assertEquals("-- <div> .. \"<a onClick=\"openLink('http://whatever');return false;\" href=\"http://whatever\">http://whatever</a>\" .. </div>", res);
-
+
}
public void testRegexEmailLinks() {
String txt, res;
-
+
txt = ".. <a href=\"mailTo:someone@somedomain.com\">..</a> ..";
res = RegexPatterns.replaceAll(txt, RegexPatterns.regex_existingEmailLinks, RegexPatterns.repl_existngEmailLinks);
assertEquals(".. <a onClick=\"mailTo('someone@somedomain.com');return false;\" href=\"mailto:someone@somedomain.com\">..</a> ..", res);
-
+
txt = "-- <div> .. someone@somedomain.com .. </div>";
res = RegexPatterns.replaceAll(txt, RegexPatterns.regex_orphandEmailLinks, RegexPatterns.repl_orphandEmailLinks);
assertEquals("-- <div> .. <a href=\"mailto:someone@somedomain.com\">someone@somedomain.com</a> .. </div>", res);
res = RegexPatterns.replaceAll(res, RegexPatterns.regex_existingEmailLinks, RegexPatterns.repl_existngEmailLinks);
assertEquals("-- <div> .. <a onClick=\"mailTo('someone@somedomain.com');return false;\" href=\"mailto:someone@somedomain.com\">someone@somedomain.com</a> .. </div>", res);
-
+
}
}
\ No newline at end of file
Modified: james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/TestUtils.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/TestUtils.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/TestUtils.java (original)
+++ james/hupa/trunk/server/src/test/java/org/apache/hupa/server/utils/TestUtils.java Thu Mar 20 08:16:02 2014
@@ -83,10 +83,10 @@ public class TestUtils extends TestCase
Arrays.fill(padding, ' ');
return new String(padding) + text;
}
-
+
public String toString() {
StringBuilder ret = new StringBuilder();
- for (String s : this)
+ for (String s : this)
ret.append(s).append("\n");
return ret.toString();
}
@@ -95,7 +95,7 @@ public class TestUtils extends TestCase
/**
* Creates a FileItem which stores data in memory
- *
+ *
* @param filename
* @return a new item
* @throws IOException
@@ -112,16 +112,16 @@ public class TestUtils extends TestCase
public static FileItem createMockFileItem(String filename) throws IOException {
return createMockFileItem(filename, "mock/attachment");
}
-
+
public void testCreateMockFileItem() throws Exception {
FileItem item = createMockFileItem("filename.jpg");
assertEquals("ABCDEFGHIJK\n", item.getString());
}
-
+
/**
* Create a new mime-message from a file stored in the fixtures folder
- *
+ *
* @param session
* @param msgFile
* @return
@@ -137,8 +137,8 @@ public class TestUtils extends TestCase
/**
* Creates a new mime message.
* It is possible to specify which parts to create (text, html or both) and
- * the number of attachments
- *
+ * the number of attachments
+ *
* @param session
* @param text
* @param html
@@ -162,7 +162,7 @@ public class TestUtils extends TestCase
message.setSubject("Subject");
return SendMessageBaseServiceImpl.composeMessage(message, text, html, items);
}
-
+
public static Message createMockMimeMessage(Session session, int nfiles) throws MessagingException, IOException {
return createMockMimeMessage(session, "Body", "<div>Body</div>", nfiles);
}
@@ -170,7 +170,7 @@ public class TestUtils extends TestCase
/**
* Creates a client side mock smtp message.
* It is possible to say the number of attachments we want.
- *
+ *
* @param registry
* @param nfiles
* @return
@@ -209,11 +209,11 @@ public class TestUtils extends TestCase
/**
* Parses a mime message and returns an array of content-types.
- * Each line in the array represents a mime part and is indented
+ * Each line in the array represents a mime part and is indented
* with spaces.
- *
+ *
* It's used in testing or debugging.
- *
+ *
* @param msg
* @return
* @throws IOException
@@ -254,7 +254,7 @@ public class TestUtils extends TestCase
/**
* Add a mock attachment to a mime message, you can specify whether the attachment
* is an in-line image, and the file name
- *
+ *
* @param message
* @param fileName
* @param isInline
@@ -263,17 +263,17 @@ public class TestUtils extends TestCase
*/
public static void addMockAttachment(Message message, String fileName, boolean isInline) throws IOException, MessagingException {
FileItem item = createMockFileItem(fileName, isInline ? "image/mock" : "mock/attachment");
-
+
BodyPart part = MessageUtils.fileitemToBodypart(item);
if (isInline)
part.addHeader("Content-ID", "any-id");
-
+
Multipart mpart = (Multipart) message.getContent();
mpart.addBodyPart(part);
message.saveChanges();
}
-
-
+
+
public static String dumpStore(IMAPStore store) throws MessagingException {
String ret = "";
for (Folder f : store.getDefaultFolder().list()) {
@@ -281,5 +281,5 @@ public class TestUtils extends TestCase
}
return ret;
}
-
+
}
\ No newline at end of file
Modified: james/hupa/trunk/shared/pom.xml
URL: http://svn.apache.org/viewvc/james/hupa/trunk/shared/pom.xml?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/shared/pom.xml (original)
+++ james/hupa/trunk/shared/pom.xml Thu Mar 20 08:16:02 2014
@@ -37,7 +37,7 @@
<dependency>
<groupId>com.google.code.guice</groupId>
<artifactId>guice</artifactId>
- </dependency>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Modified: james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/SConsts.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/SConsts.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/SConsts.java (original)
+++ james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/SConsts.java Thu Mar 20 08:16:02 2014
@@ -25,19 +25,19 @@ public class SConsts {
public static final String SERVLET_UPLOAD = "uploadAttachmentServlet";
public static final String SERVLET_SOURCE = "messageSourceServlet";
-
+
public static final String PARAM_NAME = "name";
public static final String PARAM_FOLDER = "folder";
public static final String PARAM_UID = "uid";
public static final String PARAM_MODE = "mode";
-
+
public static final String USER_SESS_ATTR = "hupa.user";
public static final String CONTACTS_SESS_ATTR = "hupa.contacts";
public static final String REG_SESS_ATTR = "hupa.registry";
-
+
public static final String HEADER_IN_REPLY_TO = "In-Reply-To";
public static final String HEADER_REFERENCES = "References";
public static final String HEADER_MESSAGE_ID = "Message-ID";
public static final String HEADER_REFERENCES_SEPARATOR = "\r\n ";
-
+
}
\ No newline at end of file
Modified: james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/Util.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/Util.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/Util.java (original)
+++ james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/Util.java Thu Mar 20 08:16:02 2014
@@ -23,14 +23,14 @@ import java.util.ArrayList;
import java.util.List;
public class Util {
-
+
public final static String HTML_LT = "<";
public final static String STRING_LT = "<";
public final static String HTML_GT = ">";
public final static String STRING_GT = ">";
public final static String HTML_CR = "<br>";
public final static String STRING_CR = "\n";
-
+
public static String unEscapeHtmlTags(String string) {
if (string != null) {
string = string.replaceAll(HTML_LT, STRING_LT);
@@ -47,7 +47,7 @@ public class Util {
}
return string;
}
-
+
public static <T> String listToString(List<T> list) {
return list == null ? "" : new ArrayList<T>(list).toString().replaceFirst("^\\[(.*)\\]$", "$1");
}
Modified: james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/algorithms/B64.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/algorithms/B64.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/algorithms/B64.java (original)
+++ james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/algorithms/B64.java Thu Mar 20 08:16:02 2014
@@ -38,7 +38,7 @@ public class B64 {
/**
* Decode a base64 string into a byte array.
- *
+ *
* @param data
* the encoded data.
* @return a byte array.
@@ -113,7 +113,7 @@ public class B64 {
* padded with zeros. Each 24-bit chunk is encoded as 4 characters from the
* sequence [A-Za-z0-9$_]. If one of the source positions consists entirely
* of padding zeros, an '=' character is used instead.
- *
+ *
* @param data
* a byte array, which may be null or empty
* @return a String
Modified: james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/data/AbstractMessageImpl.java
URL: http://svn.apache.org/viewvc/james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/data/AbstractMessageImpl.java?rev=1579559&r1=1579558&r2=1579559&view=diff
==============================================================================
--- james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/data/AbstractMessageImpl.java (original)
+++ james/hupa/trunk/shared/src/main/java/org/apache/hupa/shared/data/AbstractMessageImpl.java Thu Mar 20 08:16:02 2014
@@ -1,122 +1,122 @@
-/****************************************************************
- * 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.util.List;
-
-public class AbstractMessageImpl{
- private String from;
- private String subject;
- private String replyto;
- private List<String> to;
- private List<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(List<String> cc) {
- this.cc = cc;
- }
-
- public List<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 List<String> getTo() {
- return to;
- }
-
- public void setTo(List<String> to) {
- this.to = to;
- }
-
- public String getReplyto() {
- return replyto;
- }
-
- public void setReplyto(String replyto) {
- this.replyto = replyto;
- }
-
-
-}
+/****************************************************************
+ * 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.util.List;
+
+public class AbstractMessageImpl{
+ private String from;
+ private String subject;
+ private String replyto;
+ private List<String> to;
+ private List<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(List<String> cc) {
+ this.cc = cc;
+ }
+
+ public List<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 List<String> getTo() {
+ return to;
+ }
+
+ public void setTo(List<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