use of net.morimekta.test.providence.config.Database in project providence by morimekta.
the class FixedConfigSupplierTest method testCreate.
@Test
@SuppressWarnings("unchecked")
public void testCreate() {
FakeClock clock = FakeClock.forCurrentTimeMillis(System.currentTimeMillis());
Database value = Database.builder().build();
ConfigSupplier<Database, Database._Field> supplier = mock(ConfigSupplier.class);
when(supplier.get()).thenReturn(value).thenReturn(value);
when(supplier.configTimestamp()).thenAnswer(i -> clock.millis());
when(supplier.snapshot()).thenCallRealMethod();
FixedConfigSupplier<Database, Database._Field> fixed = new FixedConfigSupplier<>(supplier);
clock.tick(1000);
ConfigSupplier<Database, Database._Field> snapshot = supplier.snapshot();
assertThat(fixed.get(), is(sameInstance(value)));
assertThat(snapshot.get(), is(sameInstance(value)));
assertThat(fixed.configTimestamp(), is(snapshot.configTimestamp() - 1000));
assertThat(fixed.snapshot(), is(sameInstance(fixed)));
}
use of net.morimekta.test.providence.config.Database in project providence by morimekta.
the class OverrideConfigSupplierTest method testSupplier.
@Test
public void testSupplier() throws IOException {
OverrideConfigSupplier<Database, Database._Field> supplier = new OverrideConfigSupplier<>(clock, base, ImmutableMap.of("credentials.password", "password", "uri", "undefined"), true);
Database instance = supplier.get();
assertThat(supplier.get(), is(sameInstance(instance)));
// it was reset.
assertThat(instance.getUri(), is(nullValue()));
assertThat(instance.getDriver(), is("driver"));
assertThat(instance.getCredentials(), is(not(nullValue())));
assertThat(instance.getCredentials().getUsername(), is("username"));
// it was updated.
assertThat(instance.getCredentials().getPassword(), is("password"));
base.testUpdate(Database.builder().setUri("http://hostname:9057/path").setDriver("otherDriver").setCredentials(new Credentials("username", "complicated password that no one guesses")).build());
// updating the base updates the result.
assertThat(supplier.get(), is(not(sameInstance(instance))));
instance = supplier.get();
assertThat(supplier.get(), is(sameInstance(instance)));
assertThat(supplier.configTimestamp(), is(clock.millis()));
// it was reset.
assertThat(instance.getUri(), is(nullValue()));
assertThat(instance.getDriver(), is("otherDriver"));
assertThat(instance.getCredentials(), is(not(nullValue())));
assertThat(instance.getCredentials().getUsername(), is("username"));
// it was updated.
assertThat(instance.getCredentials().getPassword(), is("password"));
}
use of net.morimekta.test.providence.config.Database in project providence by morimekta.
the class ProvidenceConfigTest method testGetConfig_withParent.
@Test
public void testGetConfig_withParent() throws IOException {
File f_stage_db = copyResourceTo("/net/morimekta/providence/config/files/stage_db.cfg", temp.getRoot());
File f_stage_nocred = copyResourceTo("/net/morimekta/providence/config/files/stage_nocred.cfg", temp.getRoot());
ProvidenceConfig config = new ProvidenceConfig(registry, null, true);
Database stage_db = config.getConfig(f_stage_db);
Database stage_nocred = config.getConfig(f_stage_nocred, stage_db);
assertEquals("{\n" + " uri = \"jdbc:h2:localhost:mem\"\n" + " driver = \"org.h2.Driver\"\n" + "}", debugString(stage_nocred));
}
use of net.morimekta.test.providence.config.Database in project providence by morimekta.
the class ProvidenceConfigTest method testResolveConfig_withParent.
@Test
public void testResolveConfig_withParent() throws IOException {
File f_stage_db = copyResourceTo("/net/morimekta/providence/config/files/stage_db.cfg", temp.getRoot());
File f_stage_nocred = copyResourceTo("/net/morimekta/providence/config/files/stage_nocred.cfg", temp.getRoot());
ProvidenceConfig config = new ProvidenceConfig(registry, null, true);
ConfigSupplier<Database, Database._Field> stage_db = config.resolveConfig(f_stage_db);
ConfigSupplier<Database, Database._Field> stage_nocred = config.resolveConfig(f_stage_nocred, stage_db);
assertEquals("{\n" + " uri = \"jdbc:h2:localhost:mem\"\n" + " driver = \"org.h2.Driver\"\n" + "}", debugString(stage_nocred.get()));
}
use of net.morimekta.test.providence.config.Database in project providence by morimekta.
the class ProvidenceConfigParserTest method testParseWithUnknownInclude.
@Test
public void testParseWithUnknownInclude() 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());
Pair<Database, Set<String>> cfg = parser.parseConfig(file.toPath(), null);
// all the unknowns are skipped.
assertEquals("{\n" + " uri = \"jdbc:h2:localhost:mem\"\n" + " driver = \"org.h2.Driver\"\n" + "}", debugString(cfg.first));
file = copyResourceTo("/net/morimekta/providence/config/files/unknown_field.cfg", temp.getRoot());
cfg = parser.parseConfig(file.toPath(), null);
assertEquals("{\n" + " uri = \"jdbc:h2:localhost:mem\"\n" + " driver = \"org.h2.Driver\"\n" + "}", debugString(cfg.first));
file = copyResourceTo("/net/morimekta/providence/config/files/unknown_enum_value.cfg", temp.getRoot());
cfg = parser.parseConfig(file.toPath(), null);
assertEquals("{\n" + " uri = \"jdbc:h2:localhost:mem\"\n" + " driver = \"org.h2.Driver\"\n" + "}", debugString(cfg.first));
}
Aggregations