You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2016/02/11 20:37:48 UTC

incubator-tamaya git commit: Synched.

Repository: incubator-tamaya
Updated Branches:
  refs/heads/master 0eb9b81a8 -> ff59f4a16


Synched.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/ff59f4a1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/ff59f4a1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/ff59f4a1

Branch: refs/heads/master
Commit: ff59f4a16c3cdb08d48179cef74efc23c74bb273
Parents: 0eb9b81
Author: anatole <an...@apache.org>
Authored: Thu Feb 11 20:37:31 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Thu Feb 11 20:37:31 2016 +0100

----------------------------------------------------------------------
 .../tamaya/filter/ConfigurationFilter.java      |   2 +-
 .../tamaya/filter/ConfigurationFilterTest.java  |  32 ++++-
 .../tamaya/filter/ProgrammableFilterTest.java   | 131 +++++++++++++++----
 .../tamaya/filter/RegexPropertyFilterTest.java  |  42 +++++-
 4 files changed, 173 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ff59f4a1/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java b/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java
index 30ba3e2..b5bb45e 100644
--- a/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java
+++ b/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java
@@ -31,12 +31,12 @@ import org.apache.tamaya.spi.PropertyFilter;
  *     <li><b>Map</b> filters are applied when values are filtered as part of a full properties access.
  *     Often filtering in these cases is more commonly applied, e.g. you dont want to show up all kind of metadata.
  *     </li>
+ * </ul>
  *     For both variants individual filter rules can be applied here. All filters configured are managed on a
  *     thread-local level, so this class is typically used to temporarely filter out some values. Do not forget to
  *     restore its state, when not using a thread anymore (especially important in multi-threaded environments), not
  *     doing so will create nasty side effects of configuration not being visisble depending on the thread
  *     active.
- * </ul>
  */
 public final class ConfigurationFilter implements PropertyFilter{
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ff59f4a1/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java b/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java
index b4f3fa3..bbfe72d 100644
--- a/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java
+++ b/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.tamaya.filter;
 
 import org.junit.Test;
@@ -5,37 +23,37 @@ import org.junit.Test;
 import static org.junit.Assert.*;
 
 /**
- * Created by atsticks on 11.02.16.
+ * Tests for {@link ConfigurationFilter}. Created by atsticks on 11.02.16.
  */
 public class ConfigurationFilterTest {
 
     @Test
     public void testIsMetadataFiltered() throws Exception {
-
+// TODO
     }
 
     @Test
     public void testSetMetadataFiltered() throws Exception {
-
+// TODO
     }
 
     @Test
     public void testGetSingleFilters() throws Exception {
-
+// TODO
     }
 
     @Test
     public void testGetMapFilters() throws Exception {
-
+// TODO
     }
 
     @Test
     public void testClearFilters() throws Exception {
-
+// TODO
     }
 
     @Test
     public void testFilterProperty() throws Exception {
-
+// TODO
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ff59f4a1/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java b/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
index 0a30dc4..73db677 100644
--- a/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
+++ b/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
@@ -1,56 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.tamaya.filter;
 
+import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyFilter;
 import org.junit.Test;
 
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
 import static org.junit.Assert.*;
 
 /**
- * Created by atsticks on 11.02.16.
+ * Tests for {@link ProgrammableFilter}. Created by atsticks on 11.02.16.
  */
 public class ProgrammableFilterTest {
 
     @Test
-    public void testAddFilter() throws Exception {
-
-    }
-
-    @Test
-    public void testAddFilter1() throws Exception {
-
-    }
-
-    @Test
-    public void testRemoveFilter() throws Exception {
-
+    public void testAddRemoveFilter() throws Exception {
+        ProgrammableFilter filter = new ProgrammableFilter();
+        RegexPropertyFilter regexFilter = new RegexPropertyFilter("test\\..*");
+        Map<String,String> map = new HashMap<>();
+        map.put("test1", "test1");
+        map.put("test2", "test2");
+        map.put("test.test3", "test.test3");
+        assertEquals(filter.filterProperty("test1", new FilterContext("test1", map, true)), "test1");
+        assertEquals(filter.filterProperty("test2", new FilterContext("test2", map, true)), "test2");
+        assertEquals(filter.filterProperty("test.test3", new FilterContext("test.test3", map, true)), "test.test3");
+        filter.addFilter(regexFilter);
+        assertEquals(filter.filterProperty("test1", new FilterContext("test1", map, true)), "test1");
+        assertEquals(filter.filterProperty("test2", new FilterContext("test2", map, true)), "test2");
+        assertNull(filter.filterProperty("test.test3", new FilterContext("test.test3", map, true)));
+        filter.removeFilter(0);
+        assertEquals(filter.filterProperty("test1", new FilterContext("test1", map, true)), "test1");
+        assertEquals(filter.filterProperty("test2", new FilterContext("test2", map, true)), "test2");
+        assertEquals(filter.filterProperty("test.test3", new FilterContext("test.test3", map, true)), "test.test3");
+        filter.addFilter(0, regexFilter);
+        assertEquals(filter.filterProperty("test1", new FilterContext("test1", map, true)), "test1");
+        assertEquals(filter.filterProperty("test2", new FilterContext("test2", map, true)), "test2");
+        assertNull(filter.filterProperty("test.test3", new FilterContext("test.test3", map, true)));
     }
 
     @Test
     public void testClearFilters() throws Exception {
-
+        ProgrammableFilter filter = new ProgrammableFilter();
+        RegexPropertyFilter regexFilter = new RegexPropertyFilter("test\\..*");
+        Map<String,String> map = new HashMap<>();
+        map.put("test1", "test1");
+        map.put("test2", "test2");
+        map.put("test.test3", "test.test3");
+        assertEquals(filter.filterProperty("test1", new FilterContext("test1", map, true)), "test1");
+        assertEquals(filter.filterProperty("test2", new FilterContext("test2", map, true)), "test2");
+        assertEquals(filter.filterProperty("test.test3", new FilterContext("test.test3", map, true)), "test.test3");
+        filter.addFilter(regexFilter);
+        assertEquals(filter.filterProperty("test1", new FilterContext("test1", map, true)), "test1");
+        assertEquals(filter.filterProperty("test2", new FilterContext("test2", map, true)), "test2");
+        assertNull(filter.filterProperty("test.test3", new FilterContext("test.test3", map, true)));
+        filter.clearFilters();
+        assertEquals(filter.filterProperty("test1", new FilterContext("test1", map, true)), "test1");
+        assertEquals(filter.filterProperty("test2", new FilterContext("test2", map, true)), "test2");
+        assertEquals(filter.filterProperty("test.test3", new FilterContext("test.test3", map, true)), "test.test3");
     }
 
     @Test
     public void testSetFilters() throws Exception {
-
+        ProgrammableFilter filter = new ProgrammableFilter();
+        RegexPropertyFilter regexFilter = new RegexPropertyFilter("test\\..*");
+        Map<String,String> map = new HashMap<>();
+        map.put("test1", "test1");
+        map.put("test2", "test2");
+        map.put("test.test3", "test.test3");
+        assertEquals(filter.filterProperty("test1", new FilterContext("test1", map, true)), "test1");
+        assertEquals(filter.filterProperty("test2", new FilterContext("test2", map, true)), "test2");
+        assertEquals(filter.filterProperty("test.test3", new FilterContext("test.test3", map, true)), "test.test3");
+        filter.setFilters(regexFilter);
+        assertEquals(filter.filterProperty("test1", new FilterContext("test1", map, true)), "test1");
+        assertEquals(filter.filterProperty("test2", new FilterContext("test2", map, true)), "test2");
+        assertNull(filter.filterProperty("test.test3", new FilterContext("test.test3", map, true)));
     }
 
     @Test
     public void testSetFilters1() throws Exception {
-
+        ProgrammableFilter filter = new ProgrammableFilter();
+        RegexPropertyFilter regexFilter = new RegexPropertyFilter("test\\..*");
+        Map<String,String> map = new HashMap<>();
+        map.put("test1", "test1");
+        map.put("test2", "test2");
+        map.put("test.test3", "test.test3");
+        assertEquals(filter.filterProperty("test1", new FilterContext("test1", map, true)), "test1");
+        assertEquals(filter.filterProperty("test2", new FilterContext("test2", map, true)), "test2");
+        assertEquals(filter.filterProperty("test.test3", new FilterContext("test.test3", map, true)), "test.test3");
+        filter.setFilters(Arrays.asList(new PropertyFilter[]{regexFilter}));
+        assertEquals(filter.filterProperty("test1", new FilterContext("test1", map, true)), "test1");
+        assertEquals(filter.filterProperty("test2", new FilterContext("test2", map, true)), "test2");
+        assertNull(filter.filterProperty("test.test3", new FilterContext("test.test3", map, true)));
     }
 
     @Test
     public void testGetFilters() throws Exception {
-
-    }
-
-    @Test
-    public void testFilterProperty() throws Exception {
-
+        ProgrammableFilter filter = new ProgrammableFilter();
+        assertNotNull(filter.getFilters());
+        assertTrue(filter.getFilters().isEmpty());
+        RegexPropertyFilter regexFilter = new RegexPropertyFilter("test\\..*");
+        filter.addFilter(regexFilter);
+        assertNotNull(filter.getFilters());
+        assertFalse(filter.getFilters().isEmpty());
+        assertEquals(1, filter.getFilters().size());
+        assertEquals(regexFilter, filter.getFilters().get(0));
     }
 
     @Test
     public void testToString() throws Exception {
-
+        ProgrammableFilter filter = new ProgrammableFilter();
+        assertFalse(filter.toString().contains("test\\..*"));
+        assertTrue(filter.toString().contains("ProgrammableFilter"));
+        assertFalse(filter.toString().contains("RegexPropertyFilter"));
+        RegexPropertyFilter regexFilter = new RegexPropertyFilter("test\\..*");
+        filter.addFilter(regexFilter);
+        assertTrue(filter.toString().contains("test\\..*"));
+        assertTrue(filter.toString().contains("ProgrammableFilter"));
+        assertTrue(filter.toString().contains("RegexPropertyFilter"));
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ff59f4a1/modules/filter/src/test/java/org/apache/tamaya/filter/RegexPropertyFilterTest.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/test/java/org/apache/tamaya/filter/RegexPropertyFilterTest.java b/modules/filter/src/test/java/org/apache/tamaya/filter/RegexPropertyFilterTest.java
index 7583a86..a560b04 100644
--- a/modules/filter/src/test/java/org/apache/tamaya/filter/RegexPropertyFilterTest.java
+++ b/modules/filter/src/test/java/org/apache/tamaya/filter/RegexPropertyFilterTest.java
@@ -1,19 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.tamaya.filter;
 
+import org.apache.tamaya.spi.FilterContext;
+
+import java.util.HashMap;
+import java.util.Map;
+
 import static org.junit.Assert.*;
 
 /**
- * Created by atsticks on 11.02.16.
+ * Tests for {@link RegexPropertyFilter}. Created by anatole on 11.02.16.
  */
 public class RegexPropertyFilterTest {
 
     @org.junit.Test
     public void testFilterProperty() throws Exception {
-
+        RegexPropertyFilter filter = new RegexPropertyFilter("test\\..*");
+        Map<String,String> map = new HashMap<>();
+        map.put("test1", "test1");
+        map.put("test2", "test2");
+        map.put("test.test3", "test.test3");
+        assertEquals(filter.filterProperty("test1", new FilterContext("test1", map, true)), "test1");
+        assertEquals(filter.filterProperty("test2", new FilterContext("test2", map, true)), "test2");
+        assertNull(filter.filterProperty("test.test3", new FilterContext("test.test3", map, true)));
+        filter = new RegexPropertyFilter(".*");
+        assertNull(filter.filterProperty("test1", new FilterContext("test1", map, true)));
+        assertNull(filter.filterProperty("test2", new FilterContext("test2", map, true)));
+        assertNull(filter.filterProperty("test.test3", new FilterContext("test.test3", map, true)));
     }
 
     @org.junit.Test
     public void testToString() throws Exception {
-
+        RegexPropertyFilter filter = new RegexPropertyFilter("test\\..*");
+        assertTrue(filter.toString().contains("test\\..*"));
+        assertTrue(filter.toString().contains("RegexPropertyFilter"));
     }
 }
\ No newline at end of file