Author: cziegeler
Date: Thu Nov 4 20:55:25 2010
New Revision: 1031238
URL: http://svn.apache.org/viewvc?rev=1031238&view=rev
Log:
SLING-1861 : Add a test case
Modified:
sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiablePropertyMapTest.java
Modified:
sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiablePropertyMapTest.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiablePropertyMapTest.java?rev=1031238&r1=1031237&r2=1031238&view=diff
==============================================================================
---
sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiablePropertyMapTest.java
(original)
+++
sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrModifiablePropertyMapTest.java
Thu Nov 4 20:55:25 2010
@@ -22,10 +22,14 @@ import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeType;
import org.apache.sling.api.resource.PersistableValueMap;
import org.apache.sling.api.resource.ValueMap;
@@ -159,6 +163,40 @@ public class JcrModifiablePropertyMapTes
} catch (IllegalArgumentException iae) {}
}
+ private Set<String> getMixinNodeTypes(final Node node) throws
RepositoryException {
+ final Set<String> mixinTypes = new HashSet<String>();
+ for(final NodeType mixinNodeType : node.getMixinNodeTypes() ) {
+ mixinTypes.add(mixinNodeType.getName());
+ }
+ return mixinTypes;
+ }
+
+ public void testMixins() throws Exception {
+ final Node testNode = this.rootNode.addNode("testMixins" +
System.currentTimeMillis());
+ testNode.getSession().save();
+ final PersistableValueMap pvm = new JcrModifiablePropertyMap(testNode);
+
+ final String[] types = pvm.get("jcr:mixinTypes", String[].class);
+ final Set<String> exNodeTypes = getMixinNodeTypes(testNode);
+
+ assertEquals(exNodeTypes.size(), (types == null ? 0 : types.length));
+ if ( types != null ) {
+ for(final String name : types) {
+ assertTrue(exNodeTypes.contains(name));
+ }
+ String[] newTypes = new String[types.length + 1];
+ System.arraycopy(types, 0, newTypes, 0, types.length);
+ newTypes[types.length] = "mix:referenceable";
+ pvm.put("jcr:mixinTypes", newTypes);
+ } else {
+ pvm.put("jcr:mixinTypes", "mix:referenceable");
+ }
+ pvm.save();
+
+ final Set<String> newNodeTypes = getMixinNodeTypes(testNode);
+ assertEquals(newNodeTypes.size(), exNodeTypes.size() + 1);
+ }
+
protected JcrPropertyMap createPropertyMap(final Node node) {
return new JcrModifiablePropertyMap(node);
}