use of net.morimekta.providence.config.ProvidenceConfigException in project providence by morimekta.
the class ProvidenceConfigParserTest method assertConfigFails.
private void assertConfigFails(String cfg, String message) throws IOException {
try {
File a = writeContentTo(cfg, temp.newFile());
ProvidenceConfigParser config = new ProvidenceConfigParser(registry, false);
config.parseConfig(a.toPath(), null);
fail("No exception on fail: " + message);
} catch (ProvidenceConfigException e) {
assertThat(e.getMessage(), is(message));
}
}
use of net.morimekta.providence.config.ProvidenceConfigException in project providence by morimekta.
the class ProvidenceConfigParserTest method testInternalReference.
@Test
public void testInternalReference() throws IOException {
File a = writeContentTo("config.RefMerge {\n" + " ref1 & first = {\n" + " bool_value & boo = false\n" + " msg_value & db {\n" + " driver = \"Driver\"\n" + " }\n" + " }\n" + " ref1_1 = first {\n" + " i16_value = 12345\n" + " msg_value & db2 = db {\n" + " uri = \"someuri\"\n" + " }\n" + " }\n" + " ref2 {\n" + " bool_value = boo" + " msg_value = db2\n" + " }\n" + "}\n", temp.newFile("a.cfg"));
try {
ProvidenceConfigParser config = new ProvidenceConfigParser(registry, false);
RefMerge merged = config.parseConfig(a.toPath(), (RefMerge) null).first;
assertThat(debugString(merged), is("{\n" + " ref1 = {\n" + " bool_value = false\n" + " msg_value = {\n" + " driver = \"Driver\"\n" + " }\n" + " }\n" + " ref1_1 = {\n" + " bool_value = false\n" + " i16_value = 12345\n" + " msg_value = {\n" + " uri = \"someuri\"\n" + " driver = \"Driver\"\n" + " }\n" + " }\n" + " ref2 = {\n" + " bool_value = false\n" + " msg_value = {\n" + " uri = \"someuri\"\n" + " driver = \"Driver\"\n" + " }\n" + " }\n" + "}"));
} catch (ProvidenceConfigException e) {
System.err.println(e.asString());
throw e;
}
}
use of net.morimekta.providence.config.ProvidenceConfigException in project providence by morimekta.
the class ProvidenceConfigParserTest method assertParseFailure.
private void assertParseFailure(String message, String pretty, boolean strict) throws IOException {
File a = temp.newFile("test.cfg");
writeContentTo(pretty, a);
ProvidenceConfigParser config = new ProvidenceConfigParser(registry, strict);
try {
config.parseConfig(a.toPath(), null);
fail("no exception");
} catch (ProvidenceConfigException e) {
String actual = e.asString().replaceAll("\\r", "");
if (!actual.equals(message)) {
e.printStackTrace();
}
assertThat(actual, is(message));
}
a.delete();
}
use of net.morimekta.providence.config.ProvidenceConfigException in project providence by morimekta.
the class ProvidenceConfigParserTest method testParseWithUnknown_strict.
@Test
public void testParseWithUnknown_strict() throws IOException {
copyResourceTo("/net/morimekta/providence/config/files/unknown.cfg", temp.getRoot());
File file = copyResourceTo("/net/morimekta/providence/config/files/unknown_include.cfg", temp.getRoot());
ProvidenceConfigParser config = new ProvidenceConfigParser(registry, true);
try {
config.parseConfig(file.toPath(), null);
fail("no exception");
} catch (ProvidenceConfigException e) {
assertEquals("Unknown declared type: unknown.OtherConfig", e.getMessage());
}
file = copyResourceTo("/net/morimekta/providence/config/files/unknown_field.cfg", temp.getRoot());
try {
config.parseConfig(file.toPath(), null);
fail("no exception");
} catch (ProvidenceConfigException e) {
assertEquals("No such field unknown_field in config.Database", e.getMessage());
}
file = copyResourceTo("/net/morimekta/providence/config/files/unknown_enum_value.cfg", temp.getRoot());
try {
config.parseConfig(file.toPath(), null);
fail("no exception");
} catch (ProvidenceConfigException e) {
assertEquals("No such enum value 'LAST' for config.Value.", e.getMessage());
}
file = copyResourceTo("/net/morimekta/providence/config/files/unknown_enum_value2.cfg", temp.getRoot());
try {
config.parseConfig(file.toPath(), null);
fail("no exception");
} catch (ProvidenceConfigException e) {
assertEquals("No such enum value 'second' for config.Value, did you mean 'SECOND'?", e.getMessage());
}
}
use of net.morimekta.providence.config.ProvidenceConfigException in project providence by morimekta.
the class ProvidenceConfigSupplierTest method testSupplierKeepInstanceOnFailedReload.
@Test
public void testSupplierKeepInstanceOnFailedReload() throws IOException {
Database first = Database.builder().build();
File file = tmp.newFile().getAbsoluteFile().getCanonicalFile();
when((Pair) parser.parseConfig(file.toPath(), null)).thenReturn(Pair.create(first, ImmutableSet.of(file.toString())));
ArgumentCaptor<FileWatcher.Watcher> watcherCapture = ArgumentCaptor.forClass(FileWatcher.Watcher.class);
doNothing().when(watcher).weakAddWatcher(watcherCapture.capture());
ProvidenceConfigSupplier<Database, Database._Field> supplier = new ProvidenceConfigSupplier<>(file, null, watcher, parser, clock);
assertThat(supplier.get(), is(first));
verify(watcher).weakAddWatcher(any(FileWatcher.Watcher.class));
reset(parser, watcher);
when(parser.parseConfig(file.toPath(), null)).thenThrow(new ProvidenceConfigException("test"));
watcherCapture.getValue().onFileUpdate(file);
verify(parser).parseConfig(file.toPath(), null);
verifyNoMoreInteractions(parser);
assertThat(supplier.get(), is(first));
}
Aggregations