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/10/21 20:40:09 UTC
[1/2] incubator-tamaya-extensions git commit: TAMAYA-260 Added MP
Tests.
Repository: incubator-tamaya-extensions
Updated Branches:
refs/heads/master 4f5d90e8b -> c739afcda
TAMAYA-260 Added MP Tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/c739afcd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/c739afcd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/c739afcd
Branch: refs/heads/master
Commit: c739afcda5de3a82f1f523517e35b24b8046b71c
Parents: 98d31b7
Author: Anatole Tresch <an...@apache.org>
Authored: Sat Oct 21 22:39:31 2017 +0200
Committer: Anatole Tresch <an...@apache.org>
Committed: Sat Oct 21 22:39:55 2017 +0200
----------------------------------------------------------------------
.../microprofile/BuildableConfigSource.java | 180 +++++++++++++++++++
.../microprofile/MicroprofileAdapterTest.java | 162 +++++++++++++++++
.../MicroprofileConfigSourceProviderTest.java | 44 +++++
.../tamaya/microprofile/UppercaseConverter.java | 34 ++++
.../UppercasePropertyConverter.java | 36 ++++
5 files changed, 456 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c739afcd/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/BuildableConfigSource.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/BuildableConfigSource.java b/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/BuildableConfigSource.java
new file mode 100644
index 0000000..751a866
--- /dev/null
+++ b/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/BuildableConfigSource.java
@@ -0,0 +1,180 @@
+/*
+ * 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.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
+import org.eclipse.microprofile.config.spi.ConfigSource;
+
+import java.util.*;
+
+/**
+ * The Buildable config source.
+ */
+public class BuildableConfigSource implements ConfigSource{
+
+ private int ordinal;
+ private String name = "PropertySource-"+UUID.randomUUID().toString();
+ private Map<String,String> properties = new HashMap<>();
+
+ @Override
+ public int getOrdinal() {
+ return ordinal;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getValue(String key) {
+ return properties.get(key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return Collections.unmodifiableMap(properties);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ BuildableConfigSource that = (BuildableConfigSource) o;
+
+ return name.equals(that.name);
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "BuildableConfigSource{" +
+ "ordinal=" + ordinal +
+ ", name='" + name + '\'' +
+ ", properties=" + properties +
+ '}';
+ }
+
+ /**
+ * Builder builder.
+ *
+ * @return the builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+
+ /**
+ * The type Builder.
+ */
+ public static final class Builder {
+ private int ordinal;
+ private String source = "<on-the-fly-build>";
+ private String name = "ConfigSource-"+ UUID.randomUUID().toString();
+ private Map<String,String> properties = new HashMap<>();
+
+ private Builder() {
+ }
+
+ /**
+ * With ordinal builder.
+ *
+ * @param ordinal the ordinal
+ * @return the builder
+ */
+ public Builder withOrdinal(int ordinal) {
+ this.ordinal = ordinal;
+ return this;
+ }
+
+ /**
+ * With source builder.
+ *
+ * @param source the source
+ * @return the builder
+ */
+ public Builder withSource(String source) {
+ this.source = Objects.requireNonNull(source);
+ return this;
+ }
+
+ /**
+ * With name builder.
+ *
+ * @param name the name
+ * @return the builder
+ */
+ public Builder withName(String name) {
+ this.name = Objects.requireNonNull(name);
+ return this;
+ }
+
+ /**
+ * With simple property builder.
+ *
+ * @param key the key
+ * @param value the value
+ * @return the builder
+ */
+ public Builder withProperty(String key, String value) {
+ this.properties.put(key, value);
+ return this;
+ }
+
+ /**
+ * With properties builder.
+ *
+ * @param values the values
+ * @return the builder
+ */
+ public Builder withProperties(Map<String,String> values) {
+ this.properties.putAll(values);
+ return this;
+ }
+
+ /**
+ * But builder.
+ *
+ * @return the builder
+ */
+ public Builder but() {
+ return builder().withOrdinal(ordinal).withName(name).withProperties(properties);
+ }
+
+ /**
+ * Build buildable property source.
+ *
+ * @return the buildable property source
+ */
+ public BuildableConfigSource build() {
+ BuildableConfigSource buildableConfigSource = new BuildableConfigSource();
+ buildableConfigSource.name = this.name;
+ buildableConfigSource.properties = this.properties;
+ buildableConfigSource.ordinal = this.ordinal;
+ return buildableConfigSource;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c739afcd/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileAdapterTest.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileAdapterTest.java b/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileAdapterTest.java
new file mode 100644
index 0000000..031515d
--- /dev/null
+++ b/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileAdapterTest.java
@@ -0,0 +1,162 @@
+/*
+ * 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.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
+import org.apache.tamaya.spisupport.BuildablePropertySource;
+import org.eclipse.microprofile.config.Config;
+import org.eclipse.microprofile.config.ConfigProvider;
+import org.eclipse.microprofile.config.spi.ConfigBuilder;
+import org.eclipse.microprofile.config.spi.ConfigSource;
+import org.eclipse.microprofile.config.spi.Converter;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+public class MicroprofileAdapterTest {
+ @Test
+ public void toConfig() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Config mpConfig = MicroprofileAdapter.toConfig(config);
+ assertNotNull(mpConfig);
+ assertEquals(config.getProperties().keySet(), mpConfig.getPropertyNames());
+ }
+
+ @Test
+ public void toConfiguration() throws Exception {
+ Config mpConfig = ConfigProvider.getConfig();
+ Configuration config = MicroprofileAdapter.toConfiguration(mpConfig);
+ assertNotNull(config);
+ assertEquals(mpConfig.getPropertyNames(), config.getProperties().keySet());
+ }
+
+ @Test
+ public void toConfigSources() throws Exception {
+ BuildablePropertySource testPropertySource = BuildablePropertySource.builder()
+ .withSource("toConfigSources")
+ .withSimpleProperty("string0", "value0")
+ .withSimpleProperty("int0", "0")
+ .build();
+ List<PropertySource> tamayaSources = new ArrayList<>();
+ tamayaSources.add(testPropertySource);
+ List<ConfigSource> configSources = MicroprofileAdapter.toConfigSources(tamayaSources);
+ assertNotNull(configSources);
+ assertEquals(tamayaSources.size(), configSources.size());
+ compare(testPropertySource, configSources.get(0));
+ }
+
+ private void compare(PropertySource tamayaSource, ConfigSource mpSource) {
+ assertEquals(mpSource.getName(),tamayaSource.getName());
+ assertEquals(mpSource.getOrdinal(), tamayaSource.getOrdinal());
+ assertEquals(mpSource.getProperties().keySet(), tamayaSource.getProperties().keySet());
+ for(String key:mpSource.getPropertyNames()){
+ assertEquals(mpSource.getValue(key), tamayaSource.get(key).getValue());
+ }
+ }
+
+ @Test
+ public void toPropertySources() throws Exception {
+ BuildableConfigSource configSource = BuildableConfigSource.builder()
+ .withSource("toConfigSources")
+ .withProperty("string0", "value0")
+ .withProperty("int0", "0")
+ .build();
+ List<ConfigSource> configSources = new ArrayList<>();
+ configSources.add(configSource);
+ List<PropertySource> propertySources = MicroprofileAdapter.toPropertySources(configSources);
+ assertNotNull(propertySources);
+ assertEquals(propertySources.size(), configSources.size());
+ compare(propertySources.get(0), configSource);
+ }
+
+ @Test
+ public void toConfigSource() throws Exception {
+ BuildablePropertySource tamayaSource = BuildablePropertySource.builder()
+ .withSource("toConfigSource")
+ .withSimpleProperty("string0", "value0")
+ .withSimpleProperty("int0", "0")
+ .build();
+ ConfigSource configSource = MicroprofileAdapter.toConfigSource(tamayaSource);
+ assertNotNull(configSource);
+ compare(tamayaSource, configSource);
+ }
+
+ @Test
+ public void toPropertySource() throws Exception {
+ BuildableConfigSource configSource = BuildableConfigSource.builder()
+ .withSource("toConfigSource")
+ .withProperty("string0", "value0")
+ .withProperty("int0", "0")
+ .build();
+ PropertySource tamayaSource = MicroprofileAdapter.toPropertySource(configSource);
+ assertNotNull(configSource);
+ compare(tamayaSource, configSource);
+ }
+
+ @Test
+ public void toPropertyConverter() throws Exception {
+ PropertyConverter<String> tamayaConverter = MicroprofileAdapter.toPropertyConverter(new UppercaseConverter());
+ assertNotNull(tamayaConverter);
+ assertEquals("ABC", tamayaConverter.convert("aBC", null));
+ }
+
+ @Test
+ public void toConverter() throws Exception {
+ Converter<String> mpConverter = MicroprofileAdapter.toConverter(new UppercasePropertyConverter());
+ assertNotNull(mpConverter);
+ assertEquals("ABC", mpConverter.convert("aBC"));
+ }
+
+ @Test
+ public void toConfigBuilder() throws Exception {
+ ConfigBuilder builder = MicroprofileAdapter.toConfigBuilder(ConfigurationProvider.getConfigurationContextBuilder());
+ assertNotNull(builder);
+ }
+
+ @Test
+ public void toStringMap() throws Exception {
+ Map<String,PropertyValue> props = new HashMap<>();
+ props.put("a", PropertyValue.of("a","b", "toStringMap"));
+ Map<String, String> mpProps = MicroprofileAdapter.toStringMap(props);
+ assertNotNull(mpProps);
+ assertEquals(props.keySet(), mpProps.keySet());
+ assertEquals(mpProps.get("a"), "b");
+ }
+
+ @Test
+ public void toPropertyValueMap() throws Exception {
+ Map<String,String> props = new HashMap<>();
+ props.put("a", "b");
+ Map<String, PropertyValue> tamayaProps = MicroprofileAdapter.toPropertyValueMap(props, "toPropertyValueMap");
+ assertNotNull(tamayaProps);
+ assertEquals(tamayaProps.keySet(), props.keySet());
+ assertEquals(tamayaProps.get("a").getValue(), "b");
+ assertEquals("toPropertyValueMap", tamayaProps.get("a").getSource());
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c739afcd/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileConfigSourceProviderTest.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileConfigSourceProviderTest.java b/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileConfigSourceProviderTest.java
new file mode 100644
index 0000000..c62b390
--- /dev/null
+++ b/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileConfigSourceProviderTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.apache.tamaya.spisupport.BuildablePropertySource;
+import org.apache.tamaya.spisupport.BuildablePropertySourceProvider;
+import org.eclipse.microprofile.config.spi.ConfigSource;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class MicroprofileConfigSourceProviderTest {
+ @Test
+ public void getPropertySourceProvider() throws Exception {
+ BuildablePropertySourceProvider prov = BuildablePropertySourceProvider.builder()
+ .withPropertySourcs(
+ BuildablePropertySource.builder()
+ .withSimpleProperty("a", "b").build())
+ .build();
+ MicroprofileConfigSourceProvider provider = new MicroprofileConfigSourceProvider(prov);
+ assertNotNull(provider);
+ Iterable<ConfigSource> configSources = provider.getConfigSources(null);
+ assertNotNull(configSources);
+ assertTrue(configSources.iterator().hasNext());
+ assertEquals("b", configSources.iterator().next().getValue("a"));
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c739afcd/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/UppercaseConverter.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/UppercaseConverter.java b/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/UppercaseConverter.java
new file mode 100644
index 0000000..08623be
--- /dev/null
+++ b/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/UppercaseConverter.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;
+
+import org.eclipse.microprofile.config.spi.Converter;
+
+import java.util.Locale;
+
+public class UppercaseConverter implements Converter<String> {
+
+ @Override
+ public String convert(String s) {
+ if(s==null){
+ return null;
+ }
+ return s.toUpperCase(Locale.ENGLISH);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c739afcd/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/UppercasePropertyConverter.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/UppercasePropertyConverter.java b/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/UppercasePropertyConverter.java
new file mode 100644
index 0000000..de2d551
--- /dev/null
+++ b/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/UppercasePropertyConverter.java
@@ -0,0 +1,36 @@
+/*
+ * 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.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+import org.eclipse.microprofile.config.spi.Converter;
+
+import java.util.Locale;
+
+public class UppercasePropertyConverter implements PropertyConverter<String> {
+
+ @Override
+ public String convert(String s, ConversionContext context) {
+ if(s==null){
+ return null;
+ }
+ return s.toUpperCase(Locale.ENGLISH);
+ }
+}
[2/2] incubator-tamaya-extensions git commit: TAMAYA-260 Added
buildable items.
Posted by an...@apache.org.
TAMAYA-260 Added buildable items.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/98d31b71
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/98d31b71
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/98d31b71
Branch: refs/heads/master
Commit: 98d31b717b1f97f1a76c375c40412d3532fa9540
Parents: 4f5d90e
Author: Anatole Tresch <an...@apache.org>
Authored: Sat Oct 21 22:38:05 2017 +0200
Committer: Anatole Tresch <an...@apache.org>
Committed: Sat Oct 21 22:39:55 2017 +0200
----------------------------------------------------------------------
.../spisupport/BuildablePropertySource.java | 226 +++++++++++++++++++
.../BuildablePropertySourceProvider.java | 114 ++++++++++
.../BuildablePropertySourceProviderTest.java | 76 +++++++
.../spisupport/BuildablePropertySourceTest.java | 88 ++++++++
4 files changed, 504 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/98d31b71/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BuildablePropertySource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BuildablePropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BuildablePropertySource.java
new file mode 100644
index 0000000..e135644
--- /dev/null
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BuildablePropertySource.java
@@ -0,0 +1,226 @@
+/*
+ * 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.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
+
+import java.util.*;
+
+/**
+ * A Buildable property source.
+ */
+public class BuildablePropertySource implements PropertySource{
+
+ private int ordinal;
+ private String name = "PropertySource-"+UUID.randomUUID().toString();
+ private Map<String,PropertyValue> properties = new HashMap<>();
+
+ @Override
+ public int getOrdinal() {
+ return ordinal;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public PropertyValue get(String key) {
+ return properties.get(key);
+ }
+
+ @Override
+ public Map<String, PropertyValue> getProperties() {
+ return Collections.unmodifiableMap(properties);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ BuildablePropertySource that = (BuildablePropertySource) o;
+
+ return name.equals(that.name);
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "BuildablePropertySource{" +
+ "ordinal=" + ordinal +
+ ", name='" + name + '\'' +
+ ", properties=" + properties +
+ '}';
+ }
+
+ /**
+ * Builder builder.
+ *
+ * @return the builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+
+ /**
+ * The type Builder.
+ */
+ public static final class Builder {
+ private int ordinal;
+ private String source = "<on-the-fly-build>";
+ private String name = "PropertySource-"+ UUID.randomUUID().toString();
+ private Map<String,PropertyValue> properties = new HashMap<>();
+
+ private Builder() {
+ }
+
+ /**
+ * With ordinal builder.
+ *
+ * @param ordinal the ordinal
+ * @return the builder
+ */
+ public Builder withOrdinal(int ordinal) {
+ this.ordinal = ordinal;
+ return this;
+ }
+
+ /**
+ * With source builder.
+ *
+ * @param source the source
+ * @return the builder
+ */
+ public Builder withSource(String source) {
+ this.source = Objects.requireNonNull(source);
+ return this;
+ }
+
+ /**
+ * With name builder.
+ *
+ * @param name the name
+ * @return the builder
+ */
+ public Builder withName(String name) {
+ this.name = Objects.requireNonNull(name);
+ return this;
+ }
+
+ /**
+ * With simple property builder.
+ *
+ * @param key the key
+ * @param value the value
+ * @return the builder
+ */
+ public Builder withSimpleProperty(String key, String value) {
+ return withProperties(PropertyValue.of(key, value, this.source));
+ }
+
+ /**
+ * With simple property builder.
+ *
+ * @param key the key
+ * @param value the value
+ * @param source the source
+ * @return the builder
+ */
+ public Builder withSimpleProperty(String key, String value, String source) {
+ return withProperties(PropertyValue.of(key, value, source));
+ }
+
+ /**
+ * With properties builder.
+ *
+ * @param values the values
+ * @return the builder
+ */
+ public Builder withProperties(PropertyValue... values) {
+ for(PropertyValue val:values){
+ this.properties.put(val.getKey(), val);
+ }
+ return this;
+ }
+
+ /**
+ * With properties builder.
+ *
+ * @param properties the properties
+ * @return the builder
+ */
+ public Builder withProperties(Map<String, PropertyValue> properties) {
+ this.properties = Objects.requireNonNull(properties);
+ return this;
+ }
+
+ /**
+ * With properties builder.
+ *
+ * @param properties the properties
+ * @param source the source
+ * @return the builder
+ */
+ public Builder withProperties(Map<String, String> properties, String source) {
+ this.properties.putAll(PropertyValue.map(properties, source));
+ return this;
+ }
+
+ /**
+ * With simple properties builder.
+ *
+ * @param properties the properties
+ * @return the builder
+ */
+ public Builder withSimpleProperties(Map<String, String> properties) {
+ this.properties.putAll(PropertyValue.map(properties, this.source));
+ return this;
+ }
+
+ /**
+ * But builder.
+ *
+ * @return the builder
+ */
+ public Builder but() {
+ return builder().withOrdinal(ordinal).withName(name).withProperties(properties);
+ }
+
+ /**
+ * Build buildable property source.
+ *
+ * @return the buildable property source
+ */
+ public BuildablePropertySource build() {
+ BuildablePropertySource buildablePropertySource = new BuildablePropertySource();
+ buildablePropertySource.name = this.name;
+ buildablePropertySource.properties = this.properties;
+ buildablePropertySource.ordinal = this.ordinal;
+ return buildablePropertySource;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/98d31b71/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BuildablePropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BuildablePropertySourceProvider.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BuildablePropertySourceProvider.java
new file mode 100644
index 0000000..8341a44
--- /dev/null
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BuildablePropertySourceProvider.java
@@ -0,0 +1,114 @@
+/*
+ * 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.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+
+import java.util.*;
+
+/**
+ * A Buildable property source.
+ */
+public class BuildablePropertySourceProvider implements PropertySourceProvider{
+
+ private List<PropertySource> sources = new ArrayList<>();
+
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+ return Collections.unmodifiableCollection(sources);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ BuildablePropertySourceProvider that = (BuildablePropertySourceProvider) o;
+
+ return sources.equals(that.sources);
+ }
+
+ @Override
+ public int hashCode() {
+ return sources.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "BuildablePropertySourceProvider{" +
+ "sources=" + sources +
+ '}';
+ }
+
+ /**
+ * Builder builder.
+ *
+ * @return the builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+
+
+
+ /**
+ * The type Builder.
+ */
+ public static final class Builder {
+ private List<PropertySource> sources = new ArrayList<>();
+
+ private Builder() {
+ }
+
+ /**
+ * With propertySources.
+ *
+ * @param propertySources the propertySources
+ * @return the builder
+ */
+ public Builder withPropertySourcs(PropertySource... propertySources) {
+ this.sources.addAll(Arrays.asList(propertySources));
+ return this;
+ }
+
+ /**
+ * With property sources builder.
+ *
+ * @param sources the property sources
+ * @return the builder
+ */
+ public Builder withPropertySourcs(Collection<PropertySource> sources) {
+ this.sources.addAll(sources);
+ return this;
+ }
+
+ /**
+ * Build buildable property source.
+ *
+ * @return the buildable property source
+ */
+ public BuildablePropertySourceProvider build() {
+ BuildablePropertySourceProvider buildablePropertySource = new BuildablePropertySourceProvider();
+ buildablePropertySource.sources.addAll(this.sources);
+ return buildablePropertySource;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/98d31b71/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.java
new file mode 100644
index 0000000..cab05d2
--- /dev/null
+++ b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class BuildablePropertySourceProviderTest {
+
+ @Test
+ public void getPropertySources() throws Exception {
+ BuildablePropertySource ps = BuildablePropertySource.builder()
+ .withName("test1").build();
+ BuildablePropertySourceProvider prov = BuildablePropertySourceProvider.builder()
+ .withPropertySourcs(ps).build();
+ assertNotNull(prov);
+ assertEquals(prov.getPropertySources().iterator().next(), ps);
+ }
+
+ @Test
+ public void equals() throws Exception {
+ BuildablePropertySource ps = BuildablePropertySource.builder()
+ .withName("test1").build();
+ BuildablePropertySourceProvider prov1 = BuildablePropertySourceProvider.builder()
+ .withPropertySourcs(ps).build();
+ BuildablePropertySourceProvider prov2 = BuildablePropertySourceProvider.builder()
+ .withPropertySourcs(ps).build();
+ assertEquals(prov1, prov2);
+ BuildablePropertySource ps2 = BuildablePropertySource.builder()
+ .withName("test12").build();
+ prov2 = BuildablePropertySourceProvider.builder()
+ .withPropertySourcs(ps2).build();
+ assertNotEquals(prov1, prov2);
+ }
+
+ @Test
+ public void testHashCode() throws Exception {
+ BuildablePropertySource ps = BuildablePropertySource.builder()
+ .withName("test1").build();
+ BuildablePropertySourceProvider prov1 = BuildablePropertySourceProvider.builder()
+ .withPropertySourcs(ps).build();
+ BuildablePropertySourceProvider prov2 = BuildablePropertySourceProvider.builder()
+ .withPropertySourcs(ps).build();
+ assertEquals(prov1.hashCode(), prov2.hashCode());
+ BuildablePropertySource ps2 = BuildablePropertySource.builder()
+ .withName("test12").build();
+ prov2 = BuildablePropertySourceProvider.builder()
+ .withPropertySourcs(ps2).build();
+ assertNotEquals(prov1.hashCode(), prov2.hashCode());
+ }
+
+
+ @Test
+ public void builder() throws Exception {
+ assertNotNull(BuildablePropertySource.builder());
+ assertNotEquals(BuildablePropertySource.builder(), BuildablePropertySource.builder());
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/98d31b71/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceTest.java
new file mode 100644
index 0000000..721216d
--- /dev/null
+++ b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceTest.java
@@ -0,0 +1,88 @@
+/*
+ * 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.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class BuildablePropertySourceTest {
+ @Test
+ public void getOrdinal() throws Exception {
+ BuildablePropertySource ps1 = BuildablePropertySource.builder()
+ .withOrdinal(55).build();
+ assertEquals(55, ps1.getOrdinal());
+ }
+
+ @Test
+ public void getName() throws Exception {
+ BuildablePropertySource ps1 = BuildablePropertySource.builder()
+ .withName("test1").build();
+ assertEquals("test1", ps1.getName());
+ ps1 = BuildablePropertySource.builder().build();
+ assertNotNull(ps1.getName());
+ }
+
+ @Test
+ public void get() throws Exception {
+ BuildablePropertySource ps1 = BuildablePropertySource.builder()
+ .withSimpleProperty("a", "b").build();
+ assertEquals("b", ps1.get("a").getValue());
+ }
+
+ @Test
+ public void getProperties() throws Exception {
+ BuildablePropertySource ps1 = BuildablePropertySource.builder()
+ .withSimpleProperty("a", "b").build();
+ assertNotNull(ps1.getProperties());
+ assertEquals(1, ps1.getProperties().size());
+ assertEquals("b", ps1.getProperties().get("a").getValue());
+ }
+
+ @Test
+ public void equals() throws Exception {
+ BuildablePropertySource ps1 = BuildablePropertySource.builder()
+ .withName("test1").build();
+ BuildablePropertySource ps2 = BuildablePropertySource.builder()
+ .withName("test1").build();
+ assertEquals(ps1, ps2);
+ ps2 = BuildablePropertySource.builder()
+ .withName("test2").build();
+ assertNotEquals(ps1, ps2);
+ }
+
+ @Test
+ public void testHashCode() throws Exception {
+ BuildablePropertySource ps1 = BuildablePropertySource.builder()
+ .withName("test1").build();
+ BuildablePropertySource ps2 = BuildablePropertySource.builder()
+ .withName("test1").build();
+ assertEquals(ps1.hashCode(), ps2.hashCode());
+ ps2 = BuildablePropertySource.builder()
+ .withName("test2").build();
+ assertNotEquals(ps1.hashCode(), ps2.hashCode());
+ }
+
+ @Test
+ public void builder() throws Exception {
+ assertNotNull(BuildablePropertySource.builder());
+ assertNotEquals(BuildablePropertySource.builder(), BuildablePropertySource.builder());
+ }
+
+}
\ No newline at end of file