use of org.motechproject.security.exception.VelocityTemplateParsingException in project motech by motech.
the class EmailSenderImplTest method shouldNotSendPasswordResetReminderIfParsingThrowsException.
@Test
public void shouldNotSendPasswordResetReminderIfParsingThrowsException() throws Exception {
when(templateParser.mergeTemplateIntoString(matches(PASSWORD_CHANGE_REMINDER_TEMPLATE), eq(params))).thenThrow(new VelocityTemplateParsingException("Couldn't send password reminder email", null));
emailSender.sendPasswordResetReminder(params);
verify(templateParser).mergeTemplateIntoString(matches(PASSWORD_CHANGE_REMINDER_TEMPLATE), eq(params));
verify(eventRelay, never()).sendEventMessage(any(MotechEvent.class));
}
use of org.motechproject.security.exception.VelocityTemplateParsingException in project motech by motech.
the class VelocityTemplateParser method mergeTemplateIntoString.
public String mergeTemplateIntoString(String templateFilename, Map<String, Object> params) throws VelocityTemplateParsingException {
try (InputStream is = settingsFacade.getRawConfig(templateFilename)) {
StringReader reader = new StringReader(IOUtils.toString(is));
SimpleNode node = rs.parse(reader, templateFilename);
Template template = new Template();
template.setRuntimeServices(rs);
template.setData(node);
template.initDocument();
StringWriter writer = new StringWriter();
template.merge(new VelocityContext(params), writer);
return writer.toString();
} catch (ParseException | IOException e) {
throw new VelocityTemplateParsingException("Couldn't merge template into string", e);
}
}
Aggregations