PeriodicallyRefreshingObjectConfigurationResolver implements ObjectConfigurationResolver<OBJECT, CONFIG> { @Override public CONFIG resolve(OBJECT object) { return delegate.resolve(object); } PeriodicallyRefreshingObjectConfigurationResolver(Config configuration,
                                                      Function<OBJECT, String> selectorFieldAccessor,
                                                      Function<String, CONFIG> dynamicProxyFactory,
                                                      CONFIG defaultConfig); @Override CONFIG resolve(OBJECT object);  }
@Test public void testDefaultObjectConfiguration() { assertThat(resolver.resolve(new MyObject("a")).getLimit()).isEqualTo(100); }
@Test public void testDefaultOverrides() { update("default.limit", "200"); assertThat(resolver.resolve(new MyObject("a")).getLimit()).isEqualTo(200); }
@Test public void testObjectOverrides() { update("object.a.pattern", "a", "object.a.limit", "200", "object.b.pattern", "b", "object.b.limit", "300" ); assertThat(resolver.resolve(new MyObject("a")).getLimit()).isEqualTo(200); assertThat(resolver.resolve(new MyObject("b")).getLimit()).isEqualTo(300); assertThat(resolver.resolve(new MyObject("x")).getLimit()).isEqualTo(100); }
@Test public void testDynamicUpdates() { update("object.a.pattern", "a", "object.a.limit", "200" ); assertThat(resolver.resolve(new MyObject("a")).getLimit()).isEqualTo(200); update("object.a.limit", "300"); assertThat(resolver.resolve(new MyObject("a")).getLimit()).isEqualTo(300); update("object.a.pattern", "not_a_anymore"); assertThat(resolver.resolve(new MyObject("a")).getLimit()).isEqualTo(100); }
@Test public void testBadPattern() { update("object.a.pattern", "a", "object.a.limit", "200" ); assertThat(resolver.resolve(new MyObject("a")).getLimit()).isEqualTo(200); update("object.a.pattern", "*"); assertThat(resolver.resolve(new MyObject("a")).getLimit()).isEqualTo(200); }