Search in sources :

Example 1 with MatcherConfig

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

the class RecipAndSenderIsNotLocalTest method testMatch_LocalSender_RemoteRcpt_AssertRecipeintReturned.

public void testMatch_LocalSender_RemoteRcpt_AssertRecipeintReturned() throws Exception {
    final Mail mockMail = mock(Mail.class);
    when(mockMail.getSender()).thenReturn(new MailAddress("me@cerner.com"));
    when(mockMail.getRecipients()).thenReturn(Arrays.asList(new MailAddress("you@remoteMail")));
    final MatcherConfig newConfig = mock(MatcherConfig.class);
    when(newConfig.getCondition()).thenReturn("cerner.com");
    RecipAndSenderIsNotLocal matcher = new RecipAndSenderIsNotLocal();
    matcher.init(newConfig);
    Collection<MailAddress> matchAddresses = matcher.match(mockMail);
    assertEquals(1, matchAddresses.size());
    assertEquals("you@remoteMail", matchAddresses.iterator().next().toString());
}
Also used : Mail(org.apache.mailet.Mail) MailAddress(org.apache.mailet.MailAddress) MatcherConfig(org.apache.mailet.MatcherConfig)

Example 2 with MatcherConfig

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

the class RecipAndSenderIsNotLocalTest method testEmptyDomainList.

public void testEmptyDomainList() throws Exception {
    final MatcherConfig newConfig = mock(MatcherConfig.class);
    when(newConfig.getCondition()).thenReturn("");
    RecipAndSenderIsNotLocal matcher = new RecipAndSenderIsNotLocal();
    boolean exceptionOccured = false;
    try {
        matcher.init(newConfig);
    } catch (SmtpAgentException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) MatcherConfig(org.apache.mailet.MatcherConfig)

Example 3 with MatcherConfig

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

the class RecipAndSenderIsNotLocalTest method testMatch_LocalSender_LocalAndRemoteRcpt_AssertRemoteRcptReturned.

public void testMatch_LocalSender_LocalAndRemoteRcpt_AssertRemoteRcptReturned() throws Exception {
    final Mail mockMail = mock(Mail.class);
    when(mockMail.getSender()).thenReturn(new MailAddress("me@cerner.com"));
    when(mockMail.getRecipients()).thenReturn(Arrays.asList(new MailAddress("you@cerner.com"), new MailAddress("someone@remoteMail.com")));
    final MatcherConfig newConfig = mock(MatcherConfig.class);
    when(newConfig.getCondition()).thenReturn("cerner.com");
    RecipAndSenderIsNotLocal matcher = new RecipAndSenderIsNotLocal();
    matcher.init(newConfig);
    Collection<MailAddress> matchAddresses = matcher.match(mockMail);
    assertEquals(1, matchAddresses.size());
    assertEquals("someone@remoteMail.com", matchAddresses.iterator().next().toString());
}
Also used : Mail(org.apache.mailet.Mail) MailAddress(org.apache.mailet.MailAddress) MatcherConfig(org.apache.mailet.MatcherConfig)

Example 4 with MatcherConfig

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

the class RecipAndSenderIsNotLocalTest method testMatch_LocalSender_LocalRcpt_AssertNoneReturned.

public void testMatch_LocalSender_LocalRcpt_AssertNoneReturned() throws Exception {
    final Mail mockMail = mock(Mail.class);
    when(mockMail.getSender()).thenReturn(new MailAddress("me@cerner.com"));
    when(mockMail.getRecipients()).thenReturn(Arrays.asList(new MailAddress("you@cerner.com")));
    final MatcherConfig newConfig = mock(MatcherConfig.class);
    when(newConfig.getCondition()).thenReturn("cerner.com");
    RecipAndSenderIsNotLocal matcher = new RecipAndSenderIsNotLocal();
    matcher.init(newConfig);
    Collection<MailAddress> matchAddresses = matcher.match(mockMail);
    assertEquals(0, matchAddresses.size());
}
Also used : Mail(org.apache.mailet.Mail) MailAddress(org.apache.mailet.MailAddress) MatcherConfig(org.apache.mailet.MatcherConfig)

Example 5 with MatcherConfig

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

the class RecipAndSenderIsNotLocalTest method testNullDomainList.

public void testNullDomainList() throws Exception {
    final MatcherConfig newConfig = mock(MatcherConfig.class);
    when(newConfig.getCondition()).thenReturn(null);
    RecipAndSenderIsNotLocal matcher = new RecipAndSenderIsNotLocal();
    boolean exceptionOccured = false;
    try {
        matcher.init(newConfig);
    } catch (SmtpAgentException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) MatcherConfig(org.apache.mailet.MatcherConfig)

Aggregations

MatcherConfig (org.apache.mailet.MatcherConfig)6 Mail (org.apache.mailet.Mail)4 MailAddress (org.apache.mailet.MailAddress)4 SmtpAgentException (org.nhindirect.gateway.smtp.SmtpAgentException)2