Repository: incubator-tamaya-sandbox Updated Branches: refs/heads/master 31bdbd264 -> 67245331e
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension ---------------------------------------------------------------------- diff --git a/configjsr/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/configjsr/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension new file mode 100644 index 0000000..2404efe --- /dev/null +++ b/configjsr/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension @@ -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.jsr382.cdi.JavaConfigCDIExtension \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter ---------------------------------------------------------------------- diff --git a/configjsr/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter b/configjsr/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter new file mode 100644 index 0000000..a53b75d --- /dev/null +++ b/configjsr/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter @@ -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.jsr382.converter.BooleanAsIntegerConverterFix +org.apache.tamaya.jsr382.converter.ProviderConverter \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource ---------------------------------------------------------------------- diff --git a/configjsr/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/configjsr/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource new file mode 100644 index 0000000..7840983 --- /dev/null +++ b/configjsr/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource @@ -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.jsr382.JavaConfigDefaultProperties \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/main/resources/beans.xml ---------------------------------------------------------------------- diff --git a/configjsr/src/main/resources/beans.xml b/configjsr/src/main/resources/beans.xml new file mode 100644 index 0000000..9b07802 --- /dev/null +++ b/configjsr/src/main/resources/beans.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> +<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd"> + + +</beans> + http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/test/java/org/apache/tamaya/jsr382/BuildableConfigSource.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/BuildableConfigSource.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/BuildableConfigSource.java new file mode 100644 index 0000000..ce8c58e --- /dev/null +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/BuildableConfigSource.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.jsr382; + +import javax.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-sandbox/blob/67245331/configjsr/src/test/java/org/apache/tamaya/jsr382/ConfigSourceParis.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/ConfigSourceParis.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/ConfigSourceParis.java new file mode 100644 index 0000000..f8ec5d5 --- /dev/null +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/ConfigSourceParis.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.jsr382; + +import javax.config.spi.ConfigSource; +import java.util.Collections; +import java.util.Map; + +public class ConfigSourceParis implements ConfigSource { + @Override + public Map<String, String> getProperties() { + return Collections.emptyMap(); + } + + @Override + public String getValue(String s) { + if (s.equals("config_ordinal")) { + return "5"; + } + + return null; + } + + @Override + public String getName() { + return "paris"; + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/test/java/org/apache/tamaya/jsr382/ConfigSourceProviderMinsk.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/ConfigSourceProviderMinsk.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/ConfigSourceProviderMinsk.java new file mode 100644 index 0000000..0ef822c --- /dev/null +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/ConfigSourceProviderMinsk.java @@ -0,0 +1,31 @@ +/* + * 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.jsr382; + + +import javax.config.spi.ConfigSource; +import javax.config.spi.ConfigSourceProvider; +import java.util.Collections; + +public class ConfigSourceProviderMinsk implements ConfigSourceProvider { + @Override + public Iterable<ConfigSource> getConfigSources(ClassLoader classLoader) { + return Collections::emptyIterator; + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigAdapterTest.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigAdapterTest.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigAdapterTest.java new file mode 100644 index 0000000..019aac0 --- /dev/null +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigAdapterTest.java @@ -0,0 +1,246 @@ +/* + * 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.jsr382; + +import org.apache.tamaya.*; +import org.apache.tamaya.spi.ConfigurationContext; +import org.apache.tamaya.spi.PropertyConverter; +import org.apache.tamaya.spi.PropertySource; +import org.apache.tamaya.spi.PropertyValue; +import org.apache.tamaya.spisupport.propertysource.BuildablePropertySource; +import org.assertj.core.api.Assertions; +import org.junit.Test; + +import javax.config.Config; +import javax.config.ConfigProvider; +import javax.config.spi.ConfigBuilder; +import javax.config.spi.ConfigSource; +import javax.config.spi.Converter; +import java.util.*; + +import static org.junit.Assert.*; + +public class JavaConfigAdapterTest { + @Test + public void toConfig() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + Config mpConfig = JavaConfigAdapter.toConfig(config); + assertNotNull(mpConfig); + assertEquals(config.getProperties().keySet(), mpConfig.getPropertyNames()); + } + + @Test + public void toConfigWithTamayaConfiguration() throws Exception { + Configuration configuration = new MyConfiguration(); + JavaConfig config = new JavaConfig(configuration); + TamayaConfiguration tamayaConfiguration = new TamayaConfiguration(config); + + Config result = JavaConfigAdapter.toConfig(tamayaConfiguration); + + Assertions.assertThat(result).isNotNull() + .isInstanceOf(JavaConfig.class) + .isSameAs(config); + } + + @Test + public void toConfiguration() throws Exception { + Config mpConfig = ConfigProvider.getConfig(); + Configuration config = JavaConfigAdapter.toConfiguration(mpConfig); + assertNotNull(config); + assertEquals(mpConfig.getPropertyNames(), config.getProperties().keySet()); + } + + @Test + public void toConfigurationWithNoneJavaConfigConfig() throws Exception { + Config config = new MyConfig(); + Configuration result = JavaConfigAdapter.toConfiguration(config); + + Assertions.assertThat(result).isNotNull() + .isInstanceOf(TamayaConfiguration.class); + } + + @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 = JavaConfigAdapter.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 = JavaConfigAdapter.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 = JavaConfigAdapter.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 = JavaConfigAdapter.toPropertySource(configSource); + assertNotNull(configSource); + compare(tamayaSource, configSource); + } + + @Test + public void toPropertyConverter() throws Exception { + PropertyConverter<String> tamayaConverter = JavaConfigAdapter.toPropertyConverter(new UppercaseConverter()); + assertNotNull(tamayaConverter); + assertEquals("ABC", tamayaConverter.convert("aBC", null)); + } + + @Test + public void toConverter() throws Exception { + Converter<String> mpConverter = JavaConfigAdapter.toConverter(new UppercasePropertyConverter()); + assertNotNull(mpConverter); + assertEquals("ABC", mpConverter.convert("aBC")); + } + + @Test + public void toConfigBuilder() throws Exception { + ConfigBuilder builder = JavaConfigAdapter.toConfigBuilder(ConfigurationProvider.getConfigurationBuilder()); + 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 = JavaConfigAdapter.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 = JavaConfigAdapter.toPropertyValueMap(props, "toPropertyValueMap"); + assertNotNull(tamayaProps); + assertEquals(tamayaProps.keySet(), props.keySet()); + assertEquals(tamayaProps.get("a").getValue(), "b"); + assertEquals("toPropertyValueMap", tamayaProps.get("a").getSource()); + } + + static class MyConfig implements Config { + @Override + public <T> T getValue(String s, Class<T> aClass) { + throw new RuntimeException("Not implemented yet!"); + } + + @Override + public <T> Optional<T> getOptionalValue(String s, Class<T> aClass) { + throw new RuntimeException("Not implemented yet!"); + } + + @Override + public Iterable<String> getPropertyNames() { + throw new RuntimeException("Not implemented yet!"); + } + + @Override + public Iterable<ConfigSource> getConfigSources() { + throw new RuntimeException("Not implemented yet!"); + } + } + + static class MyConfiguration implements Configuration { + @Override + public String get(String key) { + throw new RuntimeException("Not implemented yet!"); + } + + @Override + public String getOrDefault(String key, String defaultValue) { + throw new RuntimeException("Not implemented yet!"); + } + + @Override + public <T> T getOrDefault(String key, Class<T> type, T defaultValue) { + throw new RuntimeException("Not implemented yet!"); + } + + @Override + public <T> T get(String key, Class<T> type) { + throw new RuntimeException("Not implemented yet!"); + } + + @Override + public <T> T get(String key, TypeLiteral<T> type) { + throw new RuntimeException("Not implemented yet!"); + } + + @Override + public <T> T getOrDefault(String key, TypeLiteral<T> type, T defaultValue) { + throw new RuntimeException("Not implemented yet!"); + } + + @Override + public Map<String, String> getProperties() { + throw new RuntimeException("Not implemented yet!"); + } + + @Override + public ConfigurationContext getContext() { + throw new RuntimeException("Not implemented yet!"); + } + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigBuilderTest.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigBuilderTest.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigBuilderTest.java new file mode 100644 index 0000000..05b5553 --- /dev/null +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigBuilderTest.java @@ -0,0 +1,126 @@ +/* + * 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.jsr382; + +import org.assertj.core.api.Assertions; +import org.junit.Test; + +import javax.config.Config; +import javax.config.spi.ConfigBuilder; +import javax.config.spi.ConfigProviderResolver; +import javax.config.spi.ConfigSource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +import static org.junit.Assert.*; + +/** + * Created by atsticks on 24.03.17. + */ +public class JavaConfigConfigBuilderTest { + + 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 + 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); + } + + @Test + public void addDiscoveredSourcesAddsAllConfigSources() throws Exception { + ConfigBuilder builder = ConfigProviderResolver.instance().getBuilder(); + + Config config = builder.addDiscoveredSources() + .addDefaultSources().build(); + + Iterable<ConfigSource> iterable = config.getConfigSources(); + + List<String> name = StreamSupport.stream(iterable.spliterator(), false) + .map(ConfigSource::getName) + .collect(Collectors.toList()); + + Assertions.assertThat(name).hasSize(4) + .containsExactlyInAnyOrder("paris", + "SystemPropertySource", + "environment-properties", + "META-INF/JavaConfig-config.properties"); + } + + @Test + public void addDiscoveredSourcesAddsAllConfigSourceProviders() throws Exception { + // throw new RuntimeException("Not implemented yet!"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigProviderResolverTest.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigProviderResolverTest.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigProviderResolverTest.java new file mode 100644 index 0000000..7c43bdc --- /dev/null +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigProviderResolverTest.java @@ -0,0 +1,72 @@ +/* + * 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.jsr382; + +import org.junit.Test; + +import javax.config.Config; +import javax.config.spi.ConfigProviderResolver; +import java.net.URL; +import java.net.URLClassLoader; + +import static org.junit.Assert.*; + +/** + * Created by atsticks on 24.03.17. + */ +public class JavaConfigConfigProviderResolverTest { + + @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/67245331/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigProviderTest.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigProviderTest.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigProviderTest.java new file mode 100644 index 0000000..9c39821 --- /dev/null +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigProviderTest.java @@ -0,0 +1,62 @@ +/* + * 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.jsr382; + +import org.apache.tamaya.ConfigurationProvider; +import org.junit.Test; + +import javax.config.Config; +import javax.config.ConfigProvider; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +/** + * Created by atsticks on 24.03.17. + */ +public class JavaConfigConfigProviderTest { + + @Test + public void testDefaultConfigAccess(){ + Config config = ConfigProvider.getConfig(); + assertNotNull(config); + Iterable<String> names = config.getPropertyNames(); + assertNotNull(names); + int count = 0; + for(String name:names){ + count++; + System.out.println(count + ": " +name); + } + assertTrue(ConfigurationProvider.getConfiguration().getProperties().size() <= count); + } + + @Test + public void testClassloaderAccess(){ + Config config = ConfigProvider.getConfig(Thread.currentThread().getContextClassLoader()); + assertNotNull(config); + Iterable<String> names = config.getPropertyNames(); + assertNotNull(names); + int count = 0; + for(String name:names){ + count++; + } + assertTrue(count>0); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigSourceProviderTest.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigSourceProviderTest.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigSourceProviderTest.java new file mode 100644 index 0000000..3552a4a --- /dev/null +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigSourceProviderTest.java @@ -0,0 +1,45 @@ +/* + * 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.jsr382; + +import org.apache.tamaya.spisupport.propertysource.BuildablePropertySource; +import org.apache.tamaya.spisupport.propertysource.BuildablePropertySourceProvider; +import org.junit.Test; + +import javax.config.spi.ConfigSource; + +import static org.junit.Assert.*; + +public class JavaConfigConfigSourceProviderTest { + @Test + public void getPropertySourceProvider() throws Exception { + BuildablePropertySourceProvider prov = BuildablePropertySourceProvider.builder() + .withPropertySourcs( + BuildablePropertySource.builder() + .withSimpleProperty("a", "b").build()) + .build(); + JavaConfigSourceProvider provider = new JavaConfigSourceProvider(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-sandbox/blob/67245331/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigTest.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigTest.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigTest.java new file mode 100644 index 0000000..06685e1 --- /dev/null +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConfigTest.java @@ -0,0 +1,95 @@ +/* + * 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.jsr382; + +import org.junit.Test; + +import javax.config.Config; +import javax.config.ConfigProvider; +import javax.config.spi.ConfigSource; +import java.util.NoSuchElementException; +import java.util.Optional; + +import static org.junit.Assert.*; + +/** + * Created by atsticks on 24.03.17. + */ +public class JavaConfigConfigTest { + + @Test + public void testDefaultConfigAccess() { + Config config = ConfigProvider.getConfig(); + Iterable<ConfigSource> sources = config.getConfigSources(); + int count = 0; + for (ConfigSource cs : sources) { + count++; + } + assertEquals(4, count); + } + + @Test + public void testOptionalAccess(){ + Config config = ConfigProvider.getConfig(); + int count = 0; + for(String key:config.getPropertyNames()){ + Optional<String> val = config.getOptionalValue(key, String.class); + assertNotNull(val); + val = config.getOptionalValue(key + System.currentTimeMillis(), String.class); + assertNotNull(val); + assertFalse(val.isPresent()); + } + } + + @Test + public void testGetValue(){ + Config config = ConfigProvider.getConfig(); + int count = 0; + for(String key:config.getPropertyNames()){ + String val = config.getValue(key, String.class); + assertNotNull(val); + } + } + + @Test(expected = NoSuchElementException.class) + public void testGetValue_NoValue(){ + Config config = ConfigProvider.getConfig(); + config.getValue("fooBar", String.class); + } + + @Test(expected = IllegalArgumentException.class) + public void testGetValue_InvalidType(){ + Config config = ConfigProvider.getConfig(); + config.getValue("java.version", Integer.class); + } + + @Test + public void testEmptySystemProperty(){ + System.setProperty("my.empty.property", ""); + Config config = ConfigProvider.getConfig(); + assertEquals("", config.getValue("my.empty.property", String.class)); + } + + @Test + public void testEmptyConfigProperty(){ + Config config = ConfigProvider.getConfig(); + assertEquals("", config.getValue("my.empty.property.in.config.file", String.class)); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConverterTest.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConverterTest.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConverterTest.java new file mode 100644 index 0000000..9b9aba5 --- /dev/null +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigConverterTest.java @@ -0,0 +1,41 @@ +/* + * 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.jsr382; + +import org.apache.tamaya.spi.PropertyConverter; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(MockitoJUnitRunner.class) +public class JavaConfigConverterTest { + + @Mock + private PropertyConverter<String> converter; + + @Test + public void returnedPropertyConverterIsTheOneOfTheDelegate() throws Exception { + JavaConfigConverter<String> mpConverter = new JavaConfigConverter<>(converter); + + assertThat(mpConverter.getPropertyConverter()).isSameAs(converter); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigDefaultPropertiesTest.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigDefaultPropertiesTest.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigDefaultPropertiesTest.java new file mode 100644 index 0000000..744fe63 --- /dev/null +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/JavaConfigDefaultPropertiesTest.java @@ -0,0 +1,31 @@ +/* + * 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.jsr382; + +import org.assertj.core.api.Assertions; +import org.junit.Test; + + +public class JavaConfigDefaultPropertiesTest { + @Test + public void hasOrdinalOf100() throws Exception { + JavaConfigDefaultProperties properties = new JavaConfigDefaultProperties(); + Assertions.assertThat(properties.getOrdinal()).isEqualTo(100); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/test/java/org/apache/tamaya/jsr382/TamayaPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/TamayaPropertySourceTest.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/TamayaPropertySourceTest.java new file mode 100644 index 0000000..e035a33 --- /dev/null +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/TamayaPropertySourceTest.java @@ -0,0 +1,51 @@ +/* + * 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.jsr382; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import javax.config.spi.ConfigSource; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class TamayaPropertySourceTest { + @Mock + private ConfigSource configSource; + + @Test + public void isScannable() throws Exception { + TamayaPropertySource source = new TamayaPropertySource(configSource); + + assertThat(source.isScannable()).isTrue(); + } + + @Test + public void ordinalIsTheSameAsOfTheConfigSource() throws Exception { + when(configSource.getOrdinal()).thenReturn(44); + + TamayaPropertySource source = new TamayaPropertySource(configSource); + + assertThat(source.getOrdinal()).isEqualTo(44); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/test/java/org/apache/tamaya/jsr382/UppercaseConverter.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/UppercaseConverter.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/UppercaseConverter.java new file mode 100644 index 0000000..7868c8a --- /dev/null +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/UppercaseConverter.java @@ -0,0 +1,33 @@ +/* + * 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.jsr382; + +import javax.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-sandbox/blob/67245331/configjsr/src/test/java/org/apache/tamaya/jsr382/UppercasePropertyConverter.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/UppercasePropertyConverter.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/UppercasePropertyConverter.java new file mode 100644 index 0000000..0aacb96 --- /dev/null +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/UppercasePropertyConverter.java @@ -0,0 +1,35 @@ +/* + * 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.jsr382; + +import org.apache.tamaya.spi.ConversionContext; +import org.apache.tamaya.spi.PropertyConverter; + +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); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/test/java/org/apache/tamaya/jsr382/tck/TamayaConfigArchiveProcessor.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/tck/TamayaConfigArchiveProcessor.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/tck/TamayaConfigArchiveProcessor.java new file mode 100644 index 0000000..fe2bea8 --- /dev/null +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/tck/TamayaConfigArchiveProcessor.java @@ -0,0 +1,79 @@ +/* + * 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.jsr382.tck; + +import org.apache.tamaya.core.internal.converters.OptionalConverter; +import org.apache.tamaya.jsr382.JavaConfigAdapter; +import org.apache.tamaya.jsr382.JavaConfigProviderResolver; +import org.apache.tamaya.jsr382.cdi.JavaConfigCDIExtension; +import org.apache.tamaya.jsr382.converter.BooleanAsIntegerConverterFix; +import org.apache.tamaya.spi.PropertyConverter; +import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; +import org.jboss.arquillian.test.spi.TestClass; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.resolver.api.maven.Maven; + +import javax.config.spi.ConfigProviderResolver; +import javax.enterprise.inject.spi.Extension; +import java.io.File; + +/** + * Adds the whole Config implementation classes and resources to the + * Arquillian deployment archive. This is needed to have the container + * pick up the beans from within the impl for the TCK tests. + * + * @author <a href="mailto:strub...@yahoo.de">Mark Struberg</a> + */ +public class TamayaConfigArchiveProcessor implements ApplicationArchiveProcessor { + + @Override + public void process(Archive<?> applicationArchive, TestClass testClass) { + if (applicationArchive instanceof WebArchive) { + File[] coreLibs = Maven.resolver() + .loadPomFromFile("pom.xml").resolve("org.apache.tamaya:tamaya-core") + .withTransitivity().asFile(); + File[] apiLibs = Maven.resolver() + .loadPomFromFile("pom.xml").resolve("org.apache.tamaya:tamaya-api") + .withTransitivity().asFile(); + File[] functionsLib = Maven.resolver() + .loadPomFromFile("pom.xml").resolve("org.apache.tamaya.ext:tamaya-functions") + .withTransitivity().asFile(); + + JavaArchive configJar = ShrinkWrap + .create(JavaArchive.class, "tamaya-config-impl.jar") + .addPackage(JavaConfigAdapter.class.getPackage()) + .addPackage(JavaConfigCDIExtension.class.getPackage()) + .addPackage(BooleanAsIntegerConverterFix.class.getPackage()) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") + .addAsServiceProvider(ConfigProviderResolver.class, JavaConfigProviderResolver.class) + .addAsServiceProvider(PropertyConverter.class, BooleanAsIntegerConverterFix.class) + .addAsServiceProvider(PropertyConverter.class, OptionalConverter.class) + .addAsServiceProvider(Extension.class, JavaConfigCDIExtension.class); + ((WebArchive) applicationArchive).addAsLibraries( + configJar) + .addAsLibraries(apiLibs) + .addAsLibraries(coreLibs) + .addAsLibraries(functionsLib); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/test/java/org/apache/tamaya/jsr382/tck/TamayaConfigExtension.java ---------------------------------------------------------------------- diff --git a/configjsr/src/test/java/org/apache/tamaya/jsr382/tck/TamayaConfigExtension.java b/configjsr/src/test/java/org/apache/tamaya/jsr382/tck/TamayaConfigExtension.java new file mode 100644 index 0000000..f0d50de --- /dev/null +++ b/configjsr/src/test/java/org/apache/tamaya/jsr382/tck/TamayaConfigExtension.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.jsr382.tck; + +import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; +import org.jboss.arquillian.core.spi.LoadableExtension; + +/** + * Arquillian extension to load Tamaya into Arquillian context. + * @author <a href="mailto:anat...@apache.org">Anatole Tresch</a> + */ +public class TamayaConfigExtension implements LoadableExtension { + + @Override + public void register(ExtensionBuilder extensionBuilder) { + extensionBuilder.service( + ApplicationArchiveProcessor.class, + TamayaConfigArchiveProcessor.class); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/test/resources/META-INF/beans.xml ---------------------------------------------------------------------- diff --git a/configjsr/src/test/resources/META-INF/beans.xml b/configjsr/src/test/resources/META-INF/beans.xml new file mode 100644 index 0000000..adee378 --- /dev/null +++ b/configjsr/src/test/resources/META-INF/beans.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> +<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd"> + +</beans> + http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/test/resources/META-INF/microprofile-config.properties ---------------------------------------------------------------------- diff --git a/configjsr/src/test/resources/META-INF/microprofile-config.properties b/configjsr/src/test/resources/META-INF/microprofile-config.properties new file mode 100644 index 0000000..68d7655 --- /dev/null +++ b/configjsr/src/test/resources/META-INF/microprofile-config.properties @@ -0,0 +1,105 @@ +# +# Copyright (c) 2016-2017 Contributors to the Eclipse Foundation +# +# See the NOTICES file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# Licensed 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. +# + +my.optional.int.property=1234 +my.optional.string.property=hello + +tck.config.test.javaconfig.properties.key1=VALue1 + + +tck.config.test.overwritten.in.custompropertyfile.key1=value from JavaConfig-config.properties + + +tck.config.test.javaconfig.converter.integervalue = 1234 +tck.config.test.javaconfig.converter.integervalue.broken = xxx + +tck.config.test.javaconfig.converter.longvalue = 1234567890 +tck.config.test.javaconfig.converter.longvalue.broken = xxx + +tck.config.test.javaconfig.converter.floatvalue = 12.34 +tck.config.test.javaconfig.converter.floatvalue.broken = alfasdf + +tck.config.test.javaconfig.converter.doublevalue = 12.34 +tck.config.test.javaconfig.converter.doublevalue.broken = alfasdf + +tck.config.test.javaconfig.converter.durationvalue = PT15M +tck.config.test.javaconfig.converter.durationvalue.broken = alfasdf + +tck.config.test.javaconfig.converter.localtimevalue = 10:37 +tck.config.test.javaconfig.converter.localtimevalue.broken = alfasdf + +tck.config.test.javaconfig.converter.localdatevalue = 2017-12-24 +tck.config.test.javaconfig.converter.localdatevalue.broken = alfasdf + +tck.config.test.javaconfig.converter.localdatetimevalue = 2017-12-24T10:25:30 +tck.config.test.javaconfig.converter.localdatetimevalue.broken = alfasdf + +tck.config.test.javaconfig.converter.offsetdatetimevalue = 2007-12-03T10:15:30+01:00 +tck.config.test.javaconfig.converter.offsetdatetimevalue.broken = alfasdf + +tck.config.test.javaconfig.converter.offsettimevalue = 13:45:30.123456789+02:00 +tck.config.test.javaconfig.converter.offsettimevalue.broken = alfasdf + +tck.config.test.javaconfig.converter.instantvalue = 2015-06-02T21:34:33.616Z +tck.config.test.javaconfig.converter.instantvalue.broken = alfasdf + +tck.config.test.javaconfig.configvalue.key1=value1 + +# test BooleanConverter START +tck.config.test.javaconfig.configvalue.boolean.true=true +tck.config.test.javaconfig.configvalue.boolean.true_uppercase=TRUE +tck.config.test.javaconfig.configvalue.boolean.true_mixedcase=TruE +tck.config.test.javaconfig.configvalue.boolean.false=false + +tck.config.test.javaconfig.configvalue.boolean.one=1 +tck.config.test.javaconfig.configvalue.boolean.zero=0 +tck.config.test.javaconfig.configvalue.boolean.seventeen=17 + +tck.config.test.javaconfig.configvalue.boolean.yes=yes +tck.config.test.javaconfig.configvalue.boolean.yes_uppercase=YES +tck.config.test.javaconfig.configvalue.boolean.yes_mixedcase=Yes +tck.config.test.javaconfig.configvalue.boolean.no=no + +tck.config.test.javaconfig.configvalue.boolean.y=y +tck.config.test.javaconfig.configvalue.boolean.y_uppercase=Y +tck.config.test.javaconfig.configvalue.boolean.n=n + +tck.config.test.javaconfig.configvalue.boolean.on=on +tck.config.test.javaconfig.configvalue.boolean.on_uppercase=ON +tck.config.test.javaconfig.configvalue.boolean.on_mixedcase=oN +tck.config.test.javaconfig.configvalue.boolean.off=off + +# test BooleanConverter END + +# various other converter +tck.config.test.javaconfig.configvalue.integer=1234 +tck.config.test.javaconfig.configvalue.long=1234567890123456 +tck.config.test.javaconfig.configvalue.float=12.34 +tck.config.test.javaconfig.configvalue.double=12.34567890123456 + +# Custom Converter tests +tck.config.test.javaconfig.converter.duckname=Hannelore + +# URL Converter tests +tck.config.test.javaconfig.converter.urlvalue=http://JavaConfig.io +tck.config.test.javaconfig.converter.urlvalue.broken=tt:--location$ + +# Empty values +my.empty.property.in.config.file= \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/test/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource ---------------------------------------------------------------------- diff --git a/configjsr/src/test/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource b/configjsr/src/test/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource new file mode 100644 index 0000000..49faebf --- /dev/null +++ b/configjsr/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 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.jsr382.ConfigSourceParis http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/test/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSourceProvider ---------------------------------------------------------------------- diff --git a/configjsr/src/test/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSourceProvider b/configjsr/src/test/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSourceProvider new file mode 100644 index 0000000..4641e92 --- /dev/null +++ b/configjsr/src/test/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSourceProvider @@ -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.jsr382.ConfigSourceProviderMinsk \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension ---------------------------------------------------------------------- diff --git a/configjsr/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension b/configjsr/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension new file mode 100644 index 0000000..8642f1a --- /dev/null +++ b/configjsr/src/test/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension @@ -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.jsr382.tck.TamayaConfigExtension \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/test/resources/sampleconfig.yaml ---------------------------------------------------------------------- diff --git a/configjsr/src/test/resources/sampleconfig.yaml b/configjsr/src/test/resources/sampleconfig.yaml new file mode 100644 index 0000000..27f2392 --- /dev/null +++ b/configjsr/src/test/resources/sampleconfig.yaml @@ -0,0 +1,18 @@ +# +# Copyright (c) 2016-2017 Mark Struberg and others +# +# Licensed 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. +# +# just needed as a trigger for the ConfigSource pickup. +# Content is hardcoded in SampleYamlConfigSource \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/67245331/configjsr/src/test/tck-suite.xml ---------------------------------------------------------------------- diff --git a/configjsr/src/test/tck-suite.xml b/configjsr/src/test/tck-suite.xml new file mode 100644 index 0000000..606e3b5 --- /dev/null +++ b/configjsr/src/test/tck-suite.xml @@ -0,0 +1,27 @@ +<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > +<!-- +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. +--> +<suite name="JavaConfig-config-TCK" verbose="2" configfailurepolicy="continue" > + <test name="JavaConfig-config 1.1 TCK"> + <packages> + <package name="org.eclipse.JavaConfig.config.tck.*"> + </package> + </packages> + </test> +</suite> \ No newline at end of file