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 2015/01/24 21:06:35 UTC
[5/9] incubator-tamaya git commit: TAMAYA-63: Implemented backport
for Java 7.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java b/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
new file mode 100644
index 0000000..962a6af
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.propertysource;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ * This {@link org.apache.tamaya.spi.PropertySource} manages the system properties.
+ */
+public class SystemPropertySource extends PropertiesPropertySource {
+
+ /**
+ * Lock for internal synchronization.
+ */
+ private ReentrantReadWriteLock propertySourceLock = new ReentrantReadWriteLock();
+
+
+ /**
+ * previous System.getProperties().hashCode()
+ * so we can check if we need to reload
+ */
+ private int previousHash;
+
+
+ public SystemPropertySource() {
+ super(System.getProperties());
+ previousHash = System.getProperties().hashCode();
+ initializeOrdinal(DefaultOrdinal.SYSTEM_PROPERTIES);
+ }
+
+
+ @Override
+ public String getName() {
+ return "system-properties";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+
+ Lock writeLock = propertySourceLock.writeLock();
+ // only need to reload and fill our map if something has changed
+ try {
+ writeLock.lock();
+ if (previousHash != System.getProperties().hashCode()) {
+
+ if (previousHash != System.getProperties().hashCode()) {
+
+ Properties systemProperties = System.getProperties();
+ Map<String, String> properties = new HashMap<>();
+
+ for (String propertyName : systemProperties.stringPropertyNames()) {
+ properties.put(propertyName, System.getProperty(propertyName));
+ }
+
+ this.properties = Collections.unmodifiableMap(properties);
+ previousHash = systemProperties.hashCode();
+ }
+ }
+ } finally {
+ writeLock.unlock();
+ }
+
+ return super.getProperties();
+ }
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java b/java7/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
new file mode 100644
index 0000000..bb741de
--- /dev/null
+++ b/java7/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.provider;
+
+import static org.apache.tamaya.core.internal.PropertiesFileLoader.resolvePropertiesFiles;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.core.propertysource.PropertiesFilePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Provider which reads all {@code javaconfiguration.properties} files from classpath
+ */
+public class JavaConfigurationProvider implements PropertySourceProvider {
+
+
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+
+ List<PropertySource> propertySources = new ArrayList<>();
+
+ //X TODO maybe put javaconf... in META-INF
+
+ try {
+ for (URL url : resolvePropertiesFiles("javaconfiguration.properties")) {
+ propertySources.add(new PropertiesFilePropertySource(url));
+ }
+ } catch (IOException e) {
+ throw new ConfigException("Error while loading javaconfiguration.properties", e);
+ }
+
+ return Collections.unmodifiableList(propertySources);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader
----------------------------------------------------------------------
diff --git a/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader
new file mode 100644
index 0000000..a964d3c
--- /dev/null
+++ b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader
@@ -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.resource.internal.DefaultResourceLoader
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
----------------------------------------------------------------------
diff --git a/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
new file mode 100644
index 0000000..2f0f44e
--- /dev/null
+++ b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.internal.DefaultConfigurationContext
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
----------------------------------------------------------------------
diff --git a/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
new file mode 100644
index 0000000..0f0cb26
--- /dev/null
+++ b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
@@ -0,0 +1,30 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.internal.converters.BooleanConverter
+org.apache.tamaya.core.internal.converters.ByteConverter
+org.apache.tamaya.core.internal.converters.CharConverter
+org.apache.tamaya.core.internal.converters.DoubleConverter
+org.apache.tamaya.core.internal.converters.FloatConverter
+org.apache.tamaya.core.internal.converters.IntegerConverter
+org.apache.tamaya.core.internal.converters.LongConverter
+org.apache.tamaya.core.internal.converters.ShortConverter
+org.apache.tamaya.core.internal.converters.BigDecimalConverter
+org.apache.tamaya.core.internal.converters.BigIntegerConverter
+org.apache.tamaya.core.internal.converters.CurrencyConverter
+org.apache.tamaya.core.internal.converters.NumberConverter
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
----------------------------------------------------------------------
diff --git a/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
new file mode 100644
index 0000000..f8e7e7f
--- /dev/null
+++ b/java7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.internal.DefaultServiceContext
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java b/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
new file mode 100644
index 0000000..4c0e813
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.core.internal.DefaultConfiguration;
+import org.apache.tamaya.spi.ServiceContext;
+import org.apache.tamaya.spi.ServiceContextManager;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * This tests checks if the combination of 2 prioritized PropertySource return valid results on the final Configuration.
+ */
+public class ConfigurationTest {
+
+ @Test
+ public void testAccess(){
+ assertNotNull(current());
+ }
+
+ private Configuration current() {
+ return ServiceContextManager.getServiceContext().getService(Configuration.class);
+ }
+
+ @Test
+ public void testContent(){
+ assertEquals("Robin", current().get("name"));
+ assertEquals("Sabine", current().get("name2")); // from default
+ assertEquals("Mapped to name: Robin", current().get("name3")); // oderridden default, mapped by filter to name property
+ assertEquals("Sereina(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)", current().get("name4")); // final only
+ assertNull(current().get("name5")); // final only, but removed from filter
+
+ System.out.println("name : " + current().get("name"));
+ System.out.println("name2: " + current().get("name2"));
+ System.out.println("name3: " + current().get("name3"));
+ System.out.println("name4: " + current().get("name4"));
+ System.out.println("name5: " + current().get("name5"));
+
+ System.out.println("ALL :");
+ Set<Map.Entry<String, String>> entries = current().getProperties().entrySet();
+ for (Map.Entry<String, String> entry : entries) {
+ System.out.println(" " + entry.getKey()+" = " + entry.getValue());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java b/java7/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
new file mode 100644
index 0000000..4f4079a
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/internal/DefaultServiceContextTest.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.annotation.Priority;
+import java.util.List;
+import java.util.Optional;
+
+public class DefaultServiceContextTest {
+
+ /**
+ * context to test
+ */
+ private DefaultServiceContext context = new DefaultServiceContext();
+
+
+ @Test
+ public void testGetService() {
+ ConfigurationContext configurationContext = context.getService(ConfigurationContext.class);
+
+ Assert.assertNotNull(configurationContext);
+ Assert.assertTrue(configurationContext instanceof DefaultConfigurationContext);
+ }
+
+ @Test(expected = ConfigException.class)
+ public void testGetService_multipleServicesWithoutPriority_shouldThrowConfigException() {
+ context.getService(InvalidPriorityInterface.class);
+ }
+
+ @Test
+ public void testGetService_multipleService_shouldReturnServiceWithHighestPriority() {
+ MultiImplsInterface service = context.getService(MultiImplsInterface.class);
+
+ Assert.assertNotNull(service);
+ Assert.assertTrue(service instanceof MultiImpl2);
+ }
+
+ @Test
+ public void testGetService_noImpl_shouldReturnEmptyOpional() {
+ NoImplInterface service = context.getService(NoImplInterface.class);
+ Assert.assertNull(service);
+ }
+
+
+ @Test
+ public void testGetServices_shouldReturnServices() {
+ {
+ List<InvalidPriorityInterface> services = context.getServices(InvalidPriorityInterface.class);
+ Assert.assertNotNull(services);
+ Assert.assertEquals(2, services.size());
+
+ for (InvalidPriorityInterface service : services) {
+ Assert.assertTrue(service instanceof InvalidPriorityImpl1 || service instanceof InvalidPriorityImpl2);
+ }
+ }
+
+ {
+ List<MultiImplsInterface> services = context.getServices(MultiImplsInterface.class);
+ Assert.assertNotNull(services);
+ Assert.assertEquals(3, services.size());
+
+ for (MultiImplsInterface service : services) {
+ Assert.assertTrue(service instanceof MultiImpl1 ||
+ service instanceof MultiImpl2 ||
+ service instanceof MultiImpl3);
+ }
+ }
+ }
+
+ @Test
+ public void testGetServices_noImpl_shouldReturnEmptyList() {
+ List<NoImplInterface> services = context.getServices(NoImplInterface.class);
+ Assert.assertNotNull(services);
+ Assert.assertTrue(services.isEmpty());
+ }
+
+
+ // some test interfaces and classes
+
+ public static interface InvalidPriorityInterface {
+ }
+
+ @Priority(value = 50)
+ public static class InvalidPriorityImpl1 implements InvalidPriorityInterface {
+ }
+
+ @Priority(value = 50)
+ public static class InvalidPriorityImpl2 implements InvalidPriorityInterface {
+ }
+
+
+ public static interface MultiImplsInterface {
+ }
+
+ public static class MultiImpl1 implements MultiImplsInterface {
+ }
+
+ @Priority(value = 500)
+ public static class MultiImpl2 implements MultiImplsInterface {
+ }
+
+ @Priority(value = -10)
+ public static class MultiImpl3 implements MultiImplsInterface {
+ }
+
+ private static interface NoImplInterface {
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/internal/PropetiesFileLoaderTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/internal/PropetiesFileLoaderTest.java b/java7/core/src/test/java/org/apache/tamaya/core/internal/PropetiesFileLoaderTest.java
new file mode 100644
index 0000000..c125641
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/internal/PropetiesFileLoaderTest.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.net.URL;
+import java.util.Properties;
+import java.util.Set;
+
+public class PropetiesFileLoaderTest {
+
+
+ @Test
+ public void testResolvePropertiesFiles() throws Exception {
+ Properties expectedProperties = PropertiesFileLoader.load(Thread.currentThread().getContextClassLoader().getResource("testfile.properties"));
+
+ {
+ // with .properties
+ Set<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("testfile.properties");
+ Assert.assertNotNull(urls);
+ Assert.assertFalse(urls.isEmpty());
+
+ Properties properties = PropertiesFileLoader.load(urls.iterator().next());
+ Assert.assertEquals(expectedProperties.size(), properties.size());
+ }
+
+ {
+ // without .properties
+ Set<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("testfile");
+ Assert.assertNotNull(urls);
+ Assert.assertFalse(urls.isEmpty());
+
+ Properties properties = PropertiesFileLoader.load(urls.iterator().next());
+ Assert.assertEquals(expectedProperties.size(), properties.size());
+ }
+
+ {
+ // with a while which doesn't exist
+ Set<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("nonexistingfile.properties");
+ Assert.assertNotNull(urls);
+ Assert.assertTrue(urls.isEmpty());
+ }
+
+ }
+
+ @Test
+ public void testLoad() {
+ Properties properties = PropertiesFileLoader.load(Thread.currentThread().getContextClassLoader().getResource("testfile.properties"));
+
+ Assert.assertNotNull(properties);
+ Assert.assertEquals(5, properties.size());
+
+ for (int i = 1; i < 6; i++) {
+ Assert.assertEquals(properties.getProperty("key" + i), "val" + i);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java b/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java
new file mode 100644
index 0000000..a1ac83c
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/BooleanConverterTest.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the default converter for bytes.
+ */
+public class BooleanConverterTest {
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Byte() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ // trues
+ Boolean valueRead = config.get("tests.converter.boolean.y1", Boolean.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead, Boolean.TRUE);
+ valueRead = config.get("tests.converter.boolean.y2", Boolean.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead, Boolean.TRUE);
+ valueRead = config.get("tests.converter.boolean.yes1", Boolean.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead, Boolean.TRUE);
+ valueRead = config.get("tests.converter.boolean.yes2", Boolean.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead, Boolean.TRUE);
+ valueRead = config.get("tests.converter.boolean.yes3", Boolean.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead, Boolean.TRUE);
+ valueRead = config.get("tests.converter.boolean.true1", Boolean.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead, Boolean.TRUE);
+ valueRead = config.get("tests.converter.boolean.true2", Boolean.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead, Boolean.TRUE);
+ valueRead = config.get("tests.converter.boolean.true3", Boolean.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead, Boolean.TRUE);
+ valueRead = config.get("tests.converter.boolean.t1", Boolean.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead, Boolean.TRUE);
+ valueRead = config.get("tests.converter.boolean.t2", Boolean.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead, Boolean.TRUE);
+ // falses
+ valueRead = config.get("tests.converter.boolean.n1", Boolean.class);
+ assertNotNull(valueRead);
+ assertFalse(valueRead.booleanValue());
+ valueRead = config.get("tests.converter.boolean.n2", Boolean.class);
+ assertNotNull(valueRead);
+ assertFalse(valueRead.booleanValue());
+ valueRead = config.get("tests.converter.boolean.no1", Boolean.class);
+ assertFalse(valueRead);
+ assertFalse(valueRead.booleanValue());
+ valueRead = config.get("tests.converter.boolean.no2", Boolean.class);
+ assertNotNull(valueRead);
+ assertFalse(valueRead.booleanValue());
+ valueRead = config.get("tests.converter.boolean.no3", Boolean.class);
+ assertNotNull(valueRead);
+ assertFalse(valueRead.booleanValue());
+ valueRead = config.get("tests.converter.boolean.false1", Boolean.class);
+ assertNotNull(valueRead);
+ assertFalse(valueRead.booleanValue());
+ valueRead = config.get("tests.converter.boolean.false2", Boolean.class);
+ assertNotNull(valueRead);
+ assertFalse(valueRead.booleanValue());
+ valueRead = config.get("tests.converter.boolean.false3", Boolean.class);
+ assertNotNull(valueRead);
+ assertFalse(valueRead.booleanValue());
+ valueRead = config.get("tests.converter.boolean.f1", Boolean.class);
+ assertNotNull(valueRead);
+ assertFalse(valueRead.booleanValue());
+ valueRead = config.get("tests.converter.boolean.f2", Boolean.class);
+ assertNotNull(valueRead);
+ assertFalse(valueRead.booleanValue());
+ valueRead = config.get("tests.converter.boolean.foo", Boolean.class);
+ assertNull(valueRead);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java b/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java
new file mode 100644
index 0000000..70f54c2
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/ByteConverterTest.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests the default converter for bytes.
+ */
+public class ByteConverterTest {
+
+ /**
+ * Test conversion. The value are provided by
+ * {@link org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
+ * @throws Exception
+ */
+ @Test
+ public void testConvert_Byte() throws Exception {
+ Configuration config = ConfigurationProvider.getConfiguration();
+ Byte valueRead = config.get("tests.converter.byte.decimal", Byte.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead.byteValue(), 101);
+ valueRead = config.get("tests.converter.byte.octal", Byte.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead.byteValue(), Byte.decode("02").byteValue());
+ valueRead = config.get("tests.converter.byte.hex.lowerX", Byte.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead.byteValue(), Byte.decode("0x2F").byteValue());
+ valueRead = config.get("tests.converter.byte.hex.upperX", Byte.class);
+ assertNotNull(valueRead);
+ assertEquals(valueRead.byteValue(), Byte.decode("0X3F").byteValue());
+ valueRead = config.get("tests.converter.byte.foo", Byte.class);
+ assertNull(valueRead);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java b/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java
new file mode 100644
index 0000000..ec7c01f
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.converters;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * Test Property Source used by converter tests.
+ */
+public class ConverterTestsPropertySource implements PropertySource{
+ @Override
+ public int getOrdinal() {
+ return 0;
+ }
+
+ @Override
+ public String getName() {
+ return getClass().getName();
+ }
+
+ @Override
+ public String get(String key) {
+ switch(key){
+ // Bytes
+ case "tests.converter.byte.decimal":
+ return "101";
+ case "tests.converter.byte.octal":
+ return "02";
+ case "tests.converter.byte.hex.lowerX":
+ return "0x2F";
+ case "tests.converter.byte.hex.upperX":
+ return "0X3F";
+ // Boolean
+ case "tests.converter.boolean.y1":
+ return "y";
+ case "tests.converter.boolean.y2":
+ return "Y";
+ case "tests.converter.boolean.yes1":
+ return "yes";
+ case "tests.converter.boolean.yes2":
+ return "Yes";
+ case "tests.converter.boolean.yes3":
+ return "yeS";
+ case "tests.converter.boolean.true1":
+ return "true";
+ case "tests.converter.boolean.true2":
+ return "True";
+ case "tests.converter.boolean.true3":
+ return "trUe";
+ case "tests.converter.boolean.t1":
+ return "t";
+ case "tests.converter.boolean.t2":
+ return "T";
+ case "tests.converter.boolean.n1":
+ return "n";
+ case "tests.converter.boolean.n2":
+ return "N";
+ case "tests.converter.boolean.no1":
+ return "no";
+ case "tests.converter.boolean.no2":
+ return "No";
+ case "tests.converter.boolean.no3":
+ return "nO";
+ case "tests.converter.boolean.false1":
+ return "false";
+ case "tests.converter.boolean.false2":
+ return "False";
+ case "tests.converter.boolean.false3":
+ return "falSe";
+ case "tests.converter.boolean.f1":
+ return "f";
+ case "tests.converter.boolean.f2":
+ return "F";
+ }
+ return null;
+ }
+
+ /*
+ case "yes":
+ case "y":
+ case "true":
+ case "t":
+ return Boolean.TRUE;
+ case "no":
+ case "n":
+ case "false":
+ case "f":
+ */
+ @Override
+ public Map<String, String> getProperties() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public boolean isScannable() {
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java b/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
new file mode 100644
index 0000000..e6b789c
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.test.propertysource;
+
+import org.apache.tamaya.core.propertysource.BasePropertySource;
+import org.apache.tamaya.core.propertysource.DefaultOrdinal;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+public class BasePropertySourceTest {
+
+ @Test
+ public void testGetOrdinal() {
+
+ PropertySource defaultPropertySource = new BasePropertySource() {
+
+ @Override
+ public String getName() {
+ return "testWithDefault";
+ }
+
+ @Override
+ public String get(String key) {
+ return null;
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return Collections.emptyMap();
+ }
+ };
+
+ Assert.assertEquals(DefaultOrdinal.PROPERTY_SOURCE, defaultPropertySource.getOrdinal());
+ Assert.assertEquals(1000, new OverriddenOrdinalPropertySource().getOrdinal());
+
+ // propertySource with invalid ordinal
+ Assert.assertEquals(1, new OverriddenInvalidOrdinalPropertySource().getOrdinal());
+ }
+
+ @Test
+ public void testGet() {
+ Assert.assertEquals("1000", new OverriddenOrdinalPropertySource().get(PropertySource.TAMAYA_ORDINAL));
+ }
+
+ private static class OverriddenOrdinalPropertySource extends BasePropertySource {
+
+ private OverriddenOrdinalPropertySource() {
+ initializeOrdinal(250);
+ }
+
+ @Override
+ public String getName() {
+ return "overriddenOrdinal";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ Map<String, String> map = new HashMap<>(1);
+ map.put(PropertySource.TAMAYA_ORDINAL, "1000");
+ return map;
+ }
+
+ }
+
+ private static class OverriddenInvalidOrdinalPropertySource extends BasePropertySource {
+
+ private OverriddenInvalidOrdinalPropertySource() {
+ initializeOrdinal(1);
+ }
+
+ @Override
+ public String getName() {
+ return "overriddenInvalidOrdinal";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ Map<String, String> map = new HashMap<>(1);
+ map.put(PropertySource.TAMAYA_ORDINAL, "invalid");
+ return map;
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java b/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
new file mode 100644
index 0000000..6ad7790
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.test.propertysource;
+
+import org.apache.tamaya.core.internal.PropertiesFileLoader;
+import org.apache.tamaya.core.propertysource.DefaultOrdinal;
+import org.apache.tamaya.core.propertysource.PropertiesFilePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.net.URL;
+import java.util.Map;
+import java.util.Properties;
+
+public class PropertiesFilePropertySourceTest {
+
+ private PropertiesFilePropertySource testfilePropertySource;
+ private PropertiesFilePropertySource overrideOrdinalPropertySource;
+
+
+ @Before
+ public void initTest() {
+ testfilePropertySource = new PropertiesFilePropertySource(Thread.currentThread().getContextClassLoader().getResource("testfile.properties"));
+ overrideOrdinalPropertySource = new PropertiesFilePropertySource(Thread.currentThread().getContextClassLoader().getResource("overrideOrdinal.properties"));
+ }
+
+
+ @Test
+ public void testGetOrdinal() {
+ Assert.assertEquals(DefaultOrdinal.FILE_PROPERTIES, testfilePropertySource.getOrdinal());
+ Assert.assertEquals(Integer.parseInt(overrideOrdinalPropertySource.get(PropertySource.TAMAYA_ORDINAL)), overrideOrdinalPropertySource.getOrdinal());
+ }
+
+
+ @Test
+ public void testGet() {
+ Assert.assertEquals("val3", testfilePropertySource.get("key3"));
+ Assert.assertEquals("myval5", overrideOrdinalPropertySource.get("mykey5"));
+ Assert.assertNull(testfilePropertySource.get("nonpresentkey"));
+ }
+
+
+ @Test
+ public void testGetProperties() throws Exception {
+ Properties expectedProperties = PropertiesFileLoader.load(new URL(testfilePropertySource.getName()));
+
+ Assert.assertEquals(expectedProperties.size(), testfilePropertySource.getProperties().size());
+
+ for (Map.Entry<String, String> entry : testfilePropertySource.getProperties().entrySet()) {
+ Assert.assertEquals(expectedProperties.getProperty(entry.getKey()), entry.getValue());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java b/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
new file mode 100644
index 0000000..35ebc80
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.test.propertysource;
+
+import org.apache.tamaya.core.propertysource.DefaultOrdinal;
+import org.apache.tamaya.core.propertysource.SystemPropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Map;
+import java.util.Properties;
+
+public class SystemPropertySourceTest {
+
+ private SystemPropertySource testPropertySource = new SystemPropertySource();
+
+
+ @Test
+ public void testGetOrdinal() throws Exception {
+
+ // test the default ordinal
+ Assert.assertEquals(DefaultOrdinal.SYSTEM_PROPERTIES, testPropertySource.getOrdinal());
+
+ // set the ordinal to 1000
+ System.setProperty(PropertySource.TAMAYA_ORDINAL, "1000");
+ Assert.assertEquals(1000, new SystemPropertySource().getOrdinal()); // currently its not possible to change ordinal at runtime
+
+ // reset it to not destroy other tests!!
+ System.clearProperty(PropertySource.TAMAYA_ORDINAL);
+ }
+
+ @Test
+ public void testGetName() throws Exception {
+ Assert.assertEquals("system-properties", new SystemPropertySource().getName());
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ String propertyKeyToCheck = System.getProperties().stringPropertyNames().iterator().next();
+
+ String property = testPropertySource.get(propertyKeyToCheck);
+ Assert.assertTrue("Property '" + propertyKeyToCheck + "' is not present in " + SystemPropertySource.class.getSimpleName(),
+ property != null);
+ Assert.assertEquals(System.getProperty(propertyKeyToCheck), property);
+
+
+ }
+
+ @Test
+ public void testGetProperties() throws Exception {
+ checkWithSystemProperties(testPropertySource.getProperties());
+
+ // modify system properties
+ System.setProperty("test", "myTestVal");
+
+ checkWithSystemProperties(testPropertySource.getProperties());
+
+ // cleanup
+ System.clearProperty("test");
+
+ // no modifaction
+ try {
+ testPropertySource.getProperties().put("add.new.keys", "must throw exception");
+ Assert.fail(UnsupportedOperationException.class.getName() + " expected");
+ }
+ catch (UnsupportedOperationException e) {
+ // expected -> all is fine
+ }
+ }
+
+ private void checkWithSystemProperties(Map<String, String> toCheck) {
+ Properties systemEntries = System.getProperties();
+
+ Assert.assertEquals("size of System.getProperties().entrySet() must be the same as SystemPropertySrouce.getProperties().entrySet()",
+ systemEntries.entrySet().size(), toCheck.size());
+
+ for (Map.Entry<String, String> propertySourceEntry : toCheck.entrySet()) {
+
+ Assert.assertEquals("Entry values for key '" + propertySourceEntry.getKey() + "' do not match",
+ systemEntries.getProperty(propertySourceEntry.getKey()), propertySourceEntry.getValue());
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java b/java7/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
new file mode 100644
index 0000000..6e558d7
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.test.provider;
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.core.provider.JavaConfigurationProvider;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collection;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.notNullValue;
+
+public class JavaConfigurationProviderTest {
+
+ @Test
+ public void testJavaConfigurationProvider() {
+
+ Collection<PropertySource> propertySources = new JavaConfigurationProvider().getPropertySources();
+
+ assertThat(propertySources, notNullValue());
+ assertThat(propertySources, hasSize(1));
+
+ PropertySource propertySource = propertySources.iterator().next();
+
+ assertThat(propertySource.getProperties().keySet(), hasSize(5));
+
+ for (int i = 1; i < 6; i++) {
+ String key = "confkey" + i;
+ String value = "javaconf-value" + i;
+
+ Assert.assertEquals(value, propertySource.get(key));
+
+ // check if we had our key in configuration.current
+ Assert.assertTrue(ConfigurationProvider.getConfiguration().getProperties().containsKey(key));
+ Assert.assertEquals(value, ConfigurationProvider.getConfiguration().get(key));
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java b/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java
new file mode 100644
index 0000000..74f3aff
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.testdata;
+
+import org.apache.tamaya.core.propertysource.BasePropertySource;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Test provider reading properties from classpath:cfg/defaults/**.properties.
+ */
+public class TestPropertyDefaultSource extends BasePropertySource{
+
+ private Map<String,String> properties = new HashMap<>();
+
+ public TestPropertyDefaultSource() {
+ initializeOrdinal(100);
+ properties.put("name","Anatole");
+ properties.put("name2","Sabine");
+ properties = Collections.unmodifiableMap(properties);
+ }
+
+ @Override
+ public String getName() {
+ return "default-testdata-properties";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java b/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java
new file mode 100644
index 0000000..6faa831
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.testdata;
+
+import org.apache.tamaya.spi.PropertyFilter;
+
+import javax.annotation.Priority;
+
+/**
+ * Simple PropertyFilter that filters exact one value, registered using ServiceLoader.
+ */
+@Priority(100)
+public class TestPropertyFilter implements PropertyFilter{
+ @Override
+ public String filterProperty(String key, String valueToBeFiltered) {
+ if("name4".equals(key)){
+ return valueToBeFiltered + "(filtered)";
+ }
+ return valueToBeFiltered;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java b/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java
new file mode 100644
index 0000000..948ff26
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.testdata;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.spi.PropertyFilter;
+
+import javax.annotation.Priority;
+
+/**
+ * Simple PropertyFilter that filters exact one value, registered using ServiceLoader.
+ */
+@Priority(200)
+public class TestPropertyFilterRemoving implements PropertyFilter{
+ @Override
+ public String filterProperty(String key, String valueToBeFiltered) {
+ if("name5".equals(key)){
+ return null;
+ }
+ else if("name3".equals(key)){
+ return "Mapped to name: " + ConfigurationProvider.getConfiguration().get("name");
+ }
+ return valueToBeFiltered;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java b/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java
new file mode 100644
index 0000000..7288b9f
--- /dev/null
+++ b/java7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.testdata;
+
+import org.apache.tamaya.core.propertysource.BasePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Test provider reading properties from classpath:cfg/final/**.properties.
+ */
+public class TestPropertySourceProvider implements PropertySourceProvider {
+
+ private List<PropertySource> list = new ArrayList<>();
+
+ public TestPropertySourceProvider(){
+ list.add(new MyPropertySource());
+ list = Collections.unmodifiableList(list);
+ }
+
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+ return list;
+ }
+
+ private static class MyPropertySource extends BasePropertySource {
+
+ private Map<String, String> properties = new HashMap<>();
+
+ public MyPropertySource() {
+ initializeOrdinal(200);
+ properties.put("name", "Robin");
+ properties.put("name3", "Lukas");
+ properties.put("name4", "Sereina");
+ properties.put("name5", "Benjamin");
+ properties = Collections.unmodifiableMap(properties);
+ }
+
+ @Override
+ public String getName() {
+ return "final-testdata-properties";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface b/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface
new file mode 100644
index 0000000..9d96b65
--- /dev/null
+++ b/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityInterface
@@ -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.core.internal.DefaultServiceContextTest$InvalidPriorityImpl1
+org.apache.tamaya.core.internal.DefaultServiceContextTest$InvalidPriorityImpl2
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImplsInterface
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImplsInterface b/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImplsInterface
new file mode 100644
index 0000000..2e24ed0
--- /dev/null
+++ b/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImplsInterface
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImpl1
+org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImpl2
+org.apache.tamaya.core.internal.DefaultServiceContextTest$MultiImpl3
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter b/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
new file mode 100644
index 0000000..59bbab3
--- /dev/null
+++ b/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
@@ -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 current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.testdata.TestPropertyFilter
+org.apache.tamaya.core.testdata.TestPropertyFilterRemoving
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
new file mode 100644
index 0000000..409c9cb
--- /dev/null
+++ b/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
@@ -0,0 +1,22 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.testdata.TestPropertyDefaultSource
+org.apache.tamaya.core.propertysource.SystemPropertySource
+org.apache.tamaya.core.propertysource.EnvironmentPropertySource
+org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
new file mode 100644
index 0000000..9c352f4
--- /dev/null
+++ b/java7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
@@ -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 current the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.tamaya.core.testdata.TestPropertySourceProvider
+org.apache.tamaya.core.provider.JavaConfigurationProvider
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/resources/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/javaconfiguration.properties b/java7/core/src/test/resources/javaconfiguration.properties
new file mode 100644
index 0000000..33beabb
--- /dev/null
+++ b/java7/core/src/test/resources/javaconfiguration.properties
@@ -0,0 +1,22 @@
+# 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.
+
+confkey1=javaconf-value1
+confkey2=javaconf-value2
+confkey3=javaconf-value3
+confkey4=javaconf-value4
+confkey5=javaconf-value5
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/resources/overrideOrdinal.properties
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/overrideOrdinal.properties b/java7/core/src/test/resources/overrideOrdinal.properties
new file mode 100644
index 0000000..5384d91
--- /dev/null
+++ b/java7/core/src/test/resources/overrideOrdinal.properties
@@ -0,0 +1,25 @@
+# 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.
+
+#override ordinal
+tamaya.ordinal=16784
+
+mykey1=myval1
+mykey2=myval2
+mykey3=myval3
+mykey4=myval4
+mykey5=myval5
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/core/src/test/resources/testfile.properties
----------------------------------------------------------------------
diff --git a/java7/core/src/test/resources/testfile.properties b/java7/core/src/test/resources/testfile.properties
new file mode 100644
index 0000000..4dc3b91
--- /dev/null
+++ b/java7/core/src/test/resources/testfile.properties
@@ -0,0 +1,22 @@
+# 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.
+
+key1=val1
+key2=val2
+key3=val3
+key4=val4
+key5=val5
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/bc62f716/java7/pom.xml
----------------------------------------------------------------------
diff --git a/java7/pom.xml b/java7/pom.xml
index d4a8c7b..740ff1d 100644
--- a/java7/pom.xml
+++ b/java7/pom.xml
@@ -38,9 +38,7 @@ under the License.
<modules>
<module>api</module>
-<!--
<module>core</module>
--->
</modules>
<build>