tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [1/2] incubator-tamaya-extensions git commit: TAMAYA-260 Added MP Tests.
Date Sat, 21 Oct 2017 20:40:09 GMT
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 <anatole@apache.org>
Authored: Sat Oct 21 22:39:31 2017 +0200
Committer: Anatole Tresch <anatole@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);
+    }
+}


Mime
View raw message