@Test(expected = StoreConfigException.class) public void testSaveConfigurationWithIllegalVersion() { final ScopePathBuilderFactory factory = getConfigService().getScopePathBuilderFactory(TestConfiguration.class); final ComplexConfigDTO configuration = new ComplexConfigDTO(); configuration.setPolymorph(false); configuration.setDefiningScopePath(factory.annotatedPath().create()); configuration.setVersion(-1); configuration.setNulled(false); persister.saveConfiguration(configuration); }
@Override public void saveConfiguration(final ComplexConfigDTO configDTO) { Assert.paramNotNull(configDTO, "configuration"); if (configDTO.getVersion() < 1) { throw new StoreConfigException( "Illegal config version. Must be 1 or higher. Occures at scope Path '" + configDTO.getDefiningScopePath() + "'!"); } final File configFile = new File(rootDirectory + File.separator + gen.getPathFromScopePath(configDTO.getDefiningScopePath()) + File.separator + gen.createName(configDTO.getDefiningScopePath()) + fileExtension); if (configFile.exists()) { throw new StaleConfigException( configDTO.getDefiningScopePath(), "Can't save new configuration. There exists already a file for the scope path '" + configDTO.getDefiningScopePath() + "'!"); } try { configFile.getParentFile().mkdirs(); configFile.createNewFile(); } catch (final IOException e) { throw new StoreConfigException( "Error while creating new file. Occures at scope path '" + configDTO.getDefiningScopePath() + "'!", e); } FileOutputStream out = null; try { out = FileUtils.openOutputStream(configFile); marshaller.marshal(out, configDTO); } catch (final FileNotFoundException e) { throw new StoreConfigException( "Error while saving configuration. Occures at scope path '" + configDTO.getDefiningScopePath() + "'!", e); } catch (final IOException e) { throw new StoreConfigException("Error while saving configuration." + configDTO.getDefiningScopePath() + "'!", e); } finally { if (out != null) { try { out.close(); } catch (final IOException e) { LOG.warn( "Error while closing outputStream for configuration with scopepath '" + configDTO.getDefiningScopePath() + "'!", e); } } } }
FileConfigPersister implements ConfigPersister { @Override public void saveConfiguration(final ComplexConfigDTO configDTO) { Assert.paramNotNull(configDTO, "configuration"); if (configDTO.getVersion() < 1) { throw new StoreConfigException( "Illegal config version. Must be 1 or higher. Occures at scope Path '" + configDTO.getDefiningScopePath() + "'!"); } final File configFile = new File(rootDirectory + File.separator + gen.getPathFromScopePath(configDTO.getDefiningScopePath()) + File.separator + gen.createName(configDTO.getDefiningScopePath()) + fileExtension); if (configFile.exists()) { throw new StaleConfigException( configDTO.getDefiningScopePath(), "Can't save new configuration. There exists already a file for the scope path '" + configDTO.getDefiningScopePath() + "'!"); } try { configFile.getParentFile().mkdirs(); configFile.createNewFile(); } catch (final IOException e) { throw new StoreConfigException( "Error while creating new file. Occures at scope path '" + configDTO.getDefiningScopePath() + "'!", e); } FileOutputStream out = null; try { out = FileUtils.openOutputStream(configFile); marshaller.marshal(out, configDTO); } catch (final FileNotFoundException e) { throw new StoreConfigException( "Error while saving configuration. Occures at scope path '" + configDTO.getDefiningScopePath() + "'!", e); } catch (final IOException e) { throw new StoreConfigException("Error while saving configuration." + configDTO.getDefiningScopePath() + "'!", e); } finally { if (out != null) { try { out.close(); } catch (final IOException e) { LOG.warn( "Error while closing outputStream for configuration with scopepath '" + configDTO.getDefiningScopePath() + "'!", e); } } } } }
FileConfigPersister implements ConfigPersister { @Override public void saveConfiguration(final ComplexConfigDTO configDTO) { Assert.paramNotNull(configDTO, "configuration"); if (configDTO.getVersion() < 1) { throw new StoreConfigException( "Illegal config version. Must be 1 or higher. Occures at scope Path '" + configDTO.getDefiningScopePath() + "'!"); } final File configFile = new File(rootDirectory + File.separator + gen.getPathFromScopePath(configDTO.getDefiningScopePath()) + File.separator + gen.createName(configDTO.getDefiningScopePath()) + fileExtension); if (configFile.exists()) { throw new StaleConfigException( configDTO.getDefiningScopePath(), "Can't save new configuration. There exists already a file for the scope path '" + configDTO.getDefiningScopePath() + "'!"); } try { configFile.getParentFile().mkdirs(); configFile.createNewFile(); } catch (final IOException e) { throw new StoreConfigException( "Error while creating new file. Occures at scope path '" + configDTO.getDefiningScopePath() + "'!", e); } FileOutputStream out = null; try { out = FileUtils.openOutputStream(configFile); marshaller.marshal(out, configDTO); } catch (final FileNotFoundException e) { throw new StoreConfigException( "Error while saving configuration. Occures at scope path '" + configDTO.getDefiningScopePath() + "'!", e); } catch (final IOException e) { throw new StoreConfigException("Error while saving configuration." + configDTO.getDefiningScopePath() + "'!", e); } finally { if (out != null) { try { out.close(); } catch (final IOException e) { LOG.warn( "Error while closing outputStream for configuration with scopepath '" + configDTO.getDefiningScopePath() + "'!", e); } } } } FileConfigPersister(final ConfigMarshaller marshaller, final String rootDirectory, final String fileExtension); }
FileConfigPersister implements ConfigPersister { @Override public void saveConfiguration(final ComplexConfigDTO configDTO) { Assert.paramNotNull(configDTO, "configuration"); if (configDTO.getVersion() < 1) { throw new StoreConfigException( "Illegal config version. Must be 1 or higher. Occures at scope Path '" + configDTO.getDefiningScopePath() + "'!"); } final File configFile = new File(rootDirectory + File.separator + gen.getPathFromScopePath(configDTO.getDefiningScopePath()) + File.separator + gen.createName(configDTO.getDefiningScopePath()) + fileExtension); if (configFile.exists()) { throw new StaleConfigException( configDTO.getDefiningScopePath(), "Can't save new configuration. There exists already a file for the scope path '" + configDTO.getDefiningScopePath() + "'!"); } try { configFile.getParentFile().mkdirs(); configFile.createNewFile(); } catch (final IOException e) { throw new StoreConfigException( "Error while creating new file. Occures at scope path '" + configDTO.getDefiningScopePath() + "'!", e); } FileOutputStream out = null; try { out = FileUtils.openOutputStream(configFile); marshaller.marshal(out, configDTO); } catch (final FileNotFoundException e) { throw new StoreConfigException( "Error while saving configuration. Occures at scope path '" + configDTO.getDefiningScopePath() + "'!", e); } catch (final IOException e) { throw new StoreConfigException("Error while saving configuration." + configDTO.getDefiningScopePath() + "'!", e); } finally { if (out != null) { try { out.close(); } catch (final IOException e) { LOG.warn( "Error while closing outputStream for configuration with scopepath '" + configDTO.getDefiningScopePath() + "'!", e); } } } } FileConfigPersister(final ConfigMarshaller marshaller, final String rootDirectory, final String fileExtension); @Override String getId(); @Override ComplexConfigDTO loadConfiguration(final ScopePath scopePath); @Override void updateConfiguration(final ComplexConfigDTO configDTO); @Override void saveConfiguration(final ComplexConfigDTO configDTO); @Override void delete(final ScopePath scopePath, final boolean deleteChildren); @Override void deleteAllOccurences(final String scopeName, final Map<String, String> properties); @Override Collection<ScopePath> listScopes(final String scopeName, final Map<String, String> properties); }
FileConfigPersister implements ConfigPersister { @Override public void saveConfiguration(final ComplexConfigDTO configDTO) { Assert.paramNotNull(configDTO, "configuration"); if (configDTO.getVersion() < 1) { throw new StoreConfigException( "Illegal config version. Must be 1 or higher. Occures at scope Path '" + configDTO.getDefiningScopePath() + "'!"); } final File configFile = new File(rootDirectory + File.separator + gen.getPathFromScopePath(configDTO.getDefiningScopePath()) + File.separator + gen.createName(configDTO.getDefiningScopePath()) + fileExtension); if (configFile.exists()) { throw new StaleConfigException( configDTO.getDefiningScopePath(), "Can't save new configuration. There exists already a file for the scope path '" + configDTO.getDefiningScopePath() + "'!"); } try { configFile.getParentFile().mkdirs(); configFile.createNewFile(); } catch (final IOException e) { throw new StoreConfigException( "Error while creating new file. Occures at scope path '" + configDTO.getDefiningScopePath() + "'!", e); } FileOutputStream out = null; try { out = FileUtils.openOutputStream(configFile); marshaller.marshal(out, configDTO); } catch (final FileNotFoundException e) { throw new StoreConfigException( "Error while saving configuration. Occures at scope path '" + configDTO.getDefiningScopePath() + "'!", e); } catch (final IOException e) { throw new StoreConfigException("Error while saving configuration." + configDTO.getDefiningScopePath() + "'!", e); } finally { if (out != null) { try { out.close(); } catch (final IOException e) { LOG.warn( "Error while closing outputStream for configuration with scopepath '" + configDTO.getDefiningScopePath() + "'!", e); } } } } FileConfigPersister(final ConfigMarshaller marshaller, final String rootDirectory, final String fileExtension); @Override String getId(); @Override ComplexConfigDTO loadConfiguration(final ScopePath scopePath); @Override void updateConfiguration(final ComplexConfigDTO configDTO); @Override void saveConfiguration(final ComplexConfigDTO configDTO); @Override void delete(final ScopePath scopePath, final boolean deleteChildren); @Override void deleteAllOccurences(final String scopeName, final Map<String, String> properties); @Override Collection<ScopePath> listScopes(final String scopeName, final Map<String, String> properties); static final String ID; }