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);
}
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);
}
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;
}
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);
}
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());
}
Aggregations