You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2017/12/10 22:03:29 UTC
[06/23] incubator-tamaya git commit: Reimplemented (also simjplified)
Tamaya core completely based on latest JSR API. Moved prior Tamaya API into
compat module.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationTest.java
----------------------------------------------------------------------
diff --git a/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationTest.java b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationTest.java
new file mode 100644
index 0000000..4711dc5
--- /dev/null
+++ b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationTest.java
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport;
+
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.*;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+public class DefaultConfigurationTest {
+
+ /**
+ * Tests for get(String)
+ */
+ @Test(expected = NullPointerException.class)
+ public void getDoesNotAcceptNull() {
+ DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
+
+ c.get(null);
+ }
+
+ /**
+ * Tests for get(String, Class)
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Test(expected = NullPointerException.class)
+ public void getDoesNotAcceptNullForClassTargetType() {
+ DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
+
+ c.get("a", (Class) null);
+ }
+
+ /**
+ * Tests for get(String, TypeLiteral)
+ */
+ @Test(expected = NullPointerException.class)
+ public void getDoesNotAcceptNullForTypeLiteralTargetType() {
+ DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
+
+ c.get("a", (TypeLiteral<?>)null);
+ }
+
+ /**
+ * Tests for getOrDefault(String, Class, String)
+ */
+ @Test(expected = NullPointerException.class)
+ public void getOrDefaultDoesNotAcceptNullAsKeyForThreeParameterVariant() {
+ DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
+
+ c.getOrDefault(null, String.class, "ok");
+ }
+
+ @Test
+ public void getOrDefaultDoesAcceptNullAsDefaultValueForThreeParameterVariant() {
+ DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
+
+ assertNull(c.getOrDefault("a", String.class, null));
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Test(expected = NullPointerException.class)
+ public void getOrDefaultDoesNotAcceptNullAsTargetTypeForThreeParameterVariant() {
+ DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
+
+ c.getOrDefault("a", (Class)null, "b");
+ }
+
+ /**
+ * Tests for getOrDefault(String, TypeLiteral, String)
+ */
+ @Test(expected = NullPointerException.class)
+ public void getOrDefaultDoesNotAcceptNullAsKeyForThreeParameterVariantSecondIsTypeLiteral() {
+ DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
+
+ c.getOrDefault(null, TypeLiteral.of(String.class), "ok");
+ }
+
+ @Test
+ public void getOrDefaultDoesAcceptNullAsDefaultValueForThreeParameterVariantSecondIsTypeLiteral() {
+ DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
+
+ assertNull(c.getOrDefault("a", TypeLiteral.of(String.class), null));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void getOrDefaultDoesNotAcceptNullAsTargetTypeForThreeParameterVariantSecondIsTypeLiteral() {
+ DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
+
+ c.getOrDefault("a", (TypeLiteral<String>) null, "b");
+ }
+
+ /**
+ * Tests for getOrDefault(String, String)
+ */
+ @Test(expected = NullPointerException.class)
+ public void getOrDefaultDoesNotAcceptNullAsKeyForTwoParameterVariantDefaultValueIsSecond() {
+ DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
+
+ c.getOrDefault(null, "ok");
+ }
+
+ @Test
+ public void getOrDefaultDoesAcceptNullAsDefaultValueForTwoParameterVariantDefaultValueIsSecond() {
+ DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
+ assertNull(c.getOrDefault("a", null));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void with_Null() {
+ DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
+
+ c.with(null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void query_Null() {
+ DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
+
+ c.query(null);
+ }
+
+ @Test
+ public void with() {
+ DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
+ assertEquals(c.with(config -> config), c);
+ }
+
+ @Test
+ public void query() {
+ DefaultConfiguration c = new DefaultConfiguration(new DummyConfigurationContext());
+ assertEquals(c.query(config -> "testQ"), "testQ");
+ }
+
+ public static class DummyConfigurationContext implements ConfigurationContext {
+ @Override
+ public void addPropertySources(PropertySource... propertySources) {
+ throw new RuntimeException("Method should be never called in this test");
+ }
+
+ @Override
+ public List<PropertySource> getPropertySources() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public PropertySource getPropertySource(String name) {
+ throw new RuntimeException("Method should be never called in this test");
+ }
+
+ @Override
+ public <T> void addPropertyConverter(TypeLiteral<T> type, PropertyConverter<T> propertyConverter) {
+ throw new RuntimeException("Method should be never called in this test");
+ }
+
+ @Override
+ public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> type) {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public List<PropertyFilter> getPropertyFilters() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy() {
+ throw new RuntimeException("Method should be never called in this test");
+ }
+
+ @Override
+ public ConfigurationContextBuilder toBuilder() {
+ throw new RuntimeException("Method should be never called in this test");
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultServiceContextTest.java
----------------------------------------------------------------------
diff --git a/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultServiceContextTest.java b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultServiceContextTest.java
new file mode 100644
index 0000000..9a25528
--- /dev/null
+++ b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultServiceContextTest.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.ConfigurationProviderSpi;
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.annotation.Priority;
+import java.util.Collection;
+import java.util.List;
+
+public class DefaultServiceContextTest {
+
+ /**
+ * context to test
+ */
+ private final DefaultServiceContext context = new DefaultServiceContext();
+
+
+ @Test
+ public void testGetService() {
+ ConfigurationProviderSpi providerSpi = context.getService(ConfigurationProviderSpi.class);
+ Assert.assertNotNull(providerSpi);
+ Assert.assertTrue(providerSpi instanceof TestConfigurationProvider);
+ }
+
+ @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() {
+ {
+ Collection<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());
+
+ Assert.assertTrue(services.get(0) instanceof MultiImpl2);
+ Assert.assertTrue(services.get(1) instanceof MultiImpl1);
+ Assert.assertTrue(services.get(2) instanceof MultiImpl3);
+ }
+ }
+
+ @Test
+ public void testGetServices_redundantAccessToServices() {
+ for(int i=0;i<10;i++){
+ Collection<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);
+ }
+ }
+ }
+
+ @Test
+ public void testGetServices_noImpl_shouldReturnEmptyList() {
+ Collection<NoImplInterface> services = context.getServices(NoImplInterface.class);
+ Assert.assertNotNull(services);
+ Assert.assertTrue(services.isEmpty());
+ }
+
+
+ // some test interfaces and classes
+
+ public interface InvalidPriorityInterface {
+ }
+
+ @Priority(value = 50)
+ public static class InvalidPriorityImpl1 implements InvalidPriorityInterface {
+ }
+
+ @Priority(value = 50)
+ public static class InvalidPriorityImpl2 implements InvalidPriorityInterface {
+ }
+
+
+ public 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 interface NoImplInterface {
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/EmptyConfigurationContext.java
----------------------------------------------------------------------
diff --git a/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/EmptyConfigurationContext.java b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/EmptyConfigurationContext.java
new file mode 100644
index 0000000..c5286e0
--- /dev/null
+++ b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/EmptyConfigurationContext.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.spisupport;
+
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.*;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+public class EmptyConfigurationContext implements ConfigurationContext{
+
+ private static final ConfigurationContext INSTANCE = new EmptyConfigurationContext();
+
+ @Override
+ public void addPropertySources(PropertySource... propertySources) {
+ }
+
+ @Override
+ public List<PropertySource> getPropertySources() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public PropertySource getPropertySource(String name) {
+ return null;
+ }
+
+ @Override
+ public <T> void addPropertyConverter(TypeLiteral<T> type, PropertyConverter<T> propertyConverter) {
+ }
+
+ @Override
+ public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> type) {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public List<PropertyFilter> getPropertyFilters() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy() {
+ return PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_POLICY;
+ }
+
+ @Override
+ public ConfigurationContextBuilder toBuilder() {
+ return EmptyConfigurationContextBuilder.instance();
+ }
+
+ public static ConfigurationContext instance() {
+ return INSTANCE;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/EmptyConfigurationContextBuilder.java
----------------------------------------------------------------------
diff --git a/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/EmptyConfigurationContextBuilder.java b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/EmptyConfigurationContextBuilder.java
new file mode 100644
index 0000000..4f17d9a
--- /dev/null
+++ b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/EmptyConfigurationContextBuilder.java
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport;
+
+import com.sun.org.apache.bcel.internal.generic.INSTANCEOF;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.*;
+
+import java.util.*;
+
+public class EmptyConfigurationContextBuilder implements ConfigurationContextBuilder{
+
+ private static final ConfigurationContextBuilder INSTANCE = new EmptyConfigurationContextBuilder();
+
+ @Override
+ public ConfigurationContextBuilder setContext(ConfigurationContext context) {
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder addPropertySources(PropertySource... propertySources) {
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder addPropertySources(Collection<PropertySource> propertySources) {
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder addDefaultPropertySources() {
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder removePropertySources(PropertySource... propertySources) {
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder removePropertySources(Collection<PropertySource> propertySources) {
+ return this;
+ }
+
+ @Override
+ public List<PropertySource> getPropertySources() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public List<PropertyFilter> getPropertyFilters() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public Map<TypeLiteral<?>, Collection<PropertyConverter<?>>> getPropertyConverter() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public ConfigurationContextBuilder increasePriority(PropertySource propertySource) {
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder decreasePriority(PropertySource propertySource) {
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder highestPriority(PropertySource propertySource) {
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder lowestPriority(PropertySource propertySource) {
+ return null;
+ }
+
+ @Override
+ public ConfigurationContextBuilder addPropertyFilters(PropertyFilter... filters) {
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder addPropertyFilters(Collection<PropertyFilter> filters) {
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder addDefaultPropertyFilters() {
+ return null;
+ }
+
+ @Override
+ public ConfigurationContextBuilder removePropertyFilters(PropertyFilter... filters) {
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder removePropertyFilters(Collection<PropertyFilter> filters) {
+ return this;
+ }
+
+ @Override
+ public <T> ConfigurationContextBuilder addPropertyConverters(TypeLiteral<T> typeToConvert, PropertyConverter<T>... propertyConverters) {
+ return null;
+ }
+
+ @Override
+ public <T> ConfigurationContextBuilder addPropertyConverters(TypeLiteral<T> typeToConvert, Collection<PropertyConverter<T>> propertyConverters) {
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder addDefaultPropertyConverters() {
+ return this;
+ }
+
+ @Override
+ public <T> ConfigurationContextBuilder removePropertyConverters(TypeLiteral<T> typeToConvert, PropertyConverter<T>... propertyConverters) {
+ return this;
+ }
+
+ @Override
+ public <T> ConfigurationContextBuilder removePropertyConverters(TypeLiteral<T> typeToConvert, Collection<PropertyConverter<T>> propertyConverters) {
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder removePropertyConverters(TypeLiteral<?> typeToConvert) {
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder sortPropertySources(Comparator<PropertySource> comparator) {
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder sortPropertyFilter(Comparator<PropertyFilter> comparator) {
+ return this;
+ }
+
+ @Override
+ public ConfigurationContextBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy policy) {
+ return this;
+ }
+
+ @Override
+ public ConfigurationContext build() {
+ return EmptyConfigurationContext.instance();
+ }
+
+ public static ConfigurationContextBuilder instance() {
+ return INSTANCE;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/EnumConverterTest.java
----------------------------------------------------------------------
diff --git a/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/EnumConverterTest.java b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/EnumConverterTest.java
new file mode 100644
index 0000000..8391c3a
--- /dev/null
+++ b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/EnumConverterTest.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport;
+
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConversionContext;
+import org.junit.Test;
+
+import java.math.RoundingMode;
+import java.util.Arrays;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+/**
+ * Test class testing the {@link EnumConverter} class.
+ */
+public class EnumConverterTest {
+
+ private final EnumConverter<RoundingMode> testConverter = new EnumConverter<>(RoundingMode.class);
+
+ private final ConversionContext DUMMY_CONTEXT = new ConversionContext.Builder("someKey", TypeLiteral.of(Enum.class))
+ .build();
+
+ @Test
+ public void testConversionWithMixedCasing() {
+ for (String input : Arrays.asList(RoundingMode.CEILING.toString(), "ceiling", "CeiLinG")) {
+ assertEquals(RoundingMode.CEILING, testConverter.convert(input, DUMMY_CONTEXT));
+ }
+ }
+
+ @Test
+ public void testConvert_OtherValue() {
+ assertNull(testConverter.convert("fooBars", DUMMY_CONTEXT));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/PriorityServiceComparatorTest.java
----------------------------------------------------------------------
diff --git a/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/PriorityServiceComparatorTest.java b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/PriorityServiceComparatorTest.java
new file mode 100644
index 0000000..b8e5555
--- /dev/null
+++ b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/PriorityServiceComparatorTest.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.spisupport;
+
+import org.apache.tamaya.spisupport.propertysource.SystemPropertySource;
+import org.junit.Test;
+
+import javax.annotation.Priority;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by atsticks on 12.09.16.
+ */
+public class PriorityServiceComparatorTest {
+
+ @Test
+ public void compare() throws Exception {
+ assertTrue(PriorityServiceComparator.getInstance().compare("a", "b")==0);
+ assertTrue(PriorityServiceComparator.getInstance().compare(getClass(), getClass())==0);
+ assertTrue(PriorityServiceComparator.getInstance().compare(new A(), new SystemPropertySource())==-1);
+ assertTrue(PriorityServiceComparator.getInstance().compare(new SystemPropertySource(), new A())==1);
+ }
+
+ @Priority(100)
+ private static final class A{}
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java
----------------------------------------------------------------------
diff --git a/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java
new file mode 100644
index 0000000..b91e6e4
--- /dev/null
+++ b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport;
+
+
+
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.TypeLiteral;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
+
+public class PropertyConverterManagerTest {
+
+ private final ConversionContext DUMMY_CONTEXT = new ConversionContext.Builder(
+ "someKey", TypeLiteral.of(Object.class)).build();
+
+ @Test
+ public void customTypeWithFactoryMethodOfIsRecognizedAsSupported() {
+ PropertyConverterManager manager = new PropertyConverterManager(true);
+
+ assertThat(manager.isTargetTypeSupported(TypeLiteral.of(MyType.class)),
+ is(true));
+ }
+
+ @Test
+ public void factoryMethodOfIsUsedAsConverter() {
+ PropertyConverterManager manager = new PropertyConverterManager(true);
+
+ List<PropertyConverter<MyType>> converters = manager.getPropertyConverters(
+ (TypeLiteral)TypeLiteral.of(MyType.class));
+
+ assertThat(converters, hasSize(1));
+
+ PropertyConverter<MyType> converter = converters.get(0);
+
+ Object result = converter.convert("IN", DUMMY_CONTEXT);
+
+ assertThat(result, notNullValue());
+ assertThat(result, instanceOf(MyType.class));
+ assertThat(((MyType)result).getValue(), equalTo("IN"));
+ }
+
+ @Test
+ public void testDirectConverterMapping(){
+ PropertyConverterManager manager = new PropertyConverterManager(true);
+ List<PropertyConverter<C>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(C.class)));
+ assertThat(converters, hasSize(1));
+
+ PropertyConverter<C> converter = converters.get(0);
+ C result = converter.convert("testDirectConverterMapping", DUMMY_CONTEXT);
+
+ assertThat(result, notNullValue());
+ assertThat(result, instanceOf(C.class));
+ assertThat((result).getInValue(), equalTo("testDirectConverterMapping"));
+ }
+
+ @Test
+ public void testDirectSuperclassConverterMapping(){
+ PropertyConverterManager manager = new PropertyConverterManager(true);
+ List<PropertyConverter<B>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
+ assertThat(converters, hasSize(1));
+ converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
+ assertThat(converters, hasSize(1));
+
+ PropertyConverter<B> converter = converters.get(0);
+ B result = converter.convert("testDirectSuperclassConverterMapping", DUMMY_CONTEXT);
+
+ assertThat(result, notNullValue());
+ assertThat(result, instanceOf(C.class));
+ assertThat(((C)result).getInValue(), equalTo("testDirectSuperclassConverterMapping"));
+ }
+
+ @Test
+ public void testMultipleConverterLoad(){
+ PropertyConverterManager manager = new PropertyConverterManager(true);
+ List<PropertyConverter<B>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
+ assertThat(converters, hasSize(1));
+ manager = new PropertyConverterManager(true);
+ converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
+ assertThat(converters, hasSize(1));
+ }
+
+ @Test
+ public void testTransitiveSuperclassConverterMapping(){
+ PropertyConverterManager manager = new PropertyConverterManager(true);
+ List<PropertyConverter<A>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(A.class)));
+ assertThat(converters, hasSize(1));
+
+ PropertyConverter<A> converter = converters.get(0);
+ A result = converter.convert("testTransitiveSuperclassConverterMapping", DUMMY_CONTEXT);
+
+ assertThat(result, notNullValue());
+ assertThat(result, instanceOf(C.class));
+ assertThat(((C)result).getInValue(), equalTo("testTransitiveSuperclassConverterMapping"));
+ }
+
+ @Test
+ public void testDirectInterfaceMapping(){
+ PropertyConverterManager manager = new PropertyConverterManager(true);
+ List<PropertyConverter<Readable>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(Readable.class)));
+ assertThat(converters, hasSize(1));
+
+ PropertyConverter<Readable> converter = converters.get(0);
+ Readable result = converter.convert("testDirectInterfaceMapping", DUMMY_CONTEXT);
+
+ assertThat(result, notNullValue());
+ assertThat(result, instanceOf(C.class));
+ assertThat(((C)result).getInValue(), equalTo("testDirectInterfaceMapping"));
+ }
+
+ @Test
+ public void testTransitiveInterfaceMapping1(){
+ PropertyConverterManager manager = new PropertyConverterManager(true);
+ List<PropertyConverter<Runnable>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(Runnable.class)));
+ assertThat(converters, hasSize(1));
+
+ PropertyConverter<Runnable> converter = converters.get(0);
+ Runnable result = converter.convert("testTransitiveInterfaceMapping1", DUMMY_CONTEXT);
+
+ assertThat(result, notNullValue());
+ assertThat(result, instanceOf(C.class));
+ assertThat(((C)result).getInValue(), equalTo("testTransitiveInterfaceMapping1"));
+ }
+
+ @Test
+ public void testTransitiveInterfaceMapping2(){
+ PropertyConverterManager manager = new PropertyConverterManager(true);
+ List<PropertyConverter<AutoCloseable>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(AutoCloseable.class)));
+ assertThat(converters, hasSize(1));
+
+ PropertyConverter<AutoCloseable> converter = converters.get(0);
+ AutoCloseable result = converter.convert("testTransitiveInterfaceMapping2", DUMMY_CONTEXT);
+
+ assertThat(result, notNullValue());
+ assertThat(result, instanceOf(C.class));
+ assertThat(((C)result).getInValue(), equalTo("testTransitiveInterfaceMapping2"));
+ }
+
+ public static class MyType {
+ private final String typeValue;
+
+ private MyType(String value) {
+ typeValue = value;
+ }
+
+ public static MyType of(String source) {
+ return new MyType(source);
+ }
+
+ public String getValue() {
+ return typeValue;
+ }
+
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyFilterComparatorTest.java
----------------------------------------------------------------------
diff --git a/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyFilterComparatorTest.java b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyFilterComparatorTest.java
new file mode 100644
index 0000000..9a212f7
--- /dev/null
+++ b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyFilterComparatorTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport;
+
+import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertyValue;
+import org.apache.tamaya.spisupport.PropertyFilterComparator;
+import org.junit.Test;
+
+import javax.annotation.Priority;
+
+import java.util.Comparator;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PropertyFilterComparatorTest {
+
+ @Test
+ public void comparationOfFiltersWithSamePriorityIsCorrect() {
+ Comparator<PropertyFilter> comparator = PropertyFilterComparator.getInstance();
+
+ int result = comparator.compare(new PropertyFilterA(), new PropertyFilterA());
+
+ assertThat(result).isEqualTo(0);
+ }
+
+ @Test
+ public void comparationOfFiltersFirstHigherThenSecondWorksCorrectly() {
+ Comparator<PropertyFilter> comparator = PropertyFilterComparator.getInstance();
+
+ int result = comparator.compare(new PropertyFilterB(), new PropertyFilterA());
+
+ assertThat(result).isGreaterThan(0);
+ }
+
+ @Test
+ public void comparationOfFiltersSecondHigherThenFirstWorksCorrectly() {
+ Comparator<PropertyFilter> comparator = PropertyFilterComparator.getInstance();
+
+ int result = comparator.compare(new PropertyFilterA(), new PropertyFilterB());
+
+ assertThat(result).isLessThan(0);
+ }
+
+
+ @Priority(1)
+ private static class PropertyFilterA implements PropertyFilter {
+ public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
+ throw new RuntimeException("Not implemented or look at me!");
+ }
+ }
+
+ @Priority(2)
+ private static class PropertyFilterB implements PropertyFilter {
+ public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
+ throw new RuntimeException("Not implemented or look at me!");
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java
----------------------------------------------------------------------
diff --git a/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java
new file mode 100644
index 0000000..2822cb6
--- /dev/null
+++ b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport;
+
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyValue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for {@link RegexPropertyFilter}. Created by anatole on 11.02.16.
+ */
+public class RegexPropertyFilterTest {
+
+ private static PropertyValue prop1 = PropertyValue.of("test1", "test1", "test");
+ private static PropertyValue prop2 = PropertyValue.of("test2", "test2", "test");
+ private static PropertyValue prop3 = PropertyValue.of("test1.test3", "test.test3", "test");
+ private static ConfigurationContext configContext = EmptyConfigurationContext.instance();
+
+ @org.junit.Test
+ public void testFilterProperty() throws Exception {
+ RegexPropertyFilter filter = new RegexPropertyFilter();
+ filter.setIncludes("test1.*");
+ Map<String,PropertyValue> map = new HashMap<>();
+ map.put(prop1.getKey(), prop1);
+ map.put(prop2.getKey(), prop2);
+ map.put(prop3.getKey(), prop3);
+ assertEquals(filter.filterProperty(prop1, new FilterContext(prop1, configContext)), prop1);
+ assertNull(filter.filterProperty(prop2, new FilterContext(prop2, configContext)));
+ assertEquals(filter.filterProperty(
+ prop3,
+ new FilterContext(prop3, map, configContext)), prop3);
+ assertEquals(filter.filterProperty(
+ prop3,
+ new FilterContext(prop3, map, configContext)), prop3);
+ filter = new RegexPropertyFilter();
+ filter.setIncludes("test1.*");
+ assertNotNull(filter.filterProperty(prop1, new FilterContext(prop1, map, configContext)));
+ assertNull(filter.filterProperty(prop2, new FilterContext(prop2, map, configContext)));
+ assertNotNull(filter.filterProperty(prop3, new FilterContext(prop3, map, configContext)));
+ }
+
+ @org.junit.Test
+ public void testToString() throws Exception {
+ RegexPropertyFilter filter = new RegexPropertyFilter();
+ filter.setIncludes("test\\..*");
+ assertTrue(filter.toString().contains("test\\..*"));
+ assertTrue(filter.toString().contains("RegexPropertyFilter"));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/TestConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/TestConfigurationProvider.java b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/TestConfigurationProvider.java
new file mode 100644
index 0000000..9af9a5c
--- /dev/null
+++ b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/TestConfigurationProvider.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.spi.ConfigurationBuilder;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ConfigurationContextBuilder;
+import org.apache.tamaya.spi.ConfigurationProviderSpi;
+import org.osgi.service.component.annotations.Component;
+
+import java.util.Objects;
+
+/**
+ * Implementation of the Configuration API. This class uses the current {@link ConfigurationContext} to evaluate the
+ * chain of {@link org.apache.tamaya.spi.PropertySource} and {@link org.apache.tamaya.spi.PropertyFilter}
+ * instance to evaluate the current Configuration.
+ */
+@Component(service = ConfigurationProviderSpi.class)
+public class TestConfigurationProvider implements ConfigurationProviderSpi {
+
+ private Configuration config = new DefaultConfigurationBuilder()
+ .addDefaultPropertyConverters()
+ .addDefaultPropertyFilters()
+ .addDefaultPropertySources()
+ .build();
+ @Override
+ public Configuration getConfiguration() {
+ return config;
+ }
+
+ @Override
+ public Configuration createConfiguration(ConfigurationContext context) {
+ return new DefaultConfiguration(context);
+ }
+
+ @Override
+ public ConfigurationBuilder getConfigurationBuilder() {
+ return new DefaultConfigurationBuilder();
+ }
+
+ @Override
+ public ConfigurationContextBuilder getConfigurationContextBuilder() {
+ return new DefaultConfigurationContextBuilder();
+ }
+
+ @Override
+ public void setConfiguration(Configuration config) {
+ Objects.requireNonNull(config.getContext());
+ this.config = Objects.requireNonNull(config);
+ }
+
+ @Override
+ public boolean isConfigurationSettable() {
+ return true;
+ }
+
+ /**
+ * @deprecated use {@link Configuration#getContext()} instead.
+ */
+ @Deprecated
+ @Override
+ public ConfigurationContext getConfigurationContext() {
+ return this.config.getContext();
+ }
+
+ /**
+ * @deprecated the context should be given upon creation of the {@link Configuration}
+ */
+ @Deprecated
+ @Override
+ public void setConfigurationContext(ConfigurationContext context){
+ this.config = new DefaultConfigurationBuilder(context).build();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/BasePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/BasePropertySourceTest.java b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/BasePropertySourceTest.java
new file mode 100644
index 0000000..eb549a4
--- /dev/null
+++ b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/BasePropertySourceTest.java
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport.propertysource;
+
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
+import org.apache.tamaya.spisupport.PropertySourceComparator;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.*;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class BasePropertySourceTest {
+
+ @Test
+ public void isAlwaysScanable() {
+ BasePropertySource bs = new BasePropertySource() {
+ @Override
+ public Map<String, PropertyValue> getProperties() {
+ return Collections.emptyMap();
+ }
+ };
+
+ assertThat(bs.isScannable()).isTrue();
+ }
+
+ @Test
+ public void givenOrdinalOverwritesGivenDefaulOrdinal() {
+ BasePropertySource bs = new BasePropertySource() {
+ @Override
+ public Map<String, PropertyValue> getProperties() {
+ return Collections.emptyMap();
+ }
+ };
+
+ bs.setDefaultOrdinal(10);
+
+ assertThat(bs.getDefaultOrdinal()).isEqualTo(10);
+ assertThat(bs.getOrdinal()).isEqualTo(10);
+
+ bs.setOrdinal(20);
+
+ assertThat(bs.getOrdinal()).isEqualTo(20);
+ }
+
+ @Test
+ public void testGetOrdinal() {
+
+ PropertySource defaultPropertySource = new BasePropertySource(56) {
+
+ @Override
+ public String getName() {
+ return "testWithDefault";
+ }
+
+ @Override
+ public PropertyValue get(String key) {
+ return null;
+ }
+
+ @Override
+ public Map<String, PropertyValue> getProperties() {
+ return Collections.emptyMap();
+ }
+ };
+
+ Assert.assertEquals(56, PropertySourceComparator.getOrdinal(defaultPropertySource));
+ 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().getOrdinal());
+ }
+
+ private static class OverriddenOrdinalPropertySource extends BasePropertySource {
+
+ private OverriddenOrdinalPropertySource() {
+ super(250);
+ }
+
+ @Override
+ public String getName() {
+ return "overriddenOrdinal";
+ }
+
+ @Override
+ public Map<String, PropertyValue> getProperties() {
+ Map<String,PropertyValue> result = new HashMap<>(1);
+ result.put(PropertySource.TAMAYA_ORDINAL, PropertyValue.of(PropertySource.TAMAYA_ORDINAL, "1000", getName()));
+ return result;
+ }
+ }
+
+ private static class OverriddenInvalidOrdinalPropertySource extends BasePropertySource {
+
+ private OverriddenInvalidOrdinalPropertySource() {
+ super(1);
+ }
+
+ @Override
+ public String getName() {
+ return "overriddenInvalidOrdinal";
+ }
+
+ @Override
+ public Map<String, PropertyValue> getProperties() {
+ Map<String,PropertyValue> result = new HashMap<>(1);
+ result.put(PropertySource.TAMAYA_ORDINAL, PropertyValue.of(PropertySource.TAMAYA_ORDINAL, "invalid", getName()));
+ return result;
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/CLIPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/CLIPropertySourceTest.java b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/CLIPropertySourceTest.java
new file mode 100644
index 0000000..4507772
--- /dev/null
+++ b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/CLIPropertySourceTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport.propertysource;
+
+import org.apache.tamaya.spisupport.propertysource.CLIPropertySource;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for PropertySource for reading main arguments as configuration.
+ */
+public class CLIPropertySourceTest {
+
+ @Test
+ public void setCLIProps() throws Exception {
+ System.clearProperty("main.args");
+ CLIPropertySource ps = new CLIPropertySource();
+ assertTrue(ps.getProperties().isEmpty());
+ CLIPropertySource.initMainArgs("-a", "b");
+ assertFalse(ps.getProperties().isEmpty());
+ assertEquals(ps.getProperties().get("a").getValue(), "b");
+ CLIPropertySource.initMainArgs("--c");
+ assertFalse(ps.getProperties().isEmpty());
+ assertEquals(ps.getProperties().get("c").getValue(), "c");
+ CLIPropertySource.initMainArgs("sss");
+ assertFalse(ps.getProperties().isEmpty());
+ assertEquals(ps.getProperties().get("sss").getValue(), "sss");
+ CLIPropertySource.initMainArgs("-a", "b", "--c", "sss", "--val=vvv");
+ assertFalse(ps.getProperties().isEmpty());
+ assertEquals(ps.getProperties().get("a").getValue(), "b");
+ assertEquals(ps.getProperties().get("c").getValue(), "c");
+ assertEquals(ps.getProperties().get("sss").getValue(), "sss");
+ // getProperties() throws Exception {
+ System.setProperty("main.args", "-a b\t--c sss ");
+ ps = new CLIPropertySource();
+ assertFalse(ps.getProperties().isEmpty());
+ System.clearProperty("main.args");
+ assertEquals(ps.getProperties().get("a").getValue(), "b");
+ assertEquals(ps.getProperties().get("c").getValue(), "c");
+ assertEquals(ps.getProperties().get("sss").getValue(), "sss");
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnumConverterTest.java
----------------------------------------------------------------------
diff --git a/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnumConverterTest.java b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnumConverterTest.java
new file mode 100644
index 0000000..3453caa
--- /dev/null
+++ b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnumConverterTest.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.spisupport.propertysource;
+
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.ConversionContext;
+import org.apache.tamaya.spisupport.EnumConverter;
+import org.junit.Test;
+
+import java.math.RoundingMode;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+/**
+ * Test class testing the {@link EnumConverter} class.
+ */
+public class EnumConverterTest {
+
+ private final EnumConverter testConverter = new EnumConverter(RoundingMode.class);
+
+ private final ConversionContext DUMMY_CONTEXT = new ConversionContext.Builder("someKey", TypeLiteral.of(Enum.class)).build();
+
+ @Test
+ public void testConvert() {
+ assertEquals(testConverter.convert(RoundingMode.CEILING.toString(),
+ DUMMY_CONTEXT), RoundingMode.CEILING);
+ }
+
+ @Test
+ public void testConvert_LowerCase() {
+ assertEquals(testConverter.convert("ceiling", DUMMY_CONTEXT), RoundingMode.CEILING);
+ }
+
+ @Test
+ public void testConvert_MixedCase() {
+ assertEquals(testConverter.convert("CeiLinG", DUMMY_CONTEXT), RoundingMode.CEILING);
+ }
+
+ @Test
+ public void testConvert_OtherValue() {
+ assertNull(testConverter.convert("fooBars", DUMMY_CONTEXT));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySourceTest.java b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySourceTest.java
new file mode 100644
index 0000000..1e6c958
--- /dev/null
+++ b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySourceTest.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.spisupport.propertysource;
+
+import org.apache.tamaya.spisupport.propertysource.EnvironmentPropertySource;
+import org.apache.tamaya.spi.PropertyValue;
+import org.junit.Test;
+
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests for {@link EnvironmentPropertySource}.
+ */
+public class EnvironmentPropertySourceTest {
+
+ private final EnvironmentPropertySource envPropertySource = new EnvironmentPropertySource();
+
+ @Test
+ public void testGetOrdinal() throws Exception {
+ assertEquals(EnvironmentPropertySource.DEFAULT_ORDINAL, envPropertySource.getOrdinal());
+ }
+
+ @Test
+ public void testGetName() throws Exception {
+ assertEquals("environment-properties", envPropertySource.getName());
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ for (Map.Entry<String, String> envEntry : System.getenv().entrySet()) {
+ assertEquals(envPropertySource.get(envEntry.getKey()).getValue(), envEntry.getValue());
+ }
+ }
+
+ @Test
+ public void testGetProperties() throws Exception {
+ Map<String, PropertyValue> props = envPropertySource.getProperties();
+ for(Map.Entry<String,PropertyValue> en: props.entrySet()){
+ if(!en.getKey().startsWith("_")){
+ assertEquals(System.getenv(en.getKey()), en.getValue().getValue());
+ }
+ }
+ }
+
+ @Test
+ public void testIsScannable() throws Exception {
+ assertTrue(envPropertySource.isScannable());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/JavaConfigurationProviderTest.java
----------------------------------------------------------------------
diff --git a/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/JavaConfigurationProviderTest.java b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/JavaConfigurationProviderTest.java
new file mode 100644
index 0000000..0e363b9
--- /dev/null
+++ b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/JavaConfigurationProviderTest.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport.propertysource;
+
+import org.apache.tamaya.spi.PropertySource;
+import org.hamcrest.MatcherAssert;
+import org.hamcrest.Matchers;
+import org.junit.Test;
+
+import static org.apache.tamaya.ConfigurationProvider.getConfiguration;
+
+public class JavaConfigurationProviderTest {
+
+ private static final String A_UMLAUT = "\u00E4";
+ private static final String O_UMLAUT = "\u00F6";
+
+ @Test
+ public void loadsSimpleAndXMLPropertyFilesProper() {
+ PropertySource propertySource = new JavaConfigurationPropertySource();
+ MatcherAssert.assertThat(propertySource.getProperties().keySet(), Matchers.hasSize(7)); // double the size for .source values.
+
+ for (int i = 1; i < 6; i++) {
+ String key = "confkey" + i;
+ String value = "javaconf-value" + i;
+
+ MatcherAssert.assertThat(value, Matchers.equalTo(propertySource.get(key).getValue()));
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/MapPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/MapPropertySourceTest.java b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/MapPropertySourceTest.java
new file mode 100644
index 0000000..5624ed4
--- /dev/null
+++ b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/MapPropertySourceTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport.propertysource;
+
+import org.apache.tamaya.spisupport.propertysource.MapPropertySource;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class MapPropertySourceTest {
+
+ private Map<String,String> sourceMap;
+ private Properties sourceProperties;
+
+ @Before
+ public void createMapAndProperties() throws Exception {
+ sourceMap = new HashMap<>();
+ sourceMap.put("a", "AAA");
+ sourceMap.put("b", "BBB");
+
+ sourceProperties = new Properties();
+ sourceProperties.setProperty("a", "AAA");
+ sourceProperties.setProperty("b", "BBB");
+ }
+
+ @Test
+ public void sourceWillProperlyInitializedWithMapWithoutPrefix() throws Exception {
+ MapPropertySource propertySource = new MapPropertySource("UT", sourceMap);
+
+ assertThat(propertySource.getProperties()).describedAs("Should contain exactly 2 properties.")
+ .hasSize(2);
+ assertThat(propertySource.get("a")).isNotNull();
+ assertThat(propertySource.get("b")).isNotNull();
+ }
+
+ @Test
+ public void sourceWillProperlyInitializedWithMapWithPrefix() throws Exception {
+ MapPropertySource propertySource = new MapPropertySource("UT", sourceMap, "pre-");
+
+ assertThat(propertySource.getProperties()).describedAs("Should contain exactly 2 properties.")
+ .hasSize(2);
+ assertThat(propertySource.get("pre-a")).isNotNull();
+ assertThat(propertySource.get("pre-b")).isNotNull();
+ }
+
+ @Test
+ public void sourceWillProperlyInitializedWithPropertiesWithPrefix() throws Exception {
+ MapPropertySource propertySource = new MapPropertySource("UT", sourceProperties, "pre-");
+
+ assertThat(propertySource.getProperties()).describedAs("Should contain exactly 2 properties.")
+ .hasSize(2);
+ assertThat(propertySource.get("pre-a")).isNotNull();
+ assertThat(propertySource.get("pre-b")).isNotNull();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/PropertiesFilePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/PropertiesFilePropertySourceTest.java b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/PropertiesFilePropertySourceTest.java
new file mode 100644
index 0000000..da51740
--- /dev/null
+++ b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/PropertiesFilePropertySourceTest.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.spisupport.propertysource;
+
+import org.apache.tamaya.spisupport.propertysource.SimplePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PropertiesFilePropertySourceTest {
+
+ private final SimplePropertySource testfilePropertySource = new SimplePropertySource(Thread.currentThread()
+ .getContextClassLoader().getResource("testfile.properties"));
+ private final SimplePropertySource overrideOrdinalPropertySource = new SimplePropertySource(
+ Thread.currentThread().getContextClassLoader().getResource("overrideOrdinal.properties"));
+
+
+ @Test
+ public void testGetOrdinal() {
+ Assert.assertEquals(0, testfilePropertySource.getOrdinal());
+ Assert.assertEquals(Integer.parseInt(overrideOrdinalPropertySource.get(PropertySource.TAMAYA_ORDINAL)
+ .getValue()),
+ overrideOrdinalPropertySource.getOrdinal());
+ }
+
+
+ @Test
+ public void testGet() {
+ Assert.assertEquals("val3", testfilePropertySource.get("key3").getValue());
+ Assert.assertEquals("myval5", overrideOrdinalPropertySource.get("mykey5").getValue());
+ Assert.assertNull(testfilePropertySource.get("nonpresentkey"));
+ }
+
+
+ @Test
+ public void testGetProperties() throws Exception {
+ Assert.assertEquals(5, testfilePropertySource.getProperties().size());
+ Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key1"));
+ Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key2"));
+ Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key3"));
+ Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key4"));
+ Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key5"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java
new file mode 100644
index 0000000..288b8cd
--- /dev/null
+++ b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport.propertysource;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.PropertyValue;
+import org.junit.Test;
+
+import java.net.URL;
+
+import static org.hamcrest.CoreMatchers.allOf;
+import static org.hamcrest.CoreMatchers.endsWith;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.aMapWithSize;
+import static org.hamcrest.Matchers.hasEntry;
+
+public class SimplePropertySourceTest {
+ @Test
+ public void successfulCreationWithPropertiesFromXMLPropertiesFile() {
+ URL resource = getClass().getResource("/valid-properties.xml");
+
+ SimplePropertySource source = new SimplePropertySource(resource);
+
+ assertThat(source, notNullValue());
+ assertThat(source.getProperties(), aMapWithSize(2)); // double the size for .source values.
+ assertThat(source.getProperties(), hasEntry("a", PropertyValue.of("a", "b", resource.toString())));
+ assertThat(source.getProperties(), hasEntry("b", PropertyValue.of("b", "1", resource.toString())));
+
+ }
+
+ @Test
+ public void failsToCreateFromNonXMLPropertiesXMLFile() {
+ URL resource = getClass().getResource("/non-xml-properties.xml");
+ ConfigException catchedException = null;
+
+ try {
+ new SimplePropertySource(resource);
+ } catch (ConfigException ce) {
+ catchedException = ce;
+ }
+
+ assertThat(catchedException.getMessage(), allOf(startsWith("Error loading properties from"),
+ endsWith("non-xml-properties.xml")));
+ }
+
+ @Test
+ public void failsToCreateFromInvalidPropertiesXMLFile() {
+ URL resource = getClass().getResource("/invalid-properties.xml");
+ ConfigException catchedException = null;
+
+ try {
+ new SimplePropertySource(resource);
+ } catch (ConfigException ce) {
+ catchedException = ce;
+ }
+
+ assertThat(catchedException.getMessage(), allOf(startsWith("Error loading properties from"),
+ endsWith("invalid-properties.xml")));
+ }
+
+
+ @Test
+ public void successfulCreationWithPropertiesFromSimplePropertiesFile() {
+ URL resource = getClass().getResource("/testfile.properties");
+
+ SimplePropertySource source = new SimplePropertySource(resource);
+
+ assertThat(source, notNullValue());
+ assertThat(source.getProperties(), aMapWithSize(5)); // double the size for .source values.
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.java b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.java
new file mode 100644
index 0000000..e67630c
--- /dev/null
+++ b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.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.spisupport.propertysource;
+
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Map;
+import java.util.Properties;
+
+public class SystemPropertySourceTest {
+
+ private final SystemPropertySource testPropertySource = new SystemPropertySource();
+
+
+ @Test
+ public void testGetOrdinal() throws Exception {
+
+ // test the default ordinal
+ Assert.assertEquals(SystemPropertySource.DEFAULT_ORDINAL, testPropertySource.getOrdinal());
+
+ // set the ordinal to 1001
+ System.setProperty(PropertySource.TAMAYA_ORDINAL, "1001");
+ Assert.assertEquals(1001, 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", testPropertySource.getName());
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ String propertyKeyToCheck = System.getProperties().stringPropertyNames().iterator().next();
+
+ PropertyValue property = testPropertySource.get(propertyKeyToCheck);
+ Assert.assertNotNull("Property '" + propertyKeyToCheck + "' is not present in " +
+ SystemPropertySource.class.getSimpleName(), property);
+ Assert.assertEquals(System.getProperty(propertyKeyToCheck), property.getValue());
+ }
+
+ @Test
+ public void testGetProperties() throws Exception {
+ checkWithSystemProperties(testPropertySource.getProperties());
+
+ // modify system properties
+ System.setProperty("test", "myTestVal");
+
+ checkWithSystemProperties(testPropertySource.getProperties());
+
+ // cleanup
+ System.clearProperty("test");
+ }
+
+ private void checkWithSystemProperties(Map<String,PropertyValue> toCheck) {
+ Properties systemEntries = System.getProperties();
+ int num = 0;
+ for (PropertyValue propertySourceEntry : toCheck.values()) {
+ if(propertySourceEntry.getKey().startsWith("_")){
+ continue; // meta entry
+ }
+ num ++;
+ Assert.assertEquals("Entry values for key '" + propertySourceEntry.getKey() + "' do not match",
+ systemEntries.getProperty(propertySourceEntry.getKey()), propertySourceEntry.getValue());
+ }
+ Assert.assertEquals("size of System.getProperties().entrySet() must be the same as SystemPropertySrouce.getProperties().entrySet()",
+ systemEntries.size(), num);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/9bc56a38/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/TestPropertyDefaultSource.java
----------------------------------------------------------------------
diff --git a/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/TestPropertyDefaultSource.java b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/TestPropertyDefaultSource.java
new file mode 100644
index 0000000..b326abc
--- /dev/null
+++ b/code/old/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/TestPropertyDefaultSource.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport.propertysource;
+
+import org.apache.tamaya.spisupport.propertysource.BasePropertySource;
+import org.apache.tamaya.spi.PropertyValue;
+
+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,PropertyValue> properties = new HashMap<>();
+
+ public TestPropertyDefaultSource() {
+ super(100);
+ properties.put("name",PropertyValue.of("name", "Anatole", "Test"));
+ properties.put("name2",PropertyValue.of("name2", "Sabine", "Test"));
+ properties = Collections.unmodifiableMap(properties);
+ }
+
+ @Override
+ public String getName() {
+ return "default-testdata-properties";
+ }
+
+ @Override
+ public Map<String, PropertyValue> getProperties() {
+ return properties;
+ }
+
+ @Override
+ public boolean isScannable() {
+ return true;
+ }
+
+}