Search in sources :

Example 1 with MockNHINDAgent

use of org.nhindirect.stagent.MockNHINDAgent in project nhin-d by DirectProject.

the class SmtpAgentFactory_CreateAgent_Test method testCreateDefaultAgent_XMLConfigurationProvider_AuditorModule.

public void testCreateDefaultAgent_XMLConfigurationProvider_AuditorModule() throws Exception {
    Provider<SmtpAgentConfig> configProvider = new XMLSmtpAgentConfigProvider(TestUtils.getTestConfigFile("ValidConfig.xml"), new MockNHINDAgentProvider(Arrays.asList("mydomain")));
    SmtpAgent agent = SmtpAgentFactory.createAgent(null, configProvider, new MockNHINDAgentProvider(Arrays.asList("mydomain")), Arrays.asList(FileAuditorModule.create("target/AuditFile.txt")));
    assertNotNull(agent);
    assertNotNull(agent.getAgent());
    assertTrue(agent.getAgent() instanceof MockNHINDAgent);
    DefaultSmtpAgent smtpAgent = (DefaultSmtpAgent) agent;
    assertNotNull(smtpAgent.getAuditor());
    assertTrue(smtpAgent.getAuditor() instanceof FileAuditor);
}
Also used : MockNHINDAgent(org.nhindirect.stagent.MockNHINDAgent) XMLSmtpAgentConfigProvider(org.nhindirect.gateway.smtp.provider.XMLSmtpAgentConfigProvider) MockNHINDAgentProvider(org.nhindirect.stagent.provider.MockNHINDAgentProvider) SmtpAgentConfig(org.nhindirect.gateway.smtp.config.SmtpAgentConfig) FileAuditor(org.nhindirect.common.audit.impl.FileAuditor)

Example 2 with MockNHINDAgent

use of org.nhindirect.stagent.MockNHINDAgent in project nhin-d by DirectProject.

the class SmtpAgentFactory_CreateAgent_Test method testCreateDefaultAgent_XMLConfigurationProvider_MockAgent.

public void testCreateDefaultAgent_XMLConfigurationProvider_MockAgent() throws Exception {
    Provider<SmtpAgentConfig> configProvider = new XMLSmtpAgentConfigProvider(TestUtils.getTestConfigFile("ValidConfig.xml"), new MockNHINDAgentProvider(Arrays.asList("mydomain")));
    SmtpAgent agent = SmtpAgentFactory.createAgent(null, configProvider, new MockNHINDAgentProvider(Arrays.asList("mydomain")));
    assertNotNull(agent);
    assertNotNull(agent.getAgent());
    assertTrue(agent.getAgent() instanceof MockNHINDAgent);
}
Also used : MockNHINDAgent(org.nhindirect.stagent.MockNHINDAgent) XMLSmtpAgentConfigProvider(org.nhindirect.gateway.smtp.provider.XMLSmtpAgentConfigProvider) MockNHINDAgentProvider(org.nhindirect.stagent.provider.MockNHINDAgentProvider) SmtpAgentConfig(org.nhindirect.gateway.smtp.config.SmtpAgentConfig)

Example 3 with MockNHINDAgent

use of org.nhindirect.stagent.MockNHINDAgent in project nhin-d by DirectProject.

the class NotificationProducerTest method getMessageFromFile.

private IncomingMessage getMessageFromFile(String fileName, Collection<String> domains) throws Exception {
    String text = TestUtils.readMessageResource(fileName);
    IncomingMessage retVal = new IncomingMessage(text);
    MockNHINDAgent mockAgent = new MockNHINDAgent(domains);
    retVal.setAgent(mockAgent);
    return retVal;
}
Also used : MockNHINDAgent(org.nhindirect.stagent.MockNHINDAgent) IncomingMessage(org.nhindirect.stagent.IncomingMessage)

Example 4 with MockNHINDAgent

use of org.nhindirect.stagent.MockNHINDAgent in project nhin-d by DirectProject.

the class SmtpAgentFactory_buildAgentInjectorTest method testBuildAgentInjector_customConfigModule_assertInjector.

public void testBuildAgentInjector_customConfigModule_assertInjector() throws Exception {
    Injector injector = SmtpAgentFactory.buildAgentInjector(new URL("http://doesntmatter"), new MockSmtpAgentConfigProvider(Arrays.asList("testdomain.com")), null);
    assertNotNull(injector);
    // try to get an instance of the configuration object
    NHINDAgent agent = injector.getInstance(NHINDAgent.class);
    assertNotNull(agent);
    assertTrue(agent instanceof MockNHINDAgent);
}
Also used : MockNHINDAgent(org.nhindirect.stagent.MockNHINDAgent) MockSmtpAgentConfigProvider(org.nhindirect.stagent.provider.MockSmtpAgentConfigProvider) Injector(com.google.inject.Injector) NHINDAgent(org.nhindirect.stagent.NHINDAgent) MockNHINDAgent(org.nhindirect.stagent.MockNHINDAgent) URL(java.net.URL)

Example 5 with MockNHINDAgent

use of org.nhindirect.stagent.MockNHINDAgent in project nhin-d by DirectProject.

the class NHINDSecurityAndTrustMailet_service_Test method testService_RejectRecipients_AssertRejectedList.

@SuppressWarnings("unused")
public void testService_RejectRecipients_AssertRejectedList() 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];
            usedRecipients.get(0).setStatus(TrustEnforcementStatus.Failed);
            usedRecipients.get(1).setStatus(TrustEnforcementStatus.Success);
            usedSender = (NHINDAddress) invocation.getArguments()[2];
            MyMessageEnvelope env = new MyMessageEnvelope(new Message(mimeMsg), usedRecipients, usedSender);
            env.setAgent(new MockNHINDAgent(Arrays.asList("cerner.com")));
            env.categorizeRecipients(TrustEnforcementStatus.Success);
            NHINDAddressCollection rejectedRecips = env.getRejectedRecipients();
            return new MessageProcessResult(env, null);
        }
    });
    final Mail mockMail = mock(MockMail.class, CALLS_REAL_METHODS);
    mockMail.setRecipients(Arrays.asList(new MailAddress("you@cerner.com"), new MailAddress("they@cerner.com")));
    when(mockMail.getSender()).thenReturn(new MailAddress("me@cerner.com"));
    mockMail.setMessage(mimeMsg);
    NHINDSecurityAndTrustMailet mailet = new NHINDSecurityAndTrustMailet();
    mailet.agent = mockAgent;
    mailet.service(mockMail);
    assertEquals(1, mockMail.getRecipients().size());
}
Also used : MailAddress(org.apache.mailet.MailAddress) Message(org.nhindirect.stagent.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) NHINDAddressCollection(org.nhindirect.stagent.NHINDAddressCollection) SmtpAgent(org.nhindirect.gateway.smtp.SmtpAgent) MessageProcessResult(org.nhindirect.gateway.smtp.MessageProcessResult) NHINDAddress(org.nhindirect.stagent.NHINDAddress) MockNHINDAgent(org.nhindirect.stagent.MockNHINDAgent) Mail(org.apache.mailet.Mail) MimeMessage(javax.mail.internet.MimeMessage) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Aggregations

MockNHINDAgent (org.nhindirect.stagent.MockNHINDAgent)5 SmtpAgentConfig (org.nhindirect.gateway.smtp.config.SmtpAgentConfig)2 XMLSmtpAgentConfigProvider (org.nhindirect.gateway.smtp.provider.XMLSmtpAgentConfigProvider)2 MockNHINDAgentProvider (org.nhindirect.stagent.provider.MockNHINDAgentProvider)2 Injector (com.google.inject.Injector)1 URL (java.net.URL)1 MimeMessage (javax.mail.internet.MimeMessage)1 Mail (org.apache.mailet.Mail)1 MailAddress (org.apache.mailet.MailAddress)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 FileAuditor (org.nhindirect.common.audit.impl.FileAuditor)1 MessageProcessResult (org.nhindirect.gateway.smtp.MessageProcessResult)1 SmtpAgent (org.nhindirect.gateway.smtp.SmtpAgent)1 IncomingMessage (org.nhindirect.stagent.IncomingMessage)1 NHINDAddress (org.nhindirect.stagent.NHINDAddress)1 NHINDAddressCollection (org.nhindirect.stagent.NHINDAddressCollection)1 NHINDAgent (org.nhindirect.stagent.NHINDAgent)1 Message (org.nhindirect.stagent.mail.Message)1 MockSmtpAgentConfigProvider (org.nhindirect.stagent.provider.MockSmtpAgentConfigProvider)1