Repository: incubator-tamaya Updated Branches: refs/heads/master b5731e091 -> 20907d77f
TAMAYA-42: Added test for filtering, including removing of entries and mapping to other entries. Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/20907d77 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/20907d77 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/20907d77 Branch: refs/heads/master Commit: 20907d77f51a1b43dc58d0ba0504dcac4a4b20d2 Parents: b5731e0 Author: anatole <anat...@apache.org> Authored: Sun Jan 4 20:55:39 2015 +0100 Committer: anatole <anat...@apache.org> Committed: Sun Jan 4 20:55:39 2015 +0100 ---------------------------------------------------------------------- .../internal/DefaultConfigurationContext.java | 1 + .../apache/tamaya/core/ConfigurationTest.java | 9 +++-- .../core/testdata/TestPropertyFilter.java | 38 ++++++++++++++++++ .../testdata/TestPropertyFilterRemoving.java | 41 ++++++++++++++++++++ .../org.apache.tamaya.spi.PropertyFilter | 20 ++++++++++ .../tamaya/resource/InputStreamSupplier.java | 37 ------------------ 6 files changed, 105 insertions(+), 41 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/20907d77/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java index 995f2dd..c225e59 100644 --- a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java +++ b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java @@ -140,6 +140,7 @@ public class DefaultConfigurationContext implements ConfigurationContext { Collections.sort(this.propertySources, this::comparePropertySources); this.propertyFilters.addAll(ServiceContext.getInstance().getServices(PropertyFilter.class)); Collections.sort(this.propertyFilters, this::comparePropertyFilters); + loaded = true; } } finally { writeLock.unlock(); http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/20907d77/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java b/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java index 9c7b894..adcaf24 100644 --- a/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java +++ b/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java @@ -23,6 +23,7 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; /** * This tests checks if the combination of 2 prioritized PropertySource return valid results on the final Configuration. @@ -38,15 +39,15 @@ public class ConfigurationTest { public void testContent(){ assertEquals("Robin", Configuration.current().get("name").get()); assertEquals("Sabine", Configuration.current().get("name2").get()); // from default - assertEquals("Lukas", Configuration.current().get("name3").get()); // oderridden default - assertEquals("Sereina", Configuration.current().get("name4").get()); // final only - assertEquals("Benjamin", Configuration.current().get("name5").get()); // final only + assertEquals("Mapped to name: Robin", Configuration.current().get("name3").get()); // oderridden default, mapped by filter to name property + assertEquals("Sereina(filtered)", Configuration.current().get("name4").get()); // final only + assertNull(Configuration.current().get("name5").orElse(null)); // final only, but removed from filter System.out.println("name : " + Configuration.current().get("name").get()); System.out.println("name2: " + Configuration.current().get("name2").get()); System.out.println("name3: " + Configuration.current().get("name3").get()); System.out.println("name4: " + Configuration.current().get("name4").get()); - System.out.println("name5: " + Configuration.current().get("name5").get()); + System.out.println("name5: " + Configuration.current().get("name5").orElse(null)); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/20907d77/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java b/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java new file mode 100644 index 0000000..4a0feaa --- /dev/null +++ b/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java @@ -0,0 +1,38 @@ +/* + * 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.core.testdata; + +import org.apache.tamaya.spi.PropertyFilter; + +import javax.annotation.Priority; +import java.util.function.Function; + +/** + * Simple PropertyFilter that filters exact one value, registered using ServiceLoader. + */ +@Priority(100) +public class TestPropertyFilter implements PropertyFilter{ + @Override + public String filterProperty(String key, String valueToBeFiltered, Function<String, String> propertyValueProvider) { + if("name4".equals(key)){ + return valueToBeFiltered + "(filtered)"; + } + return valueToBeFiltered; + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/20907d77/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java b/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java new file mode 100644 index 0000000..64edf97 --- /dev/null +++ b/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java @@ -0,0 +1,41 @@ +/* + * 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.core.testdata; + +import org.apache.tamaya.spi.PropertyFilter; + +import javax.annotation.Priority; +import java.util.function.Function; + +/** + * Simple PropertyFilter that filters exact one value, registered using ServiceLoader. + */ +@Priority(200) +public class TestPropertyFilterRemoving implements PropertyFilter{ + @Override + public String filterProperty(String key, String valueToBeFiltered, Function<String, String> propertyValueProvider) { + if("name5".equals(key)){ + return null; + } + else if("name3".equals(key)){ + return "Mapped to name: " + propertyValueProvider.apply("name"); + } + return valueToBeFiltered; + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/20907d77/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter ---------------------------------------------------------------------- diff --git a/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter b/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter new file mode 100644 index 0000000..4e7d068 --- /dev/null +++ b/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter @@ -0,0 +1,20 @@ +# +# 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 current 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. +# +org.apache.tamaya.core.testdata.TestPropertyFilter +org.apache.tamaya.core.testdata.TestPropertyFilterRemoving \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/20907d77/modules/resources/src/main/java/org/apache/tamaya/resource/InputStreamSupplier.java ---------------------------------------------------------------------- diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/InputStreamSupplier.java b/modules/resources/src/main/java/org/apache/tamaya/resource/InputStreamSupplier.java deleted file mode 100644 index e5f3d40..0000000 --- a/modules/resources/src/main/java/org/apache/tamaya/resource/InputStreamSupplier.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.resource; - -import java.io.IOException; -import java.io.InputStream; - -/** - * Simple interface for a component that provides data based on an InputStream. - */ -@FunctionalInterface -public interface InputStreamSupplier { - - /** - * Access the input stream. - * @return the input stream for use. - * @throws IOException i the input stream could not be obtained. - */ - InputStream getInputStream() throws IOException; - -}