You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2014/02/23 19:43:02 UTC
svn commit: r1571061 - in
/commons/proper/configuration/branches/immutableNodes/src:
main/java/org/apache/commons/configuration/tree/InMemoryNodeModel.java
test/java/org/apache/commons/configuration/tree/TestInMemoryNodeModel.java
Author: oheger
Date: Sun Feb 23 18:43:02 2014
New Revision: 1571061
URL: http://svn.apache.org/r1571061
Log:
InMemoryNodeModel.addNodes() now verifies the key pointing to the target node.
It the key references an attribute, an exception is thrown as it is not
possible to add nodes to an attribute.
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=1571061&r1=1571060&r2=1571061&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:43:02 2014
@@ -213,6 +213,8 @@ public class InMemoryNodeModel implement
* @param key the key
* @param nodes the collection of nodes to be added
* @param resolver the {@code NodeKeyResolver}
+ * @throws IllegalArgumentException if the key references an attribute (of
+ * course, it is not possible to add something to an attribute)
*/
public void addNodes(final String key,
final Collection<ImmutableNode> nodes,
@@ -227,6 +229,12 @@ public class InMemoryNodeModel implement
InMemoryNodeModel.this);
if (results.size() == 1)
{
+ if (results.get(0).isAttributeResult())
+ {
+ throw new IllegalArgumentException(
+ "New nodes cannot be added to an attribute key: "
+ + key);
+ }
tx.addAddNodesOperation(results.get(0).getNode(), nodes);
}
else
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=1571061&r1=1571060&r2=1571061&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:43:02 2014
@@ -1165,4 +1165,26 @@ public class TestInMemoryNodeModel
assertSame("Wrong added node", personaNode,
nodeForKey(model, newAuthor + "/" + newWork + "/" + newPersona));
}
+
+ /**
+ * Tries to add new nodes if the key references an attribute.
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testAddNodesToAttribute()
+ {
+ NodeKeyResolver resolver = EasyMock.createMock(NodeKeyResolver.class);
+ InMemoryNodeModel model =
+ new InMemoryNodeModel(NodeStructureHelper.ROOT_AUTHORS_TREE);
+ EasyMock.expect(
+ resolver.resolveKey(NodeStructureHelper.ROOT_AUTHORS_TREE, KEY,
+ model)).andReturn(
+ Collections.singletonList(QueryResult.createAttributeResult(
+ nodeForKey(model, NodeStructureHelper.author(1)),
+ "test")));
+ EasyMock.replay(resolver);
+
+ ImmutableNode newNode =
+ new ImmutableNode.Builder().name("newNode").create();
+ model.addNodes(KEY, Collections.singleton(newNode), resolver);
+ }
}