Search in sources :

Example 1 with Postoffice

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());
}
Also used : GreenMail(com.icegreen.greenmail.util.GreenMail) Mail(ninja.postoffice.Mail) Postoffice(ninja.postoffice.Postoffice) Test(org.junit.Test)

Example 2 with Postoffice

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"));
}
Also used : Mail(ninja.postoffice.Mail) Postoffice(ninja.postoffice.Postoffice) MailImpl(ninja.postoffice.common.MailImpl) Test(org.junit.Test)

Example 3 with Postoffice

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));
    }
}
Also used : MigrationEngine(ninja.migrations.MigrationEngine) XmlMapperProvider(ninja.utils.XmlMapperProvider) Postoffice(ninja.postoffice.Postoffice) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ObjectMapperProvider(ninja.utils.ObjectMapperProvider) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) Cache(ninja.cache.Cache) MigrationInitializer(ninja.migrations.MigrationInitializer) JpaModule(ninja.jpa.JpaModule)

Aggregations

Postoffice (ninja.postoffice.Postoffice)3 Mail (ninja.postoffice.Mail)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1 GreenMail (com.icegreen.greenmail.util.GreenMail)1 Cache (ninja.cache.Cache)1 JpaModule (ninja.jpa.JpaModule)1 MigrationEngine (ninja.migrations.MigrationEngine)1 MigrationInitializer (ninja.migrations.MigrationInitializer)1 MailImpl (ninja.postoffice.common.MailImpl)1 ObjectMapperProvider (ninja.utils.ObjectMapperProvider)1 XmlMapperProvider (ninja.utils.XmlMapperProvider)1