tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ple...@apache.org
Subject [07/18] incubator-tamaya-extensions git commit: Added ConfigurationFilter tests and fixes.
Date Wed, 28 Sep 2016 22:16:07 GMT
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/f095dea8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/f095dea8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/f095dea8

Branch: refs/heads/master
Commit: f095dea81f055ea00f0cbd0de722bc22044057fa
Parents: d2e2687
Author: anatole <anatole@apache.org>
Authored: Sat Feb 13 01:21:40 2016 +0100
Committer: Oliver B. Fischer <plexus@apache.org>
Committed: Thu Sep 29 00:15:51 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/f095dea8/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/f095dea8/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/f095dea8/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/f095dea8/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


Mime
View raw message