AbstractConfigProducer implements ConfigProducer, ConfigInstance.Producer, Serializable { protected ClassLoader getConfigClassLoader(String producerName) { ClassLoader classLoader = findInheritedClassLoader(getClass(), producerName); if (classLoader != null) return classLoader; for (AbstractConfigProducer child : childrenBySubId.values()) { ClassLoader loader = child.getConfigClassLoader(producerName); if (loader != null) { return loader; } } return null; } AbstractConfigProducer(AbstractConfigProducer parent, String subId);  AbstractConfigProducer(String subId); final String getSubId(); void removeChild(CHILD child); void setUserConfigs(UserConfigRepo repo); @Override UserConfigRepo getUserConfigs(); final String getConfigId(); Map<String, CHILD> getChildren(); @Beta List<J> getChildrenByTypeRecursive(Class<J> type); List<Service> getDescendantServices(); @Override final boolean cascadeConfig(ConfigInstance.Builder builder); @Override final boolean addUserConfig(ConfigInstance.Builder builder); HostSystem hostSystem(); AbstractConfigProducerRoot getRoot(); AbstractConfigProducer getParent(); void dump(PrintStream out); void mergeUserConfigs(UserConfigRepo newRepo); @Override void validate(); static final Logger log; }
@Test public void require_that_interface_is_found_if_directly_implemented() throws ReflectiveOperationException { MockLogdProducer producer = new MockLogdProducer("mocky"); ClassLoader loader = producer.getConfigClassLoader(LogdConfig.Producer.class.getName()); assertNotNull(loader); Class<?> clazz = loader.loadClass(LogdConfig.Builder.class.getName()); LogdConfig.Builder builder = (LogdConfig.Builder) clazz.getDeclaredConstructor().newInstance(); producer.getConfig(builder); LogdConfig config = new LogdConfig(builder); assertThat(config.logserver().host(), is("bar")); assertThat(config.logserver().port(), is(1338)); }
@Test public void require_that_interface_is_found_if_inherited() throws ReflectiveOperationException { MockLogdProducerSubclass producer = new MockLogdProducerSubclass("mocky"); ClassLoader loader = producer.getConfigClassLoader(LogdConfig.Producer.class.getName()); assertNotNull(loader); Class<?> clazz = loader.loadClass(LogdConfig.Builder.class.getName()); LogdConfig.Builder builder = (LogdConfig.Builder) clazz.getDeclaredConstructor().newInstance(); producer.getConfig(builder); LogdConfig config = new LogdConfig(builder); assertThat(config.logserver().host(), is("foo")); assertThat(config.logserver().port(), is(1337)); }