@Test public void assertHandleExceptionWithSession() throws ReflectiveOperationException { EmailJobErrorHandler emailJobErrorHandler = getEmailJobErrorHandler(); emailJobErrorHandler.handleException("test job name", new RuntimeException("test exception")); Field field = emailJobErrorHandler.getClass().getDeclaredField("session"); field.setAccessible(true); Session session = (Session) field.get(emailJobErrorHandler); assertNotNull(session); assertThat(session.getProperties().get("mail.smtp.host"), equalTo("yaml.email.com")); assertThat(session.getProperties().get("mail.debug"), equalTo("true")); assertThat(session.getProperties().get("mail.smtp.port"), equalTo(123)); assertThat(session.getProperties().get("mail.transport.protocol"), equalTo("yaml.smtp")); assertThat(session.getProperties().get("mail.smtp.auth"), equalTo("true")); }
@Override public void handleException(final String jobName, final Throwable cause) { String errorContext = createErrorContext(jobName, cause); try { sendMessage(createMessage(errorContext)); } catch (final MessagingException ex) { log.error("Elastic job: email job handler error", ex); } }
EmailJobErrorHandler implements JobErrorHandler { @Override public void handleException(final String jobName, final Throwable cause) { String errorContext = createErrorContext(jobName, cause); try { sendMessage(createMessage(errorContext)); } catch (final MessagingException ex) { log.error("Elastic job: email job handler error", ex); } } }
EmailJobErrorHandler implements JobErrorHandler { @Override public void handleException(final String jobName, final Throwable cause) { String errorContext = createErrorContext(jobName, cause); try { sendMessage(createMessage(errorContext)); } catch (final MessagingException ex) { log.error("Elastic job: email job handler error", ex); } } EmailJobErrorHandler(); }
EmailJobErrorHandler implements JobErrorHandler { @Override public void handleException(final String jobName, final Throwable cause) { String errorContext = createErrorContext(jobName, cause); try { sendMessage(createMessage(errorContext)); } catch (final MessagingException ex) { log.error("Elastic job: email job handler error", ex); } } EmailJobErrorHandler(); @Override void handleException(final String jobName, final Throwable cause); @Override String getType(); }
EmailJobErrorHandler implements JobErrorHandler { @Override public void handleException(final String jobName, final Throwable cause) { String errorContext = createErrorContext(jobName, cause); try { sendMessage(createMessage(errorContext)); } catch (final MessagingException ex) { log.error("Elastic job: email job handler error", ex); } } EmailJobErrorHandler(); @Override void handleException(final String jobName, final Throwable cause); @Override String getType(); static final String CONFIG_PREFIX; }