// http://jira.qos.ch/browse/LBCLASSIC-221 @Test public void bufferShouldBeResetBetweenMessages() throws Exception { buildSMTPAppender(smtpServer.getSmtp().getPort(), SYNCHRONOUS); smtpAppender.setLayout(buildPatternLayout(lc, DEFAULT_PATTERN)); smtpAppender.start(); logger.addAppender(smtpAppender); String msg0 = "hello zero"; logger.debug(msg0); logger.error("error zero"); String msg1 = "hello one"; logger.debug(msg1); logger.error("error one"); waitUntilEmailIsSent(); waitUntilEmailIsReceived(smtpServer, 2); MimeMessage[] mma = smtpServer.getReceivedMessages(); assertNotNull(mma); assertEquals(2, mma.length); MimeMessage mm0 = mma[0]; MimeMultipart content0 = (MimeMultipart) mm0.getContent(); String body0 = GreenMailUtil.getBody(content0.getBodyPart(0)); assertTrue(body0.contains(msg0)); MimeMessage mm1 = mma[1]; MimeMultipart content1 = (MimeMultipart) mm1.getContent(); String body1 = GreenMailUtil.getBody(content1.getBodyPart(0)); // second body should not contain content from first message assertFalse(body1.contains(msg0)); }
@Test public void testCustomBufferSize() throws Exception { configure( smtpServer.getSmtp().getPort(), ClassicTestConstants.JORAN_INPUT_PREFIX + "smtp/customBufferSize.xml"); logger.debug("invisible1"); logger.debug("invisible2"); String msg = "hello"; logger.error(msg); waitUntilEmailIsSent(); MimeMultipart mp = verify(smtpServer, this.getClass().getName() + " - " + msg); String body = GreenMailUtil.getBody(mp.getBodyPart(0)); assertEquals(msg, body); }
@Test public void testMultipleTo() throws Exception { buildSMTPAppender(smtpServer.getSmtp().getPort(), SYNCHRONOUS); smtpAppender.setLayout(buildPatternLayout(lc, DEFAULT_PATTERN)); smtpAppender.addTo("Test <*****@*****.**>, [email protected]"); smtpAppender.start(); logger.addAppender(smtpAppender); logger.debug("hello"); logger.error("an error", new Exception("an exception")); waitUntilEmailIsReceived(smtpServer, 3); MimeMessage[] mma = smtpServer.getReceivedMessages(); assertNotNull(mma); assertEquals(3, mma.length); }
// See also http://jira.qos.ch/browse/LOGBACK-734 @Test public void callerDataShouldBeCorrectlySetWithAsyncronousSending() throws Exception { buildSMTPAppender(smtpServer.getSmtp().getPort(), ASYNCHRONOUS); smtpAppender.setLayout(buildPatternLayout(lc, DEFAULT_PATTERN)); smtpAppender.setIncludeCallerData(true); smtpAppender.start(); logger.addAppender(smtpAppender); logger.debug("hello"); logger.error("an error", new Exception("an exception")); waitUntilEmailIsSent(); MimeMultipart mp = verify(smtpServer, TEST_SUBJECT); String body = GreenMailUtil.getBody(mp.getBodyPart(0)); assertTrue(body.contains("DEBUG " + this.getClass().getName() + " - hello")); }
@Test public void asyncronousSmoke() throws Exception { buildSMTPAppender(smtpServer.getSmtp().getPort(), ASYNCHRONOUS); smtpAppender.setLayout(buildPatternLayout(lc, DEFAULT_PATTERN)); smtpAppender.start(); logger.addAppender(smtpAppender); logger.debug("hello"); logger.error("an error", new Exception("an exception")); waitUntilEmailIsSent(); MimeMultipart mp = verify(smtpServer, TEST_SUBJECT); String body = GreenMailUtil.getBody(mp.getBodyPart(0)); assertTrue(body.startsWith(HEADER.trim())); assertTrue(body.endsWith(FOOTER.trim())); }
@Test public void testCustomEvaluator() throws Exception { configure( greenMailServer.getSmtp().getPort(), ClassicTestConstants.JORAN_INPUT_PREFIX + "smtp/customEvaluator.xml"); logger.debug("test"); String msg2 = "CustomEvaluator"; logger.debug(msg2); logger.debug("invisible"); waitUntilEmailIsSent(); MimeMultipart mp = verifyAndExtractMimeMultipart( "testCustomEvaluator " + this.getClass().getName() + " - " + msg2); String body = GreenMailUtil.getBody(mp.getBodyPart(0)); assertEquals("testCustomEvaluator", body); }
@Test public void html() throws Exception { buildSMTPAppender(smtpServer.getSmtp().getPort(), SYNCHRONOUS); smtpAppender.setAsynchronousSending(false); smtpAppender.setLayout(buildHTMLLayout(lc)); smtpAppender.start(); logger.addAppender(smtpAppender); logger.debug("hello"); logger.error("an error", new Exception("an exception")); MimeMultipart mp = verify(smtpServer, TEST_SUBJECT); // verify strict adherence to xhtml1-strict.dtd SAXReader reader = new SAXReader(); reader.setValidation(true); reader.setEntityResolver(new XHTMLEntityResolver()); reader.read(mp.getBodyPart(0).getInputStream()); }
@Test public void LBCLASSIC_104() throws Exception { buildSMTPAppender(smtpServer.getSmtp().getPort(), SYNCHRONOUS); smtpAppender.setAsynchronousSending(false); smtpAppender.setLayout(buildPatternLayout(lc, DEFAULT_PATTERN)); smtpAppender.start(); logger.addAppender(smtpAppender); MDC.put("key", "val"); logger.debug("hello"); MDC.clear(); logger.error("an error", new Exception("an exception")); MimeMultipart mp = verify(smtpServer, TEST_SUBJECT); String body = GreenMailUtil.getBody(mp.getBodyPart(0)); assertTrue("missing HEADER in body", body.startsWith(HEADER.trim())); assertTrue("missing MDC in body", body.contains("key=val")); assertTrue("missing FOOTER in body", body.endsWith(FOOTER.trim())); }