@Rule
public ErrorCollectorExt errorCollector = new ErrorCollectorExt();
@Test
public void testConfigFile() throws Exception {
ConfigFile configFile = new ConfigFile(new BasicSessionContext(null));
configFile.addLocation(new File(Configuration.get().getTestDataDir(), "sample.rc"));
// section1 has key1 unset, key2 overridden from included, key4 from second occurence
HashMap<String, String> section1 = new HashMap<String, String>();
section1.put("key2", "alternative value 2");
section1.put("key3", "value 3");
section1.put("key4", "value 4");
// section2 comes from included config
HashMap<String, String> section2 = new HashMap<String, String>();
section2.put("key1", "value 1-2");
HashMap<String, String> section3 = new HashMap<String, String>();
section3.put("key1", "value 1-3");
HashMap<String, HashMap<String,String>> sections = new HashMap<String, HashMap<String,String>>();
sections.put("section1", section1);
sections.put("section2", section2);
sections.put("section3", section3);
//
for (String s : configFile.getSectionNames()) {
// System.out.printf("[%s]\n", s);
final HashMap<String, String> m = sections.remove(s);
errorCollector.assertTrue(m != null);
for (Map.Entry<String, String> e : configFile.getSection(s).entrySet()) {
// System.out.printf("%s = %s\n", e.getKey(), e.getValue());
if (m.containsKey(e.getKey())) {
errorCollector.assertEquals(m.remove(e.getKey()), e.getValue());
} else {
errorCollector.fail("Unexpected key:" + e.getKey());