http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ae4ebe1d/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java index 121e331..d09ed8d 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ConverterTestsPropertySource.java @@ -30,6 +30,11 @@ import java.util.Map; public class ConverterTestsPropertySource implements PropertySource{ @Override + public int getOrdinal() { + return 0; + } + + @Override public String getName(){ return "ConverterTestsPropertySource"; } @@ -238,7 +243,7 @@ public class ConverterTestsPropertySource implements PropertySource{ } @Override - public Map<String, String> getProperties() { + public Map<String, PropertyValue> getProperties() { return Collections.emptyMap(); }
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ae4ebe1d/code/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java b/code/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java index 37cc86a..9c2fc60 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/propertysource/BasePropertySourceTest.java @@ -21,13 +21,10 @@ package org.apache.tamaya.core.propertysource; import org.apache.tamaya.core.internal.PropertySourceComparator; import org.apache.tamaya.spi.PropertySource; import org.apache.tamaya.spi.PropertyValue; -import org.apache.tamaya.spi.PropertyValueBuilder; import org.junit.Assert; import org.junit.Test; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; +import java.util.*; public class BasePropertySourceTest { @@ -47,7 +44,7 @@ public class BasePropertySourceTest { } @Override - public Map<String, String> getProperties() { + public Map<String, PropertyValue> getProperties() { return Collections.emptyMap(); } }; @@ -61,7 +58,7 @@ public class BasePropertySourceTest { @Test public void testGet() { - Assert.assertEquals("1000", new OverriddenOrdinalPropertySource().get(PropertySource.TAMAYA_ORDINAL).get(PropertySource.TAMAYA_ORDINAL)); + Assert.assertEquals(1000, new OverriddenOrdinalPropertySource().getOrdinal()); } private static class OverriddenOrdinalPropertySource extends BasePropertySource { @@ -76,10 +73,10 @@ public class BasePropertySourceTest { } @Override - public Map<String, String> getProperties() { - Map<String, String> map = new HashMap<>(1); - map.put(PropertySource.TAMAYA_ORDINAL, "1000"); - return map; + 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; } } @@ -95,10 +92,10 @@ public class BasePropertySourceTest { } @Override - public Map<String, String> getProperties() { - Map<String, String> map = new HashMap<>(1); - map.put(PropertySource.TAMAYA_ORDINAL, "invalid"); - return map; + 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/ae4ebe1d/code/core/src/test/java/org/apache/tamaya/core/propertysource/CLIPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/propertysource/CLIPropertySourceTest.java b/code/core/src/test/java/org/apache/tamaya/core/propertysource/CLIPropertySourceTest.java index dde63e5..20126f3 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/propertysource/CLIPropertySourceTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/propertysource/CLIPropertySourceTest.java @@ -34,25 +34,25 @@ public class CLIPropertySourceTest { assertTrue(ps.getProperties().isEmpty()); CLIPropertySource.initMainArgs("-a", "b"); assertFalse(ps.getProperties().isEmpty()); - assertEquals(ps.getProperties().get("a"), "b"); + assertEquals(ps.getProperties().get("a").getValue(), "b"); CLIPropertySource.initMainArgs("--c"); assertFalse(ps.getProperties().isEmpty()); - assertEquals(ps.getProperties().get("c"), "c"); + assertEquals(ps.getProperties().get("c").getValue(), "c"); CLIPropertySource.initMainArgs("sss"); assertFalse(ps.getProperties().isEmpty()); - assertEquals(ps.getProperties().get("sss"), "sss"); + assertEquals(ps.getProperties().get("sss").getValue(), "sss"); CLIPropertySource.initMainArgs("-a", "b", "--c", "sss", "--val=vvv"); assertFalse(ps.getProperties().isEmpty()); - assertEquals(ps.getProperties().get("a"), "b"); - assertEquals(ps.getProperties().get("c"), "c"); - assertEquals(ps.getProperties().get("sss"), "sss"); + 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"), "b"); - assertEquals(ps.getProperties().get("c"), "c"); - assertEquals(ps.getProperties().get("sss"), "sss"); + 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/ae4ebe1d/code/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java b/code/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java index 96d530a..2781158 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySourceTest.java @@ -18,6 +18,7 @@ */ package org.apache.tamaya.core.propertysource; +import org.apache.tamaya.spi.PropertyValue; import org.junit.Test; import java.util.Map; @@ -45,16 +46,16 @@ public class EnvironmentPropertySourceTest { @Test public void testGet() throws Exception { for (Map.Entry<String, String> envEntry : System.getenv().entrySet()) { - assertEquals(envPropertySource.get(envEntry.getKey()).get(envEntry.getKey()), envEntry.getValue()); + assertEquals(envPropertySource.get(envEntry.getKey()).getValue(), envEntry.getValue()); } } @Test public void testGetProperties() throws Exception { - Map<String, String> props = envPropertySource.getProperties(); - for(Map.Entry<String,String> en: props.entrySet()){ + 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()); + assertEquals(System.getenv(en.getKey()), en.getValue().getValue()); } } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ae4ebe1d/code/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java b/code/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java index 39aeb3b..d11b48e 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySourceTest.java @@ -34,15 +34,15 @@ public class PropertiesFilePropertySourceTest { public void testGetOrdinal() { Assert.assertEquals(0, testfilePropertySource.getOrdinal()); Assert.assertEquals(Integer.parseInt(overrideOrdinalPropertySource.get(PropertySource.TAMAYA_ORDINAL) - .get(PropertySource.TAMAYA_ORDINAL)), + .getValue()), overrideOrdinalPropertySource.getOrdinal()); } @Test public void testGet() { - Assert.assertEquals("val3", testfilePropertySource.get("key3").get("key3")); - Assert.assertEquals("myval5", overrideOrdinalPropertySource.get("mykey5").get("mykey5")); + Assert.assertEquals("val3", testfilePropertySource.get("key3").getValue()); + Assert.assertEquals("myval5", overrideOrdinalPropertySource.get("mykey5").getValue()); Assert.assertNull(testfilePropertySource.get("nonpresentkey")); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ae4ebe1d/code/core/src/test/java/org/apache/tamaya/core/propertysource/SimplePropertySourceTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/propertysource/SimplePropertySourceTest.java b/code/core/src/test/java/org/apache/tamaya/core/propertysource/SimplePropertySourceTest.java index 34902fa..2edc466 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/propertysource/SimplePropertySourceTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/propertysource/SimplePropertySourceTest.java @@ -19,6 +19,7 @@ package org.apache.tamaya.core.propertysource; import org.apache.tamaya.ConfigException; +import org.apache.tamaya.spi.PropertyValue; import org.junit.Test; import java.net.URL; @@ -40,8 +41,8 @@ public class SimplePropertySourceTest { assertThat(source, notNullValue()); assertThat(source.getProperties(), aMapWithSize(2)); // double the size for .source values. - assertThat(source.getProperties(), hasEntry("a", "b")); - assertThat(source.getProperties(), hasEntry("b", "1")); + assertThat(source.getProperties(), hasEntry("a", PropertyValue.of("a", "b", resource.toString()))); + assertThat(source.getProperties(), hasEntry("b", PropertyValue.of("b", "1", resource.toString()))); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ae4ebe1d/code/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java b/code/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java index e6dd5bd..2b2b61e 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/propertysource/SystemPropertySourceTest.java @@ -37,9 +37,9 @@ public class SystemPropertySourceTest { // test the default ordinal Assert.assertEquals(SystemPropertySource.DEFAULT_ORDINAL, testPropertySource.getOrdinal()); - // set the ordinal to 1000 - System.setProperty(PropertySource.TAMAYA_ORDINAL, "1000"); - Assert.assertEquals(1000, new SystemPropertySource().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!! @@ -72,30 +72,20 @@ public class SystemPropertySourceTest { // cleanup System.clearProperty("test"); - - // no modifaction - try { - testPropertySource.getProperties().put("add.new.keys", "must throw exception"); - Assert.fail(UnsupportedOperationException.class.getName() + " expected"); - } - catch (UnsupportedOperationException e) { - // expected -> all is fine - } } - private void checkWithSystemProperties(Map<String, String> toCheck) { + private void checkWithSystemProperties(Map<String,PropertyValue> toCheck) { Properties systemEntries = System.getProperties(); - - Assert.assertEquals("size of System.getProperties().entrySet() must be the same as SystemPropertySrouce.getProperties().entrySet()", - systemEntries.size(), toCheck.size()/2); - - for (Map.Entry<String, String> propertySourceEntry : toCheck.entrySet()) { + 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/ae4ebe1d/code/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java b/code/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java index 26e5291..f7c7f7c 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/provider/JavaConfigurationProviderTest.java @@ -42,7 +42,7 @@ public class JavaConfigurationProviderTest { String key = "confkey" + i; String value = "javaconf-value" + i; - assertThat(value, equalTo(propertySource.get(key).get(key))); + assertThat(value, equalTo(propertySource.get(key).getValue())); // check if we had our key in configuration.current assertThat(getConfiguration().getProperties().containsKey(key), is(true)); http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ae4ebe1d/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java b/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java index 6c8751c..09d86f1 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java +++ b/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java @@ -19,6 +19,7 @@ package org.apache.tamaya.core.testdata; import org.apache.tamaya.core.propertysource.BasePropertySource; +import org.apache.tamaya.spi.PropertyValue; import java.util.Collections; import java.util.HashMap; @@ -29,12 +30,12 @@ import java.util.Map; */ public class TestPropertyDefaultSource extends BasePropertySource{ - private Map<String,String> properties = new HashMap<>(); + private Map<String,PropertyValue> properties = new HashMap<>(); public TestPropertyDefaultSource() { super(100); - properties.put("name","Anatole"); - properties.put("name2","Sabine"); + properties.put("name",PropertyValue.of("name", "Anatole", "test")); + properties.put("name2",PropertyValue.of("name2", "Sabine", "test")); properties = Collections.unmodifiableMap(properties); } @@ -44,7 +45,7 @@ public class TestPropertyDefaultSource extends BasePropertySource{ } @Override - public Map<String, String> getProperties() { + public Map<String, PropertyValue> getProperties() { return properties; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ae4ebe1d/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java b/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java index 071cbb1..f0ae4d3 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java +++ b/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java @@ -20,6 +20,7 @@ package org.apache.tamaya.core.testdata; import org.apache.tamaya.spi.FilterContext; import org.apache.tamaya.spi.PropertyFilter; +import org.apache.tamaya.spi.PropertyValue; import javax.annotation.Priority; @@ -29,9 +30,11 @@ import javax.annotation.Priority; @Priority(100) public class TestPropertyFilter implements PropertyFilter{ @Override - public String filterProperty(String valueToBeFiltered, FilterContext context) { + public PropertyValue filterProperty(PropertyValue valueToBeFiltered, FilterContext context) { if("name4".equals(context.getKey())){ - return valueToBeFiltered + "(filtered)"; + return valueToBeFiltered.toBuilder() + .setValue(valueToBeFiltered.getValue() + "(filtered)") + .build(); } return valueToBeFiltered; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ae4ebe1d/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java b/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java index 5706478..b93be17 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java +++ b/code/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java @@ -21,6 +21,7 @@ package org.apache.tamaya.core.testdata; import org.apache.tamaya.core.propertysource.BasePropertySource; import org.apache.tamaya.spi.PropertySource; import org.apache.tamaya.spi.PropertySourceProvider; +import org.apache.tamaya.spi.PropertyValue; import java.util.ArrayList; import java.util.Collection; @@ -48,14 +49,14 @@ public class TestPropertySourceProvider implements PropertySourceProvider { private static class MyPropertySource extends BasePropertySource { - private Map<String, String> properties = new HashMap<>(); + private Map<String, PropertyValue> properties = new HashMap<>(); public MyPropertySource() { super(200); - properties.put("name", "Robin"); - properties.put("name3", "Lukas"); - properties.put("name4", "Sereina"); - properties.put("name5", "Benjamin"); + properties.put("name", PropertyValue.of("name", "Robin", "test")); + properties.put("name3", PropertyValue.of("name3", "Lukas", "test")); + properties.put("name4", PropertyValue.of("name4", "Sereina", "test")); + properties.put("name5", PropertyValue.of("name5", "Benjamin", "test")); properties = Collections.unmodifiableMap(properties); } @@ -65,7 +66,7 @@ public class TestPropertySourceProvider implements PropertySourceProvider { } @Override - public Map<String, String> getProperties() { + public Map<String, PropertyValue> getProperties() { return properties; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ae4ebe1d/code/core/src/test/java/org/apache/tamaya/core/testdata/TestRemovingPropertyFilter.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/testdata/TestRemovingPropertyFilter.java b/code/core/src/test/java/org/apache/tamaya/core/testdata/TestRemovingPropertyFilter.java index 7a5b7a8..e984962 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/testdata/TestRemovingPropertyFilter.java +++ b/code/core/src/test/java/org/apache/tamaya/core/testdata/TestRemovingPropertyFilter.java @@ -21,6 +21,7 @@ package org.apache.tamaya.core.testdata; import org.apache.tamaya.ConfigurationProvider; import org.apache.tamaya.spi.FilterContext; import org.apache.tamaya.spi.PropertyFilter; +import org.apache.tamaya.spi.PropertyValue; import javax.annotation.Priority; @@ -30,12 +31,14 @@ import javax.annotation.Priority; @Priority(200) public class TestRemovingPropertyFilter implements PropertyFilter{ @Override - public String filterProperty(String valueToBeFiltered, FilterContext context) { + public PropertyValue filterProperty(PropertyValue valueToBeFiltered, FilterContext context) { if("name5".equals(context.getKey())){ return null; } else if("name3".equals(context.getKey())){ - return "Mapped to name: " + ConfigurationProvider.getConfiguration().get("name"); + return valueToBeFiltered.toBuilder().setValue( + "Mapped to name: " + ConfigurationProvider.getConfiguration().get("name")) + .build(); } return valueToBeFiltered; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ae4ebe1d/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySource.java ---------------------------------------------------------------------- diff --git a/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySource.java b/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySource.java index 6d05e19..ebc054d 100644 --- a/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySource.java +++ b/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySource.java @@ -19,6 +19,7 @@ package org.apache.tamaya.examples.custompropertysource; import org.apache.tamaya.core.propertysource.BasePropertySource; +import org.apache.tamaya.spi.PropertyValue; import java.io.IOException; import java.io.InputStream; @@ -31,7 +32,7 @@ import java.util.Properties; public class SimplePropertySource extends BasePropertySource { public static final String CONFIG_PROPERTIES_LOCATION = "META-INF/MyOtherConfigProperties.properties"; - private Map<String,String> props = new HashMap<>(); + private Map<String,PropertyValue> props = new HashMap<>(); public SimplePropertySource() throws IOException { URL url = ClassLoader.getSystemClassLoader().getResource(CONFIG_PROPERTIES_LOCATION); @@ -41,7 +42,9 @@ public class SimplePropertySource extends BasePropertySource { properties.load(is); for(Map.Entry en: properties.entrySet()){ - props.put(en.getKey().toString(), en.getValue().toString()); + props.put(en.getKey().toString(), + PropertyValue.of(en.getKey().toString(), en.getValue().toString(), + getName())); } } finally{ @@ -55,7 +58,7 @@ public class SimplePropertySource extends BasePropertySource { } @Override - public Map<String, String> getProperties() { + public Map<String, PropertyValue> getProperties() { return props; } } \ No newline at end of file