Synched.
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/1aefa98c Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/1aefa98c Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/1aefa98c Branch: refs/heads/old_master Commit: 1aefa98c68e1d3fc1d788397c0d163facf451980 Parents: b16020f Author: anatole <anat...@apache.org> Authored: Thu Feb 11 20:37:31 2016 +0100 Committer: Oliver B. Fischer <ple...@apache.org> Committed: Fri Sep 30 21:29:37 2016 +0200 ---------------------------------------------------------------------- .../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-extensions/blob/1aefa98c/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 30ba3e2..b5bb45e 100644 --- a/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java +++ b/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-extensions/blob/1aefa98c/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 b4f3fa3..bbfe72d 100644 --- a/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java +++ b/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-extensions/blob/1aefa98c/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java b/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java index 0a30dc4..73db677 100644 --- a/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java +++ b/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-extensions/blob/1aefa98c/src/test/java/org/apache/tamaya/filter/RegexPropertyFilterTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/tamaya/filter/RegexPropertyFilterTest.java b/src/test/java/org/apache/tamaya/filter/RegexPropertyFilterTest.java index 7583a86..a560b04 100644 --- a/src/test/java/org/apache/tamaya/filter/RegexPropertyFilterTest.java +++ b/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