@Test public void testGetTemplateConfigurations_InputStreamException() throws Exception { IOException ioException = new IOException(); when(templateConfigurations.getInputStream()).thenThrow(ioException); when(templateConfigurations.getDescription()).thenReturn(ABSOLUTE_PATH_TO_RESOURCE); exception.expect(AcmEmailConfigurationException.class); exception.expectMessage(is( String.format("Error while reading email templates configuration from %s file.", templateConfigurations.getDescription()))); exception.expectCause(is(ioException)); service.getTemplateConfigurations(); }
@Override public List<EmailTemplateConfiguration> getTemplateConfigurations() throws AcmEmailConfigurationException { Lock readLock = lock.readLock(); readLock.lock(); try (InputStream is = templateConfigurations.getInputStream()) { List<EmailTemplateConfiguration> readConfigurationList = getObjectConverter().getJsonUnmarshaller() .unmarshallCollection(IOUtils.toString(is, StandardCharsets.UTF_8), List.class, EmailTemplateConfiguration.class); if (readConfigurationList == null) { log.warn("Error while deserializing email templates configuration from {} file.", templateConfigurations.getDescription(), null); throw new AcmEmailConfigurationJsonException( String.format("Error while deserializing email templates configuration from %s file.", templateConfigurations.getDescription()), null); } return readConfigurationList; } catch (IOException e) { log.warn("Error while reading email templates configuration from {} file.", templateConfigurations.getDescription(), e); throw new AcmEmailConfigurationIOException(String.format("Error while reading email templates configuration from %s file.", templateConfigurations.getDescription()), e); } finally { readLock.unlock(); } }
AcmFilesystemMailTemplateConfigurationService implements AcmMailTemplateConfigurationService { @Override public List<EmailTemplateConfiguration> getTemplateConfigurations() throws AcmEmailConfigurationException { Lock readLock = lock.readLock(); readLock.lock(); try (InputStream is = templateConfigurations.getInputStream()) { List<EmailTemplateConfiguration> readConfigurationList = getObjectConverter().getJsonUnmarshaller() .unmarshallCollection(IOUtils.toString(is, StandardCharsets.UTF_8), List.class, EmailTemplateConfiguration.class); if (readConfigurationList == null) { log.warn("Error while deserializing email templates configuration from {} file.", templateConfigurations.getDescription(), null); throw new AcmEmailConfigurationJsonException( String.format("Error while deserializing email templates configuration from %s file.", templateConfigurations.getDescription()), null); } return readConfigurationList; } catch (IOException e) { log.warn("Error while reading email templates configuration from {} file.", templateConfigurations.getDescription(), e); throw new AcmEmailConfigurationIOException(String.format("Error while reading email templates configuration from %s file.", templateConfigurations.getDescription()), e); } finally { readLock.unlock(); } } }
AcmFilesystemMailTemplateConfigurationService implements AcmMailTemplateConfigurationService { @Override public List<EmailTemplateConfiguration> getTemplateConfigurations() throws AcmEmailConfigurationException { Lock readLock = lock.readLock(); readLock.lock(); try (InputStream is = templateConfigurations.getInputStream()) { List<EmailTemplateConfiguration> readConfigurationList = getObjectConverter().getJsonUnmarshaller() .unmarshallCollection(IOUtils.toString(is, StandardCharsets.UTF_8), List.class, EmailTemplateConfiguration.class); if (readConfigurationList == null) { log.warn("Error while deserializing email templates configuration from {} file.", templateConfigurations.getDescription(), null); throw new AcmEmailConfigurationJsonException( String.format("Error while deserializing email templates configuration from %s file.", templateConfigurations.getDescription()), null); } return readConfigurationList; } catch (IOException e) { log.warn("Error while reading email templates configuration from {} file.", templateConfigurations.getDescription(), e); throw new AcmEmailConfigurationIOException(String.format("Error while reading email templates configuration from %s file.", templateConfigurations.getDescription()), e); } finally { readLock.unlock(); } }  }
AcmFilesystemMailTemplateConfigurationService implements AcmMailTemplateConfigurationService { @Override public List<EmailTemplateConfiguration> getTemplateConfigurations() throws AcmEmailConfigurationException { Lock readLock = lock.readLock(); readLock.lock(); try (InputStream is = templateConfigurations.getInputStream()) { List<EmailTemplateConfiguration> readConfigurationList = getObjectConverter().getJsonUnmarshaller() .unmarshallCollection(IOUtils.toString(is, StandardCharsets.UTF_8), List.class, EmailTemplateConfiguration.class); if (readConfigurationList == null) { log.warn("Error while deserializing email templates configuration from {} file.", templateConfigurations.getDescription(), null); throw new AcmEmailConfigurationJsonException( String.format("Error while deserializing email templates configuration from %s file.", templateConfigurations.getDescription()), null); } return readConfigurationList; } catch (IOException e) { log.warn("Error while reading email templates configuration from {} file.", templateConfigurations.getDescription(), e); throw new AcmEmailConfigurationIOException(String.format("Error while reading email templates configuration from %s file.", templateConfigurations.getDescription()), e); } finally { readLock.unlock(); } }  @Override List<EmailTemplateConfiguration> getTemplateConfigurations(); void setTemplateConfigurations(Resource templateConfigurations); @Override EmailTemplateValidationResponse validateEmailTemplate(EmailTemplateConfiguration templateData); @Override void updateEmailTemplate(EmailTemplateConfiguration templateData, MultipartFile template); @Override List<EmailTemplateConfiguration> getMatchingTemplates(String email, String objectType, EmailSource source, List<String> actions); @Override String getTemplate(String templateName); @Override void deleteTemplate(String templateName); @Override AcmEmailServiceExceptionMapper<ME> getExceptionMapper(AcmEmailServiceException e); void setTemplateFolderPath(String templateFolderPath); ObjectConverter getObjectConverter(); void setObjectConverter(ObjectConverter objectConverter); }
AcmFilesystemMailTemplateConfigurationService implements AcmMailTemplateConfigurationService { @Override public List<EmailTemplateConfiguration> getTemplateConfigurations() throws AcmEmailConfigurationException { Lock readLock = lock.readLock(); readLock.lock(); try (InputStream is = templateConfigurations.getInputStream()) { List<EmailTemplateConfiguration> readConfigurationList = getObjectConverter().getJsonUnmarshaller() .unmarshallCollection(IOUtils.toString(is, StandardCharsets.UTF_8), List.class, EmailTemplateConfiguration.class); if (readConfigurationList == null) { log.warn("Error while deserializing email templates configuration from {} file.", templateConfigurations.getDescription(), null); throw new AcmEmailConfigurationJsonException( String.format("Error while deserializing email templates configuration from %s file.", templateConfigurations.getDescription()), null); } return readConfigurationList; } catch (IOException e) { log.warn("Error while reading email templates configuration from {} file.", templateConfigurations.getDescription(), e); throw new AcmEmailConfigurationIOException(String.format("Error while reading email templates configuration from %s file.", templateConfigurations.getDescription()), e); } finally { readLock.unlock(); } }  @Override List<EmailTemplateConfiguration> getTemplateConfigurations(); void setTemplateConfigurations(Resource templateConfigurations); @Override EmailTemplateValidationResponse validateEmailTemplate(EmailTemplateConfiguration templateData); @Override void updateEmailTemplate(EmailTemplateConfiguration templateData, MultipartFile template); @Override List<EmailTemplateConfiguration> getMatchingTemplates(String email, String objectType, EmailSource source, List<String> actions); @Override String getTemplate(String templateName); @Override void deleteTemplate(String templateName); @Override AcmEmailServiceExceptionMapper<ME> getExceptionMapper(AcmEmailServiceException e); void setTemplateFolderPath(String templateFolderPath); ObjectConverter getObjectConverter(); void setObjectConverter(ObjectConverter objectConverter);  }