Merge branch 'feature/SLING-10245-add-jcr-primary-type' into master
diff --git a/src/main/java/org/apache/sling/testing/mock/jcr/ItemData.java b/src/main/java/org/apache/sling/testing/mock/jcr/ItemData.java
index 6661344..e528ceb 100644
--- a/src/main/java/org/apache/sling/testing/mock/jcr/ItemData.java
+++ b/src/main/java/org/apache/sling/testing/mock/jcr/ItemData.java
@@ -34,7 +34,7 @@
private final String name;
private final boolean isNode;
private final String uuid;
- private final NodeType nodeType;
+ private NodeType nodeType;
private Value[] values;
private boolean isMultiple;
private boolean isNew;
@@ -80,6 +80,10 @@
return nodeType;
}
+ public void setNodeType(NodeType nodeType) {
+ this.nodeType = nodeType;
+ }
+
public Value[] getValues() {
if (!isProperty()) {
throw new UnsupportedOperationException();
diff --git a/src/main/java/org/apache/sling/testing/mock/jcr/MockNode.java b/src/main/java/org/apache/sling/testing/mock/jcr/MockNode.java
index 6213c09..00903cd 100644
--- a/src/main/java/org/apache/sling/testing/mock/jcr/MockNode.java
+++ b/src/main/java/org/apache/sling/testing/mock/jcr/MockNode.java
@@ -35,6 +35,7 @@
import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.lock.Lock;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
import javax.jcr.nodetype.NodeDefinition;
import javax.jcr.nodetype.NodeType;
import javax.jcr.version.Version;
@@ -383,6 +384,17 @@
return new MockNodeDefinition();
}
+ @Override
+ public void setPrimaryType(final String primaryNodeTypeName) throws RepositoryException {
+ if (StringUtils.isNotBlank(primaryNodeTypeName)) {
+ // accept all node types like stated in the MockNodeTypeManager
+ this.itemData.setNodeType(new MockNodeType(primaryNodeTypeName));
+ setProperty(JcrConstants.JCR_PRIMARYTYPE, primaryNodeTypeName);
+ } else {
+ throw new NoSuchNodeTypeException("Not accepting blank node types");
+ }
+ }
+
// --- unsupported operations ---
@Override
public Property setProperty(final String name, final Value value, final int type) throws RepositoryException {
@@ -564,9 +576,5 @@
throw new UnsupportedOperationException();
}
- @Override
- public void setPrimaryType(final String nodeTypeName) throws RepositoryException {
- throw new UnsupportedOperationException();
- }
}
diff --git a/src/test/java/org/apache/sling/testing/mock/jcr/MockNodeTest.java b/src/test/java/org/apache/sling/testing/mock/jcr/MockNodeTest.java
index 3b35470..0d9c0b1 100644
--- a/src/test/java/org/apache/sling/testing/mock/jcr/MockNodeTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/jcr/MockNodeTest.java
@@ -37,6 +37,7 @@
import javax.jcr.PropertyIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
import org.apache.jackrabbit.JcrConstants;
import org.junit.Assert;
@@ -130,6 +131,17 @@
}
@Test
+ public void testSetPrimaryType() throws RepositoryException {
+ this.node1.setPrimaryType("nt:folder");
+ assertEquals("nt:folder", this.node1.getPrimaryNodeType().getName());
+ }
+
+ @Test(expected = NoSuchNodeTypeException.class)
+ public void testSetBlankPrimaryType() throws RepositoryException {
+ this.node1.setPrimaryType(" ");
+ }
+
+ @Test
public void testIsNode() {
assertTrue(this.node1.isNode());
assertFalse(this.prop1.isNode());