http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/core/src/test/java/org/apache/tamaya/core/ConfigurationBuilderTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationBuilderTest.java b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationBuilderTest.java deleted file mode 100644 index 1f702bb..0000000 --- a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationBuilderTest.java +++ /dev/null @@ -1,440 +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.core; - -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.core.internal.CoreConfigurationBuilder; -import org.apache.tamaya.spi.*; -import org.apache.tamaya.spisupport.DefaultConfigurationContextBuilder; -import org.junit.Test; -import sun.security.krb5.Config; - -import java.util.Arrays; -import java.util.Comparator; - -import static org.junit.Assert.*; - -/** - * Tests for {@link ConfigurationBuilder} by atsticks on 06.09.16. - */ -public class ConfigurationBuilderTest { - - private TestPropertySource testPropertySource = new TestPropertySource(){}; - - @Test - public void setContext() throws Exception { - Configuration cfg = ConfigurationProvider.getConfiguration(); - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder() - .setConfiguration(cfg); - assertEquals(cfg, b.build()); - } - - @Test - public void addPropertySources_Array() throws Exception { - PropertySource testPS2 = new TestPropertySource("addPropertySources_Array", 1); - ConfigurationBuilder b = new CoreConfigurationBuilder() - .addPropertySources(testPropertySource, testPS2); - Configuration cfg = b.build(); - assertEquals(2, cfg.getContext().getPropertySources().size()); - assertTrue(cfg.getContext().getPropertySources().contains(testPropertySource)); - assertTrue(cfg.getContext().getPropertySources().contains(testPS2)); - // Ensure no sorting happens during add, so switch ordinals! - testPS2 = new TestPropertySource("addPropertySources_Array", 1); - b = ConfigurationProvider.getConfigurationBuilder() - .addPropertySources(testPS2, testPropertySource); - cfg = b.build(); - assertEquals(2, cfg.getContext().getPropertySources().size()); - assertTrue(cfg.getContext().getPropertySources().contains(testPropertySource)); - assertTrue(cfg.getContext().getPropertySources().contains(testPS2)); - assertEquals(cfg.getContext().getPropertySources().get(1).getName(), "TestPropertySource"); - assertEquals(cfg.getContext().getPropertySources().get(0).getName(), "addPropertySources_Array"); - } - - @Test - public void addPropertySources_Collection() throws Exception { - PropertySource testPS2 = new TestPropertySource("addPropertySources_Collection", 1); - ConfigurationBuilder b = new CoreConfigurationBuilder() - .addPropertySources(Arrays.asList(new PropertySource[]{testPropertySource, testPS2})); - Configuration cfg = b.build(); - assertEquals(2, cfg.getContext().getPropertySources().size()); - assertTrue(cfg.getContext().getPropertySources().contains(testPropertySource)); - assertTrue(cfg.getContext().getPropertySources().contains(testPS2)); - assertEquals(cfg.getContext().getPropertySources().get(0).getName(), "TestPropertySource"); - assertEquals(cfg.getContext().getPropertySources().get(1).getName(), "addPropertySources_Collection"); - // Ensure no sorting happens during add, so switch ordinals! - testPS2 = new TestPropertySource("addPropertySources_Collection", 1); - b = ConfigurationProvider.getConfigurationBuilder() - .addPropertySources(Arrays.asList(new PropertySource[]{testPS2, testPropertySource})); - cfg = b.build(); - assertEquals(2, cfg.getContext().getPropertySources().size()); - assertTrue(cfg.getContext().getPropertySources().contains(testPropertySource)); - assertTrue(cfg.getContext().getPropertySources().contains(testPS2)); - assertEquals(cfg.getContext().getPropertySources().get(1).getName(), "TestPropertySource"); - assertEquals(cfg.getContext().getPropertySources().get(0).getName(), "addPropertySources_Collection"); - } - - @Test - public void removePropertySources_Array() throws Exception { - PropertySource testPS2 = new TestPropertySource("removePropertySources_Array", 1); - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder() - .addPropertySources(testPropertySource, testPS2); - Configuration cfg = b.build(); - assertEquals(2, cfg.getContext().getPropertySources().size()); - assertTrue(cfg.getContext().getPropertySources().contains(testPropertySource)); - assertTrue(cfg.getContext().getPropertySources().contains(testPS2)); - b = ConfigurationProvider.getConfigurationBuilder() - .addPropertySources(testPropertySource, testPS2); - b.removePropertySources(testPropertySource); - cfg = b.build(); - assertFalse(cfg.getContext().getPropertySources().contains(testPropertySource)); - assertTrue(cfg.getContext().getPropertySources().contains(testPS2)); - assertEquals(1, cfg.getContext().getPropertySources().size()); - } - - @Test - public void removePropertySources_Collection() throws Exception { - PropertySource testPS2 = new TestPropertySource("removePropertySources_Array", 1); - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder() - .addPropertySources(testPropertySource, testPS2); - Configuration cfg = b.build(); - assertEquals(2, cfg.getContext().getPropertySources().size()); - assertTrue(cfg.getContext().getPropertySources().contains(testPropertySource)); - assertTrue(cfg.getContext().getPropertySources().contains(testPS2)); - b = ConfigurationProvider.getConfigurationBuilder() - .addPropertySources(testPropertySource, testPS2); - b.removePropertySources(testPropertySource); - cfg = b.build(); - assertEquals(1, cfg.getContext().getPropertySources().size()); - assertFalse(cfg.getContext().getPropertySources().contains(testPropertySource)); - assertTrue(cfg.getContext().getPropertySources().contains(testPS2)); - } - - @Test - public void addPropertyFilters_Array() throws Exception { - PropertyFilter filter1 = (value, context) -> value; - PropertyFilter filter2 = (value, context) -> value; - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder(); - b.addPropertyFilters(filter1, filter2); - Configuration cfg = b.build(); - ConfigurationContext ctx = cfg.getContext(); - assertTrue(ctx.getPropertyFilters().contains(filter1)); - assertTrue(ctx.getPropertyFilters().contains(filter2)); - assertEquals(2, ctx.getPropertyFilters().size()); - b = ConfigurationProvider.getConfigurationBuilder(); - b.addPropertyFilters(filter1, filter2); - b.addPropertyFilters(filter1, filter2); - assertEquals(2, ctx.getPropertyFilters().size()); - } - - @Test - public void addPropertyFilters_Collection() throws Exception { - PropertyFilter filter1 = (value, context) -> value; - PropertyFilter filter2 = (value, context) -> value; - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder(); - b.addPropertyFilters(Arrays.asList(new PropertyFilter[]{filter1, filter2})); - Configuration cfg = b.build(); - ConfigurationContext ctx = cfg.getContext(); - assertTrue(ctx.getPropertyFilters().contains(filter1)); - assertTrue(ctx.getPropertyFilters().contains(filter2)); - assertEquals(2, ctx.getPropertyFilters().size()); - b = ConfigurationProvider.getConfigurationBuilder(); - b.addPropertyFilters(filter1, filter2); - b.addPropertyFilters(filter1, filter2); - assertEquals(2, ctx.getPropertyFilters().size()); - } - - @Test - public void removePropertyFilters_Array() throws Exception { - PropertyFilter filter1 = (value, context) -> value; - PropertyFilter filter2 = (value, context) -> value; - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder() - .addPropertyFilters(filter1, filter2); - Configuration cfg = b.build(); - ConfigurationContext ctx = cfg.getContext(); - assertTrue(ctx.getPropertyFilters().contains(filter1)); - assertTrue(ctx.getPropertyFilters().contains(filter2)); - assertEquals(2, ctx.getPropertyFilters().size()); - b = ConfigurationProvider.getConfigurationBuilder() - .addPropertyFilters(filter1, filter2); - b.removePropertyFilters(filter1); - cfg = b.build(); - ctx = cfg.getContext(); - assertEquals(1, ctx.getPropertyFilters().size()); - assertFalse(ctx.getPropertyFilters().contains(filter1)); - assertTrue(ctx.getPropertyFilters().contains(filter2)); - } - - @Test - public void removePropertyFilters_Collection() throws Exception { - PropertyFilter filter1 = (value, context) -> value; - PropertyFilter filter2 = (value, context) -> value; - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder() - .addPropertyFilters(Arrays.asList(new PropertyFilter[]{filter1, filter2})); - Configuration cfg = b.build(); - ConfigurationContext ctx = cfg.getContext(); - assertTrue(ctx.getPropertyFilters().contains(filter1)); - assertTrue(ctx.getPropertyFilters().contains(filter2)); - assertEquals(2, ctx.getPropertyFilters().size()); - b = ConfigurationProvider.getConfigurationBuilder() - .addPropertyFilters(Arrays.asList(new PropertyFilter[]{filter1, filter2})); - b.removePropertyFilters(filter1); - cfg = b.build(); - ctx = cfg.getContext(); - 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 { - PropertyConverter converter = (value, context) -> value.toLowerCase(); - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), converter); - Configuration cfg = b.build(); - ConfigurationContext ctx = cfg.getContext(); - assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)); - assertEquals(1, ctx.getPropertyConverters().size()); - b = ConfigurationProvider.getConfigurationBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), converter); - b.addPropertyConverters(TypeLiteral.of(String.class), converter); - assertEquals(1, ctx.getPropertyConverters().size()); - } - - @Test - @SuppressWarnings({ "rawtypes", "unchecked" }) - public void addPropertyConverters_Collection() throws Exception { - PropertyConverter converter = (value, context) -> value.toLowerCase(); - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), - Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter})); - Configuration cfg = b.build(); - ConfigurationContext ctx = cfg.getContext(); - assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)); - assertEquals(ctx.getPropertyConverters().size(), 1); - b = ConfigurationProvider.getConfigurationBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), - Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter})); - b.addPropertyConverters(TypeLiteral.of(String.class), converter); - assertEquals(ctx.getPropertyConverters().size(), 1); - } - - @Test - @SuppressWarnings({ "rawtypes", "unchecked" }) - public void removePropertyConverters_Array() throws Exception { - PropertyConverter converter = (value, context) -> value.toLowerCase(); - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), converter); - Configuration cfg = b.build(); - ConfigurationContext ctx = cfg.getContext(); - assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)); - assertEquals(1, ctx.getPropertyConverters(TypeLiteral.of(String.class)).size()); - b = ConfigurationProvider.getConfigurationBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), converter); - b.removePropertyConverters(TypeLiteral.of(String.class), converter); - cfg = b.build(); - ctx = cfg.getContext(); - assertFalse(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)); - assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).isEmpty()); - } - - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Test - public void removePropertyConverters_Collection() throws Exception { - PropertyConverter converter = (value, context) -> value.toLowerCase(); - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter})); - Configuration cfg = b.build(); - ConfigurationContext ctx = cfg.getContext(); - assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)); - assertEquals(1, ctx.getPropertyConverters(TypeLiteral.of(String.class)).size()); - b = ConfigurationProvider.getConfigurationBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter})); - b.removePropertyConverters(TypeLiteral.of(String.class), Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter})); - cfg = b.build(); - ctx = cfg.getContext(); - assertFalse(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)); - assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).isEmpty()); - } - - @Test - public void setPropertyValueCombinationPolicy() throws Exception { - PropertyValueCombinationPolicy combPol = (currentValue, key, propertySource) -> currentValue; - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder() - .setPropertyValueCombinationPolicy(combPol); - Configuration cfg = b.build(); - ConfigurationContext ctx = cfg.getContext(); - assertEquals(ctx.getPropertyValueCombinationPolicy(), combPol); - } - - @Test - public void increasePriority(){ - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder(); - TestPropertySource[] propertySources = new TestPropertySource[10]; - for(int i=0;i<propertySources.length;i++){ - propertySources[i] = new TestPropertySource("ps"+i,i); - } - b.addPropertySources(propertySources); - b.increasePriority(propertySources[propertySources.length-1]); - for(int i=0;i<propertySources.length;i++){ - assertEquals(propertySources[i], b.getPropertySources().get(i)); - } - b.increasePriority(propertySources[propertySources.length-2]); - for(int i=0;i<propertySources.length-2;i++){ - assertEquals(propertySources[i], b.getPropertySources().get(i)); - } - assertEquals(propertySources[propertySources.length-1], b.getPropertySources().get(propertySources.length-2)); - assertEquals(propertySources[propertySources.length-2], b.getPropertySources().get(propertySources.length-1)); - } - - @Test - public void decreasePriority(){ - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder(); - TestPropertySource[] propertySources = new TestPropertySource[10]; - for(int i=0;i<propertySources.length;i++){ - propertySources[i] = new TestPropertySource("ps"+i,i); - } - b.addPropertySources(propertySources); - b.decreasePriority(propertySources[0]); - for(int i=0;i<propertySources.length;i++){ - assertEquals(propertySources[i], b.getPropertySources().get(i)); - } - b.decreasePriority(propertySources[1]); - for(int i=2;i<propertySources.length;i++){ - assertEquals(propertySources[i], b.getPropertySources().get(i)); - } - assertEquals(propertySources[0], b.getPropertySources().get(1)); - assertEquals(propertySources[1], b.getPropertySources().get(0)); - } - - @Test - public void lowestPriority(){ - // setup - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder(); - TestPropertySource[] propertySources = new TestPropertySource[10]; - for(int i=0;i<propertySources.length;i++){ - propertySources[i] = new TestPropertySource("ps"+i,i); - } - b.addPropertySources(propertySources); - // test - b.lowestPriority(propertySources[0]); - for(int i=0;i<propertySources.length;i++){ - assertEquals(propertySources[i], b.getPropertySources().get(i)); - } - b.lowestPriority(propertySources[1]); - for(int i=2;i<propertySources.length;i++){ - assertEquals(propertySources[i], b.getPropertySources().get(i)); - } - assertEquals(propertySources[0], b.getPropertySources().get(1)); - assertEquals(propertySources[1], b.getPropertySources().get(0)); - b.lowestPriority(propertySources[5]); - assertEquals(propertySources[5], b.getPropertySources().get(0)); - } - - @Test - public void highestPriority(){ - // setup - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder(); - TestPropertySource[] propertySources = new TestPropertySource[10]; - for(int i=0;i<propertySources.length;i++){ - propertySources[i] = new TestPropertySource("ps"+i,i); - } - b.addPropertySources(propertySources); - // test - b.highestPriority(propertySources[propertySources.length-1]); - for(int i=0;i<propertySources.length;i++){ - assertEquals(propertySources[i], b.getPropertySources().get(i)); - } - b.highestPriority(propertySources[propertySources.length-2]); - for(int i=0;i<propertySources.length-2;i++){ - assertEquals(propertySources[i], b.getPropertySources().get(i)); - } - assertEquals(propertySources[propertySources.length-2], b.getPropertySources().get(propertySources.length-1)); - assertEquals(propertySources[propertySources.length-1], b.getPropertySources().get(propertySources.length-2)); - b.highestPriority(propertySources[5]); - assertEquals(propertySources[5], b.getPropertySources().get(propertySources.length-1)); - } - - @Test - public void sortPropertySources(){ - // setup - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder(); - TestPropertySource[] propertySources = new TestPropertySource[10]; - for(int i=0;i<propertySources.length;i++){ - propertySources[i] = new TestPropertySource("ps"+i,i); - } - b.addPropertySources(propertySources); - Comparator<PropertySource> psComp = (o1, o2) -> o1.toString().compareTo(o2.toString()); - // test - b.sortPropertySources(psComp); - Arrays.sort(propertySources, psComp); - for(int i=0;i<propertySources.length;i++){ - assertEquals(propertySources[i], b.getPropertySources().get(i)); - } - } - - @Test - public void sortPropertyFilter(){ - // setup - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder(); - PropertyFilter[] propertyFilters = new PropertyFilter[10]; - for(int i=0;i<propertyFilters.length;i++){ - propertyFilters[i] = (value, context) -> value.toBuilder().setValue(toString() + " - ").build(); - } - b.addPropertyFilters(propertyFilters); - Comparator<PropertyFilter> pfComp = (o1, o2) -> o1.toString().compareTo(o2.toString()); - // test - b.sortPropertyFilter(pfComp); - Arrays.sort(propertyFilters, pfComp); - for(int i=0;i<propertyFilters.length;i++){ - assertEquals(propertyFilters[i], b.getPropertyFilters().get(i)); - } - } - - @Test - public void build() throws Exception { - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder(); - Configuration cfg = b.build(); - ConfigurationContext ctx = cfg.getContext(); - assertNotNull(ctx); - assertTrue(ctx.getPropertySources().isEmpty()); - assertTrue(ctx.getPropertyFilters().isEmpty()); - } - - @Test - public void testRemoveAllFilters() throws Exception { - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder(); - b.addPropertyFilters((value, context) -> value.toBuilder().setValue(toString() + " - ").build()); - assertFalse(b.getPropertyFilters().isEmpty()); - b.removePropertyFilters(b.getPropertyFilters()); - assertTrue(b.getPropertyFilters().isEmpty()); - } - - @Test - public void testRemoveAllSources() throws Exception { - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder(); - b.addPropertySources(new TestPropertySource()); - assertFalse(b.getPropertySources().isEmpty()); - b.removePropertySources(b.getPropertySources()); - assertTrue(b.getPropertyFilters().isEmpty()); - } -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java deleted file mode 100644 index ac353eb..0000000 --- a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java +++ /dev/null @@ -1,422 +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.core; - -import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.spi.*; -import org.apache.tamaya.spisupport.DefaultConfigurationContextBuilder; -import org.junit.Test; - -import java.util.Arrays; -import java.util.Comparator; - -import static org.junit.Assert.*; - -/** - * Tests for {@link ConfigurationContextBuilder} by atsticks on 06.09.16. - */ -public class ConfigurationContextBuilderTest { - - private TestPropertySource testPropertySource = new TestPropertySource(){}; - - @Test - public void setContext() throws Exception { - ConfigurationContext context = ConfigurationProvider.getConfiguration().getContext(); - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder() - .setContext(context); - assertEquals(context, b.build()); - } - - @Test - public void addPropertySources_Array() throws Exception { - PropertySource testPS2 = new TestPropertySource("addPropertySources_Array", 1); - ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder() - .addPropertySources(testPropertySource, testPS2); - ConfigurationContext ctx = b.build(); - assertEquals(2, ctx.getPropertySources().size()); - assertTrue(ctx.getPropertySources().contains(testPropertySource)); - assertTrue(ctx.getPropertySources().contains(testPS2)); - // Ensure no sorting happens during add, so switch ordinals! - testPS2 = new TestPropertySource("addPropertySources_Array", 1); - b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertySources(testPS2, testPropertySource); - ctx = b.build(); - assertEquals(2, ctx.getPropertySources().size()); - assertTrue(ctx.getPropertySources().contains(testPropertySource)); - assertTrue(ctx.getPropertySources().contains(testPS2)); - assertEquals(ctx.getPropertySources().get(1).getName(), "TestPropertySource"); - assertEquals(ctx.getPropertySources().get(0).getName(), "addPropertySources_Array"); - } - - @Test - public void addPropertySources_Collection() throws Exception { - PropertySource testPS2 = new TestPropertySource("addPropertySources_Collection", 1); - ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder() - .addPropertySources(Arrays.asList(new PropertySource[]{testPropertySource, testPS2})); - ConfigurationContext ctx = b.build(); - assertEquals(2, ctx.getPropertySources().size()); - assertTrue(ctx.getPropertySources().contains(testPropertySource)); - assertTrue(ctx.getPropertySources().contains(testPS2)); - assertEquals(ctx.getPropertySources().get(0).getName(), "TestPropertySource"); - assertEquals(ctx.getPropertySources().get(1).getName(), "addPropertySources_Collection"); - // Ensure no sorting happens during add, so switch ordinals! - testPS2 = new TestPropertySource("addPropertySources_Collection", 1); - b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertySources(Arrays.asList(new PropertySource[]{testPS2, testPropertySource})); - ctx = b.build(); - assertEquals(2, ctx.getPropertySources().size()); - assertTrue(ctx.getPropertySources().contains(testPropertySource)); - assertTrue(ctx.getPropertySources().contains(testPS2)); - assertEquals(ctx.getPropertySources().get(1).getName(), "TestPropertySource"); - assertEquals(ctx.getPropertySources().get(0).getName(), "addPropertySources_Collection"); - } - - @Test - public void removePropertySources_Array() throws Exception { - PropertySource testPS2 = new TestPropertySource("removePropertySources_Array", 1); - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertySources(testPropertySource, testPS2); - ConfigurationContext ctx = b.build(); - assertEquals(2, ctx.getPropertySources().size()); - assertTrue(ctx.getPropertySources().contains(testPropertySource)); - assertTrue(ctx.getPropertySources().contains(testPS2)); - b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertySources(testPropertySource, testPS2); - b.removePropertySources(testPropertySource); - ctx = b.build(); - assertFalse(ctx.getPropertySources().contains(testPropertySource)); - assertTrue(ctx.getPropertySources().contains(testPS2)); - assertEquals(1, ctx.getPropertySources().size()); - } - - @Test - public void removePropertySources_Collection() throws Exception { - PropertySource testPS2 = new TestPropertySource("removePropertySources_Array", 1); - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertySources(testPropertySource, testPS2); - ConfigurationContext ctx = b.build(); - assertEquals(2, ctx.getPropertySources().size()); - assertTrue(ctx.getPropertySources().contains(testPropertySource)); - assertTrue(ctx.getPropertySources().contains(testPS2)); - b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertySources(testPropertySource, testPS2); - b.removePropertySources(testPropertySource); - ctx = b.build(); - assertEquals(1, ctx.getPropertySources().size()); - assertFalse(ctx.getPropertySources().contains(testPropertySource)); - assertTrue(ctx.getPropertySources().contains(testPS2)); - } - - @Test - public void addPropertyFilters_Array() throws Exception { - PropertyFilter filter1 = (value, context) -> value; - PropertyFilter filter2 = (value, context) -> value; - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - b.addPropertyFilters(filter1, filter2); - ConfigurationContext ctx = b.build(); - assertTrue(ctx.getPropertyFilters().contains(filter1)); - assertTrue(ctx.getPropertyFilters().contains(filter2)); - assertEquals(2, ctx.getPropertyFilters().size()); - b = ConfigurationProvider.getConfigurationContextBuilder(); - b.addPropertyFilters(filter1, filter2); - b.addPropertyFilters(filter1, filter2); - assertEquals(2, ctx.getPropertyFilters().size()); - } - - @Test - public void addPropertyFilters_Collection() throws Exception { - PropertyFilter filter1 = (value, context) -> value; - PropertyFilter filter2 = (value, context) -> value; - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - b.addPropertyFilters(Arrays.asList(new PropertyFilter[]{filter1, filter2})); - ConfigurationContext ctx = b.build(); - assertTrue(ctx.getPropertyFilters().contains(filter1)); - assertTrue(ctx.getPropertyFilters().contains(filter2)); - assertEquals(2, ctx.getPropertyFilters().size()); - b = ConfigurationProvider.getConfigurationContextBuilder(); - b.addPropertyFilters(filter1, filter2); - b.addPropertyFilters(filter1, filter2); - assertEquals(2, ctx.getPropertyFilters().size()); - } - - @Test - public void removePropertyFilters_Array() throws Exception { - PropertyFilter filter1 = (value, context) -> value; - PropertyFilter filter2 = (value, context) -> value; - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyFilters(filter1, filter2); - ConfigurationContext ctx = b.build(); - assertTrue(ctx.getPropertyFilters().contains(filter1)); - assertTrue(ctx.getPropertyFilters().contains(filter2)); - assertEquals(2, ctx.getPropertyFilters().size()); - b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyFilters(filter1, filter2); - b.removePropertyFilters(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 { - PropertyFilter filter1 = (value, context) -> value; - PropertyFilter filter2 = (value, context) -> value; - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyFilters(Arrays.asList(new PropertyFilter[]{filter1, filter2})); - ConfigurationContext ctx = b.build(); - assertTrue(ctx.getPropertyFilters().contains(filter1)); - assertTrue(ctx.getPropertyFilters().contains(filter2)); - assertEquals(2, ctx.getPropertyFilters().size()); - b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyFilters(Arrays.asList(new PropertyFilter[]{filter1, filter2})); - b.removePropertyFilters(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 addPropertyConverters_Array() throws Exception { - PropertyConverter converter = (value, context) -> value.toLowerCase(); - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), converter); - ConfigurationContext ctx = b.build(); - assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)); - assertEquals(1, ctx.getPropertyConverters().size()); - b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), converter); - b.addPropertyConverters(TypeLiteral.of(String.class), converter); - assertEquals(1, ctx.getPropertyConverters().size()); - } - - @Test - @SuppressWarnings({ "rawtypes", "unchecked" }) - public void addPropertyConverters_Collection() throws Exception { - PropertyConverter converter = (value, context) -> value.toLowerCase(); - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), - Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter})); - ConfigurationContext ctx = b.build(); - assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)); - assertEquals(ctx.getPropertyConverters().size(), 1); - b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), - Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter})); - b.addPropertyConverters(TypeLiteral.of(String.class), converter); - assertEquals(ctx.getPropertyConverters().size(), 1); - } - - @Test - @SuppressWarnings({ "rawtypes", "unchecked" }) - public void removePropertyConverters_Array() throws Exception { - PropertyConverter converter = (value, context) -> value.toLowerCase(); - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), converter); - ConfigurationContext ctx = b.build(); - assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)); - assertEquals(1, ctx.getPropertyConverters(TypeLiteral.of(String.class)).size()); - b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), converter); - b.removePropertyConverters(TypeLiteral.of(String.class), converter); - ctx = b.build(); - assertFalse(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)); - assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).isEmpty()); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Test - public void removePropertyConverters_Collection() throws Exception { - PropertyConverter converter = (value, context) -> value.toLowerCase(); - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter})); - ConfigurationContext ctx = b.build(); - assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)); - assertEquals(1, ctx.getPropertyConverters(TypeLiteral.of(String.class)).size()); - b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter})); - b.removePropertyConverters(TypeLiteral.of(String.class), Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter})); - ctx = b.build(); - assertFalse(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)); - assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).isEmpty()); - } - - @Test - public void setPropertyValueCombinationPolicy() throws Exception { - PropertyValueCombinationPolicy combPol = (currentValue, key, propertySource) -> currentValue; - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder() - .setPropertyValueCombinationPolicy(combPol); - ConfigurationContext ctx = b.build(); - assertEquals(ctx.getPropertyValueCombinationPolicy(), combPol); - } - - @Test - public void increasePriority(){ - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - TestPropertySource[] propertySources = new TestPropertySource[10]; - for(int i=0;i<propertySources.length;i++){ - propertySources[i] = new TestPropertySource("ps"+i,i); - } - b.addPropertySources(propertySources); - b.increasePriority(propertySources[propertySources.length-1]); - for(int i=0;i<propertySources.length;i++){ - assertEquals(propertySources[i], b.getPropertySources().get(i)); - } - b.increasePriority(propertySources[propertySources.length-2]); - for(int i=0;i<propertySources.length-2;i++){ - assertEquals(propertySources[i], b.getPropertySources().get(i)); - } - assertEquals(propertySources[propertySources.length-1], b.getPropertySources().get(propertySources.length-2)); - assertEquals(propertySources[propertySources.length-2], b.getPropertySources().get(propertySources.length-1)); - } - - @Test - public void decreasePriority(){ - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - TestPropertySource[] propertySources = new TestPropertySource[10]; - for(int i=0;i<propertySources.length;i++){ - propertySources[i] = new TestPropertySource("ps"+i,i); - } - b.addPropertySources(propertySources); - b.decreasePriority(propertySources[0]); - for(int i=0;i<propertySources.length;i++){ - assertEquals(propertySources[i], b.getPropertySources().get(i)); - } - b.decreasePriority(propertySources[1]); - for(int i=2;i<propertySources.length;i++){ - assertEquals(propertySources[i], b.getPropertySources().get(i)); - } - assertEquals(propertySources[0], b.getPropertySources().get(1)); - assertEquals(propertySources[1], b.getPropertySources().get(0)); - } - - @Test - public void lowestPriority(){ - // setup - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - TestPropertySource[] propertySources = new TestPropertySource[10]; - for(int i=0;i<propertySources.length;i++){ - propertySources[i] = new TestPropertySource("ps"+i,i); - } - b.addPropertySources(propertySources); - // test - b.lowestPriority(propertySources[0]); - for(int i=0;i<propertySources.length;i++){ - assertEquals(propertySources[i], b.getPropertySources().get(i)); - } - b.lowestPriority(propertySources[1]); - for(int i=2;i<propertySources.length;i++){ - assertEquals(propertySources[i], b.getPropertySources().get(i)); - } - assertEquals(propertySources[0], b.getPropertySources().get(1)); - assertEquals(propertySources[1], b.getPropertySources().get(0)); - b.lowestPriority(propertySources[5]); - assertEquals(propertySources[5], b.getPropertySources().get(0)); - } - - @Test - public void highestPriority(){ - // setup - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - TestPropertySource[] propertySources = new TestPropertySource[10]; - for(int i=0;i<propertySources.length;i++){ - propertySources[i] = new TestPropertySource("ps"+i,i); - } - b.addPropertySources(propertySources); - // test - b.highestPriority(propertySources[propertySources.length-1]); - for(int i=0;i<propertySources.length;i++){ - assertEquals(propertySources[i], b.getPropertySources().get(i)); - } - b.highestPriority(propertySources[propertySources.length-2]); - for(int i=0;i<propertySources.length-2;i++){ - assertEquals(propertySources[i], b.getPropertySources().get(i)); - } - assertEquals(propertySources[propertySources.length-2], b.getPropertySources().get(propertySources.length-1)); - assertEquals(propertySources[propertySources.length-1], b.getPropertySources().get(propertySources.length-2)); - b.highestPriority(propertySources[5]); - assertEquals(propertySources[5], b.getPropertySources().get(propertySources.length-1)); - } - - @Test - public void sortPropertySources(){ - // setup - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - TestPropertySource[] propertySources = new TestPropertySource[10]; - for(int i=0;i<propertySources.length;i++){ - propertySources[i] = new TestPropertySource("ps"+i,i); - } - b.addPropertySources(propertySources); - Comparator<PropertySource> psComp = (o1, o2) -> o1.toString().compareTo(o2.toString()); - // test - b.sortPropertySources(psComp); - Arrays.sort(propertySources, psComp); - for(int i=0;i<propertySources.length;i++){ - assertEquals(propertySources[i], b.getPropertySources().get(i)); - } - } - - @Test - public void sortPropertyFilter(){ - // setup - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - PropertyFilter[] propertyFilters = new PropertyFilter[10]; - for(int i=0;i<propertyFilters.length;i++){ - propertyFilters[i] = (value, context) -> value.toBuilder().setValue(toString() + " - ").build(); - } - b.addPropertyFilters(propertyFilters); - Comparator<PropertyFilter> pfComp = (o1, o2) -> o1.toString().compareTo(o2.toString()); - // test - b.sortPropertyFilter(pfComp); - Arrays.sort(propertyFilters, pfComp); - for(int i=0;i<propertyFilters.length;i++){ - assertEquals(propertyFilters[i], b.getPropertyFilters().get(i)); - } - } - - @Test - public void build() throws Exception { - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - ConfigurationContext ctx = b.build(); - assertNotNull(ctx); - assertTrue(ctx.getPropertySources().isEmpty()); - assertTrue(ctx.getPropertyFilters().isEmpty()); - } - - @Test - public void testRemoveAllFilters() throws Exception { - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - b.addPropertyFilters((value, context) -> value.toBuilder().setValue(toString() + " - ").build()); - assertFalse(b.getPropertyFilters().isEmpty()); - b.removePropertyFilters(b.getPropertyFilters()); - assertTrue(b.getPropertyFilters().isEmpty()); - } - - @Test - public void testRemoveAllSources() throws Exception { - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - b.addPropertySources(new TestPropertySource()); - assertFalse(b.getPropertySources().isEmpty()); - b.removePropertySources(b.getPropertySources()); - assertTrue(b.getPropertyFilters().isEmpty()); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java index 0fad63c..5257951 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java @@ -18,10 +18,11 @@ */ package org.apache.tamaya.core; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; import org.junit.Test; +import javax.config.Config; +import javax.config.ConfigProvider; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -36,22 +37,22 @@ public class ConfigurationTest { assertNotNull(current()); } - private Configuration current() { - return ConfigurationProvider.getConfiguration(); + private Config current() { + return ConfigProvider.getConfig(); } @Test public void testContent(){ - assertNotNull(current().get("name")); - assertNotNull(current().get("name2")); // from default - assertNotNull(current().get("name3")); // overridden default, mapped by filter to name property - assertNotNull(current().get("name4")); // final only + assertNotNull(current().getValue("name", String.class)); + assertNotNull(current().getValue("name2", String.class)); // from default + assertNotNull(current().getValue("name3", String.class)); // overridden default, mapped by filter to name property + assertNotNull(current().getValue("name4", String.class)); // final only - assertEquals("Robin", current().get("name")); - assertEquals("Sabine", current().get("name2")); // from default - assertEquals("Mapped to name: Robin", current().get("name3")); // overridden default, mapped by filter to name property - assertEquals("Sereina(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)", current().get("name4")); // final only - assertNull(current().get("name5")); // final only, but removed from filter + assertEquals("Robin", current().getValue("name", String.class)); + assertEquals("Sabine", current().getValue("name2", String.class)); // from default + assertEquals("Mapped to name: Robin", current().getValue("name3", String.class)); // overridden default, mapped by filter to name property + assertEquals("Sereina(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)", current().getValue("name4", String.class)); // final only + assertNull(current().getValue("name5", String.class)); // final only, but removed from filter } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/core/src/test/java/org/apache/tamaya/core/TestPropertySource.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/TestPropertySource.java b/code/core/src/test/java/org/apache/tamaya/core/TestPropertySource.java deleted file mode 100644 index 7ec4458..0000000 --- a/code/core/src/test/java/org/apache/tamaya/core/TestPropertySource.java +++ /dev/null @@ -1,72 +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.core; - -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spi.PropertyValue; - -import java.util.Collections; -import java.util.Date; -import java.util.Map; - -/** - * Created by atsticks on 18.10.16. - */ -public class TestPropertySource implements PropertySource { - - private String id; - private int ordinal; - - public TestPropertySource() { - this("TestPropertySource", 0); - } - - public TestPropertySource(String id, int ordinal) { - this.id = id; - this.ordinal = ordinal; - } - - public int getOrdinal() { - return ordinal; - } - - @Override - public String getName() { - return id != null ? id : "TestPropertySource"; - } - - @Override - public PropertyValue get(String key) { - return PropertyValue.builder(key, key + "Value", getName()) - .addMetaEntry("ordinal", String.valueOf(getOrdinal())) - .addMetaEntry("createdAt", String.valueOf(new Date())) - .build(); - } - - @Override - public Map<String, PropertyValue> getProperties() { - return Collections.emptyMap(); - } - - @Override - public boolean isScannable() { - return false; - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/core/src/test/java/org/apache/tamaya/core/internal/BannerManagerTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/BannerManagerTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/BannerManagerTest.java deleted file mode 100644 index 9fc4433..0000000 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/BannerManagerTest.java +++ /dev/null @@ -1,90 +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.core.internal; - -import org.junit.Test; -import org.mockito.Mockito; - -import java.io.PrintStream; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.Permission; - -/* - * Note: - * The tests of this class will fail PIT, our coverage tool. - * Therefore we excluded this class in the parent POM - * from the test execution. - * Oliver B. Fischer, 2017-09-16 - */ -public class BannerManagerTest { - - @Test - public void valueConsoleSendsBannerToSystemOut() { - - SecurityManager sm = new SecurityManager(); - AccessControlContext con = AccessController.getContext(); - - Permission p = new RuntimePermission("setIO"); - - /* - * Here we check the precondition for this unit test - * and the correct setup of the test environment - * The JVM must have been started with - * -Djava.security.policy=<path_to_core_module</src/test/resources/java-security.policy - */ - sm.checkPermission(p, con); - - PrintStream standard = System.out; - PrintStream printStream = Mockito.mock(PrintStream.class); - - System.setOut(printStream); - standard.println("Changed stream for STDOUT successfully"); - - try { - BannerManager bm = new BannerManager("console"); - bm.outputBanner(); - - } finally { - System.setOut(standard); - } - - Mockito.verify(printStream, Mockito.atLeastOnce()).println(Mockito.anyString()); - } - - @Test - public void invalidValueAvoidsLoggingToConsonle() { - - PrintStream standard = System.out; - PrintStream printStream = Mockito.mock(PrintStream.class); - - System.setOut(printStream); - - try { - BannerManager bm = new BannerManager("snafu"); - bm.outputBanner(); - - } finally { - System.setOut(standard); - } - - Mockito.verify(printStream, Mockito.never()).println(Mockito.anyString()); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/core/src/test/java/org/apache/tamaya/core/internal/CTestConverter.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/CTestConverter.java b/code/core/src/test/java/org/apache/tamaya/core/internal/CTestConverter.java index 7ee2a35..42dd5dd 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/CTestConverter.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/CTestConverter.java @@ -18,15 +18,14 @@ */ package org.apache.tamaya.core.internal; -import org.apache.tamaya.spi.ConversionContext; -import org.apache.tamaya.spi.PropertyConverter; +import javax.config.spi.Converter; /** * Created by Anatole on 13.06.2015. */ -public class CTestConverter implements PropertyConverter<C>{ +public class CTestConverter implements Converter<C> { @Override - public C convert(String value, ConversionContext context) { + public C convert(String value) { return new C(value); } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationBuilderTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationBuilderTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationBuilderTest.java deleted file mode 100644 index 37dc2cb..0000000 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationBuilderTest.java +++ /dev/null @@ -1,219 +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.core.internal; - -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.spi.*; -import org.junit.Test; - -import java.util.Collections; -import java.util.Map; - -import static org.junit.Assert.*; - -/** - * Tests for {@link CoreConfigurationBuilder} by atsticks on 06.09.16. - */ -public class CoreConfigurationBuilderTest { - - private TestPropertySource testPropertySource = new TestPropertySource(){}; - - @Test - public void setContext() throws Exception { - ConfigurationContext context = ConfigurationProvider.getConfiguration().getContext(); - ConfigurationBuilder b = new CoreConfigurationBuilder() - .setContext(context); - assertEquals(context, b.build().getContext()); - } - - @Test - public void setConfiguration() throws Exception { - Configuration cfg = ConfigurationProvider.getConfiguration(); - ConfigurationBuilder b = new CoreConfigurationBuilder() - .setConfiguration(cfg); - assertEquals(cfg, b.build()); - } - - @Test - public void addPropertySources_Array() throws Exception { - PropertySource testPS2 = new TestPropertySource("addPropertySources_Array_2"); - ConfigurationBuilder b = new CoreConfigurationBuilder() - .addPropertySources(testPropertySource, testPS2); - Configuration cfg = b.build(); - ConfigurationContext ctx = cfg.getContext(); - assertEquals(2, ctx.getPropertySources().size()); - assertTrue(ctx.getPropertySources().contains(testPropertySource)); - assertTrue(ctx.getPropertySources().contains(testPS2)); - } - - @Test - public void removePropertySources_Array() throws Exception { - PropertySource testPS2 = new TestPropertySource("addPropertySources_Array_2"); - ConfigurationBuilder b = new CoreConfigurationBuilder() - .addPropertySources(testPropertySource, testPS2); - Configuration cfg = b.build(); - ConfigurationContext ctx = cfg.getContext(); - assertEquals(2, ctx.getPropertySources().size()); - assertTrue(ctx.getPropertySources().contains(testPropertySource)); - assertTrue(ctx.getPropertySources().contains(testPS2)); - b = new CoreConfigurationBuilder() - .addPropertySources(testPropertySource, testPS2); - b.removePropertySources(testPropertySource); - cfg = b.build(); - ctx = cfg.getContext(); - assertEquals(1, ctx.getPropertySources().size()); - assertFalse(ctx.getPropertySources().contains(testPropertySource)); - assertTrue(ctx.getPropertySources().contains(testPS2)); - } - - @Test - public void addPropertyFilters_Array() throws Exception { - PropertyFilter filter1 = (value, context) -> value; - PropertyFilter filter2 = (value, context) -> value; - CoreConfigurationBuilder b = new CoreConfigurationBuilder(); - b.addPropertyFilters(filter1, filter2); - Configuration cfg = b.build(); - ConfigurationContext ctx = cfg.getContext(); - assertTrue(ctx.getPropertyFilters().contains(filter1)); - assertTrue(ctx.getPropertyFilters().contains(filter2)); - assertEquals(2, ctx.getPropertyFilters().size()); - b = new CoreConfigurationBuilder(); - b.addPropertyFilters(filter1, filter2); - b.addPropertyFilters(filter1, filter2); - assertEquals(2, ctx.getPropertyFilters().size()); - } - - @Test - public void removePropertyFilters_Array() throws Exception { - PropertyFilter filter1 = (value, context) -> value; - PropertyFilter filter2 = (value, context) -> value; - ConfigurationBuilder b = new CoreConfigurationBuilder() - .addPropertyFilters(filter1, filter2); - Configuration cfg = b.build(); - ConfigurationContext ctx = cfg.getContext(); - assertTrue(ctx.getPropertyFilters().contains(filter1)); - assertTrue(ctx.getPropertyFilters().contains(filter2)); - assertEquals(2, ctx.getPropertyFilters().size()); - b = new CoreConfigurationBuilder() - .addPropertyFilters(filter1, filter2); - b.removePropertyFilters(filter1); - cfg = b.build(); - ctx = cfg.getContext(); - assertEquals(1, ctx.getPropertyFilters().size()); - assertFalse(ctx.getPropertyFilters().contains(filter1)); - assertTrue(ctx.getPropertyFilters().contains(filter2)); - } - - @Test - @SuppressWarnings({ "rawtypes", "unchecked" }) - public void addPropertyConverter() throws Exception { - PropertyConverter converter = (value, context) -> value.toLowerCase(); - ConfigurationBuilder b = new CoreConfigurationBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), converter); - Configuration cfg = b.build(); - ConfigurationContext ctx = cfg.getContext(); - assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)); - assertEquals(1, ctx.getPropertyConverters().size()); - b = new CoreConfigurationBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), converter); - b.addPropertyConverters(TypeLiteral.of(String.class), converter); - assertEquals(1, ctx.getPropertyConverters().size()); - } - - @Test - @SuppressWarnings({ "rawtypes", "unchecked" }) - public void removePropertyConverters_Array() throws Exception { - PropertyConverter converter = (value, context) -> value.toLowerCase(); - ConfigurationBuilder b = new CoreConfigurationBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), converter); - Configuration cfg = b.build(); - ConfigurationContext ctx = cfg.getContext(); - assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)); - assertEquals(1, ctx.getPropertyConverters(TypeLiteral.of(String.class)).size()); - b = new CoreConfigurationBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), converter); - b.removePropertyConverters(TypeLiteral.of(String.class), converter); - cfg = b.build(); - ctx = cfg.getContext(); - assertFalse(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)); - assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).isEmpty()); - } - - @Test - public void setPropertyValueCombinationPolicy() throws Exception { - PropertyValueCombinationPolicy combPol = (currentValue, key, propertySource) -> currentValue; - ConfigurationBuilder b = new CoreConfigurationBuilder() - .setPropertyValueCombinationPolicy(combPol); - Configuration cfg = b.build(); - ConfigurationContext ctx = cfg.getContext(); - assertEquals(ctx.getPropertyValueCombinationPolicy(), combPol); - } - - @Test - public void build() throws Exception { - assertNotNull(new CoreConfigurationBuilder().build()); - } - - @Test - public void bla() throws Exception { - ConfigurationBuilder builder = ConfigurationProvider.getConfigurationBuilder(); - builder.addDefaultPropertyConverters(); - } - - private static class TestPropertySource implements PropertySource{ - - private String id; - - public TestPropertySource(){ - this(null); - } - - public TestPropertySource(String id){ - this.id = id; - } - - @Override - public int getOrdinal() { - return 200; - } - - @Override - public String getName() { - return id!=null?id:"TestPropertySource"; - } - - @Override - public PropertyValue get(String key) { - return PropertyValue.of(key, key + "Value", getName()); - } - - @Override - public Map<String, PropertyValue> getProperties() { - return Collections.emptyMap(); - } - - @Override - public boolean isScannable() { - return false; - } - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationProviderTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationProviderTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationProviderTest.java deleted file mode 100644 index e4dab56..0000000 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationProviderTest.java +++ /dev/null @@ -1,93 +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.core.internal; - -import org.apache.tamaya.Configuration; -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Created by atsticks on 11.09.16. - */ -public class CoreConfigurationProviderTest { - - @Test - public void testInstantiation() throws Exception { - new CoreConfigurationProvider(); - } - - @Test - public void getConfiguration() throws Exception { - assertNotNull(new CoreConfigurationProvider().getConfiguration()); - } - - @Test - public void createConfiguration() throws Exception { - Configuration cfg = new CoreConfigurationBuilder().build(); - assertNotNull(new CoreConfigurationProvider().createConfiguration(cfg.getContext())); - assertEquals(cfg, - new CoreConfigurationProvider().createConfiguration(cfg.getContext())); - } - - @Test - public void getConfigurationContext() throws Exception { - assertNotNull(new CoreConfigurationProvider().getConfigurationContext()); - assertEquals(new CoreConfigurationProvider().getConfigurationContext(), - new CoreConfigurationProvider().getConfiguration().getContext()); - } - - @Test - public void getConfigurationContextBuilder() throws Exception { - assertNotNull(new CoreConfigurationProvider().getConfigurationContextBuilder()); - } - - @Test - public void getConfigurationBuilder() throws Exception { - assertNotNull(new CoreConfigurationProvider().getConfigurationBuilder()); - } - - @SuppressWarnings("deprecation") - @Test - public void setConfigurationContext() throws Exception { - new CoreConfigurationProvider() - .setConfigurationContext(new CoreConfigurationProvider().getConfiguration().getContext()); - } - - @SuppressWarnings("deprecation") - @Test - public void setConfiguration() throws Exception { - new CoreConfigurationProvider() - .setConfiguration(new CoreConfigurationProvider().getConfiguration()); - } - - @SuppressWarnings("deprecation") - @Test - public void isConfigurationContextSettable() throws Exception { - assertTrue(new CoreConfigurationProvider().isConfigurationContextSettable()); - } - - @SuppressWarnings("deprecation") - @Test - public void isConfigurationSettable() throws Exception { - assertTrue(new CoreConfigurationProvider().isConfigurationSettable()); - } - - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationTest.java deleted file mode 100644 index 6b8d1dc..0000000 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationTest.java +++ /dev/null @@ -1,177 +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.core.internal; - -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.core.testdata.TestPropertyDefaultSource; -import org.apache.tamaya.spi.*; -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Simple tests for {@link CoreConfiguration} by atsticks on 16.08.16. - */ -public class CoreConfigurationTest { - - @Test - public void addPropertySources() throws Exception { - Configuration cfg = new CoreConfigurationBuilder().build(); - TestPropertyDefaultSource def = new TestPropertyDefaultSource(); - assertFalse(cfg.getContext().getPropertySources().contains(def)); - cfg.getContext().addPropertySources(def); - assertTrue(cfg.getContext().getPropertySources().contains(def)); - } - - @Test - public void testToString() throws Exception { - String toString = ConfigurationProvider.getConfiguration().getContext().toString(); - } - - @Test - public void getPropertySources() throws Exception { - Configuration cfg = new CoreConfigurationBuilder().build(); - assertNotNull(cfg.getContext().getPropertySources()); - assertEquals(cfg.getContext().getPropertySources().size(), 0); - cfg = new CoreConfigurationBuilder().addDefaultPropertySources().build(); - assertNotNull(cfg.getContext().getPropertySources()); - assertEquals(7, cfg.getContext().getPropertySources().size()); - } - - @Test - public void getPropertySource() throws Exception { - TestPropertyDefaultSource ps = new TestPropertyDefaultSource(); - Configuration cfg = new CoreConfigurationBuilder() - .addPropertySources(ps).build(); - assertNotNull(cfg.getContext().getPropertySources()); - assertEquals(cfg.getContext().getPropertySources().size(), 1); - assertNotNull((cfg.getContext()).getPropertySource(ps.getName())); - assertEquals(ps.getName(), cfg.getContext().getPropertySource(ps.getName()).getName()); - assertNull(cfg.getContext().getPropertySource("huhu")); - - } - - @Test - public void testHashCode() throws Exception { - TestPropertyDefaultSource ps = new TestPropertyDefaultSource(); - Configuration cfg1 = new CoreConfigurationBuilder() - .addPropertySources(ps).build(); - Configuration cfg2 = new CoreConfigurationBuilder() - .addPropertySources(ps).build(); - assertEquals(cfg1.hashCode(), cfg2.hashCode()); - cfg2 = new CoreConfigurationBuilder() - .build(); - assertNotEquals(cfg1.hashCode(), cfg2.hashCode()); - - } - - @Test - public void addPropertyConverter() throws Exception { - Configuration cfg = new CoreConfigurationBuilder().build(); - PropertyConverter testConverter = new PropertyConverter() { - @Override - public Object convert(String value, ConversionContext context) { - return ""; - } - }; - assertFalse(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter)); - cfg.getContext().addPropertyConverter(TypeLiteral.of(String.class), testConverter); - assertTrue(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter)); - } - - @Test - public void getPropertyConverters() throws Exception { - Configuration cfg = new CoreConfigurationBuilder().build(); - PropertyConverter testConverter = new PropertyConverter() { - @Override - public Object convert(String value, ConversionContext context) { - return ""; - } - }; - cfg.getContext().addPropertyConverter(TypeLiteral.of(String.class), testConverter); - assertNotNull(cfg.getContext().getPropertyConverters()); - assertTrue(cfg.getContext().getPropertyConverters().containsKey(TypeLiteral.of(String.class))); - assertTrue(cfg.getContext().getPropertyConverters().get(TypeLiteral.of(String.class)).contains(testConverter)); - testConverter = new PropertyConverter() { - @Override - public Object convert(String value, ConversionContext context) { - return Integer.valueOf(5); - } - }; - cfg.getContext().addPropertyConverter(TypeLiteral.of(Integer.class), testConverter); - assertTrue(cfg.getContext().getPropertyConverters().containsKey(TypeLiteral.of(Integer.class))); - assertTrue(cfg.getContext().getPropertyConverters().get(TypeLiteral.of(Integer.class)).contains(testConverter)); - } - - @Test - public void getPropertyConverters1() throws Exception { - Configuration cfg = new CoreConfigurationBuilder().build(); - PropertyConverter testConverter = new PropertyConverter() { - @Override - public Object convert(String value, ConversionContext context) { - return ""; - } - }; - assertNotNull(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class))); - assertEquals(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class)).size(),0); - cfg.getContext().addPropertyConverter(TypeLiteral.of(String.class), testConverter); - assertNotNull(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class))); - assertEquals(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class)).size(),1); - assertTrue(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter)); - - } - - @Test - public void getPropertyFilters() throws Exception { - Configuration cfg = new CoreConfigurationBuilder().build(); - PropertyFilter testFilter = new PropertyFilter() { - - @Override - public PropertyValue filterProperty(PropertyValue value, FilterContext context) { - return value; - } - }; - assertNotNull(cfg.getContext().getPropertyFilters()); - assertFalse(cfg.getContext().getPropertyFilters().contains(testFilter)); - cfg = cfg.toBuilder().addPropertyFilters(testFilter).build(); - assertTrue(cfg.getContext().getPropertyFilters().contains(testFilter)); - } - - @Test - public void getPropertyValueCombinationPolicy() throws Exception { - Configuration cfg = new CoreConfigurationBuilder().build(); - assertNotNull(cfg.getContext().getPropertyValueCombinationPolicy()); - assertEquals(cfg.getContext().getPropertyValueCombinationPolicy(), - PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_POLICY); - } - - @Test - public void toBuilder() throws Exception { - assertNotNull(new CoreConfigurationBuilder().build().toBuilder()); - } - - @Test - public void testRoundTrip() throws Exception { - Configuration cfg = new CoreConfigurationBuilder().build(); - assertEquals(cfg.toBuilder().build(), cfg); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultJavaConfigurationTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultJavaConfigurationTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultJavaConfigurationTest.java index a1d638f..07871ba 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultJavaConfigurationTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultJavaConfigurationTest.java @@ -1,50 +1,48 @@ -/* - * 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.internal; - -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spisupport.propertysource.JavaConfigurationPropertySource; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; - -import static org.apache.tamaya.ConfigurationProvider.getConfiguration; - -public class DefaultJavaConfigurationTest { - - private static final String A_UMLAUT = "\u00E4"; - private static final String O_UMLAUT = "\u00F6"; - - @Test - public void loadsSimpleAndXMLPropertyFilesProper() { - for (int i = 1; i < 6; i++) { - String key = "confkey" + i; - String value = "javaconf-value" + i; - // check if we had our key in configuration.current - MatcherAssert.assertThat(getConfiguration().getProperties().containsKey(key), Matchers.is(true)); - MatcherAssert.assertThat(value, Matchers.equalTo(getConfiguration().get(key))); - } - - MatcherAssert.assertThat(getConfiguration().getProperties().containsKey("aaeehh"), Matchers.is(true)); - MatcherAssert.assertThat(getConfiguration().getProperties().get("aaeehh"), Matchers.equalTo(A_UMLAUT)); - - MatcherAssert.assertThat(getConfiguration().getProperties().containsKey(O_UMLAUT), Matchers.is(true)); - MatcherAssert.assertThat(getConfiguration().getProperties().get(O_UMLAUT), Matchers.equalTo("o")); - } -} +///* +// * 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.internal; +// +//import org.hamcrest.MatcherAssert; +//import org.hamcrest.Matchers; +//import org.junit.Test; +// +//import javax.config.ConfigProvider; +// +//public class DefaultJavaConfigurationTest { +// +// private static final String A_UMLAUT = "\u00E4"; +// private static final String O_UMLAUT = "\u00F6"; +// +// @Test +// public void loadsSimpleAndXMLPropertyFilesProper() { +// for (int i = 1; i < 6; i++) { +// String key = "confkey" + i; +// String value = "javaconf-value" + i; +// // check if we had our key in configuration.current +//// MatcherAssert.assertThat(ConfigProvider.getConfig().getPropertyNames().iterator(key), Matchers.is(true)); +// MatcherAssert.assertThat(value, Matchers.equalTo(ConfigProvider.getConfig().getValue(key, String.class))); +// } +// +//// MatcherAssert.assertThat(ConfigProvider.getConfig().getProperties().containsKey("aaeehh"), Matchers.is(true)); +// MatcherAssert.assertThat(ConfigProvider.getConfig().getValue("aaeehh", String.class), Matchers.equalTo(A_UMLAUT)); +// +//// MatcherAssert.assertThat(ConfigProvider.getConfig().getProperties().containsKey(O_UMLAUT), Matchers.is(true)); +// MatcherAssert.assertThat(ConfigProvider.getConfig().getValue(O_UMLAUT, String.class), Matchers.equalTo("o")); +// } +//} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BigDecimalConverterTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BigDecimalConverterTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BigDecimalConverterTest.java index 91d3bb8..608e29f 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BigDecimalConverterTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/BigDecimalConverterTest.java @@ -18,18 +18,20 @@ */ package org.apache.tamaya.core.internal.converters; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.spi.ConversionContext; + + +import org.apache.tamaya.base.convert.ConversionContext; +import org.apache.tamaya.core.converters.BigDecimalConverter; import org.junit.Test; +import javax.config.Config; +import javax.config.ConfigProvider; import java.math.BigDecimal; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; +import static org.junit.Assert.assertTrue; /** * Tests the default converter for bytes. @@ -44,8 +46,8 @@ public class BigDecimalConverterTest { */ @Test public void testConvert_BigDecimal_Decimal() throws Exception { - Configuration config = ConfigurationProvider.getConfiguration(); - BigDecimal valueRead = config.get("tests.converter.bd.decimal", BigDecimal.class); + Config config = ConfigProvider.getConfig(); + BigDecimal valueRead = config.getValue("tests.converter.bd.decimal", BigDecimal.class); assertThat(valueRead).isNotNull(); assertEquals(new BigDecimal(101), valueRead); } @@ -58,11 +60,11 @@ public class BigDecimalConverterTest { */ @Test public void testConvert_BigDecimal_Hex() throws Exception { - Configuration config = ConfigurationProvider.getConfiguration(); - BigDecimal valueRead = config.get("tests.converter.bd.hex.lowerX", BigDecimal.class); + Config config = ConfigProvider.getConfig(); + BigDecimal valueRead = config.getValue("tests.converter.bd.hex.lowerX", BigDecimal.class); assertThat(valueRead).isNotNull(); assertEquals(new BigDecimal("47"), valueRead); - valueRead = config.get("tests.converter.bd.hex.upperX", BigDecimal.class); + valueRead = config.getValue("tests.converter.bd.hex.upperX", BigDecimal.class); assertThat(valueRead).isNotNull(); assertEquals(new BigDecimal("63"), valueRead); } @@ -75,8 +77,8 @@ public class BigDecimalConverterTest { */ @Test public void testConvert_NotPresent() throws Exception { - Configuration config = ConfigurationProvider.getConfiguration(); - BigDecimal valueRead = config.get("tests.converter.bd.foo", BigDecimal.class); + Config config = ConfigProvider.getConfig(); + BigDecimal valueRead = config.getValue("tests.converter.bd.foo", BigDecimal.class); assertNull(valueRead); } @@ -88,8 +90,8 @@ public class BigDecimalConverterTest { */ @Test public void testConvert_BigDecimal_BigValue() throws Exception { - Configuration config = ConfigurationProvider.getConfiguration(); - BigDecimal valueRead = config.get("tests.converter.bd.big", BigDecimal.class); + Config config = ConfigProvider.getConfig(); + BigDecimal valueRead = config.getValue("tests.converter.bd.big", BigDecimal.class); assertThat(valueRead).isNotNull(); assertEquals(new BigDecimal("101666666666666662333337263723628763821638923628193612983618293628763"), valueRead); @@ -103,8 +105,8 @@ public class BigDecimalConverterTest { */ @Test public void testConvert_BigDecimal_BigFloatValue() throws Exception { - Configuration config = ConfigurationProvider.getConfiguration(); - BigDecimal valueRead = config.get("tests.converter.bd.bigFloat", BigDecimal.class); + Config config = ConfigProvider.getConfig(); + BigDecimal valueRead = config.getValue("tests.converter.bd.bigFloat", BigDecimal.class); assertThat(valueRead).isNotNull(); assertEquals(new BigDecimal("1016666666666666623333372637236287638216389293628763.1016666666666666623333372" + "63723628763821638923628193612983618293628763"), valueRead); @@ -112,22 +114,23 @@ public class BigDecimalConverterTest { @Test public void converterHandlesNullValueCorrectly() throws Exception { - ConversionContext context = mock(ConversionContext.class); - + ConversionContext context = new ConversionContext.Builder("key", BigDecimal.class).build(); + ConversionContext.setContext(context); BigDecimalConverter converter = new BigDecimalConverter(); - BigDecimal value = converter.convert("", context); - + BigDecimal value = converter.convert(""); + ConversionContext.reset(); assertThat(value).isNull(); } @Test public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { - ConversionContext context = mock(ConversionContext.class); + ConversionContext context = new ConversionContext.Builder("<nokey>", BigDecimal.class).build(); + ConversionContext.setContext(context); BigDecimalConverter converter = new BigDecimalConverter(); - BigDecimal value = converter.convert("", context); - + BigDecimal value = converter.convert(""); + assertTrue(context.getSupportedFormats().contains("<BigDecimal> -> new BigDecimal(String) (BigDecimalConverter)")); + ConversionContext.reset(); assertThat(value).isNull(); - verify(context).addSupportedFormats(BigDecimalConverter.class, "<bigDecimal> -> new BigDecimal(String)"); } } \ No newline at end of file