Search in sources :

Example 6 with SmtpAgent

use of org.nhindirect.gateway.smtp.SmtpAgent 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 7 with SmtpAgent

use of org.nhindirect.gateway.smtp.SmtpAgent in project nhin-d by DirectProject.

the class NHINDSecurityAndTrustMailet_service_Test method testService_ProcessIsNull_AssertGhostState.

public void testService_ProcessIsNull_AssertGhostState() throws Exception {
    final MimeMessage mimeMsg = EntitySerializer.Default.deserialize(TestUtils.readMessageResource("PlainOutgoingMessage.txt"));
    final SmtpAgent mockAgent = mock(SmtpAgent.class);
    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);
    assertEquals(Mail.GHOST, mockMail.getState());
}
Also used : Mail(org.apache.mailet.Mail) MailAddress(org.apache.mailet.MailAddress) MimeMessage(javax.mail.internet.MimeMessage) SmtpAgent(org.nhindirect.gateway.smtp.SmtpAgent)

Aggregations

MimeMessage (javax.mail.internet.MimeMessage)7 Mail (org.apache.mailet.Mail)7 MailAddress (org.apache.mailet.MailAddress)7 SmtpAgent (org.nhindirect.gateway.smtp.SmtpAgent)7 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 MessageProcessResult (org.nhindirect.gateway.smtp.MessageProcessResult)4 NHINDAddressCollection (org.nhindirect.stagent.NHINDAddressCollection)4 Message (org.nhindirect.stagent.mail.Message)3 DefaultMessageEnvelope (org.nhindirect.stagent.DefaultMessageEnvelope)2 NHINDAddress (org.nhindirect.stagent.NHINDAddress)2 MessagingException (javax.mail.MessagingException)1 SmtpAgentException (org.nhindirect.gateway.smtp.SmtpAgentException)1 MockNHINDAgent (org.nhindirect.stagent.MockNHINDAgent)1