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/03/30 15:47:27 UTC
incubator-tamaya-sandbox git commit: TAMAYA-260: Added basic tests
for MP builder spi.
Repository: incubator-tamaya-sandbox
Updated Branches:
refs/heads/master 2852c48e1 -> 5ee4802c7
TAMAYA-260: Added basic tests for MP builder spi.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/5ee4802c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/5ee4802c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/5ee4802c
Branch: refs/heads/master
Commit: 5ee4802c7d0a2170a3c7e0b1ed79ad68ac8d82fd
Parents: 2852c48
Author: anatole <an...@apache.org>
Authored: Thu Mar 30 17:47:15 2017 +0200
Committer: anatole <an...@apache.org>
Committed: Thu Mar 30 17:47:15 2017 +0200
----------------------------------------------------------------------
.../tamaya/microprofile/MicroprofileConfig.java | 4 +-
.../MicroprofileConfigProviderResolver.java | 5 +-
.../microprofile/MicroprofileConfigSource.java | 4 +-
.../MicroprofileConfigSourceProvider.java | 4 +-
.../microprofile/MicroprofileConverter.java | 4 +-
.../microprofile/TamayaConfiguration.java | 4 +-
.../microprofile/TamayaPropertyConverter.java | 4 +-
.../microprofile/TamayaPropertySource.java | 4 +-
.../TamayaPropertySourceProvider.java | 4 +-
.../MicroprofileConfigBuilderTest.java | 101 +++++++++++++++++++
.../MicroprofileConfigProviderResolverTest.java | 75 ++++++++++++++
.../MPSystemPropertiesConfigSource.java | 34 +++++++
...eclipse.microprofile.config.spi.ConfigSource | 19 ++++
13 files changed, 249 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5ee4802c/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfig.java
----------------------------------------------------------------------
diff --git a/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfig.java b/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfig.java
index fa8d7b0..3dc4b34 100644
--- a/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfig.java
+++ b/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfig.java
@@ -29,11 +29,11 @@ import java.util.*;
/**
* Microprofile {@link ConfigSource} implementation that wraps a {@link PropertySource} instance.
*/
-final class MicroprofileConfig implements Config {
+public class MicroprofileConfig implements Config {
private Configuration delegate;
- MicroprofileConfig(Configuration delegate){
+ public MicroprofileConfig(Configuration delegate){
this.delegate = Objects.requireNonNull(delegate);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5ee4802c/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolver.java
----------------------------------------------------------------------
diff --git a/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolver.java b/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolver.java
index f1d336e..c35bd35 100644
--- a/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolver.java
+++ b/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolver.java
@@ -25,6 +25,7 @@ import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Logger;
/**
* Created by atsticks on 23.03.17.
@@ -56,7 +57,9 @@ public class MicroprofileConfigProviderResolver extends ConfigProviderResolver {
@Override
public void registerConfig(Config config, ClassLoader classLoader) {
if(configs.containsKey(classLoader)){
- throw new IllegalArgumentException("Alreadsy a config registered with classloader: " + classLoader);
+ Logger.getLogger(getClass().getName())
+ .warning("Replacing existing config for classloader: " + classLoader);
+// throw new IllegalArgumentException("Already a config registered with classloader: " + classLoader);
}
this.configs.put(classLoader, config);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5ee4802c/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigSource.java
----------------------------------------------------------------------
diff --git a/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigSource.java b/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigSource.java
index fbb02b4..39ca119 100644
--- a/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigSource.java
+++ b/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigSource.java
@@ -29,11 +29,11 @@ import java.util.Objects;
/**
* Microprofile {@link ConfigSource} implementation that wraps a {@link PropertySource} instance.
*/
-final class MicroprofileConfigSource implements ConfigSource{
+public class MicroprofileConfigSource implements ConfigSource{
private PropertySource delegate;
- MicroprofileConfigSource(PropertySource propertySource){
+ public MicroprofileConfigSource(PropertySource propertySource){
this.delegate = Objects.requireNonNull(propertySource);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5ee4802c/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigSourceProvider.java
----------------------------------------------------------------------
diff --git a/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigSourceProvider.java b/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigSourceProvider.java
index c31224f..5176940 100644
--- a/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigSourceProvider.java
+++ b/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigSourceProvider.java
@@ -29,11 +29,11 @@ import java.util.*;
/**
* Microprofile {@link ConfigSource} implementation that wraps a {@link PropertySource} instance.
*/
-final class MicroprofileConfigSourceProvider implements ConfigSourceProvider{
+public class MicroprofileConfigSourceProvider implements ConfigSourceProvider{
private PropertySourceProvider delegate;
- MicroprofileConfigSourceProvider(PropertySourceProvider propertySourceProvider){
+ public MicroprofileConfigSourceProvider(PropertySourceProvider propertySourceProvider){
this.delegate = Objects.requireNonNull(propertySourceProvider);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5ee4802c/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConverter.java
----------------------------------------------------------------------
diff --git a/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConverter.java b/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConverter.java
index 2ee42b7..cb6aab2 100644
--- a/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConverter.java
+++ b/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConverter.java
@@ -30,11 +30,11 @@ import java.util.Objects;
/**
* Property source implementation that wraps a Microprofile {@link ConfigSource} instance.
*/
-final class MicroprofileConverter<T> implements Converter<T> {
+public class MicroprofileConverter<T> implements Converter<T> {
private PropertyConverter<T> delegate;
- MicroprofileConverter(PropertyConverter<T> delegate){
+ public MicroprofileConverter(PropertyConverter<T> delegate){
this.delegate = Objects.requireNonNull(delegate);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5ee4802c/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaConfiguration.java
----------------------------------------------------------------------
diff --git a/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaConfiguration.java b/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaConfiguration.java
index 8fb87cf..72b902b 100644
--- a/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaConfiguration.java
+++ b/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaConfiguration.java
@@ -30,11 +30,11 @@ import java.util.*;
/**
* Created by atsticks on 23.03.17.
*/
-class TamayaConfiguration implements Configuration{
+public class TamayaConfiguration implements Configuration{
private Config delegate;
- TamayaConfiguration(Config config){
+ public TamayaConfiguration(Config config){
this.delegate = Objects.requireNonNull(config);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5ee4802c/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertyConverter.java
----------------------------------------------------------------------
diff --git a/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertyConverter.java b/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertyConverter.java
index 6a33ffb..a83008a 100644
--- a/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertyConverter.java
+++ b/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertyConverter.java
@@ -29,11 +29,11 @@ import java.util.Objects;
/**
* Property source implementation that wraps a Microprofile {@link ConfigSource} instance.
*/
-final class TamayaPropertyConverter<T> implements PropertyConverter<T> {
+public class TamayaPropertyConverter<T> implements PropertyConverter<T> {
private Converter<T> delegate;
- TamayaPropertyConverter(Converter<T> delegate){
+ public TamayaPropertyConverter(Converter<T> delegate){
this.delegate = Objects.requireNonNull(delegate);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5ee4802c/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySource.java
----------------------------------------------------------------------
diff --git a/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySource.java b/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySource.java
index d67db23..a1913e8 100644
--- a/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySource.java
+++ b/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySource.java
@@ -29,11 +29,11 @@ import java.util.Objects;
/**
* Property source implementation that wraps a Microprofile {@link ConfigSource} instance.
*/
-final class TamayaPropertySource implements PropertySource{
+public class TamayaPropertySource implements PropertySource{
private ConfigSource delegate;
- TamayaPropertySource(ConfigSource configSource){
+ public TamayaPropertySource(ConfigSource configSource){
this.delegate = Objects.requireNonNull(configSource);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5ee4802c/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySourceProvider.java b/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySourceProvider.java
index 8e910bb..5b0bcf7 100644
--- a/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySourceProvider.java
+++ b/microprofile/src/main/java/org/apache/tamaya/microprofile/TamayaPropertySourceProvider.java
@@ -29,11 +29,11 @@ import java.util.*;
/**
* Microprofile {@link ConfigSource} implementation that wraps a {@link PropertySource} instance.
*/
-final class TamayaPropertySourceProvider implements PropertySourceProvider{
+public class TamayaPropertySourceProvider implements PropertySourceProvider{
private ConfigSourceProvider delegate;
- TamayaPropertySourceProvider(ConfigSourceProvider configSourceProvider){
+ public TamayaPropertySourceProvider(ConfigSourceProvider configSourceProvider){
this.delegate = Objects.requireNonNull(configSourceProvider);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5ee4802c/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilderTest.java
----------------------------------------------------------------------
diff --git a/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilderTest.java b/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilderTest.java
new file mode 100644
index 0000000..6076d1b
--- /dev/null
+++ b/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilderTest.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.microprofile;
+
+import org.eclipse.microprofile.config.Config;
+import org.eclipse.microprofile.config.spi.ConfigBuilder;
+import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
+import org.eclipse.microprofile.config.spi.ConfigSource;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by atsticks on 24.03.17.
+ */
+public class MicroprofileConfigBuilderTest {
+
+ private ConfigSource testSource = new ConfigSource() {
+ @Override
+ public Map<String, String> getProperties() {
+ Map<String,String> map = new HashMap<>();
+ map.put("timestamp", String.valueOf(System.currentTimeMillis()));
+ return map;
+ }
+
+ @Override
+ public String getValue(String propertyName) {
+ if("timestamp".equals(propertyName)){
+ return String.valueOf(System.currentTimeMillis());
+ }
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ return "test";
+ }
+ };
+
+ @Test
+ public void testBuildEmptyConfig(){
+ ConfigBuilder builder = ConfigProviderResolver.instance().getBuilder();
+ assertNotNull(builder);
+ Config config = builder.build();
+ assertNotNull(config);
+ assertFalse(config.getPropertyNames().iterator().hasNext());
+ assertFalse(config.getConfigSources().iterator().hasNext());
+ }
+
+ @Test
+ public void testBuildConfig(){
+ ConfigBuilder builder = ConfigProviderResolver.instance().getBuilder();
+ assertNotNull(builder);
+ builder.withSources(testSource);
+ Config config = builder.build();
+ assertNotNull(config);
+ assertTrue(config.getPropertyNames().iterator().hasNext());
+ assertTrue(config.getConfigSources().iterator().hasNext());
+ assertNotNull(config.getValue("timestamp", String.class));
+ ConfigSource src = config.getConfigSources().iterator().next();
+ assertNotNull(src);
+ assertEquals(src, testSource);
+ }
+
+ @Test
+ @Ignore
+ public void testBuildDefaultConfig(){
+ ConfigBuilder builder = ConfigProviderResolver.instance().getBuilder();
+ assertNotNull(builder);
+ builder.addDefaultSources();
+ Config config = builder.build();
+ assertNotNull(config);
+ assertTrue(config.getPropertyNames().iterator().hasNext());
+ assertTrue(config.getConfigSources().iterator().hasNext());
+ assertNotNull(config.getValue("java.home", String.class));
+ ConfigSource src = config.getConfigSources().iterator().next();
+ assertNotNull(src);
+ assertEquals(src.getName(), "system-properties");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5ee4802c/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolverTest.java
----------------------------------------------------------------------
diff --git a/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolverTest.java b/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolverTest.java
new file mode 100644
index 0000000..4250dce
--- /dev/null
+++ b/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileConfigProviderResolverTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.microprofile;
+
+import org.eclipse.microprofile.config.Config;
+import org.eclipse.microprofile.config.spi.ConfigBuilder;
+import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
+import org.junit.Test;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by atsticks on 24.03.17.
+ */
+public class MicroprofileConfigProviderResolverTest {
+
+ @Test
+ public void testInstance(){
+ assertNotNull(ConfigProviderResolver.instance());
+ }
+
+ @Test
+ public void testGetBuilder(){
+ assertNotNull(ConfigProviderResolver.instance().getBuilder());
+ }
+
+ @Test
+ public void testGetConfig(){
+ assertNotNull(ConfigProviderResolver.instance().getConfig());
+ }
+
+ @Test
+ public void testGetConfig_CL(){
+ assertNotNull(ConfigProviderResolver.instance().getConfig(ClassLoader.getSystemClassLoader()));
+ }
+
+ @Test
+ public void testRegisterAndReleaseConfig(){
+ ClassLoader cl = new URLClassLoader(new URL[]{});
+ Config emptyConfig = ConfigProviderResolver.instance().getBuilder().build();
+ assertNotNull(emptyConfig);
+ Config cfg = ConfigProviderResolver.instance().getConfig(cl);
+ assertNotNull(cfg);
+ ConfigProviderResolver.instance().registerConfig(emptyConfig, cl);
+ cfg = ConfigProviderResolver.instance().getConfig(cl);
+ assertNotNull(cfg);
+ assertEquals(cfg, emptyConfig);
+ ConfigProviderResolver.instance().releaseConfig(emptyConfig);
+ cfg = ConfigProviderResolver.instance().getConfig(cl);
+ assertNotNull(cfg);
+ assertNotSame(cfg, emptyConfig);
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5ee4802c/microprofile/src/test/java/org/apache/tamaya/microprofile/configsources/MPSystemPropertiesConfigSource.java
----------------------------------------------------------------------
diff --git a/microprofile/src/test/java/org/apache/tamaya/microprofile/configsources/MPSystemPropertiesConfigSource.java b/microprofile/src/test/java/org/apache/tamaya/microprofile/configsources/MPSystemPropertiesConfigSource.java
new file mode 100644
index 0000000..62ecbd4
--- /dev/null
+++ b/microprofile/src/test/java/org/apache/tamaya/microprofile/configsources/MPSystemPropertiesConfigSource.java
@@ -0,0 +1,34 @@
+/*
+ * 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.microprofile.configsources;
+
+import org.apache.tamaya.microprofile.MicroprofileConfigSource;
+import org.apache.tamaya.spisupport.SystemPropertySource;
+
+/**
+ * Microprofile config source based on Tamaya's system property source.
+ * Created by atsticks on 30.03.17.
+ */
+public class MPSystemPropertiesConfigSource extends MicroprofileConfigSource {
+
+ public MPSystemPropertiesConfigSource() {
+ super(new SystemPropertySource());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/5ee4802c/microprofile/src/test/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource
----------------------------------------------------------------------
diff --git a/microprofile/src/test/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource b/microprofile/src/test/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource
new file mode 100644
index 0000000..dc7c0fa
--- /dev/null
+++ b/microprofile/src/test/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource
@@ -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 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.microprofile.configsources.MPSystemPropertiesConfigSource