org.apache.jackrabbit.test.api
Class DocumentViewImportTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.jackrabbit.test.JUnitTest
              extended by org.apache.jackrabbit.test.AbstractJCRTest
                  extended by org.apache.jackrabbit.test.api.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.


Field Summary
protected static String attributeName
           
protected static String attributeValue
           
protected static String childElem
           
protected  boolean CONTENTHANDLER
           
protected static String decodedAttributeName
           
protected static String decodedAttributeValue
           
protected static String decodedElemName
           
protected  DocumentBuilder dom
           
protected static String encodedAttributeName
           
protected static String encodedAttributeValue
           
protected static String encodedElemName
           
protected  DocumentBuilderFactory factory
           
protected  File file
           
protected static String grandChildElem
           
protected  NamespaceRegistry nsp
           
protected  NodeTypeManager ntManager
           
protected  String ntUnstructured
           
protected  String referenced
           
protected  String referencing
           
protected static String refNodeElem
           
protected  String refTarget
           
protected  Node refTargetNode
           
protected  boolean respectMixRef
           
protected static String rootElem
           
protected  Session session
           
protected  boolean SESSION
           
protected  boolean STREAM
           
protected  String target
           
protected  Node targetNode
           
protected  String TEST_PREFIX
           
protected  String TEST_URI
           
protected  String unusedPrefix
           
protected  String unusedURI
           
protected  int uuidBehaviour
           
protected  Workspace workspace
           
protected  boolean WORKSPACE
           
protected  String XML_NS
           
protected  String xmltext
           
protected static String xmltextElem
           
 
Fields inherited from class org.apache.jackrabbit.test.AbstractJCRTest
helper, isReadOnly, jcrBaseVersion, jcrCreated, jcrFrozenNode, jcrFrozenUuid, jcrIsCheckedOut, jcrlockIsDeep, jcrLockOwner, jcrMergeFailed, jcrMixinTypes, jcrPredecessors, jcrPrimaryType, jcrRootVersion, jcrSuccessors, jcrSystem, jcrUUID, jcrVersionHistory, mixLockable, mixReferenceable, mixShareable, mixSimpleVersionable, 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, testNodeTypeNoChildren, 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. that a node receives a new uuid when imported in any case.
 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(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  Node createAncestors(String absPath)
           
 String createReferenceableNode(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.
 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  String getUnusedPrefix()
          Returns a namespace prefix that currently not used in the namespace registry.
protected  String getUnusedURI()
          Returns a namespace URI that currently not used in the namespace registry.
 void importRefNodeDocument(String absPath, 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(String absPath, Document document, int uuidBehaviour, boolean withWorkspace)
          Imports a given document using the ContentHandler received either with Workspace.getImportContentHandler or Session.getImportContentHandler.
protected  void importXML(String absPath, 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(Document document)
           
 void setUp()
          Sets up the fixture for the test cases.
 boolean supportsNodeType(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
checkSupportedOption, cleanUp, cleanUpTestRoot, createRandomString, ensureCanSetProperty, ensureCanSetProperty, ensureCanSetProperty, ensureMultipleWorkspacesSupported, getJcrValue, getNonExistingWorkspaceName, getProperty, getProperty, getSize, isSupported, needsMixin, 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 String target

refTarget

protected String refTarget

session

protected Session session

workspace

protected Workspace workspace

ntManager

protected NodeTypeManager ntManager

nsp

protected NamespaceRegistry nsp

ntUnstructured

protected String ntUnstructured

file

protected File file

referenced

protected String referenced

referencing

protected String referencing

targetNode

protected Node targetNode

refTargetNode

protected Node refTargetNode

unusedPrefix

protected String unusedPrefix

unusedURI

protected String unusedURI

TEST_PREFIX

protected final String TEST_PREFIX
See Also:
Constant Field Values

TEST_URI

protected final String TEST_URI
See Also:
Constant Field Values

XML_NS

protected final String XML_NS
See Also:
Constant Field Values

rootElem

protected static final String rootElem
See Also:
Constant Field Values

refNodeElem

protected static final String refNodeElem
See Also:
Constant Field Values

xmltextElem

protected static final String xmltextElem
See Also:
Constant Field Values

childElem

protected static final String childElem
See Also:
Constant Field Values

grandChildElem

protected static final String grandChildElem
See Also:
Constant Field Values

encodedElemName

protected static final String encodedElemName
See Also:
Constant Field Values

decodedElemName

protected static final String decodedElemName
See Also:
Constant Field Values

attributeName

protected static final String attributeName
See Also:
Constant Field Values

attributeValue

protected static final String attributeValue
See Also:
Constant Field Values

encodedAttributeName

protected static final String encodedAttributeName
See Also:
Constant Field Values

decodedAttributeName

protected static final String decodedAttributeName
See Also:
Constant Field Values

encodedAttributeValue

protected static final String encodedAttributeValue
See Also:
Constant Field Values

decodedAttributeValue

protected static final String decodedAttributeValue
See Also:
Constant Field Values

xmltext

protected String xmltext

respectMixRef

protected boolean respectMixRef

uuidBehaviour

protected int uuidBehaviour

factory

protected DocumentBuilderFactory factory

dom

protected DocumentBuilder dom
Constructor Detail

DocumentViewImportTest

public DocumentViewImportTest()
Method Detail

setUp

public void setUp()
           throws Exception
Sets up the fixture for the test cases.

Throws:
Exception

tearDown

public void tearDown()
              throws Exception
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

checkImportSimpleXMLTree

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

Throws:
RepositoryException
IOException

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

checkNamespaceAdded

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

Throws:
RepositoryException
IOException

checkImportDocumentView_IMPORT_UUID_CREATE_NEW

public void checkImportDocumentView_IMPORT_UUID_CREATE_NEW()
                                                    throws Exception
Checks ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW i.e. that a node receives a new uuid when imported in any case.

Throws:
Exception

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

createReferenceableNode

public String createReferenceableNode(String name)
                               throws RepositoryException,
                                      NotExecutableException
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:
RepositoryException
NotExecutableException - if the created node is not referenceable and cannot be made referenceable by adding mix:referenceable.

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

createAncestors

protected Node createAncestors(String absPath)
                        throws RepositoryException
Throws:
RepositoryException

serialize

public void serialize(Document document)
               throws IOException
Throws:
IOException

supportsNodeType

public boolean supportsNodeType(String ntName)
                         throws RepositoryException
Throws:
RepositoryException

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

getUnusedURI

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

Returns:
an unused namespace URI.
Throws:
RepositoryException


Copyright © 2004-2009 The Apache Software Foundation. All Rights Reserved.