use of ninja.postoffice.Postoffice in project ninja by ninjaframework.
the class CommonsMailHelperImplGreenmailIntegrationTest method testCommonsMailer.
@Test
public void testCommonsMailer() throws Exception {
Mail mail = MailImplTestHelper.getMailImplWithDemoContent();
// setup the postoffice:
CommonsmailHelper commonsmailHelper = new CommonsmailHelperImpl();
Postoffice postoffice = new PostofficeCommonsmailImpl(commonsmailHelper, "localhost", SMTP_TEST_PORT, false, null, null, false);
postoffice.send(mail);
assertEquals("from1@domain", ((InternetAddress) greenMail.getReceivedMessages()[0].getFrom()[0]).getAddress());
assertEquals("subject", greenMail.getReceivedMessages()[0].getSubject());
}
use of ninja.postoffice.Postoffice in project ninja by ninjaframework.
the class PostofficeMockImplTest method testSending.
@Test
public void testSending() throws Exception {
// ////////////////////////////////////////////////////////////////////
// Setup the mockpostoffice
// ////////////////////////////////////////////////////////////////////
Postoffice postoffice = new PostofficeMockImpl();
// /////////////////////////////////////////////////////////////////////
// Sending of first mail.
// /////////////////////////////////////////////////////////////////////
Mail firstMail = new MailImpl();
firstMail.setSubject("first mail");
firstMail.addTo("to@localhost");
firstMail.setFrom("from@localhost");
firstMail.setBodyText("simple body text");
// make sure that mocked mailer did not send email previously
assertEquals(null, ((PostofficeMockImpl) postoffice).getLastSentMail());
postoffice.send(firstMail);
// and test that mail has been sent.
assertEquals("first mail", ((PostofficeMockImpl) postoffice).getLastSentMail().getSubject());
assertTrue(((PostofficeMockImpl) postoffice).getLastSentMail().getTos().contains("to@localhost"));
assertTrue(((PostofficeMockImpl) postoffice).getLastSentMail().getFrom().equals("from@localhost"));
assertTrue(((PostofficeMockImpl) postoffice).getLastSentMail().getBodyText().equals("simple body text"));
// /////////////////////////////////////////////////////////////////////
// Sending of another mail. Check that mock mailer handles repeated
// sending correctly.
// /////////////////////////////////////////////////////////////////////
Mail secondMail = new MailImpl();
secondMail.setSubject("second mail");
secondMail.addTo("to@localhost");
secondMail.setFrom("from@localhost");
secondMail.setBodyText("simple body text");
// send simple mail via mocked postoffice
postoffice.send(secondMail);
// and test that mail has been sent.
assertEquals("second mail", ((PostofficeMockImpl) postoffice).getLastSentMail().getSubject());
assertTrue(((PostofficeMockImpl) postoffice).getLastSentMail().getTos().contains("to@localhost"));
assertTrue(((PostofficeMockImpl) postoffice).getLastSentMail().getFrom().equals("from@localhost"));
assertTrue(((PostofficeMockImpl) postoffice).getLastSentMail().getBodyText().equals("simple body text"));
}
use of ninja.postoffice.Postoffice in project ninja by ninjaframework.
the class NinjaClassicModule method configure.
@Override
public void configure() {
// NOTE: these are grouped to line up with third-party dependencies
// (e.g. jackson supports templates & body parsers)
// Text & post require no 3rd party libs
bind(TemplateEngineText.class);
bind(BodyParserEnginePost.class);
// Freemarker
if (freemarker) {
bind(TemplateEngineFreemarker.class);
}
// Jackson json support
if (json) {
OptionalBinder.newOptionalBinder(binder(), ObjectMapper.class).setDefault().toProvider(ObjectMapperProvider.class).in(Singleton.class);
bind(TemplateEngineJson.class);
bind(TemplateEngineJsonP.class);
bind(BodyParserEngineJson.class);
}
// Jackson xml support
if (xml) {
OptionalBinder.newOptionalBinder(binder(), XmlMapper.class).setDefault().toProvider(XmlMapperProvider.class).in(Singleton.class);
bind(TemplateEngineXml.class);
bind(BodyParserEngineXml.class);
}
// Postoffice
if (postoffice) {
bind(Postoffice.class).toProvider(PostofficeProvider.class);
}
// Cache
if (cache) {
bind(Cache.class).toProvider(CacheProvider.class);
}
// Migrations
if (migrations) {
bind(MigrationEngine.class).toProvider(MigrationEngineProvider.class);
bind(MigrationInitializer.class).asEagerSingleton();
}
// JPA
if (jpa) {
install(new JpaModule(ninjaProperties));
}
}
Aggregations