@Test(expected = StaleConfigException.class) public void testUpdateConfigurationDoesntExists() { final ScopePathBuilderFactory factory = getConfigService().getScopePathBuilderFactory(TestConfiguration.class); final ComplexConfigDTO configuration = createTestConfigDTO(factory.annotatedPath().create()); persister.updateConfiguration(configuration); }
@Override public void updateConfiguration(final ComplexConfigDTO configDTO) { Assert.paramNotNull(configDTO, "configuration"); 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(), "There exists no record for the scope path '" + configDTO.getDefiningScopePath() + "'!"); } final long sourceVersion = loadConfiguration(configDTO.getDefiningScopePath()).getVersion(); final long destinationVersion = configDTO.getVersion(); if (sourceVersion >= destinationVersion) { throw new StaleConfigException( configDTO.getDefiningScopePath(), "The saved Data has a newer or the same version. Occures at scope path '" + configDTO.getDefiningScopePath() + "'!"); } if (sourceVersion < 1) { throw new StoreConfigException( "Illegal config version. Must be 1 or higher. Occures at scope Path '" + configDTO.getDefiningScopePath() + "'!"); } final boolean deleted = configFile.delete(); if (!deleted) { throw new StoreConfigException( "Couldn't update configuration. Deleting old configuration failed. Occures at scope Path '" + configDTO.getDefiningScopePath() + "'!"); } FileOutputStream out = null; try { out = FileUtils.openOutputStream(configFile); marshaller.marshal(out, configDTO); } catch (final FileNotFoundException e) { throw new StoreConfigException( "Error while updating configuration for scope Path '" + configDTO.getDefiningScopePath() + "'!", e); } catch (final IOException e) { throw new StoreConfigException( "Error while updating configuration for scope Path '" + 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 updateConfiguration(final ComplexConfigDTO configDTO) { Assert.paramNotNull(configDTO, "configuration"); 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(), "There exists no record for the scope path '" + configDTO.getDefiningScopePath() + "'!"); } final long sourceVersion = loadConfiguration(configDTO.getDefiningScopePath()).getVersion(); final long destinationVersion = configDTO.getVersion(); if (sourceVersion >= destinationVersion) { throw new StaleConfigException( configDTO.getDefiningScopePath(), "The saved Data has a newer or the same version. Occures at scope path '" + configDTO.getDefiningScopePath() + "'!"); } if (sourceVersion < 1) { throw new StoreConfigException( "Illegal config version. Must be 1 or higher. Occures at scope Path '" + configDTO.getDefiningScopePath() + "'!"); } final boolean deleted = configFile.delete(); if (!deleted) { throw new StoreConfigException( "Couldn't update configuration. Deleting old configuration failed. Occures at scope Path '" + configDTO.getDefiningScopePath() + "'!"); } FileOutputStream out = null; try { out = FileUtils.openOutputStream(configFile); marshaller.marshal(out, configDTO); } catch (final FileNotFoundException e) { throw new StoreConfigException( "Error while updating configuration for scope Path '" + configDTO.getDefiningScopePath() + "'!", e); } catch (final IOException e) { throw new StoreConfigException( "Error while updating configuration for scope Path '" + 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 updateConfiguration(final ComplexConfigDTO configDTO) { Assert.paramNotNull(configDTO, "configuration"); 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(), "There exists no record for the scope path '" + configDTO.getDefiningScopePath() + "'!"); } final long sourceVersion = loadConfiguration(configDTO.getDefiningScopePath()).getVersion(); final long destinationVersion = configDTO.getVersion(); if (sourceVersion >= destinationVersion) { throw new StaleConfigException( configDTO.getDefiningScopePath(), "The saved Data has a newer or the same version. Occures at scope path '" + configDTO.getDefiningScopePath() + "'!"); } if (sourceVersion < 1) { throw new StoreConfigException( "Illegal config version. Must be 1 or higher. Occures at scope Path '" + configDTO.getDefiningScopePath() + "'!"); } final boolean deleted = configFile.delete(); if (!deleted) { throw new StoreConfigException( "Couldn't update configuration. Deleting old configuration failed. Occures at scope Path '" + configDTO.getDefiningScopePath() + "'!"); } FileOutputStream out = null; try { out = FileUtils.openOutputStream(configFile); marshaller.marshal(out, configDTO); } catch (final FileNotFoundException e) { throw new StoreConfigException( "Error while updating configuration for scope Path '" + configDTO.getDefiningScopePath() + "'!", e); } catch (final IOException e) { throw new StoreConfigException( "Error while updating configuration for scope Path '" + 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 updateConfiguration(final ComplexConfigDTO configDTO) { Assert.paramNotNull(configDTO, "configuration"); 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(), "There exists no record for the scope path '" + configDTO.getDefiningScopePath() + "'!"); } final long sourceVersion = loadConfiguration(configDTO.getDefiningScopePath()).getVersion(); final long destinationVersion = configDTO.getVersion(); if (sourceVersion >= destinationVersion) { throw new StaleConfigException( configDTO.getDefiningScopePath(), "The saved Data has a newer or the same version. Occures at scope path '" + configDTO.getDefiningScopePath() + "'!"); } if (sourceVersion < 1) { throw new StoreConfigException( "Illegal config version. Must be 1 or higher. Occures at scope Path '" + configDTO.getDefiningScopePath() + "'!"); } final boolean deleted = configFile.delete(); if (!deleted) { throw new StoreConfigException( "Couldn't update configuration. Deleting old configuration failed. Occures at scope Path '" + configDTO.getDefiningScopePath() + "'!"); } FileOutputStream out = null; try { out = FileUtils.openOutputStream(configFile); marshaller.marshal(out, configDTO); } catch (final FileNotFoundException e) { throw new StoreConfigException( "Error while updating configuration for scope Path '" + configDTO.getDefiningScopePath() + "'!", e); } catch (final IOException e) { throw new StoreConfigException( "Error while updating configuration for scope Path '" + 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 updateConfiguration(final ComplexConfigDTO configDTO) { Assert.paramNotNull(configDTO, "configuration"); 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(), "There exists no record for the scope path '" + configDTO.getDefiningScopePath() + "'!"); } final long sourceVersion = loadConfiguration(configDTO.getDefiningScopePath()).getVersion(); final long destinationVersion = configDTO.getVersion(); if (sourceVersion >= destinationVersion) { throw new StaleConfigException( configDTO.getDefiningScopePath(), "The saved Data has a newer or the same version. Occures at scope path '" + configDTO.getDefiningScopePath() + "'!"); } if (sourceVersion < 1) { throw new StoreConfigException( "Illegal config version. Must be 1 or higher. Occures at scope Path '" + configDTO.getDefiningScopePath() + "'!"); } final boolean deleted = configFile.delete(); if (!deleted) { throw new StoreConfigException( "Couldn't update configuration. Deleting old configuration failed. Occures at scope Path '" + configDTO.getDefiningScopePath() + "'!"); } FileOutputStream out = null; try { out = FileUtils.openOutputStream(configFile); marshaller.marshal(out, configDTO); } catch (final FileNotFoundException e) { throw new StoreConfigException( "Error while updating configuration for scope Path '" + configDTO.getDefiningScopePath() + "'!", e); } catch (final IOException e) { throw new StoreConfigException( "Error while updating configuration for scope Path '" + 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; }