@Override public SmtpServer getSmtp() { return getGreenMail().getSmtp(); }
final GreenMail mailServer = new GreenMail(); mailServer.start(); final Properties mailSessionProperties = new Properties(); mailSessionProperties.put("mail.smtp.port", String.valueOf(mailServer.getSmtp().getPort())); final javax.mail.Session mailSession = javax.mail.Session.getInstance(mailSessionProperties); testObject.setMailSession(mailSession);
@Test void wrongPassword() { final InstallData data = mock(InstallData.class); when(data.getVariable(eq(Variables.SMTP_AUTH.getKey()))).thenReturn("true"); when(data.getVariable(eq(Variables.SMTP_IS_SSL.getKey()))).thenReturn("false"); when(data.getVariable(eq(Variables.SMTP_IS_TLS.getKey()))).thenReturn("false"); when(data.getVariable(eq(Variables.SMTP_USERNAME.getKey()))).thenReturn(USERNAME); when(data.getVariable(eq(Variables.SMTP_PASSWORD.getKey()))).thenReturn(""); when(data.getVariable(eq(Variables.SMTP_PORT.getKey()))) .thenReturn(String.valueOf(EMAIL.getSmtp().getPort())); when(data.getVariable(eq(Variables.SMTP_HOSTNAME.getKey()))) .thenReturn(String.valueOf(EMAIL.getSmtp().getBindTo())); final AdvancedEmailServerValidator validator = new AdvancedEmailServerValidator(); final DataValidator.Status result = validator.validateData(data); assertThat(result).isEqualTo(DataValidator.Status.WARNING); }
@Test void mailFailed() { final InstallData data = mock(InstallData.class); when(data.getVariable(eq(Variables.SMTP_PORT.getKey()))) .thenReturn(String.valueOf(EMAIL.getSmtp().getPort())); when(data.getVariable(eq(Variables.SMTP_HOSTNAME.getKey()))) .thenReturn(String.valueOf(EMAIL.getSmtp().getBindTo())); when(data.getVariable(eq(Variables.SMTP_USERNAME.getKey()))) .thenReturn("sender@server.cz"); when(data.getVariable(eq(Variables.SMTP_PASSWORD.getKey()))) .thenReturn(UUID.randomUUID().toString()); final DataValidator validator = new EmailSettingsValidator(); final DataValidator.Status result = validator.validateData(data); assertThat(result).isEqualTo(DataValidator.Status.WARNING); assertThat(EMAIL.getReceivedMessages()).hasSize(0); } }
@Test void wrongPassword() { final InstallData data = mock(InstallData.class); when(data.getVariable(eq(Variables.EMAIL_CONFIGURATION_TYPE.getKey()))).thenReturn("seznam.cz"); when(data.getVariable(eq(Variables.SMTP_AUTH.getKey()))).thenReturn("true"); when(data.getVariable(eq(Variables.SMTP_IS_SSL.getKey()))).thenReturn("false"); when(data.getVariable(eq(Variables.SMTP_IS_TLS.getKey()))).thenReturn("false"); when(data.getVariable(eq(Variables.SMTP_USERNAME.getKey()))).thenReturn(USERNAME); when(data.getVariable(eq(Variables.SMTP_PASSWORD.getKey()))).thenReturn(""); when(data.getVariable(eq(Variables.SMTP_PORT.getKey()))) .thenReturn(String.valueOf(EMAIL.getSmtp().getPort())); when(data.getVariable(eq(Variables.SMTP_HOSTNAME.getKey()))) .thenReturn(String.valueOf(EMAIL.getSmtp().getBindTo())); final DataValidator validator = new SimpleEmailServerValidator(); final DataValidator.Status result = validator.validateData(data); assertThat(result).isEqualTo(DataValidator.Status.WARNING); }
/** * Start Email Test Server. */ @Given("an email test server") public void startEmailTestServer() { try { if (greenMail == null) { greenMail = new GreenMail(ServerSetupTest.SMTP_POP3); Thread.UncaughtExceptionHandler silentHandler = new SilentExceptionHandler(); greenMail.getSmtp().setUncaughtExceptionHandler(silentHandler); greenMail.getPop3().setUncaughtExceptionHandler(silentHandler); //uses test ports by default greenMail.start(); } } catch (RuntimeException e) { LOG.fine("Email server is already started"); // hope email server is running } }
@Test void mailSent() { final InstallData data = mock(InstallData.class); when(data.getVariable(eq(Variables.ZONKY_USERNAME.getKey()))) .thenReturn("someone@somewhere.cz"); when(data.getVariable(eq(Variables.SMTP_PORT.getKey()))) .thenReturn(String.valueOf(EMAIL.getSmtp().getPort())); when(data.getVariable(eq(Variables.SMTP_HOSTNAME.getKey()))) .thenReturn(String.valueOf(EMAIL.getSmtp().getBindTo())); when(data.getVariable(eq(Variables.SMTP_TO.getKey()))) .thenReturn("recipient@server.cz"); when(data.getVariable(eq(Variables.SMTP_USERNAME.getKey()))) .thenReturn("sender@server.cz"); when(data.getVariable(eq(Variables.SMTP_PASSWORD.getKey()))) .thenReturn(UUID.randomUUID().toString()); final DataValidator validator = new EmailSettingsValidator(); final DataValidator.Status result = validator.validateData(data); assertThat(result).isEqualTo(DataValidator.Status.OK); assertThat(EMAIL.getReceivedMessages()).hasSize(1); }
@Test void connected() { final InstallData data = mock(InstallData.class); when(data.getVariable(eq(Variables.ZONKY_USERNAME.getKey()))) .thenReturn("someone@somewhere.cz"); when(data.getVariable(eq(Variables.SMTP_AUTH.getKey()))).thenReturn("true"); when(data.getVariable(eq(Variables.SMTP_IS_SSL.getKey()))).thenReturn("false"); when(data.getVariable(eq(Variables.SMTP_IS_TLS.getKey()))).thenReturn("false"); when(data.getVariable(eq(Variables.SMTP_USERNAME.getKey()))).thenReturn(USERNAME); when(data.getVariable(eq(Variables.SMTP_PASSWORD.getKey()))).thenReturn(PASSWORD); when(data.getVariable(eq(Variables.SMTP_PORT.getKey()))) .thenReturn(String.valueOf(EMAIL.getSmtp().getPort())); when(data.getVariable(eq(Variables.SMTP_HOSTNAME.getKey()))) .thenReturn(String.valueOf(EMAIL.getSmtp().getBindTo())); when(data.getVariable(eq(Variables.SMTP_TO.getKey()))) .thenReturn("recipient@server.cz"); final AdvancedEmailServerValidator validator = new AdvancedEmailServerValidator(); final DataValidator.Status result = validator.validateData(data); assertThat(result).isEqualTo(DataValidator.Status.OK); }
@Test void connected() { final InstallData data = mock(InstallData.class); when(data.getVariable(eq(Variables.EMAIL_CONFIGURATION_TYPE.getKey()))).thenReturn("gmail.com"); when(data.getVariable(eq(Variables.ZONKY_USERNAME.getKey()))) .thenReturn("someone@somewhere.cz"); when(data.getVariable(eq(Variables.SMTP_AUTH.getKey()))).thenReturn("true"); when(data.getVariable(eq(Variables.SMTP_IS_SSL.getKey()))).thenReturn("false"); when(data.getVariable(eq(Variables.SMTP_IS_TLS.getKey()))).thenReturn("false"); when(data.getVariable(eq(Variables.SMTP_USERNAME.getKey()))).thenReturn(USERNAME); when(data.getVariable(eq(Variables.SMTP_PASSWORD.getKey()))).thenReturn(PASSWORD); when(data.getVariable(eq(Variables.SMTP_PORT.getKey()))) .thenReturn(String.valueOf(EMAIL.getSmtp().getPort())); when(data.getVariable(eq(Variables.SMTP_HOSTNAME.getKey()))) .thenReturn(String.valueOf(EMAIL.getSmtp().getBindTo())); when(data.getVariable(eq(Variables.SMTP_TO.getKey()))) .thenReturn("recipient@server.cz"); final DataValidator validator = new SimpleEmailServerValidator(); final DataValidator.Status result = validator.validateData(data); assertThat(result).isEqualTo(DataValidator.Status.OK); }
@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 testCustomBufferSize() throws Exception { configure(greenMailServer.getSmtp().getPort(), ClassicTestConstants.JORAN_INPUT_PREFIX + "smtp/customBufferSize.xml"); logger.debug("invisible1"); logger.debug("invisible2"); String msg = "hello"; logger.error(msg); waitUntilEmailIsSent(); MimeMultipart mp = verifyAndExtractMimeMultipart("testCustomBufferSize " + this.getClass().getName() + " - " + msg); String body = GreenMailUtil.getBody(mp.getBodyPart(0)); assertEquals(msg, body); }
private Context createNormalContext(String actionXml) throws Exception { EmailActionExecutor ae = new EmailActionExecutor(); Services.get().get(ConfigurationService.class).getConf().setInt(EMAIL_SMTP_PORT, server.getSmtp().getPort()); // Use default host 'localhost'. Hence, do not set the smtp host. // Services.get().get(ConfigurationService.class).getConf().set("oozie.email.smtp.host", "localhost"); // Use default from address, 'oozie@localhost'. // Hence, do not set the from address conf. // Services.get().get(ConfigurationService.class).getConf().set("oozie.email.from.address", "oozie@localhost"); // Disable auth tests by default. Services.get().get(ConfigurationService.class).getConf().setBoolean(EMAIL_SMTP_AUTH, false); Services.get().get(ConfigurationService.class).getConf().set(EMAIL_SMTP_USER, ""); Services.get().get(ConfigurationService.class).getConf().set(EMAIL_SMTP_PASS, ""); XConfiguration protoConf = new XConfiguration(); protoConf.set(WorkflowAppService.HADOOP_USER, getTestUser()); WorkflowJobBean wf = createBaseWorkflow(protoConf, "email-action"); WorkflowActionBean action = (WorkflowActionBean) wf.getActions().get(0); action.setType(ae.getType()); action.setConf(actionXml); return new Context(wf, action); }