Added ConfigurationFilter tests and fixes.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/98980d03 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/98980d03 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/98980d03 Branch: refs/heads/old_master Commit: 98980d032ae27882eb3c8d507d29ab30c33f79b3 Parents: 1aefa98 Author: anatole <anat...@apache.org> Authored: Sat Feb 13 01:21:40 2016 +0100 Committer: Oliver B. Fischer <ple...@apache.org> Committed: Fri Sep 30 21:29:37 2016 +0200 ---------------------------------------------------------------------- .../tamaya/filter/ConfigurationFilter.java | 4 +- .../tamaya/filter/ProgrammableFilter.java | 9 ++- .../org.apache.tamaya.spi.PropertyFilter | 3 +- .../tamaya/filter/ConfigurationFilterTest.java | 85 +++++++++++++++++--- 4 files changed, 85 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/98980d03/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java b/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java index b5bb45e..b33ff27 100644 --- a/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java +++ b/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java @@ -108,11 +108,11 @@ public final class ConfigurationFilter implements PropertyFilter{ @Override public String filterProperty(String valueToBeFiltered, FilterContext context) { if(!context.isSinglePropertyScoped()){ - for(PropertyFilter pred: THREADED_MAP_FILTERS.get().getFilters()){ + for(PropertyFilter pred: THREADED_SINGLE_FILTERS.get().getFilters()){ valueToBeFiltered = pred.filterProperty(valueToBeFiltered, context); } }else{ - for(PropertyFilter pred: THREADED_SINGLE_FILTERS.get().getFilters()){ + for(PropertyFilter pred: THREADED_MAP_FILTERS.get().getFilters()){ valueToBeFiltered = pred.filterProperty(valueToBeFiltered, context); } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/98980d03/src/main/java/org/apache/tamaya/filter/ProgrammableFilter.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/tamaya/filter/ProgrammableFilter.java b/src/main/java/org/apache/tamaya/filter/ProgrammableFilter.java index 18a7e08..ec6040c 100644 --- a/src/main/java/org/apache/tamaya/filter/ProgrammableFilter.java +++ b/src/main/java/org/apache/tamaya/filter/ProgrammableFilter.java @@ -61,6 +61,14 @@ public final class ProgrammableFilter implements PropertyFilter{ } /** + * Removes a filter. + * @param filter the filter to be removed, not null. + */ + public void removeFilter(PropertyFilter filter) { + filters.remove(filter); + } + + /** * Clears all filters. */ public void clearFilters(){ @@ -107,5 +115,4 @@ public final class ProgrammableFilter implements PropertyFilter{ '}'; } - } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/98980d03/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter ---------------------------------------------------------------------- diff --git a/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter b/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter index 630c222..806b833 100644 --- a/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter +++ b/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter @@ -16,5 +16,4 @@ # specific language governing permissions and limitations # under the License. # -org.apache.tamaya.filter.ConfigurationFilter -org.apache.tamaya.filter.DefaultMetadataFilter \ No newline at end of file +org.apache.tamaya.filter.ConfigurationFilter \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/98980d03/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java b/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java index bbfe72d..9d0da1f 100644 --- a/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java +++ b/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java @@ -18,6 +18,10 @@ */ package org.apache.tamaya.filter; +import org.apache.tamaya.Configuration; +import org.apache.tamaya.ConfigurationProvider; +import org.apache.tamaya.spi.FilterContext; +import org.apache.tamaya.spi.PropertyFilter; import org.junit.Test; import static org.junit.Assert.*; @@ -28,32 +32,91 @@ import static org.junit.Assert.*; public class ConfigurationFilterTest { @Test - public void testIsMetadataFiltered() throws Exception { -// TODO + public void testMetadataFiltered() throws Exception { + ConfigurationFilter.setMetadataFiltered(true); + assertTrue(ConfigurationFilter.isMetadataFiltered()); + ConfigurationFilter.setMetadataFiltered(false); + assertFalse(ConfigurationFilter.isMetadataFiltered()); } @Test - public void testSetMetadataFiltered() throws Exception { -// TODO + public void testGetSingleFilters() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + assertNotNull(ConfigurationFilter.getSingleFilters()); + PropertyFilter testFilter = new PropertyFilter() { + @Override + public String filterProperty(String value, FilterContext context) { + return context.getKey() + ":testGetSingleFilters"; + } + }; + ConfigurationFilter.getSingleFilters().addFilter(testFilter); + assertEquals("user.home:testGetSingleFilters", config.get("user.home")); + ConfigurationFilter.getSingleFilters().removeFilter(testFilter); + assertNotSame("user.home:testGetSingleFilters", config.get("user.home")); } @Test - public void testGetSingleFilters() throws Exception { -// TODO + public void testRemoveSingleFiltersAt0() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + assertNotNull(ConfigurationFilter.getSingleFilters()); + PropertyFilter testFilter = new PropertyFilter() { + @Override + public String filterProperty(String value, FilterContext context) { + return context.getKey() + ":testGetSingleFilters"; + } + }; + ConfigurationFilter.getSingleFilters().addFilter(testFilter); + assertEquals("user.home:testGetSingleFilters", config.get("user.home")); + ConfigurationFilter.getSingleFilters().removeFilter(0); + assertNotSame("user.home:testGetSingleFilters", config.get("user.home")); } @Test public void testGetMapFilters() throws Exception { -// TODO + Configuration config = ConfigurationProvider.getConfiguration(); + assertNotNull(ConfigurationFilter.getMapFilters()); + PropertyFilter testFilter = new PropertyFilter() { + @Override + public String filterProperty(String value, FilterContext context) { + return context.getKey() + ":testGetMapFilters"; + } + }; + ConfigurationFilter.getMapFilters().addFilter(testFilter); + assertEquals("user.home:testGetMapFilters", config.getProperties().get("user.home")); + ConfigurationFilter.getSingleFilters().removeFilter(testFilter); + assertNotSame("user.home:testGetSingleFilters", config.getProperties().get("user.home")); } @Test - public void testClearFilters() throws Exception { -// TODO + public void testRemoveMapFilterAt0() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + assertNotNull(ConfigurationFilter.getMapFilters()); + PropertyFilter testFilter = new PropertyFilter() { + @Override + public String filterProperty(String value, FilterContext context) { + return context.getKey() + ":testGetMapFilters"; + } + }; + ConfigurationFilter.getMapFilters().addFilter(testFilter); + assertEquals("user.home:testGetMapFilters", config.getProperties().get("user.home")); + ConfigurationFilter.getMapFilters().removeFilter(0); + assertNotSame("user.home:testGetSingleFilters", config.getProperties().get("user.home")); } @Test - public void testFilterProperty() throws Exception { -// TODO + public void testClearFilters() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + assertNotNull(ConfigurationFilter.getSingleFilters()); + PropertyFilter testFilter = new PropertyFilter() { + @Override + public String filterProperty(String value, FilterContext context) { + return context.getKey() + ":testGetSingleFilters"; + } + }; + ConfigurationFilter.getSingleFilters().addFilter(testFilter); + assertEquals("user.home:testGetSingleFilters", config.get("user.home")); + ConfigurationFilter.clearFilters(); + assertNotSame("user.home:testGetSingleFilters", config.get("user.home")); } + } \ No newline at end of file