@Test public void testResolveConfig_simple() throws IOException { copyResourceTo("/net/morimekta/providence/config/files/base_service.cfg", temp.getRoot()); copyResourceTo("/net/morimekta/providence/config/files/prod_db.cfg", temp.getRoot()); copyResourceTo("/net/morimekta/providence/config/files/stage_db.cfg", temp.getRoot()); File prod = copyResourceTo("/net/morimekta/providence/config/files/prod.cfg", temp.getRoot()); File stage = copyResourceTo("/net/morimekta/providence/config/files/stage.cfg", temp.getRoot()); ProvidenceConfig config = new ProvidenceConfig(registry, null, true); Service stage_service = config.getConfig(stage); Service prod_service = config.getConfig(prod); assertEquals("{\n" + " name = \"prod\"\n" + " http = {\n" + " port = 8080\n" + " context = \"/app\"\n" + " signature_keys = {\n" + " \"app1\": b64(VGVzdCBPYXV0aCBLZXkK)\n" + " }\n" + " signature_override_keys = [\n" + " \"not_really_app_1\"\n" + " ]\n" + " }\n" + " admin = {\n" + " port = 8088\n" + " oauth_token_key = b64(VGVzdCBPYXV0aCBLZXkK)\n" + " }\n" + " db = {\n" + " uri = \"jdbc:mysql:db01:1364/my_db\"\n" + " driver = \"org.mysql.Driver\"\n" + " credentials = {\n" + " username = \"dbuser\"\n" + " password = \"DbP4s5w0rD\"\n" + " }\n" + " }\n" + "}", debugString(prod_service)); assertEquals("{\n" + " name = \"stage\"\n" + " http = {\n" + " port = 8080\n" + " context = \"/app\"\n" + " signature_keys = {\n" + " \"app1\": b64(VGVzdCBPYXV0aCBLZXkK)\n" + " }\n" + " signature_override_keys = [\n" + " \"not_really_app_1\"\n" + " ]\n" + " }\n" + " db = {\n" + " uri = \"jdbc:h2:localhost:mem\"\n" + " driver = \"org.h2.Driver\"\n" + " credentials = {\n" + " username = \"myuser\"\n" + " password = \"MyP4s5w0rd\"\n" + " }\n" + " }\n" + "}", debugString(stage_service)); }
@Nonnull public <M extends PMessage<M, F>, F extends PField> M getConfig(@Nonnull File configFile) throws ProvidenceConfigException { ConfigSupplier<M,F> supplier = resolveConfig(configFile); return supplier.get(); }
ProvidenceConfig implements ConfigResolver { @Nonnull public <M extends PMessage<M, F>, F extends PField> M getConfig(@Nonnull File configFile) throws ProvidenceConfigException { ConfigSupplier<M,F> supplier = resolveConfig(configFile); return supplier.get(); } }
ProvidenceConfig implements ConfigResolver { @Nonnull public <M extends PMessage<M, F>, F extends PField> M getConfig(@Nonnull File configFile) throws ProvidenceConfigException { ConfigSupplier<M,F> supplier = resolveConfig(configFile); return supplier.get(); } ProvidenceConfig(TypeRegistry registry);  ProvidenceConfig(@Nonnull TypeRegistry registry,
                            @Nullable FileWatcher watcher, boolean strict);  ProvidenceConfig(@Nonnull TypeRegistry registry,
                            @Nullable FileWatcher watcher,
                            boolean strict,
                            @Nonnull Clock clock); }
ProvidenceConfig implements ConfigResolver { @Nonnull public <M extends PMessage<M, F>, F extends PField> M getConfig(@Nonnull File configFile) throws ProvidenceConfigException { ConfigSupplier<M,F> supplier = resolveConfig(configFile); return supplier.get(); } ProvidenceConfig(TypeRegistry registry);  ProvidenceConfig(@Nonnull TypeRegistry registry,
                            @Nullable FileWatcher watcher, boolean strict);  ProvidenceConfig(@Nonnull TypeRegistry registry,
                            @Nullable FileWatcher watcher,
                            boolean strict,
                            @Nonnull Clock clock); @Nonnull @Override @SuppressWarnings("unchecked") ConfigSupplier<M, F> resolveConfig(@Nonnull File configFile,
                                       @Nullable ConfigSupplier<M, F> parentConfig); @Nonnull M getConfig(@Nonnull File configFile); @Nonnull M getConfig(@Nonnull File configFile, @Nonnull M parent); }
ProvidenceConfig implements ConfigResolver { @Nonnull public <M extends PMessage<M, F>, F extends PField> M getConfig(@Nonnull File configFile) throws ProvidenceConfigException { ConfigSupplier<M,F> supplier = resolveConfig(configFile); return supplier.get(); } ProvidenceConfig(TypeRegistry registry);  ProvidenceConfig(@Nonnull TypeRegistry registry,
                            @Nullable FileWatcher watcher, boolean strict);  ProvidenceConfig(@Nonnull TypeRegistry registry,
                            @Nullable FileWatcher watcher,
                            boolean strict,
                            @Nonnull Clock clock); @Nonnull @Override @SuppressWarnings("unchecked") ConfigSupplier<M, F> resolveConfig(@Nonnull File configFile,
                                       @Nullable ConfigSupplier<M, F> parentConfig); @Nonnull M getConfig(@Nonnull File configFile); @Nonnull M getConfig(@Nonnull File configFile, @Nonnull M parent);  }