ContextFilePersistenceService implements ConfigPersistenceBackendService<Map<String, String>> { @SuppressWarnings("unchecked") @Override public void persist(ConfigItem<Map<String, String>> config) throws PersistenceException, InvalidConfigurationException { Preconditions.checkArgument(supports((Class<? extends ConfigItem<?>>) config.getClass()), "Argument type not supported"); Preconditions.checkNotNull(config.getMetaData(), "Invalid metadata"); String contextFileName = getFileNameForMetaData(config.getMetaData()); File contextPersistenceFile = new File(storageFolder, contextFileName); try { FileUtils.touch(contextPersistenceFile); } catch (IOException e) { throw new PersistenceException(String.format("Could not persist context configuration file %s", contextFileName), e); } LOGGER.info("Created context configuration file %s", contextFileName); }  @Override List<ConfigItem<Map<String, String>>> load(Map<String, String> metadata); @SuppressWarnings("unchecked") @Override void persist(ConfigItem<Map<String, String>> config); @Override void remove(Map<String, String> metadata); @Override boolean supports(Class<? extends ConfigItem<?>> configItemType); void setStorageFolderPath(String storageFolderPath); static final String CONTEXT_FILE_EXTENSION; }
@Test(expected = IllegalArgumentException.class) public void testPersistingUnknownItemType_shouldThrowException() throws Exception { persistenceService.persist(new UnknownConfigItem()); }
@Test public void testPersistingContext_shouldCreateNewFile() throws Exception { File configFileThatShouldBeCreated = new File(temporaryFolder.getRoot(), "contextFoo.context"); Integer filesBefore = countFilesInTempFolder(); persistenceService.persist(getEmptyContextConfigurationWithId("contextFoo")); Integer filesAfter = countFilesInTempFolder(); assertThat(filesAfter, is(filesBefore + 1)); assertThat(configFileThatShouldBeCreated.exists(), is(true)); }