Repository: incubator-tamaya Updated Branches: refs/heads/configjsr 9bc56a38b -> d0e14ed70
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d0e14ed7/code/core/src/test/java/org/apache/tamaya/core/ConfigContextBuilderTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/ConfigContextBuilderTest.java b/code/core/src/test/java/org/apache/tamaya/core/ConfigContextBuilderTest.java new file mode 100644 index 0000000..11ee957 --- /dev/null +++ b/code/core/src/test/java/org/apache/tamaya/core/ConfigContextBuilderTest.java @@ -0,0 +1,424 @@ +///* +// * 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; +// +//import org.apache.tamaya.TypeLiteral; +//import org.apache.tamaya.spi.*; +//import org.apache.tamaya.spi.Filter; +//import org.junit.Test; +// +//import javax.config.ConfigProvider; +//import javax.config.spi.ConfigSource; +//import javax.config.spi.Converter; +//import java.util.Arrays; +//import java.util.Comparator; +// +//import static org.junit.Assert.*; +// +///** +// * Tests for {@link ConfigContextBuilder} by atsticks on 06.09.16. +// */ +//public class ConfigContextBuilderTest { +// +// private TestConfigSource TestConfigSource = new TestConfigSource(){}; +// +// @Test +// public void setContext() throws Exception { +// ConfigContext context = ConfigContext.of(ConfigProvider.getConfig()); +// ConfigContextBuilder b = new ConfigContextBuilder() +// .withContext(context); +// assertEquals(context, b.build()); +// } +// +// @Test +// public void withSources_Array() throws Exception { +// ConfigSource testPS2 = new TestConfigSource("withSources_Array", 1); +// ConfigContextBuilder b = new ConfigContextBuilder() +// .withSources(TestConfigSource, testPS2); +// ConfigContext ctx = b.build(); +// assertEquals(2, ctx.getSources().size()); +// assertTrue(ctx.getSources().contains(TestConfigSource)); +// assertTrue(ctx.getSources().contains(testPS2)); +// // Ensure no sorting happens during add, so switch ordinals! +// testPS2 = new TestConfigSource("withSources_Array", 1); +// b = new ConfigContextBuilder() +// .withSources(testPS2, TestConfigSource); +// ctx = b.build(); +// assertEquals(2, ctx.getSources().size()); +// assertTrue(ctx.getSources().contains(TestConfigSource)); +// assertTrue(ctx.getSources().contains(testPS2)); +// assertEquals(ctx.getSources().get(1).getName(), "TestConfigSource"); +// assertEquals(ctx.getSources().get(0).getName(), "withSources_Array"); +// } +// +// @Test +// public void withSources_Collection() throws Exception { +// ConfigSource testPS2 = new TestConfigSource("withSources_Collection", 1); +// ConfigContextBuilder b = new ConfigContextBuilder() +// .withSources(Arrays.asList(new ConfigSource[]{TestConfigSource, testPS2})); +// ConfigContext ctx = b.build(); +// assertEquals(2, ctx.getSources().size()); +// assertTrue(ctx.getSources().contains(TestConfigSource)); +// assertTrue(ctx.getSources().contains(testPS2)); +// assertEquals(ctx.getSources().get(0).getName(), "TestConfigSource"); +// assertEquals(ctx.getSources().get(1).getName(), "withSources_Collection"); +// // Ensure no sorting happens during add, so switch ordinals! +// testPS2 = new TestConfigSource("withSources_Collection", 1); +// b = new ConfigContextBuilder() +// .withSources(Arrays.asList(new ConfigSource[]{testPS2, TestConfigSource})); +// ctx = b.build(); +// assertEquals(2, ctx.getSources().size()); +// assertTrue(ctx.getSources().contains(TestConfigSource)); +// assertTrue(ctx.getSources().contains(testPS2)); +// assertEquals(ctx.getSources().get(1).getName(), "TestConfigSource"); +// assertEquals(ctx.getSources().get(0).getName(), "withSources_Collection"); +// } +// +// @Test +// public void removeConfigSources_Array() throws Exception { +// ConfigSource testPS2 = new TestConfigSource("removeConfigSources_Array", 1); +// ConfigContextBuilder b = new ConfigContextBuilder() +// .withSources(TestConfigSource, testPS2); +// ConfigContext ctx = b.build(); +// assertEquals(2, ctx.getSources().size()); +// assertTrue(ctx.getSources().contains(TestConfigSource)); +// assertTrue(ctx.getSources().contains(testPS2)); +// b = new ConfigContextBuilder() +// .withSources(TestConfigSource, testPS2); +// b.removeSources(TestConfigSource); +// ctx = b.build(); +// assertFalse(ctx.getSources().contains(TestConfigSource)); +// assertTrue(ctx.getSources().contains(testPS2)); +// assertEquals(1, ctx.getSources().size()); +// } +// +// @Test +// public void removeConfigSources_Collection() throws Exception { +// ConfigSource testPS2 = new TestConfigSource("removeConfigSources_Array", 1); +// ConfigContextBuilder b = new ConfigContextBuilder() +// .withSources(TestConfigSource, testPS2); +// ConfigContext ctx = b.build(); +// assertEquals(2, ctx.getSources().size()); +// assertTrue(ctx.getSources().contains(TestConfigSource)); +// assertTrue(ctx.getSources().contains(testPS2)); +// b = new ConfigContextBuilder() +// .withSources(TestConfigSource, testPS2); +// b.removeSources(TestConfigSource); +// ctx = b.build(); +// assertEquals(1, ctx.getSources().size()); +// assertFalse(ctx.getSources().contains(TestConfigSource)); +// assertTrue(ctx.getSources().contains(testPS2)); +// } +// +// @Test +// public void addPropertyFilters_Array() throws Exception { +// Filter filter1 = (value) -> value; +// Filter filter2 = (value) -> value; +// ConfigContextBuilder b = new ConfigContextBuilder(); +// b.withFilters(filter1, filter2); +// ConfigContext ctx = b.build(); +// assertTrue(ctx.getPropertyFilters().contains(filter1)); +// assertTrue(ctx.getPropertyFilters().contains(filter2)); +// assertEquals(2, ctx.getPropertyFilters().size()); +// b = new ConfigContextBuilder(); +// b.withFilters(filter1, filter2); +// b.withFilters(filter1, filter2); +// assertEquals(2, ctx.getPropertyFilters().size()); +// } +// +// @Test +// public void addPropertyFilters_Collection() throws Exception { +// Filter filter1 = (value) -> value; +// Filter filter2 = (value) -> value; +// ConfigContextBuilder b = new ConfigContextBuilder(); +// b.withFilters(Arrays.asList(new Filter[]{filter1, filter2})); +// ConfigContext ctx = b.build(); +// assertTrue(ctx.getPropertyFilters().contains(filter1)); +// assertTrue(ctx.getPropertyFilters().contains(filter2)); +// assertEquals(2, ctx.getPropertyFilters().size()); +// b = new ConfigContextBuilder(); +// b.withFilters(filter1, filter2); +// b.withFilters(filter1, filter2); +// assertEquals(2, ctx.getPropertyFilters().size()); +// } +// +// @Test +// public void removePropertyFilters_Array() throws Exception { +// Filter filter1 = (value) -> value; +// Filter filter2 = (value) -> value; +// ConfigContextBuilder b = new ConfigContextBuilder() +// .withFilters(filter1, filter2); +// ConfigContext ctx = b.build(); +// assertTrue(ctx.getPropertyFilters().contains(filter1)); +// assertTrue(ctx.getPropertyFilters().contains(filter2)); +// assertEquals(2, ctx.getPropertyFilters().size()); +// b = new ConfigContextBuilder() +// .withFilters(filter1, filter2); +// b.removeFilters(filter1); +// ctx = b.build(); +// assertEquals(1, ctx.getPropertyFilters().size()); +// assertFalse(ctx.getPropertyFilters().contains(filter1)); +// assertTrue(ctx.getPropertyFilters().contains(filter2)); +// } +// +// @Test +// public void removePropertyFilters_Collection() throws Exception { +// Filter filter1 = (value) -> value; +// Filter filter2 = (value) -> value; +// ConfigContextBuilder b = new ConfigContextBuilder() +// .withFilters(Arrays.asList(new Filter[]{filter1, filter2})); +// ConfigContext ctx = b.build(); +// assertTrue(ctx.getPropertyFilters().contains(filter1)); +// assertTrue(ctx.getPropertyFilters().contains(filter2)); +// assertEquals(2, ctx.getPropertyFilters().size()); +// b = new ConfigContextBuilder() +// .withFilters(Arrays.asList(new Filter[]{filter1, filter2})); +// b.removeFilters(filter1); +// ctx = b.build(); +// assertEquals(1, ctx.getPropertyFilters().size()); +// assertFalse(ctx.getPropertyFilters().contains(filter1)); +// assertTrue(ctx.getPropertyFilters().contains(filter2)); +// } +// +// @Test +// @SuppressWarnings({ "rawtypes", "unchecked" }) +// public void addConverters_Array() throws Exception { +// Converter converter = (value) -> value.toLowerCase(); +// ConfigContextBuilder b = new ConfigContextBuilder() +// .withConverters(TypeLiteral.of(String.class), converter); +// ConfigContext ctx = b.build(); +// assertTrue(ctx.getConverters(TypeLiteral.of(String.class)).contains(converter)); +// assertEquals(1, ctx.getConverters().size()); +// b = new ConfigContextBuilder() +// .withConverters(TypeLiteral.of(String.class), converter); +// b.withConverters(TypeLiteral.of(String.class), converter); +// assertEquals(1, ctx.getConverters().size()); +// } +// +// @Test +// @SuppressWarnings({ "rawtypes", "unchecked" }) +// public void addConverters_Collection() throws Exception { +// Converter converter = (value) -> value.toLowerCase(); +// ConfigContextBuilder b = new ConfigContextBuilder() +// .withConverters(TypeLiteral.of(String.class), +// Arrays.<Converter<Object>>asList(new Converter[]{converter})); +// ConfigContext ctx = b.build(); +// assertTrue(ctx.getConverters(TypeLiteral.of(String.class)).contains(converter)); +// assertEquals(ctx.getConverters().size(), 1); +// b = new ConfigContextBuilder() +// .withConverters(TypeLiteral.of(String.class), +// Arrays.<Converter<Object>>asList(new Converter[]{converter})); +// b.withConverters(TypeLiteral.of(String.class), converter); +// assertEquals(ctx.getConverters().size(), 1); +// } +// +// @Test +// @SuppressWarnings({ "rawtypes", "unchecked" }) +// public void removeConverters_Array() throws Exception { +// Converter converter = (value) -> value.toLowerCase(); +// ConfigContextBuilder b = new ConfigContextBuilder() +// .withConverters(TypeLiteral.of(String.class), converter); +// ConfigContext ctx = b.build(); +// assertTrue(ctx.getConverters(TypeLiteral.of(String.class)).contains(converter)); +// assertEquals(1, ctx.getConverters(TypeLiteral.of(String.class)).size()); +// b = new ConfigContextBuilder() +// .withConverters(TypeLiteral.of(String.class), converter); +// b.removeConverters(TypeLiteral.of(String.class), converter); +// ctx = b.build(); +// assertFalse(ctx.getConverters(TypeLiteral.of(String.class)).contains(converter)); +// assertTrue(ctx.getConverters(TypeLiteral.of(String.class)).isEmpty()); +// } +// +// @SuppressWarnings({ "rawtypes", "unchecked" }) +// @Test +// public void removeConverters_Collection() throws Exception { +// Converter converter = (value) -> value.toLowerCase(); +// ConfigContextBuilder b = new ConfigContextBuilder() +// .withConverters(TypeLiteral.of(String.class), Arrays.<Converter<Object>>asList(new Converter[]{converter})); +// ConfigContext ctx = b.build(); +// assertTrue(ctx.getConverters(TypeLiteral.of(String.class)).contains(converter)); +// assertEquals(1, ctx.getConverters(TypeLiteral.of(String.class)).size()); +// b = new ConfigContextBuilder() +// .withConverters(TypeLiteral.of(String.class), Arrays.<Converter<Object>>asList(new Converter[]{converter})); +// b.removeConverters(TypeLiteral.of(String.class), Arrays.<Converter<Object>>asList(new Converter[]{converter})); +// ctx = b.build(); +// assertFalse(ctx.getConverters(TypeLiteral.of(String.class)).contains(converter)); +// assertTrue(ctx.getConverters(TypeLiteral.of(String.class)).isEmpty()); +// } +// +// @Test +// public void setPropertyValueCombinationPolicy() throws Exception { +// ConfigValueCombinationPolicy combPol = (currentValue, key, ConfigSource) -> currentValue; +// ConfigContextBuilder b = new ConfigContextBuilder() +// .withPropertyValueCombinationPolicy(combPol); +// ConfigContext ctx = b.build(); +// assertEquals(ctx.getConfigValueCombinationPolicy(), combPol); +// } +// +// @Test +// public void increasePriority(){ +// ConfigContextBuilder b = new ConfigContextBuilder(); +// TestConfigSource[] ConfigSources = new TestConfigSource[10]; +// for(int i=0;i<ConfigSources.length;i++){ +// ConfigSources[i] = new TestConfigSource("ps"+i,i); +// } +// b.withSources(ConfigSources); +// b.increasePriority(ConfigSources[ConfigSources.length-1]); +// for(int i=0;i<ConfigSources.length;i++){ +// assertEquals(ConfigSources[i], b.getSources().get(i)); +// } +// b.increasePriority(ConfigSources[ConfigSources.length-2]); +// for(int i=0;i<ConfigSources.length-2;i++){ +// assertEquals(ConfigSources[i], b.getSources().get(i)); +// } +// assertEquals(ConfigSources[ConfigSources.length-1], b.getSources().get(ConfigSources.length-2)); +// assertEquals(ConfigSources[ConfigSources.length-2], b.getSources().get(ConfigSources.length-1)); +// } +// +// @Test +// public void decreasePriority(){ +// ConfigContextBuilder b = new ConfigContextBuilder(); +// TestConfigSource[] ConfigSources = new TestConfigSource[10]; +// for(int i=0;i<ConfigSources.length;i++){ +// ConfigSources[i] = new TestConfigSource("ps"+i,i); +// } +// b.withSources(ConfigSources); +// b.decreasePriority(ConfigSources[0]); +// for(int i=0;i<ConfigSources.length;i++){ +// assertEquals(ConfigSources[i], b.getSources().get(i)); +// } +// b.decreasePriority(ConfigSources[1]); +// for(int i=2;i<ConfigSources.length;i++){ +// assertEquals(ConfigSources[i], b.getSources().get(i)); +// } +// assertEquals(ConfigSources[0], b.getSources().get(1)); +// assertEquals(ConfigSources[1], b.getSources().get(0)); +// } +// +// @Test +// public void lowestPriority(){ +// // setup +// ConfigContextBuilder b = new ConfigContextBuilder(); +// TestConfigSource[] ConfigSources = new TestConfigSource[10]; +// for(int i=0;i<ConfigSources.length;i++){ +// ConfigSources[i] = new TestConfigSource("ps"+i,i); +// } +// b.withSources(ConfigSources); +// // test +// b.lowestPriority(ConfigSources[0]); +// for(int i=0;i<ConfigSources.length;i++){ +// assertEquals(ConfigSources[i], b.getSources().get(i)); +// } +// b.lowestPriority(ConfigSources[1]); +// for(int i=2;i<ConfigSources.length;i++){ +// assertEquals(ConfigSources[i], b.getSources().get(i)); +// } +// assertEquals(ConfigSources[0], b.getSources().get(1)); +// assertEquals(ConfigSources[1], b.getSources().get(0)); +// b.lowestPriority(ConfigSources[5]); +// assertEquals(ConfigSources[5], b.getSources().get(0)); +// } +// +// @Test +// public void highestPriority(){ +// // setup +// ConfigContextBuilder b = new ConfigContextBuilder(); +// TestConfigSource[] ConfigSources = new TestConfigSource[10]; +// for(int i=0;i<ConfigSources.length;i++){ +// ConfigSources[i] = new TestConfigSource("ps"+i,i); +// } +// b.withSources(ConfigSources); +// // test +// b.highestPriority(ConfigSources[ConfigSources.length-1]); +// for(int i=0;i<ConfigSources.length;i++){ +// assertEquals(ConfigSources[i], b.getSources().get(i)); +// } +// b.highestPriority(ConfigSources[ConfigSources.length-2]); +// for(int i=0;i<ConfigSources.length-2;i++){ +// assertEquals(ConfigSources[i], b.getSources().get(i)); +// } +// assertEquals(ConfigSources[ConfigSources.length-2], b.getSources().get(ConfigSources.length-1)); +// assertEquals(ConfigSources[ConfigSources.length-1], b.getSources().get(ConfigSources.length-2)); +// b.highestPriority(ConfigSources[5]); +// assertEquals(ConfigSources[5], b.getSources().get(ConfigSources.length-1)); +// } +// +// @Test +// public void sortConfigSources(){ +// // setup +// ConfigContextBuilder b = new ConfigContextBuilder(); +// TestConfigSource[] ConfigSources = new TestConfigSource[10]; +// for(int i=0;i<ConfigSources.length;i++){ +// ConfigSources[i] = new TestConfigSource("ps"+i,i); +// } +// b.withSources(ConfigSources); +// Comparator<ConfigSource> psComp = (o1, o2) -> o1.toString().compareTo(o2.toString()); +// // test +// b.sortSources(psComp); +// Arrays.sort(ConfigSources, psComp); +// for(int i=0;i<ConfigSources.length;i++){ +// assertEquals(ConfigSources[i], b.getSources().get(i)); +// } +// } +// +// @Test +// public void sortPropertyFilter(){ +// // setup +// ConfigContextBuilder b = new ConfigContextBuilder(); +// Filter[] filters = new Filter[10]; +// for(int i = 0; i< filters.length; i++){ +// filters[i] = (value) -> value.toBuilder().setValue(toString() + " - ").build(); +// } +// b.withFilters(filters); +// Comparator<Filter> pfComp = (o1, o2) -> o1.toString().compareTo(o2.toString()); +// // test +// b.sortFilter(pfComp); +// Arrays.sort(filters, pfComp); +// for(int i = 0; i< filters.length; i++){ +// assertEquals(filters[i], b.getFilters().get(i)); +// } +// } +// +// @Test +// public void build() throws Exception { +// ConfigContextBuilder b = new ConfigContextBuilder(); +// ConfigContext ctx = b.build(); +// assertNotNull(ctx); +// assertTrue(ctx.getSources().isEmpty()); +// assertTrue(ctx.getPropertyFilters().isEmpty()); +// } +// +// @Test +// public void testRemoveAllFilters() throws Exception { +// ConfigContextBuilder b = new ConfigContextBuilder(); +// b.withFilters((value) -> value.toBuilder().setValue(toString() + " - ").build()); +// assertFalse(b.getFilters().isEmpty()); +// b.removeFilters(b.getFilters()); +// assertTrue(b.getFilters().isEmpty()); +// } +// +// @Test +// public void testRemoveAllSources() throws Exception { +// ConfigContextBuilder b = new ConfigContextBuilder(); +// b.withSources(new TestConfigSource()); +// assertFalse(b.getSources().isEmpty()); +// b.removeSources(b.getSources()); +// assertTrue(b.getFilters().isEmpty()); +// } +//} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d0e14ed7/code/core/src/test/java/org/apache/tamaya/core/ExtConfigBuilderTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/ExtConfigBuilderTest.java b/code/core/src/test/java/org/apache/tamaya/core/ExtConfigBuilderTest.java new file mode 100644 index 0000000..178d6a6 --- /dev/null +++ b/code/core/src/test/java/org/apache/tamaya/core/ExtConfigBuilderTest.java @@ -0,0 +1,447 @@ +///* +// * 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; +// +//import org.apache.tamaya.TypeLiteral; +//import org.apache.tamaya.spi.*; +//import org.apache.tamaya.spi.Filter; +//import org.junit.Test; +// +//import javax.config.Config; +//import javax.config.ConfigProvider; +//import javax.config.spi.ConfigBuilder; +//import javax.config.spi.ConfigProviderResolver; +//import javax.config.spi.ConfigSource; +//import javax.config.spi.Converter; +//import java.util.Arrays; +//import java.util.Comparator; +// +//import static org.junit.Assert.*; +// +///** +// * Tests for {@link ConfigBuilder} by atsticks on 06.09.16. +// */ +//public class ExtConfigBuilderTest { +// +// private TestConfigSource testConfigSource = new TestConfigSource(){}; +// +// @Test +// public void fromConfig() throws Exception { +// Config cfg = ConfigProvider.getConfig(); +// ConfigBuilder b = ExtConfigBuilder.create(cfg); +// assertEquals(cfg, b.build()); +// } +// +// @Test +// public void fromConfigBuilder() throws Exception { +// ConfigBuilder b = ExtConfigBuilder.from(ConfigProviderResolver.instance().getBuilder()); +// assertNotNull(b); +// } +// +// @Test +// public void addConfigSources_Array() throws Exception { +// ConfigSource testPS2 = new TestConfigSource("addConfigSources_Array", 1); +// ExtConfigBuilder b = ExtConfigBuilder.create() +// .withSources(testConfigSource, testPS2); +// Config cfg = b.build(); +// assertEquals(2, ConfigContext.of(cfg).getSources().size()); +// assertTrue(ConfigContext.of(cfg).getSources().contains(testConfigSource)); +// assertTrue(ConfigContext.of(cfg).getSources().contains(testPS2)); +// // Ensure no sorting happens during add, so switch ordinals! +// testPS2 = new TestConfigSource("addConfigSources_Array", 1); +// b = ExtConfigBuilder.create() +// .withSources(testPS2, testConfigSource); +// cfg = b.build(); +// assertEquals(2, ConfigContext.of(cfg).getSources().size()); +// assertTrue(ConfigContext.of(cfg).getSources().contains(testConfigSource)); +// assertTrue(ConfigContext.of(cfg).getSources().contains(testPS2)); +// assertEquals(ConfigContext.of(cfg).getSources().get(1).getName(), "TestConfigSource"); +// assertEquals(ConfigContext.of(cfg).getSources().get(0).getName(), "addConfigSources_Array"); +// } +// +// @Test +// public void addConfigSources_Collection() throws Exception { +// ConfigSource testPS2 = new TestConfigSource("addConfigSources_Collection", 1); +// ExtConfigBuilder b = ExtConfigBuilder.create() +// .withSources(Arrays.asList(new ConfigSource[]{testConfigSource, testPS2})); +// Config cfg = b.build(); +// assertEquals(2, ConfigContext.of(cfg).getSources().size()); +// assertTrue(ConfigContext.of(cfg).getSources().contains(testConfigSource)); +// assertTrue(ConfigContext.of(cfg).getSources().contains(testPS2)); +// assertEquals(ConfigContext.of(cfg).getSources().get(0).getName(), "TestConfigSource"); +// assertEquals(ConfigContext.of(cfg).getSources().get(1).getName(), "addConfigSources_Collection"); +// // Ensure no sorting happens during add, so switch ordinals! +// testPS2 = new TestConfigSource("addConfigSources_Collection", 1); +// b = ExtConfigBuilder.create() +// .withSources(testPS2, testConfigSource); +// cfg = b.build(); +// assertEquals(2, ConfigContext.of(cfg).getSources().size()); +// assertTrue(ConfigContext.of(cfg).getSources().contains(testConfigSource)); +// assertTrue(ConfigContext.of(cfg).getSources().contains(testPS2)); +// assertEquals(ConfigContext.of(cfg).getSources().get(1).getName(), "TestConfigSource"); +// assertEquals(ConfigContext.of(cfg).getSources().get(0).getName(), "addConfigSources_Collection"); +// } +// +// @Test +// public void removeConfigSources_Array() throws Exception { +// ConfigSource testPS2 = new TestConfigSource("removeConfigSources_Array", 1); +// ExtConfigBuilder b = ExtConfigBuilder.create() +// .withSources(testConfigSource, testPS2); +// Config cfg = b.build(); +// assertEquals(2, ConfigContext.of(cfg).getSources().size()); +// assertTrue(ConfigContext.of(cfg).getSources().contains(testConfigSource)); +// assertTrue(ConfigContext.of(cfg).getSources().contains(testPS2)); +// b = ExtConfigBuilder.from(ConfigProviderResolver.instance().getBuilder() +// .withSources(testConfigSource, testPS2)); +// b.removeSources(testConfigSource); +// cfg = b.build(); +// assertFalse(ConfigContext.of(cfg).getSources().contains(testConfigSource)); +// assertTrue(ConfigContext.of(cfg).getSources().contains(testPS2)); +// assertEquals(1, ConfigContext.of(cfg).getSources().size()); +// } +// +// @Test +// public void removeConfigSources_Collection() throws Exception { +// ConfigSource testPS2 = new TestConfigSource("removeConfigSources_Array", 1); +// ExtConfigBuilder b = ExtConfigBuilder.create() +// .withSources(testConfigSource, testPS2); +// Config cfg = b.build(); +// assertEquals(2, ConfigContext.of(cfg).getSources().size()); +// assertTrue(ConfigContext.of(cfg).getSources().contains(testConfigSource)); +// assertTrue(ConfigContext.of(cfg).getSources().contains(testPS2)); +// b = ExtConfigBuilder.from(ConfigProviderResolver.instance().getBuilder()) +// .withSources(testConfigSource, testPS2); +// b.removeSources(testConfigSource); +// cfg = b.build(); +// assertEquals(1, ConfigContext.of(cfg).getSources().size()); +// assertFalse(ConfigContext.of(cfg).getSources().contains(testConfigSource)); +// assertTrue(ConfigContext.of(cfg).getSources().contains(testPS2)); +// } +// +// @Test +// public void addPropertyFilters_Array() throws Exception { +// Filter filter1 = (value) -> value; +// Filter filter2 = (value) -> value; +// ExtConfigBuilder b = ExtConfigBuilder.create(); +// b.withFilters(filter1, filter2); +// Config cfg = b.build(); +// ConfigContext ctx = ConfigContext.of(cfg); +// assertTrue(ctx.getPropertyFilters().contains(filter1)); +// assertTrue(ctx.getPropertyFilters().contains(filter2)); +// assertEquals(2, ctx.getPropertyFilters().size()); +// b = ExtConfigBuilder.create(); +// b.withFilters(filter1, filter2); +// b.withFilters(filter1, filter2); +// assertEquals(2, ctx.getPropertyFilters().size()); +// } +// +// @Test +// public void addPropertyFilters_Collection() throws Exception { +// Filter filter1 = (value) -> value; +// Filter filter2 = (value) -> value; +// ExtConfigBuilder b = ExtConfigBuilder.create(); +// b.withFilters(Arrays.asList(new Filter[]{filter1, filter2})); +// Config cfg = b.build(); +// ConfigContext ctx = ConfigContext.of(cfg); +// assertTrue(ctx.getPropertyFilters().contains(filter1)); +// assertTrue(ctx.getPropertyFilters().contains(filter2)); +// assertEquals(2, ctx.getPropertyFilters().size()); +// b = ExtConfigBuilder.create(); +// b.withFilters(filter1, filter2); +// b.withFilters(filter1, filter2); +// assertEquals(2, ctx.getPropertyFilters().size()); +// } +// +// @Test +// public void removePropertyFilters_Array() throws Exception { +// Filter filter1 = (value) -> value; +// Filter filter2 = (value) -> value; +// ExtConfigBuilder b = ExtConfigBuilder.create() +// .withFilters(filter1, filter2); +// Config cfg = b.build(); +// ConfigContext ctx = ConfigContext.of(cfg); +// assertTrue(ctx.getPropertyFilters().contains(filter1)); +// assertTrue(ctx.getPropertyFilters().contains(filter2)); +// assertEquals(2, ctx.getPropertyFilters().size()); +// b = ExtConfigBuilder.create() +// .withFilters(filter1, filter2); +// b.removeFilters(filter1); +// cfg = b.build(); +// ctx = ConfigContext.of(cfg); +// assertEquals(1, ctx.getPropertyFilters().size()); +// assertFalse(ctx.getPropertyFilters().contains(filter1)); +// assertTrue(ctx.getPropertyFilters().contains(filter2)); +// } +// +// @Test +// public void removePropertyFilters_Collection() throws Exception { +// Filter filter1 = (value) -> value; +// Filter filter2 = (value) -> value; +// ExtConfigBuilder b = ExtConfigBuilder.create() +// .withFilters(Arrays.asList(new Filter[]{filter1, filter2})); +// Config cfg = b.build(); +// ConfigContext ctx = ConfigContext.of(cfg); +// assertTrue(ctx.getPropertyFilters().contains(filter1)); +// assertTrue(ctx.getPropertyFilters().contains(filter2)); +// assertEquals(2, ctx.getPropertyFilters().size()); +// b = ExtConfigBuilder.create() +// .withFilters(Arrays.asList(new Filter[]{filter1, filter2})); +// b.removeFilters(filter1); +// cfg = b.build(); +// ctx = ConfigContext.of(cfg); +// assertEquals(1, ctx.getPropertyFilters().size()); +// assertFalse(ctx.getPropertyFilters().contains(filter1)); +// assertTrue(ctx.getPropertyFilters().contains(filter2)); +// } +// +// @Test +// @SuppressWarnings({ "rawtypes", "unchecked" }) +// public void addPropertyConverters_Array() throws Exception { +// Converter converter = (value) -> value.toLowerCase(); +// ExtConfigBuilder b = ExtConfigBuilder.create() +// .withConverters(TypeLiteral.of(String.class), converter); +// Config cfg = b.build(); +// ConfigContext ctx = ConfigContext.of(cfg); +// assertTrue(ctx.getConverters(TypeLiteral.of(String.class)).contains(converter)); +// assertEquals(1, ctx.getConverters().size()); +// b = ExtConfigBuilder.create() +// .withConverters(TypeLiteral.of(String.class), converter); +// b.withConverters(TypeLiteral.of(String.class), converter); +// assertEquals(1, ctx.getConverters().size()); +// } +// +// @Test +// @SuppressWarnings({ "rawtypes", "unchecked" }) +// public void addPropertyConverters_Collection() throws Exception { +// Converter converter = (value) -> value.toLowerCase(); +// ExtConfigBuilder b = ExtConfigBuilder.create() +// .withConverters(TypeLiteral.of(String.class), +// Arrays.<Converter<Object>>asList(new Converter[]{converter})); +// Config cfg = b.build(); +// ConfigContext ctx = ConfigContext.of(cfg); +// assertTrue(ctx.getConverters(TypeLiteral.of(String.class)).contains(converter)); +// assertEquals(ctx.getConverters().size(), 1); +// b = ExtConfigBuilder.create() +// .withConverters(TypeLiteral.of(String.class), +// Arrays.<Converter<Object>>asList(new Converter[]{converter})); +// b.withConverters(TypeLiteral.of(String.class), converter); +// assertEquals(ctx.getConverters().size(), 1); +// } +// +// @Test +// @SuppressWarnings({ "rawtypes", "unchecked" }) +// public void removePropertyConverters_Array() throws Exception { +// Converter converter = (value) -> value.toLowerCase(); +// ExtConfigBuilder b = b = ExtConfigBuilder.create() +// .withConverters(TypeLiteral.of(String.class), converter); +// Config cfg = b.build(); +// ConfigContext ctx = ConfigContext.of(cfg); +// assertTrue(ctx.getConverters(TypeLiteral.of(String.class)).contains(converter)); +// assertEquals(1, ctx.getConverters(TypeLiteral.of(String.class)).size()); +// b = ExtConfigBuilder.create() +// .withConverters(TypeLiteral.of(String.class), converter); +// b.removeConverters(TypeLiteral.of(String.class), converter); +// cfg = b.build(); +// ctx = ConfigContext.of(cfg); +// assertFalse(ctx.getConverters(TypeLiteral.of(String.class)).contains(converter)); +// assertTrue(ctx.getConverters(TypeLiteral.of(String.class)).isEmpty()); +// } +// +// +// @SuppressWarnings({ "rawtypes", "unchecked" }) +// @Test +// public void removePropertyConverters_Collection() throws Exception { +// Converter converter = (value) -> value.toLowerCase(); +// ExtConfigBuilder b = ExtConfigBuilder.create() +// .withConverters(TypeLiteral.of(String.class), Arrays.<Converter<Object>>asList(new Converter[]{converter})); +// Config cfg = b.build(); +// ConfigContext ctx = ConfigContext.of(cfg); +// assertTrue(ctx.getConverters(TypeLiteral.of(String.class)).contains(converter)); +// assertEquals(1, ctx.getConverters(TypeLiteral.of(String.class)).size()); +// b = b = ExtConfigBuilder.create() +// .withConverters(TypeLiteral.of(String.class), Arrays.<Converter<Object>>asList(new Converter[]{converter})); +// b.removeConverters(TypeLiteral.of(String.class), Arrays.<Converter<Object>>asList(new Converter[]{converter})); +// cfg = b.build(); +// ctx = ConfigContext.of(cfg); +// assertFalse(ctx.getConverters(TypeLiteral.of(String.class)).contains(converter)); +// assertTrue(ctx.getConverters(TypeLiteral.of(String.class)).isEmpty()); +// } +// +// @Test +// public void setPropertyValueCombinationPolicy() throws Exception { +// ConfigValueCombinationPolicy combPol = (currentValue, key, ConfigSource) -> currentValue; +// ExtConfigBuilder b = b = ExtConfigBuilder.create() +// .withPropertyValueCombinationPolicy(combPol); +// Config cfg = b.build(); +// ConfigContext ctx = ConfigContext.of(cfg); +// assertEquals(ctx.getConfigValueCombinationPolicy(), combPol); +// } +// +// @Test +// public void increasePriority(){ +// ExtConfigBuilder b = ExtConfigBuilder.create(); +// TestConfigSource[] ConfigSources = new TestConfigSource[10]; +// for(int i=0;i<ConfigSources.length;i++){ +// ConfigSources[i] = new TestConfigSource("ps"+i,i); +// } +// b.withSources(ConfigSources); +// b.increasePriority(ConfigSources[ConfigSources.length-1]); +// for(int i=0;i<ConfigSources.length;i++){ +// assertEquals(ConfigSources[i], b.getSources().get(i)); +// } +// b.increasePriority(ConfigSources[ConfigSources.length-2]); +// for(int i=0;i<ConfigSources.length-2;i++){ +// assertEquals(ConfigSources[i], b.getSources().get(i)); +// } +// assertEquals(ConfigSources[ConfigSources.length-1], b.getSources().get(ConfigSources.length-2)); +// assertEquals(ConfigSources[ConfigSources.length-2], b.getSources().get(ConfigSources.length-1)); +// } +// +// @Test +// public void decreasePriority(){ +// ExtConfigBuilder b = b = ExtConfigBuilder.create(); +// TestConfigSource[] ConfigSources = new TestConfigSource[10]; +// for(int i=0;i<ConfigSources.length;i++){ +// ConfigSources[i] = new TestConfigSource("ps"+i,i); +// } +// b.withSources(ConfigSources); +// b.decreasePriority(ConfigSources[0]); +// for(int i=0;i<ConfigSources.length;i++){ +// assertEquals(ConfigSources[i], b.getSources().get(i)); +// } +// b.decreasePriority(ConfigSources[1]); +// for(int i=2;i<ConfigSources.length;i++){ +// assertEquals(ConfigSources[i], b.getSources().get(i)); +// } +// assertEquals(ConfigSources[0], b.getSources().get(1)); +// assertEquals(ConfigSources[1], b.getSources().get(0)); +// } +// +// @Test +// public void lowestPriority(){ +// // setup +// ExtConfigBuilder b = ExtConfigBuilder.create(); +// TestConfigSource[] ConfigSources = new TestConfigSource[10]; +// for(int i=0;i<ConfigSources.length;i++){ +// ConfigSources[i] = new TestConfigSource("ps"+i,i); +// } +// b.withSources(ConfigSources); +// // test +// b.lowestPriority(ConfigSources[0]); +// for(int i=0;i<ConfigSources.length;i++){ +// assertEquals(ConfigSources[i], b.getSources().get(i)); +// } +// b.lowestPriority(ConfigSources[1]); +// for(int i=2;i<ConfigSources.length;i++){ +// assertEquals(ConfigSources[i], b.getSources().get(i)); +// } +// assertEquals(ConfigSources[0], b.getSources().get(1)); +// assertEquals(ConfigSources[1], b.getSources().get(0)); +// b.lowestPriority(ConfigSources[5]); +// assertEquals(ConfigSources[5], b.getSources().get(0)); +// } +// +// @Test +// public void highestPriority(){ +// // setup +// ExtConfigBuilder b = ExtConfigBuilder.create(); +// TestConfigSource[] ConfigSources = new TestConfigSource[10]; +// for(int i=0;i<ConfigSources.length;i++){ +// ConfigSources[i] = new TestConfigSource("ps"+i,i); +// } +// b.withSources(ConfigSources); +// // test +// b.highestPriority(ConfigSources[ConfigSources.length-1]); +// for(int i=0;i<ConfigSources.length;i++){ +// assertEquals(ConfigSources[i], b.getSources().get(i)); +// } +// b.highestPriority(ConfigSources[ConfigSources.length-2]); +// for(int i=0;i<ConfigSources.length-2;i++){ +// assertEquals(ConfigSources[i], b.getSources().get(i)); +// } +// assertEquals(ConfigSources[ConfigSources.length-2], b.getSources().get(ConfigSources.length-1)); +// assertEquals(ConfigSources[ConfigSources.length-1], b.getSources().get(ConfigSources.length-2)); +// b.highestPriority(ConfigSources[5]); +// assertEquals(ConfigSources[5], b.getSources().get(ConfigSources.length-1)); +// } +// +// @Test +// public void sortConfigSources(){ +// // setup +// ExtConfigBuilder b = ExtConfigBuilder.create(); +// TestConfigSource[] ConfigSources = new TestConfigSource[10]; +// for(int i=0;i<ConfigSources.length;i++){ +// ConfigSources[i] = new TestConfigSource("ps"+i,i); +// } +// b.withSources(ConfigSources); +// Comparator<ConfigSource> psComp = (o1, o2) -> o1.toString().compareTo(o2.toString()); +// // test +// b.sortSources(psComp); +// Arrays.sort(ConfigSources, psComp); +// for(int i=0;i<ConfigSources.length;i++){ +// assertEquals(ConfigSources[i], b.getSources().get(i)); +// } +// } +// +// @Test +// public void sortPropertyFilter(){ +// // setup +// ExtConfigBuilder b = ExtConfigBuilder.create(); +// Filter[] filters = new Filter[10]; +// for(int i = 0; i< filters.length; i++){ +// filters[i] = (value) -> value.toBuilder().setValue(toString() + " - ").build(); +// } +// b.withFilters(filters); +// Comparator<Filter> pfComp = (o1, o2) -> o1.toString().compareTo(o2.toString()); +// // test +// b.sortFilter(pfComp); +// Arrays.sort(filters, pfComp); +// for(int i = 0; i< filters.length; i++){ +// assertEquals(filters[i], b.getFilters().get(i)); +// } +// } +// +// @Test +// public void build() throws Exception { +// ExtConfigBuilder b = ExtConfigBuilder.create(); +// Config cfg = b.build(); +// ConfigContext ctx = ConfigContext.of(cfg); +// assertNotNull(ctx); +// assertTrue(ctx.getSources().isEmpty()); +// assertTrue(ctx.getPropertyFilters().isEmpty()); +// } +// +// @Test +// public void testRemoveAllFilters() throws Exception { +// ExtConfigBuilder b = ExtConfigBuilder.create(); +// b.withFilters((value) -> value.toBuilder().setValue(toString() + " - ").build()); +// assertFalse(b.getFilters().isEmpty()); +// b.removeFilters(b.getFilters()); +// assertTrue(b.getFilters().isEmpty()); +// } +// +// @Test +// public void testRemoveAllSources() throws Exception { +// ExtConfigBuilder b = ExtConfigBuilder.create(); +// b.withSources(new TestConfigSource()); +// assertFalse(b.getSources().isEmpty()); +// b.removeSources(b.getSources()); +// assertTrue(b.getSources().isEmpty()); +// } +//} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d0e14ed7/code/core/src/test/java/org/apache/tamaya/core/TamayaConfigProviderResolverTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/TamayaConfigProviderResolverTest.java b/code/core/src/test/java/org/apache/tamaya/core/TamayaConfigProviderResolverTest.java new file mode 100644 index 0000000..dafe7a3 --- /dev/null +++ b/code/core/src/test/java/org/apache/tamaya/core/TamayaConfigProviderResolverTest.java @@ -0,0 +1,69 @@ +/* + * 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; + +import org.apache.tamaya.core.TamayaConfigProviderResolver; +import org.apache.tamaya.spi.ConfigContext; +import org.apache.tamaya.spi.ConfigContextSupplier; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by atsticks on 11.09.16. + */ +public class TamayaConfigProviderResolverTest { + + @Test + public void testInstantiation() throws Exception { + new TamayaConfigProviderResolver(); + } + + @Test + public void getConfiguration() throws Exception { + assertNotNull(new TamayaConfigProviderResolver().getConfig()); + } + + @Test + public void configIsConfigContextSupplier() throws Exception { + assertTrue(new TamayaConfigProviderResolver().getConfig() instanceof ConfigContextSupplier); + } + + @Test + public void getBuilder() throws Exception { + assertNotNull(new TamayaConfigProviderResolver().getBuilder()); + } + + @SuppressWarnings("deprecation") + @Test + public void registerConfig_CL() throws Exception { + new TamayaConfigProviderResolver() + .registerConfig(new TamayaConfigProviderResolver().getConfig(), + ClassLoader.getSystemClassLoader()); + } + + @SuppressWarnings("deprecation") + @Test + public void registerConfig_Null() throws Exception { + new TamayaConfigProviderResolver() + .registerConfig(new TamayaConfigProviderResolver().getConfig(), null); + } + + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d0e14ed7/code/core/src/test/java/org/apache/tamaya/core/TestConfigSource.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/TestConfigSource.java b/code/core/src/test/java/org/apache/tamaya/core/TestConfigSource.java new file mode 100644 index 0000000..35f380b --- /dev/null +++ b/code/core/src/test/java/org/apache/tamaya/core/TestConfigSource.java @@ -0,0 +1,67 @@ +/* + * 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; + +import javax.config.spi.ConfigSource; +import java.util.Collections; +import java.util.Date; +import java.util.Map; + +/** + * Created by atsticks on 18.10.16. + */ +public class TestConfigSource implements ConfigSource { + + private String id; + private int ordinal; + + public TestConfigSource() { + this("TestConfigSource", 0); + } + + public TestConfigSource(String id, int ordinal) { + this.id = id; + this.ordinal = ordinal; + } + + public int getOrdinal() { + return ordinal; + } + + @Override + public String getName() { + return id != null ? id : "TestConfigSource"; + } + + @Override + public String getValue(String key) { + if(key.endsWith("[meta]")){ + return "ordinal=" + String.valueOf(getOrdinal()) + '\n'+ + "createdAt=" + String.valueOf(new Date()); + } + return key + "Value"; + } + + @Override + public Map<String, String> getProperties() { + return Collections.emptyMap(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d0e14ed7/code/core/src/test/java/org/apache/tamaya/core/testdata/TestConfigNamesSource.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/testdata/TestConfigNamesSource.java b/code/core/src/test/java/org/apache/tamaya/core/testdata/TestConfigNamesSource.java new file mode 100644 index 0000000..eba5bb9 --- /dev/null +++ b/code/core/src/test/java/org/apache/tamaya/core/testdata/TestConfigNamesSource.java @@ -0,0 +1,51 @@ +/* + * 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.base.configsource.BaseConfigSource; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * Test provider reading properties from classpath:cfg/defaults/**.properties. + */ +public class TestConfigNamesSource extends BaseConfigSource { + + private Map<String,String> properties = new HashMap<>(); + + public TestConfigNamesSource() { + super(100); + properties.put("name","Anatole"); + properties.put("name2", "Sabine"); + properties = Collections.unmodifiableMap(properties); + } + + @Override + public String getName() { + return "default-testdata-properties"; + } + + @Override + public Map<String, String> getProperties() { + return properties; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d0e14ed7/code/core/src/test/java/org/apache/tamaya/core/testdata/TestFilter.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/testdata/TestFilter.java b/code/core/src/test/java/org/apache/tamaya/core/testdata/TestFilter.java new file mode 100644 index 0000000..9ffe868 --- /dev/null +++ b/code/core/src/test/java/org/apache/tamaya/core/testdata/TestFilter.java @@ -0,0 +1,42 @@ +/* + * 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.base.filter.FilterContext; +import org.apache.tamaya.spi.Filter; +import org.apache.tamaya.spi.ConfigValue; + +import javax.annotation.Priority; + +/** + * Simple PropertyFilter that filters exact one value, registered using ServiceLoader. + */ +@Priority(100) +public class TestFilter implements Filter { + @Override + public ConfigValue filterProperty(ConfigValue valueToBeFiltered) { + FilterContext context = FilterContext.getContext(); + if("name4".equals(valueToBeFiltered.getKey())){ + return valueToBeFiltered.toBuilder() + .setValue(valueToBeFiltered.getValue() + "(filtered)") + .build(); + } + return valueToBeFiltered; + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d0e14ed7/code/core/src/test/java/org/apache/tamaya/core/testdata/TestRemovingFilter.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/testdata/TestRemovingFilter.java b/code/core/src/test/java/org/apache/tamaya/core/testdata/TestRemovingFilter.java new file mode 100644 index 0000000..4bead15 --- /dev/null +++ b/code/core/src/test/java/org/apache/tamaya/core/testdata/TestRemovingFilter.java @@ -0,0 +1,47 @@ +/* + * 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.base.filter.FilterContext; +import org.apache.tamaya.spi.Filter; +import org.apache.tamaya.spi.ConfigValue; + +import javax.annotation.Priority; +import javax.config.ConfigProvider; + +/** + * Simple PropertyFilter that filters exact one value, registered using ServiceLoader. + */ +@Priority(200) +public class TestRemovingFilter implements Filter { + @Override + public ConfigValue filterProperty(ConfigValue valueToBeFiltered) { + FilterContext context = FilterContext.getContext(); + + if("name5".equals(valueToBeFiltered.getKey())){ + return null; + } + else if("name3".equals(valueToBeFiltered.getKey())){ + return valueToBeFiltered.toBuilder().setValue( + "Mapped to name: " + ConfigProvider.getConfig().getValue("name", String.class)) + .build(); + } + return valueToBeFiltered; + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d0e14ed7/code/core/src/test/resources/META-INF/javaconfig.properties ---------------------------------------------------------------------- diff --git a/code/core/src/test/resources/META-INF/javaconfig.properties b/code/core/src/test/resources/META-INF/javaconfig.properties new file mode 100644 index 0000000..33beabb --- /dev/null +++ b/code/core/src/test/resources/META-INF/javaconfig.properties @@ -0,0 +1,22 @@ +# 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. + +confkey1=javaconf-value1 +confkey2=javaconf-value2 +confkey3=javaconf-value3 +confkey4=javaconf-value4 +confkey5=javaconf-value5 http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d0e14ed7/code/core/src/test/resources/META-INF/javaconfig.xml ---------------------------------------------------------------------- diff --git a/code/core/src/test/resources/META-INF/javaconfig.xml b/code/core/src/test/resources/META-INF/javaconfig.xml new file mode 100644 index 0000000..f6cdc97 --- /dev/null +++ b/code/core/src/test/resources/META-INF/javaconfig.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> + +<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> +<properties> + <entry key="aaeehh">ä</entry> + <entry key="ö">o</entry> +</properties> http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d0e14ed7/code/core/src/test/resources/META-INF/services/javax.config.spi.ConfigSource ---------------------------------------------------------------------- diff --git a/code/core/src/test/resources/META-INF/services/javax.config.spi.ConfigSource b/code/core/src/test/resources/META-INF/services/javax.config.spi.ConfigSource new file mode 100644 index 0000000..74d685e --- /dev/null +++ b/code/core/src/test/resources/META-INF/services/javax.config.spi.ConfigSource @@ -0,0 +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 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.TestConfigNamesSource +org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource + http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d0e14ed7/code/core/src/test/resources/META-INF/services/javax.config.spi.ConfigSourceProvider ---------------------------------------------------------------------- diff --git a/code/core/src/test/resources/META-INF/services/javax.config.spi.ConfigSourceProvider b/code/core/src/test/resources/META-INF/services/javax.config.spi.ConfigSourceProvider new file mode 100644 index 0000000..c9f255a --- /dev/null +++ b/code/core/src/test/resources/META-INF/services/javax.config.spi.ConfigSourceProvider @@ -0,0 +1,19 @@ +# +# 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.TestPropertySourceProvider http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d0e14ed7/code/core/src/test/resources/META-INF/services/javax.config.spi.Converter ---------------------------------------------------------------------- diff --git a/code/core/src/test/resources/META-INF/services/javax.config.spi.Converter b/code/core/src/test/resources/META-INF/services/javax.config.spi.Converter new file mode 100644 index 0000000..d039696 --- /dev/null +++ b/code/core/src/test/resources/META-INF/services/javax.config.spi.Converter @@ -0,0 +1,19 @@ +# +# 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.internal.CTestConverter \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d0e14ed7/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.Filter ---------------------------------------------------------------------- diff --git a/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.Filter b/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.Filter new file mode 100644 index 0000000..d727173 --- /dev/null +++ b/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.Filter @@ -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.TestFilter +org.apache.tamaya.core.testdata.TestRemovingFilter
