ConfigCoreContext extends ConfigContext { @Override public <T> T get(Class<T> configurable) { doLookup(); Schema schema = schemaManager.getSchema(configurable); BeanId singleton = getSingletonId(schema, configurable); Optional<Bean> bean; try { if (configurable.getName().equals(RECURSION_SHORTCIRCUIT.get())) { bean = Optional.absent(); } else { RECURSION_SHORTCIRCUIT.set(configurable.getName()); bean = beanManager.getEager(singleton); } } finally { RECURSION_SHORTCIRCUIT.set(null); } if (!bean.isPresent()) { initFile(configurable); Bean fileBean = FILE_CONFIG.get(singleton); if (fileBean != null) { fileBean.set(schema); bean = Optional.of(fileBean); } if (bean.isPresent()) { T object = (T) schemaManager.convertBean(bean.get()); if (cacheManager.isPresent()) { cacheManager.get().put(bean.get()); } return object; } } if (!bean.isPresent()) { bean = Optional.of(Bean.create(BeanId.createSingleton(schema.getName()))); } schemaManager.setSchema(Arrays.asList(bean.get())); setSingletonReferences(bean.get()); T object = (T) schemaManager.convertBean(bean.get()); if (cacheManager.isPresent()) { cacheManager.get().put(bean.get()); } return object; }  @Override void register(Class<?>... configurable); @Override void unregister(Class<?>... configurable); @Override T get(Class<T> configurable); @Override List<T> list(Class<T> configurable); @Override Optional<T> get(String id, Class<T> configurable); @Override ConfigQuery<T> newQuery(Class<T> configurable); @Override void registerObserver(ConfigObserver observer); void doLookup();  }
@Test public void test_get() { admin.create(defaultBeans); Grandfather g_runtime = config.get("g1", Grandfather.class).get(); assertReflectionEquals(g1, g_runtime, ReflectionComparatorMode.LENIENT_ORDER); }
@Test public void test_get_file_fallback() throws Exception { Grandfather g10 = config.get("g10", Grandfather.class).get(); assertGrandfather10(g10); }
@Test public void test_singleton_file_fallback() throws Exception { SingletonParent singletonParent = config.get(SingletonParent.class); assertNotNull(singletonParent); assertThat(singletonParent.getProperty(), is(SINGLETON_PARENT_SCHEMA_NAME)); Singleton singleton = singletonParent.getSingleton(); assertNotNull(singleton); assertThat(singleton.getProperty(), is(SINGLETON_SCHEMA_NAME)); Parent p10 = singleton.getParent(); assertThat(p10.getProp1(), is("p10")); List<Child> children = p10.getProp7(); assertNotNull(children); assertThat(children.size(), is(1)); Child child = children.get(0); assertThat(child.getBeanId().getInstanceId(), is("c10")); assertThat(child.getProp11(), is(1.1f)); }
@Test public void test_singleton_admin_override_file_fallback() { Singleton singleton = new Singleton(); singleton.setProperty("override"); admin.createObject(singleton); singleton = config.get(Singleton.class); assertThat(singleton.getProperty(), is("override")); }
@Test public void test_admin_override_get_file_fallback() { Grandfather g10 = new Grandfather("g10"); g10.setProp1("g10"); admin.createObject(g10); Grandfather g = config.get("g10", Grandfather.class).get(); assertThat(g.getProp1(), is("g10")); }
@Test public void test_disparate_unregistered_file_fallback() { A a = config.get(A.class); assertThat(a.getName(), is("A")); B b = config.get(B.class); assertThat(b.getName(), is("B")); }