Search in sources :

Example 16 with MailAddress

use of org.apache.mailet.MailAddress in project nhin-d by DirectProject.

the class NHINDSecurityAndTrustMailet_service_Test method testService_UseToHeader_AssertRecipientsUsed.

public void testService_UseToHeader_AssertRecipientsUsed() throws Exception {
    final MimeMessage mimeMsg = EntitySerializer.Default.deserialize(TestUtils.readMessageResource("PlainOutgoingMessage.txt"));
    final SmtpAgent mockAgent = mock(SmtpAgent.class);
    when(mockAgent.processMessage((MimeMessage) any(), (NHINDAddressCollection) any(), (NHINDAddress) any())).thenAnswer(new Answer<MessageProcessResult>() {

        public MessageProcessResult answer(InvocationOnMock invocation) throws Throwable {
            usedRecipients = (NHINDAddressCollection) invocation.getArguments()[1];
            return new MessageProcessResult(new DefaultMessageEnvelope(new Message(mimeMsg)), null);
        }
    });
    final Mail mockMail = mock(MockMail.class, CALLS_REAL_METHODS);
    when(mockMail.getRecipients()).thenReturn(null);
    when(mockMail.getSender()).thenReturn(new MailAddress("me@cerner.com"));
    mockMail.setMessage(mimeMsg);
    NHINDSecurityAndTrustMailet mailet = new NHINDSecurityAndTrustMailet();
    mailet.agent = mockAgent;
    mailet.service(mockMail);
    assertNotNull(usedRecipients);
    assertEquals(1, usedRecipients.size());
    assertEquals("externUser1@starugh-stateline.com", usedRecipients.iterator().next().toString());
}
Also used : Mail(org.apache.mailet.Mail) MailAddress(org.apache.mailet.MailAddress) Message(org.nhindirect.stagent.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MimeMessage(javax.mail.internet.MimeMessage) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NHINDAddressCollection(org.nhindirect.stagent.NHINDAddressCollection) DefaultMessageEnvelope(org.nhindirect.stagent.DefaultMessageEnvelope) SmtpAgent(org.nhindirect.gateway.smtp.SmtpAgent) MessageProcessResult(org.nhindirect.gateway.smtp.MessageProcessResult)

Example 17 with MailAddress

use of org.apache.mailet.MailAddress in project nhin-d by DirectProject.

the class IsNotSMIMEEncryptedTest method testIsNotSMIMEMessage_unecryptedMessage_assertAllRecips.

@SuppressWarnings("unchecked")
public void testIsNotSMIMEMessage_unecryptedMessage_assertAllRecips() throws Exception {
    MimeMessage msg = new MimeMessage(null, IOUtils.toInputStream(TestUtils.readMessageResource("PlainOutgoingMessage.txt")));
    IsNotSMIMEEncrypted matcher = new IsNotSMIMEEncrypted();
    final Collection<MailAddress> initialRecips = new ArrayList<MailAddress>();
    for (InternetAddress addr : (InternetAddress[]) msg.getAllRecipients()) initialRecips.add(new MailAddress(addr.getAddress()));
    final MockMail mockMail = new MockMail(msg);
    mockMail.setRecipients(initialRecips);
    Collection<MailAddress> matchAddresses = matcher.match(mockMail);
    assertEquals(1, matchAddresses.size());
    assertEquals(initialRecips.iterator().next().toString(), matchAddresses.iterator().next().toString());
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MailAddress(org.apache.mailet.MailAddress) MimeMessage(javax.mail.internet.MimeMessage) MockMail(org.nhindirect.gateway.smtp.james.mailet.MockMail) ArrayList(java.util.ArrayList)

Example 18 with MailAddress

use of org.apache.mailet.MailAddress in project nhin-d by DirectProject.

the class IsNotSMIMEEncryptedTest method testIsNotSMIMEMessage_ecryptedMessage_assertNull.

@SuppressWarnings("unchecked")
public void testIsNotSMIMEMessage_ecryptedMessage_assertNull() throws Exception {
    MimeMessage msg = new MimeMessage(null, IOUtils.toInputStream(TestUtils.readMessageResource("EncryptedMessage.txt")));
    IsNotSMIMEEncrypted matcher = new IsNotSMIMEEncrypted();
    final Collection<MailAddress> initialRecips = new ArrayList<MailAddress>();
    for (InternetAddress addr : (InternetAddress[]) msg.getAllRecipients()) initialRecips.add(new MailAddress(addr.getAddress()));
    final MockMail mockMail = new MockMail(msg);
    mockMail.setRecipients(initialRecips);
    Collection<MailAddress> matchAddresses = matcher.match(mockMail);
    assertEquals(null, matchAddresses);
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MailAddress(org.apache.mailet.MailAddress) MimeMessage(javax.mail.internet.MimeMessage) MockMail(org.nhindirect.gateway.smtp.james.mailet.MockMail) ArrayList(java.util.ArrayList)

Example 19 with MailAddress

use of org.apache.mailet.MailAddress in project nhin-d by DirectProject.

the class IsNotSMIMEEncryptedTest method testIsNotSMIMEMessage_nullMessage_assertNull.

@SuppressWarnings("unchecked")
public void testIsNotSMIMEMessage_nullMessage_assertNull() throws Exception {
    IsNotSMIMEEncrypted matcher = new IsNotSMIMEEncrypted();
    final MockMail mockMail = new MockMail(null);
    Collection<MailAddress> matchAddresses = matcher.match(mockMail);
    assertEquals(null, matchAddresses);
}
Also used : MailAddress(org.apache.mailet.MailAddress) MockMail(org.nhindirect.gateway.smtp.james.mailet.MockMail)

Example 20 with MailAddress

use of org.apache.mailet.MailAddress in project nhin-d by DirectProject.

the class IsNotificationTest method testIsNotification_MDNMessage_assertAllRecips.

@SuppressWarnings("unchecked")
public void testIsNotification_MDNMessage_assertAllRecips() throws Exception {
    MimeMessage msg = new MimeMessage(null, IOUtils.toInputStream(TestUtils.readMessageResource("MDNMessage.txt")));
    IsNotification matcher = new IsNotification();
    final Collection<MailAddress> initialRecips = new ArrayList<MailAddress>();
    for (InternetAddress addr : (InternetAddress[]) msg.getAllRecipients()) initialRecips.add(new MailAddress(addr.getAddress()));
    final MockMail mockMail = new MockMail(msg);
    mockMail.setRecipients(initialRecips);
    Collection<MailAddress> matchAddresses = matcher.match(mockMail);
    assertEquals(1, matchAddresses.size());
    assertEquals(initialRecips.iterator().next().toString(), matchAddresses.iterator().next().toString());
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MailAddress(org.apache.mailet.MailAddress) MimeMessage(javax.mail.internet.MimeMessage) MockMail(org.nhindirect.gateway.smtp.james.mailet.MockMail) ArrayList(java.util.ArrayList)

Aggregations

MailAddress (org.apache.mailet.MailAddress)28 MimeMessage (javax.mail.internet.MimeMessage)17 ArrayList (java.util.ArrayList)11 Mail (org.apache.mailet.Mail)11 InternetAddress (javax.mail.internet.InternetAddress)8 MockMail (org.nhindirect.gateway.smtp.james.mailet.MockMail)8 SmtpAgent (org.nhindirect.gateway.smtp.SmtpAgent)7 NHINDAddressCollection (org.nhindirect.stagent.NHINDAddressCollection)7 NHINDAddress (org.nhindirect.stagent.NHINDAddress)6 Collection (java.util.Collection)5 MessageProcessResult (org.nhindirect.gateway.smtp.MessageProcessResult)5 Address (javax.mail.Address)4 MessagingException (javax.mail.MessagingException)4 MatcherConfig (org.apache.mailet.MatcherConfig)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 Message (org.nhindirect.stagent.mail.Message)4 Tx (org.nhindirect.common.tx.model.Tx)2 SmtpAgentException (org.nhindirect.gateway.smtp.SmtpAgentException)2 DefaultMessageEnvelope (org.nhindirect.stagent.DefaultMessageEnvelope)2 NotificationMessage (org.nhindirect.stagent.mail.notifications.NotificationMessage)2