@Override final public T get() { try { VersionedFormat configuredFormat = readConfig(config); Provider<T> formatProvider = plugins.get(configuredFormat); if (formatProvider == null) { throw new RuntimeException( "No such format: " + configuredFormat + "(from " + config.getAll() + ")"); } else { return formatProvider.get(); } } catch (RuntimeException e) { e.printStackTrace(); throw e; } }
@Test public void testGlobalOnly() { ConfigDatabase globalOnly = IniFileConfigDatabase.globalOnly(platform); testGlobalOnly(() -> globalOnly.get("section.key")); testGlobalOnly(() -> globalOnly.getAll()); testGlobalOnly(() -> globalOnly.get("section.key", String.class)); testGlobalOnly(() -> globalOnly.getAllSection("section")); testGlobalOnly(() -> globalOnly.getAllSubsections("section.sub")); testGlobalOnly(() -> globalOnly.put("section.key", "val")); testGlobalOnly(() -> globalOnly.remove("section.key")); testGlobalOnly(() -> globalOnly.removeSection("section")); }
@Test public void testGlobalOnly() { ConfigDatabase globalOnly = IniFileConfigDatabase.globalOnly(platform); testGlobalOnly(() -> globalOnly.get("section.key")); testGlobalOnly(() -> globalOnly.getAll()); testGlobalOnly(() -> globalOnly.get("section.key", String.class)); testGlobalOnly(() -> globalOnly.getAllSection("section")); testGlobalOnly(() -> globalOnly.getAllSubsections("section.sub")); testGlobalOnly(() -> globalOnly.put("section.key", "val")); testGlobalOnly(() -> globalOnly.remove("section.key")); testGlobalOnly(() -> globalOnly.removeSection("section")); }
@Override final public T get() { try { VersionedFormat configuredFormat = readConfig(config); Provider<T> formatProvider = plugins.get(configuredFormat); if (formatProvider == null) { throw new RuntimeException( "No such format: " + configuredFormat + "(from " + config.getAll() + ")"); } else { return formatProvider.get(); } } catch (RuntimeException e) { e.printStackTrace(); throw e; } }
private void addDefaults(ConfigDatabase configDB, PluginDefaults defaults, Map<String, String> configProps) { final String refsKey = "storage.refs"; final String objectsKey = "storage.objects"; final String graphKey = "storage.graph"; final Map<String, String> providedConfig = configDB.getAll(); Optional<VersionedFormat> refs; Optional<VersionedFormat> objects; Optional<VersionedFormat> graph; refs = providedConfig.containsKey(refsKey) ? absent() : defaults.getRefs(); objects = providedConfig.containsKey(objectsKey) ? absent() : defaults.getObjects(); if (refs.isPresent()) { configProps.put(refsKey, refs.get().getFormat()); configProps.put(refs.get().getFormat() + ".version", refs.get().getVersion()); } if (objects.isPresent()) { configProps.put(objectsKey, objects.get().getFormat()); configProps.put(objects.get().getFormat() + ".version", objects.get().getVersion()); } }
private void addDefaults(ConfigDatabase configDB, PluginDefaults defaults, Map<String, String> configProps) { final String refsKey = "storage.refs"; final String objectsKey = "storage.objects"; final Map<String, String> providedConfig = configDB.getAll(); Optional<VersionedFormat> refs; Optional<VersionedFormat> objects; refs = providedConfig.containsKey(refsKey) ? absent() : defaults.getRefs(); objects = providedConfig.containsKey(objectsKey) ? absent() : defaults.getObjects(); if (refs.isPresent()) { configProps.put(refsKey, refs.get().getFormat()); configProps.put(refs.get().getFormat() + ".version", refs.get().getVersion()); } if (objects.isPresent()) { configProps.put(objectsKey, objects.get().getFormat()); configProps.put(objects.get().getFormat() + ".version", objects.get().getVersion()); } }
public List<BranchConfig> getAll() { List<BranchConfig> configs = new ArrayList<>(); final Map<String, String> all = configDatabase().getAll(); for (Ref branch : command(BranchListOp.class).call()) { final String section = String.format("branches.%s", branch.localName()); final String remoteKey = String.format("%s.%s", section, "remote"); final String remoteBranchKey = String.format("%s.%s", section, "merge"); final String descriptionKey = String.format("%s.%s", section, "description"); String remoteName = all.get(remoteKey); String remoteBranch = all.get(remoteBranchKey); String description = all.get(descriptionKey); BranchConfig config = BranchConfig.builder()// .branch(branch)// .remoteName(Optional.ofNullable(remoteName))// .remoteBranch(Optional.ofNullable(remoteBranch))// .description(Optional.ofNullable(description))// .build(); configs.add(config); } return configs; }
@Test public void testGetAll() { // Test integer and string config.put("section1.int", 1); config.put("section1.subsection.string", "2"); config.put("section1.subsection.subsub.int", 1); config.put("section2.int", 3); config.put("section2.subsection.string", "4"); Map<String, String> all = config.getAll(); Map<String, String> expected = ImmutableMap.of("section1.int", "1", "section1.subsection.string", "2", "section1.subsection.subsub.int", "1", "section2.int", "3", "section2.subsection.string", "4"); // check key by key instead of equals on the maps in case the backend adds some extra config // as part of its initialization process expected.entrySet().forEach((e) -> assertEquals(e.getValue(), all.get(e.getKey()))); }
@Test public void testGetAll() { // Test integer and string config.put("section1.int", 1); config.put("section1.subsection.string", "2"); config.put("section1.subsection.subsub.int", 1); config.put("section2.int", 3); config.put("section2.subsection.string", "4"); Map<String, String> all = config.getAll(); Map<String, String> expected = ImmutableMap.of("section1.int", "1", "section1.subsection.string", "2", "section1.subsection.subsub.int", "1", "section2.int", "3", "section2.subsection.string", "4"); // check key by key instead of equals on the maps in case the backend adds some extra config // as part of its initialization process expected.entrySet().forEach((e) -> assertEquals(e.getValue(), all.get(e.getKey()))); }
@Test public void testListDefaultWithNoLocalRepository() { ConfigDatabase database = mock(ConfigDatabase.class); when(database.getAll()).thenThrow(new ConfigException(StatusCode.INVALID_LOCATION)); ConfigOp config = new ConfigOp(database); config.setScope(ConfigScope.DEFAULT).setAction(ConfigAction.CONFIG_LIST).setName(null) .setValue(null).call(); }
@Test public void testListLocalWithNoLocalRepository() { ConfigDatabase database = mock(ConfigDatabase.class); when(database.getAll()).thenThrow(new ConfigException(StatusCode.INVALID_LOCATION)); ConfigOp config = new ConfigOp(database); exception.expect(ConfigException.class); config.setScope(ConfigScope.LOCAL).setAction(ConfigAction.CONFIG_LIST).setName(null) .setValue(null).call(); }
@Test public void testListDefaultWithNoLocalRepository() { ConfigDatabase database = mock(ConfigDatabase.class); when(database.getAll()).thenThrow(new ConfigException(StatusCode.INVALID_LOCATION)); ConfigOp config = new ConfigOp(database); config.setScope(ConfigScope.DEFAULT).setAction(ConfigAction.CONFIG_LIST).setName(null) .setValue(null).call(); }
@Test public void testListLocalWithNoLocalRepository() { ConfigDatabase database = mock(ConfigDatabase.class); when(database.getAll()).thenThrow(new ConfigException(StatusCode.INVALID_LOCATION)); ConfigOp config = new ConfigOp(database); exception.expect(ConfigException.class); config.setScope(ConfigScope.LOCAL).setAction(ConfigAction.CONFIG_LIST).setName(null) .setValue(null).call(); }