forked from sakaiproject/sakai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attachments sent to email archive from Email tool arent accessible
- Loading branch information
Showing
5 changed files
with
143 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,15 +167,16 @@ List<String> sendEmail(ConfigEntry config, String fromEmail, String fromName, | |
/** | ||
* Append email to Email Archive | ||
* | ||
* @param config | ||
* @param channelRef | ||
* @param sender | ||
* @param subject | ||
* @param body | ||
* @param config The config used by the user, can be <code>null</code>. | ||
* @param channelRef The Email Archive channel reference to add the email to. | ||
* @param sender The email sender (eg John Smith <[email protected]>) | ||
* @param subject The Subject of the email. | ||
* @param body The body of the email message. | ||
* @param attachments A list of attachments, can be <code>null</code>. | ||
* @return true if success | ||
*/ | ||
boolean addToArchive(ConfigEntry config, String channelRef, String sender, String subject, | ||
String body); | ||
String body, List<Attachment> attachments); | ||
|
||
/** | ||
* @return the current location id of the current user | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,13 +22,14 @@ | |
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
import static org.mockito.Matchers.eq; | ||
import static org.mockito.Matchers.isA; | ||
import static org.mockito.Matchers.*; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.reset; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.InputStream; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
|
||
|
@@ -41,7 +42,14 @@ | |
import org.sakaiproject.authz.api.FunctionManager; | ||
import org.sakaiproject.authz.api.SecurityService; | ||
import org.sakaiproject.component.api.ServerConfigurationService; | ||
import org.sakaiproject.content.api.ContentHostingService; | ||
import org.sakaiproject.content.api.ContentResource; | ||
import org.sakaiproject.email.api.Attachment; | ||
import org.sakaiproject.email.api.EmailService; | ||
import org.sakaiproject.entity.api.EntityManager; | ||
import org.sakaiproject.entity.api.Reference; | ||
import org.sakaiproject.entity.api.ResourceProperties; | ||
import org.sakaiproject.entity.api.ResourcePropertiesEdit; | ||
import org.sakaiproject.event.api.EventTrackingService; | ||
import org.sakaiproject.event.api.NotificationService; | ||
import org.sakaiproject.exception.IdUnusedException; | ||
|
@@ -61,6 +69,8 @@ | |
import org.sakaiproject.user.api.UserDirectoryService; | ||
import org.sakaiproject.user.api.UserNotDefinedException; | ||
|
||
import javax.activation.DataSource; | ||
|
||
/** | ||
* @author chall | ||
* | ||
|
@@ -95,6 +105,10 @@ public class ExternalLogicImplTest { | |
ServerConfigurationService configService; | ||
@Mock | ||
EventTrackingService eventService; | ||
@Mock | ||
EntityManager entityManager; | ||
@Mock | ||
ContentHostingService contentHostingService; | ||
|
||
static final String LOCATION_ID = "locationId"; | ||
static final String LOCATION_TITLE = "Location Title"; | ||
|
@@ -128,6 +142,8 @@ public void setUp() throws Exception { | |
impl.setUserDirectoryService(userDirectoryService); | ||
impl.setServerConfigurationService(configService); | ||
impl.setEventTrackingService(eventService); | ||
impl.setEntityManager(entityManager); | ||
impl.setContentHostingService(contentHostingService); | ||
|
||
impl.init(); | ||
} | ||
|
@@ -309,16 +325,57 @@ public void emailArchiveIsNotAddedToSite() throws Exception { | |
|
||
// #1 | ||
assertFalse("Permission exception from getMailArchiveChannel() should return false", | ||
impl.addToArchive(null, "channel", null, null, null)); | ||
impl.addToArchive(null, "channel", null, null, null, null)); | ||
// #2 | ||
assertFalse("Need a non-null channel", | ||
impl.addToArchive(null, "channel", null, null, null)); | ||
impl.addToArchive(null, "channel", null, null, null, null)); | ||
// #3 | ||
assertFalse("Permission exception from addMessage() should return false", | ||
impl.addToArchive(null, "channel", null, null, null)); | ||
impl.addToArchive(null, "channel", null, null, null, null)); | ||
// #4 | ||
assertTrue(impl.addToArchive(null, "channel", null, null, null)); | ||
assertTrue(impl.addToArchive(null, "channel", null, null, null, null)); | ||
|
||
verify(channel).commitMessage(eq(msg), eq(NotificationService.NOTI_NONE)); | ||
} | ||
|
||
@Test | ||
public void sendEmailToArchiveWithAttachments() throws Exception { | ||
// Simple test of adding email to archive. | ||
MailArchiveChannel channel = mock(MailArchiveChannel.class); | ||
MailArchiveMessageEdit message = mock(MailArchiveMessageEdit.class); | ||
MailArchiveMessageHeaderEdit headers = mock(MailArchiveMessageHeaderEdit.class); | ||
|
||
when(channel.addMessage()).thenReturn(message); | ||
when(message.getMailArchiveHeaderEdit()).thenReturn(headers); | ||
when(message.getId()).thenReturn("messageId"); | ||
|
||
when(channel.getContext()).thenReturn("siteId"); | ||
|
||
ContentResource resource = mock(ContentResource.class); | ||
ResourcePropertiesEdit attachmentProperties = mock(ResourcePropertiesEdit.class); | ||
|
||
when(contentHostingService.newResourceProperties()).thenReturn(attachmentProperties); | ||
when(contentHostingService.addAttachmentResource( | ||
anyString(), anyString(), anyString(), anyString(), any(InputStream.class), any(ResourceProperties.class) | ||
)).thenReturn(resource); | ||
when(resource.getReference()).thenReturn("attachmentReference"); | ||
|
||
Reference ref = mock(Reference.class); | ||
when(entityManager.newReference("attachmentReference")).thenReturn(ref); | ||
|
||
when(mailArchiveService.getMailArchiveChannel("channel")).thenReturn(channel); | ||
|
||
DataSource dataSource = mock(DataSource.class); | ||
when(dataSource.getInputStream()).thenReturn(new ByteArrayInputStream("Hello World".getBytes("UTF-8"))); | ||
Attachment attachment = mock(Attachment.class); | ||
when(attachment.getContentTypeHeader()).thenReturn("text/plain"); | ||
when(attachment.getFilename()).thenReturn("test.txt"); | ||
when(attachment.getDataSource()).thenReturn(dataSource); | ||
|
||
impl.addToArchive(null, "channel", "[email protected]", "Subject", "Body Message", | ||
Collections.singletonList(attachment)); | ||
|
||
verify(channel).commitMessage(message, NotificationService.NOTI_NONE); | ||
verify(headers).addAttachment(ref); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters