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

📄 nodetest.java

📁 jsr170接口的java实现。是个apache的开源项目。
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        // create test node in second workspace        Node testNodeW2 = 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 childrens", defaultTestNode.hasNode(nodeName2));    }    /**     * Tries to add a node using {@link javax.jcr.Node#addNode(String)} where     * node type can not be determined by parent (<code>nt:base</code> is used     * as parent nodetype). <br/><br/> 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 = (Node) superuser.getItem(testRootNode.getPath());        String nodetype = testNodeTypeNoChildren == null ? ntBase : testNodeTypeNoChildren;        Node defaultTestNode = defaultRootNode.addNode(nodeName1, nodetype);        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.<br/> <br/> This should throw an {@link     * javax.jcr.nodetype.ConstraintViolationException}.     * <br/><br/>Prerequisites: <ul> <li><code>javax.jcr.tck.propertyname1</code>     * name of a String property that can be set in <code>javax.jcr.tck.nodetype</code>     * for testing</li> </ul>     */    public void testAddNodeConstraintViolationExceptionProperty() throws RepositoryException {        // get default workspace test root node using superuser session        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());        // add a node        Node defaultTestNode = defaultRootNode.addNode(nodeName1, testNodeType);        // 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 ConstraintViolationException");        } 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 same name and     * the parent does not allow same name siblings. <br/><br/> This should     * throw an {@link javax.jcr.ItemExistsException }. <br/><br> Prerequisites:     * <ul> <li><code>javax.jcr.tck.NodeTest.testAddNodeItemExistsException.nodetype<code>     * node type that does not allow same name siblings and allows to add child     * nodes of the same type.</li> </ul>     */    public void testAddNodeItemExistsException() throws RepositoryException {        // get default workspace test root node using superuser session        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());        // add a node        Node defaultTestNode = defaultRootNode.addNode(nodeName2, testNodeType);        // 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);            defaultRootNode.save();            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. <br/><br/> This should throw an {@link     * javax.jcr.PathNotFoundException}.     */    public void testAddNodePathNotFoundException() throws RepositoryException {        // get default workspace test root node using superuser session        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());        try {            // use invalid parent path            defaultRootNode.addNode(nodeName1 + "/" + nodeName2);            fail("Creating a node at a non existent destination should throw 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. <br/><br/> This should throw an {@link     * RepositoryException}.     */    public void testAddNodeRepositoryExceptionRelPathIndex() throws RepositoryException {        // get default workspace test root node using superuser session        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());        try {            // use invalid relPath            defaultRootNode.addNode(nodeName1 + "[1]", testNodeType);            fail("Creating a node with index as postfix for new name should throw RepositoryException");        } catch (RepositoryException e) {            // ok, works as expected        }    }    /**     * Creates a new node using {@link Node#addNode(String)}, then tries to call     * {@link javax.jcr.Node#save()} on the newly node. <br/><br/> This should     * throw an {@link RepositoryException}.     */    public void testAddNodeRepositoryExceptionSaveOnNewNode() throws RepositoryException {        // get default workspace test root node using superuser session        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());        // add a node        Node testNode = 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 = (Node) superuser.getItem(testRootNode.getPath());        // add a node        Node testNode = defaultRootNode.addNode(nodeName1, testNodeType);        // save new nodes        defaultRootNode.save();        // use a different session to verify if the node is there        Session session = helper.getReadOnlySession();        try {            testNode = (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 if the     * node has been safed.     */    public void testAddNodeSessionSave() throws RepositoryException {        // get default workspace test root node using superuser session        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());        // add a node        Node testNode = defaultRootNode.addNode(nodeName1, testNodeType);        // save new nodes        superuser.save();        // use a different session to verify if the node is there        Session session = helper.getReadOnlySession();        try {            testNode = (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 delete     * the mandatory child node. <br/><br/> This should throw a {@link     * ConstraintViolationException}. <br/><br/>Prerequisites: <ul>     * <li><code>javax.jcr.tck.NodeTest.testRemoveMandatoryNode.nodetype2</code>     * a node type that has a mandatory child node</li> <li><code>javax.jcr.tck.NodeTest.testRemoveMandatoryNode.nodetype3</code>     * nodetype of the mandatory child node</li> <li><code>javax.jcr.tck.NodeTest.testRemoveMandatoryNode.nodename3</code>     * name of the mandatory child node</li> </ul>     */    public void testRemoveMandatoryNode() throws RepositoryException {        // get default workspace test root node using superuser session        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());        // create the node with the mandatory child node definition        Node defaultTestNode = defaultRootNode.addNode(nodeName2, getProperty("nodetype2"));        // add the mandatory child node        Node defaultTestNodeChild = defaultTestNode.addNode(nodeName3, getProperty("nodetype3"));        // save changes        defaultRootNode.save();        try {            // try to remove the mandatory node            defaultTestNodeChild.remove();            defaultTestNode.save();            fail("Removing a mandatory node should throw a ConstraintViolationException");        } 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. <br/><br/> This should throw     * an {@link InvalidItemStateException}.     */    public void testRemoveInvalidItemStateException() throws RepositoryException {        // get default workspace test root node using superuser session        Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());        // create the node        Node defaultTestNode = defaultRootNode.addNode(nodeName1, testNodeType);        // save the nodes        superuser.save();        // get the node with session 2        Session testSession = helper.getReadWriteSession();        try {            Node defaultTestNodeSession2 = (Node) testSession.getItem(defaultTestNode.getPath());            // remove node with session 1            defaultTestNode.remove();            superuser.save();            // try to remove already deleted node with session 2            try {                defaultTestNodeSession2.remove();                testSession.save();                fail("Removing a node already deleted by other session should throw an InvalidItemStateException!");            } catch (InvalidItemStateException e) {                //ok, works as expected            }        } finally {            testSession.logout();        }    }    /**     * Removes a node using {@link javax.jcr.Node#remove()}, then saves with     * 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 = (Node) superuser.getItem(testRootNode.getPath());        // create the node

⌨️ 快捷键说明

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