@Test void importSieveScriptFileToRepositoryShouldNotImportFileWithWrongPathToRepistory() throws Exception { String userName = "user@domain"; String script = "user_script"; URL sieveResource = ClassLoader.getSystemResource("sieve/my_sieve"); Username username = Username.of(userName); ScriptName scriptName = new ScriptName(script); String sieveContent = IOUtils.toString(sieveResource, StandardCharsets.UTF_8); ScriptContent scriptContent = new ScriptContent(sieveContent); sieveRepositoryManagement.addActiveSieveScriptFromFile(userName, script, "wrong_path/" + sieveResource.getFile()); verify(sieveRepository, times(0)).putScript(username, scriptName, scriptContent); verify(sieveRepository, times(0)).setActive(username, scriptName); }
@Override public void addActiveSieveScriptFromFile(String userName, String scriptName, String scriptPath) throws SieveRepositoryException { try (InputStream scriptFileAsStream = new FileInputStream(scriptPath)) { addActiveSieveScript(userName, scriptName, IOUtils.toString(scriptFileAsStream, StandardCharsets.UTF_8)); } catch (IOException e) { LOGGER.error("Error while reading sieve script from file {}", scriptPath, e); } }
SieveRepositoryManagement extends StandardMBean implements SieveRepositoryManagementMBean { @Override public void addActiveSieveScriptFromFile(String userName, String scriptName, String scriptPath) throws SieveRepositoryException { try (InputStream scriptFileAsStream = new FileInputStream(scriptPath)) { addActiveSieveScript(userName, scriptName, IOUtils.toString(scriptFileAsStream, StandardCharsets.UTF_8)); } catch (IOException e) { LOGGER.error("Error while reading sieve script from file {}", scriptPath, e); } } }
SieveRepositoryManagement extends StandardMBean implements SieveRepositoryManagementMBean { @Override public void addActiveSieveScriptFromFile(String userName, String scriptName, String scriptPath) throws SieveRepositoryException { try (InputStream scriptFileAsStream = new FileInputStream(scriptPath)) { addActiveSieveScript(userName, scriptName, IOUtils.toString(scriptFileAsStream, StandardCharsets.UTF_8)); } catch (IOException e) { LOGGER.error("Error while reading sieve script from file {}", scriptPath, e); } } SieveRepositoryManagement(); }
SieveRepositoryManagement extends StandardMBean implements SieveRepositoryManagementMBean { @Override public void addActiveSieveScriptFromFile(String userName, String scriptName, String scriptPath) throws SieveRepositoryException { try (InputStream scriptFileAsStream = new FileInputStream(scriptPath)) { addActiveSieveScript(userName, scriptName, IOUtils.toString(scriptFileAsStream, StandardCharsets.UTF_8)); } catch (IOException e) { LOGGER.error("Error while reading sieve script from file {}", scriptPath, e); } } SieveRepositoryManagement(); @Inject void setSieveRepository(SieveRepository sieveRepository); @Override long getQuota(); @Override void setQuota(long quota); @Override void removeQuota(); @Override long getQuota(String user); @Override void setQuota(String user, long quota); @Override void removeQuota(String user); @Override void addActiveSieveScript(String userName, String scriptName, String script); @Override void addActiveSieveScriptFromFile(String userName, String scriptName, String scriptPath); }
SieveRepositoryManagement extends StandardMBean implements SieveRepositoryManagementMBean { @Override public void addActiveSieveScriptFromFile(String userName, String scriptName, String scriptPath) throws SieveRepositoryException { try (InputStream scriptFileAsStream = new FileInputStream(scriptPath)) { addActiveSieveScript(userName, scriptName, IOUtils.toString(scriptFileAsStream, StandardCharsets.UTF_8)); } catch (IOException e) { LOGGER.error("Error while reading sieve script from file {}", scriptPath, e); } } SieveRepositoryManagement(); @Inject void setSieveRepository(SieveRepository sieveRepository); @Override long getQuota(); @Override void setQuota(long quota); @Override void removeQuota(); @Override long getQuota(String user); @Override void setQuota(String user, long quota); @Override void removeQuota(String user); @Override void addActiveSieveScript(String userName, String scriptName, String script); @Override void addActiveSieveScriptFromFile(String userName, String scriptName, String scriptPath);  }