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/26 22:51:36 UTC
[1/6] incubator-tamaya git commit: TAMAYA-321 Add
ConfigurationBuilder to core API.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master f255aa9b9 -> 27c0d76bb
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilderTest.java
----------------------------------------------------------------------
diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilderTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilderTest.java
new file mode 100644
index 0000000..c586969
--- /dev/null
+++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilderTest.java
@@ -0,0 +1,220 @@
+/*
+ * 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.spisupport;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConfigurationBuilder;
+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 DefaultConfigurationBuilder} by atsticks on 06.09.16.
+ */
+public class DefaultConfigurationBuilderTest {
+
+ private TestPropertySource testPropertySource = new TestPropertySource(){};
+
+ @Test
+ public void setContext() throws Exception {
+ ConfigurationContext context = ConfigurationProvider.getConfiguration().getContext();
+ ConfigurationBuilder b = new DefaultConfigurationBuilder()
+ .setContext(context);
+ assertEquals(context, b.build().getContext());
+ }
+
+ @Test
+ public void setConfiguration() throws Exception {
+ Configuration cfg = ConfigurationProvider.getConfiguration();
+ ConfigurationBuilder b = new DefaultConfigurationBuilder()
+ .setConfiguration(cfg);
+ assertEquals(cfg, b.build());
+ }
+
+ @Test
+ public void addPropertySources_Array() throws Exception {
+ PropertySource testPS2 = new TestPropertySource("addPropertySources_Array_2");
+ ConfigurationBuilder b = new DefaultConfigurationBuilder()
+ .addPropertySources(testPropertySource, testPS2);
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertEquals(2, ctx.getPropertySources().size());
+ assertTrue(ctx.getPropertySources().contains(testPropertySource));
+ assertTrue(ctx.getPropertySources().contains(testPS2));
+ }
+
+ @Test
+ public void removePropertySources_Array() throws Exception {
+ PropertySource testPS2 = new TestPropertySource("addPropertySources_Array_2");
+ ConfigurationBuilder b = new DefaultConfigurationBuilder()
+ .addPropertySources(testPropertySource, testPS2);
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertEquals(2, ctx.getPropertySources().size());
+ assertTrue(ctx.getPropertySources().contains(testPropertySource));
+ assertTrue(ctx.getPropertySources().contains(testPS2));
+ b = new DefaultConfigurationBuilder()
+ .addPropertySources(testPropertySource, testPS2);
+ b.removePropertySources(testPropertySource);
+ cfg = b.build();
+ ctx = cfg.getContext();
+ assertEquals(1, ctx.getPropertySources().size());
+ assertFalse(ctx.getPropertySources().contains(testPropertySource));
+ assertTrue(ctx.getPropertySources().contains(testPS2));
+ }
+
+ @Test
+ public void addPropertyFilters_Array() throws Exception {
+ PropertyFilter filter1 = (value, context) -> value;
+ PropertyFilter filter2 = (value, context) -> value;
+ DefaultConfigurationBuilder b = new DefaultConfigurationBuilder();
+ b.addPropertyFilters(filter1, filter2);
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertTrue(ctx.getPropertyFilters().contains(filter1));
+ assertTrue(ctx.getPropertyFilters().contains(filter2));
+ assertEquals(2, ctx.getPropertyFilters().size());
+ b = new DefaultConfigurationBuilder();
+ b.addPropertyFilters(filter1, filter2);
+ b.addPropertyFilters(filter1, filter2);
+ assertEquals(2, ctx.getPropertyFilters().size());
+ }
+
+ @Test
+ public void removePropertyFilters_Array() throws Exception {
+ PropertyFilter filter1 = (value, context) -> value;
+ PropertyFilter filter2 = (value, context) -> value;
+ ConfigurationBuilder b = new DefaultConfigurationBuilder()
+ .addPropertyFilters(filter1, filter2);
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertTrue(ctx.getPropertyFilters().contains(filter1));
+ assertTrue(ctx.getPropertyFilters().contains(filter2));
+ assertEquals(2, ctx.getPropertyFilters().size());
+ b = new DefaultConfigurationBuilder()
+ .addPropertyFilters(filter1, filter2);
+ b.removePropertyFilters(filter1);
+ cfg = b.build();
+ ctx = cfg.getContext();
+ assertEquals(1, ctx.getPropertyFilters().size());
+ assertFalse(ctx.getPropertyFilters().contains(filter1));
+ assertTrue(ctx.getPropertyFilters().contains(filter2));
+ }
+
+ @Test
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public void addPropertyConverter() throws Exception {
+ PropertyConverter converter = (value, context) -> value.toLowerCase();
+ ConfigurationBuilder b = new DefaultConfigurationBuilder()
+ .addPropertyConverters(TypeLiteral.of(String.class), converter);
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
+ assertEquals(1, ctx.getPropertyConverters().size());
+ b = new DefaultConfigurationBuilder()
+ .addPropertyConverters(TypeLiteral.of(String.class), converter);
+ b.addPropertyConverters(TypeLiteral.of(String.class), converter);
+ assertEquals(1, ctx.getPropertyConverters().size());
+ }
+
+ @Test
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public void removePropertyConverters_Array() throws Exception {
+ PropertyConverter converter = (value, context) -> value.toLowerCase();
+ ConfigurationBuilder b = new DefaultConfigurationBuilder()
+ .addPropertyConverters(TypeLiteral.of(String.class), converter);
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
+ assertEquals(1, ctx.getPropertyConverters(TypeLiteral.of(String.class)).size());
+ b = new DefaultConfigurationBuilder()
+ .addPropertyConverters(TypeLiteral.of(String.class), converter);
+ b.removePropertyConverters(TypeLiteral.of(String.class), converter);
+ cfg = b.build();
+ ctx = cfg.getContext();
+ assertFalse(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
+ assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).isEmpty());
+ }
+
+ @Test
+ public void setPropertyValueCombinationPolicy() throws Exception {
+ PropertyValueCombinationPolicy combPol = (currentValue, key, propertySource) -> currentValue;
+ ConfigurationBuilder b = new DefaultConfigurationBuilder()
+ .setPropertyValueCombinationPolicy(combPol);
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertEquals(ctx.getPropertyValueCombinationPolicy(), combPol);
+ }
+
+ @Test
+ public void build() throws Exception {
+ assertNotNull(new DefaultConfigurationBuilder().build());
+ }
+
+ @Test
+ public void bla() throws Exception {
+ ConfigurationBuilder builder = ConfigurationProvider.getConfigurationBuilder();
+ builder.addDefaultPropertyConverters();
+ }
+
+ private static class TestPropertySource implements PropertySource{
+
+ private String id;
+
+ public TestPropertySource(){
+ this(null);
+ }
+
+ public TestPropertySource(String id){
+ this.id = id;
+ }
+
+ @Override
+ public int getOrdinal() {
+ return 200;
+ }
+
+ @Override
+ public String getName() {
+ return id!=null?id:"TestPropertySource";
+ }
+
+ @Override
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key, key + "Value", getName());
+ }
+
+ @Override
+ public Map<String, PropertyValue> getProperties() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public boolean isScannable() {
+ return false;
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultServiceContextTest.java
----------------------------------------------------------------------
diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultServiceContextTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultServiceContextTest.java
new file mode 100644
index 0000000..9a25528
--- /dev/null
+++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultServiceContextTest.java
@@ -0,0 +1,138 @@
+/*
+ * 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.spisupport;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.ConfigurationProviderSpi;
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.annotation.Priority;
+import java.util.Collection;
+import java.util.List;
+
+public class DefaultServiceContextTest {
+
+ /**
+ * context to test
+ */
+ private final DefaultServiceContext context = new DefaultServiceContext();
+
+
+ @Test
+ public void testGetService() {
+ ConfigurationProviderSpi providerSpi = context.getService(ConfigurationProviderSpi.class);
+ Assert.assertNotNull(providerSpi);
+ Assert.assertTrue(providerSpi instanceof TestConfigurationProvider);
+ }
+
+ @Test(expected = ConfigException.class)
+ public void testGetService_multipleServicesWithoutPriority_shouldThrowConfigException() {
+ context.getService(InvalidPriorityInterface.class);
+ }
+
+ @Test
+ public void testGetService_multipleService_shouldReturnServiceWithHighestPriority() {
+ MultiImplsInterface service = context.getService(MultiImplsInterface.class);
+
+ Assert.assertNotNull(service);
+ Assert.assertTrue(service instanceof MultiImpl2);
+ }
+
+ @Test
+ public void testGetService_noImpl_shouldReturnEmptyOpional() {
+ NoImplInterface service = context.getService(NoImplInterface.class);
+ Assert.assertNull(service);
+ }
+
+
+ @Test
+ public void testGetServices_shouldReturnServices() {
+ {
+ Collection<InvalidPriorityInterface> services = context.getServices(InvalidPriorityInterface.class);
+ Assert.assertNotNull(services);
+ Assert.assertEquals(2, services.size());
+
+ for (InvalidPriorityInterface service : services) {
+ Assert.assertTrue(service instanceof InvalidPriorityImpl1 || service instanceof InvalidPriorityImpl2);
+ }
+ }
+
+ {
+ List<MultiImplsInterface> services = context.getServices(MultiImplsInterface.class);
+ Assert.assertNotNull(services);
+ Assert.assertEquals(3, services.size());
+
+ Assert.assertTrue(services.get(0) instanceof MultiImpl2);
+ Assert.assertTrue(services.get(1) instanceof MultiImpl1);
+ Assert.assertTrue(services.get(2) instanceof MultiImpl3);
+ }
+ }
+
+ @Test
+ public void testGetServices_redundantAccessToServices() {
+ for(int i=0;i<10;i++){
+ Collection<InvalidPriorityInterface> services = context.getServices(InvalidPriorityInterface.class);
+ Assert.assertNotNull(services);
+ Assert.assertEquals(2, services.size());
+ for (InvalidPriorityInterface service : services) {
+ Assert.assertTrue(service instanceof InvalidPriorityImpl1 || service instanceof InvalidPriorityImpl2);
+ }
+ }
+ }
+
+ @Test
+ public void testGetServices_noImpl_shouldReturnEmptyList() {
+ Collection<NoImplInterface> services = context.getServices(NoImplInterface.class);
+ Assert.assertNotNull(services);
+ Assert.assertTrue(services.isEmpty());
+ }
+
+
+ // some test interfaces and classes
+
+ public interface InvalidPriorityInterface {
+ }
+
+ @Priority(value = 50)
+ public static class InvalidPriorityImpl1 implements InvalidPriorityInterface {
+ }
+
+ @Priority(value = 50)
+ public static class InvalidPriorityImpl2 implements InvalidPriorityInterface {
+ }
+
+
+ public interface MultiImplsInterface {
+ }
+
+ public static class MultiImpl1 implements MultiImplsInterface {
+ }
+
+ @Priority(value = 500)
+ public static class MultiImpl2 implements MultiImplsInterface {
+ }
+
+ @Priority(value = -10)
+ public static class MultiImpl3 implements MultiImplsInterface {
+ }
+
+ private interface NoImplInterface {
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/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
new file mode 100644
index 0000000..9af9a5c
--- /dev/null
+++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/TestConfigurationProvider.java
@@ -0,0 +1,92 @@
+/*
+ * 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.spisupport;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.spi.ConfigurationBuilder;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
+import org.apache.tamaya.spi.ConfigurationProviderSpi;
+import org.osgi.service.component.annotations.Component;
+
+import java.util.Objects;
+
+/**
+ * Implementation of the Configuration API. This class uses the current {@link ConfigurationContext} to evaluate the
+ * chain of {@link org.apache.tamaya.spi.PropertySource} and {@link org.apache.tamaya.spi.PropertyFilter}
+ * instance to evaluate the current Configuration.
+ */
+@Component(service = ConfigurationProviderSpi.class)
+public class TestConfigurationProvider implements ConfigurationProviderSpi {
+
+ private Configuration config = new DefaultConfigurationBuilder()
+ .addDefaultPropertyConverters()
+ .addDefaultPropertyFilters()
+ .addDefaultPropertySources()
+ .build();
+ @Override
+ public Configuration getConfiguration() {
+ return config;
+ }
+
+ @Override
+ public Configuration createConfiguration(ConfigurationContext context) {
+ return new DefaultConfiguration(context);
+ }
+
+ @Override
+ public ConfigurationBuilder getConfigurationBuilder() {
+ return new DefaultConfigurationBuilder();
+ }
+
+ @Override
+ public ConfigurationContextBuilder getConfigurationContextBuilder() {
+ return new DefaultConfigurationContextBuilder();
+ }
+
+ @Override
+ public void setConfiguration(Configuration config) {
+ Objects.requireNonNull(config.getContext());
+ this.config = Objects.requireNonNull(config);
+ }
+
+ @Override
+ public boolean isConfigurationSettable() {
+ return true;
+ }
+
+ /**
+ * @deprecated use {@link Configuration#getContext()} instead.
+ */
+ @Deprecated
+ @Override
+ public ConfigurationContext getConfigurationContext() {
+ return this.config.getContext();
+ }
+
+ /**
+ * @deprecated the context should be given upon creation of the {@link Configuration}
+ */
+ @Deprecated
+ @Override
+ public void setConfigurationContext(ConfigurationContext context){
+ this.config = new DefaultConfigurationBuilder(context).build();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/code/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi b/code/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
new file mode 100644
index 0000000..aae53e4
--- /dev/null
+++ b/code/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
@@ -0,0 +1,18 @@
+# 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.
+
+org.apache.tamaya.spisupport.TestConfigurationProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spisupport.DefaultServiceContextTest$InvalidPriorityInterface
----------------------------------------------------------------------
diff --git a/code/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spisupport.DefaultServiceContextTest$InvalidPriorityInterface b/code/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spisupport.DefaultServiceContextTest$InvalidPriorityInterface
new file mode 100644
index 0000000..c894501
--- /dev/null
+++ b/code/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spisupport.DefaultServiceContextTest$InvalidPriorityInterface
@@ -0,0 +1,18 @@
+# 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.
+org.apache.tamaya.spisupport.DefaultServiceContextTest$InvalidPriorityImpl1
+org.apache.tamaya.spisupport.DefaultServiceContextTest$InvalidPriorityImpl2
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spisupport.DefaultServiceContextTest$MultiImplsInterface
----------------------------------------------------------------------
diff --git a/code/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spisupport.DefaultServiceContextTest$MultiImplsInterface b/code/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spisupport.DefaultServiceContextTest$MultiImplsInterface
new file mode 100644
index 0000000..71f7c46
--- /dev/null
+++ b/code/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spisupport.DefaultServiceContextTest$MultiImplsInterface
@@ -0,0 +1,20 @@
+# 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.
+
+org.apache.tamaya.spisupport.DefaultServiceContextTest$MultiImpl1
+org.apache.tamaya.spisupport.DefaultServiceContextTest$MultiImpl2
+org.apache.tamaya.spisupport.DefaultServiceContextTest$MultiImpl3
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/jqassistant/serviceloader-rules.xml
----------------------------------------------------------------------
diff --git a/jqassistant/serviceloader-rules.xml b/jqassistant/serviceloader-rules.xml
index 082430a..c8dd907 100644
--- a/jqassistant/serviceloader-rules.xml
+++ b/jqassistant/serviceloader-rules.xml
@@ -113,9 +113,9 @@ under the License.
// service configurations in version 1.0.0.
// I reported this problem already to the project
// Oliver B. Fischer, 15.5.5
- AND NOT sl.fileName IN ['/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImplsInterface',
- '/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface',
- '/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface']
+ AND NOT sl.fileName IN ['/META-INF/services/org.apache.tamaya.spisupport.DefaultServiceContextTest$MultiImplsInterface',
+ '/META-INF/services/org.apache.tamaya.spisupport.DefaultServiceContextTest$InvalidPriorityInterface',
+ '/META-INF/services/org.apache.tamaya.spisupport.DefaultServiceContextTest$InvalidPriorityInterface']
RETURN
sl.fileName AS serviceConfiguration, entry.name AS class
[5/6] incubator-tamaya git commit: TAMAYA-321 Fixed test.
getOrDefault must accept null as well.
Posted by an...@apache.org.
TAMAYA-321 Fixed test. getOrDefault must accept null as well.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/b9ce1495
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/b9ce1495
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/b9ce1495
Branch: refs/heads/master
Commit: b9ce14952b5e65bb9ec511bf3c5243167187d5e8
Parents: b117880
Author: Anatole Tresch <an...@apache.org>
Authored: Sun Nov 26 17:39:56 2017 +0100
Committer: Anatole Tresch <an...@apache.org>
Committed: Sun Nov 26 17:39:56 2017 +0100
----------------------------------------------------------------------
.../apache/tamaya/spisupport/DefaultConfigurationTest.java | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9ce1495/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationTest.java
----------------------------------------------------------------------
diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationTest.java
index 27eeda1..4711dc5 100644
--- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationTest.java
+++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationTest.java
@@ -121,11 +121,10 @@ public class DefaultConfigurationTest {
c.getOrDefault(null, "ok");
}
- @Test(expected = NullPointerException.class)
- public void getOrDefaultDoesNotAcceptNullAsDefaultValueForTwoParameterVariantDefaultValueIsSecond() {
+ @Test
+ public void getOrDefaultDoesAcceptNullAsDefaultValueForTwoParameterVariantDefaultValueIsSecond() {
DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
-
- c.getOrDefault("a", null);
+ assertNull(c.getOrDefault("a", null));
}
@Test(expected = NullPointerException.class)
[6/6] incubator-tamaya git commit: TAMAYA-321 Add
ConfigurationBuilder to core API.
Posted by an...@apache.org.
TAMAYA-321 Add ConfigurationBuilder to core API.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/27c0d76b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/27c0d76b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/27c0d76b
Branch: refs/heads/master
Commit: 27c0d76bb0b3bc5b5a2df337289fcbcfbee48218
Parents: b9ce149
Author: Anatole Tresch <an...@apache.org>
Authored: Sun Nov 26 23:51:15 2017 +0100
Committer: Anatole Tresch <an...@apache.org>
Committed: Sun Nov 26 23:51:15 2017 +0100
----------------------------------------------------------------------
.../examples/minimal/TestConfigProvider.java | 73 --------------------
1 file changed, 73 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/27c0d76b/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/TestConfigProvider.java
----------------------------------------------------------------------
diff --git a/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/TestConfigProvider.java b/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/TestConfigProvider.java
deleted file mode 100644
index 632f886..0000000
--- a/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/TestConfigProvider.java
+++ /dev/null
@@ -1,73 +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.examples.minimal;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.core.internal.CoreConfigurationContextBuilder;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-import org.apache.tamaya.spi.ConfigurationProviderSpi;
-
-/**
- * Configuration provider that allows to set and reset a configuration
- * different per thread.
- */
-public class TestConfigProvider implements ConfigurationProviderSpi{
-
- private ThreadLocal<Configuration> threadedConfig = new ThreadLocal<>();
-
- @Override
- public Configuration getConfiguration() {
- Configuration config = threadedConfig.get();
- if(config!=null){
- return config;
- }
- config = createConfiguration(new CoreConfigurationContextBuilder()
- .addDefaultPropertyFilters()
- .addDefaultPropertySources()
- .addDefaultPropertyConverters()
- .build());
- threadedConfig.set(config);
- return config;
- }
-
- @Override
- public Configuration createConfiguration(ConfigurationContext context) {
- return null;
- }
-
- @Override
- public ConfigurationContextBuilder getConfigurationContextBuilder() {
- return null;
- }
-
- @Override
- public void setConfiguration(Configuration config) {
- if(config==null){
- threadedConfig.remove();
- }else {
- threadedConfig.set(config);
- }
- }
-
- @Override
- public boolean isConfigurationSettable() {
- return false;
- }
-}
[4/6] incubator-tamaya git commit: TAMAYA-321 Fixed Javadoc.
Posted by an...@apache.org.
TAMAYA-321 Fixed Javadoc.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/b1178806
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/b1178806
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/b1178806
Branch: refs/heads/master
Commit: b1178806194f06f5800caba70a61cb04273d6dff
Parents: 15f7cbb
Author: Anatole Tresch <an...@apache.org>
Authored: Sun Nov 26 17:30:24 2017 +0100
Committer: Anatole Tresch <an...@apache.org>
Committed: Sun Nov 26 17:30:24 2017 +0100
----------------------------------------------------------------------
.../java/org/apache/tamaya/Configuration.java | 1 -
.../apache/tamaya/spi/ConfigurationBuilder.java | 33 ++++++++++----------
.../org/apache/tamaya/spi/FilterContext.java | 2 +-
3 files changed, 18 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b1178806/code/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/Configuration.java b/code/api/src/main/java/org/apache/tamaya/Configuration.java
index 401eac7..b891d43 100644
--- a/code/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/code/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -176,5 +176,4 @@ public interface Configuration {
return ConfigurationProvider.getConfigurationBuilder().setConfiguration(this);
}
-
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b1178806/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationBuilder.java b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationBuilder.java
index c9afa0f..a2b3257 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationBuilder.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationBuilder.java
@@ -27,17 +27,17 @@ import java.util.List;
import java.util.Map;
/**
- * A builder for creating new or adapting instances of {@link ConfigurationContext}.
+ * A builder for creating new instance of {@link Configuration}.
* Builders can be obtained in exactly two ways:
* <ol>
- * <li>By accessing a preinitialized builder from an existing {@link ConfigurationContext},
- * by calling {@link org.apache.tamaya.spi.ConfigurationContext#toBuilder()}.</li>
+ * <li>By accessing a preinitialized builder from an existing {@link Configuration},
+ * by calling {@link org.apache.tamaya.spi.Configuration#toBuilder()}.</li>
* <li>By accessing an empty builder instance from
- * {@link org.apache.tamaya.ConfigurationProvider#getConfigurationContextBuilder()}.</li>
+ * {@link org.apache.tamaya.ConfigurationProvider#getConfigurationBuilder()}.</li>
* </ol>
- * After all changes are applied to a builder a new {@link ConfigurationContext} instance can
+ * After all changes are applied to a builder a new {@link Configuration} instance can
* be created and can be applied by calling
- * {@link org.apache.tamaya.ConfigurationProvider#setConfigurationContext(org.apache.tamaya.spi.ConfigurationContext)}.
+ * {@link #build()}}.
*
*/
public interface ConfigurationBuilder {
@@ -46,7 +46,8 @@ public interface ConfigurationBuilder {
* Init this builder instance with the given {@link Configuration} instance. This
* method will use any existing property sources, filters, converters and the combination
* policy of the given {@link Configuration} and initialize the current builder
- * with them.
+ * with them. All previous property sources, filters, converters and the combination
+ * policy of this instance will be replaced.
*
* @param config the {@link Configuration} instance to be used, not {@code null}.
* @return this builder, for chaining, never null.
@@ -57,7 +58,8 @@ public interface ConfigurationBuilder {
* Init this builder instance with the given {@link ConfigurationContext} instance. This
* method will use any existing property sources, filters, converters and the combination
* policy of the given {@link ConfigurationContext} and initialize the current builder
- * with them.
+ * with them. All previous property sources, filters, converters and the combination
+ * policy of this instance will be replaced.
*
* @param context the {@link ConfigurationContext} instance to be used, not {@code null}.
* @return this builder, for chaining, never null.
@@ -128,7 +130,7 @@ public interface ConfigurationBuilder {
* Access the current chain of property filters. Items at the end of the list have
* precedence/more significance.
*
- * @return the property source chain, never {@code null}.
+ * @return the property filter chain, never {@code null}.
*/
List<PropertyFilter> getPropertyFilters();
@@ -212,7 +214,7 @@ public interface ConfigurationBuilder {
ConfigurationBuilder addPropertyFilters(Collection<PropertyFilter> filters);
/**
- * Add all registered (default) property filters to the context built.
+ * Add all auto-discoverable property filters to the context built.
* @return this builder, for chaining, never null.
*/
ConfigurationBuilder addDefaultPropertyFilters();
@@ -256,7 +258,7 @@ public interface ConfigurationBuilder {
* For converters already registered for the current target type the
* method has no effect.
*
- * @param typeToConvert the type for which the converter is for
+ * @param typeToConvert the type for which the converter is for
* @param propertyConverters the PropertyConverters to add for this type
* @param <T> the target type.
* @return this builder, for chaining, never null.
@@ -265,7 +267,7 @@ public interface ConfigurationBuilder {
Collection<PropertyConverter<T>> propertyConverters);
/**
- * Add all registered (default) property converters to the context built.
+ * Add all auto-discoverable property converters to the context built.
* @return this builder, for chaining, never null.
*/
ConfigurationBuilder addDefaultPropertyConverters();
@@ -333,13 +335,12 @@ public interface ConfigurationBuilder {
ConfigurationBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy policy);
/**
- * Builds a new {@link ConfigurationContext} based on the data in this builder. The ordering of property
+ * Builds a new {@link Configuration} based on the data in this builder. The ordering of property
* sources and property filters is not changed, regardless of their ordinals. For ensure a certain
- * ordering/significance call {@link #sortPropertyFilter(Comparator)} and/or {@link #sortPropertySources(Comparator)}
+ * ordering/significance use {@link #sortPropertyFilter(Comparator)} and/or {@link #sortPropertySources(Comparator)}
* before building the context.
*
- * @return the final context to be used to create a configuration.
- * @see org.apache.tamaya.ConfigurationProvider#createConfiguration(ConfigurationContext)
+ * @return the final configuration, never null.
*/
Configuration build();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b1178806/code/api/src/main/java/org/apache/tamaya/spi/FilterContext.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/FilterContext.java b/code/api/src/main/java/org/apache/tamaya/spi/FilterContext.java
index 76babb5..2851697 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/FilterContext.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/FilterContext.java
@@ -33,7 +33,7 @@ import java.util.Objects;
public class FilterContext {
/** The key. */
private final PropertyValue value;
- /** tHE CURRENT CONTEXT. */
+ /** The current context. */
private final ConfigurationContext context;
@Experimental
private Map<String, PropertyValue> configEntries = new HashMap<>();
[2/6] incubator-tamaya git commit: TAMAYA-321 Add
ConfigurationBuilder to core API.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/core/src/test/java/org/apache/tamaya/core/ConfigurationBuilderTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationBuilderTest.java b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationBuilderTest.java
new file mode 100644
index 0000000..1f702bb
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationBuilderTest.java
@@ -0,0 +1,440 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.core.internal.CoreConfigurationBuilder;
+import org.apache.tamaya.spi.*;
+import org.apache.tamaya.spisupport.DefaultConfigurationContextBuilder;
+import org.junit.Test;
+import sun.security.krb5.Config;
+
+import java.util.Arrays;
+import java.util.Comparator;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for {@link ConfigurationBuilder} by atsticks on 06.09.16.
+ */
+public class ConfigurationBuilderTest {
+
+ private TestPropertySource testPropertySource = new TestPropertySource(){};
+
+ @Test
+ public void setContext() throws Exception {
+ Configuration cfg = ConfigurationProvider.getConfiguration();
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder()
+ .setConfiguration(cfg);
+ assertEquals(cfg, b.build());
+ }
+
+ @Test
+ public void addPropertySources_Array() throws Exception {
+ PropertySource testPS2 = new TestPropertySource("addPropertySources_Array", 1);
+ ConfigurationBuilder b = new CoreConfigurationBuilder()
+ .addPropertySources(testPropertySource, testPS2);
+ Configuration cfg = b.build();
+ assertEquals(2, cfg.getContext().getPropertySources().size());
+ assertTrue(cfg.getContext().getPropertySources().contains(testPropertySource));
+ assertTrue(cfg.getContext().getPropertySources().contains(testPS2));
+ // Ensure no sorting happens during add, so switch ordinals!
+ testPS2 = new TestPropertySource("addPropertySources_Array", 1);
+ b = ConfigurationProvider.getConfigurationBuilder()
+ .addPropertySources(testPS2, testPropertySource);
+ cfg = b.build();
+ assertEquals(2, cfg.getContext().getPropertySources().size());
+ assertTrue(cfg.getContext().getPropertySources().contains(testPropertySource));
+ assertTrue(cfg.getContext().getPropertySources().contains(testPS2));
+ assertEquals(cfg.getContext().getPropertySources().get(1).getName(), "TestPropertySource");
+ assertEquals(cfg.getContext().getPropertySources().get(0).getName(), "addPropertySources_Array");
+ }
+
+ @Test
+ public void addPropertySources_Collection() throws Exception {
+ PropertySource testPS2 = new TestPropertySource("addPropertySources_Collection", 1);
+ ConfigurationBuilder b = new CoreConfigurationBuilder()
+ .addPropertySources(Arrays.asList(new PropertySource[]{testPropertySource, testPS2}));
+ Configuration cfg = b.build();
+ assertEquals(2, cfg.getContext().getPropertySources().size());
+ assertTrue(cfg.getContext().getPropertySources().contains(testPropertySource));
+ assertTrue(cfg.getContext().getPropertySources().contains(testPS2));
+ assertEquals(cfg.getContext().getPropertySources().get(0).getName(), "TestPropertySource");
+ assertEquals(cfg.getContext().getPropertySources().get(1).getName(), "addPropertySources_Collection");
+ // Ensure no sorting happens during add, so switch ordinals!
+ testPS2 = new TestPropertySource("addPropertySources_Collection", 1);
+ b = ConfigurationProvider.getConfigurationBuilder()
+ .addPropertySources(Arrays.asList(new PropertySource[]{testPS2, testPropertySource}));
+ cfg = b.build();
+ assertEquals(2, cfg.getContext().getPropertySources().size());
+ assertTrue(cfg.getContext().getPropertySources().contains(testPropertySource));
+ assertTrue(cfg.getContext().getPropertySources().contains(testPS2));
+ assertEquals(cfg.getContext().getPropertySources().get(1).getName(), "TestPropertySource");
+ assertEquals(cfg.getContext().getPropertySources().get(0).getName(), "addPropertySources_Collection");
+ }
+
+ @Test
+ public void removePropertySources_Array() throws Exception {
+ PropertySource testPS2 = new TestPropertySource("removePropertySources_Array", 1);
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder()
+ .addPropertySources(testPropertySource, testPS2);
+ Configuration cfg = b.build();
+ assertEquals(2, cfg.getContext().getPropertySources().size());
+ assertTrue(cfg.getContext().getPropertySources().contains(testPropertySource));
+ assertTrue(cfg.getContext().getPropertySources().contains(testPS2));
+ b = ConfigurationProvider.getConfigurationBuilder()
+ .addPropertySources(testPropertySource, testPS2);
+ b.removePropertySources(testPropertySource);
+ cfg = b.build();
+ assertFalse(cfg.getContext().getPropertySources().contains(testPropertySource));
+ assertTrue(cfg.getContext().getPropertySources().contains(testPS2));
+ assertEquals(1, cfg.getContext().getPropertySources().size());
+ }
+
+ @Test
+ public void removePropertySources_Collection() throws Exception {
+ PropertySource testPS2 = new TestPropertySource("removePropertySources_Array", 1);
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder()
+ .addPropertySources(testPropertySource, testPS2);
+ Configuration cfg = b.build();
+ assertEquals(2, cfg.getContext().getPropertySources().size());
+ assertTrue(cfg.getContext().getPropertySources().contains(testPropertySource));
+ assertTrue(cfg.getContext().getPropertySources().contains(testPS2));
+ b = ConfigurationProvider.getConfigurationBuilder()
+ .addPropertySources(testPropertySource, testPS2);
+ b.removePropertySources(testPropertySource);
+ cfg = b.build();
+ assertEquals(1, cfg.getContext().getPropertySources().size());
+ assertFalse(cfg.getContext().getPropertySources().contains(testPropertySource));
+ assertTrue(cfg.getContext().getPropertySources().contains(testPS2));
+ }
+
+ @Test
+ public void addPropertyFilters_Array() throws Exception {
+ PropertyFilter filter1 = (value, context) -> value;
+ PropertyFilter filter2 = (value, context) -> value;
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder();
+ b.addPropertyFilters(filter1, filter2);
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertTrue(ctx.getPropertyFilters().contains(filter1));
+ assertTrue(ctx.getPropertyFilters().contains(filter2));
+ assertEquals(2, ctx.getPropertyFilters().size());
+ b = ConfigurationProvider.getConfigurationBuilder();
+ b.addPropertyFilters(filter1, filter2);
+ b.addPropertyFilters(filter1, filter2);
+ assertEquals(2, ctx.getPropertyFilters().size());
+ }
+
+ @Test
+ public void addPropertyFilters_Collection() throws Exception {
+ PropertyFilter filter1 = (value, context) -> value;
+ PropertyFilter filter2 = (value, context) -> value;
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder();
+ b.addPropertyFilters(Arrays.asList(new PropertyFilter[]{filter1, filter2}));
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertTrue(ctx.getPropertyFilters().contains(filter1));
+ assertTrue(ctx.getPropertyFilters().contains(filter2));
+ assertEquals(2, ctx.getPropertyFilters().size());
+ b = ConfigurationProvider.getConfigurationBuilder();
+ b.addPropertyFilters(filter1, filter2);
+ b.addPropertyFilters(filter1, filter2);
+ assertEquals(2, ctx.getPropertyFilters().size());
+ }
+
+ @Test
+ public void removePropertyFilters_Array() throws Exception {
+ PropertyFilter filter1 = (value, context) -> value;
+ PropertyFilter filter2 = (value, context) -> value;
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder()
+ .addPropertyFilters(filter1, filter2);
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertTrue(ctx.getPropertyFilters().contains(filter1));
+ assertTrue(ctx.getPropertyFilters().contains(filter2));
+ assertEquals(2, ctx.getPropertyFilters().size());
+ b = ConfigurationProvider.getConfigurationBuilder()
+ .addPropertyFilters(filter1, filter2);
+ b.removePropertyFilters(filter1);
+ cfg = b.build();
+ ctx = cfg.getContext();
+ assertEquals(1, ctx.getPropertyFilters().size());
+ assertFalse(ctx.getPropertyFilters().contains(filter1));
+ assertTrue(ctx.getPropertyFilters().contains(filter2));
+ }
+
+ @Test
+ public void removePropertyFilters_Collection() throws Exception {
+ PropertyFilter filter1 = (value, context) -> value;
+ PropertyFilter filter2 = (value, context) -> value;
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder()
+ .addPropertyFilters(Arrays.asList(new PropertyFilter[]{filter1, filter2}));
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertTrue(ctx.getPropertyFilters().contains(filter1));
+ assertTrue(ctx.getPropertyFilters().contains(filter2));
+ assertEquals(2, ctx.getPropertyFilters().size());
+ b = ConfigurationProvider.getConfigurationBuilder()
+ .addPropertyFilters(Arrays.asList(new PropertyFilter[]{filter1, filter2}));
+ b.removePropertyFilters(filter1);
+ cfg = b.build();
+ ctx = cfg.getContext();
+ assertEquals(1, ctx.getPropertyFilters().size());
+ assertFalse(ctx.getPropertyFilters().contains(filter1));
+ assertTrue(ctx.getPropertyFilters().contains(filter2));
+ }
+
+ @Test
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public void addPropertyConverters_Array() throws Exception {
+ PropertyConverter converter = (value, context) -> value.toLowerCase();
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder()
+ .addPropertyConverters(TypeLiteral.of(String.class), converter);
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
+ assertEquals(1, ctx.getPropertyConverters().size());
+ b = ConfigurationProvider.getConfigurationBuilder()
+ .addPropertyConverters(TypeLiteral.of(String.class), converter);
+ b.addPropertyConverters(TypeLiteral.of(String.class), converter);
+ assertEquals(1, ctx.getPropertyConverters().size());
+ }
+
+ @Test
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public void addPropertyConverters_Collection() throws Exception {
+ PropertyConverter converter = (value, context) -> value.toLowerCase();
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder()
+ .addPropertyConverters(TypeLiteral.of(String.class),
+ Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter}));
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
+ assertEquals(ctx.getPropertyConverters().size(), 1);
+ b = ConfigurationProvider.getConfigurationBuilder()
+ .addPropertyConverters(TypeLiteral.of(String.class),
+ Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter}));
+ b.addPropertyConverters(TypeLiteral.of(String.class), converter);
+ assertEquals(ctx.getPropertyConverters().size(), 1);
+ }
+
+ @Test
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public void removePropertyConverters_Array() throws Exception {
+ PropertyConverter converter = (value, context) -> value.toLowerCase();
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder()
+ .addPropertyConverters(TypeLiteral.of(String.class), converter);
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
+ assertEquals(1, ctx.getPropertyConverters(TypeLiteral.of(String.class)).size());
+ b = ConfigurationProvider.getConfigurationBuilder()
+ .addPropertyConverters(TypeLiteral.of(String.class), converter);
+ b.removePropertyConverters(TypeLiteral.of(String.class), converter);
+ cfg = b.build();
+ ctx = cfg.getContext();
+ assertFalse(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
+ assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).isEmpty());
+ }
+
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Test
+ public void removePropertyConverters_Collection() throws Exception {
+ PropertyConverter converter = (value, context) -> value.toLowerCase();
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder()
+ .addPropertyConverters(TypeLiteral.of(String.class), Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter}));
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
+ assertEquals(1, ctx.getPropertyConverters(TypeLiteral.of(String.class)).size());
+ b = ConfigurationProvider.getConfigurationBuilder()
+ .addPropertyConverters(TypeLiteral.of(String.class), Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter}));
+ b.removePropertyConverters(TypeLiteral.of(String.class), Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter}));
+ cfg = b.build();
+ ctx = cfg.getContext();
+ assertFalse(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
+ assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).isEmpty());
+ }
+
+ @Test
+ public void setPropertyValueCombinationPolicy() throws Exception {
+ PropertyValueCombinationPolicy combPol = (currentValue, key, propertySource) -> currentValue;
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder()
+ .setPropertyValueCombinationPolicy(combPol);
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertEquals(ctx.getPropertyValueCombinationPolicy(), combPol);
+ }
+
+ @Test
+ public void increasePriority(){
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder();
+ TestPropertySource[] propertySources = new TestPropertySource[10];
+ for(int i=0;i<propertySources.length;i++){
+ propertySources[i] = new TestPropertySource("ps"+i,i);
+ }
+ b.addPropertySources(propertySources);
+ b.increasePriority(propertySources[propertySources.length-1]);
+ for(int i=0;i<propertySources.length;i++){
+ assertEquals(propertySources[i], b.getPropertySources().get(i));
+ }
+ b.increasePriority(propertySources[propertySources.length-2]);
+ for(int i=0;i<propertySources.length-2;i++){
+ assertEquals(propertySources[i], b.getPropertySources().get(i));
+ }
+ assertEquals(propertySources[propertySources.length-1], b.getPropertySources().get(propertySources.length-2));
+ assertEquals(propertySources[propertySources.length-2], b.getPropertySources().get(propertySources.length-1));
+ }
+
+ @Test
+ public void decreasePriority(){
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder();
+ TestPropertySource[] propertySources = new TestPropertySource[10];
+ for(int i=0;i<propertySources.length;i++){
+ propertySources[i] = new TestPropertySource("ps"+i,i);
+ }
+ b.addPropertySources(propertySources);
+ b.decreasePriority(propertySources[0]);
+ for(int i=0;i<propertySources.length;i++){
+ assertEquals(propertySources[i], b.getPropertySources().get(i));
+ }
+ b.decreasePriority(propertySources[1]);
+ for(int i=2;i<propertySources.length;i++){
+ assertEquals(propertySources[i], b.getPropertySources().get(i));
+ }
+ assertEquals(propertySources[0], b.getPropertySources().get(1));
+ assertEquals(propertySources[1], b.getPropertySources().get(0));
+ }
+
+ @Test
+ public void lowestPriority(){
+ // setup
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder();
+ TestPropertySource[] propertySources = new TestPropertySource[10];
+ for(int i=0;i<propertySources.length;i++){
+ propertySources[i] = new TestPropertySource("ps"+i,i);
+ }
+ b.addPropertySources(propertySources);
+ // test
+ b.lowestPriority(propertySources[0]);
+ for(int i=0;i<propertySources.length;i++){
+ assertEquals(propertySources[i], b.getPropertySources().get(i));
+ }
+ b.lowestPriority(propertySources[1]);
+ for(int i=2;i<propertySources.length;i++){
+ assertEquals(propertySources[i], b.getPropertySources().get(i));
+ }
+ assertEquals(propertySources[0], b.getPropertySources().get(1));
+ assertEquals(propertySources[1], b.getPropertySources().get(0));
+ b.lowestPriority(propertySources[5]);
+ assertEquals(propertySources[5], b.getPropertySources().get(0));
+ }
+
+ @Test
+ public void highestPriority(){
+ // setup
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder();
+ TestPropertySource[] propertySources = new TestPropertySource[10];
+ for(int i=0;i<propertySources.length;i++){
+ propertySources[i] = new TestPropertySource("ps"+i,i);
+ }
+ b.addPropertySources(propertySources);
+ // test
+ b.highestPriority(propertySources[propertySources.length-1]);
+ for(int i=0;i<propertySources.length;i++){
+ assertEquals(propertySources[i], b.getPropertySources().get(i));
+ }
+ b.highestPriority(propertySources[propertySources.length-2]);
+ for(int i=0;i<propertySources.length-2;i++){
+ assertEquals(propertySources[i], b.getPropertySources().get(i));
+ }
+ assertEquals(propertySources[propertySources.length-2], b.getPropertySources().get(propertySources.length-1));
+ assertEquals(propertySources[propertySources.length-1], b.getPropertySources().get(propertySources.length-2));
+ b.highestPriority(propertySources[5]);
+ assertEquals(propertySources[5], b.getPropertySources().get(propertySources.length-1));
+ }
+
+ @Test
+ public void sortPropertySources(){
+ // setup
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder();
+ TestPropertySource[] propertySources = new TestPropertySource[10];
+ for(int i=0;i<propertySources.length;i++){
+ propertySources[i] = new TestPropertySource("ps"+i,i);
+ }
+ b.addPropertySources(propertySources);
+ Comparator<PropertySource> psComp = (o1, o2) -> o1.toString().compareTo(o2.toString());
+ // test
+ b.sortPropertySources(psComp);
+ Arrays.sort(propertySources, psComp);
+ for(int i=0;i<propertySources.length;i++){
+ assertEquals(propertySources[i], b.getPropertySources().get(i));
+ }
+ }
+
+ @Test
+ public void sortPropertyFilter(){
+ // setup
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder();
+ PropertyFilter[] propertyFilters = new PropertyFilter[10];
+ for(int i=0;i<propertyFilters.length;i++){
+ propertyFilters[i] = (value, context) -> value.toBuilder().setValue(toString() + " - ").build();
+ }
+ b.addPropertyFilters(propertyFilters);
+ Comparator<PropertyFilter> pfComp = (o1, o2) -> o1.toString().compareTo(o2.toString());
+ // test
+ b.sortPropertyFilter(pfComp);
+ Arrays.sort(propertyFilters, pfComp);
+ for(int i=0;i<propertyFilters.length;i++){
+ assertEquals(propertyFilters[i], b.getPropertyFilters().get(i));
+ }
+ }
+
+ @Test
+ public void build() throws Exception {
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder();
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertNotNull(ctx);
+ assertTrue(ctx.getPropertySources().isEmpty());
+ assertTrue(ctx.getPropertyFilters().isEmpty());
+ }
+
+ @Test
+ public void testRemoveAllFilters() throws Exception {
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder();
+ b.addPropertyFilters((value, context) -> value.toBuilder().setValue(toString() + " - ").build());
+ assertFalse(b.getPropertyFilters().isEmpty());
+ b.removePropertyFilters(b.getPropertyFilters());
+ assertTrue(b.getPropertyFilters().isEmpty());
+ }
+
+ @Test
+ public void testRemoveAllSources() throws Exception {
+ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder();
+ b.addPropertySources(new TestPropertySource());
+ assertFalse(b.getPropertySources().isEmpty());
+ b.removePropertySources(b.getPropertySources());
+ assertTrue(b.getPropertyFilters().isEmpty());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/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 5fb65ff..ac353eb 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.CoreConfigurationContextBuilder;
+import org.apache.tamaya.spisupport.DefaultConfigurationContextBuilder;
import org.junit.Test;
import java.util.Arrays;
@@ -30,7 +30,7 @@ import java.util.Comparator;
import static org.junit.Assert.*;
/**
- * Tests for {@link CoreConfigurationContextBuilder} by atsticks on 06.09.16.
+ * Tests for {@link ConfigurationContextBuilder} 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 CoreConfigurationContextBuilder()
+ ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder()
.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 CoreConfigurationContextBuilder()
+ ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder()
.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/15f7cbbb/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationBuilderTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationBuilderTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationBuilderTest.java
new file mode 100644
index 0000000..37dc2cb
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationBuilderTest.java
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.*;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for {@link CoreConfigurationBuilder} by atsticks on 06.09.16.
+ */
+public class CoreConfigurationBuilderTest {
+
+ private TestPropertySource testPropertySource = new TestPropertySource(){};
+
+ @Test
+ public void setContext() throws Exception {
+ ConfigurationContext context = ConfigurationProvider.getConfiguration().getContext();
+ ConfigurationBuilder b = new CoreConfigurationBuilder()
+ .setContext(context);
+ assertEquals(context, b.build().getContext());
+ }
+
+ @Test
+ public void setConfiguration() throws Exception {
+ Configuration cfg = ConfigurationProvider.getConfiguration();
+ ConfigurationBuilder b = new CoreConfigurationBuilder()
+ .setConfiguration(cfg);
+ assertEquals(cfg, b.build());
+ }
+
+ @Test
+ public void addPropertySources_Array() throws Exception {
+ PropertySource testPS2 = new TestPropertySource("addPropertySources_Array_2");
+ ConfigurationBuilder b = new CoreConfigurationBuilder()
+ .addPropertySources(testPropertySource, testPS2);
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertEquals(2, ctx.getPropertySources().size());
+ assertTrue(ctx.getPropertySources().contains(testPropertySource));
+ assertTrue(ctx.getPropertySources().contains(testPS2));
+ }
+
+ @Test
+ public void removePropertySources_Array() throws Exception {
+ PropertySource testPS2 = new TestPropertySource("addPropertySources_Array_2");
+ ConfigurationBuilder b = new CoreConfigurationBuilder()
+ .addPropertySources(testPropertySource, testPS2);
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertEquals(2, ctx.getPropertySources().size());
+ assertTrue(ctx.getPropertySources().contains(testPropertySource));
+ assertTrue(ctx.getPropertySources().contains(testPS2));
+ b = new CoreConfigurationBuilder()
+ .addPropertySources(testPropertySource, testPS2);
+ b.removePropertySources(testPropertySource);
+ cfg = b.build();
+ ctx = cfg.getContext();
+ assertEquals(1, ctx.getPropertySources().size());
+ assertFalse(ctx.getPropertySources().contains(testPropertySource));
+ assertTrue(ctx.getPropertySources().contains(testPS2));
+ }
+
+ @Test
+ public void addPropertyFilters_Array() throws Exception {
+ PropertyFilter filter1 = (value, context) -> value;
+ PropertyFilter filter2 = (value, context) -> value;
+ CoreConfigurationBuilder b = new CoreConfigurationBuilder();
+ b.addPropertyFilters(filter1, filter2);
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertTrue(ctx.getPropertyFilters().contains(filter1));
+ assertTrue(ctx.getPropertyFilters().contains(filter2));
+ assertEquals(2, ctx.getPropertyFilters().size());
+ b = new CoreConfigurationBuilder();
+ b.addPropertyFilters(filter1, filter2);
+ b.addPropertyFilters(filter1, filter2);
+ assertEquals(2, ctx.getPropertyFilters().size());
+ }
+
+ @Test
+ public void removePropertyFilters_Array() throws Exception {
+ PropertyFilter filter1 = (value, context) -> value;
+ PropertyFilter filter2 = (value, context) -> value;
+ ConfigurationBuilder b = new CoreConfigurationBuilder()
+ .addPropertyFilters(filter1, filter2);
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertTrue(ctx.getPropertyFilters().contains(filter1));
+ assertTrue(ctx.getPropertyFilters().contains(filter2));
+ assertEquals(2, ctx.getPropertyFilters().size());
+ b = new CoreConfigurationBuilder()
+ .addPropertyFilters(filter1, filter2);
+ b.removePropertyFilters(filter1);
+ cfg = b.build();
+ ctx = cfg.getContext();
+ assertEquals(1, ctx.getPropertyFilters().size());
+ assertFalse(ctx.getPropertyFilters().contains(filter1));
+ assertTrue(ctx.getPropertyFilters().contains(filter2));
+ }
+
+ @Test
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public void addPropertyConverter() throws Exception {
+ PropertyConverter converter = (value, context) -> value.toLowerCase();
+ ConfigurationBuilder b = new CoreConfigurationBuilder()
+ .addPropertyConverters(TypeLiteral.of(String.class), converter);
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
+ assertEquals(1, ctx.getPropertyConverters().size());
+ b = new CoreConfigurationBuilder()
+ .addPropertyConverters(TypeLiteral.of(String.class), converter);
+ b.addPropertyConverters(TypeLiteral.of(String.class), converter);
+ assertEquals(1, ctx.getPropertyConverters().size());
+ }
+
+ @Test
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public void removePropertyConverters_Array() throws Exception {
+ PropertyConverter converter = (value, context) -> value.toLowerCase();
+ ConfigurationBuilder b = new CoreConfigurationBuilder()
+ .addPropertyConverters(TypeLiteral.of(String.class), converter);
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
+ assertEquals(1, ctx.getPropertyConverters(TypeLiteral.of(String.class)).size());
+ b = new CoreConfigurationBuilder()
+ .addPropertyConverters(TypeLiteral.of(String.class), converter);
+ b.removePropertyConverters(TypeLiteral.of(String.class), converter);
+ cfg = b.build();
+ ctx = cfg.getContext();
+ assertFalse(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter));
+ assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).isEmpty());
+ }
+
+ @Test
+ public void setPropertyValueCombinationPolicy() throws Exception {
+ PropertyValueCombinationPolicy combPol = (currentValue, key, propertySource) -> currentValue;
+ ConfigurationBuilder b = new CoreConfigurationBuilder()
+ .setPropertyValueCombinationPolicy(combPol);
+ Configuration cfg = b.build();
+ ConfigurationContext ctx = cfg.getContext();
+ assertEquals(ctx.getPropertyValueCombinationPolicy(), combPol);
+ }
+
+ @Test
+ public void build() throws Exception {
+ assertNotNull(new CoreConfigurationBuilder().build());
+ }
+
+ @Test
+ public void bla() throws Exception {
+ ConfigurationBuilder builder = ConfigurationProvider.getConfigurationBuilder();
+ builder.addDefaultPropertyConverters();
+ }
+
+ private static class TestPropertySource implements PropertySource{
+
+ private String id;
+
+ public TestPropertySource(){
+ this(null);
+ }
+
+ public TestPropertySource(String id){
+ this.id = id;
+ }
+
+ @Override
+ public int getOrdinal() {
+ return 200;
+ }
+
+ @Override
+ public String getName() {
+ return id!=null?id:"TestPropertySource";
+ }
+
+ @Override
+ public PropertyValue get(String key) {
+ return PropertyValue.of(key, key + "Value", getName());
+ }
+
+ @Override
+ public Map<String, PropertyValue> getProperties() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public boolean isScannable() {
+ return false;
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/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
deleted file mode 100644
index 8458366..0000000
--- a/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationContextBuilderTest.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 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/15f7cbbb/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
deleted file mode 100644
index 1c10124..0000000
--- a/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationContextTest.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 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/15f7cbbb/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationProviderTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationProviderTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationProviderTest.java
new file mode 100644
index 0000000..e4dab56
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationProviderTest.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.Configuration;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by atsticks on 11.09.16.
+ */
+public class CoreConfigurationProviderTest {
+
+ @Test
+ public void testInstantiation() throws Exception {
+ new CoreConfigurationProvider();
+ }
+
+ @Test
+ public void getConfiguration() throws Exception {
+ assertNotNull(new CoreConfigurationProvider().getConfiguration());
+ }
+
+ @Test
+ public void createConfiguration() throws Exception {
+ Configuration cfg = new CoreConfigurationBuilder().build();
+ assertNotNull(new CoreConfigurationProvider().createConfiguration(cfg.getContext()));
+ assertEquals(cfg,
+ new CoreConfigurationProvider().createConfiguration(cfg.getContext()));
+ }
+
+ @Test
+ public void getConfigurationContext() throws Exception {
+ assertNotNull(new CoreConfigurationProvider().getConfigurationContext());
+ assertEquals(new CoreConfigurationProvider().getConfigurationContext(),
+ new CoreConfigurationProvider().getConfiguration().getContext());
+ }
+
+ @Test
+ public void getConfigurationContextBuilder() throws Exception {
+ assertNotNull(new CoreConfigurationProvider().getConfigurationContextBuilder());
+ }
+
+ @Test
+ public void getConfigurationBuilder() throws Exception {
+ assertNotNull(new CoreConfigurationProvider().getConfigurationBuilder());
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void setConfigurationContext() throws Exception {
+ new CoreConfigurationProvider()
+ .setConfigurationContext(new CoreConfigurationProvider().getConfiguration().getContext());
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void setConfiguration() throws Exception {
+ new CoreConfigurationProvider()
+ .setConfiguration(new CoreConfigurationProvider().getConfiguration());
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void isConfigurationContextSettable() throws Exception {
+ assertTrue(new CoreConfigurationProvider().isConfigurationContextSettable());
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void isConfigurationSettable() throws Exception {
+ assertTrue(new CoreConfigurationProvider().isConfigurationSettable());
+ }
+
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationTest.java
new file mode 100644
index 0000000..6b8d1dc
--- /dev/null
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationTest.java
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.core.testdata.TestPropertyDefaultSource;
+import org.apache.tamaya.spi.*;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Simple tests for {@link CoreConfiguration} by atsticks on 16.08.16.
+ */
+public class CoreConfigurationTest {
+
+ @Test
+ public void addPropertySources() throws Exception {
+ Configuration cfg = new CoreConfigurationBuilder().build();
+ TestPropertyDefaultSource def = new TestPropertyDefaultSource();
+ assertFalse(cfg.getContext().getPropertySources().contains(def));
+ cfg.getContext().addPropertySources(def);
+ assertTrue(cfg.getContext().getPropertySources().contains(def));
+ }
+
+ @Test
+ public void testToString() throws Exception {
+ String toString = ConfigurationProvider.getConfiguration().getContext().toString();
+ }
+
+ @Test
+ public void getPropertySources() throws Exception {
+ Configuration cfg = new CoreConfigurationBuilder().build();
+ assertNotNull(cfg.getContext().getPropertySources());
+ assertEquals(cfg.getContext().getPropertySources().size(), 0);
+ cfg = new CoreConfigurationBuilder().addDefaultPropertySources().build();
+ assertNotNull(cfg.getContext().getPropertySources());
+ assertEquals(7, cfg.getContext().getPropertySources().size());
+ }
+
+ @Test
+ public void getPropertySource() throws Exception {
+ TestPropertyDefaultSource ps = new TestPropertyDefaultSource();
+ Configuration cfg = new CoreConfigurationBuilder()
+ .addPropertySources(ps).build();
+ assertNotNull(cfg.getContext().getPropertySources());
+ assertEquals(cfg.getContext().getPropertySources().size(), 1);
+ assertNotNull((cfg.getContext()).getPropertySource(ps.getName()));
+ assertEquals(ps.getName(), cfg.getContext().getPropertySource(ps.getName()).getName());
+ assertNull(cfg.getContext().getPropertySource("huhu"));
+
+ }
+
+ @Test
+ public void testHashCode() throws Exception {
+ TestPropertyDefaultSource ps = new TestPropertyDefaultSource();
+ Configuration cfg1 = new CoreConfigurationBuilder()
+ .addPropertySources(ps).build();
+ Configuration cfg2 = new CoreConfigurationBuilder()
+ .addPropertySources(ps).build();
+ assertEquals(cfg1.hashCode(), cfg2.hashCode());
+ cfg2 = new CoreConfigurationBuilder()
+ .build();
+ assertNotEquals(cfg1.hashCode(), cfg2.hashCode());
+
+ }
+
+ @Test
+ public void addPropertyConverter() throws Exception {
+ Configuration cfg = new CoreConfigurationBuilder().build();
+ PropertyConverter testConverter = new PropertyConverter() {
+ @Override
+ public Object convert(String value, ConversionContext context) {
+ return "";
+ }
+ };
+ assertFalse(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter));
+ cfg.getContext().addPropertyConverter(TypeLiteral.of(String.class), testConverter);
+ assertTrue(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter));
+ }
+
+ @Test
+ public void getPropertyConverters() throws Exception {
+ Configuration cfg = new CoreConfigurationBuilder().build();
+ PropertyConverter testConverter = new PropertyConverter() {
+ @Override
+ public Object convert(String value, ConversionContext context) {
+ return "";
+ }
+ };
+ cfg.getContext().addPropertyConverter(TypeLiteral.of(String.class), testConverter);
+ assertNotNull(cfg.getContext().getPropertyConverters());
+ assertTrue(cfg.getContext().getPropertyConverters().containsKey(TypeLiteral.of(String.class)));
+ assertTrue(cfg.getContext().getPropertyConverters().get(TypeLiteral.of(String.class)).contains(testConverter));
+ testConverter = new PropertyConverter() {
+ @Override
+ public Object convert(String value, ConversionContext context) {
+ return Integer.valueOf(5);
+ }
+ };
+ cfg.getContext().addPropertyConverter(TypeLiteral.of(Integer.class), testConverter);
+ assertTrue(cfg.getContext().getPropertyConverters().containsKey(TypeLiteral.of(Integer.class)));
+ assertTrue(cfg.getContext().getPropertyConverters().get(TypeLiteral.of(Integer.class)).contains(testConverter));
+ }
+
+ @Test
+ public void getPropertyConverters1() throws Exception {
+ Configuration cfg = new CoreConfigurationBuilder().build();
+ PropertyConverter testConverter = new PropertyConverter() {
+ @Override
+ public Object convert(String value, ConversionContext context) {
+ return "";
+ }
+ };
+ assertNotNull(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class)));
+ assertEquals(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class)).size(),0);
+ cfg.getContext().addPropertyConverter(TypeLiteral.of(String.class), testConverter);
+ assertNotNull(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class)));
+ assertEquals(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class)).size(),1);
+ assertTrue(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter));
+
+ }
+
+ @Test
+ public void getPropertyFilters() throws Exception {
+ Configuration cfg = new CoreConfigurationBuilder().build();
+ PropertyFilter testFilter = new PropertyFilter() {
+
+ @Override
+ public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
+ return value;
+ }
+ };
+ assertNotNull(cfg.getContext().getPropertyFilters());
+ assertFalse(cfg.getContext().getPropertyFilters().contains(testFilter));
+ cfg = cfg.toBuilder().addPropertyFilters(testFilter).build();
+ assertTrue(cfg.getContext().getPropertyFilters().contains(testFilter));
+ }
+
+ @Test
+ public void getPropertyValueCombinationPolicy() throws Exception {
+ Configuration cfg = new CoreConfigurationBuilder().build();
+ assertNotNull(cfg.getContext().getPropertyValueCombinationPolicy());
+ assertEquals(cfg.getContext().getPropertyValueCombinationPolicy(),
+ PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_POLICY);
+ }
+
+ @Test
+ public void toBuilder() throws Exception {
+ assertNotNull(new CoreConfigurationBuilder().build().toBuilder());
+ }
+
+ @Test
+ public void testRoundTrip() throws Exception {
+ Configuration cfg = new CoreConfigurationBuilder().build();
+ assertEquals(cfg.toBuilder().build(), cfg);
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/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
deleted file mode 100644
index 9ba3c80..0000000
--- a/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultConfigurationProviderTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Created by atsticks on 11.09.16.
- */
-public class DefaultConfigurationProviderTest {
-
- @Test
- public void testInstantiation() throws Exception {
- new DefaultConfigurationProvider();
- }
-
- @Test
- public void getConfiguration() throws Exception {
- assertNotNull(new DefaultConfigurationProvider().getConfiguration());
- }
-
- @Test
- public void createConfiguration() throws Exception {
- ConfigurationContext ctx = new CoreConfigurationContextBuilder().build();
- assertNotNull(new DefaultConfigurationProvider().createConfiguration(ctx));
- assertEquals(ctx,
- new DefaultConfigurationProvider().createConfiguration(ctx).getContext());
- }
-
- @Test
- public void getConfigurationContext() throws Exception {
- assertNotNull(new DefaultConfigurationProvider().getConfiguration().getContext());
- }
-
- @Test
- public void getConfigurationContextBuilder() throws Exception {
- assertNotNull(new DefaultConfigurationProvider().getConfigurationContextBuilder());
- }
-
- @SuppressWarnings("deprecation")
- @Test
- public void setConfigurationContext() throws Exception {
- new DefaultConfigurationProvider()
- .setConfigurationContext(new DefaultConfigurationProvider().getConfiguration().getContext());
- }
-
- @SuppressWarnings("deprecation")
- @Test
- public void isConfigurationContextSettable() throws Exception {
- assertTrue(new DefaultConfigurationProvider().isConfigurationContextSettable());
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
----------------------------------------------------------------------
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
deleted file mode 100644
index 13b2eb6..0000000
--- a/code/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
+++ /dev/null
@@ -1,138 +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.ConfigException;
-import org.apache.tamaya.spi.ConfigurationProviderSpi;
-import org.junit.Assert;
-import org.junit.Test;
-
-import javax.annotation.Priority;
-import java.util.Collection;
-import java.util.List;
-
-public class DefaultServiceContextTest {
-
- /**
- * context to test
- */
- private final DefaultServiceContext context = new DefaultServiceContext();
-
-
- @Test
- public void testGetService() {
- ConfigurationProviderSpi providerSpi = context.getService(ConfigurationProviderSpi.class);
- Assert.assertNotNull(providerSpi);
- Assert.assertTrue(providerSpi instanceof DefaultConfigurationProvider);
- }
-
- @Test(expected = ConfigException.class)
- public void testGetService_multipleServicesWithoutPriority_shouldThrowConfigException() {
- context.getService(InvalidPriorityInterface.class);
- }
-
- @Test
- public void testGetService_multipleService_shouldReturnServiceWithHighestPriority() {
- MultiImplsInterface service = context.getService(MultiImplsInterface.class);
-
- Assert.assertNotNull(service);
- Assert.assertTrue(service instanceof MultiImpl2);
- }
-
- @Test
- public void testGetService_noImpl_shouldReturnEmptyOpional() {
- NoImplInterface service = context.getService(NoImplInterface.class);
- Assert.assertNull(service);
- }
-
-
- @Test
- public void testGetServices_shouldReturnServices() {
- {
- Collection<InvalidPriorityInterface> services = context.getServices(InvalidPriorityInterface.class);
- Assert.assertNotNull(services);
- Assert.assertEquals(2, services.size());
-
- for (InvalidPriorityInterface service : services) {
- Assert.assertTrue(service instanceof InvalidPriorityImpl1 || service instanceof InvalidPriorityImpl2);
- }
- }
-
- {
- List<MultiImplsInterface> services = context.getServices(MultiImplsInterface.class);
- Assert.assertNotNull(services);
- Assert.assertEquals(3, services.size());
-
- Assert.assertTrue(services.get(0) instanceof MultiImpl2);
- Assert.assertTrue(services.get(1) instanceof MultiImpl1);
- Assert.assertTrue(services.get(2) instanceof MultiImpl3);
- }
- }
-
- @Test
- public void testGetServices_redundantAccessToServices() {
- for(int i=0;i<10;i++){
- Collection<InvalidPriorityInterface> services = context.getServices(InvalidPriorityInterface.class);
- Assert.assertNotNull(services);
- Assert.assertEquals(2, services.size());
- for (InvalidPriorityInterface service : services) {
- Assert.assertTrue(service instanceof InvalidPriorityImpl1 || service instanceof InvalidPriorityImpl2);
- }
- }
- }
-
- @Test
- public void testGetServices_noImpl_shouldReturnEmptyList() {
- Collection<NoImplInterface> services = context.getServices(NoImplInterface.class);
- Assert.assertNotNull(services);
- Assert.assertTrue(services.isEmpty());
- }
-
-
- // some test interfaces and classes
-
- public interface InvalidPriorityInterface {
- }
-
- @Priority(value = 50)
- public static class InvalidPriorityImpl1 implements InvalidPriorityInterface {
- }
-
- @Priority(value = 50)
- public static class InvalidPriorityImpl2 implements InvalidPriorityInterface {
- }
-
-
- public interface MultiImplsInterface {
- }
-
- public static class MultiImpl1 implements MultiImplsInterface {
- }
-
- @Priority(value = 500)
- public static class MultiImpl2 implements MultiImplsInterface {
- }
-
- @Priority(value = -10)
- public static class MultiImpl3 implements MultiImplsInterface {
- }
-
- private interface NoImplInterface {
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface
----------------------------------------------------------------------
diff --git a/code/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface b/code/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface
deleted file mode 100644
index f203fa6..0000000
--- a/code/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface
+++ /dev/null
@@ -1,18 +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.
-org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityImpl1
-org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityImpl2
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImplsInterface
----------------------------------------------------------------------
diff --git a/code/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImplsInterface b/code/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImplsInterface
deleted file mode 100644
index b144790..0000000
--- a/code/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImplsInterface
+++ /dev/null
@@ -1,20 +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.
-
-org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImpl1
-org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImpl2
-org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImpl3
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi b/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
new file mode 100644
index 0000000..968be8f
--- /dev/null
+++ b/code/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
@@ -0,0 +1,18 @@
+# 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.
+
+org.apache.tamaya.core.internal.CoreConfigurationProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
index 4376a9a..fbcf35f 100644
--- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
+++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
@@ -124,7 +124,6 @@ public class DefaultConfiguration implements Configuration {
@Override
public String getOrDefault(String key, String defaultValue) {
Objects.requireNonNull(key, "Key must not be null.");
- Objects.requireNonNull(defaultValue, "Default value must not be null");
String val = get(key);
if(val==null){
@@ -258,6 +257,24 @@ public class DefaultConfiguration implements Configuration {
}
@Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ DefaultConfiguration that = (DefaultConfiguration) o;
+
+ if (!configurationContext.equals(that.configurationContext)) return false;
+ return configEvaluator.getClass().equals(that.configEvaluator.getClass());
+ }
+
+ @Override
+ public int hashCode() {
+ int result = configurationContext.hashCode();
+ result = 31 * result + configEvaluator.getClass().hashCode();
+ return result;
+ }
+
+ @Override
public String toString() {
return "Configuration{\n " +
configurationContext +
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java
index f1c0f46..ec26ba6 100644
--- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java
+++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java
@@ -21,21 +21,29 @@ package org.apache.tamaya.spisupport;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.spi.*;
+import org.apache.tamaya.spi.ConfigurationBuilder;
import java.util.*;
/**
- * Default implementation of {@link ConfigurationContextBuilder}.
+ * Default implementation of {@link ConfigurationBuilder}.
*/
public class DefaultConfigurationBuilder implements ConfigurationBuilder {
- private final ConfigurationContextBuilder contextBuilder;
+ protected final DefaultConfigurationContextBuilder contextBuilder;
/**
* Creates a new builder instance.
*/
- public DefaultConfigurationBuilder(ConfigurationContextBuilder contextBuilder) {
- this.contextBuilder = Objects.requireNonNull(contextBuilder);
+ public DefaultConfigurationBuilder() {
+ this.contextBuilder = new DefaultConfigurationContextBuilder();
+ }
+
+ /**
+ * Creates a new builder instance.
+ */
+ public DefaultConfigurationBuilder(ConfigurationContext context) {
+ this.contextBuilder = new DefaultConfigurationContextBuilder(context);
}
/**
@@ -43,13 +51,13 @@ public class DefaultConfigurationBuilder implements ConfigurationBuilder {
* @param configuration the configuration to be used, not null.
*/
public DefaultConfigurationBuilder(Configuration configuration) {
- this.contextBuilder = configuration.getContext().toBuilder();
+ this.contextBuilder = new DefaultConfigurationContextBuilder(configuration.getContext());
}
/**
* Allows to set configuration context during unit tests.
*/
- ConfigurationBuilder setConfiguration(Configuration configuration) {
+ public ConfigurationBuilder setConfiguration(Configuration configuration) {
this.contextBuilder.setContext(configuration.getContext());
return this;
}
@@ -181,7 +189,6 @@ public class DefaultConfigurationBuilder implements ConfigurationBuilder {
return this;
}
-
@Override
public <T> ConfigurationBuilder addPropertyConverters(TypeLiteral<T> type, PropertyConverter<T>... propertyConverters){
this.contextBuilder.addPropertyConverters(type, propertyConverters);
[3/6] incubator-tamaya git commit: TAMAYA-321 Add
ConfigurationBuilder to core API.
Posted by an...@apache.org.
TAMAYA-321 Add ConfigurationBuilder to core API.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/15f7cbbb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/15f7cbbb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/15f7cbbb
Branch: refs/heads/master
Commit: 15f7cbbb3ffac1e4cd2d2de0aabbb380fbc0b378
Parents: f255aa9
Author: Anatole Tresch <an...@apache.org>
Authored: Sun Nov 26 17:14:21 2017 +0100
Committer: Anatole Tresch <an...@apache.org>
Committed: Sun Nov 26 17:14:21 2017 +0100
----------------------------------------------------------------------
.../java/org/apache/tamaya/Configuration.java | 26 +-
.../apache/tamaya/ConfigurationProvider.java | 25 +-
.../apache/tamaya/spi/ConfigurationBuilder.java | 347 +++++++++++++++
.../apache/tamaya/spi/ConfigurationContext.java | 10 +-
.../tamaya/spi/ConfigurationContextBuilder.java | 17 +-
.../tamaya/spi/ConfigurationProviderSpi.java | 13 +-
.../apache/tamaya/spi/ConversionContext.java | 6 +-
.../tamaya/TestConfigurationProvider.java | 6 +
.../org/apache/tamaya/core/OSGIActivator.java | 5 +-
.../core/internal/ConfigValueEvaluator.java | 47 --
.../tamaya/core/internal/CoreConfiguration.java | 43 ++
.../core/internal/CoreConfigurationBuilder.java | 91 ++++
.../core/internal/CoreConfigurationContext.java | 52 ---
.../CoreConfigurationContextBuilder.java | 93 ----
.../internal/CoreConfigurationProvider.java | 101 +++++
.../internal/DefaultConfigurationProvider.java | 106 -----
.../core/internal/DefaultServiceContext.java | 205 ---------
.../core/internal/OSGIServiceContext.java | 2 +-
.../org.apache.tamaya.spi.ConfigurationBuilder | 19 +
...pache.tamaya.spi.ConfigurationContextBuilder | 19 -
...g.apache.tamaya.spi.ConfigurationProviderSpi | 2 +-
.../org.apache.tamaya.spi.ServiceContext | 2 +-
.../tamaya/core/ConfigurationBuilderTest.java | 440 +++++++++++++++++++
.../core/ConfigurationContextBuilderTest.java | 8 +-
.../internal/CoreConfigurationBuilderTest.java | 219 +++++++++
.../CoreConfigurationContextBuilderTest.java | 200 ---------
.../internal/CoreConfigurationContextTest.java | 176 --------
.../internal/CoreConfigurationProviderTest.java | 93 ++++
.../core/internal/CoreConfigurationTest.java | 177 ++++++++
.../DefaultConfigurationProviderTest.java | 72 ---
.../internal/DefaultServiceContextTest.java | 138 ------
...tServiceContextTest$InvalidPriorityInterface | 18 -
...efaultServiceContextTest$MultiImplsInterface | 20 -
...g.apache.tamaya.spi.ConfigurationProviderSpi | 18 +
.../tamaya/spisupport/DefaultConfiguration.java | 19 +-
.../spisupport/DefaultConfigurationBuilder.java | 21 +-
.../DefaultConfigurationBuilderTest.java | 220 ++++++++++
.../spisupport/DefaultServiceContextTest.java | 138 ++++++
.../spisupport/TestConfigurationProvider.java | 92 ++++
...g.apache.tamaya.spi.ConfigurationProviderSpi | 18 +
...tServiceContextTest$InvalidPriorityInterface | 18 +
...efaultServiceContextTest$MultiImplsInterface | 20 +
jqassistant/serviceloader-rules.xml | 6 +-
43 files changed, 2174 insertions(+), 1194 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/Configuration.java b/code/api/src/main/java/org/apache/tamaya/Configuration.java
index 67aad7b..401eac7 100644
--- a/code/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/code/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -18,6 +18,7 @@
*/
package org.apache.tamaya;
+import org.apache.tamaya.spi.ConfigurationBuilder;
import org.apache.tamaya.spi.ConfigurationContext;
import java.util.Map;
@@ -53,7 +54,9 @@ public interface Configuration {
* @param key the property's key, not {@code null}.
* @return the property's value.
*/
- String get(String key);
+ default String get(String key){
+ return get(key, TypeLiteral.of(String.class));
+ }
/**
* Access a property.
@@ -62,7 +65,9 @@ public interface Configuration {
* @param defaultValue value to be returned, if no value is present, not {@code null}
* @return the property's keys.
*/
- String getOrDefault(String key, String defaultValue);
+ default String getOrDefault(String key, String defaultValue){
+ return getOrDefault(key, TypeLiteral.of(String.class), defaultValue);
+ }
/**
* Get the property keys as type T. This will implicitly require a corresponding {@link
@@ -77,7 +82,9 @@ public interface Configuration {
* @return the property value, never {@code null}.
* @throws ConfigException if the keys could not be converted to the required target type.
*/
- <T> T getOrDefault(String key, Class<T> type, T defaultValue);
+ default <T> T getOrDefault(String key, Class<T> type, T defaultValue){
+ return getOrDefault(key, TypeLiteral.of(type), defaultValue);
+ }
/**
* Get the property keys as type T. This will implicitly require a corresponding {@link
@@ -91,7 +98,9 @@ public interface Configuration {
* @return the property value, never {@code null}.
* @throws ConfigException if the keys could not be converted to the required target type.
*/
- <T> T get(String key, Class<T> type);
+ default <T> T get(String key, Class<T> type){
+ return get(key, TypeLiteral.of(type));
+ }
/**
* Get the property keys as type T. This will implicitly require a corresponding {@link
@@ -159,4 +168,13 @@ public interface Configuration {
*/
ConfigurationContext getContext();
+ /**
+ * Create a new builder using this instance as it's base.
+ * @return a new builder, never null.
+ */
+ default ConfigurationBuilder toBuilder() {
+ return ConfigurationProvider.getConfigurationBuilder().setConfiguration(this);
+ }
+
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java b/code/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
index 564d5a1..bacb944 100644
--- a/code/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
+++ b/code/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
@@ -18,10 +18,7 @@
*/
package org.apache.tamaya;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-import org.apache.tamaya.spi.ConfigurationProviderSpi;
-import org.apache.tamaya.spi.ServiceContextManager;
+import org.apache.tamaya.spi.*;
import java.util.logging.Logger;
@@ -109,17 +106,33 @@ public final class ConfigurationProvider {
}
/**
- * Create a new {@link org.apache.tamaya.spi.ConfigurationContextBuilder} instance. This method creates
+ * Create a new {@link ConfigurationBuilder} instance. This method creates
* a new builder instance that is not related to any concrete {@link org.apache.tamaya.spi.ConfigurationContext}.
* You can use {@link #setConfigurationContext(org.apache.tamaya.spi.ConfigurationContext)} to change the
* current configuration context.
*
- * @return a new, empty {@link org.apache.tamaya.spi.ConfigurationContextBuilder}, never null.
+ * @return a new, empty {@link ConfigurationBuilder}, never null.
* @see #setConfigurationContext(org.apache.tamaya.spi.ConfigurationContext)
* @see org.apache.tamaya.spi.ConfigurationContext
+ * @deprecated Will be removed.
*/
+ @Deprecated
public static ConfigurationContextBuilder getConfigurationContextBuilder() {
return spi().getConfigurationContextBuilder();
}
+ /**
+ * Create a new {@link ConfigurationBuilder} instance. This method creates
+ * a new builder instance that is not related to any concrete {@link org.apache.tamaya.spi.ConfigurationContext}.
+ * You can use {@link #setConfigurationContext(org.apache.tamaya.spi.ConfigurationContext)} to change the
+ * current configuration context.
+ *
+ * @return a new, empty {@link ConfigurationBuilder}, never null.
+ * @see #setConfigurationContext(org.apache.tamaya.spi.ConfigurationContext)
+ * @see org.apache.tamaya.spi.ConfigurationContext
+ */
+ public static ConfigurationBuilder getConfigurationBuilder() {
+ return spi().getConfigurationBuilder();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationBuilder.java b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationBuilder.java
new file mode 100644
index 0000000..c9afa0f
--- /dev/null
+++ b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationBuilder.java
@@ -0,0 +1,347 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spi;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.TypeLiteral;
+
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A builder for creating new or adapting instances of {@link ConfigurationContext}.
+ * Builders can be obtained in exactly two ways:
+ * <ol>
+ * <li>By accessing a preinitialized builder from an existing {@link ConfigurationContext},
+ * by calling {@link org.apache.tamaya.spi.ConfigurationContext#toBuilder()}.</li>
+ * <li>By accessing an empty builder instance from
+ * {@link org.apache.tamaya.ConfigurationProvider#getConfigurationContextBuilder()}.</li>
+ * </ol>
+ * After all changes are applied to a builder a new {@link ConfigurationContext} instance can
+ * be created and can be applied by calling
+ * {@link org.apache.tamaya.ConfigurationProvider#setConfigurationContext(org.apache.tamaya.spi.ConfigurationContext)}.
+ *
+ */
+public interface ConfigurationBuilder {
+
+ /**
+ * Init this builder instance with the given {@link Configuration} instance. This
+ * method will use any existing property sources, filters, converters and the combination
+ * policy of the given {@link Configuration} and initialize the current builder
+ * with them.
+ *
+ * @param config the {@link Configuration} instance to be used, not {@code null}.
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder setConfiguration(Configuration config);
+
+ /**
+ * Init this builder instance with the given {@link ConfigurationContext} instance. This
+ * method will use any existing property sources, filters, converters and the combination
+ * policy of the given {@link ConfigurationContext} and initialize the current builder
+ * with them.
+ *
+ * @param context the {@link ConfigurationContext} instance to be used, not {@code null}.
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder setContext(ConfigurationContext context);
+
+ /**
+ * This method can be used for adding {@link PropertySource}s.
+ * Hereby the property source is added to the tail of property sources with
+ * lowest priority regardless of its current ordinal value. To sort the property
+ * sources based on their ordinals call {@link #sortPropertySources}.
+ *
+ * @param propertySources the PropertySources to add
+ * @return this builder, for chaining, never null.
+ * @throws IllegalArgumentException If a property source with a given name already
+ * exists.
+ */
+ ConfigurationBuilder addPropertySources(PropertySource... propertySources);
+
+ /**
+ * This method can be used for programmatically adding {@link PropertySource}s.
+ * Hereby the property source is added to the tail of property sources with
+ * lowest priority regardless of its current ordinal value. To sort the property
+ * sources based on their ordinals call {@link #sortPropertySources}.
+ *
+ * @param propertySources the PropertySources to add
+ * @return this builder, for chaining, never null.
+ * @throws IllegalArgumentException If a property source with a given name already
+ * exists.
+ */
+ ConfigurationBuilder addPropertySources(Collection<PropertySource> propertySources);
+
+ /**
+ * Add all registered (default) property sources to the context built. The sources are ordered
+ * based on their ordinal values and added to the chain of property sources with
+ * higher priority.
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder addDefaultPropertySources();
+
+ /**
+ * Removes the given property sources, if existing. The existing order of property
+ * sources is preserved.
+ *
+ * @param propertySources the property sources to remove, not {@code null}.
+ * @return the builder for chaining.
+ */
+ ConfigurationBuilder removePropertySources(PropertySource... propertySources);
+
+ /**
+ * Removes the given property sources, if existing. The existing order of property
+ * sources is preserved.
+ *
+ * @param propertySources the property sources to remove, not {@code null}.
+ * @return the builder for chaining.
+ */
+ ConfigurationBuilder removePropertySources(Collection<PropertySource> propertySources);
+
+ /**
+ * Access the current chain of property sources. Items at the end of the list have
+ * precedence/more significance.
+ *
+ * @return the property source chain, never {@code null}.
+ */
+ List<PropertySource> getPropertySources();
+
+ /**
+ * Access the current chain of property filters. Items at the end of the list have
+ * precedence/more significance.
+ *
+ * @return the property source chain, never {@code null}.
+ */
+ List<PropertyFilter> getPropertyFilters();
+
+ /**
+ * Access the current registered property converters.
+ *
+ * @return the current registered property converters.
+ */
+ Map<TypeLiteral<?>, Collection<PropertyConverter<?>>> getPropertyConverter();
+
+ /**
+ * Increases the priority of the given property source, by moving it towards the end
+ * of the chain of property sources. If the property source given is already at the end
+ * this method has no effect. This operation does not change any ordinal values.
+ *
+ * @param propertySource the property source to be incresed regarding its significance.
+ * @return the builder for chaining.
+ * @throws IllegalArgumentException If no such property source exists in the current
+ * chain.
+ */
+ ConfigurationBuilder increasePriority(PropertySource propertySource);
+
+ /**
+ * Decreases the priority of the given property source, by moving it towards the start
+ * of the chain of property sources. If the property source given is already the first
+ * this method has no effect. This operation does not change any ordinal values.
+ *
+ * @param propertySource the property source to be decresed regarding its significance.
+ * @return the builder for chaining.
+ * @throws IllegalArgumentException If no such property source exists in the current
+ * chain.
+ */
+ ConfigurationBuilder decreasePriority(PropertySource propertySource);
+
+ /**
+ * Increases the priority of the given property source to be maximal, by moving it to
+ * the tail of the of property source chain. If the property source given is
+ * already the last item this method has no effect. This operation does not change
+ * any ordinal values.
+ *
+ * @param propertySource the property source to be maximized regarding its significance.
+ * @return the builder for chaining.
+ * @throws IllegalArgumentException If no such property source exists in the current
+ * chain.
+ */
+ ConfigurationBuilder highestPriority(PropertySource propertySource);
+
+ /**
+ * Decreases the priority of the given property source to be minimal, by moving it to
+ * the start of the chain of property source chain. If the property source given is
+ * already the first item this method has no effect. This operation does not change
+ * any ordinal values.
+ *
+ * @param propertySource the property source to be minimized regarding its significance.
+ * @return the builder for chaining.
+ * @throws IllegalArgumentException If no such property source exists in the current
+ * chain.
+ */
+ ConfigurationBuilder lowestPriority(PropertySource propertySource);
+
+ /**
+ * Adds the given PropertyFilter instances, hereby the instances are added
+ * to the end of the list with highest priority. The ordering of existing
+ * property filters remains unchanged. To sort the property
+ * filters call {@link #sortPropertyFilter}.
+ *
+ * @param filters the filters to add
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder addPropertyFilters(PropertyFilter... filters);
+
+ /**
+ * Adds the given PropertyFilter instances, hereby the instances are added
+ * to the end of the list with highest priority. The ordering of existing
+ * property filters remains unchanged. To sort the property
+ * filters call {@link #sortPropertyFilter}.
+ *
+ * @param filters the filters to add
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder addPropertyFilters(Collection<PropertyFilter> filters);
+
+ /**
+ * Add all registered (default) property filters to the context built.
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder addDefaultPropertyFilters();
+
+
+ /**
+ * Removes the given PropertyFilter instances, if existing. The order of the remaining
+ * filters is preserved.
+ *
+ * @param filters the filter to remove
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder removePropertyFilters(PropertyFilter... filters);
+
+ /**
+ * Removes the given PropertyFilter instances, if existing. The order of the remaining
+ * filters is preserved.
+ *
+ * @param filters the filter to remove
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder removePropertyFilters(Collection<PropertyFilter> filters);
+
+ /**
+ * This method can be used for adding {@link PropertyConverter}s.
+ * Converters are added at the end after any existing converters.
+ * For converters already registered for the current target type the
+ * method has no effect.
+ *
+ * @param typeToConvert the type for which the converter is for
+ * @param propertyConverters the PropertyConverters to add for this type
+ * @param <T> the target type.
+ * @return this builder, for chaining, never null.
+ */
+ <T> ConfigurationBuilder addPropertyConverters(TypeLiteral<T> typeToConvert,
+ @SuppressWarnings("unchecked") PropertyConverter<T>... propertyConverters);
+
+ /**
+ * This method can be used for adding {@link PropertyConverter}s.
+ * Converters are added at the end after any existing converters.
+ * For converters already registered for the current target type the
+ * method has no effect.
+ *
+ * @param typeToConvert the type for which the converter is for
+ * @param propertyConverters the PropertyConverters to add for this type
+ * @param <T> the target type.
+ * @return this builder, for chaining, never null.
+ */
+ <T> ConfigurationBuilder addPropertyConverters(TypeLiteral<T> typeToConvert,
+ Collection<PropertyConverter<T>> propertyConverters);
+
+ /**
+ * Add all registered (default) property converters to the context built.
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder addDefaultPropertyConverters();
+
+ /**
+ * Removes the given PropertyConverter instances for the given type,
+ * if existing.
+ *
+ * @param typeToConvert the type which the converter is for
+ * @param propertyConverters the converter to remove
+ * @param <T> the target type.
+ * @return this builder, for chaining, never null.
+ */
+ <T> ConfigurationBuilder removePropertyConverters(TypeLiteral<T> typeToConvert,
+ @SuppressWarnings("unchecked") PropertyConverter<T>... propertyConverters);
+
+ /**
+ * Removes the given PropertyConverter instances for the given type,
+ * if existing.
+ *
+ * @param typeToConvert the type which the converter is for
+ * @param propertyConverters the converter to remove
+ * @param <T> the target type.
+ * @return this builder, for chaining, never null.
+ */
+ <T> ConfigurationBuilder removePropertyConverters(TypeLiteral<T> typeToConvert,
+ Collection<PropertyConverter<T>> propertyConverters);
+
+ /**
+ * Removes all converters for the given type, which actually renders a given type
+ * unsupported for type conversion.
+ *
+ * @param typeToConvert the type which the converter is for
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder removePropertyConverters(TypeLiteral<?> typeToConvert);
+
+ /**
+ * Sorts the current registered property sources using the given comparator.
+ *
+ * NOTE: property sources at the beginning have minimal significance.
+ *
+ * @param comparator the comparator to be used, not {@code null}.
+ * @return this instance for chaining.
+ */
+ ConfigurationBuilder sortPropertySources(Comparator<PropertySource> comparator);
+
+ /**
+ * Sorts the current registered property filters using the given comparator.
+ *
+ * NOTE: property filters at the beginning have minimal significance.
+ *
+ * @param comparator the comparator to be used, not {@code null}.
+ * @return this instance for chaining.
+ */
+ ConfigurationBuilder sortPropertyFilter(Comparator<PropertyFilter> comparator);
+
+ /**
+ * Sets the {@link PropertyValueCombinationPolicy} used to evaluate the final
+ * property values.
+ *
+ * @param policy the {@link PropertyValueCombinationPolicy} used, not {@code null}.
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy policy);
+
+ /**
+ * Builds a new {@link ConfigurationContext} based on the data in this builder. The ordering of property
+ * sources and property filters is not changed, regardless of their ordinals. For ensure a certain
+ * ordering/significance call {@link #sortPropertyFilter(Comparator)} and/or {@link #sortPropertySources(Comparator)}
+ * before building the context.
+ *
+ * @return the final context to be used to create a configuration.
+ * @see org.apache.tamaya.ConfigurationProvider#createConfiguration(ConfigurationContext)
+ */
+ Configuration build();
+
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
index c33cf9d..f077a1d 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
@@ -68,7 +68,7 @@ public interface ConfigurationContext {
* It is not needed for normal 'usage' by end users, but only for Extension Developers!
*
* @param <T> the type of the type literal
- * @param type the type which the converter is for
+ * @param type the type which the converters is for
* @param propertyConverter the PropertyConverters to add for this type
* @deprecated Use {@link ConfigurationContextBuilder} to create a new {@link ConfigurationContext}.
* @see #toBuilder()
@@ -139,13 +139,13 @@ public interface ConfigurationContext {
*
* <p>
* The converters returned for a type should be used as a chain, whereas the result of the
- * first converter that is able to convert the configured value, is taken as the chain's result.
- * No more converters are called after a converter has successfully converted the input into
+ * first converters that is able to convert the configured value, is taken as the chain's result.
+ * No more converters are called after a converters has successfully converted the input into
* the required target type.
* </p>
*
* @param <T> the type of the type literal
- * @param type type of the desired converter
+ * @param type type of the desired converters
* @return a sorted list of registered PropertySources per type.
*/
<T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> type);
@@ -166,7 +166,9 @@ public interface ConfigurationContext {
/**
* Creates a {@link ConfigurationContextBuilder} preinitialized with the data from this instance.
* @return a new builder instance, never null.
+ * @deprecated Will be removed.
*/
+ @Deprecated
ConfigurationContextBuilder toBuilder();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationContextBuilder.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationContextBuilder.java b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationContextBuilder.java
index 8aa0d05..17c1bf4 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationContextBuilder.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationContextBuilder.java
@@ -37,8 +37,9 @@ import java.util.Map;
* After all changes are applied to a builder a new {@link ConfigurationContext} instance can
* be created and can be applied by calling
* {@link org.apache.tamaya.ConfigurationProvider#setConfigurationContext(org.apache.tamaya.spi.ConfigurationContext)}.
- *
+ * @deprecated Use {@link ConfigurationBuilder} instead.
*/
+@Deprecated
public interface ConfigurationContextBuilder {
/**
@@ -230,7 +231,7 @@ public interface ConfigurationContextBuilder {
* For converters already registered for the current target type the
* method has no effect.
*
- * @param typeToConvert the type for which the converter is for
+ * @param typeToConvert the type for which the converters is for
* @param propertyConverters the PropertyConverters to add for this type
* @param <T> the target type.
* @return this builder, for chaining, never null.
@@ -244,7 +245,7 @@ public interface ConfigurationContextBuilder {
* For converters already registered for the current target type the
* method has no effect.
*
- * @param typeToConvert the type for which the converter is for
+ * @param typeToConvert the type for which the converters is for
* @param propertyConverters the PropertyConverters to add for this type
* @param <T> the target type.
* @return this builder, for chaining, never null.
@@ -262,8 +263,8 @@ public interface ConfigurationContextBuilder {
* Removes the given PropertyConverter instances for the given type,
* if existing.
*
- * @param typeToConvert the type which the converter is for
- * @param propertyConverters the converter to remove
+ * @param typeToConvert the type which the converters is for
+ * @param propertyConverters the converters to remove
* @param <T> the target type.
* @return this builder, for chaining, never null.
*/
@@ -274,8 +275,8 @@ public interface ConfigurationContextBuilder {
* Removes the given PropertyConverter instances for the given type,
* if existing.
*
- * @param typeToConvert the type which the converter is for
- * @param propertyConverters the converter to remove
+ * @param typeToConvert the type which the converters is for
+ * @param propertyConverters the converters to remove
* @param <T> the target type.
* @return this builder, for chaining, never null.
*/
@@ -286,7 +287,7 @@ public interface ConfigurationContextBuilder {
* Removes all converters for the given type, which actually renders a given type
* unsupported for type conversion.
*
- * @param typeToConvert the type which the converter is for
+ * @param typeToConvert the type which the converters is for
* @return this builder, for chaining, never null.
*/
ConfigurationContextBuilder removePropertyConverters(TypeLiteral<?> typeToConvert);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
index b69bef6..fb93ab4 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationProviderSpi.java
@@ -48,10 +48,19 @@ public interface ConfigurationProviderSpi {
* Creates a new {@link org.apache.tamaya.spi.ConfigurationContextBuilder} instance.
*
* @return a new {@link org.apache.tamaya.spi.ConfigurationContextBuilder}, never null.
+ * @deprecated Will be removed
*/
+ @Deprecated
ConfigurationContextBuilder getConfigurationContextBuilder();
/**
+ * Creates a new {@link org.apache.tamaya.spi.ConfigurationBuilder} instance.
+ *
+ * @return a new {@link org.apache.tamaya.spi.ConfigurationBuilder}, never null.
+ */
+ ConfigurationBuilder getConfigurationBuilder();
+
+ /**
* This method allows to replace the current {@link org.apache.tamaya.Configuration} with a new
* instance. This can be used to update the configuration with a new one, e.g. because some of the
* data has changed and must be updated. It is the responsibility of the ConfigurationProvider to trigger
@@ -70,7 +79,9 @@ public interface ConfigurationProviderSpi {
* by the current implementation.
* @see #setConfiguration(org.apache.tamaya.Configuration)
*/
- boolean isConfigurationSettable();
+ default boolean isConfigurationSettable(){
+ return true;
+ }
/**
* Get access to the current {@link ConfigurationContext}.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/api/src/main/java/org/apache/tamaya/spi/ConversionContext.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/ConversionContext.java b/code/api/src/main/java/org/apache/tamaya/spi/ConversionContext.java
index e039cf2..ac8de68 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/ConversionContext.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/ConversionContext.java
@@ -93,7 +93,7 @@ public class ConversionContext {
* Allows to add information on the supported/tried formats, which can be shown to the user, especially when
* conversion failed. Adding of formats is synchronized, all formats are added in order to the overall list.
* This means formats should be passed in order of precedence.
- * @param converterType the converter, which implements the formats provided.
+ * @param converterType the converters, which implements the formats provided.
* @param formatDescriptors the format descriptions in a human readable form, e.g. as regular expressions.
*/
public void addSupportedFormats(@SuppressWarnings("rawtypes") Class<? extends PropertyConverter> converterType, String... formatDescriptors){
@@ -230,9 +230,9 @@ public class ConversionContext {
}
/**
- * Add the formats provided by a {@link PropertyConverter}. This method should be called by each converter
+ * Add the formats provided by a {@link PropertyConverter}. This method should be called by each converters
* performing/trying conversion, so the user can be given feedback on the supported formats on failure.
- * @param converterType the converter type, not {@code null}.
+ * @param converterType the converters type, not {@code null}.
* @param formatDescriptors the formats supported in a human readable form, e.g. as regular expressions.
* @return the builder instance, for chaining
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/code/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java b/code/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
index eaef108..1ccce31 100644
--- a/code/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
+++ b/code/api/src/test/java/org/apache/tamaya/TestConfigurationProvider.java
@@ -21,6 +21,7 @@ package org.apache.tamaya;
import javax.annotation.Priority;
import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationBuilder;
import org.apache.tamaya.spi.ConfigurationContextBuilder;
import org.apache.tamaya.spi.ConfigurationProviderSpi;
@@ -58,6 +59,11 @@ public class TestConfigurationProvider implements ConfigurationProviderSpi {
}
@Override
+ public ConfigurationBuilder getConfigurationBuilder() {
+ return null;
+ }
+
+ @Override
public ConfigurationContextBuilder getConfigurationContextBuilder() {
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/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 3ddaf69..2ca51db 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,6 @@ 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.CoreConfigurationContextBuilder;
import org.apache.tamaya.spisupport.PropertyFilterComparator;
import org.apache.tamaya.spisupport.PropertySourceComparator;
import org.osgi.framework.BundleActivator;
@@ -49,15 +48,13 @@ public class OSGIActivator implements BundleActivator {
ServiceContextManager.set(new OSGIServiceContext(serviceLoader));
LOG.info("Registered Tamaya OSGI ServiceContext...");
ConfigurationProvider.setConfiguration(
- new DefaultConfiguration(
- new CoreConfigurationContextBuilder()
+ new CoreConfigurationBuilder()
.addDefaultPropertyConverters()
.addDefaultPropertyFilters()
.addDefaultPropertySources()
.sortPropertyFilter(PropertyFilterComparator.getInstance())
.sortPropertySources(PropertySourceComparator.getInstance())
.build()
- )
);
LOG.info("Loaded default configuration from OSGI.");
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/core/src/main/java/org/apache/tamaya/core/internal/ConfigValueEvaluator.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/ConfigValueEvaluator.java b/code/core/src/main/java/org/apache/tamaya/core/internal/ConfigValueEvaluator.java
deleted file mode 100644
index f1c8bf2..0000000
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/ConfigValueEvaluator.java
+++ /dev/null
@@ -1,47 +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.spi.ConfigurationContext;
-import org.apache.tamaya.spi.PropertyValue;
-
-import java.util.Map;
-
-/**
- * Component SPI which encapsulates the evaluation of a single or full <b>raw</b>value
- * for a {@link ConfigurationContext}.
- */
-public interface ConfigValueEvaluator {
-
- /**
- * Evaluates single value using a {@link ConfigurationContext}.
- * @param key the config key, not {@code null}.
- * @param context the context, not {@code null}.
- * @return the value, or null.
- */
- PropertyValue evaluteRawValue(String key, ConfigurationContext context);
-
- /**
- * Evaluates all property values from a {@link ConfigurationContext}.
- * @param context the context, not {@code null}.
- * @return the value, or null.
- */
- Map<String, PropertyValue> evaluateRawValues(ConfigurationContext context);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfiguration.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfiguration.java b/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfiguration.java
new file mode 100644
index 0000000..5363b76
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfiguration.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.spi.ConfigurationBuilder;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spisupport.DefaultConfiguration;
+import org.apache.tamaya.spisupport.DefaultConfigurationContext;
+import org.apache.tamaya.spisupport.DefaultConfigurationContextBuilder;
+
+/**
+ * Default implementation of {@link ConfigurationBuilder}.
+ */
+public final class CoreConfiguration extends DefaultConfiguration {
+
+ /**
+ * Creates a new builder instance.
+ */
+ public CoreConfiguration(ConfigurationContext context) {
+ super(context);
+ }
+
+ @Override
+ public ConfigurationBuilder toBuilder() {
+ return new CoreConfigurationBuilder(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationBuilder.java b/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationBuilder.java
new file mode 100644
index 0000000..4daacdf
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationBuilder.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationBuilder;
+import org.apache.tamaya.core.internal.converters.*;
+import org.apache.tamaya.spisupport.DefaultConfigurationBuilder;
+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.*;
+
+/**
+ * Default implementation of {@link ConfigurationBuilder}.
+ */
+public final class CoreConfigurationBuilder extends DefaultConfigurationBuilder {
+
+ /**
+ * Creates a new builder instance.
+ */
+ public CoreConfigurationBuilder() {
+ super();
+ }
+
+ /**
+ * Creates a new builder instance.
+ */
+ public CoreConfigurationBuilder(Configuration config) {
+ super(config);
+ }
+
+ /**
+ * Creates a new builder instance initializing it with the given context.
+ * @param context the context to be used, not null.
+ */
+ public CoreConfigurationBuilder(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 Configuration build() {
+ return new CoreConfiguration(contextBuilder.build());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/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
deleted file mode 100644
index dd31b91..0000000
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationContext.java
+++ /dev/null
@@ -1,52 +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.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/15f7cbbb/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
deleted file mode 100644
index d440a88..0000000
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationContextBuilder.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.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/15f7cbbb/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationProvider.java b/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationProvider.java
new file mode 100644
index 0000000..caf7fbb
--- /dev/null
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationProvider.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationBuilder;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
+import org.apache.tamaya.spi.ConfigurationProviderSpi;
+import org.apache.tamaya.spisupport.DefaultConfiguration;
+import org.apache.tamaya.spisupport.DefaultConfigurationContextBuilder;
+import org.osgi.service.component.annotations.Component;
+
+import java.util.Objects;
+
+/**
+ * Implementation of the Configuration API. This class uses the current {@link org.apache.tamaya.spi.ConfigurationContext} to evaluate the
+ * chain of {@link org.apache.tamaya.spi.PropertySource} and {@link org.apache.tamaya.spi.PropertyFilter}
+ * instance to evaluate the current Configuration.
+ */
+@Component(service = ConfigurationProviderSpi.class)
+public class CoreConfigurationProvider implements ConfigurationProviderSpi {
+
+ private Configuration config = new CoreConfigurationBuilder()
+ .addDefaultPropertyConverters()
+ .addDefaultPropertyFilters()
+ .addDefaultPropertySources()
+ .build();
+ {
+ String bannerConfig = config.getOrDefault("tamaya.banner", "OFF");
+
+ BannerManager bm = new BannerManager(bannerConfig);
+ bm.outputBanner();
+ }
+
+ @Override
+ public Configuration getConfiguration() {
+ return config;
+ }
+
+ @Override
+ public Configuration createConfiguration(ConfigurationContext context) {
+ return new CoreConfiguration(context);
+ }
+
+ @Override
+ public ConfigurationBuilder getConfigurationBuilder() {
+ return new CoreConfigurationBuilder();
+ }
+
+ @Override
+ public ConfigurationContextBuilder getConfigurationContextBuilder() {
+ return new DefaultConfigurationContextBuilder();
+ }
+
+ @Override
+ public void setConfiguration(Configuration config) {
+ Objects.requireNonNull(config.getContext());
+ this.config = Objects.requireNonNull(config);
+ }
+
+ @Override
+ public boolean isConfigurationSettable() {
+ return true;
+ }
+
+ /**
+ * @deprecated use {@link Configuration#getContext()} instead.
+ */
+ @Deprecated
+ @Override
+ public ConfigurationContext getConfigurationContext() {
+ return this.config.getContext();
+ }
+
+ /**
+ * @deprecated the context should be given upon creation of the {@link Configuration}
+ */
+ @Deprecated
+ @Override
+ public void setConfigurationContext(ConfigurationContext context){
+ this.config = new CoreConfigurationBuilder(context).build();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/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
deleted file mode 100644
index f37d4c3..0000000
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationProvider.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-import org.apache.tamaya.spi.ConfigurationProviderSpi;
-import org.apache.tamaya.spisupport.DefaultConfiguration;
-import org.osgi.service.component.annotations.Component;
-
-import java.util.Objects;
-
-/**
- * Implementation of the Configuration API. This class uses the current {@link org.apache.tamaya.spi.ConfigurationContext} to evaluate the
- * chain of {@link org.apache.tamaya.spi.PropertySource} and {@link org.apache.tamaya.spi.PropertyFilter}
- * instance to evaluate the current Configuration.
- */
-@Component(service = ConfigurationProviderSpi.class)
-public class DefaultConfigurationProvider implements ConfigurationProviderSpi {
-
- ConfigurationContext context = new CoreConfigurationContextBuilder()
- .addDefaultPropertyConverters()
- .addDefaultPropertyFilters()
- .addDefaultPropertySources()
- .build();
-
- private Configuration config = new DefaultConfiguration(context);
-
- {
- String bannerConfig = config.getOrDefault("tamaya.banner", "OFF");
-
- BannerManager bm = new BannerManager(bannerConfig);
- bm.outputBanner();
- }
-
- @Override
- public Configuration getConfiguration() {
- return config;
- }
-
- @Override
- public Configuration createConfiguration(ConfigurationContext context) {
- return new DefaultConfiguration(context);
- }
-
- @Override
- public ConfigurationContextBuilder getConfigurationContextBuilder() {
- return new CoreConfigurationContextBuilder();
- }
-
- @Override
- public void setConfiguration(Configuration config) {
- Objects.requireNonNull(config.getContext());
- this.config = Objects.requireNonNull(config);
- this.context = config.getContext();
- }
-
- @Override
- public boolean isConfigurationSettable() {
- return true;
- }
-
- /**
- * @deprecated use {@link Configuration#getContext()} instead.
- */
- @Deprecated
- @Override
- public ConfigurationContext getConfigurationContext() {
- return context;
- }
-
- /**
- * @deprecated the context should be given upon creation of the {@link Configuration}
- */
- @Deprecated
- @Override
- public void setConfigurationContext(ConfigurationContext context){
- this.config = new DefaultConfiguration(context);
- this.context = context;
- }
-
-
- @Deprecated
- @Override
- public boolean isConfigurationContextSettable() {
- return true;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java b/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
deleted file mode 100644
index 372ae2a..0000000
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
+++ /dev/null
@@ -1,205 +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.ConfigException;
-import org.apache.tamaya.spi.ServiceContext;
-import org.apache.tamaya.spisupport.PriorityServiceComparator;
-
-import javax.annotation.Priority;
-import java.io.IOException;
-import java.net.URL;
-import java.text.MessageFormat;
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * This class implements the (default) {@link org.apache.tamaya.spi.ServiceContext} interface and hereby uses the JDK
- * {@link java.util.ServiceLoader} to load the services required.
- */
-public final class DefaultServiceContext implements ServiceContext {
- private static final Logger LOG = Logger.getLogger(DefaultServiceContext.class.getName());
- /**
- * List current services loaded, per class.
- */
- private final ConcurrentHashMap<Class<?>, List<Object>> servicesLoaded = new ConcurrentHashMap<>();
- /**
- * Singletons.
- */
- private final Map<Class<?>, Object> singletons = new ConcurrentHashMap<>();
- @SuppressWarnings("rawtypes")
- private Map<Class, Class> factoryTypes = new ConcurrentHashMap<>();
-
- @Override
- public <T> T getService(Class<T> serviceType) {
- Object cached = singletons.get(serviceType);
- if (cached == null) {
- cached = create(serviceType);
- if(cached!=null) {
- singletons.put(serviceType, cached);
- }
- }
- return serviceType.cast(cached);
- }
-
- @Override
- public <T> T create(Class<T> serviceType) {
- @SuppressWarnings("unchecked")
- Class<? extends T> implType = factoryTypes.get(serviceType);
- if(implType==null) {
- Collection<T> services = getServices(serviceType);
- if (services.isEmpty()) {
- return null;
- } else {
- return getServiceWithHighestPriority(services, serviceType);
- }
- }
- try {
- return implType.newInstance();
- } catch (Exception e) {
- LOG.log(Level.SEVERE, "Failed to create instance of " + implType.getName(), e);
- return null;
- }
- }
-
- /**
- * Loads and registers services.
- *
- * @param <T> the concrete type.
- * @param serviceType The service type.
- * @return the items found, never {@code null}.
- */
- @Override
- public <T> List<T> getServices(final Class<T> serviceType) {
- @SuppressWarnings("unchecked")
- List<T> found = (List<T>) servicesLoaded.get(serviceType);
- if (found != null) {
- return found;
- }
- List<T> services = new ArrayList<>();
- try {
- for (T t : ServiceLoader.load(serviceType)) {
- services.add(t);
- }
- if(services.isEmpty()) {
- for (T t : ServiceLoader.load(serviceType, serviceType.getClassLoader())) {
- services.add(t);
- }
- }
- Collections.sort(services, PriorityServiceComparator.getInstance());
- services = Collections.unmodifiableList(services);
- } catch (ServiceConfigurationError e) {
- LOG.log(Level.WARNING,
- "Error loading services current type " + serviceType, e);
- if(services==null){
- services = Collections.emptyList();
- }
- }
- @SuppressWarnings("unchecked")
- final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>) services));
- return previousServices != null ? previousServices : services;
- }
-
- /**
- * Checks the given instance for a @Priority annotation. If present the annotation's value is evaluated. If no such
- * annotation is present, a default priority of {@code 1} is returned.
- * @param o the instance, not {@code null}.
- * @return a priority, by default 1.
- */
- public static int getPriority(Object o){
- int prio = 1; //X TODO discuss default priority
- Priority priority = o.getClass().getAnnotation(Priority.class);
- if (priority != null) {
- prio = priority.value();
- }
- return prio;
- }
-
- /**
- * @param services to scan
- * @param <T> type of the service
- *
- * @return the service with the highest {@link javax.annotation.Priority#value()}
- *
- * @throws ConfigException if there are multiple service implementations with the maximum priority
- */
- private <T> T getServiceWithHighestPriority(Collection<T> services, Class<T> serviceType) {
- T highestService = null;
- // we do not need the priority stuff if the list contains only one element
- if (services.size() == 1) {
- highestService = services.iterator().next();
- this.factoryTypes.put(serviceType, highestService.getClass());
- return highestService;
- }
-
- Integer highestPriority = null;
- int highestPriorityServiceCount = 0;
-
- for (T service : services) {
- int prio = getPriority(service);
- if (highestPriority == null || highestPriority < prio) {
- highestService = service;
- highestPriorityServiceCount = 1;
- highestPriority = prio;
- } else if (highestPriority == prio) {
- highestPriorityServiceCount++;
- }
- }
-
- if (highestPriorityServiceCount > 1) {
- throw new ConfigException(MessageFormat.format("Found {0} implementations for Service {1} with Priority {2}: {3}",
- highestPriorityServiceCount,
- serviceType.getName(),
- highestPriority,
- services));
- }
- this.factoryTypes.put(serviceType, highestService.getClass());
- return highestService;
- }
-
- @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);
- }
-
- @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);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java
----------------------------------------------------------------------
diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java b/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java
index ddbf692..b7328d9 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceContext.java
@@ -62,7 +62,7 @@ public class OSGIServiceContext implements ServiceContext{
}
if(ConfigurationProviderSpi.class==serviceType){
@SuppressWarnings("unchecked")
- T service = (T)new DefaultConfigurationProvider();
+ T service = (T)new CoreConfigurationProvider();
this.osgiServiceLoader.getBundleContext().registerService(
serviceType.getName(),
service,
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationBuilder
----------------------------------------------------------------------
diff --git a/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationBuilder b/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationBuilder
new file mode 100644
index 0000000..700b2b5
--- /dev/null
+++ b/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationBuilder
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.internal.CoreConfigurationContextBuilder
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/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
deleted file mode 100644
index 700b2b5..0000000
--- a/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContextBuilder
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy current the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-org.apache.tamaya.core.internal.CoreConfigurationContextBuilder
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
----------------------------------------------------------------------
diff --git a/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi b/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
index 7c0e249..c4aa43f 100644
--- a/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
+++ b/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationProviderSpi
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.core.internal.DefaultConfigurationProvider
+org.apache.tamaya.core.internal.CoreConfigurationProvider
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/15f7cbbb/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
----------------------------------------------------------------------
diff --git a/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext b/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
index f8e7e7f..135caa1 100644
--- a/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
+++ b/code/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
@@ -16,4 +16,4 @@
# specific language governing permissions and limitations
# under the License.
#
-org.apache.tamaya.core.internal.DefaultServiceContext
+org.apache.tamaya.spisupport.DefaultServiceContext