http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnvironmentPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnvironmentPropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnvironmentPropertySourceTest.java deleted file mode 100644 index 877d30d..0000000 --- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnvironmentPropertySourceTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.core.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-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/MapPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/MapPropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/MapPropertySourceTest.java deleted file mode 100644 index 8a2e369..0000000 --- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/MapPropertySourceTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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.PropertyValue; -import org.assertj.core.api.Condition; -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-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PriorityServiceComparatorTest.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PriorityServiceComparatorTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PriorityServiceComparatorTest.java deleted file mode 100644 index dc15a16..0000000 --- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PriorityServiceComparatorTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tamaya.spisupport; - -import org.junit.Test; - -import 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-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertiesFilePropertySourceTest.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertiesFilePropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertiesFilePropertySourceTest.java deleted file mode 100644 index 984be08..0000000 --- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertiesFilePropertySourceTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.core.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-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java deleted file mode 100644 index 45ecc9d..0000000 --- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * 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(); - - assertThat(manager.isTargetTypeSupported(TypeLiteral.of(MyType.class)), - is(true)); - } - - @Test - public void factoryMethodOfIsUsedAsConverter() { - PropertyConverterManager manager = new PropertyConverterManager(); - - 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(); - 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(); - 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(); - List<PropertyConverter<B>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class))); - assertThat(converters, hasSize(1)); - manager = new PropertyConverterManager(); - converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class))); - assertThat(converters, hasSize(1)); - } - - @Test - public void testTransitiveSuperclassConverterMapping(){ - PropertyConverterManager manager = new PropertyConverterManager(); - 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(); - 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(); - 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(); - 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-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java deleted file mode 100644 index 0b616cd..0000000 --- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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 = new DefaultConfigurationContext(); - - @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-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SimplePropertySourceTest.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SimplePropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SimplePropertySourceTest.java deleted file mode 100644 index 7ef56c7..0000000 --- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SimplePropertySourceTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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.PropertyValue; -import org.junit.Test; - -import java.net.URL; - -import static org.hamcrest.CoreMatchers.*; -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)); - assertThat(source.getProperties(), hasEntry("a", PropertyValue.of("a","b", source.getName()))); - assertThat(source.getProperties(), hasEntry("b", PropertyValue.of("b", "1", source.getName()))); - - } - - @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)); // 5 * 2 meta entries. - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SystemPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SystemPropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SystemPropertySourceTest.java deleted file mode 100644 index 2e1625a..0000000 --- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SystemPropertySourceTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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.core.propertysource.SystemPropertySource; -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 1000 - 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-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/TestPropertyDefaultSource.java ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/TestPropertyDefaultSource.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/TestPropertyDefaultSource.java deleted file mode 100644 index 33b2462..0000000 --- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/TestPropertyDefaultSource.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.core.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; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter b/modules/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter deleted file mode 100644 index ff5d32c..0000000 --- a/modules/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter +++ /dev/null @@ -1,38 +0,0 @@ -# -# 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. -# - -# -# 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.spisupport.CTestConverter \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/resources/invalid-properties.xml ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/resources/invalid-properties.xml b/modules/spi-support/src/test/resources/invalid-properties.xml deleted file mode 100644 index d8b10b7..0000000 --- a/modules/spi-support/src/test/resources/invalid-properties.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy 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. ---> - -<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> -<properties> - <entry key="a"> - <entry key="b">1</entry> -</properties> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/resources/non-xml-properties.xml ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/resources/non-xml-properties.xml b/modules/spi-support/src/test/resources/non-xml-properties.xml deleted file mode 100644 index 8de819a..0000000 --- a/modules/spi-support/src/test/resources/non-xml-properties.xml +++ /dev/null @@ -1,18 +0,0 @@ -<!-- -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. ---> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/resources/overrideOrdinal.properties ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/resources/overrideOrdinal.properties b/modules/spi-support/src/test/resources/overrideOrdinal.properties deleted file mode 100644 index c68208a..0000000 --- a/modules/spi-support/src/test/resources/overrideOrdinal.properties +++ /dev/null @@ -1,25 +0,0 @@ -# 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. - -#overrideValue ordinal -tamaya.ordinal=16784 - -mykey1=myval1 -mykey2=myval2 -mykey3=myval3 -mykey4=myval4 -mykey5=myval5 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/resources/testfile.properties ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/resources/testfile.properties b/modules/spi-support/src/test/resources/testfile.properties deleted file mode 100644 index abd7ee8..0000000 --- a/modules/spi-support/src/test/resources/testfile.properties +++ /dev/null @@ -1,22 +0,0 @@ -# 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 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/resources/valid-properties.xml ---------------------------------------------------------------------- diff --git a/modules/spi-support/src/test/resources/valid-properties.xml b/modules/spi-support/src/test/resources/valid-properties.xml deleted file mode 100644 index 7eb51d9..0000000 --- a/modules/spi-support/src/test/resources/valid-properties.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy 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. ---> - -<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> -<properties> - <entry key="a">b</entry> - <entry key="b">1</entry> -</properties>