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 2019/05/14 14:52:05 UTC
[incubator-tamaya] 01/04: Removed PropertyValueBuilder and some
deprecations. Aligned PropertyValue API.
This is an automated email from the ASF dual-hosted git repository.
anatole pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tamaya.git
commit d5d3b748450b62ffc5968a682965c4c301566cfd
Author: Anatole Tresch <at...@gmail.com>
AuthorDate: Mon May 6 22:19:12 2019 +0200
Removed PropertyValueBuilder and some deprecations. Aligned PropertyValue API.
---
.../main/java/org/apache/tamaya/Configuration.java | 4 +-
.../apache/tamaya/spi/ConfigurationBuilder.java | 12 +-
.../apache/tamaya/spi/ConfigurationContext.java | 2 +-
.../org/apache/tamaya/spi/ConversionContext.java | 4 +-
.../java/org/apache/tamaya/spi/FilterContext.java | 8 +-
.../main/java/org/apache/tamaya/spi/ListValue.java | 157 +++++++-------
.../java/org/apache/tamaya/spi/ObjectValue.java | 192 +++++++++++------
.../org/apache/tamaya/spi/PropertyConverter.java | 2 +-
.../java/org/apache/tamaya/spi/PropertyFilter.java | 4 +-
.../java/org/apache/tamaya/spi/PropertySource.java | 8 +-
.../java/org/apache/tamaya/spi/PropertyValue.java | 204 ++++++++----------
.../apache/tamaya/spi/PropertyValueBuilder.java | 205 ------------------
.../apache/tamaya/spi/ConversionContextTest.java | 8 +-
.../org/apache/tamaya/spi/FilterContextTest.java | 44 ++--
.../java/org/apache/tamaya/spi/ListValueTest.java | 205 +++++++++---------
.../org/apache/tamaya/spi/ObjectValueTest.java | 231 ++++++++++++---------
.../org/apache/tamaya/spi/PropertySourceTest.java | 4 +-
.../tamaya/spi/PropertyValueBuilderTest.java | 6 +-
.../org/apache/tamaya/spi/PropertyValueTest.java | 211 ++++++++-----------
.../tamaya/core/ConfigurationBuilderTest.java | 4 +-
.../propertysource/BasePropertySourceTest.java | 5 +-
.../spisupport/DefaultConfigurationBuilder.java | 2 +-
.../spisupport/DefaultConfigurationContext.java | 2 +-
.../tamaya/spisupport/DefaultMetaDataProvider.java | 2 +-
.../spisupport/DefaultPropertySourceSnapshot.java | 8 +-
.../apache/tamaya/spisupport/MetadataProvider.java | 2 +-
.../spisupport/PropertyConverterManager.java | 4 +-
.../propertysource/BasePropertySource.java | 33 +--
.../propertysource/BuildablePropertySource.java | 8 +-
.../propertysource/CLIPropertySource.java | 4 +-
.../propertysource/EnvironmentPropertySource.java | 8 +-
.../propertysource/MapPropertySource.java | 40 ++++
.../PropertiesResourcePropertySource.java | 12 +-
.../propertysource/SimplePropertySource.java | 13 +-
.../propertysource/SystemPropertySource.java | 25 +--
.../spisupport/BuildablePropertySourceTest.java | 2 +-
.../DefaultConfigurationBuilderTest.java | 2 +-
.../spisupport/DefaultConfigurationTest.java | 2 +-
.../tamaya/spisupport/MockedPropertySource.java | 2 +-
.../tamaya/spisupport/RegexPropertyFilterTest.java | 6 +-
.../propertysource/BasePropertySourceTest.java | 6 +-
.../PropertiesResourcePropertySourceTest.java | 26 +--
.../propertysource/SimplePropertySourceTest.java | 24 +--
.../propertysource/SystemPropertySourceTest.java | 20 +-
.../propertysource/TestPropertyDefaultSource.java | 4 +-
.../propertysource/WrappedPropertySourceTest.java | 2 +-
46 files changed, 776 insertions(+), 1003 deletions(-)
diff --git a/code/api/src/main/java/org/apache/tamaya/Configuration.java b/code/api/src/main/java/org/apache/tamaya/Configuration.java
index 9d62652..7c47211 100644
--- a/code/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/code/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -29,7 +29,7 @@ import java.util.function.UnaryOperator;
/**
- * <p>A configuration models an aggregated set of current properties, identified by
+ * <p>A configuration models an aggregated setPropertyValue of current properties, identified by
* a unique key, but adds higher level access functions to
* a {@link org.apache.tamaya.spi.PropertySource}. Hereby in most
* cases a configuration is a wrapper around a composite
@@ -46,7 +46,7 @@ import java.util.function.UnaryOperator;
* </ul>
*
* <p>It is not recommended that implementations also are serializable, since the any configuration can be <i>frozen</i>
- * by reading out its complete configuration map into a serializable and remotable structure. This helps significantly
+ * by reading out its complete configuration mapProperties into a serializable and remotable structure. This helps significantly
* by simplifying the development of this interface, e.g. for being backed up by systems and stores that are not part of
* this library at all.</p>
*/
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationBuilder.java b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationBuilder.java
index ac19542..d8f1393 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationBuilder.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationBuilder.java
@@ -94,7 +94,7 @@ public interface ConfigurationBuilder {
* lowest priority regardless of its current ordinal value. To sort the property
* sources based on their ordinals call {@link #sortPropertySources}.
*
- * @param propertySources the {@link PropertySource}s to add
+ * @param propertySources the {@link PropertySource}s to addPropertyValue
* @return this builder, for chaining, never null.
* @throws IllegalArgumentException If a property source with a given name already
* exists.
@@ -127,7 +127,7 @@ public interface ConfigurationBuilder {
* lowest priority regardless of its current ordinal value. To sort the property
* sources based on their ordinals call {@link #sortPropertySources}.
*
- * @param propertySources the {@link PropertySource}s to add
+ * @param propertySources the {@link PropertySource}s to addPropertyValue
* @return this builder, for chaining, never null.
* @throws IllegalArgumentException If a property source with a given name already
* exists.
@@ -241,7 +241,7 @@ public interface ConfigurationBuilder {
* property filters remains unchanged. To sort the property
* filters call {@link #sortPropertyFilter}.
*
- * @param filters the filters to add
+ * @param filters the filters to addPropertyValue
* @return this builder, for chaining, never null.
*/
default ConfigurationBuilder addPropertyFilters(PropertyFilter... filters){
@@ -254,7 +254,7 @@ public interface ConfigurationBuilder {
* property filters remains unchanged. To sort the property
* filters call {@link #sortPropertyFilter}.
*
- * @param filters the filters to add
+ * @param filters the filters to addPropertyValue
* @return this builder, for chaining, never null.
*/
ConfigurationBuilder addPropertyFilters(Collection<PropertyFilter> filters);
@@ -292,7 +292,7 @@ public interface ConfigurationBuilder {
* method has no effect.
*
* @param typeToConvert the type for which the converter is used
- * @param propertyConverters the {@link PropertyConverter}s to add for this type
+ * @param propertyConverters the {@link PropertyConverter}s to addPropertyValue for this type
* @param <T> the target type.
* @return this builder, for chaining, never null.
*/
@@ -309,7 +309,7 @@ public interface ConfigurationBuilder {
* method has no effect.
*
* @param typeToConvert the type for which the converter is used
- * @param propertyConverters the PropertyConverters to add for this type
+ * @param propertyConverters the PropertyConverters to addPropertyValue for this type
* @param <T> the target type.
* @return this builder, for chaining, never null.
*/
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
index e762576..a23b035 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
@@ -83,7 +83,7 @@ public interface ConfigurationContext {
* }
* </pre>
*
- * @return map with sorted createList of registered {@link PropertySource}s per type.
+ * @return mapProperties with sorted createList of registered {@link PropertySource}s per type.
*/
Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters();
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/ConversionContext.java b/code/api/src/main/java/org/apache/tamaya/spi/ConversionContext.java
index cb4ae32..a52b884 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/ConversionContext.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/ConversionContext.java
@@ -100,7 +100,7 @@ public class ConversionContext {
/**
* Evaluate the metadata for the current target key from the given values. Later values hereby are more significant.
- * @return the evaluated meta data map.
+ * @return the evaluated meta data mapProperties.
*/
public Map<String, String> getMeta() {
Map<String, String> metaMap = new HashMap<>();
@@ -116,7 +116,7 @@ public class ConversionContext {
}
/**
- * Allows to add information on the supported/tried formats, which can be shown to the user, especially when
+ * Allows to addPropertyValue information on the supported/tried formats, which can be shown to the user, especially when
* conversion failed. Adding of formats is synchronized, all formats are added in order to the overall createList.
* This means formats should be passed in order of precedence.
* @param converterType the converters, which implements the formats provided.
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/FilterContext.java b/code/api/src/main/java/org/apache/tamaya/spi/FilterContext.java
index db4fd73..934fafb 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/FilterContext.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/FilterContext.java
@@ -132,18 +132,18 @@ public class FilterContext {
}
/**
- * This map contains the following keys:
+ * This mapProperties contains the following keys:
* <ul>
* <li>the original createValue <b>before</b> any filters were applied on it.</li>
* <li>all values starting with an {@code _<key>.}, for example {@code a.createValue}
- * may have a map setCurrent with {@code a.createValue} (oringinal createValue), {@code _a.createValue.origin,
+ * may have a mapProperties setCurrent with {@code a.createValue} (oringinal createValue), {@code _a.createValue.origin,
* _a.createValue.type, etc}. The exact contents is determine by the {@link PropertySource}s
* active.</li>
* </ul>
- * Also important to know is that this map given contains all the evaluated raw entries, regardless
+ * Also important to know is that this mapProperties given contains all the evaluated raw entries, regardless
* of the filters that are later applied. This ensures that met-information required by one filter is
* not hidden by another filter, because of an invalid filter ordering. In other words filters may remove
- * key/createValue pairs, e.g. fir security reasons, by returning {@code null}, but the values in the raw map
+ * key/createValue pairs, e.g. fir security reasons, by returning {@code null}, but the values in the raw mapProperties
* passed as input to the filter process will not be affected by any such removal (but the final properties
* returned are affected, of course).
*
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/ListValue.java b/code/api/src/main/java/org/apache/tamaya/spi/ListValue.java
index c59a7b1..ff7d69d 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/ListValue.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/ListValue.java
@@ -19,7 +19,6 @@
package org.apache.tamaya.spi;
import java.util.*;
-import java.util.function.Predicate;
/**
* Class modelling the result of a request for a property createValue. A property createValue is basically identified by its key.
@@ -41,10 +40,9 @@ public final class ListValue extends PropertyValue{
/**
* Creates a new instance
* @param key the key, not {@code null}.
- * @param parent the parent.
*/
- ListValue(PropertyValue parent, String key){
- super(parent, key);
+ ListValue(String key){
+ super(key);
}
/**
@@ -81,30 +79,18 @@ public final class ListValue extends PropertyValue{
/**
* Adds a createValue to the array.
* @param value the createValue, not null
- * @param <T> the instance type.
* @return this instance, for chaining.
* @throws IllegalStateException if the instance is immutable.
* @see #isImmutable()
*/
- public <T extends PropertyValue> T add(T value) {
+ public ListValue addPropertyValue(PropertyValue value) {
checkImmutable();
- value.setParent(this);
if(!this.list.stream().filter(p -> p==value).findAny().isPresent()){
+ value.setKey(generateListKey());
+ value.setParent(this);
this.list.add(value);
}
- return value;
- }
-
- /**
- * Adds an named text value to the array.
- * @param key the child's key, not null.
- * @param value the child's value, not null.
- * @return the created value, not null.
- * @throws IllegalStateException if the instance is immutable.
- * @see #isImmutable()
- */
- public PropertyValue addValue(String key, String value) {
- return add(new PropertyValue(this,key, value));
+ return this;
}
/**
@@ -114,8 +100,8 @@ public final class ListValue extends PropertyValue{
* @throws IllegalStateException if the instance is immutable.
* @see #isImmutable()
*/
- public PropertyValue addValue(String value) {
- return add(new PropertyValue(this,"", value));
+ public ListValue addValue(String value) {
+ return addPropertyValue(new PropertyValue(generateListKey(), value));
}
/**
@@ -125,12 +111,12 @@ public final class ListValue extends PropertyValue{
* @throws IllegalStateException if the instance is immutable.
* @see #isImmutable()
*/
- public List<PropertyValue> addValues(String... values) {
+ public ListValue addValues(String... values) {
List<PropertyValue> result = new ArrayList<>();
for(String val:values) {
- result.add(add(new PropertyValue(this, "", val)));
+ result.add(addPropertyValue(new PropertyValue(generateListKey(), val)));
}
- return result;
+ return this;
}
/**
@@ -140,18 +126,9 @@ public final class ListValue extends PropertyValue{
* @see #isImmutable()
*/
public ObjectValue addObject() {
- return add(new ObjectValue(this, ""));
- }
-
- /**
- * Adds a child createObject to the array.
- * @param name the child's name, not null.
- * @return the created createObject, not null.
- * @throws IllegalStateException if the instance is immutable.
- * @see #isImmutable()
- */
- public ObjectValue addObject(String name) {
- return add(new ObjectValue(this,name));
+ ObjectValue ov = new ObjectValue(generateListKey());
+ addPropertyValue(ov);
+ return ov;
}
/**
@@ -161,39 +138,26 @@ public final class ListValue extends PropertyValue{
* @see #isImmutable()
*/
public ListValue addList() {
- return add(new ListValue(this, ""));
- }
-
- /**
- * Adds a named array.
- * @param name the child's name, not null.
- * @return this instance, for chaining.
- * @throws IllegalStateException if the instance is immutable.
- * @see #isImmutable()
- */
- public ListValue addList(String name) {
- return add(new ListValue(this,name));
+ ListValue lv = new ListValue(generateListKey());
+ addPropertyValue(lv);
+ return lv;
}
/**
- * Get the array elements, filtered by the given predicate.
- * @param filter the filter predicate, null selects all elements.
- * @return this values matching, never null.
+ * Get a String value with the given key, if possible. If a node is present, but no value is setPropertyValue, then the
+ * node's {@code toString()} method is used as a result.
+ * @param index the target index.
+ * @return the value found, or null.
*/
- public List<PropertyValue> getValues(Predicate<PropertyValue> filter) {
- List<PropertyValue> result = new ArrayList<>();
- this.list.stream().filter(filter::test).forEach(result::add);
- return result;
- }
-
- /**
- * Get the array elements.
- * @return this values matching, never null.
- */
- public List<PropertyValue> getValues() {
- List<PropertyValue> result = new ArrayList<>();
- result.addAll(this.list);
- return result;
+ public String getValue(int index) {
+ PropertyValue value = getPropertyValue(index);
+ if(value!=null){
+ if(value.getValueType()==ValueType.VALUE) {
+ return value.getValue();
+ }
+ return value.toString();
+ }
+ return null;
}
/**
@@ -202,8 +166,8 @@ public final class ListValue extends PropertyValue{
* @return the element found
* @throws NoSuchElementException if no such element exists.
*/
- public PropertyValue get(int n) {
- return this.getValues().get(n);
+ public PropertyValue getPropertyValue(int n) {
+ return this.list.get(n);
}
@@ -256,7 +220,7 @@ public final class ListValue extends PropertyValue{
* @param name the name of the objects, null selects all.
* @return this values matching, never null.
*/
- public List<PropertyValue> getValues(String name) {
+ public List<PropertyValue> getPropertyValues(String name) {
List<PropertyValue> result = new ArrayList<>();
if (name == null) {
result.addAll(this.list);
@@ -271,22 +235,14 @@ public final class ListValue extends PropertyValue{
}
@Override
- public PropertyValue toPropertyValue(){
- PropertyValue value = new PropertyValue(getParent(), getKey(), getValue());
- value.setMeta(getMeta());
- value.setVersion(getVersion());
- return value;
- }
-
- @Override
public ObjectValue toObjectValue(){
- ObjectValue object = new ObjectValue(getParent(), getKey());
+ ObjectValue object = new ObjectValue(getKey());
+ object.setParent(getParent());
object.setMeta(getMeta());
object.setVersion(getVersion());
- object.setValue(getValue());
int index = 0;
for(PropertyValue val: list){
- object.set(val.deepClone().setKey(val.getKey()+"["+index+"]"));
+ object.setPropertyValue(val.deepClone().setKey(val.getKey()));
index++;
}
return object;
@@ -298,6 +254,19 @@ public final class ListValue extends PropertyValue{
}
/**
+ * Get the node's createValue.
+ * @return the createValue, or null.
+ */
+ public String getValue() {
+ return "List: " + this.list;
+ }
+
+ @Override
+ public PropertyValue setValue(String value) {
+ throw new UnsupportedOperationException("Cannot set value on list value.");
+ }
+
+ /**
* Clones this instance and all it's children, marking as mutable value.
* @return the new value clone.
*/
@@ -308,11 +277,11 @@ public final class ListValue extends PropertyValue{
@Override
protected ListValue deepClone(){
- ListValue newProp = new ListValue(getParent(), getKey());
+ ListValue newProp = new ListValue(getKey());
+ newProp.setParent(getParent());
newProp.setMeta(getMeta());
- list.forEach(c -> newProp.add(c.deepClone().mutable()));
+ list.forEach(c -> newProp.addPropertyValue(c.deepClone().mutable()));
newProp.setVersion(getVersion());
- newProp.setValue(getValue());
return newProp;
}
@@ -331,6 +300,10 @@ public final class ListValue extends PropertyValue{
Objects.equals(getMeta(), dataNode.getMeta());
}
+ private String generateListKey(){
+ return "["+this.list.size()+"]";
+ }
+
@Override
public int hashCode() {
return Objects.hash(getKey(), list, getValue(), getMeta());
@@ -339,12 +312,24 @@ public final class ListValue extends PropertyValue{
@Override
public String toString() {
- return "PropertyValue[ARRAY]{" +
- '\'' +getQualifiedKey() + '\'' +
- (getValue()!=null?", value='" + getValue() + '\'':"") +
+ return "List{" +
", size='" + getSize() + '\'' +
+ ", values=" + list +
(getMeta().isEmpty()?"":", metaData=" + getMeta()) +
'}';
}
+ /**
+ * Merges multiple values into one single node.
+ * @param values the values to merge, not null.
+ * @return the merged instance, or null.
+ */
+ public static ListValue from(Collection<PropertyValue> values) {
+ ListValue merged = PropertyValue.createList();
+ for(PropertyValue val:values){
+ merged.addPropertyValue(val);
+ }
+ return merged;
+ }
+
}
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/ObjectValue.java b/code/api/src/main/java/org/apache/tamaya/spi/ObjectValue.java
index 286fbe5..801260c 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/ObjectValue.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/ObjectValue.java
@@ -19,10 +19,8 @@
package org.apache.tamaya.spi;
import java.util.*;
-import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.logging.Logger;
-import java.util.stream.Collectors;
/**
* Class modelling the result of a request for a property value. A property value is basically identified by its key.
@@ -47,10 +45,9 @@ public final class ObjectValue extends PropertyValue{
/**
* Creates a new instance
* @param key the key, not {@code null}.
- * @param parent the parent.
*/
- ObjectValue(PropertyValue parent, String key){
- super(parent, key);
+ ObjectValue( String key){
+ super(key);
}
/**
@@ -70,32 +67,61 @@ public final class ObjectValue extends PropertyValue{
}
/**
- * Get the fields of this instance, filtered with the given predicate.
- * @param predicate the predicate, not null.
- * @return the current fields, never null.
+ * Access the current present field names/keys.
+ * @return the keys present, never null.
*/
- public Collection<PropertyValue> getValues(Predicate<PropertyValue> predicate){
- return Collections.unmodifiableCollection(this.fields.values().stream()
- .filter(predicate).collect(Collectors.toList()));
+ public Set<String> getKeys() {
+ return Collections.unmodifiableSet(this.fields.keySet());
}
/**
* Get a single child getValue by name.
* @param name the child's name, not null.
* @return the child found, or null.
- * @throws IllegalArgumentException if multiple getValues with the given name are existing (ambigous).
+ * @throws IllegalArgumentException if multiple getPropertyValues with the given name are existing (ambigous).
*/
- public PropertyValue getValue(String name){
+ public PropertyValue getPropertyValue(String name){
return this.fields.get(name);
}
/**
+ * Get the node's createValue.
+ * @return the createValue, or null.
+ */
+ public String getValue() {
+ return "Map: " + this.fields;
+ }
+
+ @Override
+ public PropertyValue setValue(String value) {
+ throw new UnsupportedOperationException("Cannot set value on object value.");
+ }
+
+ /**
+ * Get a String value with the given key, if possible. If a node is present, but no value is setPropertyValue, then the
+ * node's {@code toString()} method is used as a result.
+ * @param key the key, not null.
+ * @return the value found, or null.
+ */
+ public String getValue(String key) {
+ String result = null;
+ PropertyValue value = getPropertyValue(key);
+ if(value!=null){
+ result = value.getValue();
+ if(result==null){
+ result = value.toString();
+ }
+ }
+ return result;
+ }
+
+ /**
* Get a single child getValue with the given name, creates it if not existing.
* @param name the child's name, not null.
* @param valueSupplier the supplier to create a new instance, if no value is present, not null.
* @param <T> the target type.
* @return the child found or created, never null.
- * @throws IllegalArgumentException if multiple getValues with the given name are existing (ambigous).
+ * @throws IllegalArgumentException if multiple getPropertyValues with the given name are existing (ambigous).
* @throws IllegalStateException if the instance is immutable.
* @see #isImmutable()
*/
@@ -119,12 +145,38 @@ public final class ObjectValue extends PropertyValue{
return this.fields.size();
}
- @Override
- public PropertyValue toPropertyValue(){
- PropertyValue value = new PropertyValue(getParent(), getKey(), getValue());
- value.setMeta(getMeta());
- value.setVersion(getVersion());
- return value;
+ /**
+ * Applies a mapProperties of {@code Map<String,String>} to this instance as values.
+ * @param config the String based mapProperties, not {@code null}.
+ * @return the corresponding createValue based mapProperties.
+ */
+ public ObjectValue setValues(Map<String, String> config) {
+ return setValues(config, null, true);
+ }
+
+ /**
+ * Applies a mapProperties of {@code Map<String,String>} to this instance as values.
+ * @param config the String based mapProperties, not {@code null}.
+ * @param source the source name, optional.
+ * @param overwriteExisting if true, existing values will be overridden.
+ * @return the corresponding createValue based mapProperties.
+ */
+ public ObjectValue setValues(Map<String, String> config, String source, boolean overwriteExisting) {
+ checkImmutable();
+ Map<String, PropertyValue> result = PropertyValue.mapProperties(config, source);
+ for(Map.Entry<String,String> en:config.entrySet()){
+ PropertyValue value = new PropertyValue( en.getKey(), en.getValue());
+ value.setParent(this);
+ if(source!=null) {
+ value.setMeta("source", source);
+ }
+ if(overwriteExisting){
+ this.fields.put(en.getKey(), value);
+ }else{
+ this.fields.putIfAbsent(en.getKey(), value);
+ }
+ }
+ return this;
}
@Override
@@ -134,13 +186,13 @@ public final class ObjectValue extends PropertyValue{
@Override
public ListValue toListValue(){
- ListValue array = new ListValue(getParent(), getKey());
- array.setValue(getValue());
+ ListValue array = new ListValue(getKey());
+ array.setParent(getParent());
array.setMeta(getMeta());
array.setVersion(getVersion());
int index = 0;
for(PropertyValue val:fields.values()){
- array.add(val.deepClone());
+ array.addPropertyValue(val.deepClone());
}
return array;
}
@@ -151,36 +203,19 @@ public final class ObjectValue extends PropertyValue{
return Collections.unmodifiableCollection(this.fields.values()).iterator();
}
- /**
- * Adds text values to the createObject.
- * @param values the child's values, not null.
- * @return the created values, not null.
- * @throws IllegalStateException if the instance is immutable.
- * @see #isImmutable()
- */
- public Collection<PropertyValue> setValues(Map<String, String> values) {
- checkImmutable();
- List<PropertyValue> result = new ArrayList<>();
- for(Map.Entry<String, String> en:values.entrySet()) {
- PropertyValue val = setValue(en.getKey(), en.getValue());
- result.add(val);
- }
- return result;
- }
/**
* Adds another existing node, hereby setting the corresponding parent node.
* @param value the value, not null
- * @param <T> the value type.
* @return the value added, not null.
* @throws IllegalStateException if the instance is immutable.
* @see #isImmutable()
*/
- public <T extends PropertyValue> T set(T value) {
+ protected ObjectValue setPropertyValue(PropertyValue value) {
checkImmutable();
value.setParent(this);
this.fields.put(value.getKey(), value);
- return value;
+ return this;
}
/**
@@ -189,8 +224,8 @@ public final class ObjectValue extends PropertyValue{
* @param v the value, not null.
* @return the value added, not null.
*/
- public PropertyValue setValue(String k, String v) {
- return set(PropertyValue.createValue(k,v));
+ public ObjectValue setValue(String k, String v) {
+ return setPropertyValue(new PropertyValue(k,v));
}
/**
@@ -198,8 +233,10 @@ public final class ObjectValue extends PropertyValue{
* @param key the key, not null.
* @return the value added, not null.
*/
- public ListValue setList(String key) {
- return set(PropertyValue.createList(key));
+ public ListValue addList(String key) {
+ ListValue lv = PropertyValue.createList(key);
+ setPropertyValue(lv);
+ return lv;
}
/**
@@ -207,8 +244,10 @@ public final class ObjectValue extends PropertyValue{
* @param key the key, not null.
* @return the value added, not null.
*/
- public ObjectValue setObject(String key) {
- return set(PropertyValue.createObject(key));
+ public ObjectValue addObject(String key) {
+ ObjectValue ov = PropertyValue.createObject(key);
+ setPropertyValue(ov);
+ return ov;
}
/**
@@ -229,7 +268,7 @@ public final class ObjectValue extends PropertyValue{
if(tokenizer.hasMoreTokens()) {
node = node.getOrSetValue(token, () -> PropertyValue.createObject(token));
}else{
- return node.set(PropertyValue.createValue(token, value));
+ return node.setPropertyValue(new PropertyValue(token, value));
}
}
return null;
@@ -253,8 +292,8 @@ public final class ObjectValue extends PropertyValue{
}
/**
- * Convert the getValue tree to a property map.
- * @return the corresponding property map, not null.
+ * Convert the getValue tree to a property mapProperties.
+ * @return the corresponding property mapProperties, not null.
*/
@Override
public Map<String,String> toMap(){
@@ -273,6 +312,28 @@ public final class ObjectValue extends PropertyValue{
return map;
}
+ /**
+ * Convert the value tree to a local property mapProperties.
+ * @return the corresponding local mapProperties, not null.
+ */
+ @Override
+ public Map<String,String> toLocalMap(){
+ Map<String, String> map = new TreeMap<>();
+ for (PropertyValue n : fields.values()) {
+ switch(n.getValueType()){
+ case VALUE:
+ map.put(n.getKey(), n.getValue());
+ break;
+ default:
+ for(PropertyValue val:n) {
+ Map<String,String> valueMap = val.toLocalMap();
+ map.putAll(valueMap);
+ }
+ }
+ }
+ return map;
+ }
+
/**
* Clones this instance and all it's children, marking as mutable value.
@@ -285,11 +346,11 @@ public final class ObjectValue extends PropertyValue{
@Override
protected ObjectValue deepClone(){
- ObjectValue newProp = new ObjectValue(getParent(), getKey());
+ ObjectValue newProp = new ObjectValue(getKey());
+ newProp.setParent(getParent());
newProp.setMeta(getMeta());
- fields.values().forEach(c -> newProp.set(c.deepClone().mutable()));
+ fields.values().forEach(c -> newProp.setPropertyValue(c.deepClone().mutable()));
newProp.setVersion(getVersion());
- newProp.setValue(getValue());
return newProp;
}
@@ -315,12 +376,27 @@ public final class ObjectValue extends PropertyValue{
@Override
public String toString() {
- return "PropertyValue[MAP]{" +
- '\'' +getQualifiedKey() + '\'' +
- (getValue()!=null?", value='" + getValue() + '\'':"") +
- ", size='" + getSize() + '\'' +
+ return "Object{" +
+ "size='" + getSize() + '\'' +
+ ", values='" + toLocalMap() +
(getMeta().isEmpty()?"":", metaData=" + getMeta()) +
'}';
}
+ /**
+ * Merges multiple values into one single node.
+ * @param values the values to merge, not null.
+ * @return the merged instance, or null.
+ */
+ public static ObjectValue from(Collection<PropertyValue> values) {
+ if(values.size()==1){
+ return values.iterator().next().toObjectValue();
+ }
+ ObjectValue merged = PropertyValue.createObject();
+ for(PropertyValue val:values){
+ merged.setPropertyValue(val);
+ }
+ return merged;
+ }
+
}
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java b/code/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java
index 986e17e..4d08a55 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java
@@ -30,7 +30,7 @@ public interface PropertyConverter<T>{
/**
* Convert the given configuration keys from its String representation into the required target type.
- * Additional data can be obtained from {@link ConversionContext}, which also allows to add a list
+ * Additional data can be obtained from {@link ConversionContext}, which also allows to addPropertyValue a list
* of supported formats, which is very handy in case a
* value could not be converted. This list of supported formats can then shown to the user to give some hints
* how a value could be configured.
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java b/code/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
index 376f686..bea080f 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
@@ -20,7 +20,7 @@ package org.apache.tamaya.spi;
/**
- * <p>Interface for filtering the current map of properties during the evaluation of the chain of PropertySources.
+ * <p>Interface for filtering the current mapProperties of properties during the evaluation of the chain of PropertySources.
* Filters can be registered using the {@link org.apache.tamaya.spi.ServiceContext}. The ordinal
* hereby is defined by the corresponding {@code @Priority} annotation.</p>
* <p>Filters </p>
@@ -31,7 +31,7 @@ public interface PropertyFilter{
/**
* <p>Maps the current {@code value} to a new value. The resulting value will be used as the result
* passed to the user.</p>
- * <p>If a filter is currently not available, it should just pass the input map to the method's
+ * <p>If a filter is currently not available, it should just pass the input mapProperties to the method's
* output.</p>
* <p>Returning {@code null} will remove the entry.</p>
* <h3>Implementation specification</h3>
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/PropertySource.java b/code/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
index 8ea4801..0bf4b4b 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
@@ -112,7 +112,7 @@ public interface PropertySource{
*
* <p>Reordering of the default order of the config-sources:</p>
* <p>Example: If the properties file/s should be used <b>before</b> the other implementations,
- * you have to configure an ordinal > 1000. That means, you have to add e.g. tamaya.ordinal=401 to
+ * you have to configure an ordinal > 1000. That means, you have to addPropertyValue e.g. tamaya.ordinal=401 to
* /META-INF/javaconfiguration.properties . Hint: In case of property files every file is handled as independent
* config-source, but all of them have ordinal 400 by default (and can be reordered in a fine-grained manner.</p>
*
@@ -152,7 +152,7 @@ public interface PropertySource{
* Access a property.
*
* @param key the property's key, not {@code null}.
- * @return the property value map, where {@code map.current(key) == value}, including also any metadata. In case a
+ * @return the property value mapProperties, where {@code mapProperties.current(key) == value}, including also any metadata. In case a
* value is null, simply return {@code null}.
*/
PropertyValue get(String key);
@@ -161,7 +161,7 @@ public interface PropertySource{
* Access the current properties as Set. The resulting Map may not return all items accessible, e.g.
* when the underlying storage does not support iteration of its entries.
{@code null}
- * @return the corresponding map, never null.
+ * @return the corresponding mapProperties, never null.
*/
Map<String, PropertyValue> getProperties();
@@ -197,7 +197,7 @@ public interface PropertySource{
/**
* Get the current version. A new version signals that it is known that properties have changed for this property
* source. This is especially useful, when {@link #getChangeSupport()} is {@link ChangeSupport#SUPPORTED}.
- * The content and format of the version String is imeplemtation specific. We recommend to add information
+ * The content and format of the version String is imeplemtation specific. We recommend to addPropertyValue information
* such as the loading timestamp, the source systems read or whatever is appropriate. By default this
* method returns {@code "N/A"}.
* @return the version this property source, never null.
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/PropertyValue.java b/code/api/src/main/java/org/apache/tamaya/spi/PropertyValue.java
index 5ea569c..6fdaadf 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/PropertyValue.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/PropertyValue.java
@@ -21,6 +21,7 @@ package org.apache.tamaya.spi;
import java.io.Serializable;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Predicate;
/**
* Class modelling the result of a request for a property createValue. A property createValue is basically identified by its key.
@@ -60,29 +61,12 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
VALUE
}
-
- /**
- * Creates a new builder instance.
- * @param key the key, not {@code null}.
- * @param source the source, typically the name of the {@link PropertySource}
- * providing the createValue, not {@code null}.
- * @return a new builder instance.
- * @deprecated Will be removed, use {@link PropertyValue} directly.
- */
- @Deprecated
- public static PropertyValueBuilder builder(String key, String source){
- Objects.requireNonNull(key, "Key must be given.");
- Objects.requireNonNull(source, "Source must be given");
-
- return new PropertyValueBuilder(key, null).setSource(source);
- }
-
/**
* Creates a new (invisible) root, which is a node with an empty name.
* @return a new empty root, never null.
*/
public static ObjectValue createObject(){
- return new ObjectValue(null, "");
+ return new ObjectValue("");
}
/**
@@ -90,7 +74,7 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
* @return a new empty root, never null.
*/
public static ListValue createList(){
- return new ListValue(null, "");
+ return new ListValue("");
}
/**
@@ -100,7 +84,7 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
* @return a new createValue instance.
*/
public static PropertyValue createValue(String key, String value){
- return new PropertyValue(null, key, value);
+ return new PropertyValue(key, value);
}
/**
@@ -109,7 +93,7 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
* @return a new createValue instance.
*/
public static ListValue createList(String key){
- return new ListValue(null, key);
+ return new ListValue(key);
}
/**
@@ -118,62 +102,59 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
* @return a new createValue instance.
*/
public static ObjectValue createObject(String key){
- return new ObjectValue(null, key);
+ return new ObjectValue(key);
}
/**
- * Creates a new builder instance.
- * @param key the key, not {@code null}.
- * @param value the property createValue, not {@code null}.
- * @param source the source, typically the name of the {@link PropertySource}
- * providing the createValue, not {@code null}.
- * @return a new builder instance.
+ * Maps a mapProperties of {@code Map<String,String>} to a {@code Map<String,PropertyValue>}.
+ * @param config the String based mapProperties, not {@code null}.
+ * @param source the source name, not {@code null}.
+ * @return the corresponding createValue based mapProperties.
*/
- @Deprecated
- public static PropertyValue of(String key, String value, String source) {
- Objects.requireNonNull(key);
- if(source!=null) {
- return new PropertyValue(null, key, value).setMeta("source", source);
- }
- return new PropertyValue(null, key, value);
+ public static Map<String, PropertyValue> mapProperties(Map<String, String> config, String source) {
+ return mapProperties(config, source, null);
}
/**
- * Maps a map of {@code Map<String,String>} to a {@code Map<String,PropertyValue>}.
- * @param config the String based map, not {@code null}.
- * @param source the source name, not {@code null}.
- * @return the corresponding createValue based map.
- */
- public static Map<String, PropertyValue> map(Map<String, String> config, String source) {
- Map<String, PropertyValue> result = new HashMap<>(config.size());
- for(Map.Entry<String,String> en:config.entrySet()){
- result.put(en.getKey(), createValue(en.getKey(), en.getValue()).setMeta("source", source));
- }
- return result;
+ * Maps a mapProperties of {@code Map<String,String>} to a {@code Map<String,PropertyValue>}.
+ *
+ * @param config the String based mapProperties, not {@code null}.
+ * @param source the source name, not {@code null}.
+ * @param metaData additional metadata, not {@code null}.
+ * @return the corresponding createValue based mapProperties.
+ */
+ public static Map<String, PropertyValue> mapProperties(Map<String, String> config, String source,
+ Map<String,String> metaData) {
+ return mapProperties(config, source, metaData, null);
}
/**
- * Maps a map of {@code Map<String,String>} to a {@code Map<String,PropertyValue>}.
+ * Maps a mapProperties of {@code Map<String,String>} to a {@code Map<String,PropertyValue>}.
*
- * @param config the String based map, not {@code null}.
+ * @param config the String based mapProperties, not {@code null}.
* @param source the source name, not {@code null}.
* @param metaData additional metadata, not {@code null}.
- * @return the corresponding createValue based map.
+ * @return the corresponding createValue based mapProperties.
*/
- public static Map<String, PropertyValue> map(Map<String, String> config, String source,
- Map<String,String> metaData) {
+ public static Map<String, PropertyValue> mapProperties(Map<String, String> config, String source,
+ Map<String,String> metaData, String prefix) {
Objects.requireNonNull(config, "Config must be given.");
- Objects.requireNonNull(metaData, "Meta data must be given.");
Map<String, PropertyValue> result = new HashMap<>(config.size());
for(Map.Entry<String,String> en:config.entrySet()){
- PropertyValue pv = createValue(en.getKey(), en.getValue())
- .setMeta(metaData);
+ PropertyValue pv = createValue(en.getKey(), en.getValue());
+ if(metaData!=null) {
+ pv.setMeta(metaData);
+ }
if(source!=null){
pv.setMeta("source", source);
}
- result.put(en.getKey(), pv);
+ if(prefix==null) {
+ result.put(en.getKey(), pv);
+ }else{
+ result.put(prefix + en.getKey(), pv.setKey(prefix=en.getKey()));
+ }
}
return result;
}
@@ -181,20 +162,17 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
/**
* Creates a new instance
* @param key the key, not {@code null}.
- * @param parent the parent.
*/
- protected PropertyValue(PropertyValue parent, String key){
- this(parent, key, null);
+ public PropertyValue(String key){
+ this(key, null);
}
/**
* Creates a new instance
* @param key the key, not {@code null}.
- * @param parent the parent.
* @param value the initial text createValue.
*/
- protected PropertyValue(PropertyValue parent, String key, String value){
- this.parent = parent;
+ protected PropertyValue(String key, String value){
this.key = Objects.requireNonNull(key);
this.value = value;
}
@@ -347,9 +325,9 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
}
/**
- * Creates a full configuration map for this key, createValue pair and all its getMeta context data. This map
+ * Creates a full configuration mapProperties for this key, createValue pair and all its getMeta context data. This mapProperties
* is also used for subsequent processing, like createValue filtering.
- * @return the property createValue entry map.
+ * @return the property createValue entry mapProperties.
*/
public final Map<String, String> getMeta() {
return Collections.unmodifiableMap(metaEntries);
@@ -391,23 +369,6 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
/**
- * Changes the entry's key, mapping also corresponding context entries.
- * @param key the new key, not {@code null}.
- * @return the builder for chaining.
- * @throws IllegalStateException if the instance is immutable.
- * @see #isImmutable()
- */
- public PropertyValue setKey(String key) {
- checkImmutable();
- if(!Objects.equals(this.key, key)) {
- this.key = Objects.requireNonNull(key);
- version.incrementAndGet();
- }
- return this;
- }
-
-
- /**
* Replaces/sets the context data.
* @param metaEntries the context data to be applied, not {@code null}.
* @return the builder for chaining.
@@ -462,8 +423,8 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
/**
- * Convert the value tree to a property map.
- * @return the corresponding property map, not null.
+ * Convert the value tree to a property mapProperties using full keys.
+ * @return the corresponding property mapProperties, not null.
*/
public Map<String,String> toMap(){
Map<String, String> map = new TreeMap<>();
@@ -474,37 +435,25 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
}
/**
- * Create a String representation of the tree.
- * @return the corresponding String representation, not null.
+ * Convert the value tree to a property mapProperties using local keys.
+ * @return the corresponding property mapProperties, not null.
*/
- public String asString() {
- Map<String, String> map = toMap();
- StringBuilder b = new StringBuilder();
- map.entrySet().forEach(en -> b.append(en.getKey()).append(" = ").append(en.getValue()).append('\n'));
- if(b.length()==0){
- return "<nodata>";
+ public Map<String,String> toLocalMap(){
+ Map<String, String> map = new TreeMap<>();
+ if(value!=null) {
+ map.put(getKey(), value);
}
- return b.toString();
+ return map;
}
- /**
- * Creates a new builder instance based on this item.
- * @return a new builder, never null.
- * @deprecated Use {@link PropertyValue} directly.
- */
- @Deprecated
- public PropertyValueBuilder toBuilder() {
- return new PropertyValueBuilder(this.getKey(), this.getValue())
- .setMeta(this.metaEntries);
- }
/**
- * Convert an instance to a simple PropertyValue. Note, that in case
- * of object/list values, data loss can occur.
- * @return the simple value, never null.
+ * Create a String representation of the tree.
+ * @return the corresponding String representation, not null.
*/
- public PropertyValue toPropertyValue(){
- return this;
+ @Override
+ public String toString() {
+ return String.valueOf(value);
}
/**
@@ -512,8 +461,9 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
* @return the list value, never null.
*/
public ObjectValue toObjectValue(){
- ObjectValue ov = new ObjectValue(getParent(),getKey());
- ov.setValue("createValue", value);
+ ObjectValue ov = new ObjectValue(getKey());
+ ov.setParent(getParent());
+ ov.setValue("value", value);
return ov;
}
@@ -522,8 +472,9 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
* @return the list value, never null.
*/
public ListValue toListValue(){
- ListValue lv = new ListValue(getParent(),getKey());
- lv.addValue("createValue", value);
+ ListValue lv = new ListValue(getKey());
+ lv.setParent(getParent());
+ lv.addValue(value);
return lv;
}
@@ -533,7 +484,8 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
* @return a clone, never null.
*/
protected PropertyValue deepClone() {
- PropertyValue newProp = new PropertyValue(getParent(), getKey(), this.value);
+ PropertyValue newProp = new PropertyValue(getKey(), this.value);
+ newProp.setParent(getParent());
newProp.setMeta(getMeta());
newProp.setVersion(getVersion());
newProp.setValue(getValue());
@@ -567,6 +519,23 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
}
/**
+ * Changes the entry's key, mapping also corresponding context entries.
+ *
+ * @param key the new key, not {@code null}.
+ * @return the builder for chaining.
+ * @throws IllegalStateException if the instance is immutable.
+ * @see #isImmutable()
+ */
+ public PropertyValue setKey(String key) {
+ checkImmutable();
+ if(!Objects.equals(this.key, key)) {
+ this.key = Objects.requireNonNull(key);
+ version.incrementAndGet();
+ }
+ return this;
+ }
+
+ /**
* Sets the new parent, used iternally when converting between value types.
* @param parent the parent value.
* @return the simple value, never null.
@@ -587,8 +556,7 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
}
PropertyValue dataNode = (PropertyValue) o;
return Objects.equals(getKey(), dataNode.getKey()) &&
- Objects.equals(value, dataNode.value) &&
- Objects.equals(getMeta(), dataNode.getMeta());
+ Objects.equals(value, dataNode.value);
}
@Override
@@ -596,14 +564,4 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
return Objects.hash(getParent(), getKey(), value, getMeta());
}
-
- @Override
- public String toString() {
- return "PropertyValue{" +
- '\'' +getQualifiedKey() + '\'' +
- (value!=null?", value='" + value + '\'':"") +
- (getMeta().isEmpty()?"":", metaData=" + getMeta()) +
- '}';
- }
-
}
diff --git a/code/api/src/main/java/org/apache/tamaya/spi/PropertyValueBuilder.java b/code/api/src/main/java/org/apache/tamaya/spi/PropertyValueBuilder.java
deleted file mode 100644
index 6f6ca9a..0000000
--- a/code/api/src/main/java/org/apache/tamaya/spi/PropertyValueBuilder.java
+++ /dev/null
@@ -1,205 +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.spi;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * Builder to createObject a {@link org.apache.tamaya.spi.PropertyValue} instance.
- * @deprecated Use {@link PropertyValue} directly.
- */
-@Deprecated
-public class PropertyValueBuilder {
- /** The key accessed. */
- protected String key;
- /** The property value. */
- protected String value;
- /** The property value. */
- protected String source;
- /** additional metadata entries (optional). */
- protected Map<String,String> metaEntries = new HashMap<>();
- /** The parent value, null if it's a root value. */
- protected PropertyValue parent;
- /** The value's getIndex, if the value is participating in a createList structure. */
- protected int index = -1;
- /** Helper structure used for indexing new createList values. */
- protected Map<String, AtomicInteger> indices = new HashMap<>();
-
- /**
- * Create a new builder instance, for a given setCurrent of parameters.
- * Before calling build at least a {@link #value}
- * must be setCurrent.
- */
- PropertyValueBuilder(String key, String value){
- this.key = Objects.requireNonNull(key);
- this.value = value;
- }
-
- /**
- * Replaces/sets the context data.
- * @param metaEntries the context data to be applied, not {@code null}.
- * @return the builder for chaining.
- */
- public PropertyValueBuilder setMeta(Map<String, String> metaEntries) {
- this.metaEntries.clear();
- this.metaEntries.putAll(metaEntries);
- return this;
- }
-
- /**
- * Add an additional context data information.
- * @param key the context data key, not {@code null}.
- * @param value the context value, not {@code null} (will be converted to String).
- * @return the builder for chaining.
- */
- public PropertyValueBuilder addMetaEntry(String key, String value) {
- Objects.requireNonNull(key, "Meta key must be given.");
- Objects.requireNonNull(value, "Meta value must be given.");
-
- this.metaEntries.put(key, value);
- return this;
- }
-
- /**
- * Adds the context data given.
- * @param metaEntries the context data to be applied, not {@code null}.
- * @return the builder for chaining.
- */
- public PropertyValueBuilder setMetaEntries(Map<String, String> metaEntries) {
- this.metaEntries.putAll(metaEntries);
- return this;
- }
-
- /**
- * Removes a getMeta entry.
- * @param key the entry's key, not {@code null}.
- * @return the builder for chaining.
- */
- public PropertyValueBuilder removeMetaEntry(String key) {
- Objects.requireNonNull(key, "Key must be given.");
-
- this.metaEntries.remove(key);
- return this;
- }
-
- /**
- * Get the value's context data.
- * @return the context data, not {@code null}.
- */
- public Map<String,String> getMetaEntries() {
- return Collections.unmodifiableMap(this.metaEntries);
- }
-
- /**
- * Get the value's context data.
- * @param key the key, not null.
- * @return the context data, not {@code null}.
- */
- public String getMeta(String key) {
- return this.metaEntries.get(key);
- }
-
- /**
- * Get the value's context data.
- * @param <T> the type of the class modeled by the type parameter
- * @param type the target type, not null.
- * @return the context data, not {@code null}.
- */
- public <T> T getMeta(Class<T> type) {
- return (T)this.metaEntries.get(type.toString());
- }
-
- /**
- * Changes the entry's key, mapping also corresponding context entries.
- * @param key the new key, not {@code null}.
- * @return the builder for chaining.
- */
- public PropertyValueBuilder mapKey(String key) {
- // todo obf if (1==1) throw new RuntimeException("No tests written.");
- Map<String,String> newContext = new HashMap<>();
- for(Map.Entry<String,String> en:this.metaEntries.entrySet()){
- if(en.getKey().startsWith("_"+this.key)){
- newContext.put("_"+key+'.'+ en.getKey().substring(this.key.length()+1), en.getValue());
- }else{
- newContext.put(en.getKey(), en.getValue());
- }
- }
- this.metaEntries = newContext;
- this.key = key;
- return this;
- }
-
- /**
- * Sets a new key.
- * @param key the new key, not {@code null}.
- * @return the builder for chaining.
- */
- public PropertyValueBuilder setKey(String key) {
- this.key = Objects.requireNonNull(key);
- return this;
- }
-
- /**
- * Sets a new value.
- * @param value the new value, not {@code null}.
- * @return the builder for chaining.
- */
- public PropertyValueBuilder setValue(String value) {
- this.value = Objects.requireNonNull(value, "Value must be given.");
-
- return this;
- }
-
- /**
- * Sets a new source.
- * @param source the new source, not {@code null}.
- * @return the builder for chaining.
- * @deprecated Use {@link #addMetaEntry(String, String)}
- */
- @Deprecated
- public PropertyValueBuilder setSource(String source) {
- if(source!=null) {
- this.source = source;
- }
- return this;
- }
-
- /**
- * Creates a new immutable {@link org.apache.tamaya.spi.PropertyValue}.
- * @return a new immutable {@link org.apache.tamaya.spi.PropertyValue}, never {@code null}.
- */
- public PropertyValue build(){
- return PropertyValue.of(key, value, source).setMeta(metaEntries);
- }
-
- @Override
- public String toString() {
- return "PropertyValueBuilder{" +
- "key='" + key + '\'' +
- ", value='" + value + '\'' +
- ", source='" + source + '\'' +
- ", metaEntries=" + metaEntries +
- '}';
- }
-
-}
diff --git a/code/api/src/test/java/org/apache/tamaya/spi/ConversionContextTest.java b/code/api/src/test/java/org/apache/tamaya/spi/ConversionContextTest.java
index c269013..33a9929 100644
--- a/code/api/src/test/java/org/apache/tamaya/spi/ConversionContextTest.java
+++ b/code/api/src/test/java/org/apache/tamaya/spi/ConversionContextTest.java
@@ -104,7 +104,7 @@ public class ConversionContextTest {
public void testGetSetValues_Ellipse(){
ConversionContext ctx = new ConversionContext.Builder("toString", TypeLiteral.of(List.class))
.addSupportedFormats(MyConverter.class, "0.0.0.0/nnn", "x.x.x.x/yyy")
- .setValues(PropertyValue.createValue("test", "value")).build();
+ .setValues(new PropertyValue("test", "value")).build();
assertThat(ctx.getValues()).isNotNull().hasSize(1);
assertThat("value").isEqualTo(ctx.getValues().get(0).getValue());
assertThat("test").isEqualTo(ctx.getValues().get(0).getKey());
@@ -114,7 +114,7 @@ public class ConversionContextTest {
public void testGetSetValues_List(){
ConversionContext ctx = new ConversionContext.Builder("toString", TypeLiteral.of(List.class))
.addSupportedFormats(MyConverter.class, "0.0.0.0/nnn", "x.x.x.x/yyy")
- .setValues(Collections.singletonList(PropertyValue.createValue("test", "value"))).build();
+ .setValues(Collections.singletonList(new PropertyValue("test", "value"))).build();
assertThat(ctx.getValues()).isNotNull().hasSize(1);
assertThat("value").isEqualTo(ctx.getValues().get(0).getValue());
assertThat("test").isEqualTo(ctx.getValues().get(0).getKey());
@@ -124,7 +124,7 @@ public class ConversionContextTest {
public void testGetConfigurationContext(){
ConversionContext ctx = new ConversionContext.Builder("toString", TypeLiteral.of(List.class))
.addSupportedFormats(MyConverter.class, "0.0.0.0/nnn", "x.x.x.x/yyy")
- .setValues(PropertyValue.createValue("test", "value")).build();
+ .setValues(PropertyValue.createObject().setValue("test", "value")).build();
assertThat(ctx.getConfigurationContext()).isNotNull();
}
@@ -132,7 +132,7 @@ public class ConversionContextTest {
public void testGetMeta(){
ConversionContext ctx = new ConversionContext.Builder("test", TypeLiteral.of(List.class))
.addSupportedFormats(MyConverter.class, "0.0.0.0/nnn", "x.x.x.x/yyy")
- .setValues(PropertyValue.createValue("test", "value")
+ .setValues(new PropertyValue("test", "value")
.setMeta("meta1", "val1").setMeta("meta2", "val2")).build();
assertThat(ctx.getMeta()).isNotNull().isNotEmpty().hasSize(2);
}
diff --git a/code/api/src/test/java/org/apache/tamaya/spi/FilterContextTest.java b/code/api/src/test/java/org/apache/tamaya/spi/FilterContextTest.java
index 1602f57..361ded7 100644
--- a/code/api/src/test/java/org/apache/tamaya/spi/FilterContextTest.java
+++ b/code/api/src/test/java/org/apache/tamaya/spi/FilterContextTest.java
@@ -34,7 +34,7 @@ public class FilterContextTest {
@Test
public void constructorWithContext() {
- PropertyValue val = new PropertyValue(null, "");
+ PropertyValue val = new PropertyValue( "");
FilterContext ctx = new FilterContext(val, ConfigurationContext.EMPTY);
assertThat(val).isEqualTo(ctx.getProperty());
assertThat(ConfigurationContext.EMPTY).isEqualTo(ctx.getConfigurationContext());
@@ -44,27 +44,27 @@ public class FilterContextTest {
// @Test
// public void setNullContext() {
-// FilterContext.set(null);
+// FilterContext.setPropertyValue(null);
// }
//
// @Test
// public void setGetContext() {
-// PropertyValue val = PropertyValue.of("getKey", "v", "");
+// PropertyValue val = new PropertyValue( "getKey", "v", "");
// FilterContext ctx = new FilterContext(val,
// new HashMap<String,PropertyValue>(), ConfigurationContext.EMPTY);
-// FilterContext.set(ctx);
-// assertEquals(ctx, FilterContext.get());
+// FilterContext.setPropertyValue(ctx);
+// assertEquals(ctx, FilterContext.getPropertyValue());
// }
//
// @Test
// public void resetContext() {
-// PropertyValue val = PropertyValue.of("getKey", "v", "");
+// PropertyValue val = new PropertyValue( "getKey", "v", "");
// FilterContext ctx = new FilterContext(val,
// new HashMap<String,PropertyValue>(), ConfigurationContext.EMPTY);
-// FilterContext.set(ctx);
-// assertNotNull(FilterContext.get());
+// FilterContext.setPropertyValue(ctx);
+// assertNotNull(FilterContext.getPropertyValue());
// FilterContext.reset();
-// assertNull(FilterContext.get());
+// assertNull(FilterContext.getPropertyValue());
// }
@Test(expected = NullPointerException.class)
@@ -79,7 +79,7 @@ public class FilterContextTest {
@Test(expected = NullPointerException.class)
public void constructorRequiresNonNullConfigurationContextTwoParameterVariant() {
- new FilterContext(Collections.singletonList(PropertyValue.of("a", "b", "s")), null);
+ new FilterContext(Collections.singletonList(new PropertyValue( "a", "b")), null);
}
@SuppressWarnings("unchecked")
@@ -91,17 +91,17 @@ public class FilterContextTest {
@SuppressWarnings("unchecked")
@Test(expected = NullPointerException.class)
public void constructorRequiresNonNullConfigurationContextThreeParameterVariant() {
- new FilterContext(PropertyValue.of("a", "b", "s"), Collections.EMPTY_MAP, null);
+ new FilterContext(new PropertyValue( "a", "b"), Collections.EMPTY_MAP, null);
}
@Test(expected = NullPointerException.class)
public void constructorRequiresNonNullMapForConfigEntriesThreeParameterVariant() {
- new FilterContext(PropertyValue.of("a", "b", "s"), null, ConfigurationContext.EMPTY);
+ new FilterContext(new PropertyValue("a", "b"), null, ConfigurationContext.EMPTY);
}
@Test
public void getKey() throws Exception {
- PropertyValue val = PropertyValue.of("getKey", "v", "");
+ PropertyValue val = new PropertyValue( "getKey", "v");
FilterContext ctx = new FilterContext(val,
new HashMap<String,PropertyValue>(), ConfigurationContext.EMPTY);
assertThat(ctx.getProperty()).isEqualTo(val);
@@ -109,7 +109,7 @@ public class FilterContextTest {
@Test
public void isSinglePropertyScoped() throws Exception {
- PropertyValue val = PropertyValue.of("isSinglePropertyScoped", "v", "");
+ PropertyValue val = new PropertyValue( "isSinglePropertyScoped", "v");
FilterContext ctx = new FilterContext(val, new HashMap<String,PropertyValue>(), ConfigurationContext.EMPTY);
assertThat(ctx.isSinglePropertyScoped()).isEqualTo(false);
ctx = new FilterContext(Collections.singletonList(val), ConfigurationContext.EMPTY);
@@ -120,9 +120,9 @@ public class FilterContextTest {
public void getConfigEntries() throws Exception {
Map<String,PropertyValue> config = new HashMap<>();
for(int i=0;i<10;i++) {
- config.put("key-"+i, PropertyValue.of("key-"+i, "value-"+i, "test"));
+ config.put("key-"+i, new PropertyValue( "key-"+i, "value-"+i));
}
- PropertyValue val = PropertyValue.of("getConfigEntries", "v", "");
+ PropertyValue val = new PropertyValue( "getConfigEntries", "v");
FilterContext ctx = new FilterContext(val, config, ConfigurationContext.EMPTY);
assertThat(ctx.getConfigEntries()).isEqualTo(config);
assertThat(config != ctx.getConfigEntries()).isTrue();
@@ -130,18 +130,18 @@ public class FilterContextTest {
@Test
public void testToString() throws Exception {
- Map<String,PropertyValue> config = new HashMap<>();
- for(int i=0;i<2;i++) {
- config.put("key-"+i, PropertyValue.of("key-"+i, "value-"+i, "test"));
+ Map<String, PropertyValue> config = new HashMap<>();
+ for (int i = 0; i < 2; i++) {
+ config.put("key-" + i, new PropertyValue("key-" + i, "value-" + i));
}
- PropertyValue val = PropertyValue.of("testToString", "val", "mySource");
+ PropertyValue val = new PropertyValue("testToString", "val");
FilterContext ctx = new FilterContext(val, config, ConfigurationContext.EMPTY);
String toString = ctx.toString();
assertThat(toString).isNotNull();
System.out.println(toString);
- assertThat(toString).contains("FilterContext{value='[PropertyValue{'testToString', value='val'," +
- " metaData={source=mySource}}]', configEntries=[", "key-0", "key-1").endsWith("}");
+ assertThat(toString).contains("FilterContext{value='[val]', configEntries=[",
+ "key-0", "key-1").endsWith("}");
}
}
diff --git a/code/api/src/test/java/org/apache/tamaya/spi/ListValueTest.java b/code/api/src/test/java/org/apache/tamaya/spi/ListValueTest.java
index c432366..5d97f26 100644
--- a/code/api/src/test/java/org/apache/tamaya/spi/ListValueTest.java
+++ b/code/api/src/test/java/org/apache/tamaya/spi/ListValueTest.java
@@ -21,7 +21,6 @@ package org.apache.tamaya.spi;
import org.junit.Test;
import java.util.Iterator;
-import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@@ -47,65 +46,82 @@ public class ListValueTest {
@Test
public void getIndex() {
ListValue lv = PropertyValue.createList();
- PropertyValue val = PropertyValue.createValue("k", "v");
- lv.add(val);
- PropertyValue val2 = PropertyValue.createValue("k2", "v2");
- lv.add(val2);
+ PropertyValue val = new PropertyValue( "k", "v");
+ lv.addPropertyValue(val);
+ PropertyValue val2 = new PropertyValue( "k2", "v2");
+ lv.addPropertyValue(val2);
assertThat(0).isEqualTo(lv.getIndex(val));
assertThat(1).isEqualTo(lv.getIndex(val2));
- PropertyValue val3 = PropertyValue.createValue("k3", "v");
+ PropertyValue val3 = new PropertyValue( "k3", "v");
assertThat(-1).isEqualTo(lv.getIndex(val3));
}
@Test
+ public void getLists() {
+ ListValue lv = PropertyValue.createList();
+ PropertyValue val = PropertyValue.createList("k");
+ lv.addPropertyValue(val);
+ PropertyValue val2 = PropertyValue.createObject("k2");
+ lv.addPropertyValue(val2);
+ assertThat(lv.getLists()).isNotEmpty().hasSize(1);
+ }
+
+ @Test
+ public void getObjects() {
+ ListValue lv = PropertyValue.createList();
+ PropertyValue val = PropertyValue.createObject("k");
+ lv.addPropertyValue(val);
+ PropertyValue val2 = PropertyValue.createObject("k2");
+ lv.addPropertyValue(val2);
+ assertThat(lv.getObjects("[0]")).isNotEmpty().hasSize(1);
+ assertThat(lv.getObjects("[1]")).isNotEmpty().hasSize(1);
+ assertThat(lv.getObjects("foo")).isEmpty();
+ }
+
+ @Test
+ public void getStringValue() {
+ ListValue lv = PropertyValue.createList();
+ PropertyValue val = PropertyValue.createObject("k").setValue("k1", "v1");
+ lv.addPropertyValue(val);
+ assertThat(lv.getValue(0)).isNotNull();
+ assertThat(lv.getPropertyValue(0).toObjectValue().getValue("k1")).isEqualTo("v1");
+ }
+
+ @Test
public void getSize() {
ListValue lv = PropertyValue.createList();
assertThat(0).isEqualTo(lv.getSize());
- PropertyValue val = PropertyValue.createValue("k", "v");
- lv.add(val);
+ PropertyValue val = new PropertyValue( "k", "v");
+ lv.addPropertyValue(val);
assertThat(1).isEqualTo(lv.getSize());
- PropertyValue val2 = PropertyValue.createValue("k", "v");
- lv.add(val2);
+ PropertyValue val2 = new PropertyValue( "k", "v");
+ lv.addPropertyValue(val2);
assertThat(2).isEqualTo(lv.getSize());
}
@Test
public void getList() {
ListValue lv = PropertyValue.createList();
- PropertyValue val = PropertyValue.createValue("k", "v");
- lv.add(val);
- PropertyValue val2 = PropertyValue.createValue("k", "v");
- lv.add(val2);
- assertThat(lv.getValues()).isNotNull().hasSize(2);
- assertThat(val).isEqualTo(lv.getValues().get(0));
- assertThat(val2).isEqualTo(lv.getValues().get(1));
- lv.add(val2);
- assertThat(lv.getValues()).isNotNull().hasSize(2);
- assertThat(val).isEqualTo(lv.getValues().get(0));
- assertThat(val2).isEqualTo(lv.getValues().get(1));
- }
-
- @Test
- public void getList_WithPredicate() {
- ListValue lv = PropertyValue.createList();
- PropertyValue val = PropertyValue.createValue("k1", "v");
- lv.add(val);
- PropertyValue val2 = PropertyValue.createValue("k2", "v");
- lv.add(val2);
- List<PropertyValue> result = lv.getValues(
- pv -> "k1".equals(pv.getKey())
- );
- assertThat(result).isNotNull().hasSize(1);
- assertThat(val).isEqualTo(result.get(0));
+ PropertyValue val = new PropertyValue( "k", "v");
+ lv.addPropertyValue(val);
+ PropertyValue val2 = new PropertyValue( "k", "v");
+ lv.addPropertyValue(val2);
+ assertThat(lv.getSize()).isEqualTo(2);
+ assertThat(val).isEqualTo(lv.getPropertyValue(0));
+ assertThat(val2).isEqualTo(lv.getPropertyValue(1));
+ lv.addPropertyValue(val2);
+ assertThat(lv.getSize()).isEqualTo(2);
+ assertThat(val).isEqualTo(lv.getPropertyValue(0));
+ assertThat(val2).isEqualTo(lv.getPropertyValue(1));
}
@Test
public void iterator() {
ListValue lv = PropertyValue.createList();
- PropertyValue val = PropertyValue.createValue("k", "v");
- PropertyValue val2 = PropertyValue.createValue("k", "v");
- lv.add(val);
- lv.add(val2);
+ PropertyValue val = new PropertyValue( "k", "v");
+ PropertyValue val2 = new PropertyValue( "k", "v");
+ lv.addPropertyValue(val);
+ lv.addPropertyValue(val2);
Iterator iter = lv.iterator();
assertThat(iter).isNotNull();
assertThat(iter.hasNext()).isTrue();
@@ -118,12 +134,12 @@ public class ListValueTest {
@Test
public void add() {
ListValue lv = PropertyValue.createList();
- PropertyValue val = PropertyValue.createValue("k", "v");
- lv.add(val);
- lv.add(val);
- lv.add(val);
+ PropertyValue val = new PropertyValue( "k", "v");
+ lv.addPropertyValue(val);
+ lv.addPropertyValue(val);
+ lv.addPropertyValue(val);
assertThat(1).isEqualTo(lv.getSize());
- assertThat(val).isEqualTo(lv.get(0));
+ assertThat(val).isEqualTo(lv.getPropertyValue(0));
}
@@ -132,30 +148,30 @@ public class ListValueTest {
ListValue lv = PropertyValue.createList();
lv.addValue("v");
assertThat(1).isEqualTo(lv.getSize());
- assertThat("v").isEqualTo(lv.get(0).getValue());
+ assertThat("v").isEqualTo(lv.getPropertyValue(0).getValue());
lv.addValue("v2");
assertThat(2).isEqualTo(lv.getSize());
- assertThat("v2").isEqualTo(lv.get(1).getValue());
+ assertThat("v2").isEqualTo(lv.getPropertyValue(1).getValue());
lv.addValue("v");
assertThat(3).isEqualTo(lv.getSize());
- assertThat("v").isEqualTo(lv.get(2).getValue());
+ assertThat("v").isEqualTo(lv.getPropertyValue(2).getValue());
}
@Test
public void addValue_KeyValue() {
ListValue lv = PropertyValue.createList();
- lv.addValue("k", "v");
+ lv.addValue("v");
assertThat(1).isEqualTo(lv.getSize());
- assertThat("v").isEqualTo(lv.get(0).getValue());
- assertThat("k").isEqualTo(lv.get(0).getKey());
- lv.addValue("k2", "v2");
+ assertThat("v").isEqualTo(lv.getPropertyValue(0).getValue());
+ assertThat("[0]").isEqualTo(lv.getPropertyValue(0).getKey());
+ lv.addValue("v2");
assertThat(2).isEqualTo(lv.getSize());
- assertThat("v2").isEqualTo(lv.get(1).getValue());
- assertThat("k2").isEqualTo(lv.get(1).getKey());
- lv.addValue("k", "v");
+ assertThat("v2").isEqualTo(lv.getPropertyValue(1).getValue());
+ assertThat("[1]").isEqualTo(lv.getPropertyValue(1).getKey());
+ lv.addValue("v");
assertThat(3).isEqualTo(lv.getSize());
- assertThat("v").isEqualTo(lv.get(2).getValue());
- assertThat("k").isEqualTo(lv.get(2).getKey());
+ assertThat("v").isEqualTo(lv.getPropertyValue(2).getValue());
+ assertThat("[2]").isEqualTo(lv.getPropertyValue(2).getKey());
}
@Test
@@ -163,9 +179,9 @@ public class ListValueTest {
ListValue lv = PropertyValue.createList();
lv.addValues("v", "v1", "v");
assertThat(3).isEqualTo(lv.getSize());
- assertThat("v").isEqualTo(lv.get(0).getValue());
- assertThat("v1").isEqualTo(lv.get(1).getValue());
- assertThat("v").isEqualTo(lv.get(2).getValue());
+ assertThat("v").isEqualTo(lv.getPropertyValue(0).getValue());
+ assertThat("v1").isEqualTo(lv.getPropertyValue(1).getValue());
+ assertThat("v").isEqualTo(lv.getPropertyValue(2).getValue());
}
@Test
@@ -173,16 +189,7 @@ public class ListValueTest {
ListValue lv = PropertyValue.createList();
lv.addObject();
assertThat(1).isEqualTo(lv.getSize());
- ObjectValue ov = (ObjectValue)lv.get(0);
- }
-
- @Test
- public void addObject_Key() {
- ListValue lv = PropertyValue.createList();
- lv.addObject("key");
- assertThat(1).isEqualTo(lv.getSize());
- ObjectValue ov = (ObjectValue)lv.get(0);
- assertThat("key").isEqualTo(ov.getKey());
+ ObjectValue ov = (ObjectValue)lv.getPropertyValue(0);
}
@Test
@@ -190,53 +197,35 @@ public class ListValueTest {
ListValue lv = PropertyValue.createList();
lv.addList();
assertThat(1).isEqualTo(lv.getSize());
- ListValue ov = (ListValue)lv.get(0);
- assertThat("").isEqualTo(ov.getKey());
- }
-
- @Test
- public void addList_Key() {
- ListValue lv = PropertyValue.createList();
- lv.addList("key");
- assertThat(1).isEqualTo(lv.getSize());
- ListValue ov = (ListValue)lv.get(0);
- assertThat("key").isEqualTo(ov.getKey());
+ ListValue ov = (ListValue)lv.getPropertyValue(0);
+ assertThat("[0]").isEqualTo(ov.getKey());
}
@Test
public void getValues() {
ListValue lv = PropertyValue.createList();
- lv.addList("list");
- lv.addObject("object");
- assertThat(lv.getValues("")).isNotNull().hasSize(0);
- assertThat(lv.getValues("list")).hasSize(1);
- assertThat(lv.getValues("object")).hasSize(1);
- }
-
- @Test
- public void toPropertyValue() {
- ListValue lv = PropertyValue.createList("foo");
- lv.addList("list");
- PropertyValue pv = lv.toPropertyValue();
- assertThat(pv).isNotNull();
- assertThat(pv.getKey()).isEqualTo(lv.getKey());
+ lv.addList();
+ lv.addObject();
+ assertThat(lv.getPropertyValues("")).isNotNull().hasSize(0);
+ assertThat(lv.getPropertyValues("[0]")).hasSize(1);
+ assertThat(lv.getPropertyValues("[1]")).hasSize(1);
}
@Test
public void toObjectValue() {
ListValue lv = PropertyValue.createList("foo");
- lv.addList("list").setValue("a");
+ lv.addList().addValue("a");
ObjectValue ov = lv.toObjectValue();
assertThat(ov).isNotNull();
assertThat(ov.getKey()).isEqualTo(lv.getKey());
- assertThat(ov.getValue("list[0]")).isNotNull();
- assertThat(lv.getLists("list").get(0).getValue()).isEqualTo(ov.getValue("list[0]").getValue());
+ assertThat(ov.getValue("[0]")).isNotNull();
+ assertThat(ov.getValue("[0]")).isEqualTo("List: [a]");
}
@Test
public void toListValue() {
ListValue lv = PropertyValue.createList("foo");
- lv.addList("list");
+ lv.addList();
ListValue lv2 = lv.toListValue();
assertThat(lv == lv2).isTrue();
}
@@ -244,7 +233,7 @@ public class ListValueTest {
@Test
public void mutable() {
ListValue lv = PropertyValue.createList("foo");
- lv.addList("list");
+ lv.addList();
assertThat(lv.isImmutable()).isFalse();
ListValue lv2 = lv.mutable();
assertThat(lv2.isImmutable()).isFalse();
@@ -254,9 +243,8 @@ public class ListValueTest {
@Test
public void deepClone() {
ListValue lv1 = PropertyValue.createList("foo");
- lv1.addList("list");
+ lv1.addList();
ListValue lv2 = lv1.deepClone();
- assertThat(lv1.getValues()!=lv2.getValues()).isTrue();
assertThat(lv1.getMeta()!=lv2.getMeta()).isTrue();
assertThat(lv1.equals(lv2)).isTrue();
assertThat(lv1.iterator().next()!=lv2.iterator().next()).isTrue();
@@ -265,18 +253,18 @@ public class ListValueTest {
@Test
public void equals() {
ListValue lv1 = PropertyValue.createList("foo");
- lv1.addList("list");
+ lv1.addList();
ListValue lv2 = PropertyValue.createList("foo");
- lv2.addList("list");
+ lv2.addList();
assertThat(lv1.equals(lv2)).isTrue();
}
@Test
public void testHashCode() {
ListValue lv1 = PropertyValue.createList("foo");
- lv1.addList("list");
+ lv1.addList();
ListValue lv2 = PropertyValue.createList("foo");
- lv2.addList("list");
+ lv2.addList();
assertThat(lv1.hashCode() == lv2.hashCode()).isTrue();
}
@@ -285,15 +273,16 @@ public class ListValueTest {
ListValue lv1 = PropertyValue.createList("foo");
String toString = lv1.toString();
assertThat(toString).isNotNull();
- lv1.addList("list");
+ lv1.addList();
toString = lv1.toString();
assertThat(toString).isNotNull();
- lv1.addObject("object");
+ lv1.addObject();
toString = lv1.toString();
assertThat(toString).isNotNull();
lv1.addValue("valueKey");
toString = lv1.toString();
assertThat(toString).isNotNull();
- assertThat("PropertyValue[ARRAY]{'foo', size='3'}").isEqualTo(toString);
+ assertThat("List{, size='3', values=[List{, size='0', values=[]}, Object{size='0', values='{}}, " +
+ "valueKey]}").isEqualTo(toString);
}
}
diff --git a/code/api/src/test/java/org/apache/tamaya/spi/ObjectValueTest.java b/code/api/src/test/java/org/apache/tamaya/spi/ObjectValueTest.java
index 8e1fcb1..67ca968 100644
--- a/code/api/src/test/java/org/apache/tamaya/spi/ObjectValueTest.java
+++ b/code/api/src/test/java/org/apache/tamaya/spi/ObjectValueTest.java
@@ -49,59 +49,94 @@ public class ObjectValueTest {
@Test
public void getIndex() {
ObjectValue ov = PropertyValue.createObject();
- PropertyValue val = PropertyValue.createValue("k", "v");
- ov.set(val);
- PropertyValue val2 = PropertyValue.createValue("k2", "v2");
- ov.set(val2);
- assertThat(val).isEqualTo(ov.getValue(val.getKey()));
- assertThat(val2).isEqualTo(ov.getValue(val2.getKey()));
- assertThat(ov.getValue("foo")).isNull();
+ PropertyValue val = new PropertyValue("k", "v");
+ ov.setPropertyValue(val);
+ PropertyValue val2 = new PropertyValue("k2", "v2");
+ ov.setPropertyValue(val2);
+ assertThat(val).isEqualTo(ov.getPropertyValue(val.getKey()));
+ assertThat(val2).isEqualTo(ov.getPropertyValue(val2.getKey()));
+ assertThat(ov.getPropertyValue("foo")).isNull();
+ }
+
+ @Test
+ public void getKeys() {
+ ObjectValue ov = PropertyValue.createObject();
+ PropertyValue val = new PropertyValue("k", "v");
+ ov.setPropertyValue(val);
+ PropertyValue val2 = new PropertyValue("k2", "v2");
+ ov.setPropertyValue(val2);
+ assertThat(ov.getKeys()).contains("k", "k2");
}
@Test
public void getSize() {
ObjectValue ov = PropertyValue.createObject();
assertThat(0).isEqualTo(ov.getSize());
- PropertyValue val = PropertyValue.createValue("k", "v");
- ov.set(val);
+ PropertyValue val = new PropertyValue("k", "v");
+ ov.setPropertyValue(val);
assertThat(1).isEqualTo(ov.getSize());
- PropertyValue val2 = PropertyValue.createValue("k2", "v");
- ov.set(val2);
+ PropertyValue val2 = new PropertyValue("k2", "v");
+ ov.setPropertyValue(val2);
assertThat(2).isEqualTo(ov.getSize());
- PropertyValue val3 = PropertyValue.createValue("k2", "v");
- ov.set(val3);
+ PropertyValue val3 = new PropertyValue("k2", "v");
+ ov.setPropertyValue(val3);
assertThat(2).isEqualTo(ov.getSize());
}
@Test
public void getValue() {
ObjectValue ov = PropertyValue.createObject();
- PropertyValue val = PropertyValue.createValue("k1", "v");
- ov.set(val);
- PropertyValue val2 = PropertyValue.createValue("k2", "v");
- ov.set(val2);
+ PropertyValue val = new PropertyValue("k1", "v");
+ ov.setPropertyValue(val);
+ PropertyValue val2 = new PropertyValue("k2", "v");
+ ov.setPropertyValue(val2);
assertThat(ov.getValues()).isNotNull().hasSize(2);
- assertThat(val).isEqualTo(ov.getValue("k1"));
- assertThat(val2).isEqualTo(ov.getValue("k2"));
- ov.set(val2);
+ assertThat(val).isEqualTo(ov.getPropertyValue("k1"));
+ assertThat(val2).isEqualTo(ov.getPropertyValue("k2"));
+ ov.setPropertyValue(val2);
assertThat(ov.getValues()).isNotNull().hasSize(2);
- assertThat(val).isEqualTo(ov.getValue("k1"));
- assertThat(val2).isEqualTo(ov.getValue("k2"));
+ assertThat(val).isEqualTo(ov.getPropertyValue("k1"));
+ assertThat(val2).isEqualTo(ov.getPropertyValue("k2"));
+ }
+
+ @Test
+ public void setValueWithCompositeKeys_KeyValue() {
+ ObjectValue ov = PropertyValue.createObject();
+ ov.setValueWithCompositeKey("a.b", "val");
+ assertThat(ov.toLocalMap()).containsKeys("b");
+ }
+
+ @Test
+ public void setValueWithCompositeKeys_Map() {
+ ObjectValue ov = PropertyValue.createObject();
+ Map<String,String> data = new HashMap<>();
+ data.put("a.b", "val");
+ ov.setValueWithCompositeKey(data);
+ assertThat(ov.toLocalMap()).containsKeys("b");
+ }
+
+ @Test
+ public void getStringValue() {
+ ObjectValue ov = PropertyValue.createObject();
+ PropertyValue val = new PropertyValue("k1", "v");
+ ov.setPropertyValue(val);
+ assertThat(ov.getValue("k1")).isEqualTo("v");
+ assertThat(ov.getValue("foo")).isNull();
}
@Test
public void getOrSetValue() {
ObjectValue ov = PropertyValue.createObject();
- PropertyValue val = PropertyValue.createValue("k1", "v");
- ov.set(val);
+ PropertyValue val = new PropertyValue("k1", "v");
+ ov.setPropertyValue(val);
PropertyValue val2 = ov.getOrSetValue("k2",
- () -> PropertyValue.createValue("foo", "bar"));
- PropertyValue pv = ov.getOrSetValue("foo", () -> PropertyValue.createValue("foo", "bar"));
+ () -> new PropertyValue("foo", "bar"));
+ PropertyValue pv = ov.getOrSetValue("foo", () -> new PropertyValue("foo", "bar"));
assertThat(pv).isNotNull();
assertThat(ov.getValues()).hasSize(3);
- assertThat(val).isEqualTo(ov.getValue("k1"));
- assertThat(val2).isEqualTo(ov.getValue("k2"));
- assertThat(pv).isEqualTo(ov.getValue("foo"));
+ assertThat(val).isEqualTo(ov.getPropertyValue("k1"));
+ assertThat(val2).isEqualTo(ov.getPropertyValue("k2"));
+ assertThat(pv).isEqualTo(ov.getPropertyValue("foo"));
}
@Test
@@ -112,7 +147,7 @@ public class ObjectValueTest {
map.put("k2.k3", "v2");
map.put("foo", "bar");
ov.setValues(map);
- PropertyValue pv = ov.getValue("foo");
+ PropertyValue pv = ov.getPropertyValue("foo");
assertThat(pv).isNotNull();
assertThat("foo").isEqualTo(pv.getKey());
assertThat("bar").isEqualTo(pv.getValue());
@@ -121,10 +156,10 @@ public class ObjectValueTest {
@Test
public void iterator() {
ObjectValue ov = PropertyValue.createObject();
- PropertyValue val = PropertyValue.createValue("k1", "v");
- PropertyValue val2 = PropertyValue.createValue("k2", "v");
- ov.set(val);
- ov.set(val2);
+ PropertyValue val = new PropertyValue("k1", "v");
+ PropertyValue val2 = new PropertyValue("k2", "v");
+ ov.setPropertyValue(val);
+ ov.setPropertyValue(val2);
Iterator iter = ov.iterator();
assertThat(iter).isNotNull();
assertThat(iter.hasNext()).isTrue();
@@ -137,21 +172,20 @@ public class ObjectValueTest {
@Test
public void set() {
ObjectValue ov = PropertyValue.createObject();
- PropertyValue val = PropertyValue.createValue("k", "v");
- ov.set(val);
- ov.set(val);
- ov.set(val);
+ PropertyValue val = new PropertyValue("k", "v");
+ ov.setPropertyValue(val);
+ ov.setPropertyValue(val);
+ ov.setPropertyValue(val);
assertThat(1).isEqualTo(ov.getSize());
- assertThat(val).isEqualTo(ov.getValue("k"));
+ assertThat(val).isEqualTo(ov.getPropertyValue("k"));
}
@Test
public void getSet_Value() {
ObjectValue ov = PropertyValue.createObject();
- ov.setValue("v");
assertThat(0).isEqualTo(ov.getSize());
- assertThat("v").isEqualTo(ov.getValue());
+ assertThat(ov.getValue()).isNotNull();
}
@Test
@@ -159,16 +193,16 @@ public class ObjectValueTest {
ObjectValue ov = PropertyValue.createObject();
ov.setValue("k", "v");
assertThat(1).isEqualTo(ov.getSize());
- assertThat("v").isEqualTo(ov.getValue("k").getValue());
- assertThat("k").isEqualTo(ov.getValue("k").getKey());
+ assertThat("v").isEqualTo(ov.getValue("k"));
+ assertThat("k").isEqualTo(ov.getPropertyValue("k").getKey());
ov.setValue("k2", "v2");
assertThat(2).isEqualTo(ov.getSize());
- assertThat("v2").isEqualTo(ov.getValue("k2").getValue());
- assertThat("k2").isEqualTo(ov.getValue("k2").getKey());
+ assertThat("v2").isEqualTo(ov.getValue("k2"));
+ assertThat("k2").isEqualTo(ov.getPropertyValue("k2").getKey());
ov.setValue("k", "v");
assertThat(2).isEqualTo(ov.getSize());
- assertThat("v").isEqualTo(ov.getValue("k").getValue());
- assertThat("k").isEqualTo(ov.getValue("k").getKey());
+ assertThat("v").isEqualTo(ov.getPropertyValue("k").getValue());
+ assertThat("k").isEqualTo(ov.getPropertyValue("k").getKey());
}
@Test
@@ -176,11 +210,11 @@ public class ObjectValueTest {
ObjectValue ov = PropertyValue.createObject();
ov.setValueWithCompositeKey("k1.k2.k3", "v");
assertThat(1).isEqualTo(ov.getSize());
- ObjectValue treeNode = (ObjectValue)ov.getValue("k1");
+ ObjectValue treeNode = (ObjectValue)ov.getPropertyValue("k1");
assertThat(treeNode).isNotNull();
- treeNode = (ObjectValue)treeNode.getValue("k2");
+ treeNode = (ObjectValue)treeNode.getPropertyValue("k2");
assertThat(treeNode).isNotNull();
- PropertyValue finalValue = treeNode.getValue("k3");
+ PropertyValue finalValue = treeNode.getPropertyValue("k3");
assertThat(finalValue).isNotNull();
assertThat("v").isEqualTo(finalValue.getValue());
}
@@ -189,9 +223,9 @@ public class ObjectValueTest {
@Test
public void setObject() {
ObjectValue ov = PropertyValue.createObject();
- ov.setObject("k");
+ ov.addObject("k");
assertThat(1).isEqualTo(ov.getSize());
- ObjectValue ov2 = (ObjectValue)ov.getValue("k");
+ ObjectValue ov2 = (ObjectValue)ov.getPropertyValue("k");
assertThat(ov2).isNotNull();
assertThat("k").isEqualTo(ov2.getKey());
}
@@ -199,72 +233,49 @@ public class ObjectValueTest {
@Test
public void setList() {
ObjectValue ov = PropertyValue.createObject();
- ov.setList("k");
+ ov.addList("k");
assertThat(1).isEqualTo(ov.getSize());
- ListValue lv = (ListValue)ov.getValue("k");
+ ListValue lv = (ListValue)ov.getPropertyValue("k");
assertThat("k").isEqualTo(lv.getKey());
}
@Test
public void getValue_WithName() {
ObjectValue ov = PropertyValue.createObject();
- ov.setList("k1");
- ov.setList("k2");
- ov.setObject("k3");
+ ov.addList("k1");
+ ov.addList("k2");
+ ov.addObject("k3");
ov.setValue("k4", "v");
Collection<PropertyValue> values = ov.getValues();
assertThat(values).isNotNull().hasSize(4);
}
@Test
- public void getValues_WithPredicate() {
- ObjectValue ov = PropertyValue.createObject();
- ov.setList("k1");
- ov.setList("k2");
- ov.setObject("k3");
- ov.setValue("k4", "v");
- Collection<PropertyValue> values = ov.getValues(
- pv -> "k1".equals(pv.getKey())
- );
- assertThat(values).isNotNull().hasSize(1);
- assertThat("k1").isEqualTo(values.iterator().next().getKey());
- }
-
- @Test
public void getValues() {
ObjectValue ov = PropertyValue.createObject();
- ov.setList("k1");
- ov.setList("k2");
- ov.setObject("k3");
+ ov.addList("k1");
+ ov.addList("k2");
+ ov.addObject("k3");
ov.setValue("k4", "v");
Collection<PropertyValue> values = ov.getValues();
assertThat(values).isNotNull().hasSize(4);
}
@Test
- public void toPropertyValue() {
- ObjectValue ov = PropertyValue.createObject("foo");
- ov.setList("list");
- PropertyValue pv = ov.toPropertyValue();
- assertThat(pv).isNotNull();
- assertThat(pv.getKey()).isEqualTo(ov.getKey());
- }
-
- @Test
public void toListValue() {
ObjectValue ov = PropertyValue.createObject("foo");
- ov.setList("list").setValue("a");
+ ov.addList("list").addValue("a");
ListValue lv = ov.toListValue();
assertThat(lv).isNotNull();
assertThat(lv.getKey()).isEqualTo(ov.getKey());
- assertThat(lv.get(0)).isNotNull();
- assertThat(ov.getValue("list").getValue()).isEqualTo(lv.get(0).getValue());
+ assertThat(lv.getPropertyValue(0)).isNotNull();
+ assertThat(ov.getValue("list")).isEqualTo(lv.getPropertyValue(0).getValue());
}
@Test
public void toObjectValue() {
ObjectValue ov = PropertyValue.createObject("foo");
- ov.setList("list");
+ ov.addList("list");
ObjectValue ov2 = ov.toObjectValue();
assertThat(ov == ov2).isTrue();
}
@@ -272,7 +283,7 @@ public class ObjectValueTest {
@Test
public void mutable() {
ObjectValue ov = PropertyValue.createObject("foo");
- ov.setList("list");
+ ov.addList("list");
assertThat(ov.isImmutable()).isFalse();
ObjectValue ov2 = ov.mutable();
assertThat(ov2.isImmutable()).isFalse();
@@ -280,9 +291,37 @@ public class ObjectValueTest {
}
@Test
+ public void testSetValues_WithSource() throws Exception {
+ Map<String, String> map = new HashMap<>();
+ map.put("a", "b");
+ map.put("b", "c");
+ ObjectValue ov = PropertyValue.createObject();
+ ov.setValues(map, "source", true);
+ assertThat(ov.getSize()).isEqualTo(map.size());
+ for(PropertyValue pv:ov){
+ assertThat("source").isEqualTo(pv.getMeta("source"));
+ }
+ assertThat("b").isEqualTo(ov.getValue("a"));
+ assertThat("c").isEqualTo(ov.getValue("b"));
+ }
+
+ @Test
+ public void testSetValues() {
+ Map<String, String> map = new HashMap<>();
+ map.put("a", "b");
+ map.put("b", "c");
+ ObjectValue ov = PropertyValue.createObject();
+ ov.setValues(map);
+ assertThat(ov.getSize()).isEqualTo(map.size());
+ assertThat(ov.getSize()).isEqualTo(map.size());
+ assertThat("b").isEqualTo(ov.getValue("a"));
+ assertThat("c").isEqualTo(ov.getValue("b"));
+ }
+
+ @Test
public void deepClone() {
ObjectValue ov1 = PropertyValue.createObject("foo");
- ov1.setList("list");
+ ov1.addList("list");
ObjectValue ov2 = ov1.deepClone();
assertThat(ov1.getValues()!=ov2.getValues()).isTrue();
assertThat(ov1.getMeta()!=ov2.getMeta()).isTrue();
@@ -293,18 +332,18 @@ public class ObjectValueTest {
@Test
public void equals() {
ObjectValue ov1 = PropertyValue.createObject("foo");
- ov1.setList("list");
+ ov1.addList("list");
ObjectValue ov2 = PropertyValue.createObject("foo");
- ov2.setList("list");
+ ov2.addList("list");
assertThat(ov1.equals(ov2)).isTrue();
}
@Test
public void testHashCode() {
ObjectValue ov1 = PropertyValue.createObject("foo");
- ov1.setList("list");
+ ov1.addList("list");
ObjectValue ov2 = PropertyValue.createObject("foo");
- ov2.setList("list");
+ ov2.addList("list");
assertThat(ov1.hashCode() == ov2.hashCode()).isTrue();
}
@@ -313,15 +352,15 @@ public class ObjectValueTest {
ObjectValue ov1 = PropertyValue.createObject("foo");
String toString = ov1.toString();
assertThat(toString).isNotNull();
- ov1.setList("list");
+ ov1.addList("list");
toString = ov1.toString();
assertThat(toString).isNotNull();
- ov1.setObject("object");
+ ov1.addObject("object");
toString = ov1.toString();
assertThat(toString).isNotNull();
ov1.setValue("valueKey", "value");
toString = ov1.toString();
assertThat(toString).isNotNull();
- assertThat("PropertyValue[MAP]{'foo', size='3'}").isEqualTo(toString);
+ assertThat("Object{size='3', values='{valueKey=value}}").isEqualTo(toString);
}
}
diff --git a/code/api/src/test/java/org/apache/tamaya/spi/PropertySourceTest.java b/code/api/src/test/java/org/apache/tamaya/spi/PropertySourceTest.java
index 139e85b..a3b7fdc 100644
--- a/code/api/src/test/java/org/apache/tamaya/spi/PropertySourceTest.java
+++ b/code/api/src/test/java/org/apache/tamaya/spi/PropertySourceTest.java
@@ -49,9 +49,9 @@ public class PropertySourceTest {
public void getOrdinal(){
assertThat(0).isEqualTo(new PropertySourceImpl().getOrdinal());
PropertySourceImpl ps = new PropertySourceImpl();
- ps.value = PropertyValue.createValue(PropertySource.TAMAYA_ORDINAL, "123");
+ ps.value = new PropertyValue(PropertySource.TAMAYA_ORDINAL, "123");
assertThat(123).isEqualTo(ps.getOrdinal());
- ps.value = PropertyValue.createValue(PropertySource.TAMAYA_ORDINAL, "abc");
+ ps.value = new PropertyValue(PropertySource.TAMAYA_ORDINAL, "abc");
assertThat(0).isEqualTo(ps.getOrdinal());
}
diff --git a/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueBuilderTest.java b/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueBuilderTest.java
index 3af9775..c718aa1 100644
--- a/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueBuilderTest.java
+++ b/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueBuilderTest.java
@@ -199,17 +199,17 @@
//
// @Test(expected = NullPointerException.class)
// public void mapThreeParameterVariantRequiresNonNullValueForConfigParameter() {
-// PropertyValueBuilder.map(null, "a", Collections.EMPTY_MAP);
+// PropertyValueBuilder.mapProperties(null, "a", Collections.EMPTY_MAP);
// }
//
// @Test
// public void mapThreeParameterVariantRequiresNonNullValueForSource() {
-// PropertyValueBuilder.map(Collections.EMPTY_MAP, null, Collections.EMPTY_MAP);
+// PropertyValueBuilder.mapProperties(Collections.EMPTY_MAP, null, Collections.EMPTY_MAP);
// }
//
// @Test(expected = NullPointerException.class)
// public void mapThreeParameterVariantRequiresNonNullValueForMetaData() {
-// PropertyValueBuilder.map(Collections.EMPTY_MAP, "s", null);
+// PropertyValueBuilder.mapProperties(Collections.EMPTY_MAP, "s", null);
// }
//
//}
\ No newline at end of file
diff --git a/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueTest.java b/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueTest.java
index 2a5f946..1f2e5fd 100644
--- a/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueTest.java
+++ b/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueTest.java
@@ -20,6 +20,7 @@ package org.apache.tamaya.spi;
import org.junit.Test;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -28,32 +29,29 @@ import static org.assertj.core.api.Assertions.assertThat;
@SuppressWarnings("unchecked")
public class PropertyValueTest {
- @Test(expected = NullPointerException.class)
- public void ofDoesNotAcceptNullAsKey() throws Exception {
- PropertyValue.of(null, "b", "source");
- }
-
- @Test
- public void ofDoesAcceptNullAsSource() throws Exception {
- PropertyValue.of("a", "b", null);
- }
-
@Test
- public void builder() throws Exception {
- PropertyValueBuilder b = PropertyValue.builder("a", "b");
- assertThat(b).isNotNull();
- assertThat("a").isEqualTo(b.key);
- assertThat("b").isEqualTo(b.source);
- }
-
- @Test
- public void testOf(){
- assertThat(PropertyValue.of("k", "v", "testGetKey")).isNotNull();
- }
-
- @Test(expected = NullPointerException.class)
- public void getMetaEntryRequiresNonNullValueForKey() {
- PropertyValue.of("a", "b", "s").getMeta(null);
+ public void from(){
+
+ ObjectValue val = ObjectValue.from(Arrays.asList());
+ assertThat(val).isNotNull();
+ val = ObjectValue.from(Arrays.asList(
+ PropertyValue.createObject("o1").setValue("key", "value"),
+ PropertyValue.createObject("o2").setValue("key2", "value2"))
+ );
+ assertThat(val).isNotNull();
+ assertThat(val.getValue("o1")).isNotNull();
+ assertThat(val.getValue("o2")).isNotNull();
+ assertThat(val.getPropertyValue("o1").toObjectValue().getValue("key")).isEqualTo("value");
+ assertThat(val.getPropertyValue("o2").toObjectValue().getValue("key2")).isEqualTo("value2");
+ val = ObjectValue.from(Arrays.asList(
+ PropertyValue.createList("o1").addValue("value"),
+ new PropertyValue( "o2", "value2"))
+ );
+ assertThat(val).isNotNull();
+ assertThat(val.getValue("o1")).isNotNull();
+ assertThat(val.getValue("o2")).isNotNull();
+ assertThat(val.getPropertyValue("o1").toListValue().getValue(0)).isEqualTo("value");
+ assertThat(val.getPropertyValue("o2").getValue()).isEqualTo("value2");
}
@Test(expected = NullPointerException.class)
@@ -113,80 +111,39 @@ public class PropertyValueTest {
@Test
public void testGetMetaEntries2() throws Exception {
- PropertyValue pv = PropertyValue.of("k", "v", null);
+ PropertyValue pv = new PropertyValue( "k", "v");
assertThat(pv.getMeta()).isNotNull().isEmpty();
}
@Test
- public void testMap() throws Exception {
- Map<String, String> map = new HashMap<>();
- map.put("a", "b");
- map.put("b", "c");
- Map<String, PropertyValue> result = PropertyValue.map(map, "source");
- assertThat(result).isNotNull().hasSize(map.size());
- for(PropertyValue pv:result.values()){
- assertThat("source").isEqualTo(pv.getMetaEntry("source"));
- }
- assertThat("b").isEqualTo(map.get("a"));
- assertThat("c").isEqualTo(map.get("b"));
- }
-
- @Test
- public void testMap_WithMeta() throws Exception {
- Map<String, String> map = new HashMap<>();
- map.put("a", "b");
- map.put("b", "c");
- Map<String, String> meta = new HashMap<>();
- meta.put("m1", "m1v");
- meta.put("m2", "m2v");
- Map<String, PropertyValue> result = PropertyValue.map(map, "source", meta);
- assertThat(result).isNotNull().hasSize(map.size());
- for(PropertyValue pv:result.values()){
- assertThat("source").isEqualTo(pv.getMetaEntry("source"));
- assertThat("m1v").isEqualTo(pv.getMeta("m1"));
- assertThat("m2v").isEqualTo(pv.getMeta("m2"));
- }
- assertThat("b").isEqualTo(map.get("a"));
- assertThat("c").isEqualTo(map.get("b"));
- }
-
- @Test
public void testHashCode(){
- assertThat(PropertyValue.of("k", "v", "testGetKey").hashCode()).isEqualTo(PropertyValue.of("k", "v", "testGetKey").hashCode());
- assertThat(PropertyValue.of("k", "v", "testGetKey").hashCode()).isNotSameAs(PropertyValue.of("k1", "v", "testGetKey").hashCode());
- assertThat(PropertyValue.of("k", "v", "testGetKey").hashCode()).isNotSameAs(PropertyValue.of("k", "v1", "testGetKey").hashCode());
- assertThat(PropertyValue.of("k", "v", "1").hashCode()).isNotSameAs(PropertyValue.of("k", "v", "2").hashCode());
+ assertThat(new PropertyValue( "k", "v").hashCode()).isEqualTo(new PropertyValue( "k", "v").hashCode());
+ assertThat(new PropertyValue( "k", "v").hashCode()).isNotSameAs(new PropertyValue( "k1", "v").hashCode());
+ assertThat(new PropertyValue( "k", "v").hashCode()).isNotSameAs(new PropertyValue( "k", "v1").hashCode());
+ assertThat(new PropertyValue( "k", "v").hashCode()).isNotSameAs(new PropertyValue( "k", "v").hashCode());
}
@Test
public void testEquals(){
- assertThat(PropertyValue.of("k", "v", "testEquals")).isEqualTo(PropertyValue.of("k", "v", "testEquals"));
- assertThat(PropertyValue.of("k2", "v", "testEquals")).isNotSameAs(PropertyValue.of("k", "v", "testEquals"));
- assertThat(PropertyValue.of("k", "v", "testEquals")).isNotSameAs(PropertyValue.of("k", "v2", "testEquals"));
- assertThat(PropertyValue.of("k", "v", "testEquals")).isNotSameAs(PropertyValue.of("k", "v", "testEquals2"));
+ assertThat(new PropertyValue( "k", "v")).isEqualTo(new PropertyValue( "k", "v"));
+ assertThat(new PropertyValue( "k2", "v")).isNotSameAs(new PropertyValue( "k", "v"));
+ assertThat(new PropertyValue( "k", "v")).isNotSameAs(new PropertyValue( "k", "v2"));
+ assertThat(new PropertyValue( "k", "v")).isNotSameAs(new PropertyValue( "k", "v"));
}
@Test
public void testGetKey() throws Exception {
- PropertyValue pv = PropertyValue.of("k", "v", "testGetKey");
+ PropertyValue pv = new PropertyValue( "k", "v");
assertThat(pv.getKey()).isEqualTo("k");
}
@Test
public void testGetValue() throws Exception {
- PropertyValue pv = PropertyValue.of("k", "v", "testGetValue");
+ PropertyValue pv = new PropertyValue("k", "v");
assertThat(pv.getValue()).isEqualTo("v");
}
@Test
- public void testGetSource() throws Exception {
- PropertyValue pv = PropertyValue.of("k", "v", "testGetSource");
- assertThat(pv.getSource()).isEqualTo("testGetSource");
- pv = PropertyValue.of("k", "v", "testGetSource");
- assertThat(pv.getSource()).isEqualTo("testGetSource");
- }
-
- @Test
public void testGetMetaEntry() throws Exception {
PropertyValue pv = PropertyValue.createObject("k")
.setMeta("k", "v2");
@@ -202,17 +159,17 @@ public class PropertyValueTest {
@Test(expected = NullPointerException.class)
public void testInstantiateNoKey2() throws Exception {
- PropertyValue.createValue(null, "v");
+ new PropertyValue( null, "v");
}
@Test
public void testInstantiateNoValue2() throws Exception {
- PropertyValue.createValue("k", null);
+ new PropertyValue("k", null);
}
@Test
public void testInstantiateNoSource2() throws Exception {
- PropertyValue.createValue("k", "v");
+ new PropertyValue("k", "v");
}
@Test(expected = NullPointerException.class)
@@ -227,7 +184,7 @@ public class PropertyValueTest {
@Test
public void newXXX() {
- assertThat(PropertyValue.createValue("", null)).isNotNull();
+ assertThat(new PropertyValue("", null)).isNotNull();
assertThat(PropertyValue.createObject()).isNotNull();
assertThat(PropertyValue.createObject("")).isNotNull();
assertThat(PropertyValue.createList()).isNotNull();
@@ -236,7 +193,7 @@ public class PropertyValueTest {
@Test
public void valueOf() {
- PropertyValue foo = PropertyValue.createValue("foo", "bar");
+ PropertyValue foo = new PropertyValue("foo", "bar");
assertThat(foo).isNotNull();
assertThat("foo").isEqualTo(foo.getKey());
assertThat("bar").isEqualTo(foo.getValue());
@@ -255,10 +212,10 @@ public class PropertyValueTest {
assertThat(root.getSize() == 0).isTrue();
assertThat(root.setValue("foo", null)).isNotNull();
assertThat(root.getSize()==0).isFalse();
- assertThat(root.getValue("foo")).isNotNull();
- assertThat(root.getValue("foo").getValue()).isNull();
+ assertThat(root.getPropertyValue("foo")).isNotNull();
+ assertThat(root.getValue("foo")).isEqualTo("null");
assertThat(root.setValue("foo", "bar")).isNotNull();
- assertThat(root.getValue("foo").getValue()).isEqualTo("bar");
+ assertThat(root.getValue("foo")).isEqualTo("bar");
assertThat(root.getSize()==1).isTrue();
}
@@ -280,15 +237,16 @@ public class PropertyValueTest {
ObjectValue root = PropertyValue.createObject("a");
assertThat("a").isEqualTo(root.getQualifiedKey());
ObjectValue child = PropertyValue.createObject("b");
- ObjectValue n = root.set(child);
+ ObjectValue n = root.setPropertyValue(child);
assertThat("a.b").isEqualTo(child.getQualifiedKey());
- PropertyValue added = child.setValue("c", null);
- assertThat("a.b.c").isEqualTo(added.getQualifiedKey());
+ child.setValue("c", null);
+ PropertyValue val = child.getPropertyValue("c");
+ assertThat("a.b.c").isEqualTo(val.getQualifiedKey());
}
@Test
public void isLeaf() {
- PropertyValue n = PropertyValue.createValue("", "");
+ PropertyValue n = new PropertyValue("", "");
assertThat(n.isLeaf()).isTrue();
n = PropertyValue.createList("");
assertThat(n.isLeaf()).isFalse();
@@ -296,7 +254,7 @@ public class PropertyValueTest {
@Test
public void isImmutable() {
- PropertyValue n = PropertyValue.createValue("", "");
+ PropertyValue n = new PropertyValue("", "");
assertThat(n.isImmutable()).isFalse();
n.immutable();
assertThat(n.isImmutable()).isTrue();
@@ -305,22 +263,22 @@ public class PropertyValueTest {
@Test
public void isRoot() {
- PropertyValue n = PropertyValue.createValue("", "");
+ PropertyValue n = new PropertyValue("", "");
assertThat(n.isRoot()).isTrue();
- n = PropertyValue.createValue("", "").setParent(n);
+ n = new PropertyValue("", "").setParent(n);
assertThat(n.isRoot()).isFalse();
}
@Test(expected=IllegalStateException.class)
public void checkImmutableChangeThrowsExceotion() {
- PropertyValue n = PropertyValue.createValue("", "");
+ PropertyValue n = new PropertyValue("", "");
n.immutable();
n.setValue("jhgjg");
}
@Test
public void checkMutable() {
- PropertyValue n = PropertyValue.createValue("", "");
+ PropertyValue n = new PropertyValue("", "");
n.immutable();
n = n.mutable();
n.setValue("jhgjg");
@@ -331,22 +289,22 @@ public class PropertyValueTest {
public void getParent() {
ObjectValue n = PropertyValue.createObject("");
assertThat(n.getParent()).isNull();
- PropertyValue val = n.setObject("b");
+ PropertyValue val = n.addObject("b");
assertThat(n.getValue("b")).isNotNull();
- assertThat(val).isEqualTo(n.getValue("b"));
- assertThat(n.getValue("b").getParent()).isNotNull();
+ assertThat(val).isEqualTo(n.getPropertyValue("b"));
+ assertThat(n.getPropertyValue("b").getParent()).isNotNull();
}
@Test
public void size(){
- PropertyValue n = PropertyValue.createValue("key", "");
+ PropertyValue n = new PropertyValue("key", "");
assertThat(0).isEqualTo(n.getSize());
assertThat(n.iterator().hasNext()).isFalse();
}
@Test
public void setValue() {
- PropertyValue n = PropertyValue.createValue("key", "");
+ PropertyValue n = new PropertyValue("key", "");
assertThat("").isEqualTo(n.getValue());
n.setValue("jhgjg");
assertThat("jhgjg").isEqualTo(n.getValue());
@@ -354,33 +312,21 @@ public class PropertyValueTest {
@Test
public void setKey() {
- PropertyValue n = PropertyValue.createValue("key", "");
+ PropertyValue n = new PropertyValue("key", "");
assertThat("key").isEqualTo(n.getKey());
n.setKey("jhgjg");
assertThat("jhgjg").isEqualTo(n.getKey());
}
@Test
- public void toBuilder() {
- PropertyValue n = PropertyValue.createValue("key", "");
- assertThat(n.toBuilder()).isNotNull();
- }
-
- @Test
- public void toPropertyValue() {
- PropertyValue n = PropertyValue.createValue("key", "");
- assertThat(n == n.toPropertyValue()).isTrue();
- }
-
- @Test
public void toObjectValue() {
- PropertyValue n = PropertyValue.createValue("key", "");
+ PropertyValue n = new PropertyValue("key", "");
assertThat(n.toObjectValue()).isNotNull();
}
@Test
public void toListValue() {
- PropertyValue n = PropertyValue.createValue("key", "");
+ PropertyValue n = new PropertyValue("key", "");
assertThat(n.toListValue()).isNotNull();
}
@@ -391,25 +337,25 @@ public class PropertyValueTest {
// n.setField("b");
// n.setField("c");
// n.setField("c");
-// List<PropertyValue> nodes = n.getValues("a");
+// List<PropertyValue> nodes = n.getPropertyValues("a");
// assertNotNull(nodes);
// assertEquals(1, nodes.size());
// assertEquals("a", nodes.getValue(0).getKey());
//
-// nodes = n.getValues("c");
+// nodes = n.getPropertyValues("c");
// assertEquals(2, nodes.size());
// assertEquals("c", nodes.getValue(0).getKey());
// assertEquals("c", nodes.getValue(1).getKey());
// }
//
// @Test
-// public void getValues() {
+// public void getPropertyValues() {
// PropertyValue n = PropertyValue.createObject();
// n.setField("a");
// n.setField("b");
// n.setField("c");
// n.setField("c");
-// List<PropertyValue> nodes = n.getValues();
+// List<PropertyValue> nodes = n.getPropertyValues();
// assertNotNull(nodes);
// assertEquals(4, nodes.size());
// assertEquals("a", nodes.getValue(0).getKey());
@@ -419,11 +365,28 @@ public class PropertyValueTest {
// }
@Test
- public void asMap() {
+ public void toMap() {
+ ObjectValue n = PropertyValue.createObject("");
+ n.setValue("a", "aVal");
+ n.addObject("b").addObject("b2").setValue("b3", "b3Val");
+ ListValue array = n.addList("c");
+ array.addValue("cVal1");
+ array.addValue("cVal2");
+ Map<String,String> map = n.toMap();
+ System.out.println(map);
+ assertThat(map).hasSize(4);
+ assertThat("aVal").isEqualTo(map.get("a"));
+ assertThat("b3Val").isEqualTo(map.get("b.b2.b3"));
+ assertThat("cVal1").isEqualTo(map.get("c[0]"));
+ assertThat("cVal2").isEqualTo(map.get("c[1]"));
+ }
+
+ @Test
+ public void toLocalMap() {
ObjectValue n = PropertyValue.createObject("");
n.setValue("a", "aVal");
- n.setObject("b").setObject("b2").setValue("b3", "b3Val");
- ListValue array = n.setList("c");
+ n.addObject("b").addObject("b2").setValue("b3", "b3Val");
+ ListValue array = n.addList("c");
array.addValue("cVal1");
array.addValue("cVal2");
Map<String,String> map = n.toMap();
@@ -441,9 +404,7 @@ public class PropertyValueTest {
n.setValue("a", "aVal");
n.setValue("b.b2.b3", "b3Val");
n.setValue("c", "cVal2");
- assertThat("a = aVal\n" +
- "b.b2.b3 = b3Val\n" +
- "c = cVal2\n").isEqualTo(n.asString());
+ assertThat("Object{size='3', values='{a=aVal, b.b2.b3=b3Val, c=cVal2}}").isEqualTo(n.toString());
}
@Test
@@ -461,7 +422,7 @@ public class PropertyValueTest {
n.setValue("a", "aVal");
n.setValue("b.b2.b3", "b3Val");
n.setValue("c", "cVal1");
- assertThat("PropertyValue[MAP]{'', size='3'}").isEqualTo(n.toString());
+ assertThat("Object{size='3', values='{a=aVal, b.b2.b3=b3Val, c=cVal1}}").isEqualTo(n.toString());
}
}
diff --git a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationBuilderTest.java b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationBuilderTest.java
index 82a9aea..f8bc6c5 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationBuilderTest.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationBuilderTest.java
@@ -55,7 +55,7 @@ public class ConfigurationBuilderTest {
.addPropertySources(testPropertySource, testPS2);
Configuration cfg = b.build();
assertThat(cfg.getContext().getPropertySources()).hasSize(2).contains(testPropertySource, testPS2);
- // Ensure no sorting happens during add, so switch ordinals!
+ // Ensure no sorting happens during addPropertyValue, so switch ordinals!
testPS2 = new TestPropertySource("addPropertySources_Array", 1);
b = Configuration.createConfigurationBuilder()
.addPropertySources(testPS2, testPropertySource);
@@ -74,7 +74,7 @@ public class ConfigurationBuilderTest {
assertThat(cfg.getContext().getPropertySources()).hasSize(2).contains(testPropertySource, testPS2);
assertThat("TestPropertySource").isEqualTo(cfg.getContext().getPropertySources().get(0).getName());
assertThat("addPropertySources_Collection").isEqualTo(cfg.getContext().getPropertySources().get(1).getName());
- // Ensure no sorting happens during add, so switch ordinals!
+ // Ensure no sorting happens during addPropertyValue, so switch ordinals!
testPS2 = new TestPropertySource("addPropertySources_Collection", 1);
b = Configuration.createConfigurationBuilder()
.addPropertySources(Arrays.asList(new PropertySource[]{testPS2, testPropertySource}));
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 5ac28be..1074b41 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
@@ -125,7 +125,7 @@ public class BasePropertySourceTest {
@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()));
+ result.put(PropertySource.TAMAYA_ORDINAL, PropertyValue.createValue(PropertySource.TAMAYA_ORDINAL, "1000"));
return result;
}
}
@@ -144,7 +144,8 @@ public class BasePropertySourceTest {
@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()));
+ result.put(PropertySource.TAMAYA_ORDINAL, PropertyValue.createValue(PropertySource.TAMAYA_ORDINAL, "invalid")
+ .setMeta("source", getName()));
return result;
}
}
diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java
index 3cd459d..0123148 100644
--- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java
+++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java
@@ -142,7 +142,7 @@ public class DefaultConfigurationBuilder implements ConfigurationBuilder {
/**
* Adds the given sources as property sources.
*
- * @param sources property sources to add.
+ * @param sources property sources to addPropertyValue.
* @return the current configuration builder.
*/
@Override
diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java
index 0645edc..e01adb5 100644
--- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java
+++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java
@@ -79,7 +79,7 @@ public class DefaultConfigurationContext implements ConfigurationContext {
List<PropertyFilter> propertyFilters = new ArrayList<>(builder.getPropertyFilters());
immutablePropertyFilters = Collections.unmodifiableList(propertyFilters);
- // Finally add the converters
+ // Finally addPropertyValue the converters
for(Map.Entry<TypeLiteral<?>, List<PropertyConverter<?>>> en:builder.getPropertyConverter().entrySet()) {
for (@SuppressWarnings("rawtypes") PropertyConverter converter : en.getValue()) {
this.propertyConverterManager.register(en.getKey(), converter);
diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultMetaDataProvider.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultMetaDataProvider.java
index e1337bd..fa27237 100644
--- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultMetaDataProvider.java
+++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultMetaDataProvider.java
@@ -30,7 +30,7 @@ import java.util.logging.Logger;
/**
* Default metadata provider implementation, which searches for all kind of entries
* formatted as {@code [(META)key].metaKey=metaValue}. All matching key/values are added to the
- * meta data map for the given key as {@code metaKey=metaValue} meta entries.
+ * meta data mapProperties for the given key as {@code metaKey=metaValue} meta entries.
*/
public class DefaultMetaDataProvider implements MetadataProvider {
diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultPropertySourceSnapshot.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultPropertySourceSnapshot.java
index 6c37543..ee76418 100644
--- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultPropertySourceSnapshot.java
+++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultPropertySourceSnapshot.java
@@ -79,7 +79,7 @@ public class DefaultPropertySourceSnapshot implements PropertySource, Serializab
this.name = propertySource.getName();
if(propertySource.getChangeSupport().equals(ChangeSupport.UNSUPPORTED) ||
propertySource.getChangeSupport().equals(ChangeSupport.IMMUTABLE)){
- // simply get the keys and we are done. We cant do more...
+ // simply getPropertyValue the keys and we are done. We cant do more...
this.properties = initProperties(propertySource, false);
}else{
this.properties = initProperties(propertySource, true);
@@ -120,8 +120,8 @@ public class DefaultPropertySourceSnapshot implements PropertySource, Serializab
}
/**
- * Creates a new FrozenPropertySource instance based on a PropertySource and the target key set given. This method
- * uses all keys available in the property map.
+ * Creates a new FrozenPropertySource instance based on a PropertySource and the target key setPropertyValue given. This method
+ * uses all keys available in the property mapProperties.
*
* @param propertySource the property source to be frozen, not null.
* @return the frozen property source.
@@ -132,7 +132,7 @@ public class DefaultPropertySourceSnapshot implements PropertySource, Serializab
}
/**
- * Creates a new FrozenPropertySource instance based on a PropertySource and the target key set given.
+ * Creates a new FrozenPropertySource instance based on a PropertySource and the target key setPropertyValue given.
*
* @param propertySource the property source to be frozen, not null.
* @param keys the keys to be evaluated for the snapshot. Only these keys will be contained in the resulting
diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/MetadataProvider.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/MetadataProvider.java
index d4a0abe..0253f94 100644
--- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/MetadataProvider.java
+++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/MetadataProvider.java
@@ -63,7 +63,7 @@ public interface MetadataProvider {
* from alternate sources.
*
* @param property the property key, not null.
- * @param metaData the metadata to set/replace.
+ * @param metaData the metadata to setPropertyValue/replace.
* @return this instance, for chaining.
*/
MetadataProvider setMeta(String property, Map<String, String> metaData);
diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java
index ce718b7..5782526 100644
--- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java
+++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java
@@ -185,11 +185,11 @@ public class PropertyConverterManager {
}
/**
- * Get a map of all property converters currently registered. This will not contain the converters that
+ * Get a mapProperties of all property converters currently registered. This will not contain the converters that
* may be created, when an instance is adapted, which provides a String constructor or compatible
* factory methods taking a single String instance.
*
- * @return the current map of instantiated and registered converters.
+ * @return the current mapProperties of instantiated and registered converters.
* @see #createDefaultPropertyConverter(org.apache.tamaya.TypeLiteral)
*/
public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/BasePropertySource.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/BasePropertySource.java
index 51a0a24..dc490b7 100644
--- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/BasePropertySource.java
+++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/BasePropertySource.java
@@ -39,8 +39,7 @@ public abstract class BasePropertySource implements PropertySource{
private volatile Integer ordinal;
/** The name of the property source. */
private String name;
- /** The optional prefix. */
- private String prefix;
+
/**
* If true, this property source does not return any properties. This is useful since this
* property source is applied by default, but can be switched off by setting the
@@ -155,14 +154,6 @@ public abstract class BasePropertySource implements PropertySource{
return val;
}
- public String getPrefix() {
- return prefix;
- }
-
- public void setPrefix(String prefix) {
- this.prefix = prefix;
- }
-
public boolean isDisabled() {
return disabled;
}
@@ -200,32 +191,10 @@ public abstract class BasePropertySource implements PropertySource{
protected String toStringValues() {
return " defaultOrdinal=" + defaultOrdinal + '\n' +
" ordinal=" + ordinal + '\n' +
- " prefix=" + prefix + '\n' +
" disabled=" + disabled + '\n' +
" name='" + name + '\'' + '\n';
}
- protected Map<String,PropertyValue> mapProperties(Map<String, String> props, long timestamp) {
- Map<String,PropertyValue> result = new HashMap<>();
- String timestampVal = String.valueOf(timestamp);
- if (prefix == null) {
- for (Map.Entry<String, String> en : props.entrySet()) {
- result.put(en.getKey(),
- PropertyValue.createValue(en.getKey(), en.getValue())
- .setMeta("source", getName())
- .setMeta("timestamp", timestampVal));
- }
- } else {
- for (Map.Entry<String, String> en : props.entrySet()) {
- result.put(prefix + en.getKey(),
- PropertyValue.createValue(prefix + en.getKey(), en.getValue())
- .setMeta("source", getName())
- .setMeta("timestamp", timestampVal));
- }
- }
- return result;
- }
-
@Override
public ChangeSupport getChangeSupport() {
return changeSupport;
diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/BuildablePropertySource.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/BuildablePropertySource.java
index e9a7f70..7568cb0 100644
--- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/BuildablePropertySource.java
+++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/BuildablePropertySource.java
@@ -149,7 +149,7 @@ public class BuildablePropertySource implements PropertySource{
* @return the builder
*/
public Builder withSimpleProperty(String key, String value) {
- return withProperties(PropertyValue.of(key, value, this.source));
+ return withProperties(PropertyValue.createValue(key, value).setMeta("source", this.source));
}
/**
@@ -161,7 +161,7 @@ public class BuildablePropertySource implements PropertySource{
* @return the builder
*/
public Builder withSimpleProperty(String key, String value, String source) {
- return withProperties(PropertyValue.of(key, value, source));
+ return withProperties(PropertyValue.createValue(key, value).setMeta("source", source));
}
/**
@@ -196,7 +196,7 @@ public class BuildablePropertySource implements PropertySource{
* @return the builder
*/
public Builder withProperties(Map<String, String> properties, String source) {
- this.properties.putAll(PropertyValue.map(properties, source));
+ this.properties.putAll(PropertyValue.mapProperties(properties, source));
return this;
}
@@ -207,7 +207,7 @@ public class BuildablePropertySource implements PropertySource{
* @return the builder
*/
public Builder withSimpleProperties(Map<String, String> properties) {
- this.properties.putAll(PropertyValue.map(properties, this.source));
+ this.properties.putAll(PropertyValue.mapProperties(properties, this.source));
return this;
}
diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/CLIPropertySource.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/CLIPropertySource.java
index 502af4b..62968ac 100644
--- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/CLIPropertySource.java
+++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/CLIPropertySource.java
@@ -32,7 +32,7 @@ public class CLIPropertySource extends BasePropertySource {
/** The original main arguments. */
private static String[] args = new String[0];
- /** The map of parsed main arguments. */
+ /** The mapProperties of parsed main arguments. */
private static Map<String,PropertyValue> mainArgs;
/** Initializes the initial state. */
@@ -120,7 +120,7 @@ public class CLIPropertySource extends BasePropertySource {
Map<String,PropertyValue> finalProps = new HashMap<>();
for(Map.Entry<String,String> en:result.entrySet()) {
finalProps.put(en.getKey(),
- PropertyValue.of(en.getKey(), en.getValue(), "main-args"));
+ PropertyValue.createValue(en.getKey(), en.getValue()).setMeta("source", "main-args"));
}
CLIPropertySource.mainArgs = Collections.unmodifiableMap(finalProps);
}
diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySource.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySource.java
index 0308b76..c53bd76 100644
--- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySource.java
+++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/EnvironmentPropertySource.java
@@ -219,7 +219,7 @@ public class EnvironmentPropertySource extends BasePropertySource {
if(value==null){
return null;
}
- return PropertyValue.of(key, value, getName());
+ return PropertyValue.createValue(key, value).setMeta("source", getName());
}
private boolean hasPrefix() {
@@ -235,13 +235,15 @@ public class EnvironmentPropertySource extends BasePropertySource {
if(prefix==null) {
Map<String, PropertyValue> entries = new HashMap<>(System.getenv().size());
for (Map.Entry<String, String> entry : System.getenv().entrySet()) {
- entries.put(entry.getKey(), PropertyValue.of(entry.getKey(), entry.getValue(), getName()));
+ entries.put(entry.getKey(), PropertyValue.createValue(entry.getKey(), entry.getValue())
+ .setMeta("source", getName()));
}
return entries;
}else{
Map<String, PropertyValue> entries = new HashMap<>(System.getenv().size());
for (Map.Entry<String, String> entry : System.getenv().entrySet()) {
- entries.put(prefix + entry.getKey(), PropertyValue.of(prefix + entry.getKey(), entry.getValue(), getName()));
+ entries.put(prefix + entry.getKey(), PropertyValue.createValue(prefix + entry.getKey(), entry.getValue())
+ .setMeta("source", getName()));
}
return entries;
}
diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/MapPropertySource.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/MapPropertySource.java
index e93e79f..3817d5f 100644
--- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/MapPropertySource.java
+++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/MapPropertySource.java
@@ -30,6 +30,9 @@ import java.util.Properties;
*/
public class MapPropertySource extends BasePropertySource {
+ /** The optional prefix. */
+ private String prefix;
+
/**
* The current properties.
*/
@@ -95,4 +98,41 @@ public class MapPropertySource extends BasePropertySource {
return ChangeSupport.IMMUTABLE;
}
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ protected Map<String,PropertyValue> mapProperties(Map<String, String> props, long timestamp) {
+ Map<String,PropertyValue> result = new HashMap<>();
+ String timestampVal = String.valueOf(timestamp);
+ if (prefix == null) {
+ for (Map.Entry<String, String> en : props.entrySet()) {
+ result.put(en.getKey(),
+ PropertyValue.createValue(en.getKey(), en.getValue())
+ .setMeta("source", getName())
+ .setMeta("timestamp", timestampVal));
+ }
+ } else {
+ for (Map.Entry<String, String> en : props.entrySet()) {
+ result.put(prefix + en.getKey(),
+ PropertyValue.createValue(prefix + en.getKey(), en.getValue())
+ .setMeta("source", getName())
+ .setMeta("timestamp", timestampVal));
+ }
+ }
+ return result;
+ }
+
+ protected String toStringValues() {
+ return " defaultOrdinal=" + getDefaultOrdinal() + '\n' +
+ " ordinal=" + getOrdinal() + '\n' +
+ " prefix=" + prefix + '\n' +
+ " disabled=" + isDisabled() + '\n' +
+ " name='" + getName() + '\'' + '\n';
+ }
+
}
diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/PropertiesResourcePropertySource.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/PropertiesResourcePropertySource.java
index 3ddc74f..33ea194 100644
--- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/PropertiesResourcePropertySource.java
+++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/PropertiesResourcePropertySource.java
@@ -57,7 +57,6 @@ public class PropertiesResourcePropertySource extends BasePropertySource {
*/
public PropertiesResourcePropertySource(URL url, String prefix){
super(url.toExternalForm());
- setPrefix(prefix);
this.cachedProperties.load(loadProps(url));
this.cachedProperties.scheduleChangeMonitor(() -> loadProps(url),
120, TimeUnit.SECONDS);
@@ -65,22 +64,19 @@ public class PropertiesResourcePropertySource extends BasePropertySource {
/**
* Creates a new instance.
- * @param prefix the (optional) prefix context for mapping (prefixing) the properties loaded.
* @param path the resource path, not null.
*/
- public PropertiesResourcePropertySource(String path, String prefix){
- this(path, prefix, ServiceContextManager.getDefaultClassLoader());
+ public PropertiesResourcePropertySource(String path){
+ this(path, ServiceContextManager.getDefaultClassLoader());
}
/**
* Creates a new instance.
- * @param prefix the (optional) prefix context for mapping (prefixing) the properties loaded.
* @param path the resource path, not null.
* @param cl the class loader.
*/
- public PropertiesResourcePropertySource(String path, String prefix, ClassLoader cl){
+ public PropertiesResourcePropertySource(String path, ClassLoader cl){
super(path);
- setPrefix(prefix);
this.cachedProperties.load(loadProps(path, cl));
this.cachedProperties.scheduleChangeMonitor(() -> loadProps(path, cl),
120, TimeUnit.SECONDS);
@@ -106,7 +102,7 @@ public class PropertiesResourcePropertySource extends BasePropertySource {
try (InputStream is = url.openStream()) {
Properties props = new Properties();
props.load(is);
- return mapProperties(MapPropertySource.getMap(props), System.currentTimeMillis());
+ return PropertyValue.mapProperties(MapPropertySource.getMap(props), getName());
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Failed to read properties from " + url, e);
}
diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySource.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySource.java
index 8a7567b..b5b68f8 100644
--- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySource.java
+++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySource.java
@@ -78,12 +78,13 @@ public class SimplePropertySource extends BasePropertySource {
public SimplePropertySource(String name, Map<String, String> properties, int defaultOrdinal){
super(name, defaultOrdinal);
for(Map.Entry<String,String> en: properties.entrySet()) {
- this.properties.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), name));
+ this.properties.put(en.getKey(), PropertyValue.createValue(en.getKey(), en.getValue())
+ .setMeta("source", name));
}
}
/**
- * Creates a new Properties based PropertySource based on the given properties map.
+ * Creates a new Properties based PropertySource based on the given properties mapProperties.
*
* @param name the name, not null.
* @param properties the properties, not null.
@@ -150,7 +151,8 @@ public class SimplePropertySource extends BasePropertySource {
}
String source = propertiesFile.toString();
for (String key : props.stringPropertyNames()) {
- properties.put(key, PropertyValue.of(key, props.getProperty(key), source));
+ properties.put(key, PropertyValue.createValue(key, props.getProperty(key))
+ .setMeta("source", source));
}
} catch (IOException e) {
throw new ConfigException("Error loading properties from " + propertiesFile, e);
@@ -259,7 +261,8 @@ public class SimplePropertySource extends BasePropertySource {
*/
public Builder withProperties(Map<String, String> val) {
for(Map.Entry<String,String> en: val.entrySet()) {
- this.properties.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), name));
+ this.properties.put(en.getKey(), PropertyValue.createValue(en.getKey(), en.getValue())
+ .setMeta("source", name));
}
return this;
}
@@ -272,7 +275,7 @@ public class SimplePropertySource extends BasePropertySource {
* @return a reference to this Builder
*/
public Builder withProperty(String key, String val) {
- this.properties.put(key, PropertyValue.of(key, val, name));
+ this.properties.put(key, PropertyValue.createValue(key, val).setMeta("source", name));
return this;
}
diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySource.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySource.java
index 72c8af9..b853e2d 100644
--- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySource.java
+++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySource.java
@@ -51,7 +51,8 @@ public class SystemPropertySource extends BasePropertySource {
* </pre>
*/
public SystemPropertySource(){
- super("system-properties", DEFAULT_ORDINAL);
+ super("system-properties");
+ setDefaultOrdinal(DEFAULT_ORDINAL);
initFromSystemProperties();
if(!isDisabled()){
reload();
@@ -71,7 +72,6 @@ public class SystemPropertySource extends BasePropertySource {
if(value==null){
value = System.getenv("tamaya.sysprops.prefix");
}
- setPrefix(value);
value = System.getProperty("tamaya.sysprops.disable");
if(value==null){
value = System.getenv("tamaya.sysprops.disable");
@@ -92,31 +92,12 @@ public class SystemPropertySource extends BasePropertySource {
* @param ordinal the ordinal number.
*/
public SystemPropertySource(int ordinal){
- this(null, ordinal);
- }
-
- /**
- * Creates a new instance.
- * @param prefix the prefix to be used, or null.
- * @param ordinal the ordinal to be used.
- */
- public SystemPropertySource(String prefix, int ordinal){
- setPrefix(prefix);
setOrdinal(ordinal);
}
- /**
- * Creates a new instance.
- * @param prefix the prefix to be used, or null.
- */
- public SystemPropertySource(String prefix){
- setPrefix(prefix);
- }
-
-
private Map<String, PropertyValue> loadProperties() {
Map<String, String> props = MapPropertySource.getMap(System.getProperties());
- return mapProperties(props, System.currentTimeMillis());
+ return PropertyValue.mapProperties(props, getName());
}
@Override
diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceTest.java
index 1df89fc..f60373b 100644
--- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceTest.java
+++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceTest.java
@@ -87,7 +87,7 @@ public class BuildablePropertySourceTest {
propertySecond.put("secondKey", "secondValue");
Map<String, PropertyValue> propertyThird = new HashMap<>();
- propertyThird.put("thirdKey", PropertyValue.of("thirdPVKey", "thirdValue", "thirdSource"));
+ propertyThird.put("thirdKey", PropertyValue.createValue("thirdPVKey", "thirdValue").setMeta("source", "thirdSource"));
//This seems wrong
BuildablePropertySource bps = BuildablePropertySource.builder()
diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilderTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilderTest.java
index 9289bff..18df2d8 100644
--- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilderTest.java
+++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilderTest.java
@@ -385,7 +385,7 @@ public class DefaultConfigurationBuilderTest {
@Override
public PropertyValue get(String key) {
- return PropertyValue.of(key, key + "Value", getName());
+ return PropertyValue.createValue(key, key + "Value").setMeta("source", getName());
}
@Override
diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationTest.java
index 2964fd6..b80f118 100644
--- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationTest.java
+++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationTest.java
@@ -206,7 +206,7 @@ public class DefaultConfigurationTest {
public void testConvertValue() {
DefaultConfiguration c = new DefaultConfiguration(new MockedConfigurationContext());
assertThat(100 == (Integer) c.convertValue("aHundred",
- Collections.singletonList(PropertyValue.of("aHundred", "100", null)),
+ Collections.singletonList(PropertyValue.createValue("aHundred", "100")),
TypeLiteral.of(Integer.class))).isTrue();
}
diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/MockedPropertySource.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/MockedPropertySource.java
index 7b61103..af9ecde 100644
--- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/MockedPropertySource.java
+++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/MockedPropertySource.java
@@ -62,7 +62,7 @@ public class MockedPropertySource implements PropertySource {
} else if (key.contains("missing")){
return null;
}
- return PropertyValue.of(key, "valueFromMockedPropertySource", "MockedPropertySource");
+ return PropertyValue.createValue(key, "valueFromMockedPropertySource");
}
@Override
diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java
index 37417cd..9092fc5 100644
--- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java
+++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java
@@ -32,9 +32,9 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
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 PropertyValue prop1 = PropertyValue.createValue("test1", "test1");
+ private static PropertyValue prop2 = PropertyValue.createValue("test2", "test2");
+ private static PropertyValue prop3 = PropertyValue.createValue("test1.test3", "test.test3");
private static ConfigurationContext configContext = ConfigurationContext.EMPTY;
@org.junit.Test
diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/BasePropertySourceTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/BasePropertySourceTest.java
index 089f5ea..62f616d 100644
--- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/BasePropertySourceTest.java
+++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/BasePropertySourceTest.java
@@ -124,7 +124,8 @@ public class BasePropertySourceTest {
@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()));
+ result.put(PropertySource.TAMAYA_ORDINAL, PropertyValue.createValue(PropertySource.TAMAYA_ORDINAL, "1000")
+ .setMeta("source", getName()));
return result;
}
}
@@ -143,7 +144,8 @@ public class BasePropertySourceTest {
@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()));
+ result.put(PropertySource.TAMAYA_ORDINAL, PropertyValue.createValue(PropertySource.TAMAYA_ORDINAL, "invalid")
+ .setMeta("source", getName()));
return result;
}
}
diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/PropertiesResourcePropertySourceTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/PropertiesResourcePropertySourceTest.java
index 5b227ad..b29beae 100644
--- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/PropertiesResourcePropertySourceTest.java
+++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/PropertiesResourcePropertySourceTest.java
@@ -40,22 +40,6 @@ public class PropertiesResourcePropertySourceTest {
}
@Test
- public void testPrefixedConstructor() {
- PropertiesResourcePropertySource source = new PropertiesResourcePropertySource(resource, "somePrefix");
- assertThat(source).isNotNull();
- assertThat(source.getProperties()).hasSize(5).containsKey("somePrefixkey1");
- }
-
- @Test
- public void testPrefixedPathConstructor() {
- //File path must be relative to classloader, not the class
- System.out.println(resource.getPath());
- PropertiesResourcePropertySource source = new PropertiesResourcePropertySource(testFileName, "somePrefix");
- assertThat(source).isNotNull();
- assertThat(source.getProperties()).hasSize(5).containsKey("somePrefixkey1");
- }
-
- @Test
public void testPrefixedPathBadClassloaderConstructor() {
ClassLoader badLoader = new ClassLoader() {
@Override
@@ -63,17 +47,9 @@ public class PropertiesResourcePropertySourceTest {
return null;
}
};
- PropertiesResourcePropertySource source = new PropertiesResourcePropertySource(testFileName, "somePrefix", badLoader);
+ PropertiesResourcePropertySource source = new PropertiesResourcePropertySource(testFileName, badLoader);
assertThat(source).isNotNull();
assertThat(source.getProperties()).isEmpty();
}
- @Test
- public void testPrefixedPathClassloaderConstructor() {
- PropertiesResourcePropertySource source = new PropertiesResourcePropertySource(testFileName, "somePrefix",
- getClass().getClassLoader());
- assertThat(source).isNotNull();
- assertThat(source.getProperties()).hasSize(5).containsKey("somePrefixkey1");
- }
-
}
diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java
index bacc7de..f497e86 100644
--- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java
+++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SimplePropertySourceTest.java
@@ -44,8 +44,8 @@ public class SimplePropertySourceTest {
assertThat(source).isNotNull();
assertThat(source.getProperties()).hasSize(2); // double the getNumChilds for .source values.
- assertThat(source.getProperties()).contains(entry("a", PropertyValue.of("a", "b", resource.toString())));
- assertThat(source.getProperties()).contains(entry("b", PropertyValue.of("b", "1", resource.toString())));
+ assertThat(source.getProperties()).contains(entry("a", PropertyValue.createValue("a", "b")));
+ assertThat(source.getProperties()).contains(entry("b", PropertyValue.createValue("b", "1")));
}
@Test(expected=ConfigException.class)
@@ -61,8 +61,8 @@ public class SimplePropertySourceTest {
assertThat(source).isNotNull();
assertThat(source.getProperties()).hasSize(2); // double the getNumChilds for .source values.
- assertThat(source.getProperties()).contains(entry("a", PropertyValue.of("a", "b", resource.toString())));
- assertThat(source.getProperties()).contains(entry("b", PropertyValue.of("b", "1", resource.toString())));
+ assertThat(source.getProperties()).contains(entry("a", PropertyValue.createValue("a", "b")));
+ assertThat(source.getProperties()).contains(entry("b", PropertyValue.createValue("b", "1")));
}
@Test
@@ -73,8 +73,8 @@ public class SimplePropertySourceTest {
assertThat(source).isNotNull();
assertThat(source.getProperties()).hasSize(2); // double the getNumChilds for .source values.
- assertThat(source.getProperties()).contains(entry("a", PropertyValue.of("a", "b", resource.toString())));
- assertThat(source.getProperties()).contains(entry("b", PropertyValue.of("b", "1", resource.toString())));
+ assertThat(source.getProperties()).contains(entry("a", PropertyValue.createValue("a", "b")));
+ assertThat(source.getProperties()).contains(entry("b", PropertyValue.createValue("b", "1")));
}
@Test
@@ -87,8 +87,8 @@ public class SimplePropertySourceTest {
assertThat(source).isNotNull();
assertThat(source.getProperties()).hasSize(2); // double the getNumChilds for .source values.
- assertThat(source.getProperties()).contains(entry("a", PropertyValue.of("a", "b", "test")));
- assertThat(source.getProperties()).contains(entry("b", PropertyValue.of("b", "1", "test")));
+ assertThat(source.getProperties()).contains(entry("a", PropertyValue.createValue("a", "b").setMeta("source", "test")));
+ assertThat(source.getProperties()).contains(entry("b", PropertyValue.createValue("b", "1").setMeta("source", "test")));
}
@Test
@@ -221,8 +221,8 @@ public class SimplePropertySourceTest {
.build();
assertThat(sps.get("firstKey").getValue()).isEqualTo("firstValue");
- assertThat(sps.getProperties()).contains(entry("a", PropertyValue.of("a", "b", resource.toString())));
- assertThat(sps.getProperties()).contains(entry("b", PropertyValue.of("b", "1", resource.toString())));
+ assertThat(sps.getProperties()).contains(entry("a", PropertyValue.createValue("a", "b")));
+ assertThat(sps.getProperties()).contains(entry("b", PropertyValue.createValue("b", "1")));
sps = SimplePropertySource.newBuilder()
.withUuidName()
@@ -231,8 +231,8 @@ public class SimplePropertySourceTest {
.build();
assertThat(sps.get("firstKey").getValue()).isEqualTo("firstValue");
- assertThat(sps.getProperties()).contains(entry("a", PropertyValue.of("a", "b", resource.toString())));
- assertThat(sps.getProperties()).contains(entry("b", PropertyValue.of("b", "1", resource.toString())));
+ assertThat(sps.getProperties()).contains(entry("a", PropertyValue.createValue("a", "b")));
+ assertThat(sps.getProperties()).contains(entry("b", PropertyValue.createValue("b", "1")));
}
@Test
diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.java
index 09c4e90..4155e05 100644
--- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.java
+++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/SystemPropertySourceTest.java
@@ -33,15 +33,15 @@ public class SystemPropertySourceTest {
private final SystemPropertySource testPropertySource = new SystemPropertySource();
- @Test
- public void testConstrcutorWithPrefix() throws Exception {
- SystemPropertySource testPropertySource = new SystemPropertySource("PRE::");
- assertThat(testPropertySource.getProperties()).isNotNull();
- for(Map.Entry en:System.getProperties().entrySet()){
- assertThat(System.getProperty(en.getKey().toString()))
- .isEqualTo(testPropertySource.get("PRE::"+en.getKey()).getValue());
- }
- }
+// @Test
+// public void testConstrcutorWithPrefix() throws Exception {
+// SystemPropertySource testPropertySource = new SystemPropertySource("PRE::");
+// assertThat(testPropertySource.getProperties()).isNotNull();
+// for(Map.Entry en:System.getProperties().entrySet()){
+// assertThat(System.getProperty(en.getKey().toString()))
+// .isEqualTo(testPropertySource.get("PRE::"+en.getKey()).getValue());
+// }
+// }
@Test
public void testConstructionPropertiesAndDisabledBehavior() throws IOException {
@@ -104,7 +104,7 @@ public class SystemPropertySourceTest {
SystemPropertySource constructorSetOrdinal22 = new SystemPropertySource(22);
assertThat(constructorSetOrdinal22.getOrdinal()).isEqualTo(22);
- SystemPropertySource constructorSetOrdinal16 = new SystemPropertySource("sixteenprefix", 16);
+ SystemPropertySource constructorSetOrdinal16 = new SystemPropertySource( 16);
assertThat(constructorSetOrdinal16.getOrdinal()).isEqualTo(16);
}
diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/TestPropertyDefaultSource.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/TestPropertyDefaultSource.java
index b9b9dd0..3d4cf3b 100644
--- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/TestPropertyDefaultSource.java
+++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/TestPropertyDefaultSource.java
@@ -33,8 +33,8 @@ public class TestPropertyDefaultSource extends BasePropertySource{
public TestPropertyDefaultSource() {
super(100);
- properties.put("name", PropertyValue.of("name", "Anatole", "Test"));
- properties.put("name2",PropertyValue.of("name2", "Sabine", "Test"));
+ properties.put("name", PropertyValue.createValue("name", "Anatole"));
+ properties.put("name2",PropertyValue.createValue("name2", "Sabine"));
properties = Collections.unmodifiableMap(properties);
}
diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/WrappedPropertySourceTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/WrappedPropertySourceTest.java
index 925176e..55877c1 100644
--- a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/WrappedPropertySourceTest.java
+++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/propertysource/WrappedPropertySourceTest.java
@@ -149,7 +149,7 @@ public class WrappedPropertySourceTest {
@Override
public PropertyValue get(String key) {
- return PropertyValue.of(key, "valueFromMockedWrappablePropertySource", "MockedWrappablePropertySource");
+ return PropertyValue.createValue(key, "valueFromMockedWrappablePropertySource");
}
@Override