@Override /* ConfigStore */ public synchronized ConfigFileStore update(String name, String newContents) { cache.put(name, newContents); super.update(name, newContents); return this; }
@Override /* ConfigStore */ public synchronized ConfigFileStore update(String name, String newContents) { cache.put(name, newContents); super.update(name, newContents); return this; }
@Override /* ConfigStore */ public synchronized ConfigFileStore update(String name, String newContents) { cache.put(name, newContents); super.update(name, newContents); return this; }
@Override /* ConfigStore */ public synchronized ConfigClasspathStore update(String name, String newContents) { if (newContents == null) cache.remove(name); else cache.put(name, newContents); super.update(name, newContents); return this; }
@Override /* ConfigStore */ public synchronized ConfigMemoryStore update(String name, String newContents) { if (newContents == null) cache.remove(name); else cache.put(name, newContents); super.update(name, newContents); // Trigger any listeners. return this; }
@Override /* ConfigStore */ public synchronized ConfigMemoryStore update(String name, String newContents) { if (newContents == null) cache.remove(name); else cache.put(name, newContents); super.update(name, newContents); // Trigger any listeners. return this; }
@Override /* ConfigStore */ public synchronized ConfigMemoryStore update(String name, String newContents) { if (newContents == null) cache.remove(name); else cache.put(name, newContents); super.update(name, newContents); // Trigger any listeners. return this; }
@Override /* ConfigStore */ public synchronized ConfigClasspathStore update(String name, String newContents) { if (newContents == null) cache.remove(name); else cache.put(name, newContents); super.update(name, newContents); return this; }
@Override /* ConfigStore */ public synchronized ConfigClasspathStore update(String name, String newContents) { if (newContents == null) cache.remove(name); else cache.put(name, newContents); super.update(name, newContents); return this; }
/** * Convenience method for updating the contents of a file with lines. * * @param name The config name (e.g. the filename without the extension). * @param contentLines The new contents. * @return This object (for method chaining). */ public synchronized ConfigStore update(String name, String...contentLines) { StringBuilder sb = new StringBuilder(); for (String l : contentLines) sb.append(l).append('\n'); return update(name, sb.toString()); }
/** * Convenience method for updating the contents of a file with lines. * * @param name The config name (e.g. the filename without the extension). * @param contentLines The new contents. * @return This object (for method chaining). */ public synchronized ConfigStore update(String name, String...contentLines) { name = resolveName(name); StringBuilder sb = new StringBuilder(); for (String l : contentLines) sb.append(l).append('\n'); return update(name, sb.toString()); }
/** * Convenience method for updating the contents of a file with lines. * * @param name The config name (e.g. the filename without the extension). * @param contentLines The new contents. * @return This object (for method chaining). */ public synchronized ConfigStore update(String name, String...contentLines) { name = resolveName(name); StringBuilder sb = new StringBuilder(); for (String l : contentLines) sb.append(l).append('\n'); return update(name, sb.toString()); }
@Test public void testBlankConfig() throws Exception { ConfigStore s = initStore("Foo.cfg", ""); ConfigMap cm = s.getMap("Foo.cfg"); assertEquals("", cm.toString()); s.update("Foo.cfg", " \n \n "); cm = s.getMap("Foo.cfg"); }
@Test public void testSimpleOneLine() throws Exception { ConfigStore s = initStore("Foo.cfg", "foo=bar" ); ConfigMap cm = s.getMap("Foo.cfg"); assertTextEquals("foo=bar|", cm); assertEquals("", join(cm.getPreLines(""), '|')); assertEquals("", join(cm.getEntry("", "foo").getPreLines(), '|')); assertEquals("bar", cm.getEntry("", "foo").getValue()); // Round trip. s.update("Foo.cfg", cm.toString()); cm = s.getMap("Foo.cfg"); assertTextEquals("foo=bar|", cm); }
@Test public void testSimpleOneLineWithComments() throws Exception { ConfigStore s = initStore("Foo.cfg", "#comment", "foo=bar" ); ConfigMap cm = s.getMap("Foo.cfg"); assertTextEquals("#comment|foo=bar|", cm); assertEquals("", join(cm.getPreLines(""), '|')); assertEquals("#comment", join(cm.getEntry("", "foo").getPreLines(), '|')); assertEquals("bar", cm.getEntry("", "foo").getValue()); // Round trip. s.update("Foo.cfg", cm.toString()); cm = s.getMap("Foo.cfg"); assertTextEquals("#comment|foo=bar|", cm); }
@Test public void testSimpleSection() throws Exception { ConfigStore s = initStore("Foo.cfg", "[MySection]", "foo=bar" ); ConfigMap cm = s.getMap("Foo.cfg"); assertTextEquals("[MySection]|foo=bar|", cm); assertEquals("", join(cm.getPreLines(""), '|')); assertEquals("", join(cm.getPreLines("MySection"), '|')); assertEquals("", join(cm.getEntry("MySection", "foo").getPreLines(), '|')); assertEquals("bar", cm.getEntry("MySection", "foo").getValue()); // Round trip. s.update("Foo.cfg", cm.toString()); cm = s.getMap("Foo.cfg"); assertTextEquals("[MySection]|foo=bar|", cm); }
@Test public void testMultipleLinesInSection() throws Exception { ConfigStore s = initStore("Foo.cfg", "[S1]", "k1 = v1a,", "\tv1b,", "\tv1c", "k2 = v2a,", "\tv2b,", "\tv2c" ); ConfigMap cm = s.getMap("Foo.cfg"); assertEquals("", join(cm.getEntry("S1", "k1").getPreLines(), '|')); assertEquals("", join(cm.getEntry("S1", "k2").getPreLines(), '|')); assertTextEquals("[S1]|k1 = v1a,|\tv1b,|\tv1c|k2 = v2a,|\tv2b,|\tv2c|", cm); assertEquals("v1a,\nv1b,\nv1c", cm.getEntry("S1", "k1").getValue()); assertEquals("v2a,\nv2b,\nv2c", cm.getEntry("S1", "k2").getValue()); // Round trip. s.update("Foo.cfg", cm.toString()); cm = s.getMap("Foo.cfg"); assertTextEquals("[S1]|k1 = v1a,|\tv1b,|\tv1c|k2 = v2a,|\tv2b,|\tv2c|", cm); }
@Test public void testMultipleLines() throws Exception { ConfigStore s = initStore("Foo.cfg", "k1 = v1a,", "\tv1b,", "\tv1c", "k2 = v2a,", "\tv2b,", "\tv2c" ); ConfigMap cm = s.getMap("Foo.cfg"); assertEquals("", join(cm.getEntry("", "k1").getPreLines(), '|')); assertEquals("", join(cm.getEntry("", "k2").getPreLines(), '|')); assertTextEquals("k1 = v1a,|\tv1b,|\tv1c|k2 = v2a,|\tv2b,|\tv2c|", cm); assertEquals("v1a,\nv1b,\nv1c", cm.getEntry("", "k1").getValue()); assertEquals("v2a,\nv2b,\nv2c", cm.getEntry("", "k2").getValue()); // Round trip. s.update("Foo.cfg", cm.toString()); cm = s.getMap("Foo.cfg"); assertTextEquals("k1 = v1a,|\tv1b,|\tv1c|k2 = v2a,|\tv2b,|\tv2c|", cm); }
@Test public void testSimpleAndDefaultSectionsWithComments() throws Exception { ConfigStore s = initStore("Foo.cfg", "#D", "", "#k", "k=v", "#S1", "[S1]", "#k1", "k1=v1" ); ConfigMap cm = s.getMap("Foo.cfg"); assertTextEquals("#D||#k|k=v|#S1|[S1]|#k1|k1=v1|", cm); assertEquals("#D", join(cm.getPreLines(""), '|')); assertEquals("#k", join(cm.getEntry("", "k").getPreLines(), '|')); assertEquals("#S1", join(cm.getPreLines("S1"), '|')); assertEquals("#k1", join(cm.getEntry("S1", "k1").getPreLines(), '|')); assertEquals("v", cm.getEntry("", "k").getValue()); assertEquals("v1", cm.getEntry("S1", "k1").getValue()); // Round trip. s.update("Foo.cfg", cm.toString()); cm = s.getMap("Foo.cfg"); assertTextEquals("#D||#k|k=v|#S1|[S1]|#k1|k1=v1|", cm); }
@Test public void testSimpleSectionWithComments() throws Exception { ConfigStore s = initStore("Foo.cfg", "#S1", "[S1]", "#k1", "k1=v1", "#S2", "[S2]", "#k2", "k2=v2" ); ConfigMap cm = s.getMap("Foo.cfg"); assertTextEquals("#S1|[S1]|#k1|k1=v1|#S2|[S2]|#k2|k2=v2|", cm); assertEquals("", join(cm.getPreLines(""), '|')); assertEquals("#S1", join(cm.getPreLines("S1"), '|')); assertEquals("#k1", join(cm.getEntry("S1", "k1").getPreLines(), '|')); assertEquals("#S2", join(cm.getPreLines("S2"), '|')); assertEquals("#k2", join(cm.getEntry("S2", "k2").getPreLines(), '|')); assertEquals("v1", cm.getEntry("S1", "k1").getValue()); assertEquals("v2", cm.getEntry("S2", "k2").getValue()); // Round trip. s.update("Foo.cfg", cm.toString()); cm = s.getMap("Foo.cfg"); assertTextEquals("#S1|[S1]|#k1|k1=v1|#S2|[S2]|#k2|k2=v2|", cm); }