org.apache.jackrabbit.test.api
Class DocumentViewImportTest

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byorg.apache.jackrabbit.test.JUnitTest
              extended byorg.apache.jackrabbit.test.AbstractJCRTest
                  extended byorg.apache.jackrabbit.test.api.AbstractImportXmlTest
                      extended byorg.apache.jackrabbit.test.api.DocumentViewImportTest
All Implemented Interfaces:
junit.framework.Test

public class DocumentViewImportTest
extends org.apache.jackrabbit.test.api.AbstractImportXmlTest

DocumentViewImportTest Tests importXML and getImportContentHandler methods of the Workspace and Session class. Also tests the UuidBehaviour flag.


Field Summary
protected static java.lang.String attributeName
           
protected static java.lang.String attributeValue
           
protected static java.lang.String childElem
           
protected  boolean CONTENTHANDLER
           
protected static java.lang.String decodedAttributeName
           
protected static java.lang.String decodedAttributeValue
           
protected static java.lang.String decodedElemName
           
protected  javax.xml.parsers.DocumentBuilder dom
           
protected static java.lang.String encodedAttributeName
           
protected static java.lang.String encodedAttributeValue
           
protected static java.lang.String encodedElemName
           
protected  javax.xml.parsers.DocumentBuilderFactory factory
           
protected  java.io.File file
           
protected static java.lang.String grandChildElem
           
protected  javax.jcr.NamespaceRegistry nsp
           
protected  javax.jcr.nodetype.NodeTypeManager ntManager
           
protected  java.lang.String ntUnstructured
           
protected  java.lang.String referenced
           
protected  java.lang.String referencing
           
protected static java.lang.String refNodeElem
           
protected  java.lang.String refTarget
           
protected  javax.jcr.Node refTargetNode
           
protected  boolean respectMixRef
           
protected static java.lang.String rootElem
           
protected  javax.jcr.Session session
           
protected  boolean SESSION
           
protected  boolean STREAM
           
protected  java.lang.String target
           
protected  javax.jcr.Node targetNode
           
protected  java.lang.String TEST_PREFIX
           
protected  java.lang.String TEST_URI
           
protected  java.lang.String unusedPrefix
           
protected  java.lang.String unusedURI
           
protected  int uuidBehaviour
           
protected  javax.jcr.Workspace workspace
           
protected  boolean WORKSPACE
           
protected  java.lang.String XML_NS
           
protected  java.lang.String xmltext
           
protected static java.lang.String xmltextElem
           
 
Fields inherited from class org.apache.jackrabbit.test.AbstractJCRTest
helper, isReadOnly, jcrBaseVersion, jcrCreated, jcrFrozenNode, jcrlockIsDeep, jcrLockOwner, jcrMergeFailed, jcrMixinTypes, jcrPredecessors, jcrPrimaryType, jcrRootVersion, jcrSuccessors, jcrSystem, jcrUUID, jcrVersionHistory, mixLockable, mixReferenceable, mixVersionable, nodeName1, nodeName2, nodeName3, nodeName4, NS_JCR_URI, NS_MIX_URI, NS_NT_URI, NS_SV_URI, ntBase, ntFrozenNode, ntQuery, ntVersion, ntVersionHistory, ntVersionLabels, propertyName1, propertyName2, superuser, testNodeType, testPath, testRoot, testRootNode, workspaceName
 
Fields inherited from class org.apache.jackrabbit.test.JUnitTest
log
 
Constructor Summary
DocumentViewImportTest()
           
 
Method Summary
 void checkImportDocumentView_IMPORT_UUID_COLLISION_REMOVE_EXISTING()
          Checks ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING i.e that the existing node is removed in case of uuid collision.
 void checkImportDocumentView_IMPORT_UUID_COLLISION_REPLACE_EXISTING()
          Checks ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING i.e that the existing node is replaced by the imported one node when uuid collision occurs.
 void checkImportDocumentView_IMPORT_UUID_COLLISION_THROW()
          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.
 void checkImportDocumentView_IMPORT_UUID_CREATE_NEW()
          Checks ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW i.e.
 void checkImportSimpleXMLTree()
          Tests if the simple xml document defined in createSimpleDocument() is imported correctly according the specification rules given in 7.3.2
 void checkNamespaceAdded()
          Checks if a namespace not yet existing in the repository is registered after an according document import.
 void checkXmlTextNode(javax.jcr.Node node)
          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.
protected  javax.jcr.Node createAncestors(java.lang.String absPath)
           
 java.lang.String createReferenceableNode(java.lang.String name)
          Creates a node with given name below the testRootNode which will be referenced by the node nodeName2 and returns the UUID assigned to the created node.
 org.w3c.dom.Document createSimpleDocument()
          Creates a document with some nodes and props for Namespace adding test and for correct tree structure tests after having imported.
 void doTestGetImportContentHandler()
          Tests getImportContentHandler method with uuidBehaviour IMPORT_UUID_CREATE_NEW.
 void doTestImportXML()
          Tests importXML method with uuidBehaviour IMPORT_UUID_CREATE_NEW.
 void doTestSameUUIDAtAncestor(boolean withWorkspace, boolean withHandler)
          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.
protected  java.lang.String getUnusedPrefix()
          Returns a namespace prefix that currently not used in the namespace registry.
protected  java.lang.String getUnusedURI()
          Returns a namespace URI that currently not used in the namespace registry.
 void importRefNodeDocument(java.lang.String absPath, java.lang.String uuid, int uuidBehaviour, boolean withWorkspace, boolean withHandler)
          Creates a document with a element rootElem containing a jcr:uuid attribute with the given uuid as value.
 void importWithHandler(java.lang.String absPath, org.w3c.dom.Document document, int uuidBehaviour, boolean withWorkspace)
          Imports a given document using the ContentHandler received either with Workspace.getImportContentHandler or Session.getImportContentHandler.
protected  void importXML(java.lang.String absPath, org.w3c.dom.Document document, int uuidBehaviour, boolean withWorkspace)
          Imports a given document using either Workspace.importXML or Session.importXML method.
 boolean isMixRefRespected()
          Tests if jcr:uuid property of mix:referenceable nodetype is respected.
 void serialize(org.w3c.dom.Document document)
           
 void setUp()
          Sets up the fixture for the test cases.
 boolean supportsNodeType(java.lang.String ntName)
           
 void tearDown()
           
 void testSameUUIDAtAncestorSession()
           
 void testSameUUIDAtAncestorSessionHandler()
           
 void testSameUUIDAtAncestorWorkspace()
           
 void testSameUUIDAtAncestorWorkspaceHandler()
           
 void testSessionGetImportContentHandler()
           
 void testSessionImportXml()
           
 void testWorkspaceGetImportContentHandler()
           
 void testWorkspaceImportXml()
           
 
Methods inherited from class org.apache.jackrabbit.test.AbstractJCRTest
createRandomString, getNonExistingWorkspaceName, getProperty, getSize, run
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

WORKSPACE

protected final boolean WORKSPACE
See Also:
Constant Field Values

SESSION

protected final boolean SESSION
See Also:
Constant Field Values

CONTENTHANDLER

protected boolean CONTENTHANDLER

STREAM

protected boolean STREAM

target

protected java.lang.String target

refTarget

protected java.lang.String refTarget

session

protected javax.jcr.Session session

workspace

protected javax.jcr.Workspace workspace

ntManager

protected javax.jcr.nodetype.NodeTypeManager ntManager

nsp

protected javax.jcr.NamespaceRegistry nsp

ntUnstructured

protected java.lang.String ntUnstructured

file

protected java.io.File file

referenced

protected java.lang.String referenced

referencing

protected java.lang.String referencing

targetNode

protected javax.jcr.Node targetNode

refTargetNode

protected javax.jcr.Node refTargetNode

unusedPrefix

protected java.lang.String unusedPrefix

unusedURI

protected java.lang.String unusedURI

TEST_PREFIX

protected final java.lang.String TEST_PREFIX
See Also:
Constant Field Values

TEST_URI

protected final java.lang.String TEST_URI
See Also:
Constant Field Values

XML_NS

protected final java.lang.String XML_NS
See Also:
Constant Field Values

rootElem

protected static final java.lang.String rootElem
See Also:
Constant Field Values

refNodeElem

protected static final java.lang.String refNodeElem
See Also:
Constant Field Values

xmltextElem

protected static final java.lang.String xmltextElem
See Also:
Constant Field Values

childElem

protected static final java.lang.String childElem
See Also:
Constant Field Values

grandChildElem

protected static final java.lang.String grandChildElem
See Also:
Constant Field Values

encodedElemName

protected static final java.lang.String encodedElemName
See Also:
Constant Field Values

decodedElemName

protected static final java.lang.String decodedElemName
See Also:
Constant Field Values

attributeName

protected static final java.lang.String attributeName
See Also:
Constant Field Values

attributeValue

protected static final java.lang.String attributeValue
See Also:
Constant Field Values

encodedAttributeName

protected static final java.lang.String encodedAttributeName
See Also:
Constant Field Values

decodedAttributeName

protected static final java.lang.String decodedAttributeName
See Also:
Constant Field Values

encodedAttributeValue

protected static final java.lang.String encodedAttributeValue
See Also:
Constant Field Values

decodedAttributeValue

protected static final java.lang.String decodedAttributeValue
See Also:
Constant Field Values

xmltext

protected java.lang.String xmltext

respectMixRef

protected boolean respectMixRef

uuidBehaviour

protected int uuidBehaviour

factory

protected javax.xml.parsers.DocumentBuilderFactory factory

dom

protected javax.xml.parsers.DocumentBuilder dom
Constructor Detail

DocumentViewImportTest

public DocumentViewImportTest()
Method Detail

setUp

public void setUp()
           throws java.lang.Exception
Description copied from class: org.apache.jackrabbit.test.api.AbstractImportXmlTest
Sets up the fixture for the test cases.

Throws:
java.lang.Exception

tearDown

public void tearDown()
              throws java.lang.Exception
Throws:
java.lang.Exception

testWorkspaceImportXml

public void testWorkspaceImportXml()
                            throws javax.jcr.RepositoryException,
                                   java.io.IOException,
                                   org.xml.sax.SAXException,
                                   NotExecutableException
Throws:
javax.jcr.RepositoryException
java.io.IOException
org.xml.sax.SAXException
NotExecutableException

testSessionImportXml

public void testSessionImportXml()
                          throws javax.jcr.RepositoryException,
                                 java.io.IOException,
                                 org.xml.sax.SAXException,
                                 NotExecutableException
Throws:
javax.jcr.RepositoryException
java.io.IOException
org.xml.sax.SAXException
NotExecutableException

testWorkspaceGetImportContentHandler

public void testWorkspaceGetImportContentHandler()
                                          throws javax.jcr.RepositoryException,
                                                 org.xml.sax.SAXException,
                                                 java.io.IOException,
                                                 NotExecutableException
Throws:
javax.jcr.RepositoryException
org.xml.sax.SAXException
java.io.IOException
NotExecutableException

testSessionGetImportContentHandler

public void testSessionGetImportContentHandler()
                                        throws javax.jcr.RepositoryException,
                                               org.xml.sax.SAXException,
                                               java.io.IOException,
                                               NotExecutableException
Throws:
javax.jcr.RepositoryException
org.xml.sax.SAXException
java.io.IOException
NotExecutableException

doTestImportXML

public void doTestImportXML()
                     throws javax.jcr.RepositoryException,
                            java.io.IOException,
                            org.xml.sax.SAXException,
                            NotExecutableException
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:
javax.jcr.RepositoryException
java.io.IOException
org.xml.sax.SAXException
NotExecutableException

doTestGetImportContentHandler

public void doTestGetImportContentHandler()
                                   throws javax.jcr.RepositoryException,
                                          org.xml.sax.SAXException,
                                          java.io.IOException,
                                          NotExecutableException
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:
javax.jcr.RepositoryException
org.xml.sax.SAXException
java.io.IOException
NotExecutableException

checkImportSimpleXMLTree

public void checkImportSimpleXMLTree()
                              throws javax.jcr.RepositoryException,
                                     java.io.IOException
Tests if the simple xml document defined in createSimpleDocument() is imported correctly according the specification rules given in 7.3.2

Throws:
javax.jcr.RepositoryException
java.io.IOException

checkXmlTextNode

public void checkXmlTextNode(javax.jcr.Node node)
                      throws javax.jcr.RepositoryException,
                             java.io.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:
javax.jcr.RepositoryException
java.io.IOException

checkNamespaceAdded

public void checkNamespaceAdded()
                         throws javax.jcr.RepositoryException,
                                java.io.IOException
Checks if a namespace not yet existing in the repository is registered after an according document import.

Throws:
javax.jcr.RepositoryException
java.io.IOException

checkImportDocumentView_IMPORT_UUID_CREATE_NEW

public void checkImportDocumentView_IMPORT_UUID_CREATE_NEW()
                                                    throws javax.jcr.RepositoryException,
                                                           java.io.IOException,
                                                           org.xml.sax.SAXException
Checks ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW i.e. that a node receives a new uuid when imported in any case.

Throws:
javax.jcr.RepositoryException
java.io.IOException
org.xml.sax.SAXException

checkImportDocumentView_IMPORT_UUID_COLLISION_REMOVE_EXISTING

public void checkImportDocumentView_IMPORT_UUID_COLLISION_REMOVE_EXISTING()
                                                                   throws javax.jcr.RepositoryException,
                                                                          java.io.IOException,
                                                                          org.xml.sax.SAXException
Checks ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING i.e that the existing node is removed in case of uuid collision.

Throws:
javax.jcr.RepositoryException
java.io.IOException
org.xml.sax.SAXException

checkImportDocumentView_IMPORT_UUID_COLLISION_REPLACE_EXISTING

public void checkImportDocumentView_IMPORT_UUID_COLLISION_REPLACE_EXISTING()
                                                                    throws javax.jcr.RepositoryException,
                                                                           java.io.IOException,
                                                                           org.xml.sax.SAXException
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:
javax.jcr.RepositoryException
java.io.IOException
org.xml.sax.SAXException

checkImportDocumentView_IMPORT_UUID_COLLISION_THROW

public void checkImportDocumentView_IMPORT_UUID_COLLISION_THROW()
                                                         throws javax.jcr.RepositoryException,
                                                                java.io.IOException,
                                                                org.xml.sax.SAXException
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:
javax.jcr.RepositoryException
java.io.IOException
org.xml.sax.SAXException

doTestSameUUIDAtAncestor

public void doTestSameUUIDAtAncestor(boolean withWorkspace,
                                     boolean withHandler)
                              throws javax.jcr.RepositoryException,
                                     java.io.IOException,
                                     org.xml.sax.SAXException
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:
javax.jcr.RepositoryException
java.io.IOException
org.xml.sax.SAXException

testSameUUIDAtAncestorWorkspaceHandler

public void testSameUUIDAtAncestorWorkspaceHandler()
                                            throws javax.jcr.RepositoryException,
                                                   java.io.IOException,
                                                   org.xml.sax.SAXException
Throws:
javax.jcr.RepositoryException
java.io.IOException
org.xml.sax.SAXException

testSameUUIDAtAncestorWorkspace

public void testSameUUIDAtAncestorWorkspace()
                                     throws javax.jcr.RepositoryException,
                                            java.io.IOException,
                                            org.xml.sax.SAXException
Throws:
javax.jcr.RepositoryException
java.io.IOException
org.xml.sax.SAXException

testSameUUIDAtAncestorSessionHandler

public void testSameUUIDAtAncestorSessionHandler()
                                          throws javax.jcr.RepositoryException,
                                                 java.io.IOException,
                                                 org.xml.sax.SAXException
Throws:
javax.jcr.RepositoryException
java.io.IOException
org.xml.sax.SAXException

testSameUUIDAtAncestorSession

public void testSameUUIDAtAncestorSession()
                                   throws javax.jcr.RepositoryException,
                                          java.io.IOException,
                                          org.xml.sax.SAXException
Throws:
javax.jcr.RepositoryException
java.io.IOException
org.xml.sax.SAXException

createSimpleDocument

public org.w3c.dom.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(java.lang.String absPath,
                         org.w3c.dom.Document document,
                         int uuidBehaviour,
                         boolean withWorkspace)
                  throws javax.jcr.RepositoryException,
                         java.io.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:
javax.jcr.RepositoryException
java.io.IOException

importWithHandler

public void importWithHandler(java.lang.String absPath,
                              org.w3c.dom.Document document,
                              int uuidBehaviour,
                              boolean withWorkspace)
                       throws javax.jcr.RepositoryException,
                              org.xml.sax.SAXException,
                              java.io.IOException
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:
javax.jcr.RepositoryException
org.xml.sax.SAXException
java.io.IOException

isMixRefRespected

public boolean isMixRefRespected()
                          throws javax.jcr.RepositoryException,
                                 java.io.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:
javax.jcr.RepositoryException
java.io.IOException

createReferenceableNode

public java.lang.String createReferenceableNode(java.lang.String name)
                                         throws javax.jcr.RepositoryException
Creates a node with given name below the testRootNode which will be referenced by the node nodeName2 and returns the UUID assigned to the created node.

Parameters:
name -
Returns:
Throws:
javax.jcr.RepositoryException

importRefNodeDocument

public void importRefNodeDocument(java.lang.String absPath,
                                  java.lang.String uuid,
                                  int uuidBehaviour,
                                  boolean withWorkspace,
                                  boolean withHandler)
                           throws javax.jcr.RepositoryException,
                                  java.io.IOException,
                                  org.xml.sax.SAXException
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:
javax.jcr.RepositoryException
java.io.IOException
org.xml.sax.SAXException

createAncestors

protected javax.jcr.Node createAncestors(java.lang.String absPath)
                                  throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

serialize

public void serialize(org.w3c.dom.Document document)
               throws java.io.IOException
Throws:
java.io.IOException

supportsNodeType

public boolean supportsNodeType(java.lang.String ntName)
                         throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getUnusedPrefix

protected java.lang.String getUnusedPrefix()
                                    throws javax.jcr.RepositoryException
Returns a namespace prefix that currently not used in the namespace registry.

Returns:
an unused namespace prefix.
Throws:
javax.jcr.RepositoryException

getUnusedURI

protected java.lang.String getUnusedURI()
                                 throws javax.jcr.RepositoryException
Returns a namespace URI that currently not used in the namespace registry.

Returns:
an unused namespace URI.
Throws:
javax.jcr.RepositoryException


Copyright © -2005 . All Rights Reserved.