Class DocumentViewImportTest

  • All Implemented Interfaces:
    junit.framework.Test

    public class DocumentViewImportTest
    extends AbstractJCRTest
    DocumentViewImportTest Tests importXML and getImportContentHandler methods of the Workspace and Session class. Also tests the UuidBehaviour flag.
    • Constructor Detail

      • DocumentViewImportTest

        public DocumentViewImportTest()
    • Method Detail

      • setUp

        public void setUp()
                   throws Exception
        Sets up the fixture for the test cases.
        Throws:
        Exception
      • testWorkspaceImportXml

        public void testWorkspaceImportXml()
                                    throws Exception
        Throws:
        Exception
      • testSessionImportXml

        public void testSessionImportXml()
                                  throws Exception
        Throws:
        Exception
      • testWorkspaceGetImportContentHandler

        public void testWorkspaceGetImportContentHandler()
                                                  throws Exception
        Throws:
        Exception
      • testSessionGetImportContentHandler

        public void testSessionGetImportContentHandler()
                                                throws Exception
        Throws:
        Exception
      • doTestImportXML

        public void doTestImportXML()
                             throws Exception
        Tests importXML method with uuidBehaviour IMPORT_UUID_CREATE_NEW. It imports the document created with createSimpleDocument method and checks the imported tree according the rules outlined in chapter 7.3.2 of the specification.

        Additionally it checks the uuidBehaviour flag if the jcr:uuid property is respected during import.

        Throws:
        RepositoryException
        IOException
        SAXException
        NotExecutableException
        Exception
      • doTestGetImportContentHandler

        public void doTestGetImportContentHandler()
                                           throws Exception
        Tests getImportContentHandler method with uuidBehaviour IMPORT_UUID_CREATE_NEW. It imports the document created with createSimpleDocument method and checks the imported tree according the rules outlined in chapter 7.3.2 of the specification.

        Additionally it checks the uuidBehaviour flag if the jcr:uuid property is respected during import.

        Throws:
        RepositoryException
        SAXException
        IOException
        NotExecutableException
        Exception
      • checkXmlTextNode

        public void checkXmlTextNode​(Node node)
                              throws RepositoryException,
                                     IOException
        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
        IOException
      • checkImportDocumentView_IMPORT_UUID_COLLISION_REMOVE_EXISTING

        public void checkImportDocumentView_IMPORT_UUID_COLLISION_REMOVE_EXISTING()
                                                                           throws Exception
        Checks ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING i.e that the existing node is removed in case of uuid collision.
        Throws:
        Exception
      • checkImportDocumentView_IMPORT_UUID_COLLISION_REPLACE_EXISTING

        public void checkImportDocumentView_IMPORT_UUID_COLLISION_REPLACE_EXISTING()
                                                                            throws Exception
        Checks ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING i.e that the existing node is replaced by the imported one node when uuid collision occurs.
        Throws:
        Exception
      • checkImportDocumentView_IMPORT_UUID_COLLISION_THROW

        public void checkImportDocumentView_IMPORT_UUID_COLLISION_THROW()
                                                                 throws Exception
        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
        IOException
        Exception
      • doTestSameUUIDAtAncestor

        public void doTestSameUUIDAtAncestor​(boolean withWorkspace,
                                             boolean withHandler)
                                      throws Exception
        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.
        Throws:
        Exception
      • testSameUUIDAtAncestorWorkspaceHandler

        public void testSameUUIDAtAncestorWorkspaceHandler()
                                                    throws Exception
        Throws:
        Exception
      • testSameUUIDAtAncestorWorkspace

        public void testSameUUIDAtAncestorWorkspace()
                                             throws Exception
        Throws:
        Exception
      • testSameUUIDAtAncestorSessionHandler

        public void testSameUUIDAtAncestorSessionHandler()
                                                  throws Exception
        Throws:
        Exception
      • testSameUUIDAtAncestorSession

        public void testSameUUIDAtAncestorSession()
                                           throws Exception
        Throws:
        Exception
      • createSimpleDocument

        public Document createSimpleDocument()
        Creates a document with some nodes and props for Namespace adding test and for correct tree structure tests after having imported.
        Returns:
      • importXML

        protected void importXML​(String absPath,
                                 Document document,
                                 int uuidBehaviour,
                                 boolean withWorkspace)
                          throws RepositoryException,
                                 IOException
        Imports a given document using either Workspace.importXML or Session.importXML method.
        Parameters:
        absPath - the absPath to the parent node where to import the document
        document - the document to import
        uuidBehaviour - how the uuid collisions should be handled
        withWorkspace - if workspace or session interface should be used
        Throws:
        RepositoryException
        IOException
      • importWithHandler

        public void importWithHandler​(String absPath,
                                      Document document,
                                      int uuidBehaviour,
                                      boolean withWorkspace)
                               throws Exception
        Imports a given document using the ContentHandler received either with Workspace.getImportContentHandler or Session.getImportContentHandler. This handler is then passed to a XML parser which parses the given document.
        Parameters:
        absPath - the absPath to the parent node where to import the document
        document - the document to import
        uuidBehaviour - how the uuid collisions should be handled
        withWorkspace - if workspace or session interface should be used
        Throws:
        RepositoryException
        SAXException
        IOException
        Exception
      • isMixRefRespected

        public boolean isMixRefRespected()
                                  throws RepositoryException,
                                         IOException
        Tests if jcr:uuid property of mix:referenceable nodetype is respected. This is believed as true when during import with uuidBehaviour IMPORT_UUID_COLLISION_REMOVE_EXISTING a node with the same uuid as a node to be imported will be deleted.
        Returns:
        Throws:
        RepositoryException
        IOException
      • importRefNodeDocument

        public void importRefNodeDocument​(String absPath,
                                          String uuid,
                                          int uuidBehaviour,
                                          boolean withWorkspace,
                                          boolean withHandler)
                                   throws Exception
        Creates a document with a element rootElem containing a jcr:uuid attribute with the given uuid as value. This document is imported below the node with path absPath. If nod node at absPth it is created. If there is yet a node rootElem below the then this node is romoved in advance.
        Parameters:
        uuid -
        uuidBehaviour -
        withWorkspace -
        withHandler -
        Throws:
        RepositoryException
        IOException
        Exception
      • getUnusedPrefix

        protected String getUnusedPrefix()
                                  throws RepositoryException
        Returns a namespace prefix that currently not used in the namespace registry.
        Returns:
        an unused namespace prefix.
        Throws:
        RepositoryException