⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nodetest.java

📁 jsr170接口的java实现。是个apache的开源项目。
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        defaultRootNode.remove();        try {            testNode.refresh(true);            fail("Calling Node.refresh() on deleted node should throw InvalidItemStateException!");        } catch (InvalidItemStateException e) {            // ok, works as expected        }    }    /**     * Checks if {@link javax.jcr.Node#refresh(boolean refresh)} works properly     * with <code>refresh</code> set to <code>false</code>.<br/> <br/>     * Procedure: <ul> <li>Creates two nodes with session 1</li> <li>Modifies     * node 1 with session 1 by adding a child node</li> <li>Get node 2 with     * session 2</li> <li>Modifies node 2 with session 2 by adding a child     * node</li> <li>saves session 2 changes using {@link     * javax.jcr.Node#save()}</li> <li>calls <code>Node.refresh(false)</code>     * on root node in session 1</li> </ul> Session 1 changes should be cleared     * and session 2 changes should now be visible to session 1.     * <br/><br/>Prerequisites: <ul> <li><code>javax.jcr.tck.nodetype</code>     * must accept children of same nodetype</li> </ul>     */    public void testRefreshBooleanFalse() throws RepositoryException {        // get default workspace test root node using superuser session        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());        // create a node        Node testNode1Session1 = defaultRootNode.addNode(nodeName1, testNodeType);        // create a second node        Node testNode2Session1 = defaultRootNode.addNode(nodeName2, testNodeType);        // 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 = helper.getReadWriteSession();        try {            // get the second node            Node testNode2Session2 = (Node) session2.getItem(testNode2Session1.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 removed            assertFalse("Node Modifications have not been flushed after Node.refresh(false)", testNode1Session1.hasNodes());            // check if added child node for node 2 by session 2 has become visible in session 1            assertTrue("Node modified by a different session has not been updated after Node.refresh(false)", testNode2Session1.hasNodes());        } finally {            session2.logout();        }    }    /**     * Checks if {@link javax.jcr.Node#refresh(boolean refresh)} works properly     * with <code>refresh</code> set to <code>true</code>.<br/> <br/>     * Procedure: <ul> <li>Creates two nodes with session 1</li> <li>Modifies     * node 1 with session 1 by adding a child node</li> <li>Get node 2 with     * session 2</li> <li>Modifies node 2 with session 2 by adding a child     * node</li> <li>saves session 2 changes using {@link     * javax.jcr.Node#save()}</li> <li>calls <code>Node.refresh(true)</code> on     * root node in session 1</li> </ul> Session 1 changes and session 2     * changes now be visible to session 1. <br/><br/>Prerequisites: <ul>     * <li><code>javax.jcr.tck.nodetype</code> must accept children of same     * nodetype</li> </ul>     */    public void testRefreshBooleanTrue() throws RepositoryException {        // get default workspace test root node using superuser session        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());        // create a node        Node testNode1Session1 = defaultRootNode.addNode(nodeName1, testNodeType);        // create a second node        Node testNode2Session1 = defaultRootNode.addNode(nodeName2, testNodeType);        // 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 = helper.getReadWriteSession();        try {            // get the second node            Node testNode2Session2 = (Node) session2.getItem(testNode2Session1.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 after 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 visible in session 1            assertTrue("Node modified by a different session has not been updated after Node.refresh(true)", testNode2Session1.hasNodes());        } finally {            session2.logout();        }    }    /**     * Tries to save a node using {@link javax.jcr.Node#save()} that was already     * deleted by an other session.<br/> <br/> Procedure: <ul> <li>Creates a new     * node with session 1, saves it, adds a child node.</li> <li>Access new     * node with session 2,deletes the node, saves it.</li> <li>Session 1 tries     * to save modifications using <code>Node.save()</code> on root node .</li>     * </ul> This should throw an {@link javax.jcr.InvalidItemStateException}.     * <br/><br/>Prerequisites: <ul> <li><code>javax.jcr.tck.nodetype</code>     * must accept children of same nodetype</li> </ul>     */    public void testSaveInvalidStateException() throws RepositoryException {        // get default workspace test root node using superuser session        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());        // create a node        Node nodeSession1 = defaultRootNode.addNode(nodeName1, testNodeType);        // save new node        superuser.save();        // make a modification        nodeSession1.addNode(nodeName2, testNodeType);        // get the new node with a different session        Session testSession = helper.getReadWriteSession();        try {            Node nodeSession2 = (Node) testSession.getItem(nodeSession1.getPath());            // 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            }        } finally {            testSession.logout();        }    }    /**     * Tries to create and save a node using {@link javax.jcr.Node#save()} with     * an mandatory property that is not set on saving time.     * <p/>     * Prerequisites: <ul> <li><code>javax.jcr.tck.Node.testSaveContstraintViolationException.nodetype2</code>     * must reference a nodetype that has at least one property that is     * mandatory but not autocreated</li> </ul>     */    public void testSaveContstraintViolationException() throws RepositoryException {        // get default workspace test root node using superuser session        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());        // create a node with at least one mandatory, not autocreated property        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 = (Node) superuser.getItem(testRootNode.getPath());        // create a node        Node testNode = defaultRootNode.addNode(nodeName1, testNodeType);        // save new node        defaultRootNode.save();        // get the new node with a different session        Session testSession = helper.getReadOnlySession();        try {            testSession.getItem(testNode.getPath());        } finally {            testSession.logout();        }    }    /**     * Tests if a {@link javax.jcr.RepositoryException} is thrown when calling     * <code>Node.save()</code> on a newly added node     */    public void testSaveOnNewNodeRepositoryException() throws Exception {        // get default workspace test root node using superuser session        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());        // create a node        Node newNode = defaultRootNode.addNode(nodeName1, testNodeType);        try {            newNode.save();            fail("Calling Node.save() on a newly added node should throw a RepositoryException");        } catch (RepositoryException success) {            // ok        }    }    /**     * Tests if the primary node type is properly stored in jcr:primaryType     */    public void testPrimaryType() throws Exception {        // get default workspace test root node using superuser session        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());        Node testNode = defaultRootNode.addNode(nodeName1, testNodeType);        assertEquals("The primary node type is not properly stored in jcr:primaryType",testNodeType,testNode.getProperty(jcrPrimaryType).getString());    }    /**     * Tests if jcr:primaryType is protected     */    public void testPrimaryTypeProtected() throws Exception {        // get default workspace test root node using superuser session        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());        Node testNode = defaultRootNode.addNode(nodeName1, testNodeType);        try {            testNode.setProperty(jcrPrimaryType,ntBase);            fail("Manually setting jcr:primaryType should throw a ConstraintViolationException");        }        catch (ConstraintViolationException success) {            // ok        }    }    /**     * Tests if jcr:mixinTypes is protected     */    public void testMixinTypesProtected() throws Exception {        // get default workspace test root node using superuser session        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());        Node testNode = defaultRootNode.addNode(nodeName1, testNodeType);        Value mixinName = superuser.getValueFactory().createValue(mixLockable, PropertyType.NAME);        try {            testNode.setProperty(jcrMixinTypes, new Value[]{mixinName});            fail("Manually setting jcr:mixinTypes should throw a ConstraintViolationException");        }        catch (ConstraintViolationException success) {            // ok        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -