Node.addNode(String relPath) but I Don't know the type
bwallis42 Jun 20, 2012 2:07 AMI have a bit of code in my system that I have extracted into the following two test cases. The original code was working when we were using jackrabbit and also with ModeShape 2.8 (but I haven't reproduced that in my test case as yet). I'm currently running 3.0.0.Alpha5.
Given the following schema
{code}
<inf = 'http://infomedix.com.au/inf'>
<er = 'http://infomedix.com.au/eReferral'>
[inf:documentGroup] > mix:referenceable
orderable
[inf:person]
- inf:firstName (STRING) mandatory
- inf:lastName (STRING) mandatory
[inf:doctor] > inf:person
- inf:doctorProviderNumber (STRING)
[er:eReferral] > mix:referenceable
mixin
+ er:gp (inf:doctor) = inf:doctor mandatory
{code}
If I run the following testcase
{code}
@Test
public void addTwoNodesWithoutSubnodeType() throws Exception
{
Node docGroup = session.getRootNode().addNode("inf:documentGroup", "inf:documentGroup");
assertEquals("inf:documentGroup",docGroup.getPrimaryNodeType().getName());
docGroup.addMixin("er:eReferral");
Node ergp = docGroup.addNode("er:gp");
assertEquals("inf:doctor",ergp.getPrimaryNodeType().getName());
}
{code}
I get an error in the last assert:
{noformat}
javax.jcr.nodetype.ConstraintViolationException: Unable to determine a valid node definition for the node "/inf:documentGroup/er:gp" in workspace "default" of "Document Store Repository"
at org.modeshape.jcr.AbstractJcrNode.validateChildNodeDefinition(AbstractJcrNode.java:1186)
at org.modeshape.jcr.AbstractJcrNode.addChildNode(AbstractJcrNode.java:1036)
at org.modeshape.jcr.AbstractJcrNode.addNode(AbstractJcrNode.java:994)
at org.modeshape.jcr.AbstractJcrNode.addNode(AbstractJcrNode.java:915)
at org.modeshape.jcr.AbstractJcrNode.addNode(AbstractJcrNode.java:104)
at au.com.infomedix.harvey.documentstore.jcr.MixinTest.addTwoNodesWithoutSubnodeType(MixinTest.java:86)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
{noformat}
If I do supply the type of the er:gp child node then it works OK. So, the following test case does work when I explicitly supply the child node type
{code}
@Test
public void addTwoNodesWithTypes() throws Exception
{
Node docGroup = session.getRootNode().addNode("inf:documentGroup", "inf:documentGroup");
assertEquals("inf:documentGroup",docGroup.getPrimaryNodeType().getName());
docGroup.addMixin("er:eReferral");
Node ergp = docGroup.addNode("er:gp", "inf:doctor");
assertEquals("inf:doctor",ergp.getPrimaryNodeType().getName());
}
{code}