Repository: incubator-tamaya Updated Branches: refs/heads/master 30021afe2 -> f3c2ed3be
TAMAYA-60 Started to add a feature which allows to enable or disable loading of PropertyConverter service providers. Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/f3c2ed3b Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/f3c2ed3b Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/f3c2ed3b Branch: refs/heads/master Commit: f3c2ed3be15af5d9071fde4200855c4c04565617 Parents: 30021af Author: Oliver B. Fischer <[email protected]> Authored: Fri Feb 6 18:31:21 2015 +0100 Committer: Oliver B. Fischer <[email protected]> Committed: Fri Feb 6 18:31:21 2015 +0100 ---------------------------------------------------------------------- .../tamaya/builder/ConfigurationBuilder.java | 49 +++++++++++ .../ProgrammaticConfigurationContext.java | 2 + .../builder/ConfigurationBuilderTest.java | 86 +++++++++++++++++++- 3 files changed, 135 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f3c2ed3b/modules/builder/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java ---------------------------------------------------------------------- diff --git a/modules/builder/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java b/modules/builder/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java index aa9c766..e327672 100644 --- a/modules/builder/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java +++ b/modules/builder/src/main/java/org/apache/tamaya/builder/ConfigurationBuilder.java @@ -30,6 +30,18 @@ import org.apache.tamaya.spi.PropertyValueCombinationPolicy; import java.util.Objects; +/* TODO LIST FOR TAMAYA-60 + * + * - configurable loading of provided PropertyConverter + * - configurable loading of provided PropertySources + * - configurable loading of provided PropertySourceProviders + * - adding sources via URL + * + * + * + * + */ + /** * Builder that allows to build a Configuration completely manually. */ @@ -43,6 +55,12 @@ public class ConfigurationBuilder { */ private boolean built; + /** + * Flag if all existing property converter service providers + * should be loaded if the configuration is build. + */ + private boolean loadProvidedPropertyConverters; + /** * Allows to set configuration context during unit tests. @@ -95,6 +113,37 @@ public class ConfigurationBuilder { return this; } + + public boolean isPropertyConverterLoadingEnabled() { + return loadProvidedPropertyConverters; + } + + /** + * Enables the loading of all {@link org.apache.tamaya.PropertyConverter} + * service providers. + * + * @see org.apache.tamaya.PropertyConverter + * @see #disableProvidedPropertyConverters() + */ + public ConfigurationBuilder enableProvidedPropertyConverters() { + loadProvidedPropertyConverters = true; + + return this; + } + + /** + * Disables the loading of all {@link org.apache.tamaya.PropertyConverter} + * service providers. + * + * @see org.apache.tamaya.PropertyConverter + * @see #enableProvidedPropertyConverters() + */ + public ConfigurationBuilder disableProvidedPropertyConverters() { + loadProvidedPropertyConverters = false; + + return this; + } + //X TODO think on a functonality/API for using the default PropertyConverters and use the configured ones here //X TODO as overrides used first. http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f3c2ed3b/modules/builder/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java ---------------------------------------------------------------------- diff --git a/modules/builder/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java b/modules/builder/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java index 31850c4..c8e0875 100644 --- a/modules/builder/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java +++ b/modules/builder/src/main/java/org/apache/tamaya/builder/ProgrammaticConfigurationContext.java @@ -310,4 +310,6 @@ class ProgrammaticConfigurationContext implements ConfigurationContext { } + + } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/f3c2ed3b/modules/builder/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java ---------------------------------------------------------------------- diff --git a/modules/builder/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java b/modules/builder/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java index b504f4e..a833217 100644 --- a/modules/builder/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java +++ b/modules/builder/src/test/java/org/apache/tamaya/builder/ConfigurationBuilderTest.java @@ -27,13 +27,18 @@ import org.apache.tamaya.builder.util.types.CustomTypeA; import org.apache.tamaya.builder.util.types.CustomTypeB; import org.apache.tamaya.spi.PropertySource; import org.hamcrest.CoreMatchers; +import org.hamcrest.Matchers; +import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; import static org.apache.tamaya.builder.util.mockito.NotMockedAnswer.NOT_MOCKED_ANSWER; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -56,6 +61,10 @@ public class ConfigurationBuilderTest { builder.build(); } + /********************************************************************* + * Tests for adding P r o p e r t y S o u r c e s + */ + @Test(expected = NullPointerException.class) public void addPropertySourcesDoesNotAcceptNullValue() { ConfigurationBuilder builder = new ConfigurationBuilder(); @@ -180,8 +189,7 @@ public class ConfigurationBuilderTest { doReturn("a").when(sourceTwo).get("keyOfA"); doReturn(20).when(sourceTwo).getOrdinal(); - ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne) - .addPropertySources(sourceTwo); + ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne, sourceTwo); Configuration config = builder.build(); @@ -191,6 +199,35 @@ public class ConfigurationBuilderTest { assertThat(valueOfA, equalTo("b")); } + @Test + public void consecutiveCallsToAddPropertySourceArePossible() { + PropertySource sourceOne = mock(PropertySource.class, NOT_MOCKED_ANSWER); + + doReturn("one").when(sourceOne).getName(); + doReturn(null).when(sourceOne).get(anyString()); + doReturn("b").when(sourceOne).get("b"); + doReturn(30).when(sourceOne).getOrdinal(); + + PropertySource sourceTwo = mock(PropertySource.class, NOT_MOCKED_ANSWER); + doReturn("two").when(sourceTwo).getName(); + doReturn(null).when(sourceTwo).get(anyString()); + doReturn("a").when(sourceTwo).get("a"); + doReturn(30).when(sourceTwo).getOrdinal(); + + ConfigurationBuilder builder = new ConfigurationBuilder().addPropertySources(sourceOne) + .addPropertySources(sourceTwo); + + Configuration config = builder.build(); + + assertThat(config.get("b"), equalTo("b")); + assertThat(config.get("a"), equalTo("a")); + } + + /** + * ****************************************************************** + * Tests for adding P r o p e r t y C o n v e r t e r + */ + @Test(expected = NullPointerException.class) public void canNotAddNullPropertyConverter() { ConfigurationBuilder builder = new ConfigurationBuilder(); @@ -275,4 +312,49 @@ public class ConfigurationBuilderTest { assertThat(result.getName(), equalTo("A")); } + + /********************************************************************* + * Tests for adding P r o p e r t y F i l t e r + */ + + // @todo TAYAMA-60 Write more tests + + /********************************************************************* + * Tests for adding P r o p e r t + */ + + // @todo TAYAMA-60 Write more tests + + /********************************************************************* + * Tests for adding + * P r o p e r t y V a l u e C o m b i n a t i o n P o l i c y + */ + + // @todo TAYAMA-60 Write more tests + + /********************************************************************* + * Tests for enabling and disabling of automatic loading of + * P r o p e r t y S o u r c e s + */ + + @Test + public void enablingOfProvidedPropertySourceServiceProvidersIsOk() { + ConfigurationBuilder builder = new ConfigurationBuilder(); + + builder.disableProvidedPropertyConverters() + .enableProvidedPropertyConverters(); + + assertThat(builder.isPropertyConverterLoadingEnabled(), is(true)); + } + + @Test + public void disablingOfProvidedPropertySourceServiceProvidersIsOk() { + ConfigurationBuilder builder = new ConfigurationBuilder(); + + builder.enableProvidedPropertyConverters() + .disableProvidedPropertyConverters(); + + assertThat(builder.isPropertyConverterLoadingEnabled(), is(false)); + } + }
