From jackrabbit-commits-return-437-apmail-incubator-jackrabbit-commits-archive=www.apache.org@incubator.apache.org Wed Mar 02 16:32:38 2005 Return-Path: Delivered-To: apmail-incubator-jackrabbit-commits-archive@www.apache.org Received: (qmail 72580 invoked from network); 2 Mar 2005 16:32:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 2 Mar 2005 16:32:37 -0000 Received: (qmail 98872 invoked by uid 500); 2 Mar 2005 16:32:35 -0000 Mailing-List: contact jackrabbit-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jackrabbit-dev@incubator.apache.org Delivered-To: mailing list jackrabbit-commits@incubator.apache.org Received: (qmail 98819 invoked by uid 500); 2 Mar 2005 16:32:34 -0000 Delivered-To: apmail-incubator-jackrabbit-cvs@incubator.apache.org Received: (qmail 98739 invoked by uid 99); 2 Mar 2005 16:32:33 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Wed, 02 Mar 2005 08:32:31 -0800 Received: (qmail 72428 invoked by uid 65534); 2 Mar 2005 16:32:30 -0000 Message-ID: <20050302163230.72426.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Wed, 02 Mar 2005 16:32:29 -0000 Subject: svn commit: r155927 [1/2] - in incubator/jackrabbit/trunk: applications/test/ applications/test/repository/nodetypes/ src/java/org/apache/jackrabbit/core/util/ src/test/org/apache/jackrabbit/test/ src/test/org/apache/jackrabbit/test/api/ To: jackrabbit-cvs@incubator.apache.org From: mreutegg@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: mreutegg Date: Wed Mar 2 08:32:25 2005 New Revision: 155927 URL: http://svn.apache.org/viewcvs?view=3Drev&rev=3D155927 Log: Adding level 2 test cases for Node and Session interface. Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/Node= OrderableChildNodesTest.java (with props) incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/Node= Test.java (with props) incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/Node= UUIDTest.java (with props) incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/Sess= ionTest.java (with props) incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/Sess= ionUUIDTest.java (with props) Modified: incubator/jackrabbit/trunk/applications/test/repository/nodetypes/custo= m_nodetypes.xml incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.propert= ies incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/util/ISO= 9075.java incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/Abstract= JCRTest.java incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/Test= All.java Modified: incubator/jackrabbit/trunk/applications/test/repository/nodetypes= /custom_nodetypes.xml URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/applications/= test/repository/nodetypes/custom_nodetypes.xml?view=3Ddiff&r1=3D155926&r2= =3D155927 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/applications/test/repository/nodetypes/custo= m_nodetypes.xml (original) +++ incubator/jackrabbit/trunk/applications/test/repository/nodetypes/custo= m_nodetypes.xml Wed Mar 2 08:32:25 2005 @@ -66,5 +66,14 @@ + =20 + + + + mix:versionable + nt:base + + + =20 Modified: incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.p= roperties URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/applications/= test/repositoryStubImpl.properties?view=3Ddiff&r1=3D155926&r2=3D155927 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.propert= ies (original) +++ incubator/jackrabbit/trunk/applications/test/repositoryStubImpl.propert= ies Wed Mar 2 08:32:25 2005 @@ -106,6 +106,78 @@ # Test class: NamespaceRemappingTest javax.jcr.tck.NamespaceRemappingTest.testroot=3D/ =20 +# Test class: SessionTest +# Test method: testMoveItemExistsException +# nodetype that does not allow same name siblings +javax.jcr.tck.SessionTest.testMoveItemExistsException.nodetype2=3Dnt:folder +# valid node type that can be added as child of nodetype2 +javax.jcr.tck.SessionTest.testMoveItemExistsException.nodetype3=3Dnt:hiera= rchyNode + +# Test class: SessionTest +# Test method: testSaveContstraintViolationException +# nodetype that has a property that is mandatory but not autocreated +javax.jcr.tck.SessionTest.testSaveContstraintViolationException.nodetype2= =3Dnt:file + +# Test class: SessionUUIDTest +# node type that has a property of type PropertyType.REFERENCE +javax.jcr.tck.SessionUUIDTest.nodetype=3Dnt:unstructured +# name of the property that is of type PropertyType.REFERENCE +javax.jcr.tck.SessionUUIDTest.propertyname1=3Dfoobar +# nodetype that has nodetype mix:referenceable assigned +javax.jcr.tck.SessionUUIDTest.nodetype2=3Dtest:refTargetNode + +# Test class: SessionUUIDTest +# Test method: testSaveMovedRefNode +# name of the property that can be modified +javax.jcr.tck.SessionUUIDTest.testSaveMovedRefNode.propertyname1=3Dfoobar + +# Test class: NodeTest +# Test method: testAddNodeItemExistsException +# nodetype that does not allow same name siblings and allows child nodes of +# the same type +javax.jcr.tck.NodeTest.testAddNodeItemExistsException.nodetype=3Dnt:folder + +# Test class: NodeTest +# Test method: testRemoveMandatoryNode +# nodetype that has a mandatory child node definition +javax.jcr.tck.NodeTest.testRemoveMandatoryNode.nodetype2=3Dnt:file +# nodetype of the mandatory child +javax.jcr.tck.NodeTest.testRemoveMandatoryNode.nodetype3=3Dnt:base +# name of the mandatory node +javax.jcr.tck.NodeTest.testRemoveMandatoryNode.nodename3=3Djcr:content + +# Test class: NodeTest +# Test method: testSaveContstraintViolationException +# nodetype that has a property that is mandatory but not autocreated +javax.jcr.tck.NodeTest.testSaveContstraintViolationException.nodetype2=3Dn= t:file + +# Test class: NodeUUIDTest +# node type that has a property of type PropertyType.REFERENCE +javax.jcr.tck.NodeUUIDTest.nodetype=3Dnt:unstructured +# name of the property that is of type PropertyType.REFERENCE +javax.jcr.tck.NodeUUIDTest.propertyname1=3Dref +# nodetype that has nodetype mix:referenceable assigned +javax.jcr.tck.NodeUUIDTest.nodetype2=3Dtest:refTargetNode + +# Test class: NodeUUIDTest +# Test method: testSaveMovedRefNode +# name of the property that can be modified +javax.jcr.tck.NodeUUIDTest.testSaveMovedRefNode.propertyname1=3Dfoobar +# nodetype that has nodetype mix:referenceable assigned + +# Test class: NodeOrderableChildNodesTest +# nodetype that supports orderable child nodes +javax.jcr.tck.NodeOrderableChildNodesTest.nodetype2=3Dnt:unstructured +# valid node type that can be added as child of nodetype 2 +javax.jcr.tck.NodeOrderableChildNodesTest.nodetype3=3Dnt:unstructured + +# Test class: NodeOrderableChildNodesTest +# Test method: testOrderBeforeUnsupportedRepositoryOperationException +# nodetype that does not allow ordering of child nodes +javax.jcr.tck.NodeOrderableChildNodesTest.testOrderBeforeUnsupportedReposi= toryOperationException.nodetype2=3Dnt:folder +# valid node type that can be added as child of nodetype 2 +javax.jcr.tck.NodeOrderableChildNodesTest.testOrderBeforeUnsupportedReposi= toryOperationException.nodetype3=3Dnt:hierarchyNode + # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D # JAVAX.JCR.QUERY CONFIGURATION # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ut= il/ISO9075.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/= apache/jackrabbit/core/util/ISO9075.java?view=3Ddiff&r1=3D155926&r2=3D155927 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/util/ISO= 9075.java (original) +++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/util/ISO= 9075.java Wed Mar 2 08:32:25 2005 @@ -26,12 +26,12 @@ * Implements the encode and decode routines as specified for XML name to = SQL * identifier conversion in ISO 9075-14:2003.
* If a character c is not valid at a certain position in an = XML 1.0 - * Name it is encoded in the form: '_x' + hexValueOf(c) + '_' - * todo or is it NCName + * NCName it is encoded in the form: '_x' + hexValueOf(c) + '_' *

* Note that only the local part of a {@link org.apache.jackrabbit.core.QN= ame} * is encoded / decoded. A URI namespace will always be valid and does not * need encoding. + * todo change implementation to latest spec. only encode _x when followed= by XXXX_ */ public class ISO9075 { =20 Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/Ab= stractJCRTest.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/AbstractJCRTest.java?view=3Ddiff&r1=3D155926&r2=3D15= 5927 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/Abstract= JCRTest.java (original) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/Abstract= JCRTest.java Wed Mar 2 08:32:25 2005 @@ -25,6 +25,9 @@ import javax.jcr.NamespaceException; import javax.jcr.RangeIterator; import java.util.StringTokenizer; +import java.util.Random; +import java.util.List; +import java.util.Arrays; =20 /** * Abstract base class for all JCR test classes. @@ -92,6 +95,11 @@ protected String jcrlockIsDeep; =20 /** + * JCR Name jcr:mergeFailed using the namespace resolver of the curren= t session. + */ + protected String jcrMergeFailed; + + /** * JCR Name nt:base using the namespace resolver of the current sessio= n=2E */ protected String ntBase; @@ -231,6 +239,7 @@ jcrUUID =3D superuser.getNamespacePrefix(NS_JCR_URI) + ":uuid"; jcrLockOwner =3D superuser.getNamespacePrefix(NS_JCR_URI) + ":lock= Owner"; jcrlockIsDeep =3D superuser.getNamespacePrefix(NS_JCR_URI) + ":loc= kIsDeep"; + jcrMergeFailed =3D superuser.getNamespacePrefix(NS_JCR_URI) + ":me= rgeFailed"; ntBase =3D superuser.getNamespacePrefix(NS_NT_URI) + ":base"; mixReferenceable =3D superuser.getNamespacePrefix(NS_MIX_URI) + ":= referenceable"; mixVersionable =3D superuser.getNamespacePrefix(NS_MIX_URI) + ":ve= rsionable"; @@ -364,6 +373,41 @@ size++; } return size; + } + + /** + * Returns the name of a workspace that is not accessible from + * session. + * @param session the session. + * @return name of a non existing workspace. + * @throws RepositoryException if an error occurs. + */ + protected String getNonExistingWorkspaceName(Session session) throws R= epositoryException { + List names =3D Arrays.asList(session.getWorkspace().getAccessibleW= orkspaceNames()); + String nonExisting =3D null; + while (nonExisting =3D=3D null) { + String name =3D createRandomString(10); + if (!names.contains(name)) { + nonExisting =3D name; + } + } + return nonExisting; + } + + /** + * Creates a String with a random sequence of characters + * using 'a' - 'z'. + * @param numChars number of characters. + * @return the generated String. + */ + protected String createRandomString(int numChars) { + Random rand =3D new Random(System.currentTimeMillis()); + StringBuffer tmp =3D new StringBuffer(numChars); + for (int i =3D 0; i < numChars; i++) { + char c =3D (char) (rand.nextInt(('z' + 1) - 'a') + 'a'); + tmp.append(c); + } + return tmp.toString(); } =20 } Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/N= odeOrderableChildNodesTest.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/api/NodeOrderableChildNodesTest.java?view=3Dauto&rev= =3D155927 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/Node= OrderableChildNodesTest.java (added) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/Node= OrderableChildNodesTest.java Wed Mar 2 08:32:25 2005 @@ -0,0 +1,281 @@ +/* + * Copyright 2004-2005 The Apache Software Foundation or its licensors, + * as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.test.api; + +import org.apache.jackrabbit.test.AbstractJCRTest; +import org.apache.jackrabbit.test.NotExecutableException; + +import javax.jcr.nodetype.ConstraintViolationException; +import javax.jcr.nodetype.NodeType; +import javax.jcr.Node; +import javax.jcr.ItemNotFoundException; +import javax.jcr.RepositoryException; +import javax.jcr.UnsupportedRepositoryOperationException; +import javax.jcr.NodeIterator; +import javax.jcr.Session; + +/** + * NodeOrderableChildNodesTest contains all node writing test= s (LEVEL 2) that require a node + * that allows child node ordering (tests therefore are optional). + *

+ * If the repository does not support a node type with orderable child nod= es + * a {@link NotExecutableException} exception is thrown. + *

+ * Prerequisites: + *

    + *
  • javax.jcr.tck.NodeOrderableChildNodesTest.nodetype2Nam= e of a + * valid node type that allows orderable child nodes
  • + *
  • javax.jcr.tck.NodeOrderableChildNodesTest.nodetype3Nam= e of a + * valid node type that can be added as child node
  • + *
+ * + * @test + * @sources NodeOrderableChildNodesTest.java + * @executeClass org.apache.jackrabbit.test.api.NodeOrderableChildNodesTest + * @keywords level2 + */ +public class NodeOrderableChildNodesTest extends AbstractJCRTest { + + /** + * A child Node of {@link #parentNode}. + */ + private Node initialFirstNode; + + /** + * A child Node of {@link #parentNode}. + */ + private Node initialSecondNode; + + /** + * The node that allows orderable child nodes + */ + private Node parentNode; + + /** + * Tries to reorder child nodes using {@link Node#orderBefore(String, = String)} + * with an invalid destination reference.

This should + * throw an {@link ItemNotFoundException}. + */ + public void testOrderBeforeInvalidDest() + throws RepositoryException, NotExecutableException { + checkOrderableNodeType(getProperty("nodetype2")); + prepareTest(); + + // ok lets try to reorder + try { + parentNode.orderBefore(initialSecondNode.getName(), "invalid"); + fail("Trying to reorder child nodes using Node.orderBefore() w= here destination is invalid" + + " should throw ItemNotFoundException!"); + } catch (ItemNotFoundException e) { + // ok + } + } + + /** + * Tries to reorder child nodes using {@link Node#orderBefore(String, + * String)} with an invalid source reference.

This = should throw + * an {@link ItemNotFoundException}. + */ + public void testOrderBeforeInvalidSrc() + throws RepositoryException, NotExecutableException { + checkOrderableNodeType(getProperty("nodetype2")); + prepareTest(); + + // ok lets try to reorder + try { + parentNode.orderBefore("invalid", initialFirstNode.getName()); + fail("Trying to reorder child nodes using Node.orderBefore() w= here source is invalid " + + "should throw ItemNotFoundException!"); + } catch (ItemNotFoundException e) { + // ok + } + } + + /** + * Tries to reorder child nodes using {@link Node#orderBefore(String, + * String)} using same source and destination reference.
=
This + * should throw an {@link ConstraintViolationException}. + */ + public void testOrderBeforeConstraintViolationException() + throws RepositoryException, NotExecutableException { + checkOrderableNodeType(getProperty("nodetype2")); + prepareTest(); + // ok lets try to reorder + try { + parentNode.orderBefore(initialFirstNode.getName(), initialFirs= tNode.getName()); + fail("Trying to reorder child nodes using Node.orderBefore() w= here source and target are same " + + "hould throw ConstraintViolationException!"); + } catch (ConstraintViolationException e) { + // ok + } + } + + /** + * Tries to reorder on a node using {@link Node#orderBefore(String, St= ring)} + * that does not support child reordering.

This should thro= w and + * {@link UnsupportedRepositoryOperationException}. Prequisites:
    + *
  • javax.jcr.tck.NodeOrderableChildNodesTest.testOrderBeforeUnsupp= ortedRepositoryOperationException.nodetype2
  • + * A valid node type that does not suport child node ordering. + *
  • javax.jcr.tck.NodeOrderableChildNodesTest.testOrderBeforeUnsupp= ortedRepositoryOperationException.nodetype3
  • + * A valid node type that can be added as a child.
+ */ + public void testOrderBeforeUnsupportedRepositoryOperationException() + throws RepositoryException, NotExecutableException { + prepareTest(); + + // ok lets try to reorder + try { + parentNode.orderBefore(initialSecondNode.getName(), initialFir= stNode.getName()); + fail("Trying to reorder child nodes using Node.orderBefore() o= n node that " + + "does not support ordering should throw UnsupportedRep= ositoryException!"); + } catch (UnsupportedRepositoryOperationException e) { + // ok + } + } + + + /** + * Creates two child nodes, reorders first node to end, uses parentNod= e's + * {@link Node#save()}. + */ + public void testOrderBeforePlaceAtEndParentSave() + throws RepositoryException, NotExecutableException { + checkOrderableNodeType(getProperty("nodetype2")); + prepareTest(); + + // ok lets reorder and save + parentNode.orderBefore(initialFirstNode.getName(), null); + parentNode.save(); + + // get child node refs + NodeIterator it =3D parentNode.getNodes(); + Node firstNode =3D it.nextNode(); + Node secondNode =3D it.nextNode(); + + // lets see if reordering worked + assertTrue("Child nodes are not added in proper order after Node.o= rderBefore()!", firstNode.isSame(initialSecondNode)); + assertTrue("Child nodes are not added in proper order after Node.o= rderBefore()!", secondNode.isSame(initialFirstNode)); + } + + /** + * Test Creates two child nodes, verifies that they are added propery. + * reorders first node to the end , checks again. uses session.save(); + */ + public void testOrderBeforePlaceAtEndSessionSave() + throws RepositoryException, NotExecutableException { + checkOrderableNodeType(getProperty("nodetype2")); + prepareTest(); + + // ok lets reorder and save + parentNode.orderBefore(initialFirstNode.getName(), null); + superuser.save(); + + // get child node refs + NodeIterator it =3D parentNode.getNodes(); + Node firstNode =3D it.nextNode(); + Node secondNode =3D it.nextNode(); + + // lets see if reordering worked + assertTrue("Child nodes are not added in proper order after Node.o= rderBefore()!", firstNode.isSame(initialSecondNode)); + assertTrue("Child nodes are not added in proper order after Node.o= rderBefore()!", secondNode.isSame(initialFirstNode)); + } + + + /** + * Creates two child nodes, reorders second node before first, uses + * parentNode's {@link Node#save()}. + */ + public void testOrderBeforeSecondToFirstParentSave() + throws RepositoryException, NotExecutableException { + checkOrderableNodeType(getProperty("nodetype2")); + prepareTest(); + + // ok lets reorder and save + parentNode.orderBefore(initialSecondNode.getName(), initialFirstNo= de.getName()); + parentNode.save(); + + // get child node refs + NodeIterator it =3D parentNode.getNodes(); + Node firstNode =3D it.nextNode(); + Node secondNode =3D it.nextNode(); + + // lets see if reordering worked + assertTrue("Child nodes are not added in proper order after Node.o= rderBefore()!", firstNode.isSame(initialSecondNode)); + assertTrue("Child nodes are not added in proper order after Node.o= rderBefore()!", secondNode.isSame(initialFirstNode)); + } + + /** + * Creates two child nodes than reorders second node before first, sav= es + * using {@link Session#save()}. + */ + public void testOrderBeforeSecondToFirstSessionSave() + throws RepositoryException, NotExecutableException { + checkOrderableNodeType(getProperty("nodetype2")); + prepareTest(); + + // ok lets reorder and save + parentNode.orderBefore(initialSecondNode.getName(), initialFirstNo= de.getName()); + superuser.save(); + + // get child node refs + NodeIterator it =3D parentNode.getNodes(); + Node firstNode =3D it.nextNode(); + Node secondNode =3D it.nextNode(); + + // lets see if reordering worked + assertTrue("Child nodes are not added in proper order after Node.o= rderBefore()!", firstNode.isSame(initialSecondNode)); + assertTrue("Child nodes are not added in proper order after Node.o= rderBefore()!", secondNode.isSame(initialFirstNode)); + } + + /** + * Sets up the test content needed for the test cases. + */ + private void prepareTest() throws RepositoryException { + // get root node + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + // create testNode + parentNode =3D defaultRootNode.addNode(nodeName1, getProperty("nod= etype2")); + // add child node + Node firstNode =3D parentNode.addNode(nodeName2, getProperty("node= type3")); + // add a second child node + Node secondNode =3D parentNode.addNode(nodeName3, getProperty("nod= etype3")); + // save the new nodes + superuser.save(); + + // get child node refs + NodeIterator it =3D parentNode.getNodes(); + initialFirstNode =3D it.nextNode(); + initialSecondNode =3D it.nextNode(); + + // first lets test if the nodes have been added in the right order + assertTrue("Child nodes are not added in proper order ", firstNode= .isSame(initialFirstNode)); + assertTrue("Child nodes are not added in proper order ", secondNod= e=2EisSame(initialSecondNode)); + } + + /** + * Checks if the NodeType with name ntName supports order= able + * child nodes. If not a {@link NotExecutableException} is thrown. + * @param ntName the name of the node type. + */ + private void checkOrderableNodeType(String ntName) + throws RepositoryException, NotExecutableException { + NodeType nt =3D superuser.getWorkspace().getNodeTypeManager().getN= odeType(ntName); + if (!nt.hasOrderableChildNodes()) { + throw new NotExecutableException("NodeType: " + ntName + " doe= s not support orderable child nodes."); + } + } +} Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/= api/NodeOrderableChildNodesTest.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/N= odeTest.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/api/NodeTest.java?view=3Dauto&rev=3D155927 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/Node= Test.java (added) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/Node= Test.java Wed Mar 2 08:32:25 2005 @@ -0,0 +1,972 @@ +/* + * Copyright 2004-2005 The Apache Software Foundation or its licensors, + * as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.test.api; + +import org.apache.jackrabbit.test.AbstractJCRTest; + +import javax.jcr.nodetype.ConstraintViolationException; +import javax.jcr.Session; +import javax.jcr.Node; +import javax.jcr.NodeIterator; +import javax.jcr.RepositoryException; +import javax.jcr.NoSuchWorkspaceException; +import javax.jcr.ItemNotFoundException; +import javax.jcr.InvalidItemStateException; +import javax.jcr.ItemExistsException; +import javax.jcr.PathNotFoundException; +import java.util.StringTokenizer; + +/** + * NodeTest contains all test cases for the + * javax.jcr.Node that are related to writing, modifing or de= leting + * nodes (level 2 of the specification). + * + * @test + * @sources NodeTest.java + * @executeClass org.apache.jackrabbit.test.api.NodeTest + * @keywords level2 + */ +public class NodeTest extends AbstractJCRTest { + + private Session superuserW2; + + /** + * to be able to test the update(String) and getCorrespondingNodePath(= String) + * methods we need an addtional workspace + */ + public void setUp() throws Exception { + super.setUp(); + + // login to second workspace + superuserW2 =3D helper.getSuperuserSession(workspaceName); + // create the test root node + Node root =3D superuserW2.getRootNode(); + if (root.hasNode(testPath)) { + // clean test root + Node testNode =3D root.getNode(testPath); + for (NodeIterator children =3D testNode.getNodes(); children.h= asNext();) { + children.nextNode().remove(); + } + } else { + StringTokenizer names =3D new StringTokenizer(testPath, "/"); + Node currentNode =3D superuserW2.getRootNode(); + while (names.hasMoreTokens()) { + currentNode =3D currentNode.addNode(names.nextToken(), tes= tNodeType); + } + } + superuserW2.save(); + } + + /** + * remove all nodes in second workspace and log out + */ + public void tearDown() throws Exception { + try { + // delete all children of test root node + Node rootNodeW2 =3D (Node) superuserW2.getItem(testRootNode.ge= tPath()); + for (NodeIterator children =3D rootNodeW2.getNodes(); children= .hasNext();) { + children.nextNode().remove(); + } + // save changes + superuserW2.save(); + // log out + superuserW2.logout(); + } catch (RepositoryException e) { + log.println("Exception in tearDown: " + e.toString()); + } + + super.tearDown(); + } + + + /** + * Calls {@link javax.jcr.Node#getCorrespondingNodePath(String )} with= a non + * existing workspace.

This should throw an {@link + * javax.jcr.NoSuchWorkspaceException }. + */ + public void testGetCorrespondingNodePathNoSuchWorkspaceException() thr= ows RepositoryException { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create testNode in default workspace + Node defaultTestNode =3D defaultRootNode.addNode(nodeName1, testNo= deType); + + // save changes + superuser.save(); + + try { + defaultTestNode.getCorrespondingNodePath(getNonExistingWorkspa= ceName(superuser)); + fail("Calling Node.getCorrespondingNodePath(workspace) with in= valid workspace should throw NoSuchWorkspaceException"); + } catch (NoSuchWorkspaceException e) { + // ok, works as expected + } + } + + + /** + * Calls {@link javax.jcr.Node#getCorrespondingNodePath(String)} on a= node + * that has no corresponding node in second workspace + */ + public void testGetCorrespondingNodePathItemNotFoundException() throws= RepositoryException { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create testNode in default workspace + Node defaultTestNode =3D defaultRootNode.addNode(nodeName1, testNo= deType); + + // save changes + superuser.save(); + + try { + // call the update method on test node in default workspace + defaultTestNode.getCorrespondingNodePath(workspaceName); + fail("Calling Node.getCorrespondingNodePath() on node that has= no correspondend node should throw ItemNotFoundException"); + } catch (ItemNotFoundException e) { + // ok, works as expected + } + } + + /** + * Creates a node with same path in both workspaces to check if {@link + * javax.jcr.Node#getCorrespondingNodePath(String)} works properly. + */ + public void testGetCorrespondingNodePath() throws RepositoryException { + + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create test node in default workspace + Node defaultTestNode =3D defaultRootNode.addNode(nodeName1, testNo= deType); + + // save changes + superuser.save(); + + // get the root node in the second workspace + Node rootNodeW2 =3D (Node) superuserW2.getItem(testRootNode.getPat= h()); + + // create test node in second workspace + rootNodeW2.addNode(nodeName1, testNodeType); + + // save changes + superuserW2.save(); + + // call the update method on test node in default workspace + defaultTestNode.getCorrespondingNodePath(workspaceName); + + // ok, works as expected + } + + /** + * Tries calling {@link javax.jcr.Node#update(String)} after node has + * changed in first workspace but not been saved yet.

This = should + * throw and {@link javax.jcr.InvalidItemStateException}.

+ * Prerequisites:
  • javax.jcr.tck.propertyname1 na= me of + * a String property that can be modified in javax.jcr.tck.nodet= ype + * for testing
+ */ + public void testUpdateInvalidItemStateException() throws RepositoryExc= eption { + + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create a test node in default workspace + Node testNode =3D defaultRootNode.addNode(nodeName1, testNodeType); + + // save changes + superuser.save(); + + // get the root node in the second workspace + Node rootNodeW2 =3D (Node) superuserW2.getItem(testRootNode.getPat= h()); + + // create test node in second workspace + rootNodeW2.addNode(nodeName1); + + // save changes + superuserW2.save(); + + // modify the node + testNode.setProperty(propertyName1, "test"); + + try { + // try calling update + testNode.update(workspaceName); + fail("Calling Node.update() on modified node should throw Inva= lidItemStateException"); + } catch (InvalidItemStateException e) { + // ok , works as expected + } + } + + /** + * Tries to use {@link javax.jcr.Node#update(String)} with an invalid + * workspace.

This should throw an {@link + * javax.jcr.NoSuchWorkspaceException}. + */ + public void testUpdateNoSuchWorkspaceException() throws RepositoryExce= ption { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create a test node in default workspace + Node testNode =3D defaultRootNode.addNode(nodeName1, testNodeType); + + // save changes + superuser.save(); + + try { + testNode.update(getNonExistingWorkspaceName(superuser)); + fail("Calling Node.update() on a non existing workspace should= throw NoSuchWorkspaceException"); + } catch (NoSuchWorkspaceException e) { + // ok, works as expected + } + } + + /** + * Calls {@link javax.jcr.Node#update(String)} for a node that only ex= ists + * in current workspace.

In that case nothing should happen. + *

Prerequisites:
  • javax.jcr.tck.propertyname1= + * name of a String property that can be modified in + * javax.jcr.tck.nodetype for testing
+ */ + public void testUpdateNoClone() throws RepositoryException { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create a test node in default workspace + Node testNode =3D defaultRootNode.addNode(nodeName1, testNodeType); + + // modify the node + testNode.setProperty(propertyName1, "test"); + + superuser.save(); + + // call the update method on test node in default workspace + testNode.update(workspaceName); + + // check if property is still there + assertTrue("Node got property removed after Node.update() eventhou= gh node has no clone", testNode.hasProperty(propertyName1)); + // check if node did not get childs suddenly + assertFalse("Node has children assigned after Node.update() eventh= ough node has no clone", testNode.hasNodes()); + } + + + /** + * Checks if {@link javax.jcr.Node#update(String)} works properly by + * creating the same node in two workspaces one with a child node the = other + * with a property set.

Calling update() on th= e node + * with properties, should remove the properties and add the child nod= e=2E + *

Prerequisites:
  • javax.jcr.tck.nodetype + * must allow children of same nodetype.
  • javax.jcr.tck.prope= rtyname1 + * name of a String property that can be modified in + * javax.jcr.tck.nodetype for testing
+ */ + public void testUpdate() throws RepositoryException { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create test node in default workspace + Node defaultTestNode =3D defaultRootNode.addNode(nodeName1, testNo= deType); + + defaultTestNode.setProperty(propertyName1, "test"); + + // save changes + superuser.save(); + + // get the root node in the second workspace + Node rootNodeW2 =3D (Node) superuserW2.getItem(testRootNode.getPat= h()); + + // create test node in second workspace + Node testNodeW2 =3D rootNodeW2.addNode(nodeName1, testNodeType); + + // add a child node + testNodeW2.addNode(nodeName2, testNodeType); + + // save changes + superuserW2.save(); + + // call the update method on test node in default workspace + defaultTestNode.update(workspaceName); + + // ok first check if node has no longer propertis + assertFalse("Node updated with Node.update() should have property = removed", defaultTestNode.hasProperty(propertyName1)); + // ok check if the child has been added + assertTrue("Node updated with Node.update() should have received c= hildrens", defaultTestNode.hasNode(nodeName1)); + } + + /** + * Tries to add a node using {@link javax.jcr.Node#addNode(String)} wh= ere + * node type can not be determined by parent (nt:base is = used + * as parent nodetype).

This should throw a {@link + * javax.jcr.nodetype.ConstraintViolationException}. + */ + public void testAddNodeConstraintViolationExceptionUndefinedNodeType()= throws RepositoryException { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + Node defaultTestNode =3D defaultRootNode.addNode(nodeName1, ntBase= ); + + try { + defaultTestNode.addNode(nodeName2); + fail("Adding a node with node.addNode(node) where nodetype can= not be determined from parent should" + + " throw ConstraintViolationException"); + } catch (ConstraintViolationException e) { + // ok, works as expected + } + } + + /** + * Tries to add a node using {@link javax.jcr.Node#addNode(String)} as= a + * child of a property.

This should throw an {@link + * javax.jcr.nodetype.ConstraintViolationException}. + *

Prerequisites:
  • javax.jcr.tck.propertyname1= + * name of a String property that can be set in javax.jcr.tck.no= detype + * for testing
+ */ + public void testAddNodeConstraintViolationExceptionProperty() throws R= epositoryException { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // add a node + Node defaultTestNode =3D defaultRootNode.addNode(nodeName1, testNo= deType); + + // set a property + defaultTestNode.setProperty(propertyName1, "test"); + + try { + // try to add a node as a child of a property + defaultTestNode.addNode(propertyName1 + "/" + nodeName2); + fail("Adding a node as a child of a property should throw Cons= traintViolationException"); + } catch (ConstraintViolationException e) { + // ok, works as expected + } + } + + /** + * Tries to create a node using {@link javax.jcr.Node#addNode(String, + * String)} at a location where there is already a node with s= ame name and + * the parent does not allow same name siblings.

This should + * throw an {@link javax.jcr.ItemExistsException }.

Prerequi= sites: + *
  • javax.jcr.tck.NodeTest.testAddNodeItemExistsExceptio= n=2Enodetype + * node type that does not allow same name siblings and allows to add = child + * nodes of the same type.
+ */ + public void testAddNodeItemExistsException() throws RepositoryExceptio= n { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // add a node + Node defaultTestNode =3D defaultRootNode.addNode(nodeName2, testNo= deType); + // add a child + defaultTestNode.addNode(nodeName3, testNodeType); + + // save the new node + defaultRootNode.save(); + + try { + // try to add a node with same name again + defaultTestNode.addNode(nodeName3, testNodeType); + fail("Adding a node to a location where same name siblings are= not allowed, but a node with same name" + + " already exists should throw ItemExistsException "); + } catch (ItemExistsException e) { + //ok, works as expected + } + } + + /** + * Tries to add a node using {@link javax.jcr.Node#addNode(String)} to= a non + * existing destination node.

This should throw an {@link + * javax.jcr.PathNotFoundException}. + */ + public void testAddNodePathNotFoundException() throws RepositoryExcept= ion { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + try { + // use invalid parent path + defaultRootNode.addNode(nodeName1 + "/" + nodeName2); + fail("Creating a node at a non existent destination should thr= ow PathNotFoundException"); + } catch (PathNotFoundException e) { + // ok, works as expected + } + } + + /** + * Adds a new node using {@link javax.jcr.Node#addNode(String)} with an + * index for the new name.

This should throw an {@link + * RepositoryException}. + */ + public void testAddNodeRepositoryExceptionRelPathIndex() throws Reposi= toryException { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + try { + // use invalid relPath + defaultRootNode.addNode(nodeName1 + "[1]", testNodeType); + fail("Creating a node with index as postfix for new name shoul= d throw RepositoryException"); + } catch (RepositoryException e) { + // ok, works as expected + } + } + + /** + * Creates a new node using {@link Node#addNode(String)}, then tries t= o call + * {@link javax.jcr.Node#save()} on the newly node.

This sh= ould + * throw an {@link RepositoryException}. + */ + public void testAddNodeRepositoryExceptionSaveOnNewNode() throws Repos= itoryException { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // add a node + Node testNode =3D defaultRootNode.addNode(nodeName1, testNodeType); + + try { + // try to call save on newly created node + testNode.save(); + fail("Calling Node.save() on a newly created node should throw= RepositoryException"); + } catch (RepositoryException e) { + // ok, works as expected. + } + } + + /** + * Creates a new node using {@link Node#addNode(String)} , saves using + * {@link javax.jcr.Node#save()} on parent node. Uses a second session= to + * verify if the node has been safed. + */ + public void testAddNodeParentSave() throws RepositoryException { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // add a node + Node testNode =3D defaultRootNode.addNode(nodeName1, testNodeType); + + // save new nodes + defaultRootNode.save(); + + // use a different session to verify if the node is there + Session session =3D helper.getReadOnlySession(); + try { + testNode =3D (Node) session.getItem(testNode.getPath()); + } finally { + session.logout(); + } + } + + /** + * Creates a new node using {@link Node#addNode(String)} , saves using + * {@link javax.jcr.Session#save()}. Uses a second session to verify i= f the + * node has been safed. + */ + public void testAddNodeSessionSave() throws RepositoryException { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // add a node + Node testNode =3D defaultRootNode.addNode(nodeName1, testNodeType); + + // save new nodes + superuser.save(); + + // use a different session to verify if the node is there + Session session =3D helper.getReadOnlySession(); + try { + testNode =3D (Node) session.getItem(testNode.getPath()); + } finally { + session.logout(); + } + } + + /** + * Creates a node with a mandatory child node using {@link + * Node#addNode(String, String)}, saves on parent node then tries to d= elete + * the mandatory child node.

This should throw a {@link + * ConstraintViolationException}.

Prerequisites:
    + *
  • javax.jcr.tck.NodeTest.testRemoveMandatoryNode.nodetype2<= /code> + * a node type that has a mandatory child node
  • javax.jc= r=2Etck.NodeTest.testRemoveMandatoryNode.nodetype3 + * nodetype of the mandatory child node
  • javax.jcr.tck.N= odeTest.testRemoveMandatoryNode.nodename3 + * name of the mandatory child node
+ */ + public void testRemoveMandatoryNode() throws RepositoryException { + + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create the node with the mandatory child node definition + Node defaultTestNode =3D defaultRootNode.addNode(nodeName2, getPro= perty("nodetype2")); + + // add the mandatory child node + Node defaultTestNodeChild =3D defaultTestNode.addNode(nodeName3, g= etProperty("nodetype3")); + + // save changes + defaultRootNode.save(); + + try { + // try to remove the mandatory node + defaultTestNodeChild.remove(); + + defaultTestNode.save(); + fail("Removing a mandatory node should throw a ConstraintViola= tionException"); + } catch (ConstraintViolationException e) { + // ok, works as expected + } + } + + /** + * Removes a node using {@link javax.jcr.Node#remove()} with session 1, + * afterwards it tries the same with session 2.

This should= throw + * an {@link InvalidItemStateException}. + */ + public void testRemoveInvalidItemStateException() throws RepositoryExc= eption { + + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create the node + Node defaultTestNode =3D defaultRootNode.addNode(nodeName1, testNo= deType); + + // save the nodes + superuser.save(); + + // get the node with session 2 + Session testSession =3D helper.getReadWriteSession(); + Node defaultTestNodeSession2 =3D (Node) testSession.getItem(defaul= tTestNode.getPath()); + + // remove node with session 1 + defaultTestNode.remove(); + superuser.save(); + + // try to remove already deleted node with session 2 + try { + defaultTestNodeSession2.remove(); + fail("Removing a node already deleted by other session should = throw an InvalidItemStateException!"); + } catch (InvalidItemStateException e) { + //ok, works as expected + } + testSession.logout(); + } + + /** + * Removes a node using {@link javax.jcr.Node#remove()}, then saves wi= th + * parent's nodes {@link javax.jcr.Node#save()} method. + */ + public void testRemoveNodeParentSave() throws RepositoryException { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create the node + Node defaultTestNode =3D defaultRootNode.addNode(nodeName1, testNo= deType); + + // save the nodes + defaultRootNode.save(); + + // remove them + defaultTestNode.remove(); + + defaultRootNode.save(); + + // check if the node has been properly removed + try { + defaultRootNode.getNode(nodeName1); + fail("Permanently removed node should no longer be adressable = using Parent Node's getNode() method"); + } catch (PathNotFoundException e) { + // ok , works as expected + } + } + + + /** + * Removes a node using {@link javax.jcr.Node#remove()}, then saves us= ing + * {@link javax.jcr.Session#save()} method. + */ + public void testRemoveNodeSessionSave() throws RepositoryException { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create the node + Node defaultTestNode =3D defaultRootNode.addNode(nodeName1, testNo= deType); + + // save the nodes + superuser.save(); + + // remove them + defaultTestNode.remove(); + + superuser.save(); + + // check if the node has been properly removed + try { + superuser.getItem(defaultRootNode.getPath() + "/" + nodeName1); + fail("Permanently removed node should no longer be adressable = using Session.getItem()"); + } catch (PathNotFoundException e) { + // ok, works as expected + } + } + + + /** + * Tests object identity, meaning two nodes objects accuired through t= he + * same session must have the same properties and states.

+ * Prerequisites:
  • javax.jcr.tck.nodetype must al= low + * children of same node type
  • javax.jcr.tck.propertynam= e1 + * name of a String property that can be set in javax.jcr.tck.no= detype + * for testing
+ */ + public void testNodeIdentity() throws RepositoryException { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create a node + Node testNode1 =3D defaultRootNode.addNode(nodeName1, testNodeType= ); + // add a child node + testNode1.addNode(nodeName1, testNodeType); + // add a property + testNode1.setProperty(propertyName1, "test"); + + // save the new node + defaultRootNode.save(); + + // accuire the same node with session 2 + Node testNode2 =3D (Node) superuser.getItem(testNode1.getPath()); + + // check if they have the same property + assertEquals("Two references of same node have different propertie= s", testNode1.getProperty(propertyName1), testNode2.getProperty(propertyNam= e1)); + // check if they have the same child + assertEquals("Two references of same node have different children"= , testNode1.getNode(nodeName1), testNode2.getNode(nodeName1)); + // check state methods + assertEquals("Two references of same node have different State for= Node.isCheckedOut()", testNode1.isCheckedOut(), testNode2.isCheckedOut()); + assertEquals("Two references of same node have different State for= Node.isLocked()", testNode1.isLocked(), testNode2.isLocked()); + assertEquals("Two references of same node have different State for= Node.isModified()", testNode1.isModified(), testNode2.isModified()); + assertEquals("Two references of same node have different State for= Node.isNew()", testNode1.isNew(), testNode2.isNew()); + assertEquals("Two references of same node have different State for= Node.isNode()", testNode1.isNode(), testNode2.isNode()); + assertEquals("Two references of same node have different State for= Node.isNodeType()", testNode1.isNodeType(testNodeType), testNode2.isNodeTy= pe(testNodeType)); + assertTrue("Two references of same node should return true for Nod= e1.isSame(Node2)", testNode1.isSame(testNode2)); + assertEquals("Two references of same node have different Definitio= ns", testNode1.getDefinition(), testNode2.getDefinition()); + } + + /** + * Checks if {@link Node#isModified()} works correcty for unmodified a= nd + * modified nodes. + */ + public void testIsModified() throws RepositoryException { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create a node + Node testNode =3D defaultRootNode.addNode(nodeName1, testNodeType); + + defaultRootNode.save(); + + assertFalse("Unmodified node should return false on Node.isModifie= d()", testNode.isModified()); + + // check if modified properties are recognised + testNode.setProperty(propertyName1, "test"); + + assertTrue("Modified node should return true on Node.isModified()"= , testNode.isModified()); + + defaultRootNode.save(); + + // check if modified child nodes are recognised + testNode.addNode(nodeName2, testNodeType); + + assertTrue("Modified node should return true on Node.isModified()"= , testNode.isModified()); + + } + + /** + * Checks if {@link Node#isNew()} works correctly for new and existing, + * unmodified nodes. + */ + public void testIsNew() throws RepositoryException { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create a node + Node testNode =3D defaultRootNode.addNode(nodeName1, testNodeType); + + assertTrue("Newly created node should return true on newNode.isNew= ()", testNode.isNew()); + + defaultRootNode.save(); + + assertFalse("Unmodified, exisiting node should return false on new= Node.isNew()", testNode.isNew()); + + } + + /** + * Tries to call {@link Node#refresh(boolean)} on a deleted node. + *

This should throw an {@link InvalidItemStateException}. + */ + public void testRefreshInvalidItemStateException() throws RepositoryEx= ception { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create a node + Node testNode =3D defaultRootNode.addNode(nodeName1, testNodeType); + + // save the new node + defaultRootNode.save(); + + // remove the node + defaultRootNode.remove(); + + try { + testNode.refresh(true); + fail("Calling Node.refresh() on deleted node should throw Inva= lidItemStateException!"); + } catch (InvalidItemStateException e) { + // ok, works as expected + } + } + + /** + * Moves an unreferencable node with one session and saves the same no= de + * using a different session at same time.

Procedure:
    + *
  • Creates node 1 and node 2 with session 1
  • Gets referenc= e to + * node 1 using session 2
  • session 1 moves node 1 under node 2= , + * saves using parent nodes {@link Node#save()}
  • session 2 mod= ifies + * node 1 by adding a child node, saves using Node.save()
  • + *
Should throw {@link javax.jcr.InvalidItemStateException} since + * saving an unreferencable node that has been moved by and other sess= ion is + * not possible.

Prerequisites:
  • javax.jcr.tck= .nodetype + * must accept children of same nodetype and it must not be + * referencable
+ */ + public void testSaveMovedNotRefNode() throws RepositoryException { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create non referenciable node to be moved with session 1 + Node testNodeSession1 =3D defaultRootNode.addNode(nodeName1, testN= odeType); + + // create a second node with session 1 that will serve as new pare= nt + Node newParentNodeSession1 =3D defaultRootNode.addNode(nodeName2, = testNodeType); + + // save the new nodes + defaultRootNode.save(); + + // get the moving node with session 2 + Session testSession =3D helper.getReadWriteSession(); + Node testNodeSession2 =3D (Node) testSession.getItem(testNodeSessi= on1.getPath()); + + //move the node with session 1 + superuser.move(testNodeSession1.getPath(), newParentNodeSession1.g= etPath() + "/testNewName"); + + // make the move persistent with session 1 + defaultRootNode.save(); + + // add a child to the node with session + testNodeSession2.addNode(nodeName3, testNodeType); + + // save it + try { + defaultRootNode.save(); + fail("Saving a unreferencedable Node that has been moved by ot= her session should throw InvalidItemStateException"); + } catch (InvalidItemStateException e) { + // ok, works as expected + } + } + + /** + * Checks if {@link javax.jcr.Node#refresh(boolean refresh)} works pro= perly + * with refresh set to false.

+ * Procedure:
  • Creates two nodes with session 1
  • Modif= ies + * node 1 with session 1 by adding a child node
  • Get node 2 wi= th + * session 2
  • Modifies node 2 with session 2 by adding a child + * node
  • saves session 2 changes using {@link + * javax.jcr.Node#save()}
  • calls Node.refresh(false) + * on root node in session 1
Session 1 changes should be cl= eared + * and session 2 changes should now be visible to session 1. + *

Prerequisites:
  • javax.jcr.tck.nodetype + * must accept children of same nodetype
+ */ + public void testRefreshBooleanFalse() throws RepositoryException { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create a node + Node testNode1Session1 =3D defaultRootNode.addNode(nodeName1, test= NodeType); + // create a second node + Node testNode2Session1 =3D defaultRootNode.addNode(nodeName2, test= NodeType); + + // save the new nodes + defaultRootNode.save(); + + // add child node to test node 1 using session 1 + testNode1Session1.addNode(nodeName2, testNodeType); + + // get session 2 + Session session2 =3D helper.getReadWriteSession(); + + // get the second node + Node testNode2Session2 =3D (Node) session2.getItem(testNode2Sessio= n1.getPath()); + + // adds a child node + testNode2Session2.addNode(nodeName3, testNodeType); + + // save the changes + session2.save(); + + // call refresh on session 1 + defaultRootNode.refresh(false); + + // check if session 1 flag has been cleared + assertFalse("Session should have no pending changes recorded after= Node.refresh(false)!", superuser.hasPendingChanges()); + + // check if added child node for node 1 by session 1 has been remo= ved + assertFalse("Node Modifications have not been flushed after Node.r= efresh(false)", testNode1Session1.hasNodes()); + + // check if added child node for node 2 by session 2 has become vi= sible in session 1 + assertTrue("Node modified by a different session has not been upda= ted after Node.refresh(false)", testNode2Session1.hasNodes()); + } + + /** + * Checks if {@link javax.jcr.Node#refresh(boolean refresh)} works pro= perly + * with refresh set to true.

+ * Procedure:
  • Creates two nodes with session 1
  • Modif= ies + * node 1 with session 1 by adding a child node
  • Get node 2 wi= th + * session 2
  • Modifies node 2 with session 2 by adding a child + * node
  • saves session 2 changes using {@link + * javax.jcr.Node#save()}
  • calls Node.refresh(true) on + * root node in session 1
Session 1 changes and session 2 + * changes now be visible to session 1.

Prerequisites:
    + *
  • javax.jcr.tck.nodetype must accept children of same + * nodetype
+ */ + public void testRefreshBooleanTrue() throws RepositoryException { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create a node + Node testNode1Session1 =3D defaultRootNode.addNode(nodeName1, test= NodeType); + // create a second node + Node testNode2Session1 =3D defaultRootNode.addNode(nodeName2, test= NodeType); + + // save the new nodes + defaultRootNode.save(); + + // add child node to test node 1 using session 1 + testNode1Session1.addNode(nodeName2, testNodeType); + + // get session 2 + Session session2 =3D helper.getReadWriteSession(); + + // get the second node + Node testNode2Session2 =3D (Node) session2.getItem(testNode2Sessio= n1.getPath()); + + // adds a child node + testNode2Session2.addNode(nodeName3, testNodeType); + + // save the changes + session2.save(); + + // call refresh on session 1 + defaultRootNode.refresh(true); + + // check if session 1 flag has been cleared + assertTrue("Session should still have pending changes recorded aft= er Node.refresh(true)!", superuser.hasPendingChanges()); + + // check if added child node for node 1 by session 1 is still there + assertTrue("Node Modifications are lost after Node.refresh(true)",= testNode1Session1.hasNodes()); + + // check if added child node for node 2 by session 2 has become vi= sible in session 1 + assertTrue("Node modified by a different session has not been upda= ted after Node.refresh(true)", testNode2Session1.hasNodes()); + } + + /** + * Tries to save a node using {@link javax.jcr.Node#save()} that was a= lready + * deleted by an other session.

Procedure:
  • Creates= a new + * node with session 1, saves it, adds a child node.
  • Access n= ew + * node with session 2,deletes the node, saves it.
  • Session 1 = tries + * to save modifications using Node.save() on root node .=
  • + *
This should throw an {@link javax.jcr.InvalidItemStateExcepti= on}. + *

Prerequisites:
  • javax.jcr.tck.nodetype + * must accept children of same nodetype
+ */ + public void testSaveInvalidStateException() throws RepositoryException= { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create a node + Node nodeSession1 =3D defaultRootNode.addNode(nodeName1, testNodeT= ype); + + // save new node + superuser.save(); + + // make a modification + nodeSession1.addNode(nodeName2, testNodeType); + + // get the new node with a different session + Session testSession =3D helper.getReadWriteSession(); + Node nodeSession2 =3D (Node) testSession.getItem(nodeSession1.getP= ath()); + + // delete the node with the new session + nodeSession2.remove(); + + // make node removal persistent + testSession.save(); + + // save changes made wit superuser session + try { + defaultRootNode.save(); + fail("Saving a modified Node using Node.save() already deleted= by an other session should throw InvalidItemStateException"); + } catch (InvalidItemStateException e) { + // ok, works as expected + } + } + + /** + * Tries to create and save a node using {@link javax.jcr.Node#save()}= with + * an mandatory property that is not set on saving time. + *

+ * Prerequisites:

  • javax.jcr.tck.Node.testSaveContstrain= tViolationException.nodetype2 + * must reference a nodetype that has at least one property that is + * mandatory but not autocreated
+ */ + public void testSaveContstraintViolationException() throws RepositoryE= xception { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create a node with at least one mandatory, not autocreated prop= erty + defaultRootNode.addNode(nodeName1, this.getProperty("nodetype2")); + + // save changes + try { + superuser.save(); + fail("Trying to use parent Node.save() with a node that has a = mandatory property not set, should throw ConstraintViolationException"); + } catch (ConstraintViolationException e) { + // ok + } + } + + + /** + * Creates a new node, saves it uses second session to verify if node = has + * been added. + */ + public void testNodeSave() throws RepositoryException { + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create a node + Node testNode =3D defaultRootNode.addNode(nodeName1, testNodeType); + + // save new node + defaultRootNode.save(); + + // get the new node with a different session + Session testSession =3D helper.getReadOnlySession(); + testSession.getItem(testNode.getPath()); + testSession.logout(); + } +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/= api/NodeTest.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/N= odeUUIDTest.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/= apache/jackrabbit/test/api/NodeUUIDTest.java?view=3Dauto&rev=3D155927 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/Node= UUIDTest.java (added) +++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/Node= UUIDTest.java Wed Mar 2 08:32:25 2005 @@ -0,0 +1,205 @@ +/* + * Copyright 2004-2005 The Apache Software Foundation or its licensors, + * as applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.test.api; + +import org.apache.jackrabbit.test.AbstractJCRTest; +import org.apache.jackrabbit.test.NotExecutableException; + +import javax.jcr.RepositoryException; +import javax.jcr.Node; +import javax.jcr.Session; +import javax.jcr.ReferentialIntegrityException; +import javax.jcr.InvalidItemStateException; +import javax.jcr.nodetype.NoSuchNodeTypeException; + +/** + * NodeUUIDTest contains all tests for the + * javax.jcr.Node class that require a UUID (and therefore are + * optional). If the repository does not support the node type mix:referen= ceable + * a {@link NotExecutableException} is thrown. + * + * @test + * @sources NodeUUIDTest.java + * @executeClass org.apache.jackrabbit.test.api.NodeUUIDTest + * @keywords level2 + */ +public class NodeUUIDTest extends AbstractJCRTest { + + /** + * Tries to remove a node that is a reference target using {@link + * Node#save()}.

Procedure:
  • Creates two nodes with sa= me + * session
  • One has a referencing property pointing to the oth= er + * node
  • Target node gets removed.
This shou= ld + * generate a {@link javax.jcr.ReferentialIntegrityException} upon sav= e=2E + *

Prerequisites:
  • javax.jcr.tck.NodeUUIDTest.no= detype + * must allow a property of type {@link javax.jcr.PropertyType#REFEREN= CE}
  • + *
  • javax.jcr.tck.NodeUUIDTest.propertyname1 name of t= he + * property of type {@link javax.jcr.PropertyType#REFERENCE}
  • + *
  • javax.jcr.tck.NodeUUIDTest.nodetype2 must have the= mixin + * type mix:referenceable assigned.
+ */ + public void testSaveReferentialIntegrityException() throws RepositoryE= xception, NotExecutableException { + checkMixReferenceable(); + + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create a node with a property of type PropertyType.REFERENCE + Node referencingNode =3D defaultRootNode.addNode(nodeName1, testNo= deType); + + // create a node with a jcr:uuid property to serve as target + Node refTargetNode =3D defaultRootNode.addNode(nodeName2, getPrope= rty("nodetype2")); + + // set the reference + referencingNode.setProperty(propertyName1, refTargetNode); + + // save the new nodes + defaultRootNode.save(); + + // remove the referenced node + refTargetNode.remove(); + + // try to save + try { + defaultRootNode.save(); + fail("Saving a deleted node using Node.save() that is a refere= nce target should throw ReferentialIntegrityException"); + } catch (ReferentialIntegrityException e) { + // ok, works as expected + } + } + + /** + * Moves a referencable node using {@link javax.jcr.Session#move(Strin= g, + * String)} with one session and saves afterward changes made w= ith a second + * session to the moved node using {@link Node#save()}.

+ * Procedure:
  • Creates node 1 and node 2 with session 1
  • + *
  • Gets reference to node 1 using session 2
  • Session 1 mov= es + * node 1 under node 2, saves changes
  • Session 2 modifes node = 1, + * saves
This should work since the modified node is identi= fied + * by its UUID, not by position in repository.

Prerequisites: =
    + *
  • javax.jcr.tck.NodeUUIDTest.nodetype2 must have the= mixin + * type mix:referenceable assigned.
  • + *
  • javax.jcr.tck.NodeUUIDTest.testSaveMovedRefNode.propertyn= ame1 + * name of a property that can be modified in nodetype2 f= or + * testing
+ */ + public void testSaveMovedRefNode() throws RepositoryException, NotExec= utableException { + checkMixReferenceable(); + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create a node + Node newParentNode =3D defaultRootNode.addNode(nodeName1, testNode= Type); + + // create a referenceable node + Node refTargetNode =3D defaultRootNode.addNode(nodeName2, getPrope= rty("nodetype2")); + + // save the new nodes + superuser.save(); + + // get the moving node with session 2 + Session testSession =3D helper.getReadWriteSession(); + Node refTargetNodeSession2 =3D (Node) testSession.getItem(refTarge= tNode.getPath()); + + //move the node with session 1 + superuser.move(refTargetNode.getPath(), newParentNode.getPath() + = "/" + nodeName3); + + // make the move persistent with session 1 + superuser.save(); + + // modify some prop of the moved node with session 2 + refTargetNodeSession2.setProperty(propertyName1, "test"); + + // save it + refTargetNodeSession2.save(); + // ok, works as expected + testSession.logout(); + } + + /** + * Moves a node using {@link javax.jcr.Session#move(String, String)} a= nd + * places a new referenceable node at the source position with = same + * name. A second session tries to save changes made to the moved node= using + * {@link Node#save()}.
Procedure:
  • Create node 1 and no= de 2 + * with session 1
  • Session 2 gets a reference to node 1
  • + *
  • Session 1 moves node 1 under node 2 , saves
  • session 1 = adds + * new referencable node previous position of node 1
  • session 2 + * modifes node, saves
This should fail since the node that + * replaces the moved node is referencable. Should throw {@link + * javax.jcr.InvalidItemStateException}.

Prerequisites:
    + *
  • javax.jcr.tck.nodetype must allow children of + * itself.
  • javax.jcr.tck.propertyname1 name of a + * property that can be modified in javax.jcr.tck.nodetype for + * testing
  • javax.jcr.tck.NodeUUIDTest.nodetype2 = must + * have the mixin type mix:referenceable assigned.
  • <= /ul> + */ + public void testSaveReplacedNotRefNodeByRefNode() throws RepositoryExc= eption, NotExecutableException { + checkMixReferenceable(); + // get default workspace test root node using superuser session + Node defaultRootNode =3D (Node) superuser.getItem(testRootNode.get= Path()); + + // create a node + Node parentNode =3D defaultRootNode.addNode(nodeName1, testNodeTyp= e); + + // create a moving node + Node movingNode =3D defaultRootNode.addNode(nodeName2, testNodeTyp= e); + + // save the new nodes + defaultRootNode.save(); + + // get the moving node with session 2 + Session testSession =3D helper.getReadWriteSession(); + Node movingNodeSession2 =3D (Node) testSession.getItem(movingNode.= getPath()); + + //move the node with session 1 + superuser.move(movingNode.getPath(), parentNode.getPath() + "/" + = nodeName3); + + // repace it it with a referenciable node + parentNode.addNode(nodeName2, getProperty("nodetype2")); + + // make the move and adding of new node persistent with session 1 + defaultRootNode.save(); + + // modify some prop of the moved node + movingNodeSession2.setProperty(propertyName1, "test"); + + // save it + try { + movingNodeSession2.save(); + fail("Saving a unreferenceable Node using Node.save() that has= been moved and replaced by a referenceable node in the meantime should" + + " throw InvalidItemStateException"); + } catch (InvalidItemStateException e) { + // ok, what's expected + } + testSession.logout(); + } + + /** + * Checks if the repository supports the mixin mix:Referenceable other= wise a + * {@link NotExecutableException} is thrown. + * + * @throws NotExecutableException if the repository does not support t= he + * mixin mix:referenceable. + */ + private void checkMixReferenceable() throws RepositoryException, NotEx= ecutableException { + try { + superuser.getWorkspace().getNodeTypeManager().getNodeType(mixR= eferenceable); + } catch (NoSuchNodeTypeException e) { + throw new NotExecutableException("Repository does not support = mix:referenceable"); + } + } +} \ No newline at end of file Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/= api/NodeUUIDTest.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native