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 2018/12/15 23:19:28 UTC
[incubator-tamaya] 05/05: - Added tests for default methods. -
Fixed spelling issues in docs. - Fixed code issues as needed.
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 756b61453f76c5d2d0c64a34a6ca4c18129af9c0
Author: Anatole Tresch <at...@gmail.com>
AuthorDate: Sat Dec 15 22:38:21 2018 +0100
- Added tests for default methods.
- Fixed spelling issues in docs.
- Fixed code issues as needed.
---
.../main/java/org/apache/tamaya/spi/ListValue.java | 90 +++---
.../java/org/apache/tamaya/spi/ObjectValue.java | 114 +++----
.../java/org/apache/tamaya/spi/PropertyValue.java | 26 +-
.../apache/tamaya/spi/PropertyValueBuilder.java | 6 +-
.../java/org/apache/tamaya/spi/ListValueTest.java | 304 +++++++++++++++++++
.../org/apache/tamaya/spi/ObjectValueTest.java | 332 +++++++++++++++++++++
.../org/apache/tamaya/spi/PropertyValueTest.java | 59 ++--
.../tamaya/core/internal/BannerManagerTest.java | 2 +-
.../propertysource/BasePropertySource.java | 2 +-
.../spisupport/DefaultMetaDataProviderTest.java | 96 ++++++
pom.xml | 3 +-
11 files changed, 891 insertions(+), 143 deletions(-)
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 1e7b493..503b7a7 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
@@ -20,7 +20,6 @@ package org.apache.tamaya.spi;
import java.util.*;
import java.util.function.Predicate;
-import java.util.logging.Logger;
/**
* Class modelling the result of a request for a property createValue. A property createValue is basically identified by its key.
@@ -74,15 +73,6 @@ public final class ListValue extends PropertyValue{
return this.list.size();
}
- /**
- * The createValue.
- * @return the createValue, in case a createValue is null it is valid to return {#code null} as result for
- * {@link PropertySource#get(String)}.
- */
- public List<PropertyValue> getList() {
- return Collections.unmodifiableList(this.list);
- }
-
@Override
public Iterator<PropertyValue> iterator() {
return Collections.unmodifiableList(this.list).iterator();
@@ -99,7 +89,9 @@ public final class ListValue extends PropertyValue{
public <T extends PropertyValue> T add(T value) {
checkImmutable();
value.setParent(this);
- this.list.add(value);
+ if(!this.list.stream().filter(p -> p==value).findAny().isPresent()){
+ this.list.add(value);
+ }
return value;
}
@@ -188,38 +180,47 @@ public final class ListValue extends PropertyValue{
* @param filter the filter predicate, null selects all elements.
* @return this values matching, never null.
*/
- public List<PropertyValue> getList(Predicate<PropertyValue> filter) {
+ public List<PropertyValue> getValues(Predicate<PropertyValue> filter) {
List<PropertyValue> result = new ArrayList<>();
- if(filter==null){
- result.addAll(this.list);
- }else {
- this.list.forEach(el -> {
+ this.list.forEach(el -> {
if (filter.test(el)) result.add(el);
});
- }
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;
+ }
+
+ /**
+ * Get the n-th element of the children.
+ * @param n the index.
+ * @return the element found
+ * @throws NoSuchElementException if no such element exists.
+ */
+ public PropertyValue get(int n) {
+ return this.getValues().get(n);
+ }
+
+
+ /**
* Get the array elements, filtered by the given predicate.
* @param name the name of the objects, null selects all.
* @return this values matching, never null.
*/
public List<ObjectValue> getObjects(String name) {
List<ObjectValue> result = new ArrayList<>();
- if (name == null) {
- this.list.forEach(el -> {
- if (el instanceof ObjectValue) {
- result.add((ObjectValue) el);
- }
- });
- } else {
- this.list.forEach(el -> {
- if (el instanceof ObjectValue && name.equals(el.getKey())) {
- result.add((ObjectValue) el);
- }
- });
- }
+ this.list.forEach(el -> {
+ if (el instanceof ObjectValue && name.equals(el.getKey())) {
+ result.add((ObjectValue) el);
+ }
+ });
return result;
}
@@ -230,19 +231,25 @@ public final class ListValue extends PropertyValue{
*/
public List<ListValue> getLists(String name) {
List<ListValue> result = new ArrayList<>();
- if (name == null) {
- this.list.forEach(el -> {
- if (el instanceof ListValue) {
+ this.list.forEach(el -> {
+ if (el instanceof ListValue && name.equals(el.getKey())) {
result.add((ListValue) el);
}
});
- } else {
+ return result;
+ }
+
+ /**
+ * Get all array elements of type {@link ListValue}.
+ * @return this values matching, never null.
+ */
+ public List<ListValue> getLists() {
+ List<ListValue> result = new ArrayList<>();
this.list.forEach(el -> {
- if (el instanceof ListValue && name.equals(el.getKey())) {
+ if (el instanceof ListValue) {
result.add((ListValue) el);
}
});
- }
return result;
}
@@ -278,9 +285,10 @@ public final class ListValue extends PropertyValue{
ObjectValue object = new ObjectValue(getParent(), getKey());
object.setMeta(getMeta());
object.setVersion(getVersion());
+ object.setValue(getValue());
int index = 0;
for(PropertyValue val: list){
- object.set(val.deepClone().setKey("["+index+"]"));
+ object.set(val.deepClone().setKey(val.getKey()+"["+index+"]"));
index++;
}
return object;
@@ -304,8 +312,9 @@ public final class ListValue extends PropertyValue{
protected ListValue deepClone(){
ListValue newProp = new ListValue(getParent(), getKey());
newProp.setMeta(getMeta());
- list.forEach(c -> newProp.add(c.mutable()));
+ list.forEach(c -> newProp.add(c.deepClone().mutable()));
newProp.setVersion(getVersion());
+ newProp.setValue(getValue());
return newProp;
}
@@ -314,8 +323,7 @@ public final class ListValue extends PropertyValue{
if (this == o) return true;
if (!(o instanceof ListValue)) return false;
ListValue dataNode = (ListValue) o;
- return getParent() == dataNode.getParent() &&
- Objects.equals(getKey(), dataNode.getKey()) &&
+ return Objects.equals(getKey(), dataNode.getKey()) &&
Objects.equals(getValue(), dataNode.getValue()) &&
Objects.equals(list, dataNode.list) &&
Objects.equals(getMeta(), dataNode.getMeta());
@@ -323,7 +331,7 @@ public final class ListValue extends PropertyValue{
@Override
public int hashCode() {
- return Objects.hash(getParent(), getKey(), list, getValue(), getMeta());
+ return Objects.hash(getKey(), list, getValue(), getMeta());
}
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 7d09eee..342937e 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,8 +19,10 @@
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 createValue. A property createValue is basically identified by its key.
@@ -63,31 +65,41 @@ public final class ObjectValue extends PropertyValue{
* Get the fields of this instance.
* @return the current fields, never null.
*/
- public Map<String, PropertyValue> getFields(){
- return Collections.unmodifiableMap(this.fields);
+ public Collection<PropertyValue> getValues(){
+ return Collections.unmodifiableCollection(this.fields.values());
}
/**
- * Get a single child getField by name.
+ * Get the fields of this instance, filtered with the given predicate.
+ * @param predicate the predicate, not null.
+ * @return the current fields, never null.
+ */
+ public Collection<PropertyValue> getValues(Predicate<PropertyValue> predicate){
+ return Collections.unmodifiableCollection(this.fields.values().stream()
+ .filter(predicate).collect(Collectors.toList()));
+ }
+
+ /**
+ * 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 getList with the given name are existing (ambigous).
+ * @throws IllegalArgumentException if multiple getValues with the given name are existing (ambigous).
*/
- public PropertyValue getField(String name){
+ public PropertyValue getValue(String name){
return this.fields.get(name);
}
/**
- * Get a single child getField with the given name, creates it if not existing.
+ * 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 getList with the given name are existing (ambigous).
+ * @throws IllegalArgumentException if multiple getValues with the given name are existing (ambigous).
* @throws IllegalStateException if the instance is immutable.
* @see #isImmutable()
*/
- public <T extends PropertyValue> T getOrSetField(String name, Supplier<T> valueSupplier){
+ public <T extends PropertyValue> T getOrSetValue(String name, Supplier<T> valueSupplier){
T field = (T)this.fields.get(name);
if(field==null){
checkImmutable();
@@ -140,88 +152,82 @@ public final class ObjectValue extends PropertyValue{
}
/**
- * Adds a new nvalue child.
- * @param name the child's name, not null.
- * @param value the value
- * @return the createValue added, not null.
- * @throws IllegalStateException if the instance is immutable.
- * @see #isImmutable()
- */
- public PropertyValue setField(String name, String value){
- return set(new PropertyValue(this, name, value));
- }
-
- /**
* 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> setFields(Map<String, String> values) {
+ public Collection<PropertyValue> setValues(Map<String, String> values) {
checkImmutable();
List<PropertyValue> result = new ArrayList<>();
for(Map.Entry<String, String> en:values.entrySet()) {
- result.add(new PropertyValue(this, en.getKey(), en.getValue()));
+ PropertyValue val = setValue(en.getKey(), en.getValue());
+ result.add(val);
}
return result;
}
/**
- * Adds a new non-indexed child getField.
- * @param name the child's name, not null.
+ * Adds another existing node, hereby setting the corresponding parent node.
+ * @param value the createValue, not null
+ * @param <T> the value type.
* @return the createValue added, not null.
* @throws IllegalStateException if the instance is immutable.
* @see #isImmutable()
*/
- public ListValue setFieldList(String name){
- return set(new ListValue(this, name));
+ public <T extends PropertyValue> T set(T value) {
+ checkImmutable();
+ value.setParent(this);
+ this.fields.put(value.getKey(), value);
+ return value;
}
/**
- * Adds a new non-indexed child getField.
- * @param name the child's name, not null.
- * @return the createValue added, not null.
- * @throws IllegalStateException if the instance is immutable.
- * @see #isImmutable()
+ * Sets the given key, value pair.
+ * @param k the key, not null.
+ * @param v the value, not null.
+ * @return the value added, not null.
*/
- public ObjectValue setFieldObject(String name){
- return set(new ObjectValue(this, name));
+ public PropertyValue setValue(String k, String v) {
+ return set(PropertyValue.createValue(k,v));
}
+ /**
+ * Sets the given list value.
+ * @param key the key, not null.
+ * @return the value added, not null.
+ */
+ public ListValue setList(String key) {
+ return set(PropertyValue.createList(key));
+ }
/**
- * Adds another existing node, hereby setting the corresponding parent node.
- * @param value the createValue, not null
- * @param <T> the value type.
- * @return the createValue added, not null.
- * @throws IllegalStateException if the instance is immutable.
- * @see #isImmutable()
+ * Sets the given object vaƶue.
+ * @param key the key, not null.
+ * @return the value added, not null.
*/
- public <T extends PropertyValue> T set(T value) {
- checkImmutable();
- value.setParent(this);
- this.fields.put(value.getKey(), value);
- return value;
+ public ObjectValue setObject(String key) {
+ return set(PropertyValue.createObject(key));
}
/**
- * Adds a new child getField, where the getField is given in '.'-separated property notation,
+ * Adds a new child getValue, where the getValue is given in '.'-separated property notation,
* e.g. {@code a.b.c}.
* @param key the property key, e.g. {@code a.b.c}
* @param value the property createValue
- * @return the new leaf-getField created.
+ * @return the new leaf-getValue created.
* @throws IllegalStateException if the instance is immutable.
* @see #isImmutable()
*/
- public PropertyValue setFieldWithCompositeKey(String key, String value) {
+ public PropertyValue setValueWithCompositeKey(String key, String value) {
checkImmutable();
ObjectValue node = this;
StringTokenizer tokenizer = new StringTokenizer(key, "\\.", false);
while(tokenizer.hasMoreTokens()){
String token = tokenizer.nextToken().trim();
if(tokenizer.hasMoreTokens()) {
- node = node.getOrSetField(token, () -> PropertyValue.createObject(token));
+ node = node.getOrSetValue(token, () -> PropertyValue.createObject(token));
}else{
return node.set(PropertyValue.createValue(token, value));
}
@@ -237,17 +243,17 @@ public final class ObjectValue extends PropertyValue{
* @throws IllegalStateException if the instance is immutable.
* @see #isImmutable()
*/
- public Collection<PropertyValue> setFielsWithCompositeKey(Map<String,String> values) {
+ public Collection<PropertyValue> setValueWithCompositeKey(Map<String,String> values) {
checkImmutable();
List<PropertyValue> result = new ArrayList<>();
for(Map.Entry<String,String> en:values.entrySet()){
- result.add(setFieldWithCompositeKey(en.getKey(), en.getValue()));
+ result.add(setValueWithCompositeKey(en.getKey(), en.getValue()));
}
return result;
}
/**
- * Convert the getField tree to a property map.
+ * Convert the getValue tree to a property map.
* @return the corresponding property map, not null.
*/
@Override
@@ -281,8 +287,9 @@ public final class ObjectValue extends PropertyValue{
protected ObjectValue deepClone(){
ObjectValue newProp = new ObjectValue(getParent(), getKey());
newProp.setMeta(getMeta());
- fields.values().forEach(c -> newProp.set(c.mutable()));
+ fields.values().forEach(c -> newProp.set(c.deepClone().mutable()));
newProp.setVersion(getVersion());
+ newProp.setValue(getValue());
return newProp;
}
@@ -291,8 +298,7 @@ public final class ObjectValue extends PropertyValue{
if (this == o) return true;
if (!(o instanceof ObjectValue)) return false;
ObjectValue dataNode = (ObjectValue) o;
- return getParent() == dataNode.getParent() &&
- Objects.equals(getKey(), dataNode.getKey()) &&
+ return Objects.equals(getKey(), dataNode.getKey()) &&
Objects.equals(fields, dataNode.fields) &&
Objects.equals(getMeta(), dataNode.getMeta());
}
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 048e4b2..925cf46 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
@@ -39,7 +39,7 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
private String key;
/** The createValue. */
private String value;
- /** The getParent getField, null if it's a root getField. */
+ /** The parent value, null if it's a root value. */
private PropertyValue parent;
/** The createValue version, used for determining config changes. */
private AtomicInteger version = new AtomicInteger();
@@ -266,7 +266,7 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
/**
* Sets the createValue.
* @param value the createValue
- * @return this getField for chaining.
+ * @return this value for chaining.
* @throws IllegalStateException if the instance is immutable.
* @see #isImmutable()
*/
@@ -280,7 +280,7 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
}
/**
- * Get a qualified name of a getField in property format using '.' as separator, e.g.
+ * Get a qualified name of a value in property format using '.' as separator, e.g.
* {@code a.b.c} or {@code a.b.c[0]} for indexed entries. Entries hereby also can have multiple
* levels of indexing, e.g. {@code a[1].b.c[14].d} is a valid option.
*
@@ -314,8 +314,8 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
}
/**
- * Get the getField's getParent.
- * @return the getParent, or null.
+ * Get the value's parent.
+ * @return the parent, or null.
*/
public final PropertyValue getParent(){
return parent;
@@ -331,16 +331,16 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
/**
- * Checks if the getField is a root getField.
- * @return true, if the current getField is a root getField.
+ * Checks if the value is a root value.
+ * @return true, if the current value is a root value.
*/
public final boolean isRoot() {
return parent == null;
}
/**
- * Checks if the getField is a leaf getField (has no getList).
- * @return true, if the current getField is a leaf getField.
+ * Checks if the value is a leaf value (has no values).
+ * @return true, if the current value is a leaf value.
*/
public final boolean isLeaf(){
return getValueType()==ValueType.VALUE;
@@ -462,7 +462,7 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
/**
- * Convert the getField tree to a property map.
+ * Convert the value tree to a property map.
* @return the corresponding property map, not null.
*/
public Map<String,String> toMap(){
@@ -513,7 +513,7 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
*/
public ObjectValue toObjectValue(){
ObjectValue ov = new ObjectValue(getParent(),getKey());
- ov.setField("createValue", value);
+ ov.setValue("createValue", value);
return ov;
}
@@ -536,6 +536,7 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
PropertyValue newProp = new PropertyValue(getParent(), getKey(), this.value);
newProp.setMeta(getMeta());
newProp.setVersion(getVersion());
+ newProp.setValue(getValue());
return newProp;
}
@@ -580,8 +581,7 @@ public class PropertyValue implements Serializable, Iterable<PropertyValue>{
if (this == o) return true;
if (!(o instanceof PropertyValue)) return false;
PropertyValue dataNode = (PropertyValue) o;
- return getParent() == dataNode.getParent() &&
- Objects.equals(getKey(), dataNode.getKey()) &&
+ return Objects.equals(getKey(), dataNode.getKey()) &&
Objects.equals(value, dataNode.value) &&
Objects.equals(getMeta(), dataNode.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
index c9dfcc5..f0d7b4c 100644
--- a/code/api/src/main/java/org/apache/tamaya/spi/PropertyValueBuilder.java
+++ b/code/api/src/main/java/org/apache/tamaya/spi/PropertyValueBuilder.java
@@ -38,11 +38,11 @@ public class PropertyValueBuilder {
protected String source;
/** additional metadata entries (optional). */
protected Map<String,String> metaEntries = new HashMap<>();
- /** The getParent getField, null if it's a root getField. */
+ /** The parent value, null if it's a root value. */
protected PropertyValue parent;
- /** The getField's getIndex, if the getField is participating in a createList structure. */
+ /** The value's getIndex, if the value is participating in a createList structure. */
protected int index = -1;
- /** Helper structure used for indexing new createList getList. */
+ /** Helper structure used for indexing new createList values. */
protected Map<String, AtomicInteger> indices = new HashMap<>();
/**
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
new file mode 100644
index 0000000..6f27a0e
--- /dev/null
+++ b/code/api/src/test/java/org/apache/tamaya/spi/ListValueTest.java
@@ -0,0 +1,304 @@
+/*
+ * 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 org.junit.Test;
+
+import java.util.Iterator;
+import java.util.List;
+
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for {@link ListValue}.
+ */
+public class ListValueTest {
+
+ @Test
+ public void getCreation() {
+ ListValue lv = PropertyValue.createList();
+ assertNotNull(lv);
+ lv = PropertyValue.createList("k");
+ assertNotNull(lv);
+ assertEquals("k", lv.getKey());
+ }
+
+ @Test
+ public void getValueType() {
+ assertEquals(PropertyValue.ValueType.ARRAY, PropertyValue.createList().getValueType());
+ }
+
+ @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);
+ assertEquals(0, lv.getIndex(val));
+ assertEquals(1, lv.getIndex(val2));
+ PropertyValue val3 = PropertyValue.createValue("k3", "v");
+ assertEquals(-1, lv.getIndex(val3));
+ }
+
+ @Test
+ public void getSize() {
+ ListValue lv = PropertyValue.createList();
+ assertEquals(0, lv.getSize());
+ PropertyValue val = PropertyValue.createValue("k", "v");
+ lv.add(val);
+ assertEquals(1, lv.getSize());
+ PropertyValue val2 = PropertyValue.createValue("k", "v");
+ lv.add(val2);
+ assertEquals(2, 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);
+ assertNotNull(lv.getValues());
+ assertEquals(2, lv.getValues().size());
+ assertEquals(val, lv.getValues().get(0));
+ assertEquals(val2, lv.getValues().get(1));
+ lv.add(val2);
+ assertNotNull(lv.getValues());
+ assertEquals(2, lv.getValues().size());
+ assertEquals(val, lv.getValues().get(0));
+ assertEquals(val2, 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())
+ );
+ assertNotNull(result);
+ assertEquals(1, result.size());
+ assertEquals(val, result.get(0));
+ }
+
+ @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);
+ Iterator iter = lv.iterator();
+ assertNotNull(iter);
+ assertTrue(iter.hasNext());
+ assertEquals(val, iter.next());
+ assertTrue(iter.hasNext());
+ assertEquals(val2, iter.next());
+ assertFalse(iter.hasNext());
+ }
+
+ @Test
+ public void add() {
+ ListValue lv = PropertyValue.createList();
+ PropertyValue val = PropertyValue.createValue("k", "v");
+ lv.add(val);
+ lv.add(val);
+ lv.add(val);
+ assertEquals(1, lv.getSize());
+ assertEquals(val, lv.get(0));
+
+ }
+
+ @Test
+ public void addValue_Value() {
+ ListValue lv = PropertyValue.createList();
+ lv.addValue("v");
+ assertEquals(1, lv.getSize());
+ assertEquals("v", lv.get(0).getValue());
+ lv.addValue("v2");
+ assertEquals(2, lv.getSize());
+ assertEquals("v2", lv.get(1).getValue());
+ lv.addValue("v");
+ assertEquals(3, lv.getSize());
+ assertEquals("v", lv.get(2).getValue());
+ }
+
+ @Test
+ public void addValue_KeyValue() {
+ ListValue lv = PropertyValue.createList();
+ lv.addValue("k", "v");
+ assertEquals(1, lv.getSize());
+ assertEquals("v", lv.get(0).getValue());
+ assertEquals("k", lv.get(0).getKey());
+ lv.addValue("k2", "v2");
+ assertEquals(2, lv.getSize());
+ assertEquals("v2", lv.get(1).getValue());
+ assertEquals("k2", lv.get(1).getKey());
+ lv.addValue("k", "v");
+ assertEquals(3, lv.getSize());
+ assertEquals("v", lv.get(2).getValue());
+ assertEquals("k", lv.get(2).getKey());
+ }
+
+ @Test
+ public void addValues() {
+ ListValue lv = PropertyValue.createList();
+ lv.addValues("v", "v1", "v");
+ assertEquals(3, lv.getSize());
+ assertEquals("v", lv.get(0).getValue());
+ assertEquals("v1", lv.get(1).getValue());
+ assertEquals("v", lv.get(2).getValue());
+ }
+
+ @Test
+ public void addObject() {
+ ListValue lv = PropertyValue.createList();
+ lv.addObject();
+ assertEquals(1, lv.getSize());
+ ObjectValue ov = (ObjectValue)lv.get(0);
+ }
+
+ @Test
+ public void addObject_Key() {
+ ListValue lv = PropertyValue.createList();
+ lv.addObject("key");
+ assertEquals(1, lv.getSize());
+ ObjectValue ov = (ObjectValue)lv.get(0);
+ assertEquals("key", ov.getKey());
+ }
+
+ @Test
+ public void addList() {
+ ListValue lv = PropertyValue.createList();
+ lv.addList();
+ assertEquals(1, lv.getSize());
+ ListValue ov = (ListValue)lv.get(0);
+ assertEquals("", ov.getKey());
+ }
+
+ @Test
+ public void addList_Key() {
+ ListValue lv = PropertyValue.createList();
+ lv.addList("key");
+ assertEquals(1, lv.getSize());
+ ListValue ov = (ListValue)lv.get(0);
+ assertEquals("key", ov.getKey());
+ }
+
+ @Test
+ public void getValues() {
+ ListValue lv = PropertyValue.createList();
+ lv.addList("list");
+ lv.addObject("object");
+ assertNotNull(lv.getValues(""));
+ assertEquals(0, lv.getValues("").size());
+ assertEquals(1, lv.getValues("list").size());
+ assertEquals(1, lv.getValues("object").size());
+ }
+
+ @Test
+ public void toPropertyValue() {
+ ListValue lv = PropertyValue.createList("foo");
+ lv.addList("list");
+ PropertyValue pv = lv.toPropertyValue();
+ assertNotNull(pv);
+ assertEquals(pv.getKey(), lv.getKey());
+ }
+
+ @Test
+ public void toObjectValue() {
+ ListValue lv = PropertyValue.createList("foo");
+ lv.addList("list").setValue("a");
+ ObjectValue ov = lv.toObjectValue();
+ assertNotNull(ov);
+ assertEquals(ov.getKey(), lv.getKey());
+ assertNotNull(ov.getValue("list[0]"));
+ assertEquals(lv.getLists("list").get(0).getValue(), ov.getValue("list[0]").getValue());
+ }
+
+ @Test
+ public void toListValue() {
+ ListValue lv = PropertyValue.createList("foo");
+ lv.addList("list");
+ ListValue lv2 = lv.toListValue();
+ assertTrue(lv == lv2);
+ }
+
+ @Test
+ public void mutable() {
+ ListValue lv = PropertyValue.createList("foo");
+ lv.addList("list");
+ assertFalse(lv.isImmutable());
+ ListValue lv2 = lv.mutable();
+ assertFalse(lv2.isImmutable());
+ assertTrue(lv == lv2);
+ }
+
+ @Test
+ public void deepClone() {
+ ListValue lv1 = PropertyValue.createList("foo");
+ lv1.addList("list");
+ ListValue lv2 = lv1.deepClone();
+ assertTrue(lv1.getValues()!=lv2.getValues());
+ assertTrue(lv1.getMeta()!=lv2.getMeta());
+ assertTrue(lv1.equals(lv2));
+ assertTrue(lv1.iterator().next()!=lv2.iterator().next());
+ }
+
+ @Test
+ public void equals() {
+ ListValue lv1 = PropertyValue.createList("foo");
+ lv1.addList("list");
+ ListValue lv2 = PropertyValue.createList("foo");
+ lv2.addList("list");
+ assertTrue(lv1.equals(lv2));
+ }
+
+ @Test
+ public void testHashCode() {
+ ListValue lv1 = PropertyValue.createList("foo");
+ lv1.addList("list");
+ ListValue lv2 = PropertyValue.createList("foo");
+ lv2.addList("list");
+ assertTrue(lv1.hashCode() == lv2.hashCode());
+ }
+
+ @Test
+ public void testToString() {
+ ListValue lv1 = PropertyValue.createList("foo");
+ String toString = lv1.toString();
+ assertNotNull(toString);
+ lv1.addList("list");
+ toString = lv1.toString();
+ assertNotNull(toString);
+ lv1.addObject("object");
+ toString = lv1.toString();
+ assertNotNull(toString);
+ lv1.addValue("valueKey");
+ toString = lv1.toString();
+ assertNotNull(toString);
+ assertEquals("PropertyValue[ARRAY]{'foo', size='3'}", toString);
+ }
+}
\ No newline at end of file
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
new file mode 100644
index 0000000..e5266a0
--- /dev/null
+++ b/code/api/src/test/java/org/apache/tamaya/spi/ObjectValueTest.java
@@ -0,0 +1,332 @@
+/*
+ * 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 org.junit.Test;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for {@link ObjectValue}.
+ */
+public class ObjectValueTest {
+
+ @Test
+ public void getCreation() {
+ ObjectValue ov = PropertyValue.createObject();
+ assertNotNull(ov);
+ ov = PropertyValue.createObject("k");
+ assertNotNull(ov);
+ assertEquals("k", ov.getKey());
+ }
+
+ @Test
+ public void getValueType() {
+ assertEquals(PropertyValue.ValueType.ARRAY, PropertyValue.createList().getValueType());
+ }
+
+ @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);
+ assertEquals(val, ov.getValue(val.getKey()));
+ assertEquals(val2, ov.getValue(val2.getKey()));
+ assertNull(ov.getValue("foo"));
+ }
+
+ @Test
+ public void getSize() {
+ ObjectValue ov = PropertyValue.createObject();
+ assertEquals(0, ov.getSize());
+ PropertyValue val = PropertyValue.createValue("k", "v");
+ ov.set(val);
+ assertEquals(1, ov.getSize());
+ PropertyValue val2 = PropertyValue.createValue("k2", "v");
+ ov.set(val2);
+ assertEquals(2, ov.getSize());
+ PropertyValue val3 = PropertyValue.createValue("k2", "v");
+ ov.set(val3);
+ assertEquals(2, 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);
+ assertNotNull(ov.getValues());
+ assertEquals(2, ov.getValues().size());
+ assertEquals(val, ov.getValue("k1"));
+ assertEquals(val2, ov.getValue("k2"));
+ ov.set(val2);
+ assertNotNull(ov.getValues());
+ assertEquals(2, ov.getValues().size());
+ assertEquals(val, ov.getValue("k1"));
+ assertEquals(val2, ov.getValue("k2"));
+ }
+
+ @Test
+ public void getOrSetValue() {
+ ObjectValue ov = PropertyValue.createObject();
+ PropertyValue val = PropertyValue.createValue("k1", "v");
+ ov.set(val);
+ PropertyValue val2 = ov.getOrSetValue("k2",
+ () -> PropertyValue.createValue("foo", "bar"));
+ PropertyValue pv = ov.getOrSetValue("foo", () -> PropertyValue.createValue("foo", "bar"));
+ assertNotNull(pv);
+ assertEquals(3, ov.getValues().size());
+ assertEquals(val, ov.getValue("k1"));
+ assertEquals(val2, ov.getValue("k2"));
+ assertEquals(pv, ov.getValue("foo"));
+ }
+
+ @Test
+ public void setValues_Map() {
+ ObjectValue ov = PropertyValue.createObject();
+ Map map = new HashMap<>();
+ map.put("k1", "v");
+ map.put("k2.k3", "v2");
+ map.put("foo", "bar");
+ ov.setValues(map);
+ PropertyValue pv = ov.getValue("foo");
+ assertNotNull(pv);
+ assertEquals("foo", pv.getKey());
+ assertEquals("bar", pv.getValue());
+ }
+
+ @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);
+ Iterator iter = ov.iterator();
+ assertNotNull(iter);
+ assertTrue(iter.hasNext());
+ assertEquals(val, iter.next());
+ assertTrue(iter.hasNext());
+ assertEquals(val2, iter.next());
+ assertFalse(iter.hasNext());
+ }
+
+ @Test
+ public void set() {
+ ObjectValue ov = PropertyValue.createObject();
+ PropertyValue val = PropertyValue.createValue("k", "v");
+ ov.set(val);
+ ov.set(val);
+ ov.set(val);
+ assertEquals(1, ov.getSize());
+ assertEquals(val, ov.getValue("k"));
+
+ }
+
+ @Test
+ public void getSet_Value() {
+ ObjectValue ov = PropertyValue.createObject();
+ ov.setValue("v");
+ assertEquals(0, ov.getSize());
+ assertEquals("v", ov.getValue());
+ }
+
+ @Test
+ public void setValue_KeyValue() {
+ ObjectValue ov = PropertyValue.createObject();
+ ov.setValue("k", "v");
+ assertEquals(1, ov.getSize());
+ assertEquals("v", ov.getValue("k").getValue());
+ assertEquals("k", ov.getValue("k").getKey());
+ ov.setValue("k2", "v2");
+ assertEquals(2, ov.getSize());
+ assertEquals("v2", ov.getValue("k2").getValue());
+ assertEquals("k2", ov.getValue("k2").getKey());
+ ov.setValue("k", "v");
+ assertEquals(2, ov.getSize());
+ assertEquals("v", ov.getValue("k").getValue());
+ assertEquals("k", ov.getValue("k").getKey());
+ }
+
+ @Test
+ public void setValue_WithCompositeKey_Single() {
+ ObjectValue ov = PropertyValue.createObject();
+ ov.setValueWithCompositeKey("k1.k2.k3", "v");
+ assertEquals(1, ov.getSize());
+ ObjectValue treeNode = (ObjectValue)ov.getValue("k1");
+ assertNotNull(treeNode);
+ treeNode = (ObjectValue)treeNode.getValue("k2");
+ assertNotNull(treeNode);
+ PropertyValue finalValue = treeNode.getValue("k3");
+ assertNotNull(finalValue);
+ assertEquals("v", finalValue.getValue());
+ }
+
+
+ @Test
+ public void setObject() {
+ ObjectValue ov = PropertyValue.createObject();
+ ov.setObject("k");
+ assertEquals(1, ov.getSize());
+ ObjectValue ov2 = (ObjectValue)ov.getValue("k");
+ assertNotNull(ov2);
+ assertEquals("k", ov2.getKey());
+ }
+
+ @Test
+ public void setList() {
+ ObjectValue ov = PropertyValue.createObject();
+ ov.setList("k");
+ assertEquals(1, ov.getSize());
+ ListValue lv = (ListValue)ov.getValue("k");
+ assertEquals("k", lv.getKey());
+ }
+
+ @Test
+ public void getValue_WithName() {
+ ObjectValue ov = PropertyValue.createObject();
+ ov.setList("k1");
+ ov.setList("k2");
+ ov.setObject("k3");
+ ov.setValue("k4", "v");
+ Collection<PropertyValue> values = ov.getValues();
+ assertNotNull(values);
+ assertEquals(4, values.size());
+ }
+
+ @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())
+ );
+ assertNotNull(values);
+ assertEquals(1, values.size());
+ assertEquals("k1", values.iterator().next().getKey());
+ }
+
+ @Test
+ public void getValues() {
+ ObjectValue ov = PropertyValue.createObject();
+ ov.setList("k1");
+ ov.setList("k2");
+ ov.setObject("k3");
+ ov.setValue("k4", "v");
+ Collection<PropertyValue> values = ov.getValues();
+ assertNotNull(values);
+ assertEquals(4, values.size());
+ }
+
+ @Test
+ public void toPropertyValue() {
+ ObjectValue ov = PropertyValue.createObject("foo");
+ ov.setList("list");
+ PropertyValue pv = ov.toPropertyValue();
+ assertNotNull(pv);
+ assertEquals(pv.getKey(), ov.getKey());
+ }
+
+ @Test
+ public void toListValue() {
+ ObjectValue ov = PropertyValue.createObject("foo");
+ ov.setList("list").setValue("a");
+ ListValue lv = ov.toListValue();
+ assertNotNull(lv);
+ assertEquals(lv.getKey(), ov.getKey());
+ assertNotNull(lv.get(0));
+ assertEquals(ov.getValue("list").getValue(), lv.get(0).getValue());
+ }
+
+ @Test
+ public void toObjectValue() {
+ ObjectValue ov = PropertyValue.createObject("foo");
+ ov.setList("list");
+ ObjectValue ov2 = ov.toObjectValue();
+ assertTrue(ov == ov2);
+ }
+
+ @Test
+ public void mutable() {
+ ObjectValue ov = PropertyValue.createObject("foo");
+ ov.setList("list");
+ assertFalse(ov.isImmutable());
+ ObjectValue ov2 = ov.mutable();
+ assertFalse(ov2.isImmutable());
+ assertTrue(ov == ov2);
+ }
+
+ @Test
+ public void deepClone() {
+ ObjectValue ov1 = PropertyValue.createObject("foo");
+ ov1.setList("list");
+ ObjectValue ov2 = ov1.deepClone();
+ assertTrue(ov1.getValues()!=ov2.getValues());
+ assertTrue(ov1.getMeta()!=ov2.getMeta());
+ assertTrue(ov1.equals(ov2));
+ assertTrue(ov1.iterator().next()!=ov2.iterator().next());
+ }
+
+ @Test
+ public void equals() {
+ ObjectValue ov1 = PropertyValue.createObject("foo");
+ ov1.setList("list");
+ ObjectValue ov2 = PropertyValue.createObject("foo");
+ ov2.setList("list");
+ assertTrue(ov1.equals(ov2));
+ }
+
+ @Test
+ public void testHashCode() {
+ ObjectValue ov1 = PropertyValue.createObject("foo");
+ ov1.setList("list");
+ ObjectValue ov2 = PropertyValue.createObject("foo");
+ ov2.setList("list");
+ assertTrue(ov1.hashCode() == ov2.hashCode());
+ }
+
+ @Test
+ public void testToString() {
+ ObjectValue ov1 = PropertyValue.createObject("foo");
+ String toString = ov1.toString();
+ assertNotNull(toString);
+ ov1.setList("list");
+ toString = ov1.toString();
+ assertNotNull(toString);
+ ov1.setObject("object");
+ toString = ov1.toString();
+ assertNotNull(toString);
+ ov1.setValue("valueKey", "value");
+ toString = ov1.toString();
+ assertNotNull(toString);
+ assertEquals("PropertyValue[MAP]{'foo', size='3'}", toString);
+ }
+}
\ 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 6317714..a4d177e 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
@@ -261,12 +261,12 @@ public class PropertyValueTest {
public void objectOf() {
ObjectValue root = PropertyValue.createObject("bar");
assertTrue(root.getSize() == 0);
- assertNotNull(root.setField("foo", null));
+ assertNotNull(root.setValue("foo", null));
assertFalse(root.getSize()==0);
- assertNotNull(root.getField("foo"));
- assertNull(root.getField("foo").getValue());
- assertNotNull(root.setField("foo", "bar"));
- assertEquals(root.getField("foo").getValue(), "bar");
+ assertNotNull(root.getValue("foo"));
+ assertNull(root.getValue("foo").getValue());
+ assertNotNull(root.setValue("foo", "bar"));
+ assertEquals(root.getValue("foo").getValue(), "bar");
assertTrue(root.getSize()==1);
}
@@ -290,7 +290,7 @@ public class PropertyValueTest {
ObjectValue child = PropertyValue.createObject("b");
ObjectValue n = root.set(child);
assertEquals("a.b", child.getQualifiedKey());
- PropertyValue added = child.setField("c", null);
+ PropertyValue added = child.setValue("c", null);
assertEquals("a.b.c", added.getQualifiedKey());
}
@@ -339,9 +339,10 @@ public class PropertyValueTest {
public void getParent() {
ObjectValue n = PropertyValue.createObject("");
assertNull(n.getParent());
- n.setFieldObject("b");
- assertNotNull(n.getField("b"));
- assertNotNull(n.getField("b").getParent());
+ PropertyValue val = n.setObject("b");
+ assertNotNull(n.getValue("b"));
+ assertEquals(val, n.getValue("b"));
+ assertNotNull(n.getValue("b").getParent());
}
@Test
@@ -398,39 +399,39 @@ public class PropertyValueTest {
// n.setField("b");
// n.setField("c");
// n.setField("c");
-// List<PropertyValue> nodes = n.getList("a");
+// List<PropertyValue> nodes = n.getValues("a");
// assertNotNull(nodes);
// assertEquals(1, nodes.size());
-// assertEquals("a", nodes.getField(0).getKey());
+// assertEquals("a", nodes.getValue(0).getKey());
//
-// nodes = n.getList("c");
+// nodes = n.getValues("c");
// assertEquals(2, nodes.size());
-// assertEquals("c", nodes.getField(0).getKey());
-// assertEquals("c", nodes.getField(1).getKey());
+// assertEquals("c", nodes.getValue(0).getKey());
+// assertEquals("c", nodes.getValue(1).getKey());
// }
//
// @Test
-// public void getList() {
+// public void getValues() {
// PropertyValue n = PropertyValue.createObject();
// n.setField("a");
// n.setField("b");
// n.setField("c");
// n.setField("c");
-// List<PropertyValue> nodes = n.getList();
+// List<PropertyValue> nodes = n.getValues();
// assertNotNull(nodes);
// assertEquals(4, nodes.size());
-// assertEquals("a", nodes.getField(0).getKey());
-// assertEquals("b", nodes.getField(1).getKey());
-// assertEquals("c", nodes.getField(2).getKey());
-// assertEquals("c", nodes.getField(3).getKey());
+// assertEquals("a", nodes.getValue(0).getKey());
+// assertEquals("b", nodes.getValue(1).getKey());
+// assertEquals("c", nodes.getValue(2).getKey());
+// assertEquals("c", nodes.getValue(3).getKey());
// }
@Test
public void asMap() {
ObjectValue n = PropertyValue.createObject("");
- n.setField("a", "aVal");
- n.setFieldObject("b").setFieldObject("b2").setField("b3", "b3Val");
- ListValue array = n.setFieldList("c");
+ n.setValue("a", "aVal");
+ n.setObject("b").setObject("b2").setValue("b3", "b3Val");
+ ListValue array = n.setList("c");
array.addValue("cVal1");
array.addValue("cVal2");
Map<String,String> map = n.toMap();
@@ -445,9 +446,9 @@ public class PropertyValueTest {
@Test
public void asString() {
ObjectValue n = PropertyValue.createObject();
- n.setField("a", "aVal");
- n.setField("b.b2.b3", "b3Val");
- n.setField("c", "cVal2");
+ n.setValue("a", "aVal");
+ n.setValue("b.b2.b3", "b3Val");
+ n.setValue("c", "cVal2");
assertEquals("a = aVal\n" +
"b.b2.b3 = b3Val\n" +
"c = cVal2\n", n.asString());
@@ -465,9 +466,9 @@ public class PropertyValueTest {
@Test
public void testToString() {
ObjectValue n = PropertyValue.createObject("");
- n.setField("a", "aVal");
- n.setField("b.b2.b3", "b3Val");
- n.setFieldList("c").addValue("cVal1");
+ n.setValue("a", "aVal");
+ n.setValue("b.b2.b3", "b3Val");
+ n.setValue("c", "cVal1");
assertEquals("PropertyValue[MAP]{'', size='3'}", n.toString());
}
diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/BannerManagerTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/BannerManagerTest.java
index 2024723..9fc4433 100644
--- a/code/core/src/test/java/org/apache/tamaya/core/internal/BannerManagerTest.java
+++ b/code/core/src/test/java/org/apache/tamaya/core/internal/BannerManagerTest.java
@@ -29,7 +29,7 @@ import java.security.Permission;
/*
* Note:
* The tests of this class will fail PIT, our coverage tool.
- * Therefore we excluded this class in the getParent POM
+ * Therefore we excluded this class in the parent POM
* from the test execution.
* Oliver B. Fischer, 2017-09-16
*/
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 d918082..4e1965f 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
@@ -128,7 +128,7 @@ public abstract class BasePropertySource implements PropertySource{
PropertyValue configuredOrdinal = get(TAMAYA_ORDINAL);
if(configuredOrdinal!=null){
try {
- return Integer.parseInt(configuredOrdinal.getValue());
+ return Double.valueOf(configuredOrdinal.getValue()).intValue();
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.WARNING,
"Configured ordinal is not an int number: " + configuredOrdinal, e);
diff --git a/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultMetaDataProviderTest.java b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultMetaDataProviderTest.java
new file mode 100644
index 0000000..7ef54d4
--- /dev/null
+++ b/code/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultMetaDataProviderTest.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport;
+
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.ServiceContextManager;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for {@link DefaultMetaDataProvider}.
+ */
+public class DefaultMetaDataProviderTest {
+
+ @Test
+ public void cretion() {
+ new DefaultMetaDataProvider();
+ }
+
+ @Test
+ public void init() {
+ DefaultMetaDataProvider provider = new DefaultMetaDataProvider();
+ assertEquals(this, provider.init(ConfigurationContext.EMPTY));
+ }
+
+ @Test
+ public void getMetaData() {
+ DefaultMetaDataProvider provider = new DefaultMetaDataProvider();
+ assertEquals(this, provider.init(ConfigurationContext.EMPTY));
+ assertNotNull(provider.getMetaData("foo"));
+
+ }
+
+ @Test
+ public void setMeta() {
+ DefaultMetaDataProvider provider = new DefaultMetaDataProvider();
+ assertEquals(this, provider.init(ConfigurationContext.EMPTY));
+ provider.setMeta("foo", "a", "b");
+ assertNotNull(provider.getMetaData("foo"));
+ assertEquals(1, provider.getMetaData("foo").size());
+ }
+
+ @Test
+ public void setMeta_Map() {
+ DefaultMetaDataProvider provider = new DefaultMetaDataProvider();
+ assertEquals(this, provider.init(ConfigurationContext.EMPTY));
+ Map<String,String> map = new HashMap<>();
+ map.put("a", "b");
+ provider.setMeta("foo", map);
+ assertNotNull(provider.getMetaData("foo"));
+ assertEquals(1, provider.getMetaData("foo").size());
+
+ }
+
+ @Test
+ public void reset() {
+ DefaultMetaDataProvider provider = new DefaultMetaDataProvider();
+ assertEquals(this, provider.init(ConfigurationContext.EMPTY));
+ provider.reset();
+ assertNull(provider.getMetaData("foo"));
+ }
+
+ @Test
+ public void reset1() {
+ DefaultMetaDataProvider provider = new DefaultMetaDataProvider();
+ assertEquals(this, provider.init(ConfigurationContext.EMPTY));
+ provider.reset();
+ assertNull(provider.getMetaData("foo"));
+ }
+
+
+ @Test
+ public void testToString() {
+ }
+}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 340bd7f..120525a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -67,6 +67,7 @@
<mockito.version>1.10.19</mockito.version>
<rat.version>0.12</rat.version>
<toolchains.plugin>1.1</toolchains.plugin>
+ <assertj.version>3.10.0</assertj.version>
<!-- Dependencies for site generation -->
<reflow-skin.version>1.1.1</reflow-skin.version>
@@ -234,7 +235,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
- <version>3.8.0</version>
+ <version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>