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

📄 documentviewimporttest.java

📁 jsr170接口的java实现。是个apache的开源项目。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                            + encodedAttributeName + " not imported: " + pnfe2);                }            }        } catch (PathNotFoundException pne) {            fail("Element or attribute is not imported: " + pne);        }    }    /**     * Tests if xmltext in a body of a xml element is correctly imported to a     * node with name jcr:xmltext and that the value of the text is stored in     * the singlevalued jcr:xmlcharacters property of String type.     *     * @throws RepositoryException     */    public void checkXmlTextNode(Node node) throws RepositoryException, IOException {        if (node.hasNode(JCR_XMLTEXT)) {            Node xmlNode = node.getNode(JCR_XMLTEXT);            if (xmlNode.hasProperty(JCR_XMLCHAR)) {                Property prop = xmlNode.getProperty(JCR_XMLCHAR);                // correct type?                assertTrue("Property " + prop.getPath() + " is not of type String.",                        prop.getType() == PropertyType.STRING);                // correct text?                // todo remove the trim as only the white spaces of the current text should be collected                assertEquals("Xml text is not correctly stored.",                        xmltext.trim(), prop.getString().trim());                // only jcr:xmlcharacters property beneath the jcr:primaryType                PropertyIterator iter = xmlNode.getProperties();                assertTrue(JCR_XMLCHAR + " is not the only property beneath " +                        jcrPrimaryType + " in a " + JCR_XMLTEXT + " node.", getSize(iter) == 2);            } else {                fail("Xmltext not stored in property named " + JCR_XMLCHAR);            }        } else {            fail("Xmltext not imported to Node named " + JCR_XMLTEXT);        }    }    /**     * Checks if a namespace not yet existing in the repository is registered     * after an according document import.     *     * @throws RepositoryException     * @throws IOException     */    public void checkNamespaceAdded() throws RepositoryException, IOException {        try {            assertEquals("URI not correctly imported.", nsp.getURI(unusedPrefix), unusedURI);            assertEquals("Prefix not correctly imported", nsp.getPrefix(unusedURI), unusedPrefix);        } catch (NamespaceException nse) {            fail("Namespace " + unusedPrefix + ":" + unusedURI +                    " not imported during document view import.");        }    }    //------------------< uuid collision behaviour tests >--------------------------    // we create a node named referenced below the testRootNode, also we create a xml    // document with an element named rootElem having the uuid of the referenced node    // as attribute and we import this document below the refTargetNode.    /**     * Checks {@link ImportUUIDBehavior#IMPORT_UUID_CREATE_NEW} i.e. that a node     * receives a new uuid when imported in any case.     */    public void checkImportDocumentView_IMPORT_UUID_CREATE_NEW() throws Exception {        String uuid = createReferenceableNode(referenced);        // import a document with a element having the same uuid as the node referenced        importRefNodeDocument(refTarget, uuid, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, withWorkspace, withHandler);        // different uuid?        Node node = refTargetNode.getNode(rootElem);        String rootElemUUID = node.getUUID();        assertFalse("Imported node " + rootElem + " has a UUID which is " +                "yet assigned to another node", uuid.equals(rootElemUUID));    }    /**     * Checks ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING i.e that     * the existing node is removed in case of uuid collision.     */    public void checkImportDocumentView_IMPORT_UUID_COLLISION_REMOVE_EXISTING()            throws Exception {        String uuid = createReferenceableNode(referenced);        // import a document with a element having the same uuid as the node referenced        importRefNodeDocument(refTarget, uuid, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING,                withWorkspace, withHandler);        try {            // should be removed now            testRootNode.getNode(referenced);            fail("UUID behavior IMPORT_UUID_COLLISION_REMOVE_EXISTING test is failed: " +                    "existing node not removed");        } catch (PathNotFoundException pnfe) {            // ok        }        try {            // should be there            refTargetNode.getNode(rootElem);        } catch (PathNotFoundException pnfe) {            fail("UUID behavior IMPORT_UUID_COLLISION_REMOVE_EXISTING test is failed: " +                    "imported node not in its correct place.");        }    }    /**     * Checks ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING i.e that     * the existing node is replaced by the imported one node when uuid     * collision occurs.     */    public void checkImportDocumentView_IMPORT_UUID_COLLISION_REPLACE_EXISTING()            throws Exception {        String uuid = createReferenceableNode(referenced);        // import a document with a element having the same uuid as the node referenced        importRefNodeDocument(refTarget, uuid, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING,                withWorkspace, withHandler);        // should be replaced i.e should be modified, in case Workspace method is used        //  we cannot decide unless we have some additional property of the imported node.        if (!withWorkspace) {            Node node = testRootNode.getNode(rootElem);            assertTrue("Node " + node.getPath() + " not replaced during " +                    "import with IMPORT_UUID_COLLISION_REPLACE_EXISTING", node.hasProperty(propertyName1));        }    }    /**     * Checks ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW i.e that a     * ItemExistsException is thrown in case of importing with an input stream     * or a SAXException is thrown in case of importing with a ContentHandler.     *     * @throws RepositoryException     * @throws IOException     */    public void checkImportDocumentView_IMPORT_UUID_COLLISION_THROW()            throws Exception {        String uuid = createReferenceableNode(referenced);        try {            importRefNodeDocument(refTarget, uuid, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW,                    withWorkspace, withHandler);            fail("UUID behavior IMPORT_UUID_COLLISION_THROW test is failed: " +                    "should throw an Exception.");        } catch (ItemExistsException e) {            if (!withHandler) {                // ok            } else {                throw e;            }        } catch (SAXException e) {            if (withHandler) {                // ok            } else {                throw e;            }        }    }  //-------------------------------< exception tests >--------------------------------------    /**     * Tests correct failure of importing a element wit the same UUID as the target node or     * an ancestor of it in case of uuidBehavior IMPORT_UUID_COLLISION_REMOVE_EXISTING.     *     * The imported document contains a element with jcr:uuid attribute the same as the     * parent of the import target.     */    public void doTestSameUUIDAtAncestor(boolean withWorkspace, boolean withHandler)            throws Exception {        String uuid = createReferenceableNode(referenced);        Node node = testRootNode.getNode(referenced);        Node node2 = node.addNode("newParent");        session.save();        // import a document with a element having the same uuid as the node referenced        try {            importRefNodeDocument(node2.getPath(), uuid,                ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING,                    withWorkspace, withHandler);            fail("UUID collision with an ancestor of the target node hould throw a " +                    "SAXException or a ConstraintViolationException in case of " +                    "uuidBehavior IMPORT_UUID_COLLISION_REMOVE_EXISTING.");        } catch(SAXException se) {            if (!withHandler) {                throw se;            }            // ok        } catch (ConstraintViolationException cve) {            if (withHandler) {                throw cve;            }            // ok        }    }    public void testSameUUIDAtAncestorWorkspaceHandler() throws Exception {        doTestSameUUIDAtAncestor(WORKSPACE, CONTENTHANDLER);    }    public void testSameUUIDAtAncestorWorkspace() throws Exception {        doTestSameUUIDAtAncestor(WORKSPACE, STREAM);    }    public void testSameUUIDAtAncestorSessionHandler() throws Exception  {        doTestSameUUIDAtAncestor(SESSION, CONTENTHANDLER);    }    public void testSameUUIDAtAncestorSession() throws Exception {        doTestSameUUIDAtAncestor(SESSION, STREAM);    }}

⌨️ 快捷键说明

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