http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/main/resources/tamaya-banner.txt ---------------------------------------------------------------------- diff --git a/code/old/api/src/main/resources/tamaya-banner.txt b/code/old/api/src/main/resources/tamaya-banner.txt new file mode 100644 index 0000000..b4ceca4 --- /dev/null +++ b/code/old/api/src/main/resources/tamaya-banner.txt @@ -0,0 +1,11 @@ + + ââââââ âââââââ ââââââ ââââââââââ âââââââââââ âââââââââ ââââââ ââââ ââââ ââââââ âââ âââ ââââââ +âââââââââââââââââââââââââââââââââââ âââââââââââ ââââââââââââââââââââââ âââââââââââââââââ ââââââââââââ +âââââââââââââââââââââââââââ ââââââââââââââ âââ âââââââââââââââââââââââââââ âââââââ ââââââââ +âââââââââââââââ âââââââââââ ââââââââââââââ âââ âââââââââââââââââââââââââââ âââââ ââââââââ +âââ ââââââ âââ ââââââââââââââ âââââââââââ âââ âââ ââââââ âââ ââââââ âââ âââ âââ âââ +âââ ââââââ âââ âââ ââââââââââ âââââââââââ âââ âââ ââââââ ââââââ âââ âââ âââ âââ + +Apache Tamaya Configuration API: http://tamaya.incubator.apache.org + +
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/test/java/org/apache/tamaya/ConfigExceptionTest.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/test/java/org/apache/tamaya/ConfigExceptionTest.java b/code/old/api/src/test/java/org/apache/tamaya/ConfigExceptionTest.java new file mode 100644 index 0000000..fa7da0a --- /dev/null +++ b/code/old/api/src/test/java/org/apache/tamaya/ConfigExceptionTest.java @@ -0,0 +1,45 @@ +/* + * 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; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests instantiating {@link ConfigException}. + */ +public class ConfigExceptionTest { + + @Test + public void testCreationMessage(){ + ConfigException ex = new ConfigException("test"); + assertNull(ex.getCause()); + assertEquals(ex.getMessage(), "test"); + } + + @Test + public void testCreationMessageThrowable(){ + Exception e = new IllegalStateException("blabla"); + ConfigException ex = new ConfigException("test", e); + assertTrue(ex.getCause() == e); + assertEquals("test", ex.getMessage()); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/test/java/org/apache/tamaya/ConfigurationTest.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/test/java/org/apache/tamaya/ConfigurationTest.java b/code/old/api/src/test/java/org/apache/tamaya/ConfigurationTest.java new file mode 100644 index 0000000..ecbb75c --- /dev/null +++ b/code/old/api/src/test/java/org/apache/tamaya/ConfigurationTest.java @@ -0,0 +1,63 @@ +/* + * 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; + +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * Test class that tests the default methods implemented on {@link org.apache.tamaya.Configuration}. The provided + * {@link org.apache.tamaya.TestConfiguration} is implemeted with maximal use of the default methods. + */ +public class ConfigurationTest { + + @Test + public void testget() throws Exception { + assertEquals(Boolean.TRUE, ConfigurationProvider.getConfiguration().get("booleanTrue", Boolean.class)); + assertEquals(Boolean.FALSE, ConfigurationProvider.getConfiguration().get("booleanFalse", Boolean.class)); + assertEquals((int)Byte.MAX_VALUE, (int)ConfigurationProvider.getConfiguration().get("byte", Byte.class)); + assertEquals(Integer.MAX_VALUE, (int)ConfigurationProvider.getConfiguration().get("int", Integer.class)); + assertEquals(Long.MAX_VALUE, (long)ConfigurationProvider.getConfiguration().get("long", Long.class)); + assertEquals(Float.MAX_VALUE, (double)ConfigurationProvider.getConfiguration().get("float", Float.class), 0.0d); + assertEquals(Double.MAX_VALUE, ConfigurationProvider.getConfiguration().get("double", Double.class), 0.0d); + } + + @Test + public void testGetBoolean() throws Exception { + assertTrue(ConfigurationProvider.getConfiguration().get("booleanTrue", Boolean.class)); + assertFalse(ConfigurationProvider.getConfiguration().get("booleanFalse", Boolean.class)); + assertFalse(ConfigurationProvider.getConfiguration().get("foorBar", Boolean.class)); + } + + @Test + public void testGetInteger() throws Exception { + assertEquals(Integer.MAX_VALUE,(int) ConfigurationProvider.getConfiguration().get("int", Integer.class)); + } + + @Test + public void testGetLong() throws Exception { + assertEquals(Long.MAX_VALUE,(long) ConfigurationProvider.getConfiguration().get("long", Long.class)); + } + + @Test + public void testGetDouble() throws Exception { + assertEquals(Double.MAX_VALUE,ConfigurationProvider.getConfiguration().get("double", Double.class), 0.0d); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/test/java/org/apache/tamaya/TestConfiguration.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/test/java/org/apache/tamaya/TestConfiguration.java b/code/old/api/src/test/java/org/apache/tamaya/TestConfiguration.java new file mode 100644 index 0000000..f50c1dc --- /dev/null +++ b/code/old/api/src/test/java/org/apache/tamaya/TestConfiguration.java @@ -0,0 +1,137 @@ +/* + * 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; + + +import org.apache.tamaya.spi.ConfigurationContext; + +import java.util.HashMap; +import java.util.Map; + +/** + * Test Configuration class, that is used to testdata the default methods provided by the API. + */ +public class TestConfiguration implements Configuration{ + + private static final Map<String, String> VALUES; + static { + VALUES = new HashMap<>(); + VALUES.put("long", String.valueOf(Long.MAX_VALUE)); + VALUES.put("int", String.valueOf(Integer.MAX_VALUE)); + VALUES.put("double", String.valueOf(Double.MAX_VALUE)); + VALUES.put("float", String.valueOf(Float.MAX_VALUE)); + VALUES.put("short", String.valueOf(Short.MAX_VALUE)); + VALUES.put("byte", String.valueOf(Byte.MAX_VALUE)); + VALUES.put("booleanTrue", "true"); + VALUES.put("booleanFalse", "false"); + VALUES.put("String", "aStringValue"); + } + + @Override + public String get(String key) { + return VALUES.get(key); + } + + @Override + public String getOrDefault(String key, String defaultValue) { + String val = get(key); + if(val==null){ + return defaultValue; + } + return val; + } + + @Override + public <T> T getOrDefault(String key, Class<T> type, T defaultValue) { + T val = get(key, type); + if(val==null){ + return defaultValue; + } + return val; + } + + @SuppressWarnings("unchecked") + @Override + public <T> T get(String key, Class<T> type) { + if(type.equals(Long.class)){ + return (T)(Object)Long.MAX_VALUE; + } + else if(type.equals(Integer.class)){ + return (T)(Object) Integer.MAX_VALUE; + } + else if(type.equals(Double.class)){ + return (T)(Object) Double.MAX_VALUE; + } + else if(type.equals(Float.class)){ + return (T)(Object) Float.MAX_VALUE; + } + else if(type.equals(Short.class)){ + return (T)(Object) Short.MAX_VALUE; + } + else if(type.equals(Byte.class)){ + return (T)(Object) Byte.MAX_VALUE; + } + else if(type.equals(Boolean.class)){ + if("booleanTrue".equals(key)) { + return (T)Boolean.TRUE; + } + else{ + return (T)Boolean.FALSE; + } + } + else if(type.equals(String.class)){ + return (T)"aStringValue"; + } + throw new ConfigException("No such property: " + key); + } + + @Override + public <T> T get(String key, TypeLiteral<T> type) { + throw new RuntimeException("Method not implemented yet."); + } + + @Override + public <T> T getOrDefault(String key, TypeLiteral<T> type, T defaultValue) { + T val = get(key, type); + if(val==null){ + return defaultValue; + } + return val; + } + + @Override + public Configuration with(ConfigOperator operator) { + return null; + } + + @Override + public <T> T query(ConfigQuery<T> query) { + throw new RuntimeException("Method not implemented yet."); + } + + @Override + public ConfigurationContext getContext() { + return null; + } + + @Override + public Map<String, String> getProperties() { + throw new RuntimeException("Method not implemented yet."); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java b/code/old/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java new file mode 100644 index 0000000..1ccce31 --- /dev/null +++ b/code/old/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java @@ -0,0 +1,79 @@ +/* + * 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; + +import javax.annotation.Priority; + +import org.apache.tamaya.spi.ConfigurationContext; +import org.apache.tamaya.spi.ConfigurationBuilder; +import org.apache.tamaya.spi.ConfigurationContextBuilder; +import org.apache.tamaya.spi.ConfigurationProviderSpi; + +/** + * Test Configuration class, that is used to testdata the default methods provided by the API. + */ +@Priority(-1) +public class TestConfigurationProvider implements ConfigurationProviderSpi { + + private static final Configuration config = new TestConfiguration(); + + @Override + public Configuration getConfiguration() { + return config; + } + + @Override + public Configuration createConfiguration(ConfigurationContext context) { + return config; + } + + @Override + public ConfigurationContext getConfigurationContext() { + return config.getContext(); + } + + @Override + public void setConfigurationContext(ConfigurationContext context) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean isConfigurationContextSettable() { + return false; + } + + @Override + public ConfigurationBuilder getConfigurationBuilder() { + return null; + } + + @Override + public ConfigurationContextBuilder getConfigurationContextBuilder() { + return null; + } + + @Override + public void setConfiguration(Configuration config) { + } + + @Override + public boolean isConfigurationSettable() { + return false; + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/test/java/org/apache/tamaya/TypeLiteralTest.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/test/java/org/apache/tamaya/TypeLiteralTest.java b/code/old/api/src/test/java/org/apache/tamaya/TypeLiteralTest.java new file mode 100644 index 0000000..7435e08 --- /dev/null +++ b/code/old/api/src/test/java/org/apache/tamaya/TypeLiteralTest.java @@ -0,0 +1,90 @@ +/* + * 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; + +import static org.apache.tamaya.TypeLiteral.getGenericInterfaceTypeParameters; +import static org.apache.tamaya.TypeLiteral.getTypeParameters; +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.Test; + +/** + * Tests for the {@link TypeLiteral} class. + */ +@SuppressWarnings("serial") +public class TypeLiteralTest { + + @Test(expected = NullPointerException.class) + public void constructorRequiresNonNullParameter() { + new TypeLiteral<List<String>>(null){}; + } + + @Test + public void test_constrcutor(){ + TypeLiteral<List<String>> listTypeLiteral = new TypeLiteral<List<String>>(){}; + assertEquals(List.class, listTypeLiteral.getRawType()); + assertEquals(String.class, TypeLiteral.getTypeParameters(listTypeLiteral.getType())[0]); + } + + @Test + public void test_of(){ + class MyListClass extends ArrayList<String>{} + TypeLiteral<MyListClass> listTypeLiteral = TypeLiteral.of(MyListClass.class); + assertEquals(MyListClass.class, listTypeLiteral.getRawType()); + assertEquals(MyListClass.class, listTypeLiteral.getType()); + } + + @Test(expected = NullPointerException.class) + public void ofDoesNotAcceptNullAsParamter() { + TypeLiteral.of(null); + } + + @Test + public void test_getTypeParameter(){ + TypeLiteral<List<String>> listTypeLiteral = new TypeLiteral<List<String>>(){}; + assertEquals(List.class, listTypeLiteral.getRawType()); + assertEquals(String.class, TypeLiteral.getTypeParameters(listTypeLiteral.getType())[0]); + } + + @Test + public void test_getGenericInterfaceTypeParameter(){ + class MyListClass extends ArrayList<String> implements List<String>{} + assertEquals(String.class, getGenericInterfaceTypeParameters(MyListClass.class, List.class)[0]); + } + + @Test(expected = NullPointerException.class) + public void getGenericInterfaceTypeParametersRequiredNonNullValueForClassParameter() { + getGenericInterfaceTypeParameters(null, Iterator.class); + } + + @Test(expected = NullPointerException.class) + public void getGenericInterfaceTypeParametersRequiredNonNullValueForInterfaceParameter() { + getGenericInterfaceTypeParameters(String.class, null); + } + + @Test(expected = NullPointerException.class) + public void getTypeParametersRequiresNonNullParameter() { + getTypeParameters(null); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/test/java/org/apache/tamaya/spi/ConversionContextTest.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/test/java/org/apache/tamaya/spi/ConversionContextTest.java b/code/old/api/src/test/java/org/apache/tamaya/spi/ConversionContextTest.java new file mode 100644 index 0000000..30f5aba --- /dev/null +++ b/code/old/api/src/test/java/org/apache/tamaya/spi/ConversionContextTest.java @@ -0,0 +1,194 @@ +/* + * 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.spi; + +import org.apache.tamaya.ConfigOperator; +import org.apache.tamaya.ConfigQuery; +import org.apache.tamaya.Configuration; +import org.apache.tamaya.TypeLiteral; +import org.junit.Test; + +import java.net.InetAddress; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.*; + +/** + * Tests for {@link ConversionContext}, created by atsticks on 20.08.16. + */ +public class ConversionContextTest { + @Test + public void getKey() throws Exception { + ConversionContext ctx = new ConversionContext.Builder("getKey", TypeLiteral.of(String.class)).build(); + assertEquals("getKey", ctx.getKey()); + } + + @Test + public void getTargetType() throws Exception { + ConversionContext ctx = new ConversionContext.Builder("getTargetType", TypeLiteral.of(String.class)).build(); + assertEquals(TypeLiteral.of(String.class), ctx.getTargetType()); + } + + @Test + public void getAnnotatedElement() throws Exception { + ConversionContext ctx = new ConversionContext.Builder("getAnnotatedElement", TypeLiteral.of(List.class)).build(); + assertNull(ctx.getAnnotatedElement()); + } + + @Test + public void testConfiguration() throws Exception { + Configuration config = new MyConfiguration(); + ConversionContext ctx = new ConversionContext.Builder("testConfiguration", TypeLiteral.of(List.class)) + .setConfiguration(config).build(); + assertEquals(config, ctx.getConfiguration()); + } + + @Test + public void testSupportedFormats() throws Exception { + ConversionContext ctx = new ConversionContext.Builder("getAnnotatedElement", TypeLiteral.of(List.class)) + .addSupportedFormats(MyConverter.class, "0.0.0.0/nnn").build(); + assertTrue(ctx.getSupportedFormats().contains("0.0.0.0/nnn (MyConverter)")); + } + + @Test + public void testToString() throws Exception { + ConversionContext ctx = new ConversionContext.Builder("getAnnotatedElement", TypeLiteral.of(List.class)) + .addSupportedFormats(MyConverter.class, "0.0.0.0/nnn").build(); + assertEquals("ConversionContext{configuration=null, key='getAnnotatedElement', targetType=TypeLiteral{type=interface java.util.List}, annotatedElement=null, supportedFormats=[0.0.0.0/nnn (MyConverter)]}", ctx.toString()); + } + + @Test + public void getConfigurationContext() throws Exception { + ConfigurationContext context = new MyConfigurationContext(); + ConversionContext ctx = new ConversionContext.Builder("getAnnotatedElement", TypeLiteral.of(List.class)) + .setConfigurationContext(context).build(); + assertEquals(context, ctx.getConfigurationContext()); + } + + + private static final class MyConverter implements PropertyConverter<InetAddress>{ + @Override + public InetAddress convert(String value, ConversionContext context) { + return null; + } + } + + private static final class MyConfigurationContext implements ConfigurationContext{ + + @Override + public void addPropertySources(PropertySource... propertySources) { + + } + + @Override + public List<PropertySource> getPropertySources() { + return null; + } + + @Override + public PropertySource getPropertySource(String name) { + return null; + } + + @Override + public <T> void addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) { + + } + + @Override + public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() { + return null; + } + + @Override + public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> type) { + return null; + } + + @Override + public List<PropertyFilter> getPropertyFilters() { + return null; + } + + @Override + public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy() { + return null; + } + + @Override + public ConfigurationContextBuilder toBuilder() { + return null; + } + } + + private static final class MyConfiguration implements Configuration{ + + @Override + public String get(String key) { + return null; + } + + @Override + public String getOrDefault(String key, String defaultValue) { + return null; + } + + @Override + public <T> T getOrDefault(String key, Class<T> type, T defaultValue) { + return null; + } + + @Override + public <T> T get(String key, Class<T> type) { + return null; + } + + @Override + public <T> T get(String key, TypeLiteral<T> type) { + return null; + } + + @Override + public <T> T getOrDefault(String key, TypeLiteral<T> type, T defaultValue) { + return null; + } + + @Override + public Map<String, String> getProperties() { + return null; + } + + @Override + public Configuration with(ConfigOperator operator) { + return null; + } + + @Override + public <T> T query(ConfigQuery<T> query) { + return null; + } + + @Override + public ConfigurationContext getContext() { + return null; + } + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/test/java/org/apache/tamaya/spi/FilterContextTest.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/test/java/org/apache/tamaya/spi/FilterContextTest.java b/code/old/api/src/test/java/org/apache/tamaya/spi/FilterContextTest.java new file mode 100644 index 0000000..d8ff360 --- /dev/null +++ b/code/old/api/src/test/java/org/apache/tamaya/spi/FilterContextTest.java @@ -0,0 +1,158 @@ +/* + * 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.spi; + +import org.apache.tamaya.TypeLiteral; +import org.junit.Test; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.*; + +/** + * Tests for {@link FilterContext}. + */ +public class FilterContextTest { + + @Test(expected = NullPointerException.class) + public void constructorRequiresNonNullPropertyValueTwoParameterVariant() { + new FilterContext(null, new TestConfigContext()); + } + + @Test(expected = NullPointerException.class) + public void constructorRequiresNonNullConfigurationContextTwoParameterVariant() { + new FilterContext(PropertyValue.of("a", "b", "s"), null); + } + + @SuppressWarnings("unchecked") + @Test(expected = NullPointerException.class) + public void constructorRequiresNonNullPropertyValueThreeParameterVariant() { + new FilterContext(null, Collections.EMPTY_MAP, new TestConfigContext()); + } + + @SuppressWarnings("unchecked") + @Test(expected = NullPointerException.class) + public void constructorRequiresNonNullConfigurationContextThreeParameterVariant() { + new FilterContext(PropertyValue.of("a", "b", "s"), Collections.EMPTY_MAP, null); + } + + @Test(expected = NullPointerException.class) + public void constructorRequiresNonNullMapForConfigEntriesThreeParameterVariant() { + new FilterContext(PropertyValue.of("a", "b", "s"), null, new TestConfigContext()); + } + + @Test + public void getKey() throws Exception { + PropertyValue val = PropertyValue.of("getKey", "v", ""); + FilterContext ctx = new FilterContext(val, + new HashMap<String,PropertyValue>(), new TestConfigContext()); + assertEquals(val, ctx.getProperty()); + } + + @Test + public void isSinglePropertyScoped() throws Exception { + PropertyValue val = PropertyValue.of("isSinglePropertyScoped", "v", ""); + FilterContext ctx = new FilterContext(val, new HashMap<String,PropertyValue>(), new TestConfigContext()); + assertEquals(false, ctx.isSinglePropertyScoped()); + ctx = new FilterContext(val, new TestConfigContext()); + assertEquals(true, ctx.isSinglePropertyScoped()); + } + + @Test + public void getConfigEntries() throws Exception { + Map<String,PropertyValue> config = new HashMap<>(); + for(int i=0;i<10;i++) { + config.put("key-"+i, PropertyValue.of("key-"+i, "value-"+i, "test")); + } + PropertyValue val = PropertyValue.of("getConfigEntries", "v", ""); + FilterContext ctx = new FilterContext(val, config, new TestConfigContext()); + assertEquals(config, ctx.getConfigEntries()); + assertTrue(config != ctx.getConfigEntries()); + } + + @Test + public void testToString() throws Exception { + Map<String,PropertyValue> config = new HashMap<>(); + for(int i=0;i<2;i++) { + config.put("key-"+i, PropertyValue.of("key-"+i, "value-"+i, "test")); + } + PropertyValue val = PropertyValue.of("testToString", "val", "mySource"); + FilterContext ctx = new FilterContext(val, config, new TestConfigContext()); + String toString = ctx.toString(); + + assertNotNull(toString); + assertTrue(toString.contains("FilterContext{value='PropertyValue{key='testToString', value='val', " + + "source='mySource'}', configEntries=[")); + assertTrue(toString.contains("key-0")); + assertTrue(toString.contains("key-1")); + assertTrue(toString.endsWith("}")); + } + + private static class TestConfigContext implements ConfigurationContext{ + + @Override + public void addPropertySources(PropertySource... propertySources) { + + } + + @Override + public List<PropertySource> getPropertySources() { + return null; + } + + @Override + public PropertySource getPropertySource(String name) { + return null; + } + + @Override + public <T> void addPropertyConverter(TypeLiteral<T> type, PropertyConverter<T> propertyConverter) { + + } + + @Override + public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() { + return null; + } + + @Override + public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> type) { + return null; + } + + @Override + public List<PropertyFilter> getPropertyFilters() { + return null; + } + + @Override + public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy() { + return null; + } + + @Override + public ConfigurationContextBuilder toBuilder() { + return null; + } + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/test/java/org/apache/tamaya/spi/PropertyValueBuilderTest.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/test/java/org/apache/tamaya/spi/PropertyValueBuilderTest.java b/code/old/api/src/test/java/org/apache/tamaya/spi/PropertyValueBuilderTest.java new file mode 100644 index 0000000..cd187db --- /dev/null +++ b/code/old/api/src/test/java/org/apache/tamaya/spi/PropertyValueBuilderTest.java @@ -0,0 +1,246 @@ +/* + * 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.spi; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + +public class PropertyValueBuilderTest { + + /* + * Tests for PropertyValueBuilder(String) + */ + + @Test(expected = NullPointerException.class) + public void constructorWithSingleParameterRequiresNonNullValue() { + new PropertyValue(null); + } + + /* + * Tests for PropertyValueBuilder(String, String) + */ + + @Test(expected = NullPointerException.class) + public void constructorWithTwoParametersRequiresNonNullValueForKey() { + new PropertyValueBuilder(null, "s"); + } + + @Test(expected = NullPointerException.class) + public void constructorWithTwoParametersRequiresNonNullValueForSource() { + new PropertyValueBuilder("a", null); + } + + /* + * Tests for PropertyValueBuilder(String, String, String) + */ + + @Test(expected = NullPointerException.class) + public void constructorWithThreeParametersRequiresNonNullValueForSource() { + new PropertyValueBuilder("a", "b", null); + } + + @Test(expected = NullPointerException.class) + public void constructorWithThreeParametersRequiresNonNullValueForKey() { + new PropertyValueBuilder(null, "b", "s"); + } + + /* + * Tests for addMetaEntry(String, Object) + */ + + @Test(expected = NullPointerException.class) + public void addMetaEntryRequiresNonNullParameterForKey() { + new PropertyValueBuilder("a", "b", "c").addMetaEntry(null, "a"); + } + + @Test(expected = NullPointerException.class) + public void addMetaEntryRequiresNonNullParameterForValue() { + new PropertyValueBuilder("a", "b", "c").addMetaEntry("a", null); + } + + @Test(expected = NullPointerException.class) + public void setKeyRequiresNonNullParameterForKey() { + new PropertyValueBuilder("a", "b", "s").setKey(null); + } + + @Test(expected = NullPointerException.class) + public void setKeyRequiresNonNullParameterForValue() { + new PropertyValueBuilder("a", "b", "s").setValue(null); + } + + /* + * Tests für addMetaEntries(Map) + */ + + @Test(expected = NullPointerException.class) + public void addMetaEntriesRequiresNonNullParameter() { + new PropertyValueBuilder("a", "b", "s").addMetaEntries(null); + } + + @Test + public void testCreate1(){ + new PropertyValueBuilder("k"); + } + + @Test(expected = NullPointerException.class) + public void testCreate1_Null(){ + new PropertyValueBuilder(null); + } + + @Test + public void testCreate2(){ + new PropertyValueBuilder("k", "source"); + } + + @Test(expected = NullPointerException.class) + public void testCreate2_Null(){ + new PropertyValueBuilder("k", null); + } + + @Test + public void testKey() throws Exception { + PropertyValueBuilder b = new PropertyValueBuilder("k", "testKey").setValue("v"); + PropertyValue val = b.build(); + assertEquals(val.getKey(),"k"); + } + + @Test + public void testSource() throws Exception { + PropertyValueBuilder b = new PropertyValueBuilder("k", "testSource").setValue("v"); + PropertyValue val = b.build(); + assertEquals(val.getSource(),"testSource"); + } + + @Test + public void testValue() throws Exception { + PropertyValueBuilder b = new PropertyValueBuilder("k", "testValue").setValue("v"); + PropertyValue val = b.build(); + assertEquals(val.getValue(),"v"); + assertNull(val.getMetaEntries().get("k")); + } + + @Test(expected=NullPointerException.class) + public void testKeyNullValue() throws Exception { + new PropertyValueBuilder(null, "testKeyNullValue"); + } + + @Test + public void testSetMetaEntries() throws Exception { + Map<String,String> meta = new HashMap<>(); + meta.put("1","2"); + meta.put("a", "b"); + PropertyValue pv = PropertyValue.builder("k", "testGetKey") + .setValue("v") + .addMetaEntry("k", "v2") + .setMetaEntries(meta).build(); + assertEquals("v", pv.getValue()); + assertEquals("k", pv.getKey()); + assertNull("v2", pv.getMetaEntry("k")); + assertEquals("testGetKey", pv.getSource()); + assertEquals("2", pv.getMetaEntry("1")); + assertEquals("b", pv.getMetaEntry("a")); + } + + @Test + public void testGetKey() throws Exception { + PropertyValue pv = PropertyValue.builder("k", "testGetKey").setValue("v").build(); + assertEquals("k", pv.getKey()); + } + + @Test + public void testGetValue1() throws Exception { + PropertyValue pv = PropertyValue.of("k", "v", "testGetValue"); + assertEquals("v", pv.getValue()); + } + + @Test + public void testGetValue2() throws Exception { + PropertyValue pv = PropertyValue.builder("k", "testGetValue").setValue("v").build(); + assertEquals("v", pv.getValue()); + } + + @Test(expected = NullPointerException.class) + public void removeMetaEntryRequiresNonNullParameter() { + new PropertyValueBuilder("y").removeMetaEntry(null); + } + + @Test + public void testRemoveMetaEntry() throws Exception { + PropertyValue pv = PropertyValue.builder("k", "testGetKey") + .setValue("v") + .addMetaEntry("k", "v2") + .addMetaEntry("k2", "v22") + .removeMetaEntry("k").build(); + assertEquals("v22", pv.getMetaEntry("k2")); + assertNull(pv.getMetaEntry("k")); + } + + @Test(expected=NullPointerException.class) + public void testSourceNullValue() throws Exception { + new PropertyValueBuilder("k", null); + } + + @Test + public void testGetMetaEntries() throws Exception { + Map<String,String> meta = new HashMap<>(); + meta.put("1","2"); + meta.put("a", "b"); + PropertyValue pv = PropertyValue.builder("k", "testGetKey") + .setValue("v") + .setMetaEntries(meta).build(); + assertEquals(meta, pv.getMetaEntries()); + } + + @Test + public void testSetContextData() throws Exception { + PropertyValueBuilder b = new PropertyValueBuilder("k", "testSetContextData").setValue("v"); + Map<String,String> context = new HashMap<>(); + context.put("source", "testSetContextData"); + context.put("ts", String.valueOf(System.currentTimeMillis())); + context.put("y", "yValue"); + b.setMetaEntries(new HashMap<String, String>()); + b.setMetaEntries(context); + context.remove("y"); + b.setMetaEntries(context); + PropertyValue contextData = b.build(); + assertEquals(contextData.getMetaEntries().size(), context.size()); + assertEquals(contextData.getMetaEntry("source"), "testSetContextData"); + assertNotNull(contextData.getMetaEntry("ts")); + assertNull(contextData.getMetaEntry("y")); + } + + @Test + public void testAddContextData() throws Exception { + PropertyValueBuilder b = new PropertyValueBuilder("k", "testAddContextData").setValue("v"); + b.addMetaEntry("ts", System.currentTimeMillis()); + b.addMetaEntry("y", "yValue"); + b.addMetaEntry("y", "y2"); + PropertyValue contextData = b.build(); + assertEquals(contextData.getMetaEntries().size(), 2); + assertNotNull(contextData.getMetaEntry("ts")); + assertEquals(contextData.getMetaEntry("y"), "y2"); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/test/java/org/apache/tamaya/spi/PropertyValueCombinationPolicyTest.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/test/java/org/apache/tamaya/spi/PropertyValueCombinationPolicyTest.java b/code/old/api/src/test/java/org/apache/tamaya/spi/PropertyValueCombinationPolicyTest.java new file mode 100644 index 0000000..c7a4698 --- /dev/null +++ b/code/old/api/src/test/java/org/apache/tamaya/spi/PropertyValueCombinationPolicyTest.java @@ -0,0 +1,89 @@ +/* + * 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.spi; + +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PropertyValueCombinationPolicyTest { + + @Test + public void defaulPolicyOverridesCurrentValueByTheOneOfTheGivenProperySource() throws Exception { + PropertyValueCombinationPolicy policy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_POLICY; + + PropertyValue current = PropertyValue.of("a", "AAA", "Test"); + PropertyValue result = policy.collect(current, "a", new DummyPropertySource()); + + assertThat(result.getKey()).isEqualTo("a"); + assertThat(result.getValue()).isEqualTo("Ami"); + } + + @Test + public void defaulPolicyOverridesKeepsTheCurrentValueIfGivenProperySourceDoesNotHaveIt() throws Exception { + PropertyValueCombinationPolicy policy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_POLICY; + + PropertyValue current = PropertyValue.of("a", "AAA", "Test"); + PropertyValue result = policy.collect(current, "a", PropertySource.EMPTY); + + assertThat(result.getKey()).isEqualTo("a"); + assertThat(result.getValue()).isEqualTo("AAA"); + assertThat(result).isEqualTo(current); + } + + + static class DummyPropertySource implements PropertySource { + @Override + public int getOrdinal() { + return 10; + } + + @Override + public String getName() { + return "NAME"; + } + + @Override + public PropertyValue get(String key) { + return getProperties().get(key); + } + + @Override + public Map<String, PropertyValue> getProperties() { + PropertyValue a = PropertyValue.of("a", "Ami", "Test"); + PropertyValue b = PropertyValue.of("b", "Big", "Test"); + + HashMap<String, PropertyValue> properties = new HashMap<>(); + + properties.put(a.getKey(), a); + properties.put(b.getKey(), b); + + return properties; + } + + @Override + public boolean isScannable() { + return true; + } + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/test/java/org/apache/tamaya/spi/PropertyValueTest.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/test/java/org/apache/tamaya/spi/PropertyValueTest.java b/code/old/api/src/test/java/org/apache/tamaya/spi/PropertyValueTest.java new file mode 100644 index 0000000..f443f60 --- /dev/null +++ b/code/old/api/src/test/java/org/apache/tamaya/spi/PropertyValueTest.java @@ -0,0 +1,250 @@ +/* + * 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.spi; + +import org.junit.Test; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.*; + +@SuppressWarnings("unchecked") +public class PropertyValueTest { + + @Test(expected = NullPointerException.class) + public void mapThreeParameterVariantRequiresNonNullValueForConfigParameter() { + PropertyValue.map(null, "a", Collections.EMPTY_MAP); + } + + @Test(expected = NullPointerException.class) + public void mapThreeParameterVariantRequiresNonNullValueForSource() { + PropertyValue.map(Collections.EMPTY_MAP, null, Collections.EMPTY_MAP); + } + + @Test(expected = NullPointerException.class) + public void mapThreeParameterVariantRequiresNonNullValueForMetaData() { + PropertyValue.map(Collections.EMPTY_MAP, "s", null); + } + + @Test(expected = NullPointerException.class) + public void ofDoesNotAcceptNullAsKey() throws Exception { + PropertyValue.of(null, "b", "source"); + } + + @Test(expected = NullPointerException.class) + public void ofDoesNotAcceptNullAsSource() throws Exception { + PropertyValue.of("a", "b", null); + } + + @Test + public void testOf(){ + assertNotNull(PropertyValue.of("k", "v", "testGetKey")); + } + + @Test(expected = NullPointerException.class) + public void getMetaEntryRequiresNonNullValueForKey() { + PropertyValue.of("a", "b", "s").getMetaEntry(null); + } + + @Test(expected = NullPointerException.class) + public void testSetMetaEntriesRequiresNonNullParameter() { + new PropertyValueBuilder("a").setMetaEntries(null); + } + + @Test + public void testHashCode(){ + assertEquals(PropertyValue.of("k", "v", "testGetKey").hashCode(), + PropertyValue.of("k", "v", "testGetKey").hashCode()); + assertNotSame(PropertyValue.of("k", "v", "testGetKey").hashCode(), + PropertyValue.of("k1", "v", "testGetKey").hashCode()); + assertNotSame(PropertyValue.of("k", "v", "testGetKey").hashCode(), + PropertyValue.of("k", "v1", "testGetKey").hashCode()); + assertNotSame(PropertyValue.of("k", "v", "1").hashCode(), + PropertyValue.of("k", "v", "2").hashCode()); + } + + @Test + public void testEquals(){ + assertEquals(PropertyValue.of("k", "v", "testEquals"), + PropertyValue.of("k", "v", "testEquals")); + assertNotSame(PropertyValue.of("k2", "v", "testEquals"), + PropertyValue.of("k", "v", "testEquals")); + assertNotSame(PropertyValue.of("k", "v", "testEquals"), + PropertyValue.of("k", "v2", "testEquals")); + assertNotSame(PropertyValue.of("k", "v", "testEquals"), + PropertyValue.of("k", "v", "testEquals2")); + } + + @Test + public void testBuilder(){ + assertNotNull(PropertyValue.builder("k", "testGetKey")); + assertEquals(PropertyValue.of("k", "v", "testEquals"), + PropertyValue.builder("k", "testEquals").setValue("v").build()); + } + + @Test + public void testToBuilder(){ + assertNotNull(PropertyValue.of("k", "v", "testGetKey").toBuilder()); + // round-trip + PropertyValue val = PropertyValue.of("k", "v", "testGetKey"); + assertEquals(val, + val.toBuilder().build()); + } + + @Test + public void testGetKey() throws Exception { + PropertyValue pv = PropertyValue.of("k", "v", "testGetKey"); + assertEquals("k", pv.getKey()); + } + + @Test + public void testGetValue() throws Exception { + PropertyValue pv = PropertyValue.of("k", "v", "testGetValue"); + assertEquals("v", pv.getValue()); + } + + @Test + public void testGetSource() throws Exception { + PropertyValue pv = PropertyValue.of("k", "v", "testGetSource"); + assertEquals("testGetSource", pv.getSource()); + pv = PropertyValue.of("k", "v", "testGetSource"); + assertEquals("testGetSource", pv.getSource()); + } + + @Test + public void testGetMetaEntry() throws Exception { + PropertyValue pv = PropertyValue.builder("k", "testGetMetaEntry").setValue("v") + .addMetaEntry("k", "v2").build(); + assertEquals("v", pv.getValue()); + assertEquals("k", pv.getKey()); + assertEquals("v2", pv.getMetaEntry("k")); + assertEquals("testGetMetaEntry", pv.getSource()); + } + + @Test + public void testGetMetaEntries() throws Exception { + PropertyValue pv = PropertyValue.of("k", "v", "testGetMetaEntries"); + assertNotNull(pv.getMetaEntries()); + assertTrue(pv.getMetaEntries().isEmpty()); + } + + @Test + public void testMap() throws Exception { + Map<String,String> map = new HashMap<>(); + map.put("a", "1"); + map.put("b", "2"); + Map<String,PropertyValue> result = PropertyValue.map(map, "source1"); + assertNotNull(result); + assertEquals(map.size(), result.size()); + + for (Map.Entry<String,String>en:map.entrySet()) { + PropertyValue val = result.get(en.getKey()); + assertNotNull(val); + assertEquals(val.getKey(), en.getKey()); + assertEquals(val.getValue(), en.getValue()); + assertEquals(val.getSource(), "source1"); + assertTrue(val.getMetaEntries().isEmpty()); + } + } + + @Test + public void testMapWithMetadata() throws Exception { + Map<String,String> map = new HashMap<>(); + map.put("a", "1"); + map.put("b", "2"); + Map<String,String> meta = new HashMap<>(); + map.put("m1", "n1"); + map.put("m2", "n2"); + Map<String,PropertyValue> result = PropertyValue.map(map, "source1", meta); + assertNotNull(result); + assertEquals(map.size(), result.size()); + for(Map.Entry<String,String>en:map.entrySet()){ + PropertyValue val = result.get(en.getKey()); + assertNotNull(val); + assertEquals(val.getKey(), en.getKey()); + assertEquals(val.getValue(), en.getValue()); + assertEquals(val.getSource(), "source1"); + assertEquals(val.getMetaEntries(), meta); + } + } + + @Test(expected = NullPointerException.class) + public void testInstantiateNoKey1() throws Exception { + PropertyValue.builder(null, "testGetKey").setValue("v").build(); + } + + @Test(expected = NullPointerException.class) + public void testInstantiateNoKey2() throws Exception { + PropertyValue.of(null, "v", "testGetKey"); + } + + @Test + public void testInstantiateNoValue1() throws Exception { + PropertyValue.builder("k", "testGetKey").build(); + } + + @Test + public void testInstantiateNoValue2() throws Exception { + PropertyValue.of("k", null, "testGetKey"); + } + + @Test(expected = NullPointerException.class) + public void testInstantiateNoSource1() throws Exception { + PropertyValue.builder("k", null).setValue("v").build(); + } + + @Test(expected = NullPointerException.class) + public void testInstantiateNoSource2() throws Exception { + PropertyValue.of("k", "v", null); + } + + @Test(expected = NullPointerException.class) + public void testGetMetaEntry_Null() throws Exception { + PropertyValue.of("k", "v", "src").getMetaEntry(null); + } + + @Test(expected = NullPointerException.class) + public void builderMethodThreeParameterVariantRequiresNonNullValueAsKey() { + PropertyValue.builder(null, "b", "s"); + } + + @Test(expected = NullPointerException.class) + public void builderMethodThreeParameterVariantRequiresNonNullValueAsSource() { + PropertyValue.builder("A", "b", null); + } + + @Test(expected = NullPointerException.class) + public void builderMethodThreeParameterVariantRequiresNonNullValueAsValue() { + PropertyValue.builder("A", null, "s"); + } + + + @Test(expected = NullPointerException.class) + public void builderMethodTwoParameterVariantRequiresNonNullValueAsSource() { + PropertyValue.builder(null, "a"); + } + + @Test(expected = NullPointerException.class) + public void builderMethodTwoParameterVariantRequiresNonNullValueAsValue() { + PropertyValue.builder("A", null); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java b/code/old/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java new file mode 100644 index 0000000..7379555 --- /dev/null +++ b/code/old/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java @@ -0,0 +1,90 @@ +/* + * 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.spi; + +import org.junit.Test; + +import java.io.IOException; +import java.net.URL; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; + +import static org.junit.Assert.*; + +/** + * Additional tests for {@link ServiceContextManager}, created by atsticks on 20.08.16. + */ +public class ServiceContextManagerTest { + + @Test + public void setGetServiceContext() throws Exception { + ServiceContext prev = ServiceContextManager.getServiceContext(); + try { + MyServiceContext mine = new MyServiceContext(); + ServiceContextManager.set(mine); + assertTrue(ServiceContextManager.getServiceContext() == mine); + ServiceContextManager.set(mine); + assertTrue(ServiceContextManager.getServiceContext() == mine); + } finally { + ServiceContextManager.set(prev); + assertTrue(ServiceContextManager.getServiceContext() == prev); + } + + } + + @Test(expected = NullPointerException.class) + public void setRequiresNonNullParameter() { + ServiceContextManager.set(null); + } + + private static final class MyServiceContext implements ServiceContext{ + + @Override + public int ordinal() { + return 0; + } + + @Override + public <T> T getService(Class<T> serviceType) { + return null; + } + + @Override + public <T> T create(Class<T> serviceType) { + return null; + } + + @Override + public <T> List<T> getServices(Class<T> serviceType) { + return Collections.emptyList(); + } + + @Override + public Enumeration<URL> getResources(String resource, ClassLoader cl) throws IOException { + return null; + } + + @Override + public URL getResource(String resource, ClassLoader cl) { + return null; + } + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java b/code/old/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java new file mode 100644 index 0000000..301c6ab --- /dev/null +++ b/code/old/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java @@ -0,0 +1,113 @@ +/* + * 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.spi; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.net.URL; +import java.util.*; + +import org.junit.Test; + +public class ServiceContextTest { + + private final ServiceContext serviceContext = new ServiceContext(){ + + @Override + public int ordinal() { + return 1; + } + + @Override + public <T> T getService(Class<T> serviceType) { + if(String.class.equals(serviceType)){ + return serviceType.cast("ServiceContextTest"); + } + return null; + } + + @Override + public <T> T create(Class<T> serviceType) { + return getService(serviceType); + } + + @SuppressWarnings("unchecked") + @Override + public <T> List<T> getServices(Class<T> serviceType) { + if(String.class.equals(serviceType)){ + List<String> list = new ArrayList<>(); + list.add("ServiceContextTest"); + return List.class.cast(list); + } + return Collections.emptyList(); + } + + @Override + public Enumeration<URL> getResources(String resource, ClassLoader cl) throws IOException { + return cl.getResources(resource); + } + + @Override + public URL getResource(String resource, ClassLoader cl) { + return cl.getResource(resource); + } + }; + + @Test + public void testOrdinal() throws Exception { + assertEquals(1, serviceContext.ordinal()); + } + + @Test + public void testgetService() throws Exception { + assertEquals("ServiceContextTest", serviceContext.getService(String.class)); + assertNull(serviceContext.getService(Integer.class)); + } + + @Test + public void testGetService() throws Exception { + String service = serviceContext.getService(String.class); + assertNotNull(service); + assertEquals("ServiceContextTest", service); + Integer intService = serviceContext.getService(Integer.class); + assertNull(intService); + } + + @Test + public void testGetServices() throws Exception { + Collection<String> services = serviceContext.getServices(String.class); + assertNotNull(services); + assertFalse(services.isEmpty()); + assertEquals("ServiceContextTest", services.iterator().next()); + List<Integer> intServices = serviceContext.getServices(Integer.class); + assertNotNull(intServices); + assertTrue(intServices.isEmpty()); + } + + @Test + public void testGetInstance() throws Exception { + assertNotNull(ServiceContextManager.getServiceContext()); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java ---------------------------------------------------------------------- diff --git a/code/old/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java b/code/old/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java new file mode 100644 index 0000000..bbc3ee2 --- /dev/null +++ b/code/old/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java @@ -0,0 +1,105 @@ +/* + * 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.spi; + +import java.io.IOException; +import java.net.URL; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * This class implements the (default) {@link org.apache.tamaya.spi.ServiceContext} interface and hereby uses the JDK + * {@link java.util.ServiceLoader} to load the services required. + */ +public final class TestServiceContext implements ServiceContext { + /** List current services loaded, per class. */ + private final ConcurrentHashMap<Class<?>, List<Object>> servicesLoaded = new ConcurrentHashMap<>(); + + private final Map<Class<?>, Object> singletons = new ConcurrentHashMap<>(); + + @Override + public int ordinal() { + return 1; + } + + @SuppressWarnings("rawtypes") + @Override + public <T> T getService(Class<T> serviceType) { + T cached = serviceType.cast(singletons.get(serviceType)); + if(cached==null) { + cached = create(serviceType); + singletons.put((Class)serviceType, cached); + } + if (cached == Object.class) { + cached = null; + } + return cached; + } + + @SuppressWarnings("unchecked") + @Override + public <T> T create(Class<T> serviceType) { + Collection<T> services = getServices(serviceType); + if (services.isEmpty()) { + return (T) Object.class; // as marker for 'nothing here' + } + else{ + return services.iterator().next(); + } + } + + /** + * Loads and registers services. + * + * @param <T> the concrete type. + * + * @param serviceType The service type. + * @return the items found, never {@code null}. + */ + @Override + public <T> List<T> getServices(Class<T> serviceType) { + try { + List<T> services = new ArrayList<>(); + for (T t : ServiceLoader.load(serviceType)) { + services.add(t); + } + services = Collections.unmodifiableList(services); + @SuppressWarnings("unchecked") + final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>)services)); + return previousServices != null ? previousServices : services; + } catch (Exception e) { + Logger.getLogger(TestServiceContext.class.getName()).log(Level.WARNING, + "Error loading services current type " + serviceType, e); + return Collections.emptyList(); + } + } + + @Override + public Enumeration<URL> getResources(String resource, ClassLoader cl) throws IOException { + return cl.getResources(resource); + } + + @Override + public URL getResource(String resource, ClassLoader cl) { + return cl.getResource(resource); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi ---------------------------------------------------------------------- diff --git a/code/old/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi b/code/old/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi new file mode 100644 index 0000000..b9c5ba5 --- /dev/null +++ b/code/old/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi @@ -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.TestConfigurationProvider http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext ---------------------------------------------------------------------- diff --git a/code/old/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext b/code/old/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext new file mode 100644 index 0000000..199956f --- /dev/null +++ b/code/old/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext @@ -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.spi.TestServiceContext \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/bnd.bnd ---------------------------------------------------------------------- diff --git a/code/old/core/bnd.bnd b/code/old/core/bnd.bnd new file mode 100644 index 0000000..b611eb1 --- /dev/null +++ b/code/old/core/bnd.bnd @@ -0,0 +1,43 @@ +-buildpath: \ + osgi.annotation; version=6.0.0,\ + osgi.core; version=6.0,\ + osgi.cmpn; version=6.0 + +-testpath: \ + ${junit} + +javac.source: 1.8 +javac.target: 1.8 + +Bundle-Version: ${version}.${tstamp} +Bundle-Name: Apache Tamaya - Core +Bundle-SymbolicName: org.apache.tamaya.core +Bundle-Description: Apacha Tamaya Configuration Java Core Implementation +Bundle-Category: Implementation +Bundle-Copyright: (C) Apache Foundation +Bundle-License: Apache Licence version 2 +Bundle-Vendor: Apache Software Foundation +Bundle-ContactAddress: dev-tam...@incubator.apache.org +Bundle-DocURL: http://tamaya.apache.org +Bundle-Activator: org.apache.tamaya.core.OSGIActivator +Export-Package: \ + org.apache.tamaya.core +Import-Package: \ + org.apache.tamaya,\ + org.apache.tamaya.spi,\ + org.apache.tamaya.spisupport,\ + org.apache.tamaya.spisupport.propertysource,\ + org.osgi.framework,\ + javax.annotation +Private-Package: \ + org.apache.tamaya.core.internal,\ + org.apache.tamaya.core.internal.converters +Export-Service: \ + org.apache.tamaya.Configuration,\ + org.apache.tamaya.core.internal.ConfigValueEvaluator,\ + org.apache.tamaya.spi.ConfigurationContextBuilder,\ + org.apache.tamaya.spi.ConfigurationProviderSpi,\ + org.apache.tamaya.spi.PropertyConverter,\ + org.apache.tamaya.spi.PropertySource,\ + org.apache.tamaya.spi.ServiceContext + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/pom.xml ---------------------------------------------------------------------- diff --git a/code/old/core/pom.xml b/code/old/core/pom.xml new file mode 100644 index 0000000..2d98631 --- /dev/null +++ b/code/old/core/pom.xml @@ -0,0 +1,95 @@ +<!-- +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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.tamaya</groupId> + <artifactId>tamaya-code</artifactId> + <version>0.4-incubating-SNAPSHOT</version> + </parent> + + <artifactId>tamaya-core</artifactId> + <name>Apache Tamaya Core Implementation</name> + <packaging>jar</packaging> + + <dependencies> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.tamaya</groupId> + <artifactId>tamaya-api</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.tamaya</groupId> + <artifactId>tamaya-spisupport</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>java-hamcrest</artifactId> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + <scope>provided</scope> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + <scope>provided</scope> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.annotation</artifactId> + <scope>provided</scope> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <forkCount>1</forkCount> + <!-- + ! Add -Djava.security.debug=all for debugging if needed + !--> + <argLine>-Djava.security.policy=${project.basedir}/src/test/resources/java-security.policy</argLine> + </configuration> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/main/java/org/apache/tamaya/core/OSGIActivator.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/main/java/org/apache/tamaya/core/OSGIActivator.java b/code/old/core/src/main/java/org/apache/tamaya/core/OSGIActivator.java new file mode 100644 index 0000000..2ca51db --- /dev/null +++ b/code/old/core/src/main/java/org/apache/tamaya/core/OSGIActivator.java @@ -0,0 +1,68 @@ +/* + * 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.core.internal.*; +import org.apache.tamaya.spi.ServiceContextManager; +import org.apache.tamaya.spisupport.DefaultConfiguration; +import org.apache.tamaya.spisupport.PropertyFilterComparator; +import org.apache.tamaya.spisupport.PropertySourceComparator; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +import java.util.logging.Logger; + +/** + * A bundle activator that registers the {@link OSGIServiceLoader}. + */ +public class OSGIActivator implements BundleActivator { + + private static final Logger LOG = Logger.getLogger(OSGIActivator.class.getName()); + + private OSGIServiceLoader serviceLoader; + + @Override + public void start(BundleContext context) { + // Register marker service + this.serviceLoader = new OSGIServiceLoader(context); + context.addBundleListener(serviceLoader); + ServiceContextManager.set(new OSGIServiceContext(serviceLoader)); + LOG.info("Registered Tamaya OSGI ServiceContext..."); + ConfigurationProvider.setConfiguration( + new CoreConfigurationBuilder() + .addDefaultPropertyConverters() + .addDefaultPropertyFilters() + .addDefaultPropertySources() + .sortPropertyFilter(PropertyFilterComparator.getInstance()) + .sortPropertySources(PropertySourceComparator.getInstance()) + .build() + ); + LOG.info("Loaded default configuration from OSGI."); + } + + @Override + public void stop(BundleContext context) { + if(serviceLoader!=null) { + context.removeBundleListener(serviceLoader); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/main/java/org/apache/tamaya/core/internal/BannerManager.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/main/java/org/apache/tamaya/core/internal/BannerManager.java b/code/old/core/src/main/java/org/apache/tamaya/core/internal/BannerManager.java new file mode 100644 index 0000000..52247c9 --- /dev/null +++ b/code/old/core/src/main/java/org/apache/tamaya/core/internal/BannerManager.java @@ -0,0 +1,165 @@ +/* + * 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.ConfigurationProvider; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Locale; +import java.util.Objects; +import java.util.logging.Level; +import java.util.logging.Logger; + +import static org.apache.tamaya.core.internal.BannerManager.BANNER_RESOURCE_PATH; + +/** + * Controls the output of the banner of Tamaya. + * + * <p>This class controls if and how the banner of Tamaya is presented the user. + * The banner is provided by the Tamaya Core under the resource path + * {@value BANNER_RESOURCE_PATH}.</p> + * + * <p>The behavior of the banner manager can be controlled by + * specifying the configuration key {@code tamaya.banner} with one of + * the three folowing values: + * + * <dl> + * <dt>OFF</dt> + * <dd>Banner will not be shown</dd> + * <dt>CONSOLE</dt> + * <dd>The banner will be printed on STDOUT</dd> + * <dt>LOGGER</dt> + * <dd>The banner will be logged</dd> + * </dl> + * + * In case of any other value the banner will not be shown. + * </p> + * + * + * + * @see BannerTarget + */ +class BannerManager { + /** + * The resouce path to the file containing the banner of Tamaya. + */ + protected final static String BANNER_RESOURCE_PATH = "/tamaya-banner.txt"; + + enum BannerTarget { + OFF, CONSOLE, LOGGER + } + + private BannerTarget bannerTarget; + + public BannerManager(String value) { + value = Objects.requireNonNull(value).toUpperCase(Locale.getDefault()); + + try { + bannerTarget = BannerTarget.valueOf(value); + } catch (NullPointerException | IllegalArgumentException e) { + bannerTarget = BannerTarget.OFF; + } + } + + public void outputBanner() { + BannerPrinter bp = new SilentBannerPrinter(); + + switch (bannerTarget) { + case CONSOLE: + bp = new ConsoleBannerPrinter(); + break; + case LOGGER: + bp = new LoggingBannerPrinter(); + break; + case OFF: + default: + break; + } + + bp.outputBanner(); + } +} + +abstract class AbstractBannerPrinter implements BannerPrinter { + private static final Logger log = Logger.getLogger(AbstractBannerPrinter.class.getName()); + + @Override + public void outputBanner() { + try (InputStream in = ConfigurationProvider.class.getResourceAsStream(BANNER_RESOURCE_PATH)) { + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + String line; + + while ((line = reader.readLine()) != null) { + outputSingleLine(line); + } + } catch (Exception e) { + log.log(Level.WARNING, "Failed to output the banner of tamaya.", e); + } + } + + abstract void outputSingleLine(String line); +} + + +/** + * Outputs the Tamaya banner to an implementation specific output channel + * as STDOUT or the logging system. + */ +interface BannerPrinter { + /** + * Outputs the banner to the output channel + * used by the implementation. + */ + void outputBanner(); +} + +/** + * Silent implementation of a {@link BannerPrinter}. + */ +class SilentBannerPrinter implements BannerPrinter { + @Override + public void outputBanner() { + } +} + +/** + * Logs the banner via JUL at level {@link java.util.logging.Level#INFO}. + */ +class LoggingBannerPrinter extends AbstractBannerPrinter { + private static final Logger log = Logger.getLogger(LoggingBannerPrinter.class.getName()); + + @Override + void outputSingleLine(String line) { + log.log(Level.INFO, line); + } +} + +/** + * Prints the banner to the console. + */ +class ConsoleBannerPrinter extends AbstractBannerPrinter { + @Override + void outputSingleLine(String line) { + System.out.println(line); + } +} + + http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/core/src/main/java/org/apache/tamaya/core/internal/CoreConfiguration.java ---------------------------------------------------------------------- diff --git a/code/old/core/src/main/java/org/apache/tamaya/core/internal/CoreConfiguration.java b/code/old/core/src/main/java/org/apache/tamaya/core/internal/CoreConfiguration.java new file mode 100644 index 0000000..5363b76 --- /dev/null +++ b/code/old/core/src/main/java/org/apache/tamaya/core/internal/CoreConfiguration.java @@ -0,0 +1,43 @@ +/* + * 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.ConfigurationBuilder; +import org.apache.tamaya.spi.ConfigurationContext; +import org.apache.tamaya.spisupport.DefaultConfiguration; +import org.apache.tamaya.spisupport.DefaultConfigurationContext; +import org.apache.tamaya.spisupport.DefaultConfigurationContextBuilder; + +/** + * Default implementation of {@link ConfigurationBuilder}. + */ +public final class CoreConfiguration extends DefaultConfiguration { + + /** + * Creates a new builder instance. + */ + public CoreConfiguration(ConfigurationContext context) { + super(context); + } + + @Override + public ConfigurationBuilder toBuilder() { + return new CoreConfigurationBuilder(this); + } +}