Author: oheger
Date: Sun Feb 23 18:40:40 2014
New Revision: 1571056
URL: http://svn.apache.org/r1571056
Log:
InMemoryNodeModel.setProperty() now can deal with empty operations.
Modified:
commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/InMemoryNodeModel.java
commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestInMemoryNodeModel.java
Modified:
commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/InMemoryNodeModel.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/InMemoryNodeModel.java?rev=1571056&r1=1571055&r2=1571056&view=diff
==============================================================================
---
commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/InMemoryNodeModel.java
(original)
+++
commons/proper/configuration/branches/immutableNodes/src/main/java/org/apache/commons/configuration/tree/InMemoryNodeModel.java
Sun Feb 23 18:40:40 2014
@@ -224,6 +224,7 @@ public class InMemoryNodeModel implement
{
public boolean initTransaction(ModelTransaction tx)
{
+ boolean added = false;
NodeUpdateData<ImmutableNode> updateData =
resolver.resolveUpdateKey(
tx.getCurrentData().getRoot(), key, value,
@@ -232,10 +233,15 @@ public class InMemoryNodeModel implement
{
initializeAddTransaction(tx, key,
updateData.getNewValues(), resolver);
+ added = true;
}
- initializeClearTransaction(tx, updateData.getRemovedNodes());
- initializeUpdateTransaction(tx, updateData.getChangedValues());
- return true;
+ boolean cleared =
+ initializeClearTransaction(tx,
+ updateData.getRemovedNodes());
+ boolean updated =
+ initializeUpdateTransaction(tx,
+ updateData.getChangedValues());
+ return added || cleared || updated;
}
});
}
@@ -534,8 +540,9 @@ public class InMemoryNodeModel implement
* @param tx the transaction to be initialized
* @param results a collection with results pointing to the nodes to be
* cleared
+ * @return a flag whether there are elements to be cleared
*/
- private static void initializeClearTransaction(ModelTransaction tx,
+ private static boolean initializeClearTransaction(ModelTransaction tx,
Collection<QueryResult<ImmutableNode>> results)
{
for (QueryResult<ImmutableNode> result : results)
@@ -550,6 +557,8 @@ public class InMemoryNodeModel implement
tx.addClearNodeValueOperation(result.getNode());
}
}
+
+ return !results.isEmpty();
}
/**
@@ -558,8 +567,9 @@ public class InMemoryNodeModel implement
*
* @param tx the transaction to be initialized
* @param changedValues the map defining the elements to be changed
+ * @return a flag whether there are elements to be updated
*/
- private static void initializeUpdateTransaction(ModelTransaction tx,
+ private static boolean initializeUpdateTransaction(ModelTransaction tx,
Map<QueryResult<ImmutableNode>, Object> changedValues)
{
for (Map.Entry<QueryResult<ImmutableNode>, Object> e : changedValues
@@ -576,6 +586,8 @@ public class InMemoryNodeModel implement
e.getValue());
}
}
+
+ return !changedValues.isEmpty();
}
/**
Modified:
commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestInMemoryNodeModel.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestInMemoryNodeModel.java?rev=1571056&r1=1571055&r2=1571056&view=diff
==============================================================================
---
commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestInMemoryNodeModel.java
(original)
+++
commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestInMemoryNodeModel.java
Sun Feb 23 18:40:40 2014
@@ -1082,4 +1082,25 @@ public class TestInMemoryNodeModel
.getAttributes().get(NodeStructureHelper.ATTR_TESTED));
assertEquals("Node value not changed", newValue, node.getValue());
}
+
+ /**
+ * Tests a set property operation which is a no-op.
+ */
+ @Test
+ public void testSetPropertyNoChanges()
+ {
+ NodeKeyResolver resolver = EasyMock.createMock(NodeKeyResolver.class);
+ InMemoryNodeModel model =
+ new InMemoryNodeModel(NodeStructureHelper.ROOT_PERSONAE_TREE);
+ EasyMock.expect(
+ resolver.resolveUpdateKey(
+ NodeStructureHelper.ROOT_PERSONAE_TREE, KEY, this,
+ model)).andReturn(
+ new NodeUpdateData<ImmutableNode>(null, null, null, null));
+ EasyMock.replay(resolver);
+
+ model.setProperty(KEY, this, resolver);
+ assertSame("Model was changed", NodeStructureHelper.ROOT_PERSONAE_TREE,
+ model.getRootNode());
+ }
}