You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2017/11/14 09:25:53 UTC
[12/12] incubator-tamaya git commit: TAMAYA-318 Moved spi-support as
API base implementation package to remove code duplicates.
TAMAYA-318 Moved spi-support as API base implementation package to remove code duplicates.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/545e1779
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/545e1779
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/545e1779
Branch: refs/heads/master
Commit: 545e1779bd77057e8cf0617acb1638ee4576c9f3
Parents: aa6dbe6
Author: Anatole Tresch <an...@apache.org>
Authored: Tue Nov 14 10:25:18 2017 +0100
Committer: Anatole Tresch <an...@apache.org>
Committed: Tue Nov 14 10:25:18 2017 +0100
----------------------------------------------------------------------
code/api/pom.xml | 2 +-
.../org/apache/tamaya/core/OSGIActivator.java | 4 +-
.../core/internal/CoreConfigurationContext.java | 52 +++
.../CoreConfigurationContextBuilder.java | 93 ++++
.../internal/DefaultConfigurationContext.java | 291 ------------
.../DefaultConfigurationContextBuilder.java | 461 -------------------
.../internal/DefaultConfigurationProvider.java | 4 +-
...pache.tamaya.spi.ConfigurationContextBuilder | 2 +-
.../core/ConfigurationContextBuilderTest.java | 8 +-
.../CoreConfigurationContextBuilderTest.java | 200 ++++++++
.../internal/CoreConfigurationContextTest.java | 176 +++++++
.../DefaultConfigurationContextBuilderTest.java | 200 --------
.../DefaultConfigurationContextTest.java | 176 -------
.../DefaultConfigurationProviderTest.java | 2 +-
code/spi-support/pom.xml | 2 +-
.../spisupport/DefaultConfigurationContext.java | 277 +++++++++++
.../DefaultConfigurationContextBuilder.java | 437 ++++++++++++++++++
.../examples/minimal/TestConfigProvider.java | 30 +-
18 files changed, 1274 insertions(+), 1143 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/545e1779/code/api/pom.xml
----------------------------------------------------------------------
diff --git a/code/api/pom.xml b/code/api/pom.xml
index 99f08dd..581e18d 100644
--- a/code/api/pom.xml
+++ b/code/api/pom.xml
@@ -26,7 +26,7 @@ under the License.
</parent>
<artifactId>tamaya-api</artifactId>
- <name>Apache Tamaya API</name>
+ <name>Apache Tamaya Core API</name>
<packaging>jar</packaging>
<description>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/545e1779/code/core/src/main/java/org/apache/tamaya/core/OSGIActivator.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/OSGIActivator.java b/code/core/src/main/java/org/apache/tamaya/core/OSGIActivator.java
index 09bf384..3ddaf69 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/OSGIActivator.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/OSGIActivator.java
@@ -24,7 +24,7 @@ import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.core.internal.*;
import org.apache.tamaya.spi.ServiceContextManager;
import org.apache.tamaya.spisupport.DefaultConfiguration;
-import org.apache.tamaya.core.internal.DefaultConfigurationContextBuilder;
+import org.apache.tamaya.core.internal.CoreConfigurationContextBuilder;
import org.apache.tamaya.spisupport.PropertyFilterComparator;
import org.apache.tamaya.spisupport.PropertySourceComparator;
import org.osgi.framework.BundleActivator;
@@ -50,7 +50,7 @@ public class OSGIActivator implements BundleActivator {
LOG.info("Registered Tamaya OSGI ServiceContext...");
ConfigurationProvider.setConfiguration(
new DefaultConfiguration(
- new DefaultConfigurationContextBuilder()
+ new CoreConfigurationContextBuilder()
.addDefaultPropertyConverters()
.addDefaultPropertyFilters()
.addDefaultPropertySources()
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/545e1779/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationContext.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationContext.java b/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationContext.java
new file mode 100644
index 0000000..dd31b91
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationContext.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.core.internal.converters.*;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
+import org.apache.tamaya.spisupport.DefaultConfigurationContext;
+import org.apache.tamaya.spisupport.DefaultConfigurationContextBuilder;
+
+import java.io.File;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.net.URI;
+import java.net.URL;
+import java.nio.file.Path;
+import java.util.Currency;
+
+/**
+ * Default implementation of {@link ConfigurationContextBuilder}.
+ */
+public final class CoreConfigurationContext extends DefaultConfigurationContext {
+
+ /**
+ * Creates a new builder instance.
+ */
+ public CoreConfigurationContext(CoreConfigurationContextBuilder builder) {
+ super(builder);
+ }
+
+ @Override
+ public ConfigurationContextBuilder toBuilder() {
+ return new CoreConfigurationContextBuilder(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/545e1779/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationContextBuilder.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationContextBuilder.java b/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationContextBuilder.java
new file mode 100644
index 0000000..d440a88
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationContextBuilder.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.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.PropertySourceProvider;
+import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
+import org.apache.tamaya.spi.ServiceContextManager;
+import org.apache.tamaya.core.internal.converters.*;
+import org.apache.tamaya.spisupport.DefaultConfigurationContextBuilder;
+import org.apache.tamaya.spisupport.PropertySourceComparator;
+import org.apache.tamaya.spisupport.propertysource.CLIPropertySource;
+import org.apache.tamaya.spisupport.propertysource.EnvironmentPropertySource;
+import org.apache.tamaya.spisupport.propertysource.JavaConfigurationPropertySource;
+import org.apache.tamaya.spisupport.propertysource.SystemPropertySource;
+
+import java.io.File;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.net.URI;
+import java.net.URL;
+import java.nio.file.Path;
+import java.util.*;
+import java.util.logging.Logger;
+
+/**
+ * Default implementation of {@link ConfigurationContextBuilder}.
+ */
+public final class CoreConfigurationContextBuilder extends DefaultConfigurationContextBuilder {
+
+ /**
+ * Creates a new builder instance.
+ */
+ public CoreConfigurationContextBuilder() {
+ }
+
+ /**
+ * Creates a new builder instance initializing it with the given context.
+ * @param context the context to be used, not null.
+ */
+ public CoreConfigurationContextBuilder(ConfigurationContext context) {
+ super(context);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void addCorePropertyConverters() {
+ addPropertyConverters(TypeLiteral.<BigDecimal>of(BigDecimal.class), new BigDecimalConverter());
+ addPropertyConverters(TypeLiteral.<BigInteger>of(BigInteger.class), new BigIntegerConverter());
+ addPropertyConverters(TypeLiteral.<Boolean>of(Boolean.class), new BooleanConverter());
+ addPropertyConverters(TypeLiteral.<Byte>of(Byte.class), new ByteConverter());
+ addPropertyConverters(TypeLiteral.<Character>of(Character.class), new CharConverter());
+ addPropertyConverters(TypeLiteral.<Class<?>>of(Class.class), new ClassConverter());
+ addPropertyConverters(TypeLiteral.<Currency>of(Currency.class), new CurrencyConverter());
+ addPropertyConverters(TypeLiteral.<Double>of(Double.class), new DoubleConverter());
+ addPropertyConverters(TypeLiteral.<File>of(File.class), new FileConverter());
+ addPropertyConverters(TypeLiteral.<Float>of(Float.class), new FloatConverter());
+ addPropertyConverters(TypeLiteral.<Integer>of(Integer.class), new IntegerConverter());
+ addPropertyConverters(TypeLiteral.<Long>of(Long.class), new LongConverter());
+ addPropertyConverters(TypeLiteral.<Number>of(Number.class), new NumberConverter());
+ addPropertyConverters(TypeLiteral.<Path>of(Path.class), new PathConverter());
+ addPropertyConverters(TypeLiteral.<Short>of(Short.class), new ShortConverter());
+ addPropertyConverters(TypeLiteral.<URI>of(URI.class), new URIConverter());
+ addPropertyConverters(TypeLiteral.<URL>of(URL.class), new URLConverter());
+ }
+
+ @Override
+ public ConfigurationContext build() {
+ return new CoreConfigurationContext(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/545e1779/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
deleted file mode 100644
index 95ebbca..0000000
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.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.PropertyValue;
-import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
-import org.apache.tamaya.spi.ServiceContextManager;
-import org.apache.tamaya.spisupport.PropertyConverterManager;
-import org.apache.tamaya.spisupport.PropertySourceComparator;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-import java.util.logging.Logger;
-
-/**
- * Default implementation of a simple ConfigurationContext.
- */
-public class DefaultConfigurationContext implements ConfigurationContext {
-
- /** The logger used. */
- private final static Logger LOG = Logger.getLogger(DefaultConfigurationContext.class.getName());
-
- /**
- * Subcomponent handling {@link org.apache.tamaya.spi.PropertyConverter} instances.
- */
- private final PropertyConverterManager propertyConverterManager = new PropertyConverterManager();
-
- /**
- * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertySource} instances.
- */
- private List<PropertySource> immutablePropertySources;
-
- /**
- * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertyFilter} instances.
- */
- private List<PropertyFilter> immutablePropertyFilters;
-
- /**
- * The overriding policy used when combining PropertySources registered to evalute the final configuration
- * values.
- */
- private PropertyValueCombinationPolicy propertyValueCombinationPolicy;
-
- /**
- * Lock for internal synchronization.
- */
- private final ReentrantReadWriteLock propertySourceLock = new ReentrantReadWriteLock();
-
- @SuppressWarnings("unchecked")
- DefaultConfigurationContext(DefaultConfigurationContextBuilder builder) {
- List<PropertySource> propertySources = new ArrayList<>();
- // first we load all PropertySources which got registered via java.util.ServiceLoader
- propertySources.addAll(builder.propertySources);
- // now sort them according to their ordinal values
- immutablePropertySources = Collections.unmodifiableList(propertySources);
-
- // as next step we pick up the PropertyFilters pretty much the same way
- List<PropertyFilter> propertyFilters = new ArrayList<>(builder.getPropertyFilters());
- immutablePropertyFilters = Collections.unmodifiableList(propertyFilters);
-
- // Finally add the converters
- for(Map.Entry<TypeLiteral<?>, Collection<PropertyConverter<?>>> en:builder.getPropertyConverter().entrySet()) {
- for (@SuppressWarnings("rawtypes") PropertyConverter converter : en.getValue()) {
- this.propertyConverterManager.register(en.getKey(), converter);
- }
- }
- LOG.info("Registered " + propertyConverterManager.getPropertyConverters().size() + " property converters: " +
- propertyConverterManager.getPropertyConverters());
-
- propertyValueCombinationPolicy = builder.combinationPolicy;
- if(propertyValueCombinationPolicy==null){
- propertyValueCombinationPolicy = ServiceContextManager.getServiceContext().getService(PropertyValueCombinationPolicy.class);
- }
- if(propertyValueCombinationPolicy==null){
- propertyValueCombinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR;
- }
- LOG.info("Using PropertyValueCombinationPolicy: " + propertyValueCombinationPolicy);
- }
-
-
- @Deprecated
- @Override
- public void addPropertySources(PropertySource... propertySourcesToAdd) {
- Lock writeLock = propertySourceLock.writeLock();
- try {
- writeLock.lock();
- List<PropertySource> newPropertySources = new ArrayList<>(this.immutablePropertySources);
- newPropertySources.addAll(Arrays.asList(propertySourcesToAdd));
- Collections.sort(newPropertySources, PropertySourceComparator.getInstance());
-
- this.immutablePropertySources = Collections.unmodifiableList(newPropertySources);
- } finally {
- writeLock.unlock();
- }
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof DefaultConfigurationContext)){
- return false;
- }
-
- DefaultConfigurationContext that = (DefaultConfigurationContext) o;
-
- if (!propertyConverterManager.equals(that.propertyConverterManager)) {
- return false;
- }
- if (!immutablePropertySources.equals(that.immutablePropertySources)) {
- return false;
- }
- if (!immutablePropertyFilters.equals(that.immutablePropertyFilters)) {
- return false;
- }
- return getPropertyValueCombinationPolicy().equals(that.getPropertyValueCombinationPolicy());
-
- }
-
- @Override
- public int hashCode() {
- int result = propertyConverterManager.hashCode();
- result = 31 * result + immutablePropertySources.hashCode();
- result = 31 * result + immutablePropertyFilters.hashCode();
- result = 31 * result + getPropertyValueCombinationPolicy().hashCode();
- return result;
- }
-
- @Override
- public String toString() {
- StringBuilder b = new StringBuilder("ConfigurationContext{\n");
- b.append(" Property Sources\n");
- b.append(" ----------------\n");
- if(immutablePropertySources.isEmpty()){
- b.append(" No property sources loaded.\n\n");
- }else {
- b.append(" CLASS NAME ORDINAL SCANNABLE SIZE STATE ERROR\n\n");
- for (PropertySource ps : immutablePropertySources) {
- b.append(" ");
- appendFormatted(b, ps.getClass().getSimpleName(), 30);
- appendFormatted(b, ps.getName(), 70);
- appendFormatted(b, String.valueOf(PropertySourceComparator.getOrdinal(ps)), 8);
- appendFormatted(b, String.valueOf(ps.isScannable()), 10);
- if (ps.isScannable()) {
- appendFormatted(b, String.valueOf(ps.getProperties().size()), 8);
- } else {
- appendFormatted(b, "-", 8);
- }
- PropertyValue state = ps.get("_state");
- if(state==null){
- appendFormatted(b, "OK", 10);
- }else {
- appendFormatted(b, state.getValue(), 10);
- if("ERROR".equals(state.getValue())){
- PropertyValue val = ps.get("_exception");
- if(val!=null) {
- appendFormatted(b, val.getValue(), 30);
- }
- }
- }
- b.append('\n');
- }
- b.append("\n");
- }
- b.append(" Property Filters\n");
- b.append(" ----------------\n");
- if(immutablePropertyFilters.isEmpty()){
- b.append(" No property filters loaded.\n\n");
- }else {
- b.append(" CLASS INFO\n\n");
- for (PropertyFilter filter : getPropertyFilters()) {
- b.append(" ");
- appendFormatted(b, filter.getClass().getSimpleName(), 30);
- b.append(removeNewLines(filter.toString()));
- b.append('\n');
- }
- b.append("\n\n");
- }
- b.append(" Property Converters\n");
- b.append(" -------------------\n");
- b.append(" CLASS TYPE INFO\n\n");
- for(Map.Entry<TypeLiteral<?>, List<PropertyConverter<?>>> converterEntry:getPropertyConverters().entrySet()){
- for(PropertyConverter converter: converterEntry.getValue()){
- b.append(" ");
- appendFormatted(b, converter.getClass().getSimpleName(), 30);
- appendFormatted(b, converterEntry.getKey().getRawType().getSimpleName(), 30);
- b.append(removeNewLines(converter.toString()));
- b.append('\n');
- }
- }
- b.append("\n\n");
- b.append(" PropertyValueCombinationPolicy: " + getPropertyValueCombinationPolicy().getClass().getName()).append('\n');
- b.append('}');
- return b.toString();
- }
-
- private 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(' ');
- }
- }
-
- private String removeNewLines(String s) {
- return s.replace('\n', ' ').replace('\r', ' ');
- }
-
-
- @Override
- public List<PropertySource> getPropertySources() {
- return immutablePropertySources;
- }
-
- @Override
- public PropertySource getPropertySource(String name) {
- for(PropertySource ps:getPropertySources()){
- if(name.equals(ps.getName())){
- return ps;
- }
- }
- return null;
- }
-
- @Override
- public <T> void addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) {
- propertyConverterManager.register(typeToConvert, propertyConverter);
- LOG.info("Added PropertyConverter: " + propertyConverter.getClass().getName());
- }
-
- @Override
- public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
- return propertyConverterManager.getPropertyConverters();
- }
-
- @Override
- public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) {
- return propertyConverterManager.getPropertyConverters(targetType);
- }
-
- @Override
- public List<PropertyFilter> getPropertyFilters() {
- return immutablePropertyFilters;
- }
-
- @Override
- public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy(){
- return propertyValueCombinationPolicy;
- }
-
- @Override
- public ConfigurationContextBuilder toBuilder() {
- return new DefaultConfigurationContextBuilder(this);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/545e1779/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
deleted file mode 100644
index 8268f64..0000000
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilder.java
+++ /dev/null
@@ -1,461 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.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.PropertySourceProvider;
-import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
-import org.apache.tamaya.spi.ServiceContextManager;
-import org.apache.tamaya.core.internal.converters.*;
-import org.apache.tamaya.spisupport.PropertySourceComparator;
-import org.apache.tamaya.spisupport.propertysource.CLIPropertySource;
-import org.apache.tamaya.spisupport.propertysource.EnvironmentPropertySource;
-import org.apache.tamaya.spisupport.propertysource.JavaConfigurationPropertySource;
-import org.apache.tamaya.spisupport.propertysource.SystemPropertySource;
-
-import java.io.File;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.net.URI;
-import java.net.URL;
-import java.nio.file.Path;
-import java.util.*;
-import java.util.logging.Logger;
-
-/**
- * Default implementation of {@link ConfigurationContextBuilder}.
- */
-public class DefaultConfigurationContextBuilder implements ConfigurationContextBuilder {
-
- private static final Logger LOG = Logger.getLogger(DefaultConfigurationContextBuilder.class.getName());
-
- List<PropertyFilter> propertyFilters = new ArrayList<>();
- List<PropertySource> propertySources = new ArrayList<>();
- PropertyValueCombinationPolicy combinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_POLICY;
- Map<TypeLiteral<?>, Collection<PropertyConverter<?>>> propertyConverters = new HashMap<>();
-
- /**
- * Flag if the config has already been built.
- * Configuration can be built only once
- */
- private boolean built;
-
-
-
- /**
- * Creates a new builder instance.
- */
- public DefaultConfigurationContextBuilder() {
- }
-
- /**
- * Creates a new builder instance initializing it with the given context.
- * @param context the context to be used, not null.
- */
- public DefaultConfigurationContextBuilder(ConfigurationContext context) {
- this.propertyConverters.putAll(context.getPropertyConverters());
- this.propertyFilters.addAll(context.getPropertyFilters());
- for(PropertySource ps:context.getPropertySources()) {
- addPropertySources(ps);
- }
- this.combinationPolicy = context.getPropertyValueCombinationPolicy();
- }
-
- /**
- * Allows to set configuration context during unit tests.
- */
- ConfigurationContextBuilder setConfigurationContext(ConfigurationContext configurationContext) {
- checkBuilderState();
- //noinspection deprecation
- this.propertyFilters.clear();
- this.propertyFilters.addAll(configurationContext.getPropertyFilters());
- this.propertySources.clear();
- for(PropertySource ps:configurationContext.getPropertySources()) {
- addPropertySources(ps);
- }
- this.propertyConverters.clear();
- this.propertyConverters.putAll(configurationContext.getPropertyConverters());
- this.combinationPolicy = configurationContext.getPropertyValueCombinationPolicy();
- return this;
- }
-
-
- @Override
- public ConfigurationContextBuilder setContext(ConfigurationContext context) {
- checkBuilderState();
- this.propertyConverters.putAll(context.getPropertyConverters());
- for(PropertySource ps:context.getPropertySources()){
- this.propertySources.add(ps);
- }
- this.propertyFilters.addAll(context.getPropertyFilters());
- this.combinationPolicy = context.getPropertyValueCombinationPolicy();
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder addPropertySources(PropertySource... sources){
- return addPropertySources(Arrays.asList(sources));
- }
-
- @Override
- public ConfigurationContextBuilder addPropertySources(Collection<PropertySource> sources){
- checkBuilderState();
- for(PropertySource source:sources) {
- if (!this.propertySources.contains(source)) {
- this.propertySources.add(source);
- }
- }
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder addDefaultPropertySources() {
- checkBuilderState();
- List<PropertySource> propertySources = new ArrayList<>();
- addCorePropertyResources(propertySources);
- for(PropertySource ps: ServiceContextManager.getServiceContext().getServices(PropertySource.class)) {
- if(!propertySources.contains(ps)){
- propertySources.add(ps);
- }
- }
- for(PropertySourceProvider provider:
- ServiceContextManager.getServiceContext().getServices(PropertySourceProvider.class)){
- propertySources.addAll(provider.getPropertySources());
- }
- Collections.sort(propertySources, PropertySourceComparator.getInstance());
- return addPropertySources(propertySources);
- }
-
- private void addCorePropertyResources(List<PropertySource> propertySources) {
- for(PropertySource ps: new PropertySource[]{
- new EnvironmentPropertySource(),
- new JavaConfigurationPropertySource(),
- new CLIPropertySource(),
- new SystemPropertySource()
- }){
- if(!propertySources.contains(ps)){
- propertySources.add(ps);
- }
- }
- }
-
- @Override
- public ConfigurationContextBuilder addDefaultPropertyFilters() {
- checkBuilderState();
- for(PropertyFilter pf:ServiceContextManager.getServiceContext().getServices(PropertyFilter.class)){
- addPropertyFilters(pf);
- }
- return this;
- }
-
- public DefaultConfigurationContextBuilder addDefaultPropertyConverters() {
- checkBuilderState();
- addCorePropertyConverters();
- for(Map.Entry<TypeLiteral, Collection<PropertyConverter>> en:getDefaultPropertyConverters().entrySet()){
- for(PropertyConverter pc: en.getValue()) {
- addPropertyConverters(en.getKey(), pc);
- }
- }
- return this;
- }
-
- @SuppressWarnings("unchecked")
- protected void addCorePropertyConverters() {
- addPropertyConverters(TypeLiteral.<BigDecimal>of(BigDecimal.class), new BigDecimalConverter());
- addPropertyConverters(TypeLiteral.<BigInteger>of(BigInteger.class), new BigIntegerConverter());
- addPropertyConverters(TypeLiteral.<Boolean>of(Boolean.class), new BooleanConverter());
- addPropertyConverters(TypeLiteral.<Byte>of(Byte.class), new ByteConverter());
- addPropertyConverters(TypeLiteral.<Character>of(Character.class), new CharConverter());
- addPropertyConverters(TypeLiteral.<Class<?>>of(Class.class), new ClassConverter());
- addPropertyConverters(TypeLiteral.<Currency>of(Currency.class), new CurrencyConverter());
- addPropertyConverters(TypeLiteral.<Double>of(Double.class), new DoubleConverter());
- addPropertyConverters(TypeLiteral.<File>of(File.class), new FileConverter());
- addPropertyConverters(TypeLiteral.<Float>of(Float.class), new FloatConverter());
- addPropertyConverters(TypeLiteral.<Integer>of(Integer.class), new IntegerConverter());
- addPropertyConverters(TypeLiteral.<Long>of(Long.class), new LongConverter());
- addPropertyConverters(TypeLiteral.<Number>of(Number.class), new NumberConverter());
- addPropertyConverters(TypeLiteral.<Path>of(Path.class), new PathConverter());
- addPropertyConverters(TypeLiteral.<Short>of(Short.class), new ShortConverter());
- addPropertyConverters(TypeLiteral.<URI>of(URI.class), new URIConverter());
- addPropertyConverters(TypeLiteral.<URL>of(URL.class), new URLConverter());
- }
-
- @Override
- public ConfigurationContextBuilder removePropertySources(PropertySource... propertySources) {
- return removePropertySources(Arrays.asList(propertySources));
- }
-
- @Override
- public ConfigurationContextBuilder removePropertySources(Collection<PropertySource> propertySources) {
- checkBuilderState();
- this.propertySources.removeAll(propertySources);
- return this;
- }
-
- private PropertySource getPropertySource(String name) {
- for(PropertySource ps:propertySources){
- if(ps.getName().equals(name)){
- return ps;
- }
- }
- throw new IllegalArgumentException("No such PropertySource: "+name);
- }
-
- @Override
- public List<PropertySource> getPropertySources() {
- return this.propertySources;
- }
-
- @Override
- public ConfigurationContextBuilder increasePriority(PropertySource propertySource) {
- checkBuilderState();
- int index = propertySources.indexOf(propertySource);
- if(index<0){
- throw new IllegalArgumentException("No such PropertySource: " + propertySource);
- }
- if(index<(propertySources.size()-1)){
- propertySources.remove(propertySource);
- propertySources.add(index+1, propertySource);
- }
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder decreasePriority(PropertySource propertySource) {
- checkBuilderState();
- int index = propertySources.indexOf(propertySource);
- if(index<0){
- throw new IllegalArgumentException("No such PropertySource: " + propertySource);
- }
- if(index>0){
- propertySources.remove(propertySource);
- propertySources.add(index-1, propertySource);
- }
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder highestPriority(PropertySource propertySource) {
- checkBuilderState();
- int index = propertySources.indexOf(propertySource);
- if(index<0){
- throw new IllegalArgumentException("No such PropertySource: " + propertySource);
- }
- if(index<(propertySources.size()-1)){
- propertySources.remove(propertySource);
- propertySources.add(propertySource);
- }
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder lowestPriority(PropertySource propertySource) {
- checkBuilderState();
- int index = propertySources.indexOf(propertySource);
- if(index<0){
- throw new IllegalArgumentException("No such PropertySource: " + propertySource);
- }
- if(index>0){
- propertySources.remove(propertySource);
- propertySources.add(0, propertySource);
- }
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder addPropertyFilters(PropertyFilter... filters){
- return addPropertyFilters(Arrays.asList(filters));
- }
-
- @Override
- public ConfigurationContextBuilder addPropertyFilters(Collection<PropertyFilter> filters){
- checkBuilderState();
- for(PropertyFilter f:filters) {
- if (!this.propertyFilters.contains(f)) {
- this.propertyFilters.add(f);
- }
- }
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder removePropertyFilters(PropertyFilter... filters) {
- return removePropertyFilters(Arrays.asList(filters));
- }
-
- @Override
- public ConfigurationContextBuilder removePropertyFilters(Collection<PropertyFilter> filters) {
- checkBuilderState();
- this.propertyFilters.removeAll(filters);
- return this;
- }
-
-
- @Override
- public <T> ConfigurationContextBuilder removePropertyConverters(TypeLiteral<T> typeToConvert,
- @SuppressWarnings("unchecked") PropertyConverter<T>... converters) {
- return removePropertyConverters(typeToConvert, Arrays.asList(converters));
- }
-
- @Override
- public <T> ConfigurationContextBuilder removePropertyConverters(TypeLiteral<T> typeToConvert,
- Collection<PropertyConverter<T>> converters) {
- Collection<PropertyConverter<?>> subConverters = this.propertyConverters.get(typeToConvert);
- if(subConverters!=null) {
- subConverters.removeAll(converters);
- }
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder removePropertyConverters(TypeLiteral<?> typeToConvert) {
- this.propertyConverters.remove(typeToConvert);
- return this;
- }
-
-
- @Override
- public ConfigurationContextBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy combinationPolicy){
- checkBuilderState();
- this.combinationPolicy = Objects.requireNonNull(combinationPolicy);
- return this;
- }
-
-
- @Override
- public <T> ConfigurationContextBuilder addPropertyConverters(TypeLiteral<T> type, PropertyConverter<T>... propertyConverters){
- checkBuilderState();
- Objects.requireNonNull(type);
- Objects.requireNonNull(propertyConverters);
- Collection<PropertyConverter<?>> converters = this.propertyConverters.get(type);
- if(converters==null){
- converters = new ArrayList<>();
- this.propertyConverters.put(type, converters);
- }
- for(PropertyConverter<T> propertyConverter:propertyConverters) {
- if (!converters.contains(propertyConverter)) {
- converters.add(propertyConverter);
- } else {
- LOG.warning("Converter ignored, already registered: " + propertyConverter);
- }
- }
- return this;
- }
-
- @Override
- public <T> ConfigurationContextBuilder addPropertyConverters(TypeLiteral<T> type, Collection<PropertyConverter<T>> propertyConverters){
- checkBuilderState();
- Objects.requireNonNull(type);
- Objects.requireNonNull(propertyConverters);
- Collection<PropertyConverter<?>> converters = this.propertyConverters.get(type);
- if(converters==null){
- converters = new ArrayList<>();
- this.propertyConverters.put(type, converters);
- }
- for(PropertyConverter<T> propertyConverter:propertyConverters) {
- if (!converters.contains(propertyConverter)) {
- converters.add(propertyConverter);
- } else {
- LOG.warning("Converter ignored, already registered: " + propertyConverter);
- }
- }
- return this;
- }
-
- protected ConfigurationContextBuilder loadDefaults() {
- checkBuilderState();
- this.combinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR;
- addDefaultPropertySources();
- addDefaultPropertyFilters();
- addDefaultPropertyConverters();
- return this;
- }
-
-
- private Map<TypeLiteral, Collection<PropertyConverter>> getDefaultPropertyConverters() {
- Map<TypeLiteral, Collection<PropertyConverter>> result = new HashMap<>();
- for (PropertyConverter conv : ServiceContextManager.getServiceContext().getServices(
- PropertyConverter.class)) {
- for(Type type:conv.getClass().getGenericInterfaces()){
- if(type instanceof ParameterizedType){
- ParameterizedType pt = (ParameterizedType)type;
- if(PropertyConverter.class.equals(((ParameterizedType) type).getRawType())){
- TypeLiteral target = TypeLiteral.of(pt.getActualTypeArguments()[0]);
- Collection<PropertyConverter> convList = result.get(target);
- if (convList == null) {
- convList = new ArrayList<>();
- result.put(target, convList);
- }
- convList.add(conv);
- }
- }
- }
- }
- return result;
- }
-
-
- /**
- * Builds a new configuration based on the configuration of this builder instance.
- *
- * @return a new {@link org.apache.tamaya.Configuration configuration instance},
- * never {@code null}.
- */
- @Override
- public ConfigurationContext build() {
- checkBuilderState();
- built = true;
- return new DefaultConfigurationContext(this);
- }
-
- @Override
- public ConfigurationContextBuilder sortPropertyFilter(Comparator<PropertyFilter> comparator) {
- Collections.sort(propertyFilters, comparator);
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder sortPropertySources(Comparator<PropertySource> comparator) {
- Collections.sort(propertySources, comparator);
- return this;
- }
-
- private void checkBuilderState() {
- if (built) {
- throw new IllegalStateException("Configuration has already been build.");
- }
- }
-
- @Override
- public List<PropertyFilter> getPropertyFilters() {
- return propertyFilters;
- }
-
- @Override
- public Map<TypeLiteral<?>, Collection<PropertyConverter<?>>> getPropertyConverter() {
- return Collections.unmodifiableMap(this.propertyConverters);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/545e1779/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
index dd73889..f37d4c3 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
@@ -35,7 +35,7 @@ import java.util.Objects;
@Component(service = ConfigurationProviderSpi.class)
public class DefaultConfigurationProvider implements ConfigurationProviderSpi {
- ConfigurationContext context = new DefaultConfigurationContextBuilder()
+ ConfigurationContext context = new CoreConfigurationContextBuilder()
.addDefaultPropertyConverters()
.addDefaultPropertyFilters()
.addDefaultPropertySources()
@@ -62,7 +62,7 @@ public class DefaultConfigurationProvider implements ConfigurationProviderSpi {
@Override
public ConfigurationContextBuilder getConfigurationContextBuilder() {
- return new DefaultConfigurationContextBuilder();
+ return new CoreConfigurationContextBuilder();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/545e1779/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContextBuilder
----------------------------------------------------------------------
diff --git a/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContextBuilder b/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContextBuilder
index 4efa42e..700b2b5 100644
--- a/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContextBuilder
+++ b/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContextBuilder
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.core.internal.DefaultConfigurationContextBuilder
\ No newline at end of file
+org.apache.tamaya.core.internal.CoreConfigurationContextBuilder
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/545e1779/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java
index 2c8f627..5fb65ff 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java
@@ -21,7 +21,7 @@ package org.apache.tamaya.core;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.spi.*;
-import org.apache.tamaya.core.internal.DefaultConfigurationContextBuilder;
+import org.apache.tamaya.core.internal.CoreConfigurationContextBuilder;
import org.junit.Test;
import java.util.Arrays;
@@ -30,7 +30,7 @@ import java.util.Comparator;
import static org.junit.Assert.*;
/**
- * Tests for {@link DefaultConfigurationContextBuilder} by atsticks on 06.09.16.
+ * Tests for {@link CoreConfigurationContextBuilder} by atsticks on 06.09.16.
*/
public class ConfigurationContextBuilderTest {
@@ -47,7 +47,7 @@ public class ConfigurationContextBuilderTest {
@Test
public void addPropertySources_Array() throws Exception {
PropertySource testPS2 = new TestPropertySource("addPropertySources_Array", 1);
- ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder()
+ ConfigurationContextBuilder b = new CoreConfigurationContextBuilder()
.addPropertySources(testPropertySource, testPS2);
ConfigurationContext ctx = b.build();
assertEquals(2, ctx.getPropertySources().size());
@@ -68,7 +68,7 @@ public class ConfigurationContextBuilderTest {
@Test
public void addPropertySources_Collection() throws Exception {
PropertySource testPS2 = new TestPropertySource("addPropertySources_Collection", 1);
- ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder()
+ ConfigurationContextBuilder b = new CoreConfigurationContextBuilder()
.addPropertySources(Arrays.asList(new PropertySource[]{testPropertySource, testPS2}));
ConfigurationContext ctx = b.build();
assertEquals(2, ctx.getPropertySources().size());
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/545e1779/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationContextBuilderTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationContextBuilderTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationContextBuilderTest.java
new file mode 100644
index 0000000..8458366
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationContextBuilderTest.java
@@ -0,0 +1,200 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.*;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for {@link CoreConfigurationContextBuilder} by atsticks on 06.09.16.
+ */
+public class CoreConfigurationContextBuilderTest {
+
+ private TestPropertySource testPropertySource = new TestPropertySource(){};
+
+ @Test
+ public void setContext() throws Exception {
+ ConfigurationContext context = ConfigurationProvider.getConfiguration().getContext();
+ ConfigurationContextBuilder b = new CoreConfigurationContextBuilder()
+ .setContext(context);
+ assertEquals(context, b.build());
+ }
+
+ @Test
+ public void addPropertySources_Array() throws Exception {
+ PropertySource testPS2 = new TestPropertySource("addPropertySources_Array_2");
+ ConfigurationContextBuilder b = new CoreConfigurationContextBuilder()
+ .addPropertySources(testPropertySource, testPS2);
+ ConfigurationContext ctx = b.build();
+ assertEquals(2, ctx.getPropertySources().size());
+ assertTrue(ctx.getPropertySources().contains(testPropertySource));
+ assertTrue(ctx.getPropertySources().contains(testPS2));
+ }
+
+ @Test
+ public void removePropertySources_Array() throws Exception {
+ PropertySource testPS2 = new TestPropertySource("addPropertySources_Array_2");
+ ConfigurationContextBuilder b = new CoreConfigurationContextBuilder()
+ .addPropertySources(testPropertySource, testPS2);
+ ConfigurationContext ctx = b.build();
+ assertEquals(2, ctx.getPropertySources().size());
+ assertTrue(ctx.getPropertySources().contains(testPropertySource));
+ assertTrue(ctx.getPropertySources().contains(testPS2));
+ b = new CoreConfigurationContextBuilder()
+ .addPropertySources(testPropertySource, testPS2);
+ b.removePropertySources(testPropertySource);
+ ctx = b.build();
+ assertEquals(1, ctx.getPropertySources().size());
+ assertFalse(ctx.getPropertySources().contains(testPropertySource));
+ assertTrue(ctx.getPropertySources().contains(testPS2));
+ }
+
+ @Test
+ public void addPropertyFilters_Array() throws Exception {
+ PropertyFilter filter1 = (value, context) -> value;
+ PropertyFilter filter2 = (value, context) -> value;
+ CoreConfigurationContextBuilder b = new CoreConfigurationContextBuilder();
+ b.addPropertyFilters(filter1, filter2);
+ ConfigurationContext ctx = b.build();
+ assertTrue(ctx.getPropertyFilters().contains(filter1));
+ assertTrue(ctx.getPropertyFilters().contains(filter2));
+ assertEquals(2, ctx.getPropertyFilters().size());
+ b = new CoreConfigurationContextBuilder();
+ b.addPropertyFilters(filter1, filter2);
+ b.addPropertyFilters(filter1, filter2);
+ assertEquals(2, ctx.getPropertyFilters().size());
+ }
+
+ @Test
+ public void removePropertyFilters_Array() throws Exception {
+ PropertyFilter filter1 = (value, context) -> value;
+ PropertyFilter filter2 = (value, context) -> value;
+ ConfigurationContextBuilder b = new CoreConfigurationContextBuilder()
+ .addPropertyFilters(filter1, filter2);
+ ConfigurationContext ctx = b.build();
+ assertTrue(ctx.getPropertyFilters().contains(filter1));
+ assertTrue(ctx.getPropertyFilters().contains(filter2));
+ assertEquals(2, ctx.getPropertyFilters().size());
+ b = new CoreConfigurationContextBuilder()
+ .addPropertyFilters(filter1, filter2);
+ b.removePropertyFilters(filter1);
+ ctx = b.build();
+ assertEquals(1, ctx.getPropertyFilters().size());
+ assertFalse(ctx.getPropertyFilters().contains(filter1));
+ assertTrue(ctx.getPropertyFilters().contains(filter2));
+ }
+
+ @Test
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public void addPropertyConverter() throws Exception {
+ PropertyConverter converter = (value, context) -> value.toLowerCase();
+ ConfigurationContextBuilder b = new CoreConfigurationContextBuilder()
+ .addPropertyConverters(TypeLiteral.of(String.class), converter);
+ ConfigurationContext ctx = b.build();
+ assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
+ assertEquals(1, ctx.getPropertyConverters().size());
+ b = new CoreConfigurationContextBuilder()
+ .addPropertyConverters(TypeLiteral.of(String.class), converter);
+ b.addPropertyConverters(TypeLiteral.of(String.class), converter);
+ assertEquals(1, ctx.getPropertyConverters().size());
+ }
+
+ @Test
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public void removePropertyConverters_Array() throws Exception {
+ PropertyConverter converter = (value, context) -> value.toLowerCase();
+ ConfigurationContextBuilder b = new CoreConfigurationContextBuilder()
+ .addPropertyConverters(TypeLiteral.of(String.class), converter);
+ ConfigurationContext ctx = b.build();
+ assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
+ assertEquals(1, ctx.getPropertyConverters(TypeLiteral.of(String.class)).size());
+ b = new CoreConfigurationContextBuilder()
+ .addPropertyConverters(TypeLiteral.of(String.class), converter);
+ b.removePropertyConverters(TypeLiteral.of(String.class), converter);
+ ctx = b.build();
+ assertFalse(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
+ assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).isEmpty());
+ }
+
+ @Test
+ public void setPropertyValueCombinationPolicy() throws Exception {
+ PropertyValueCombinationPolicy combPol = (currentValue, key, propertySource) -> currentValue;
+ ConfigurationContextBuilder b = new CoreConfigurationContextBuilder()
+ .setPropertyValueCombinationPolicy(combPol);
+ ConfigurationContext ctx = b.build();
+ assertEquals(ctx.getPropertyValueCombinationPolicy(), combPol);
+ }
+
+ @Test
+ public void build() throws Exception {
+ assertNotNull(new CoreConfigurationContextBuilder().build());
+ }
+
+ @Test
+ public void bla() throws Exception {
+ ConfigurationContextBuilder builder = ConfigurationProvider.getConfigurationContextBuilder();
+ builder.addDefaultPropertyConverters();
+ }
+
+ private static class TestPropertySource implements PropertySource{
+
+ private String id;
+
+ public TestPropertySource(){
+ this(null);
+ }
+
+ public TestPropertySource(String id){
+ this.id = id;
+ }
+
+ @Override
+ public int getOrdinal() {
+ return 200;
+ }
+
+ @Override
+ public String getName() {
+ return id!=null?id:"TestPropertySource";
+ }
+
+ @Override
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key, key + "Value", getName());
+ }
+
+ @Override
+ public Map<String, PropertyValue> getProperties() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public boolean isScannable() {
+ return false;
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/545e1779/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationContextTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationContextTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationContextTest.java
new file mode 100644
index 0000000..1c10124
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationContextTest.java
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.core.testdata.TestPropertyDefaultSource;
+import org.apache.tamaya.spi.*;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Simple tests for {@link CoreConfigurationContext} by atsticks on 16.08.16.
+ */
+public class CoreConfigurationContextTest {
+
+ @Test
+ public void addPropertySources() throws Exception {
+ ConfigurationContext ctx = new CoreConfigurationContextBuilder().build();
+ TestPropertyDefaultSource def = new TestPropertyDefaultSource();
+ assertFalse(ctx.getPropertySources().contains(def));
+ ctx.addPropertySources(def);
+ assertTrue(ctx.getPropertySources().contains(def));
+ }
+
+ @Test
+ public void testToString() throws Exception {
+ String toString = ConfigurationProvider.getConfiguration().getContext().toString();
+ }
+
+ @Test
+ public void getPropertySources() throws Exception {
+ ConfigurationContext ctx = new CoreConfigurationContextBuilder().build();
+ assertNotNull(ctx.getPropertySources());
+ assertEquals(ctx.getPropertySources().size(), 0);
+ ctx = new CoreConfigurationContextBuilder().addDefaultPropertySources().build();
+ assertNotNull(ctx.getPropertySources());
+ assertEquals(7, ctx.getPropertySources().size());
+ }
+
+ @Test
+ public void getPropertySource() throws Exception {
+ TestPropertyDefaultSource ps = new TestPropertyDefaultSource();
+ ConfigurationContext ctx = new CoreConfigurationContextBuilder()
+ .addPropertySources(ps).build();
+ assertNotNull(ctx.getPropertySources());
+ assertEquals(ctx.getPropertySources().size(), 1);
+ assertNotNull(((CoreConfigurationContext)ctx).getPropertySource(ps.getName()));
+ assertEquals(ps.getName(), ((CoreConfigurationContext)ctx).getPropertySource(ps.getName()).getName());
+ assertNull(((CoreConfigurationContext)ctx).getPropertySource("huhu"));
+
+ }
+
+ @Test
+ public void testHashCode() throws Exception {
+ TestPropertyDefaultSource ps = new TestPropertyDefaultSource();
+ ConfigurationContext ctx1 = new CoreConfigurationContextBuilder()
+ .addPropertySources(ps).build();
+ ConfigurationContext ctx2 = new CoreConfigurationContextBuilder()
+ .addPropertySources(ps).build();
+ assertEquals(ctx1.hashCode(), ctx2.hashCode());
+ ctx2 = new CoreConfigurationContextBuilder()
+ .build();
+ assertNotEquals(ctx1.hashCode(), ctx2.hashCode());
+
+ }
+
+ @Test
+ public void addPropertyConverter() throws Exception {
+ ConfigurationContext ctx = new CoreConfigurationContextBuilder().build();
+ PropertyConverter testConverter = new PropertyConverter() {
+ @Override
+ public Object convert(String value, ConversionContext context) {
+ return "";
+ }
+ };
+ assertFalse(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter));
+ ctx.addPropertyConverter(TypeLiteral.of(String.class), testConverter);
+ assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter));
+ }
+
+ @Test
+ public void getPropertyConverters() throws Exception {
+ ConfigurationContext ctx = new CoreConfigurationContextBuilder().build();
+ PropertyConverter testConverter = new PropertyConverter() {
+ @Override
+ public Object convert(String value, ConversionContext context) {
+ return "";
+ }
+ };
+ ctx.addPropertyConverter(TypeLiteral.of(String.class), testConverter);
+ assertNotNull(ctx.getPropertyConverters());
+ assertTrue(ctx.getPropertyConverters().containsKey(TypeLiteral.of(String.class)));
+ assertTrue(ctx.getPropertyConverters().get(TypeLiteral.of(String.class)).contains(testConverter));
+ testConverter = new PropertyConverter() {
+ @Override
+ public Object convert(String value, ConversionContext context) {
+ return Integer.valueOf(5);
+ }
+ };
+ ctx.addPropertyConverter(TypeLiteral.of(Integer.class), testConverter);
+ assertTrue(ctx.getPropertyConverters().containsKey(TypeLiteral.of(Integer.class)));
+ assertTrue(ctx.getPropertyConverters().get(TypeLiteral.of(Integer.class)).contains(testConverter));
+ }
+
+ @Test
+ public void getPropertyConverters1() throws Exception {
+ ConfigurationContext ctx = new CoreConfigurationContextBuilder().build();
+ PropertyConverter testConverter = new PropertyConverter() {
+ @Override
+ public Object convert(String value, ConversionContext context) {
+ return "";
+ }
+ };
+ assertNotNull(ctx.getPropertyConverters(TypeLiteral.of(String.class)));
+ assertEquals(ctx.getPropertyConverters(TypeLiteral.of(String.class)).size(),0);
+ ctx.addPropertyConverter(TypeLiteral.of(String.class), testConverter);
+ assertNotNull(ctx.getPropertyConverters(TypeLiteral.of(String.class)));
+ assertEquals(ctx.getPropertyConverters(TypeLiteral.of(String.class)).size(),1);
+ assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter));
+
+ }
+
+ @Test
+ public void getPropertyFilters() throws Exception {
+ ConfigurationContext ctx = new CoreConfigurationContextBuilder().build();
+ PropertyFilter testFilter = new PropertyFilter() {
+
+ @Override
+ public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
+ return value;
+ }
+ };
+ assertNotNull(ctx.getPropertyFilters());
+ assertFalse(ctx.getPropertyFilters().contains(testFilter));
+ ctx = ctx.toBuilder().addPropertyFilters(testFilter).build();
+ assertTrue(ctx.getPropertyFilters().contains(testFilter));
+ }
+
+ @Test
+ public void getPropertyValueCombinationPolicy() throws Exception {
+ ConfigurationContext ctx = new CoreConfigurationContextBuilder().build();
+ assertNotNull(ctx.getPropertyValueCombinationPolicy());
+ assertEquals(ctx.getPropertyValueCombinationPolicy(),
+ PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_POLICY);
+ }
+
+ @Test
+ public void toBuilder() throws Exception {
+ assertNotNull(new CoreConfigurationContextBuilder().build().toBuilder());
+ }
+
+ @Test
+ public void testRoundTrip() throws Exception {
+ ConfigurationContext ctx = new CoreConfigurationContextBuilder().build();
+ assertEquals(ctx.toBuilder().build(), ctx);
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/545e1779/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilderTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilderTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilderTest.java
deleted file mode 100644
index dc301ff..0000000
--- a/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationContextBuilderTest.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.*;
-import org.junit.Test;
-
-import java.util.Collections;
-import java.util.Map;
-
-import static org.junit.Assert.*;
-
-/**
- * Tests for {@link DefaultConfigurationContextBuilder} by atsticks on 06.09.16.
- */
-public class DefaultConfigurationContextBuilderTest {
-
- private TestPropertySource testPropertySource = new TestPropertySource(){};
-
- @Test
- public void setContext() throws Exception {
- ConfigurationContext context = ConfigurationProvider.getConfiguration().getContext();
- ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder()
- .setContext(context);
- assertEquals(context, b.build());
- }
-
- @Test
- public void addPropertySources_Array() throws Exception {
- PropertySource testPS2 = new TestPropertySource("addPropertySources_Array_2");
- ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder()
- .addPropertySources(testPropertySource, testPS2);
- ConfigurationContext ctx = b.build();
- assertEquals(2, ctx.getPropertySources().size());
- assertTrue(ctx.getPropertySources().contains(testPropertySource));
- assertTrue(ctx.getPropertySources().contains(testPS2));
- }
-
- @Test
- public void removePropertySources_Array() throws Exception {
- PropertySource testPS2 = new TestPropertySource("addPropertySources_Array_2");
- ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder()
- .addPropertySources(testPropertySource, testPS2);
- ConfigurationContext ctx = b.build();
- assertEquals(2, ctx.getPropertySources().size());
- assertTrue(ctx.getPropertySources().contains(testPropertySource));
- assertTrue(ctx.getPropertySources().contains(testPS2));
- b = new DefaultConfigurationContextBuilder()
- .addPropertySources(testPropertySource, testPS2);
- b.removePropertySources(testPropertySource);
- ctx = b.build();
- assertEquals(1, ctx.getPropertySources().size());
- assertFalse(ctx.getPropertySources().contains(testPropertySource));
- assertTrue(ctx.getPropertySources().contains(testPS2));
- }
-
- @Test
- public void addPropertyFilters_Array() throws Exception {
- PropertyFilter filter1 = (value, context) -> value;
- PropertyFilter filter2 = (value, context) -> value;
- DefaultConfigurationContextBuilder b = new DefaultConfigurationContextBuilder();
- b.addPropertyFilters(filter1, filter2);
- ConfigurationContext ctx = b.build();
- assertTrue(ctx.getPropertyFilters().contains(filter1));
- assertTrue(ctx.getPropertyFilters().contains(filter2));
- assertEquals(2, ctx.getPropertyFilters().size());
- b = new DefaultConfigurationContextBuilder();
- b.addPropertyFilters(filter1, filter2);
- b.addPropertyFilters(filter1, filter2);
- assertEquals(2, ctx.getPropertyFilters().size());
- }
-
- @Test
- public void removePropertyFilters_Array() throws Exception {
- PropertyFilter filter1 = (value, context) -> value;
- PropertyFilter filter2 = (value, context) -> value;
- ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder()
- .addPropertyFilters(filter1, filter2);
- ConfigurationContext ctx = b.build();
- assertTrue(ctx.getPropertyFilters().contains(filter1));
- assertTrue(ctx.getPropertyFilters().contains(filter2));
- assertEquals(2, ctx.getPropertyFilters().size());
- b = new DefaultConfigurationContextBuilder()
- .addPropertyFilters(filter1, filter2);
- b.removePropertyFilters(filter1);
- ctx = b.build();
- assertEquals(1, ctx.getPropertyFilters().size());
- assertFalse(ctx.getPropertyFilters().contains(filter1));
- assertTrue(ctx.getPropertyFilters().contains(filter2));
- }
-
- @Test
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public void addPropertyConverter() throws Exception {
- PropertyConverter converter = (value, context) -> value.toLowerCase();
- ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder()
- .addPropertyConverters(TypeLiteral.of(String.class), converter);
- ConfigurationContext ctx = b.build();
- assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
- assertEquals(1, ctx.getPropertyConverters().size());
- b = new DefaultConfigurationContextBuilder()
- .addPropertyConverters(TypeLiteral.of(String.class), converter);
- b.addPropertyConverters(TypeLiteral.of(String.class), converter);
- assertEquals(1, ctx.getPropertyConverters().size());
- }
-
- @Test
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public void removePropertyConverters_Array() throws Exception {
- PropertyConverter converter = (value, context) -> value.toLowerCase();
- ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder()
- .addPropertyConverters(TypeLiteral.of(String.class), converter);
- ConfigurationContext ctx = b.build();
- assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
- assertEquals(1, ctx.getPropertyConverters(TypeLiteral.of(String.class)).size());
- b = new DefaultConfigurationContextBuilder()
- .addPropertyConverters(TypeLiteral.of(String.class), converter);
- b.removePropertyConverters(TypeLiteral.of(String.class), converter);
- ctx = b.build();
- assertFalse(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
- assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).isEmpty());
- }
-
- @Test
- public void setPropertyValueCombinationPolicy() throws Exception {
- PropertyValueCombinationPolicy combPol = (currentValue, key, propertySource) -> currentValue;
- ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder()
- .setPropertyValueCombinationPolicy(combPol);
- ConfigurationContext ctx = b.build();
- assertEquals(ctx.getPropertyValueCombinationPolicy(), combPol);
- }
-
- @Test
- public void build() throws Exception {
- assertNotNull(new DefaultConfigurationContextBuilder().build());
- }
-
- @Test
- public void bla() throws Exception {
- ConfigurationContextBuilder builder = ConfigurationProvider.getConfigurationContextBuilder();
- builder.addDefaultPropertyConverters();
- }
-
- private static class TestPropertySource implements PropertySource{
-
- private String id;
-
- public TestPropertySource(){
- this(null);
- }
-
- public TestPropertySource(String id){
- this.id = id;
- }
-
- @Override
- public int getOrdinal() {
- return 200;
- }
-
- @Override
- public String getName() {
- return id!=null?id:"TestPropertySource";
- }
-
- @Override
- public PropertyValue get(String key) {
- return PropertyValue.of(key, key + "Value", getName());
- }
-
- @Override
- public Map<String, PropertyValue> getProperties() {
- return Collections.emptyMap();
- }
-
- @Override
- public boolean isScannable() {
- return false;
- }
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/545e1779/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationContextTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationContextTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationContextTest.java
deleted file mode 100644
index 38412f3..0000000
--- a/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationContextTest.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.core.testdata.TestPropertyDefaultSource;
-import org.apache.tamaya.spi.*;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Simple tests for {@link DefaultConfigurationContext} by atsticks on 16.08.16.
- */
-public class DefaultConfigurationContextTest {
-
- @Test
- public void addPropertySources() throws Exception {
- ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build();
- TestPropertyDefaultSource def = new TestPropertyDefaultSource();
- assertFalse(ctx.getPropertySources().contains(def));
- ctx.addPropertySources(def);
- assertTrue(ctx.getPropertySources().contains(def));
- }
-
- @Test
- public void testToString() throws Exception {
- String toString = ConfigurationProvider.getConfiguration().getContext().toString();
- }
-
- @Test
- public void getPropertySources() throws Exception {
- ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build();
- assertNotNull(ctx.getPropertySources());
- assertEquals(ctx.getPropertySources().size(), 0);
- ctx = new DefaultConfigurationContextBuilder().addDefaultPropertySources().build();
- assertNotNull(ctx.getPropertySources());
- assertEquals(7, ctx.getPropertySources().size());
- }
-
- @Test
- public void getPropertySource() throws Exception {
- TestPropertyDefaultSource ps = new TestPropertyDefaultSource();
- ConfigurationContext ctx = new DefaultConfigurationContextBuilder()
- .addPropertySources(ps).build();
- assertNotNull(ctx.getPropertySources());
- assertEquals(ctx.getPropertySources().size(), 1);
- assertNotNull(((DefaultConfigurationContext)ctx).getPropertySource(ps.getName()));
- assertEquals(ps.getName(), ((DefaultConfigurationContext)ctx).getPropertySource(ps.getName()).getName());
- assertNull(((DefaultConfigurationContext)ctx).getPropertySource("huhu"));
-
- }
-
- @Test
- public void testHashCode() throws Exception {
- TestPropertyDefaultSource ps = new TestPropertyDefaultSource();
- ConfigurationContext ctx1 = new DefaultConfigurationContextBuilder()
- .addPropertySources(ps).build();
- ConfigurationContext ctx2 = new DefaultConfigurationContextBuilder()
- .addPropertySources(ps).build();
- assertEquals(ctx1.hashCode(), ctx2.hashCode());
- ctx2 = new DefaultConfigurationContextBuilder()
- .build();
- assertNotEquals(ctx1.hashCode(), ctx2.hashCode());
-
- }
-
- @Test
- public void addPropertyConverter() throws Exception {
- ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build();
- PropertyConverter testConverter = new PropertyConverter() {
- @Override
- public Object convert(String value, ConversionContext context) {
- return "";
- }
- };
- assertFalse(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter));
- ctx.addPropertyConverter(TypeLiteral.of(String.class), testConverter);
- assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter));
- }
-
- @Test
- public void getPropertyConverters() throws Exception {
- ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build();
- PropertyConverter testConverter = new PropertyConverter() {
- @Override
- public Object convert(String value, ConversionContext context) {
- return "";
- }
- };
- ctx.addPropertyConverter(TypeLiteral.of(String.class), testConverter);
- assertNotNull(ctx.getPropertyConverters());
- assertTrue(ctx.getPropertyConverters().containsKey(TypeLiteral.of(String.class)));
- assertTrue(ctx.getPropertyConverters().get(TypeLiteral.of(String.class)).contains(testConverter));
- testConverter = new PropertyConverter() {
- @Override
- public Object convert(String value, ConversionContext context) {
- return Integer.valueOf(5);
- }
- };
- ctx.addPropertyConverter(TypeLiteral.of(Integer.class), testConverter);
- assertTrue(ctx.getPropertyConverters().containsKey(TypeLiteral.of(Integer.class)));
- assertTrue(ctx.getPropertyConverters().get(TypeLiteral.of(Integer.class)).contains(testConverter));
- }
-
- @Test
- public void getPropertyConverters1() throws Exception {
- ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build();
- PropertyConverter testConverter = new PropertyConverter() {
- @Override
- public Object convert(String value, ConversionContext context) {
- return "";
- }
- };
- assertNotNull(ctx.getPropertyConverters(TypeLiteral.of(String.class)));
- assertEquals(ctx.getPropertyConverters(TypeLiteral.of(String.class)).size(),0);
- ctx.addPropertyConverter(TypeLiteral.of(String.class), testConverter);
- assertNotNull(ctx.getPropertyConverters(TypeLiteral.of(String.class)));
- assertEquals(ctx.getPropertyConverters(TypeLiteral.of(String.class)).size(),1);
- assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter));
-
- }
-
- @Test
- public void getPropertyFilters() throws Exception {
- ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build();
- PropertyFilter testFilter = new PropertyFilter() {
-
- @Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value;
- }
- };
- assertNotNull(ctx.getPropertyFilters());
- assertFalse(ctx.getPropertyFilters().contains(testFilter));
- ctx = ctx.toBuilder().addPropertyFilters(testFilter).build();
- assertTrue(ctx.getPropertyFilters().contains(testFilter));
- }
-
- @Test
- public void getPropertyValueCombinationPolicy() throws Exception {
- ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build();
- assertNotNull(ctx.getPropertyValueCombinationPolicy());
- assertEquals(ctx.getPropertyValueCombinationPolicy(),
- PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_POLICY);
- }
-
- @Test
- public void toBuilder() throws Exception {
- assertNotNull(new DefaultConfigurationContextBuilder().build().toBuilder());
- }
-
- @Test
- public void testRoundTrip() throws Exception {
- ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build();
- assertEquals(ctx.toBuilder().build(), ctx);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/545e1779/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationProviderTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationProviderTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationProviderTest.java
index ce5d046..9ba3c80 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationProviderTest.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationProviderTest.java
@@ -40,7 +40,7 @@ public class DefaultConfigurationProviderTest {
@Test
public void createConfiguration() throws Exception {
- ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build();
+ ConfigurationContext ctx = new CoreConfigurationContextBuilder().build();
assertNotNull(new DefaultConfigurationProvider().createConfiguration(ctx));
assertEquals(ctx,
new DefaultConfigurationProvider().createConfiguration(ctx).getContext());
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/545e1779/code/spi-support/pom.xml
----------------------------------------------------------------------
diff --git a/code/spi-support/pom.xml b/code/spi-support/pom.xml
index e602199..1221fd3 100644
--- a/code/spi-support/pom.xml
+++ b/code/spi-support/pom.xml
@@ -28,7 +28,7 @@ under the License.
</parent>
<artifactId>tamaya-spisupport</artifactId>
- <name>Apache Tamaya Common Support Classes</name>
+ <name>Apache Tamaya Core SPI Support</name>
<description>Apache Tamaya Support Classes useful when implementing the Tamaya SPI or code independent of the core RI
implementation.</description>
<packaging>jar</packaging>