@Test public void cannotLoadStoresWithMismatchedNames() throws IOException { File customStorePropertiesFile = temporaryFolder.newFile("custom-store.properties"); write(customStorePropertiesFile.toPath(), ImmutableList.of("name=example")); try { underTest.load("custom"); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), containsString("is for a different data store")); } }
@Override public DataStoreConfiguration load(final String storeName) { checkName(storeName); PropertiesFile storeProperties = findStoreProperties(storeName); synchronized (storeProperties) { try { if (storeProperties.exists()) { storeProperties.load(); checkArgument(storeName.equals(storeProperties.getProperty(NAME_KEY)), "%s is for a different data store", storeProperties); } } catch (IOException e) { throw new UncheckedIOException(e); } String storeType = storeProperties.getProperty(TYPE_KEY); if (storeType == null) { storeType = "jdbc"; storeProperties.setProperty(TYPE_KEY, storeType); storeProperties.setProperty("jdbcUrl", JDBC_TEMPLATE_URL); } DataStoreConfiguration configuration = new DataStoreConfiguration(); configuration.setName(storeName); configuration.setType(storeType); configuration.setAttributes(filterKeys(fromProperties(storeProperties), not(in(TOP_LEVEL_KEYS)))); configuration.setSource(LOCAL); return configuration; } }
DataStoreConfigurationLocalSource extends ComponentSupport implements DataStoreConfigurationSource { @Override public DataStoreConfiguration load(final String storeName) { checkName(storeName); PropertiesFile storeProperties = findStoreProperties(storeName); synchronized (storeProperties) { try { if (storeProperties.exists()) { storeProperties.load(); checkArgument(storeName.equals(storeProperties.getProperty(NAME_KEY)), "%s is for a different data store", storeProperties); } } catch (IOException e) { throw new UncheckedIOException(e); } String storeType = storeProperties.getProperty(TYPE_KEY); if (storeType == null) { storeType = "jdbc"; storeProperties.setProperty(TYPE_KEY, storeType); storeProperties.setProperty("jdbcUrl", JDBC_TEMPLATE_URL); } DataStoreConfiguration configuration = new DataStoreConfiguration(); configuration.setName(storeName); configuration.setType(storeType); configuration.setAttributes(filterKeys(fromProperties(storeProperties), not(in(TOP_LEVEL_KEYS)))); configuration.setSource(LOCAL); return configuration; } } }
DataStoreConfigurationLocalSource extends ComponentSupport implements DataStoreConfigurationSource { @Override public DataStoreConfiguration load(final String storeName) { checkName(storeName); PropertiesFile storeProperties = findStoreProperties(storeName); synchronized (storeProperties) { try { if (storeProperties.exists()) { storeProperties.load(); checkArgument(storeName.equals(storeProperties.getProperty(NAME_KEY)), "%s is for a different data store", storeProperties); } } catch (IOException e) { throw new UncheckedIOException(e); } String storeType = storeProperties.getProperty(TYPE_KEY); if (storeType == null) { storeType = "jdbc"; storeProperties.setProperty(TYPE_KEY, storeType); storeProperties.setProperty("jdbcUrl", JDBC_TEMPLATE_URL); } DataStoreConfiguration configuration = new DataStoreConfiguration(); configuration.setName(storeName); configuration.setType(storeType); configuration.setAttributes(filterKeys(fromProperties(storeProperties), not(in(TOP_LEVEL_KEYS)))); configuration.setSource(LOCAL); return configuration; } } @Inject  DataStoreConfigurationLocalSource(final ApplicationDirectories directories); }
DataStoreConfigurationLocalSource extends ComponentSupport implements DataStoreConfigurationSource { @Override public DataStoreConfiguration load(final String storeName) { checkName(storeName); PropertiesFile storeProperties = findStoreProperties(storeName); synchronized (storeProperties) { try { if (storeProperties.exists()) { storeProperties.load(); checkArgument(storeName.equals(storeProperties.getProperty(NAME_KEY)), "%s is for a different data store", storeProperties); } } catch (IOException e) { throw new UncheckedIOException(e); } String storeType = storeProperties.getProperty(TYPE_KEY); if (storeType == null) { storeType = "jdbc"; storeProperties.setProperty(TYPE_KEY, storeType); storeProperties.setProperty("jdbcUrl", JDBC_TEMPLATE_URL); } DataStoreConfiguration configuration = new DataStoreConfiguration(); configuration.setName(storeName); configuration.setType(storeType); configuration.setAttributes(filterKeys(fromProperties(storeProperties), not(in(TOP_LEVEL_KEYS)))); configuration.setSource(LOCAL); return configuration; } } @Inject  DataStoreConfigurationLocalSource(final ApplicationDirectories directories); @Override String getName(); @Override boolean isModifiable(); @Override Iterable<String> browseStoreNames(); @Override DataStoreConfiguration load(final String storeName); @Override void save(final DataStoreConfiguration configuration); @Override void delete(final DataStoreConfiguration configuration); }
DataStoreConfigurationLocalSource extends ComponentSupport implements DataStoreConfigurationSource { @Override public DataStoreConfiguration load(final String storeName) { checkName(storeName); PropertiesFile storeProperties = findStoreProperties(storeName); synchronized (storeProperties) { try { if (storeProperties.exists()) { storeProperties.load(); checkArgument(storeName.equals(storeProperties.getProperty(NAME_KEY)), "%s is for a different data store", storeProperties); } } catch (IOException e) { throw new UncheckedIOException(e); } String storeType = storeProperties.getProperty(TYPE_KEY); if (storeType == null) { storeType = "jdbc"; storeProperties.setProperty(TYPE_KEY, storeType); storeProperties.setProperty("jdbcUrl", JDBC_TEMPLATE_URL); } DataStoreConfiguration configuration = new DataStoreConfiguration(); configuration.setName(storeName); configuration.setType(storeType); configuration.setAttributes(filterKeys(fromProperties(storeProperties), not(in(TOP_LEVEL_KEYS)))); configuration.setSource(LOCAL); return configuration; } } @Inject  DataStoreConfigurationLocalSource(final ApplicationDirectories directories); @Override String getName(); @Override boolean isModifiable(); @Override Iterable<String> browseStoreNames(); @Override DataStoreConfiguration load(final String storeName); @Override void save(final DataStoreConfiguration configuration); @Override void delete(final DataStoreConfiguration configuration);  }