diff --git a/kernel-component/src/main/webapp/WEB-INF/email-components.xml b/kernel-component/src/main/webapp/WEB-INF/email-components.xml
index a800b03..428ae27 100644
--- a/kernel-component/src/main/webapp/WEB-INF/email-components.xml
+++ b/kernel-component/src/main/webapp/WEB-INF/email-components.xml
@@ -9,14 +9,14 @@
destroy-method="destroy"
singleton="true">
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
SAKAI_DIGEST
false
@@ -29,7 +29,7 @@
destroy-method="destroy"
singleton="true">
-
+
diff --git a/kernel-impl/src/main/java/org/sakaiproject/email/impl/BaseDigestService.java b/kernel-impl/src/main/java/org/sakaiproject/email/impl/BaseDigestService.java
index f68e2a6..f1f3ee1 100644
--- a/kernel-impl/src/main/java/org/sakaiproject/email/impl/BaseDigestService.java
+++ b/kernel-impl/src/main/java/org/sakaiproject/email/impl/BaseDigestService.java
@@ -255,7 +255,7 @@ public abstract class BaseDigestService implements DigestService, StorageUser //
if (M_log.isDebugEnabled()) M_log.debug("checking for sending digests");
// compute the current period
- String curPeriod = computeRange(timeService().newTime()).toString();
+ String curPeriod = computeRange(timeService.newTime()).toString();
// if we are in a new period, start sending again
if (!curPeriod.equals(m_lastSendPeriod))
@@ -316,7 +316,7 @@ public abstract class BaseDigestService implements DigestService, StorageUser //
// process if it's not the current period
if (!curPeriod.equals(period))
{
- TimeRange periodRange = timeService().newTimeRange(period);
+ TimeRange periodRange = timeService.newTimeRange(period);
Time timeInPeriod = periodRange.firstTime();
// any messages?
@@ -393,13 +393,13 @@ public abstract class BaseDigestService implements DigestService, StorageUser //
try
{
- String to = userDirectoryService().getUser(id).getEmail();
+ String to = userDirectoryService.getUser(id).getEmail();
// if use has no email address we can't send it
if ((to == null) || (to.length() == 0)) return;
- String from = "postmaster@" + serverConfigurationService().getServerName();
- String subject = serverConfigurationService().getString("ui.service", "Sakai") + " " + rb.getString("notif") + " "
+ String from = "postmaster@" + serverConfigurationService.getServerName();
+ String subject = serverConfigurationService.getString("ui.service", "Sakai") + " " + rb.getString("notif") + " "
+ period.firstTime().toStringLocalDate();
StringBuilder body = new StringBuilder();
@@ -440,12 +440,12 @@ public abstract class BaseDigestService implements DigestService, StorageUser //
}
// tag
- body.append(rb.getString("thiaut") + " " + serverConfigurationService().getString("ui.service", "Sakai") + " " + "("
- + serverConfigurationService().getServerUrl() + ")" + "\n" + rb.getString("youcan") + "\n");
+ body.append(rb.getString("thiaut") + " " + serverConfigurationService.getString("ui.service", "Sakai") + " " + "("
+ + serverConfigurationService.getServerUrl() + ")" + "\n" + rb.getString("youcan") + "\n");
if (M_log.isDebugEnabled()) M_log.debug(this + " sending digest email to: " + to);
- emailService().send(from, to, subject, body.toString(), to, null, null);
+ emailService.send(from, to, subject, body.toString(), to, null, null);
}
catch (Throwable any)
{
@@ -471,7 +471,7 @@ public abstract class BaseDigestService implements DigestService, StorageUser //
*/
protected String getAccessPoint(boolean relative)
{
- return (relative ? "" : serverConfigurationService().getAccessUrl()) + m_relativeAccessPoint;
+ return (relative ? "" : serverConfigurationService.getAccessUrl()) + m_relativeAccessPoint;
}
/**
@@ -513,7 +513,7 @@ public abstract class BaseDigestService implements DigestService, StorageUser //
*/
protected boolean unlockCheck(String lock, String resource)
{
- if (!securityService().unlock(lock, resource))
+ if (!securityService.unlock(lock, resource))
{
return false;
}
@@ -535,7 +535,7 @@ public abstract class BaseDigestService implements DigestService, StorageUser //
{
if (!unlockCheck(lock, resource))
{
- throw new PermissionException(sessionManager().getCurrentSessionUserId(), lock, resource);
+ throw new PermissionException(sessionManager.getCurrentSessionUserId(), lock, resource);
}
}
@@ -543,40 +543,69 @@ public abstract class BaseDigestService implements DigestService, StorageUser //
* Dependencies
*********************************************************************************************************************************************************************************************************************************************************/
+ protected TimeService timeService;
+ protected ServerConfigurationService serverConfigurationService;
+ protected EmailService emailService;
+ protected EventTrackingService eventTrackingService;
+ protected SecurityService securityService;
+ protected UserDirectoryService userDirectoryService;
+ protected SessionManager sessionManager;
+
/**
* @return the TimeService collaborator.
*/
- protected abstract TimeService timeService();
+ public void setTimeService(TimeService timeService)
+ {
+ this.timeService = timeService;
+ }
/**
* @return the ServerConfigurationService collaborator.
*/
- protected abstract ServerConfigurationService serverConfigurationService();
+ public void setServerConfigurationService(ServerConfigurationService serverConfigurationService)
+ {
+ this.serverConfigurationService = serverConfigurationService;
+ }
/**
* @return the EmailService collaborator.
*/
- protected abstract EmailService emailService();
+ public void setEmailService(EmailService emailService)
+ {
+ this.emailService = emailService;
+ }
/**
* @return the EventTrackingService collaborator.
*/
- protected abstract EventTrackingService eventTrackingService();
+ public void setEventTrackingService(EventTrackingService eventTrackingService)
+ {
+ this.eventTrackingService = eventTrackingService;
+ }
/**
* @return the MemoryServiSecurityServicece collaborator.
*/
- protected abstract SecurityService securityService();
+ public void setSecurityService(SecurityService securityService)
+ {
+ this.securityService = securityService;
+ }
/**
* @return the UserDirectoryService collaborator.
*/
- protected abstract UserDirectoryService userDirectoryService();
+ public void setUserDirectoryService(UserDirectoryService userDirectoryService)
+ {
+ this.userDirectoryService = userDirectoryService;
+ }
/**
* @return the SessionManager collaborator.
*/
- protected abstract SessionManager sessionManager();
+ public void setSessionManager(SessionManager sessionManager)
+ {
+ this.sessionManager = sessionManager;
+ }
/**********************************************************************************************************************************************************************************************************************************************************
* Init and Destroy
@@ -598,8 +627,8 @@ public abstract class BaseDigestService implements DigestService, StorageUser //
// USE A TIMER INSTEAD OF CREATING A NEW THREAD -AZ
// start();
- int digestPeriod = serverConfigurationService().getInt(EMAIL_DIGEST_CHECK_PERIOD_PROPERTY, DIGEST_PERIOD);
- int digestDelay = serverConfigurationService().getInt(EMAIL_DIGEST_START_DELAY_PROPERTY, DIGEST_DELAY);
+ int digestPeriod = serverConfigurationService.getInt(EMAIL_DIGEST_CHECK_PERIOD_PROPERTY, DIGEST_PERIOD);
+ int digestDelay = serverConfigurationService.getInt(EMAIL_DIGEST_START_DELAY_PROPERTY, DIGEST_DELAY);
digestDelay += new Random().nextInt(60); // add some random delay to get the servers out of sync
digestTimer.schedule(new DigestTimerTask(), (digestDelay * 1000), (digestPeriod * 1000) );
@@ -747,7 +776,7 @@ public abstract class BaseDigestService implements DigestService, StorageUser //
m_storage.commit(edit);
// track it
- eventTrackingService().post(eventTrackingService().newEvent(((BaseDigest) edit).getEvent(), edit.getReference(), true));
+ eventTrackingService.post(eventTrackingService.newEvent(((BaseDigest) edit).getEvent(), edit.getReference(), true));
// close the edit object
((BaseDigest) edit).closeEdit();
@@ -802,7 +831,7 @@ public abstract class BaseDigestService implements DigestService, StorageUser //
m_storage.remove(edit);
// track it
- eventTrackingService().post(eventTrackingService().newEvent(SECURE_REMOVE_DIGEST, edit.getReference(), true));
+ eventTrackingService.post(eventTrackingService.newEvent(SECURE_REMOVE_DIGEST, edit.getReference(), true));
// close the edit object
((BaseDigest) edit).closeEdit();
@@ -1183,7 +1212,7 @@ public abstract class BaseDigestService implements DigestService, StorageUser //
synchronized (m_ranges)
{
// find the current range
- String range = computeRange(timeService().newTime()).toString();
+ String range = computeRange(timeService.newTime()).toString();
List msgs = (List) m_ranges.get(range);
if (msgs == null)
{
@@ -1204,7 +1233,7 @@ public abstract class BaseDigestService implements DigestService, StorageUser //
synchronized (m_ranges)
{
// find the current range
- String range = computeRange(timeService().newTime()).toString();
+ String range = computeRange(timeService.newTime()).toString();
List msgs = (List) m_ranges.get(range);
if (msgs == null)
{
@@ -1569,9 +1598,9 @@ public abstract class BaseDigestService implements DigestService, StorageUser //
brk.setSec(0);
brk.setMin(0);
brk.setHour(0);
- Time start = timeService().newTimeLocal(brk);
- Time end = timeService().newTime(start.getTime() + 24 * 60 * 60 * 1000);
- return timeService().newTimeRange(start, end, true, false);
+ Time start = timeService.newTimeLocal(brk);
+ Time end = timeService.newTime(start.getTime() + 24 * 60 * 60 * 1000);
+ return timeService.newTimeRange(start, end, true, false);
}
}
diff --git a/kernel-impl/src/main/java/org/sakaiproject/email/impl/BasicEmailService.java b/kernel-impl/src/main/java/org/sakaiproject/email/impl/BasicEmailService.java
index 1464531..5f5e0ed 100644
--- a/kernel-impl/src/main/java/org/sakaiproject/email/impl/BasicEmailService.java
+++ b/kernel-impl/src/main/java/org/sakaiproject/email/impl/BasicEmailService.java
@@ -24,7 +24,6 @@ package org.sakaiproject.email.impl;
import java.io.UnsupportedEncodingException;
import javax.mail.internet.MimeUtility;
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
@@ -69,7 +68,7 @@ import org.sakaiproject.user.api.User;
* BasicEmailService implements the EmailService.
*
*/
-public abstract class BasicEmailService implements EmailService
+public class BasicEmailService implements EmailService
{
/** Our logger. */
private static Log M_log = LogFactory.getLog(BasicEmailService.class);
@@ -103,16 +102,12 @@ public abstract class BasicEmailService implements EmailService
/** Protocol name for smtp. */
protected static final String SMTP_PROTOCOL = "smtp";
- /**********************************************************************************************************************************************************************************************************************************************************
- * Dependencies Note: keep these in sync with the TestEmailService, to make switching between them easier -ggolden
- *********************************************************************************************************************************************************************************************************************************************************/
-
- /**
- * @return the ServerConfigurationService collaborator.
- */
- protected abstract ServerConfigurationService serverConfigurationService();
+ protected ServerConfigurationService serverConfigurationService;
-// protected abstract ContentHostingService contentHostingService();
+ public void setServerConfigurationService(ServerConfigurationService serverConfigurationService)
+ {
+ this.serverConfigurationService = serverConfigurationService;
+ }
/**********************************************************************************************************************************************************************************************************************************************************
* Configuration Note: keep these in sync with the TestEmailService, to make switching between them easier -ggolden
@@ -232,7 +227,7 @@ public abstract class BasicEmailService implements EmailService
// if no m_mailfrom set, set to the postmaster
if (m_smtpFrom == null)
{
- m_smtpFrom = POSTMASTER + "@" + serverConfigurationService().getServerName();
+ m_smtpFrom = POSTMASTER + "@" + serverConfigurationService.getServerName();
}
// promote these to the system properties, to keep others (James) from messing with them
diff --git a/kernel-impl/src/main/java/org/sakaiproject/email/impl/DbDigestService.java b/kernel-impl/src/main/java/org/sakaiproject/email/impl/DbDigestService.java
index 4ab3f94..c4afd3b 100644
--- a/kernel-impl/src/main/java/org/sakaiproject/email/impl/DbDigestService.java
+++ b/kernel-impl/src/main/java/org/sakaiproject/email/impl/DbDigestService.java
@@ -36,7 +36,7 @@ import org.sakaiproject.util.StorageUser;
* DbDigestService is an extension of the BaseDigestService with database storage.
*
*/
-public abstract class DbDigestService extends BaseDigestService
+public class DbDigestService extends BaseDigestService
{
/** Our logger. */
private static Log M_log = LogFactory.getLog(DbDigestService.class);
@@ -47,6 +47,8 @@ public abstract class DbDigestService extends BaseDigestService
/** If true, we do our locks in the remote database, otherwise we do them here. */
protected boolean m_locksInDb = true;
+ protected SqlService sqlService;
+
/**********************************************************************************************************************************************************************************************************************************************************
* Dependencies
*********************************************************************************************************************************************************************************************************************************************************/
@@ -54,7 +56,10 @@ public abstract class DbDigestService extends BaseDigestService
/**
* @return the MemoryService collaborator.
*/
- protected abstract SqlService sqlService();
+ public void setSqlService(SqlService sqlService)
+ {
+ this.sqlService = sqlService;
+ }
/**********************************************************************************************************************************************************************************************************************************************************
* Configuration
@@ -110,7 +115,7 @@ public abstract class DbDigestService extends BaseDigestService
// if we are auto-creating our schema, check and create
if (m_autoDdl)
{
- sqlService().ddl(this.getClass().getClassLoader(), "sakai_digest");
+ sqlService.ddl(this.getClass().getClassLoader(), "sakai_digest");
}
super.init();
@@ -154,7 +159,7 @@ public abstract class DbDigestService extends BaseDigestService
*/
public DbStorage(StorageUser user)
{
- super(m_tableName, "DIGEST_ID", null, m_locksInDb, "digest", user, sqlService());
+ super(m_tableName, "DIGEST_ID", null, m_locksInDb, "digest", user, sqlService);
}
public boolean check(String id)
diff --git a/kernel-impl/src/main/java/org/sakaiproject/email/impl/DigestServiceTest.java b/kernel-impl/src/main/java/org/sakaiproject/email/impl/DigestServiceTest.java
deleted file mode 100644
index 86f422f..0000000
--- a/kernel-impl/src/main/java/org/sakaiproject/email/impl/DigestServiceTest.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/**********************************************************************************
- * $URL$
- * $Id$
- ***********************************************************************************
- *
- * Copyright (c) 2006, 2008 Sakai Foundation
- *
- * Licensed under the Educational Community 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.osedu.org/licenses/ECL-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.sakaiproject.email.impl;
-
-import org.sakaiproject.authz.api.SecurityService;
-import org.sakaiproject.component.api.ServerConfigurationService;
-import org.sakaiproject.db.api.SqlService;
-import org.sakaiproject.email.api.EmailService;
-import org.sakaiproject.event.api.EventTrackingService;
-import org.sakaiproject.time.api.TimeService;
-import org.sakaiproject.user.api.UserDirectoryService;
-import org.sakaiproject.tool.api.SessionManager;
-
-/**
- *
- * DigestServiceTest extends the db digest service providing the dependency injectors for testing.
- *
- */
-public class DigestServiceTest extends DbDigestService
-{
- /**
- * @return the MemoryService collaborator.
- */
- protected SqlService sqlService()
- {
- return null;
- }
-
- /**
- * @return the TimeService collaborator.
- */
- protected TimeService timeService()
- {
- return null;
- }
-
- /**
- * @return the ServerConfigurationService collaborator.
- */
- protected ServerConfigurationService serverConfigurationService()
- {
- return null;
- }
-
- /**
- * @return the EmailService collaborator.
- */
- protected EmailService emailService()
- {
- return null;
- }
-
- /**
- * @return the EventTrackingService collaborator.
- */
- protected EventTrackingService eventTrackingService()
- {
- return null;
- }
-
- /**
- * @return the MemoryServiSecurityServicece collaborator.
- */
- protected SecurityService securityService()
- {
- return null;
- }
-
- /**
- * @return the UserDirectoryService collaborator.
- */
- protected UserDirectoryService userDirectoryService()
- {
- return null;
- }
-
- /**
- * @return the SessionManager collaborator.
- */
- protected SessionManager sessionManager()
- {
- return null;
- }
-}
diff --git a/kernel-impl/src/main/java/org/sakaiproject/email/impl/EmailServiceTest.java b/kernel-impl/src/main/java/org/sakaiproject/email/impl/EmailServiceTest.java
deleted file mode 100644
index a2687e4..0000000
--- a/kernel-impl/src/main/java/org/sakaiproject/email/impl/EmailServiceTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**********************************************************************************
- * $URL$
- * $Id$
- ***********************************************************************************
- *
- * Copyright (c) 2006, 2008 Sakai Foundation
- *
- * Licensed under the Educational Community 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.osedu.org/licenses/ECL-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.sakaiproject.email.impl;
-
-import org.sakaiproject.component.api.ServerConfigurationService;
-
-// import org.sakaiproject.content.api.ContentHostingService;
-
-/**
- *
- * EmailServiceTest extends the basic alias service providing the dependency injectors for testing.
- * This class is here to ensure that abstract methods not implemented by BasicEmailService are not
- * overlooked somehow and create problems on server start. BasicEmailService has abstract methods
- * that are implemented by Spring using lookup-method.
- *
- */
-public class EmailServiceTest extends BasicEmailService
-{
- /**
- * @return the ServerConfigurationService collaborator.
- */
- protected ServerConfigurationService serverConfigurationService()
- {
- return null;
- }
-}
\ No newline at end of file
diff --git a/kernel-impl/src/test/java/org/sakaiproject/component/test/ConfigurationLoadingTest.java b/kernel-impl/src/test/java/org/sakaiproject/component/test/ConfigurationLoadingTest.java
index baf7557..742dc5b 100644
--- a/kernel-impl/src/test/java/org/sakaiproject/component/test/ConfigurationLoadingTest.java
+++ b/kernel-impl/src/test/java/org/sakaiproject/component/test/ConfigurationLoadingTest.java
@@ -25,7 +25,6 @@ package org.sakaiproject.component.test;
import junit.extensions.TestSetup;
import junit.framework.Assert;
import junit.framework.Test;
-import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.logging.Log;
@@ -56,7 +55,6 @@ public class ConfigurationLoadingTest extends SakaiKernelTestBase {
}
protected void tearDown() throws Exception {
oneTimeTearDown();
- TestComponentManagerContainer.setSakaiHome(null);
}
};
return setup;
diff --git a/kernel-impl/src/test/java/org/sakaiproject/component/test/DynamicConfigurationTest.java b/kernel-impl/src/test/java/org/sakaiproject/component/test/DynamicConfigurationTest.java
index 0e150b2..6c4143f 100644
--- a/kernel-impl/src/test/java/org/sakaiproject/component/test/DynamicConfigurationTest.java
+++ b/kernel-impl/src/test/java/org/sakaiproject/component/test/DynamicConfigurationTest.java
@@ -56,7 +56,6 @@ public class DynamicConfigurationTest extends SakaiKernelTestBase {
}
protected void tearDown() throws Exception {
oneTimeTearDown();
- TestComponentManagerContainer.setSakaiHome(null);
}
};
return setup;
diff --git a/kernel-impl/src/test/java/org/sakaiproject/email/impl/test/EmailServiceTest.java b/kernel-impl/src/test/java/org/sakaiproject/email/impl/test/EmailServiceTest.java
new file mode 100644
index 0000000..8ea3190
--- /dev/null
+++ b/kernel-impl/src/test/java/org/sakaiproject/email/impl/test/EmailServiceTest.java
@@ -0,0 +1,240 @@
+/**********************************************************************************
+ * $URL$
+ * $Id$
+ ***********************************************************************************
+ *
+ * Copyright 2003, 2004, 2005, 2006, 2008 Sakai Foundation
+ *
+ * Licensed under the Educational Community 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.osedu.org/licenses/ECL-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.sakaiproject.email.impl.test;
+
+import com.dumbster.smtp.SimpleSmtpServer;
+import com.dumbster.smtp.SmtpMessage;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.mail.internet.InternetAddress;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.sakaiproject.email.api.Attachment;
+import org.sakaiproject.email.api.EmailAddress;
+import org.sakaiproject.email.api.EmailMessage;
+import org.sakaiproject.email.api.RecipientType;
+import org.sakaiproject.email.impl.BaseAttachment;
+import org.sakaiproject.email.impl.BaseEmailAddress;
+import org.sakaiproject.email.impl.BaseEmailMessage;
+import org.sakaiproject.email.impl.BasicEmailService;
+
+public class EmailServiceTest extends TestCase
+{
+ static Log log = LogFactory.getLog(EmailServiceTest.class);
+
+ static final boolean USE_INT_MAIL_SERVER = false;
+ static final boolean LOG_SENT_EMAIL = false;
+
+ static SimpleSmtpServer server;
+ static BasicEmailService emailService;
+
+ InternetAddress from;
+ InternetAddress[] to;
+ String subject;
+ String content;
+ HashMap headerToMap;
+ InternetAddress[] headerTo;
+ InternetAddress[] replyTo;
+ ArrayList additionalHeaders;
+ ArrayList attachments;
+
+ public static Test suite()
+ {
+ TestSetup setup = new TestSetup(new TestSuite(EmailServiceTest.class))
+ {
+ protected void setUp() throws Exception
+ {
+ try
+ {
+ emailService = new BasicEmailService();
+
+ if (USE_INT_MAIL_SERVER)
+ {
+ emailService.setSmtp("localhost");
+ emailService.setSmtpPort("8025");
+ emailService.init();
+ server = SimpleSmtpServer.start(8025);
+ }
+ else
+ {
+ emailService.setTestMode(true);
+ }
+ }
+ catch (Exception e)
+ {
+ log.warn(e);
+ }
+ }
+
+ protected void tearDown() throws Exception
+ {
+ emailService.destroy();
+ if (server != null && !server.isStopped())
+ {
+ if (LOG_SENT_EMAIL)
+ {
+ for (Iterator emails = server.getReceivedEmail(); emails.hasNext(); )
+ {
+ SmtpMessage email = emails.next();
+ log.info(email);
+ }
+ }
+ server.stop();
+ }
+ }
+ };
+ return setup;
+ }
+
+ public void setUp() throws Exception
+ {
+ from = new InternetAddress("from@example.com");
+
+ to = new InternetAddress[2];
+ to[0] = new InternetAddress("to@example.com");
+ to[1] = new InternetAddress("too@example.com");
+
+ subject = "Super cool test subject";
+
+ content = "Super cool test content";
+
+ headerToMap = new HashMap();
+ headerTo = new InternetAddress[1];
+ // create the TO
+ headerTo[0] = new InternetAddress("randomDude@example.com", "Random Dude");
+ headerToMap.put(RecipientType.TO, headerTo);
+ // create the CC
+ headerTo[0] = new InternetAddress("otherPerson@example.com");
+ headerToMap.put(RecipientType.CC, headerTo);
+
+ replyTo = new InternetAddress[1];
+ replyTo[0] = new InternetAddress("replyTo@example.com");
+
+ additionalHeaders = new ArrayList();
+ additionalHeaders.add("x-testmessage-rocks: super-awesome");
+
+ attachments = new ArrayList();
+ File f1 = File.createTempFile("testFile1", ".txt");
+ f1.deleteOnExit();
+ FileWriter fw1 = new FileWriter(f1);
+ fw1.write("This is some really killer test text for the first attachment.");
+ fw1.flush();
+ fw1.close();
+ File f2 = File.createTempFile("testFile2", ".csv");
+ f2.deleteOnExit();
+ FileWriter fw2 = new FileWriter(f2);
+ fw2.write("this,is,some,comma,delimited\ntext,in,a,message,body");
+ fw2.flush();
+ fw2.close();
+ attachments.add(new BaseAttachment(f1));
+ attachments.add(new BaseAttachment(f2));
+ }
+
+ public void tearDown() throws Exception
+ {
+ }
+
+ public void testSend() throws Exception
+ {
+ emailService.send(from.getAddress(), to[0].getAddress() + ", test2@example.com", subject,
+ content, headerTo[0].getAddress(), replyTo[0].getAddress(), additionalHeaders);
+ }
+
+ public void testSendMessageWithoutAttachments() throws Exception
+ {
+ // create message with from, subject, content
+ EmailMessage msg = new BaseEmailMessage(from.getAddress(), subject, content);
+ // add message recipients that appear in the header
+ HashMap> tos = new HashMap>();
+ for (RecipientType type : headerToMap.keySet())
+ {
+ ArrayList addrs = new ArrayList();
+ for (InternetAddress iaddr : headerToMap.get(type))
+ {
+ addrs.add(new BaseEmailAddress(iaddr.getAddress(), iaddr.getPersonal()));
+ }
+ tos.put(type, addrs);
+ }
+ // add the actual recipients
+ tos.put(RecipientType.ACTUAL, BaseEmailAddress.toEmailAddress(to));
+ msg.setRecipients(tos);
+ // add additional headers
+ msg.setHeaders(additionalHeaders);
+ // send message
+ emailService.send(msg);
+ }
+
+ public void testSendEmailMessage() throws Exception
+ {
+ // create message with from, subject, content
+ EmailMessage msg = new BaseEmailMessage(from.getAddress(), subject + " with attachments",
+ content);
+ // add message recipients that appear in the header
+ HashMap> tos = new HashMap>();
+ for (RecipientType type : headerToMap.keySet())
+ {
+ ArrayList addrs = new ArrayList();
+ for (InternetAddress iaddr : headerToMap.get(type))
+ {
+ addrs.add(new BaseEmailAddress(iaddr.getAddress(), iaddr.getPersonal()));
+ }
+ tos.put(type, addrs);
+ }
+ // add the actual recipients
+ tos.put(RecipientType.ACTUAL, BaseEmailAddress.toEmailAddress(to));
+ msg.setRecipients(tos);
+ // add additional headers
+ msg.setHeaders(additionalHeaders);
+ // add attachments
+ msg.setAttachments(attachments);
+ // send message
+ emailService.send(msg);
+ }
+
+ public void testSendMailBasic() throws Exception
+ {
+ emailService.sendMail(from, to, subject, content, null, null, null, null);
+ }
+
+ public void testSendMailAllButAttachments() throws Exception
+ {
+ emailService.sendMail(from, to, subject, content, headerTo, replyTo, additionalHeaders);
+ }
+
+ public void testSendMailAll() throws Exception
+ {
+ emailService.sendMail(from, to, subject, content, headerToMap, replyTo, additionalHeaders,
+ attachments);
+ }
+}
\ No newline at end of file
diff --git a/kernel-impl/src/test/java/org/sakaiproject/email/impl/test/EmailServiceTestDisabled.java b/kernel-impl/src/test/java/org/sakaiproject/email/impl/test/EmailServiceTestDisabled.java
deleted file mode 100644
index fc75a41..0000000
--- a/kernel-impl/src/test/java/org/sakaiproject/email/impl/test/EmailServiceTestDisabled.java
+++ /dev/null
@@ -1,220 +0,0 @@
-package org.sakaiproject.email.impl.test;
-
-import com.dumbster.smtp.SimpleSmtpServer;
-import com.dumbster.smtp.SmtpMessage;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.mail.internet.InternetAddress;
-
-import junit.extensions.TestSetup;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.sakaiproject.email.api.Attachment;
-import org.sakaiproject.email.api.EmailAddress;
-import org.sakaiproject.email.api.EmailMessage;
-import org.sakaiproject.email.api.EmailService;
-import org.sakaiproject.email.api.RecipientType;
-import org.sakaiproject.email.impl.BaseAttachment;
-import org.sakaiproject.email.impl.BaseEmailAddress;
-import org.sakaiproject.email.impl.BaseEmailMessage;
-import org.sakaiproject.test.SakaiKernelTestBase;
-
-public class EmailServiceTestDisabled extends SakaiKernelTestBase
-{
- private static Log log = LogFactory.getLog(EmailServiceTestDisabled.class);
-
- private static final boolean USE_INT_MAIL_SERVER = true;
- private static final boolean LOG_SENT_EMAIL = true;
-
- static SimpleSmtpServer server;
-
- EmailService emailService;
-
- InternetAddress from;
- InternetAddress[] to;
- String subject;
- String content;
- HashMap headerToMap;
- InternetAddress[] headerTo;
- InternetAddress[] replyTo;
- ArrayList additionalHeaders;
- ArrayList attachments;
-
- public static Test suite()
- {
- TestSetup setup = new TestSetup(new TestSuite(EmailServiceTestDisabled.class))
- {
- protected void setUp() throws Exception
- {
- if (log.isDebugEnabled())
- log.info("starting setup");
- try
- {
- oneTimeSetup(null);
- }
- catch (Exception e)
- {
- log.warn(e);
- }
- if (log.isDebugEnabled())
- log.debug("finished setup");
- }
-
- protected void tearDown() throws Exception
- {
- if (log.isDebugEnabled())
- log.info("tearing down");
- oneTimeTearDown();
- }
- };
- return setup;
- }
-
- public void setUp() throws Exception
- {
- log.info("Setting up test case...");
- from = new InternetAddress("from@example.com");
-
- to = new InternetAddress[2];
- to[0] = new InternetAddress("to@example.com");
- to[1] = new InternetAddress("too@example.com");
-
- subject = "Super cool test subject";
-
- content = "Super cool test content";
-
- headerToMap = new HashMap();
- headerTo = new InternetAddress[1];
- // create the TO
- headerTo[0] = new InternetAddress("randomDude@example.com", "Random Dude");
- headerToMap.put(RecipientType.TO, headerTo);
- // create the CC
- headerTo[0] = new InternetAddress("otherPerson@example.com");
- headerToMap.put(RecipientType.CC, headerTo);
-
- replyTo = new InternetAddress[1];
- replyTo[0] = new InternetAddress("replyTo@example.com");
-
- additionalHeaders = new ArrayList();
- additionalHeaders.add("x-testmessage-rocks: super-awesome");
-
- attachments = new ArrayList();
- File f1 = File.createTempFile("testFile1", ".txt");
- f1.deleteOnExit();
- FileWriter fw1 = new FileWriter(f1);
- fw1.write("This is some really killer test text for the first attachment.");
- fw1.flush();
- fw1.close();
- File f2 = File.createTempFile("testFile2", ".csv");
- f2.deleteOnExit();
- FileWriter fw2 = new FileWriter(f2);
- fw2.write("this,is,some,comma,delimited\ntext,in,a,message,body");
- fw2.flush();
- fw2.close();
- attachments.add(new BaseAttachment(f1));
- attachments.add(new BaseAttachment(f2));
-
- emailService = (EmailService) getService(EmailService.class.getName());
-
- if (USE_INT_MAIL_SERVER)
- server = SimpleSmtpServer.start(8025);
- }
-
- public void tearDown() throws Exception
- {
- if (server != null && !server.isStopped())
- {
- if (LOG_SENT_EMAIL)
- {
- for (Iterator emails = server.getReceivedEmail(); emails.hasNext(); )
- {
- SmtpMessage email = emails.next();
- log.info(email);
- }
- }
- server.stop();
- }
- }
-
- public void testSend() throws Exception
- {
- emailService.send(from.getAddress(), to[0].getAddress() + ", test2@example.com", subject,
- content, headerTo[0].getAddress(), replyTo[0].getAddress(), additionalHeaders);
- }
-
- public void testSendMessageWithoutAttachments() throws Exception
- {
- // create message with from, subject, content
- EmailMessage msg = new BaseEmailMessage(from.getAddress(), subject, content);
- // add message recipients that appear in the header
- HashMap> tos = new HashMap>();
- for (RecipientType type : headerToMap.keySet())
- {
- ArrayList addrs = new ArrayList();
- for (InternetAddress iaddr : headerToMap.get(type))
- {
- addrs.add(new BaseEmailAddress(iaddr.getAddress(), iaddr.getPersonal()));
- }
- tos.put(type, addrs);
- }
- // add the actual recipients
- tos.put(RecipientType.ACTUAL, BaseEmailAddress.toEmailAddress(to));
- msg.setRecipients(tos);
- // add additional headers
- msg.setHeaders(additionalHeaders);
- // send message
- emailService.send(msg);
- }
-
- public void testSendEmailMessage() throws Exception
- {
- // create message with from, subject, content
- EmailMessage msg = new BaseEmailMessage(from.getAddress(), subject + " with attachments",
- content);
- // add message recipients that appear in the header
- HashMap> tos = new HashMap>();
- for (RecipientType type : headerToMap.keySet())
- {
- ArrayList addrs = new ArrayList();
- for (InternetAddress iaddr : headerToMap.get(type))
- {
- addrs.add(new BaseEmailAddress(iaddr.getAddress(), iaddr.getPersonal()));
- }
- tos.put(type, addrs);
- }
- // add the actual recipients
- tos.put(RecipientType.ACTUAL, BaseEmailAddress.toEmailAddress(to));
- msg.setRecipients(tos);
- // add additional headers
- msg.setHeaders(additionalHeaders);
- // add attachments
- msg.setAttachments(attachments);
- // send message
- emailService.send(msg);
- }
-
- public void testSendMailBasic() throws Exception
- {
- emailService.sendMail(from, to, subject, content, null, null, null, null);
- }
-
- public void testSendMailAllButAttachments() throws Exception
- {
- emailService.sendMail(from, to, subject, content, headerTo, replyTo, additionalHeaders);
- }
-
- public void testSendMailAll() throws Exception
- {
- emailService.sendMail(from, to, subject, content, headerToMap, replyTo, additionalHeaders,
- attachments);
- }
-}
\ No newline at end of file