Repository: incubator-tamaya Updated Branches: refs/heads/master bf18659a5 -> 8745dd246
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/code/spi-support/src/test/java/org/apache/tamaya/spisupport/EmptyConfigurationContext.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/EmptyConfigurationContext.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/EmptyConfigurationContext.java index c5286e0..96d2cd4 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/EmptyConfigurationContext.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/EmptyConfigurationContext.java @@ -30,6 +30,11 @@ public class EmptyConfigurationContext implements ConfigurationContext{ private static final ConfigurationContext INSTANCE = new EmptyConfigurationContext(); @Override + public ServiceContext getServiceContext() { + return ServiceContextManager.getServiceContext(getClass().getClassLoader()); + } + + @Override public void addPropertySources(PropertySource... propertySources) { } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/code/spi-support/src/test/java/org/apache/tamaya/spisupport/EmptyConfigurationContextBuilder.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/EmptyConfigurationContextBuilder.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/EmptyConfigurationContextBuilder.java index 4f17d9a..5ea6bfa 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/EmptyConfigurationContextBuilder.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/EmptyConfigurationContextBuilder.java @@ -18,7 +18,6 @@ */ package org.apache.tamaya.spisupport; -import com.sun.org.apache.bcel.internal.generic.INSTANCEOF; import org.apache.tamaya.TypeLiteral; import org.apache.tamaya.spi.*; @@ -29,6 +28,16 @@ public class EmptyConfigurationContextBuilder implements ConfigurationContextBui private static final ConfigurationContextBuilder INSTANCE = new EmptyConfigurationContextBuilder(); @Override + public ConfigurationContextBuilder setClassLoader(ClassLoader classLoader) { + return this; + } + + @Override + public ConfigurationContextBuilder setServiceContext(ServiceContext serviceContext) { + return this; + } + + @Override public ConfigurationContextBuilder setContext(ConfigurationContext context) { return this; } @@ -164,6 +173,11 @@ public class EmptyConfigurationContextBuilder implements ConfigurationContextBui } @Override + public ServiceContext getServiceContext() { + return ServiceContextManager.getServiceContext(getClass().getClassLoader()); + } + + @Override public ConfigurationContext build() { return EmptyConfigurationContext.instance(); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/code/spi-support/src/test/java/org/apache/tamaya/spisupport/EnumConverterTest.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/EnumConverterTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/EnumConverterTest.java index c6d767d..ff068d2 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/EnumConverterTest.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/EnumConverterTest.java @@ -44,21 +44,22 @@ public class EnumConverterTest { @Test public void testConversionWithMixedCasing() { for (String input : Arrays.asList(RoundingMode.CEILING.toString(), "ceiling", "CeiLinG")) { - assertThat(RoundingMode.CEILING).isEqualTo(testConverter.convert(input, DUMMY_CONTEXT)); + assertThat(RoundingMode.CEILING).isEqualTo(testConverter.convert(input)); } } @Test public void testConvert_OtherValue() { - assertThat(testConverter.convert("fooBars", DUMMY_CONTEXT)).isNull(); + assertThat(testConverter.convert("fooBars")).isNull(); } @Test public void callToConvertAddsMoreSupportedFormatsToTheContext() throws Exception { ConversionContext context = new ConversionContext.Builder("someKey", TypeLiteral.of(Enum.class)).build(); + ConversionContext.set(context); EnumConverter<RoundingMode> converter = new EnumConverter<>(RoundingMode.class); - converter.convert("fooBars", context); - + converter.convert("fooBars"); + ConversionContext.reset();; assertThat(context.getSupportedFormats().contains("<enumValue> (EnumConverter)")).isTrue(); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/code/spi-support/src/test/java/org/apache/tamaya/spisupport/IntegerTestConverter.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/IntegerTestConverter.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/IntegerTestConverter.java index e6e6a2a..d028bcc 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/IntegerTestConverter.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/IntegerTestConverter.java @@ -19,6 +19,7 @@ package org.apache.tamaya.spisupport; import java.util.Objects; + import org.apache.tamaya.spi.ConversionContext; import org.apache.tamaya.spi.PropertyConverter; @@ -28,8 +29,9 @@ import org.apache.tamaya.spi.PropertyConverter; public class IntegerTestConverter implements PropertyConverter<Integer> { @Override - public Integer convert(String value, ConversionContext context) { - context.addSupportedFormats(getClass(), "<int>"); + public Integer convert(String value) { + ConversionContext.doOptional(ctx -> + ctx.addSupportedFormats(getClass(), "<int>")); String trimmed = Objects.requireNonNull(value).trim(); try { return Integer.decode(trimmed); http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/code/spi-support/src/test/java/org/apache/tamaya/spisupport/MockedConfigurationContext.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/MockedConfigurationContext.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/MockedConfigurationContext.java index 29a9492..23226b0 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/MockedConfigurationContext.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/MockedConfigurationContext.java @@ -23,12 +23,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.spi.ConfigurationContext; -import org.apache.tamaya.spi.ConfigurationContextBuilder; -import org.apache.tamaya.spi.PropertyConverter; -import org.apache.tamaya.spi.PropertyFilter; -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spi.PropertyValueCombinationPolicy; +import org.apache.tamaya.spi.*; /** * @@ -36,7 +31,8 @@ import org.apache.tamaya.spi.PropertyValueCombinationPolicy; */ public class MockedConfigurationContext implements ConfigurationContext { - PropertyConverterManager pcm = new PropertyConverterManager(false); + ServiceContext serviceContext = ServiceContextManager.getServiceContext(getClass().getClassLoader()); + PropertyConverterManager pcm = new PropertyConverterManager(serviceContext,false); List<PropertySource> pss = new ArrayList<>(); public MockedConfigurationContext() { @@ -45,6 +41,11 @@ public class MockedConfigurationContext implements ConfigurationContext { } @Override + public ServiceContext getServiceContext() { + return serviceContext; + } + + @Override public void addPropertySources(PropertySource... propertySources) { throw new RuntimeException("addPropertySources should be never called in this test"); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/code/spi-support/src/test/java/org/apache/tamaya/spisupport/MockedPropertyFilter.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/MockedPropertyFilter.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/MockedPropertyFilter.java index 9a56476..25b5623 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/MockedPropertyFilter.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/MockedPropertyFilter.java @@ -18,7 +18,6 @@ */ package org.apache.tamaya.spisupport; -import org.apache.tamaya.spi.FilterContext; import org.apache.tamaya.spi.PropertyFilter; import org.apache.tamaya.spi.PropertyValue; @@ -29,7 +28,7 @@ import org.apache.tamaya.spi.PropertyValue; public class MockedPropertyFilter implements PropertyFilter { @Override - public PropertyValue filterProperty(PropertyValue value, FilterContext context) { + public PropertyValue filterProperty(PropertyValue value) { if (value.getKey().contains("Filternull")) { return null; } else { http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/code/spi-support/src/test/java/org/apache/tamaya/spisupport/MockedPropertySource.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/MockedPropertySource.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/MockedPropertySource.java index 59ae3cd..b91c8f7 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/MockedPropertySource.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/MockedPropertySource.java @@ -58,7 +58,7 @@ public class MockedPropertySource implements PropertySource { @Override public PropertyValue get(String key) { if (key.contains("Null")) { - return PropertyValue.of(key, null, "MockedPropertySource"); + return null; } else if (key.contains("missing")){ return null; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/code/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java index 7cc74a6..0db0499 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java @@ -19,9 +19,12 @@ package org.apache.tamaya.spisupport; import java.lang.reflect.Method; + import org.apache.tamaya.spi.ConversionContext; import org.apache.tamaya.spi.PropertyConverter; import org.apache.tamaya.TypeLiteral; +import org.apache.tamaya.spi.ServiceContext; +import org.apache.tamaya.spi.ServiceContextManager; import org.junit.Test; import java.util.List; @@ -35,7 +38,8 @@ public class PropertyConverterManagerTest { @Test public void customTypeWithFactoryMethodOfIsRecognizedAsSupported() { - PropertyConverterManager manager = new PropertyConverterManager(true); + ServiceContext serviceContext = ServiceContextManager.getServiceContext(getClass().getClassLoader()); + PropertyConverterManager manager = new PropertyConverterManager(serviceContext, true); assertThat(manager.isTargetTypeSupported(TypeLiteral.of(MyType.class))) .isTrue(); @@ -43,7 +47,8 @@ public class PropertyConverterManagerTest { @Test public void factoryMethodOfIsUsedAsConverter() { - PropertyConverterManager manager = new PropertyConverterManager(true); + ServiceContext serviceContext = ServiceContextManager.getServiceContext(getClass().getClassLoader()); + PropertyConverterManager manager = new PropertyConverterManager(serviceContext, true); List<PropertyConverter<MyType>> converters = manager.getPropertyConverters( (TypeLiteral) TypeLiteral.of(MyType.class)); @@ -52,7 +57,7 @@ public class PropertyConverterManagerTest { PropertyConverter<MyType> converter = converters.get(0); - Object result = converter.convert("IN", DUMMY_CONTEXT); + Object result = converter.convert("IN"); assertThat(result).isNotNull(); assertThat(result).isInstanceOf(MyType.class); @@ -61,13 +66,14 @@ public class PropertyConverterManagerTest { @Test public void testDirectConverterMapping() { - PropertyConverterManager manager = new PropertyConverterManager(true); + ServiceContext serviceContext = ServiceContextManager.getServiceContext(getClass().getClassLoader()); + PropertyConverterManager manager = new PropertyConverterManager(serviceContext, true); assertThat(manager.isTargetTypeSupported(TypeLiteral.of(C.class))).isTrue(); List<PropertyConverter<C>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(C.class))); assertThat(converters).hasSize(1); PropertyConverter<C> converter = converters.get(0); - C result = converter.convert("testDirectConverterMapping", DUMMY_CONTEXT); + C result = converter.convert("testDirectConverterMapping"); assertThat(result).isNotNull(); assertThat(result).isInstanceOf(C.class); @@ -76,7 +82,8 @@ public class PropertyConverterManagerTest { @Test public void testDirectSuperclassConverterMapping() { - PropertyConverterManager manager = new PropertyConverterManager(true); + ServiceContext serviceContext = ServiceContextManager.getServiceContext(getClass().getClassLoader()); + PropertyConverterManager manager = new PropertyConverterManager(serviceContext, true); assertThat(manager.isTargetTypeSupported(TypeLiteral.of(B.class))).isTrue(); List<PropertyConverter<B>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class))); assertThat(converters).hasSize(1); @@ -84,7 +91,7 @@ public class PropertyConverterManagerTest { assertThat(converters).hasSize(1); PropertyConverter<B> converter = converters.get(0); - B result = converter.convert("testDirectSuperclassConverterMapping", DUMMY_CONTEXT); + B result = converter.convert("testDirectSuperclassConverterMapping"); assertThat(result).isNotNull(); assertThat(result).isInstanceOf(C.class); @@ -93,24 +100,26 @@ public class PropertyConverterManagerTest { @Test public void testMultipleConverterLoad() { - PropertyConverterManager manager = new PropertyConverterManager(true); + ServiceContext serviceContext = ServiceContextManager.getServiceContext(getClass().getClassLoader()); + PropertyConverterManager manager = new PropertyConverterManager(serviceContext, true); assertThat(manager.isTargetTypeSupported(TypeLiteral.of(B.class))).isTrue(); List<PropertyConverter<B>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class))); assertThat(converters).hasSize(1); - manager = new PropertyConverterManager(true); + manager = new PropertyConverterManager(serviceContext, true); converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class))); assertThat(converters).hasSize(1); } @Test public void testTransitiveSuperclassConverterMapping() { - PropertyConverterManager manager = new PropertyConverterManager(true); + ServiceContext serviceContext = ServiceContextManager.getServiceContext(getClass().getClassLoader()); + PropertyConverterManager manager = new PropertyConverterManager(serviceContext, true); assertThat(manager.isTargetTypeSupported(TypeLiteral.of(A.class))).isTrue(); List<PropertyConverter<A>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(A.class))); assertThat(converters).hasSize(1); PropertyConverter<A> converter = converters.get(0); - A result = converter.convert("testTransitiveSuperclassConverterMapping", DUMMY_CONTEXT); + A result = converter.convert("testTransitiveSuperclassConverterMapping"); assertThat(result).isNotNull(); assertThat(result).isInstanceOf(C.class); @@ -119,13 +128,14 @@ public class PropertyConverterManagerTest { @Test public void testDirectInterfaceMapping() { - PropertyConverterManager manager = new PropertyConverterManager(true); + ServiceContext serviceContext = ServiceContextManager.getServiceContext(getClass().getClassLoader()); + PropertyConverterManager manager = new PropertyConverterManager(serviceContext, true); assertThat(manager.isTargetTypeSupported(TypeLiteral.of(Readable.class))).isTrue(); List<PropertyConverter<Readable>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(Readable.class))); assertThat(converters).hasSize(1); PropertyConverter<Readable> converter = converters.get(0); - Readable result = converter.convert("testDirectInterfaceMapping", DUMMY_CONTEXT); + Readable result = converter.convert("testDirectInterfaceMapping"); assertThat(result).isNotNull(); assertThat(result).isInstanceOf(C.class); @@ -134,13 +144,14 @@ public class PropertyConverterManagerTest { @Test public void testTransitiveInterfaceMapping1() { - PropertyConverterManager manager = new PropertyConverterManager(true); + ServiceContext serviceContext = ServiceContextManager.getServiceContext(getClass().getClassLoader()); + PropertyConverterManager manager = new PropertyConverterManager(serviceContext, true); assertThat(manager.isTargetTypeSupported(TypeLiteral.of(Runnable.class))).isTrue(); List<PropertyConverter<Runnable>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(Runnable.class))); assertThat(converters).hasSize(1); PropertyConverter<Runnable> converter = converters.get(0); - Runnable result = converter.convert("testTransitiveInterfaceMapping1", DUMMY_CONTEXT); + Runnable result = converter.convert("testTransitiveInterfaceMapping1"); assertThat(result).isNotNull(); assertThat(result).isInstanceOf(C.class); @@ -149,13 +160,14 @@ public class PropertyConverterManagerTest { @Test public void testTransitiveInterfaceMapping2() { - PropertyConverterManager manager = new PropertyConverterManager(true); + ServiceContext serviceContext = ServiceContextManager.getServiceContext(getClass().getClassLoader()); + PropertyConverterManager manager = new PropertyConverterManager(serviceContext, true); assertThat(manager.isTargetTypeSupported(TypeLiteral.of(AutoCloseable.class))).isTrue(); List<PropertyConverter<AutoCloseable>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(AutoCloseable.class))); assertThat(converters).hasSize(1); PropertyConverter<AutoCloseable> converter = converters.get(0); - AutoCloseable result = converter.convert("testTransitiveInterfaceMapping2", DUMMY_CONTEXT); + AutoCloseable result = converter.convert("testTransitiveInterfaceMapping2"); assertThat(result).isNotNull(); assertThat(result).isInstanceOf(C.class); @@ -164,14 +176,15 @@ public class PropertyConverterManagerTest { @Test public void testBoxedConverterMapping() { - PropertyConverterManager manager = new PropertyConverterManager(true); + ServiceContext serviceContext = ServiceContextManager.getServiceContext(getClass().getClassLoader()); + PropertyConverterManager manager = new PropertyConverterManager(serviceContext, true); assertThat(manager.isTargetTypeSupported(TypeLiteral.of(int.class))).isFalse(); assertThat(manager.isTargetTypeSupported(TypeLiteral.of(Integer.class))).isTrue(); List<PropertyConverter<Integer>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(int.class))); assertThat(converters).hasSize(1); PropertyConverter<Integer> converter = converters.get(0); - Integer result = converter.convert("101", DUMMY_CONTEXT); + Integer result = converter.convert("101"); assertThat(result).isNotNull(); assertThat(result).isInstanceOf(Integer.class); @@ -181,7 +194,8 @@ public class PropertyConverterManagerTest { @Test public void testCreateEnumPropertyConverter() { - PropertyConverterManager manager = new PropertyConverterManager(false); + ServiceContext serviceContext = ServiceContextManager.getServiceContext(getClass().getClassLoader()); + PropertyConverterManager manager = new PropertyConverterManager(serviceContext, false); PropertyConverter pc = manager.createDefaultPropertyConverter(TypeLiteral.of(MyEnum.class)); assertThat(pc instanceof EnumConverter).isTrue(); assertThat(manager.isTargetTypeSupported(TypeLiteral.of(MyEnum.class))).isTrue(); @@ -189,7 +203,8 @@ public class PropertyConverterManagerTest { @Test public void testGetFactoryMethod() throws Exception { - PropertyConverterManager manager = new PropertyConverterManager(false); + ServiceContext serviceContext = ServiceContextManager.getServiceContext(getClass().getClassLoader()); + PropertyConverterManager manager = new PropertyConverterManager(serviceContext, false); Method getFactoryMethod = PropertyConverterManager.class.getDeclaredMethod("getFactoryMethod", new Class[]{Class.class, String[].class}); getFactoryMethod.setAccessible(true); @@ -208,7 +223,8 @@ public class PropertyConverterManagerTest { @Test public void testMapBoxedType() throws Exception { - PropertyConverterManager manager = new PropertyConverterManager(false); + ServiceContext serviceContext = ServiceContextManager.getServiceContext(getClass().getClassLoader()); + PropertyConverterManager manager = new PropertyConverterManager(serviceContext, false); Class[] boxed = new Class[]{ Integer[].class, Short[].class, Byte[].class, Long[].class, http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/code/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyFilterComparatorTest.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyFilterComparatorTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyFilterComparatorTest.java index 9a212f7..ee46ede 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyFilterComparatorTest.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyFilterComparatorTest.java @@ -18,10 +18,8 @@ */ package org.apache.tamaya.spisupport; -import org.apache.tamaya.spi.FilterContext; import org.apache.tamaya.spi.PropertyFilter; import org.apache.tamaya.spi.PropertyValue; -import org.apache.tamaya.spisupport.PropertyFilterComparator; import org.junit.Test; import javax.annotation.Priority; @@ -62,14 +60,14 @@ public class PropertyFilterComparatorTest { @Priority(1) private static class PropertyFilterA implements PropertyFilter { - public PropertyValue filterProperty(PropertyValue value, FilterContext context) { + public PropertyValue filterProperty(PropertyValue value) { throw new RuntimeException("Not implemented or look at me!"); } } @Priority(2) private static class PropertyFilterB implements PropertyFilter { - public PropertyValue filterProperty(PropertyValue value, FilterContext context) { + public PropertyValue filterProperty(PropertyValue value) { throw new RuntimeException("Not implemented or look at me!"); } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/code/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java index 06e0890..aa0fe85 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java @@ -19,7 +19,6 @@ package org.apache.tamaya.spisupport; import org.apache.tamaya.spi.ConfigurationContext; -import org.apache.tamaya.spi.FilterContext; import org.apache.tamaya.spi.PropertyValue; import java.util.HashMap; @@ -45,31 +44,29 @@ public class RegexPropertyFilterTest { map.put(prop1.getKey(), prop1); map.put(prop2.getKey(), prop2); map.put(prop3.getKey(), prop3); - assertThat(filter.filterProperty(prop1, new FilterContext(prop1, configContext))).isEqualTo(prop1); - assertThat(filter.filterProperty(prop2, new FilterContext(prop2, configContext))).isNull(); + assertThat(filter.filterProperty(prop1)).isEqualTo(prop1); + assertThat(filter.filterProperty(prop2)).isNull(); assertThat(filter.filterProperty( - prop3, - new FilterContext(prop3, map, configContext))).isEqualTo(prop3); + prop3)).isEqualTo(prop3); assertThat(filter.filterProperty( - prop3, - new FilterContext(prop3, map, configContext))).isEqualTo(prop3); + prop3)).isEqualTo(prop3); filter = new RegexPropertyFilter(); filter.setIncludes("test1.*"); - assertThat(filter.filterProperty(prop1, new FilterContext(prop1, map, configContext))).isNotNull(); - assertThat(filter.filterProperty(prop2, new FilterContext(prop2, map, configContext))).isNull(); - assertThat(filter.filterProperty(prop3, new FilterContext(prop3, map, configContext))).isNotNull(); + assertThat(filter.filterProperty(prop1)).isNotNull(); + assertThat(filter.filterProperty(prop2)).isNull(); + assertThat(filter.filterProperty(prop3)).isNotNull(); filter = new RegexPropertyFilter(); filter.setExcludes("test1.*"); - assertThat(filter.filterProperty(prop1, new FilterContext(prop1, map, configContext))).isNull(); - assertThat(filter.filterProperty(prop2, new FilterContext(prop2, map, configContext))).isEqualTo(prop2); - assertThat(filter.filterProperty(prop3, new FilterContext(prop3, map, configContext))).isNull(); + assertThat(filter.filterProperty(prop1)).isNull(); + assertThat(filter.filterProperty(prop2)).isEqualTo(prop2); + assertThat(filter.filterProperty(prop3)).isNull(); filter = new RegexPropertyFilter(); filter.setIncludes("test1.*"); //Includes overrides Excludes filter.setExcludes("test1.*"); - assertThat(filter.filterProperty(prop1, new FilterContext(prop1, map, configContext))).isNotNull(); - assertThat(filter.filterProperty(prop2, new FilterContext(prop2, map, configContext))).isNull(); - assertThat(filter.filterProperty(prop3, new FilterContext(prop3, map, configContext))).isNotNull(); + assertThat(filter.filterProperty(prop1)).isNotNull(); + assertThat(filter.filterProperty(prop2)).isNull(); + assertThat(filter.filterProperty(prop3)).isNotNull(); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/code/spi-support/src/test/java/org/apache/tamaya/spisupport/TestConfigurationProvider.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/TestConfigurationProvider.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/TestConfigurationProvider.java index 9af9a5c..b20e02a 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/TestConfigurationProvider.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/TestConfigurationProvider.java @@ -41,7 +41,7 @@ public class TestConfigurationProvider implements ConfigurationProviderSpi { .addDefaultPropertySources() .build(); @Override - public Configuration getConfiguration() { + public Configuration getConfiguration(ClassLoader classLoader) { return config; } @@ -61,13 +61,13 @@ public class TestConfigurationProvider implements ConfigurationProviderSpi { } @Override - public void setConfiguration(Configuration config) { + public void setConfiguration(Configuration config, ClassLoader classLoader) { Objects.requireNonNull(config.getContext()); this.config = Objects.requireNonNull(config); } @Override - public boolean isConfigurationSettable() { + public boolean isConfigurationSettable(ClassLoader classLoader) { return true; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnumConverterTest.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnumConverterTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnumConverterTest.java index 281652a..a78a3d6 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnumConverterTest.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnumConverterTest.java @@ -38,21 +38,21 @@ public class EnumConverterTest { @Test public void testConvert() { - assertThat(testConverter.convert(RoundingMode.CEILING.toString(), DUMMY_CONTEXT)).isEqualTo(RoundingMode.CEILING); + assertThat(testConverter.convert(RoundingMode.CEILING.toString())).isEqualTo(RoundingMode.CEILING); } @Test public void testConvert_LowerCase() { - assertThat(RoundingMode.CEILING).isEqualTo(testConverter.convert("ceiling", DUMMY_CONTEXT)); + assertThat(RoundingMode.CEILING).isEqualTo(testConverter.convert("ceiling")); } @Test public void testConvert_MixedCase() { - assertThat(RoundingMode.CEILING).isEqualTo(testConverter.convert("CeiLinG", DUMMY_CONTEXT)); + assertThat(RoundingMode.CEILING).isEqualTo(testConverter.convert("CeiLinG")); } @Test public void testConvert_OtherValue() { - assertThat(testConverter.convert("fooBars", DUMMY_CONTEXT)).isNull(); + assertThat(testConverter.convert("fooBars")).isNull(); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySourceTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySourceTest.java index 6f21320..2b7928e 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySourceTest.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySourceTest.java @@ -109,15 +109,9 @@ public class EnvironmentPropertySourceTest { } } - @Ignore("Why is this test case disabled?") @Test public void testPrefixedGet() throws Exception { - System.setProperty("tamaya.envprops.prefix", "fancyprefix"); - System.setProperty("tamaya.envprops.disable", "false"); - System.setProperty("tamaya.defaults.disable", "false"); - // works: EnvironmentPropertySource localEnvironmentPropertySource = new - // EnvironmentPropertySource("fancyprefix"); - EnvironmentPropertySource localEnvironmentPropertySource = new EnvironmentPropertySource(); + EnvironmentPropertySource localEnvironmentPropertySource = new EnvironmentPropertySource("fancyprefix"); System.out.println(localEnvironmentPropertySource); assertThat(localEnvironmentPropertySource.getPrefix()).isEqualTo("fancyprefix"); localEnvironmentPropertySource.setPropertiesProvider(new MockedSystemPropertiesProvider()); http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/JavaConfigurationProviderTest.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/JavaConfigurationProviderTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/JavaConfigurationProviderTest.java index d54ac50..284ee82 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/JavaConfigurationProviderTest.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/JavaConfigurationProviderTest.java @@ -34,8 +34,9 @@ public class JavaConfigurationProviderTest { @Test public void loadsSimpleAndXMLPropertyFilesProper() { - PropertySource propertySource = new JavaConfigurationPropertySource(); - assertThat(propertySource.getProperties().keySet()).hasSize(7); // double the size for .source values. + JavaConfigurationPropertySource propertySource = new JavaConfigurationPropertySource(); + propertySource.init(getClass().getClassLoader()); + assertThat(propertySource.getProperties().keySet()).hasSize(7); // double the getNumChilds for .source values. for (int i = 1; i < 6; i++) { String key = "confkey" + i; http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/PropertiesResourcePropertySourceTest.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/PropertiesResourcePropertySourceTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/PropertiesResourcePropertySourceTest.java index 57f695c..b1337fd 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/PropertiesResourcePropertySourceTest.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/PropertiesResourcePropertySourceTest.java @@ -36,7 +36,7 @@ public class PropertiesResourcePropertySourceTest { public void testBasicConstructor() { PropertiesResourcePropertySource source = new PropertiesResourcePropertySource(resource); assertThat(source).isNotNull(); - assertThat(5 == source.getProperties().size()).isTrue(); // double the size for .source values. + assertThat(5 == source.getProperties().size()).isTrue(); // double the getNumChilds for .source values. assertThat(source.getProperties().containsKey("key1")).isTrue(); } @@ -73,7 +73,8 @@ public class PropertiesResourcePropertySourceTest { @Test public void testPrefixedPathClassloaderConstructor() { - PropertiesResourcePropertySource source = new PropertiesResourcePropertySource(testFileName, "somePrefix", null); + PropertiesResourcePropertySource source = new PropertiesResourcePropertySource(testFileName, "somePrefix", + getClass().getClassLoader()); assertThat(source).isNotNull(); assertThat(5 == source.getProperties().size()).isTrue(); assertThat(source.getProperties().containsKey("somePrefixkey1")).isTrue(); http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java index 3b53b32..f98ccac 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java @@ -40,7 +40,7 @@ public class SimplePropertySourceTest { SimplePropertySource source = new SimplePropertySource(resource); assertThat(source).isNotNull(); - assertThat(source.getProperties()).hasSize(2); // double the size for .source values. + assertThat(source.getProperties()).hasSize(2); // double the getNumChilds for .source values. assertThat(source.getProperties()).contains(entry("a", PropertyValue.of("a", "b", resource.toString()))); assertThat(source.getProperties()).contains(entry("b", PropertyValue.of("b", "1", resource.toString()))); } @@ -84,7 +84,7 @@ public class SimplePropertySourceTest { SimplePropertySource source = new SimplePropertySource(resource); assertThat(source).isNotNull(); - assertThat(source.getProperties()).hasSize(5); // double the size for .source values. + assertThat(source.getProperties()).hasSize(5); // double the getNumChilds for .source values. } @Test http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.java index 8bf4d99..0139268 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.java @@ -83,7 +83,7 @@ public class SystemPropertySourceTest { // test the default ordinal assertThat(testPropertySource.getOrdinal()).isEqualTo(SystemPropertySource.DEFAULT_ORDINAL); - // set the ordinal to 1001 + // setCurrent the ordinal to 1001 System.setProperty(PropertySource.TAMAYA_ORDINAL, "1001"); assertThat(new SystemPropertySource().getOrdinal()).isEqualTo(1001); // currently its not possible to change ordinal at runtime @@ -135,7 +135,7 @@ public class SystemPropertySourceTest { int num = 0; for (PropertyValue propertySourceEntry : toCheck.values()) { if (propertySourceEntry.getKey().startsWith("_")) { - continue; // meta entry + continue; // getMeta entry } num++; assertThat(systemEntries.getProperty(propertySourceEntry.getKey())).isEqualTo(propertySourceEntry.getValue()); http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/TestPropertyDefaultSource.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/TestPropertyDefaultSource.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/TestPropertyDefaultSource.java index b326abc..b9b9dd0 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/TestPropertyDefaultSource.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/TestPropertyDefaultSource.java @@ -18,7 +18,6 @@ */ package org.apache.tamaya.spisupport.propertysource; -import org.apache.tamaya.spisupport.propertysource.BasePropertySource; import org.apache.tamaya.spi.PropertyValue; import java.util.Collections; @@ -34,7 +33,7 @@ public class TestPropertyDefaultSource extends BasePropertySource{ public TestPropertyDefaultSource() { super(100); - properties.put("name",PropertyValue.of("name", "Anatole", "Test")); + properties.put("name", PropertyValue.of("name", "Anatole", "Test")); properties.put("name2",PropertyValue.of("name2", "Sabine", "Test")); properties = Collections.unmodifiableMap(properties); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/WrappedPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/WrappedPropertySourceTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/WrappedPropertySourceTest.java index 26d68ae..bfbddf1 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/WrappedPropertySourceTest.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/WrappedPropertySourceTest.java @@ -75,7 +75,7 @@ public class WrappedPropertySourceTest { /** - * Test of get method, of class WrappedPropertySource. + * Test of current method, of class WrappedPropertySource. */ @Test public void testGet() { http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/code/spi-support/src/test/java/org/apache/tamaya/spisupport/services/DefaultServiceContext.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/services/DefaultServiceContext.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/services/DefaultServiceContext.java index 46d69da..963bfbb 100644 --- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/services/DefaultServiceContext.java +++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/services/DefaultServiceContext.java @@ -41,6 +41,21 @@ public final class DefaultServiceContext implements ServiceContext { * List current services loaded, per class. */ private final ConcurrentHashMap<Class<?>, List<Object>> servicesLoaded = new ConcurrentHashMap<>(); + + /** + * The classloader to be used by this instance. + */ + private ClassLoader classLoader; + + @Override + public void init(ClassLoader classLoader) { + if(this.classLoader==null){ + this.classLoader = classLoader; + }else{ + throw new IllegalStateException("Classloader already setCurrent on this context."); + } + } + /** * Singletons. */ @@ -176,30 +191,23 @@ public final class DefaultServiceContext implements ServiceContext { } @Override + public ClassLoader getClassLoader() { + return classLoader; + } + + @Override public int ordinal() { return 1; } @Override - public Enumeration<URL> getResources(String resource, ClassLoader cl) throws IOException { - if(cl==null){ - cl = Thread.currentThread().getContextClassLoader(); - } - if(cl==null){ - cl = getClass().getClassLoader(); - } - return cl.getResources(resource); + public Enumeration<URL> getResources(String resource) throws IOException { + return classLoader.getResources(resource); } @Override - public URL getResource(String resource, ClassLoader cl) { - if(cl==null){ - cl = Thread.currentThread().getContextClassLoader(); - } - if(cl==null){ - cl = getClass().getClassLoader(); - } - return cl.getResource(resource); + public URL getResource(String resource) { + return classLoader.getResource(resource); } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/distribution/src/main/assembly/distribution-src.xml ---------------------------------------------------------------------- diff --git a/distribution/src/main/assembly/distribution-src.xml b/distribution/src/main/assembly/distribution-src.xml index 986fdeb..4fb20dd 100644 --- a/distribution/src/main/assembly/distribution-src.xml +++ b/distribution/src/main/assembly/distribution-src.xml @@ -42,7 +42,7 @@ under the License. </excludes> <includes> </includes> - <outputDirectory>${project.basedir}</outputDirectory> + <outputDirectory>/</outputDirectory> </fileSet> </fileSets> </assembly> http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/e45effd2/distribution/src/main/assembly/index.html ---------------------------------------------------------------------- diff --git a/distribution/src/main/assembly/index.html b/distribution/src/main/assembly/index.html index 7dddf5b..8fe02e1 100644 --- a/distribution/src/main/assembly/index.html +++ b/distribution/src/main/assembly/index.html @@ -21,7 +21,7 @@ under the License. <head> <meta charset="UTF-8"> <!--[if IE]> - <meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]--> + <getMeta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]--> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="generator" content="Asciidoctor 1.5.2"> <title>Tamaya Documentation</title>
