http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/api/src/main/resources/tamaya-banner.txt ---------------------------------------------------------------------- diff --git a/code/api/src/main/resources/tamaya-banner.txt b/code/api/src/main/resources/tamaya-banner.txt deleted file mode 100644 index b4ceca4..0000000 --- a/code/api/src/main/resources/tamaya-banner.txt +++ /dev/null @@ -1,11 +0,0 @@ - - ââââââ âââââââ ââââââ ââââââââââ âââââââââââ âââââââââ ââââââ ââââ ââââ ââââââ âââ âââ ââââââ -âââââââââââââââââââââââââââââââââââ âââââââââââ ââââââââââââââââââââââ âââââââââââââââââ ââââââââââââ -âââââââââââââââââââââââââââ ââââââââââââââ âââ âââââââââââââââââââââââââââ âââââââ ââââââââ -âââââââââââââââ âââââââââââ ââââââââââââââ âââ âââââââââââââââââââââââââââ âââââ ââââââââ -âââ ââââââ âââ ââââââââââââââ âââââââââââ âââ âââ ââââââ âââ ââââââ âââ âââ âââ âââ -âââ ââââââ âââ âââ ââââââââââ âââââââââââ âââ âââ ââââââ ââââââ âââ âââ âââ âââ - -Apache Tamaya Configuration API: http://tamaya.incubator.apache.org - -
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/api/src/test/java/org/apache/tamaya/ConfigExceptionTest.java ---------------------------------------------------------------------- diff --git a/code/api/src/test/java/org/apache/tamaya/ConfigExceptionTest.java b/code/api/src/test/java/org/apache/tamaya/ConfigExceptionTest.java deleted file mode 100644 index fa7da0a..0000000 --- a/code/api/src/test/java/org/apache/tamaya/ConfigExceptionTest.java +++ /dev/null @@ -1,45 +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; - -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/api/src/test/java/org/apache/tamaya/ConfigurationTest.java ---------------------------------------------------------------------- diff --git a/code/api/src/test/java/org/apache/tamaya/ConfigurationTest.java b/code/api/src/test/java/org/apache/tamaya/ConfigurationTest.java deleted file mode 100644 index ecbb75c..0000000 --- a/code/api/src/test/java/org/apache/tamaya/ConfigurationTest.java +++ /dev/null @@ -1,63 +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; - -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/api/src/test/java/org/apache/tamaya/TestConfiguration.java ---------------------------------------------------------------------- diff --git a/code/api/src/test/java/org/apache/tamaya/TestConfiguration.java b/code/api/src/test/java/org/apache/tamaya/TestConfiguration.java deleted file mode 100644 index f50c1dc..0000000 --- a/code/api/src/test/java/org/apache/tamaya/TestConfiguration.java +++ /dev/null @@ -1,137 +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; - - -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/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java ---------------------------------------------------------------------- diff --git a/code/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java b/code/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java deleted file mode 100644 index 1ccce31..0000000 --- a/code/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java +++ /dev/null @@ -1,79 +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; - -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/api/src/test/java/org/apache/tamaya/TypeLiteralTest.java ---------------------------------------------------------------------- diff --git a/code/api/src/test/java/org/apache/tamaya/TypeLiteralTest.java b/code/api/src/test/java/org/apache/tamaya/TypeLiteralTest.java deleted file mode 100644 index 7435e08..0000000 --- a/code/api/src/test/java/org/apache/tamaya/TypeLiteralTest.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; - -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/api/src/test/java/org/apache/tamaya/spi/ConversionContextTest.java ---------------------------------------------------------------------- diff --git a/code/api/src/test/java/org/apache/tamaya/spi/ConversionContextTest.java b/code/api/src/test/java/org/apache/tamaya/spi/ConversionContextTest.java deleted file mode 100644 index 30f5aba..0000000 --- a/code/api/src/test/java/org/apache/tamaya/spi/ConversionContextTest.java +++ /dev/null @@ -1,194 +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.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/api/src/test/java/org/apache/tamaya/spi/FilterContextTest.java ---------------------------------------------------------------------- diff --git a/code/api/src/test/java/org/apache/tamaya/spi/FilterContextTest.java b/code/api/src/test/java/org/apache/tamaya/spi/FilterContextTest.java deleted file mode 100644 index d8ff360..0000000 --- a/code/api/src/test/java/org/apache/tamaya/spi/FilterContextTest.java +++ /dev/null @@ -1,158 +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.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/api/src/test/java/org/apache/tamaya/spi/PropertyValueBuilderTest.java ---------------------------------------------------------------------- diff --git a/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueBuilderTest.java b/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueBuilderTest.java deleted file mode 100644 index cd187db..0000000 --- a/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueBuilderTest.java +++ /dev/null @@ -1,246 +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.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/api/src/test/java/org/apache/tamaya/spi/PropertyValueCombinationPolicyTest.java ---------------------------------------------------------------------- diff --git a/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueCombinationPolicyTest.java b/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueCombinationPolicyTest.java deleted file mode 100644 index c7a4698..0000000 --- a/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueCombinationPolicyTest.java +++ /dev/null @@ -1,89 +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.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/api/src/test/java/org/apache/tamaya/spi/PropertyValueTest.java ---------------------------------------------------------------------- diff --git a/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueTest.java b/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueTest.java deleted file mode 100644 index f443f60..0000000 --- a/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueTest.java +++ /dev/null @@ -1,250 +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.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/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java ---------------------------------------------------------------------- diff --git a/code/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java b/code/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java deleted file mode 100644 index 7379555..0000000 --- a/code/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.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.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/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java ---------------------------------------------------------------------- diff --git a/code/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java b/code/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java deleted file mode 100644 index 301c6ab..0000000 --- a/code/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java +++ /dev/null @@ -1,113 +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.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/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java ---------------------------------------------------------------------- diff --git a/code/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java b/code/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java deleted file mode 100644 index bbc3ee2..0000000 --- a/code/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java +++ /dev/null @@ -1,105 +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.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/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi ---------------------------------------------------------------------- diff --git a/code/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi b/code/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi deleted file mode 100644 index b9c5ba5..0000000 --- a/code/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi +++ /dev/null @@ -1,19 +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 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/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext ---------------------------------------------------------------------- diff --git a/code/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext b/code/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext deleted file mode 100644 index 199956f..0000000 --- a/code/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext +++ /dev/null @@ -1,19 +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 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/base/src/main/java/org/apache/tamaya/base/FormatUtils.java ---------------------------------------------------------------------- diff --git a/code/base/src/main/java/org/apache/tamaya/base/FormatUtils.java b/code/base/src/main/java/org/apache/tamaya/base/FormatUtils.java new file mode 100644 index 0000000..82c3c41 --- /dev/null +++ b/code/base/src/main/java/org/apache/tamaya/base/FormatUtils.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.base; + +/** + * Some helper functions used when creating formatted text out.put. + */ +public final class FormatUtils { + + private FormatUtils(){} + + public static void appendFormatted(StringBuilder b, String text, int length) { + int padding; + if(text.length() <= (length)){ + b.append(text); + padding = length - text.length(); + }else{ + b.append(text.substring(0, length-1)); + padding = 1; + } + for(int i=0;i<padding;i++){ + b.append(' '); + } + } + + public static String removeNewLines(String s) { + return s.replace('\n', ' ').replace('\r', ' '); + } + + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/base/src/main/java/org/apache/tamaya/spi/ConfigContextSupplier.java ---------------------------------------------------------------------- diff --git a/code/base/src/main/java/org/apache/tamaya/spi/ConfigContextSupplier.java b/code/base/src/main/java/org/apache/tamaya/spi/ConfigContextSupplier.java new file mode 100644 index 0000000..0207ebe --- /dev/null +++ b/code/base/src/main/java/org/apache/tamaya/spi/ConfigContextSupplier.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.spi; + +import jdk.nashorn.internal.objects.annotations.Function; + +import javax.config.spi.ConfigSource; +import javax.config.spi.Converter; +import java.lang.reflect.Type; +import java.util.List; +import java.util.Map; + +/** + * Central SPI for programmatically dealing with the setup of the configuration system. + * This includes adding and enlisting {@link ConfigSource}s, + * managing {@link Converter}s, ConfigFilters, etc. + */ +@FunctionalInterface +public interface ConfigContextSupplier { + + /** + * Make an instance of a configuration accessible for use with Apache Tamaya specific extensions. + * In most cases it should be sufficient to implement this interfance on your implementation of + * {@link javax.config.Config}. + * + * @return the corresponding configuration context, never null. + */ + ConfigContext getConfigContext(); + +} + http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/base/src/main/java/org/apache/tamaya/spi/ConfigValueCombinationPolicy.java ---------------------------------------------------------------------- diff --git a/code/base/src/main/java/org/apache/tamaya/spi/ConfigValueCombinationPolicy.java b/code/base/src/main/java/org/apache/tamaya/spi/ConfigValueCombinationPolicy.java new file mode 100644 index 0000000..b94dd9d --- /dev/null +++ b/code/base/src/main/java/org/apache/tamaya/spi/ConfigValueCombinationPolicy.java @@ -0,0 +1,72 @@ +/* + * 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 javax.config.Config; +import javax.config.spi.ConfigSource; + +/** + * Policy that determines how the final value of a configuration entry is evaluated. An instances of this + * interface can be registered to get control how multiple PropertySources are combined. This is useful in cases + * where the default overriding policy as implemented in {@link #DEFAULT_OVERRIDING_POLICY} is not matching + * the need of the current application, e.g. then entries containing multiple values should be combined to new + * values instead of overridden. + */ +public interface ConfigValueCombinationPolicy { + + /** + * Default overriding collector, where each existing entry ({@code current} is overridden by a subsequent non-null + * entry evaluated by {@code propertySource.get(key)}. + */ + ConfigValueCombinationPolicy DEFAULT_OVERRIDING_POLICY = (currentValue, key, propertySource) -> { + String value = propertySource.getValue(key); + String meta = propertySource.getValue(key+"[meta]"); + return value!=null? ConfigValue.builder(key, value).setMetaEntry(meta) + .build():currentValue; + }; + + /** + * @deprecated Use {@linkplain #DEFAULT_OVERRIDING_POLICY} instead. Will be removed in 1.0. + */ + @Deprecated + ConfigValueCombinationPolicy DEFAULT_OVERRIDING_COLLECTOR = DEFAULT_OVERRIDING_POLICY; + + + /** + * Method that is called for each value evaluated by a PropertySource for the given key. This method is called + * either when a single key is accessed, e.g. by calling {@code org.apache.tamaya.Configuration.getXXX}, but also + * when the full configuration property map is accessed by calling + * {@link Config#getPropertyNames()}}. + * + * @param currentValue the current value, including metadata entries. If no such key is present the current value + * is null. + * The collector should either combine the existing value with value from {@code currentValue} + * or replace the value in {@code currentValue} with {@code valueRead}, hereby returning the + * result to be used as new {@code currentValue}. + * @param key The current key to be evaluated. + * @param propertySource The PropertySource that may return an value for the given key. The PropertySource given + * may be evaluated for additional meta-data, how the given values are to be combined. + * Note that the value returned by a PropertySource can be null. In that case + * {@code currentValue} should be returned in almost all cases. + * @return the value to be used for future evaluation, including metadata entries. + */ + ConfigValue collect(ConfigValue currentValue, String key, ConfigSource propertySource); + +}