org.apache.jackrabbit.test.api
Class NamespaceRemappingTest

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.NamespaceRemappingTest
All Implemented Interfaces:
junit.framework.Test

public class NamespaceRemappingTest
extends AbstractJCRTest

Test cases for JSR 283 sections 3.5.2 Session-Local Mappings and 5.11 Namespace Mapping and the related namespace mapping methods in Session.


Field Summary
 
Fields inherited from class org.apache.jackrabbit.test.AbstractJCRTest
isReadOnly, jcrBaseVersion, jcrCopiedFrom, 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, ntUnstructured, ntVersion, ntVersionHistory, ntVersionLabels, propertyName1, propertyName2, superuser, testNodeType, testNodeTypeNoChildren, testPath, testRoot, testRootNode, vf, workspaceName
 
Fields inherited from class org.apache.jackrabbit.test.JUnitTest
log
 
Constructor Summary
NamespaceRemappingTest()
           
 
Method Summary
protected  void setUp()
          Sets up the fixture for the tests.
protected  void tearDown()
           
 void testAutomaticNewLocalPrefix()
          Test case for the automatic generation of a new local prefix for a registered namespace URI that doesn't have a local mapping, as specified in section 3.5.2 Session-Local Mappings: If a JCR method returns a name from the repository with a namespace URI for which no local mapping exists, a prefix is created automatically and a mapping between that prefix and the namespace URI in question is added to the set of local mappings.
 void testExceptionOnUnknownPrefix()
          Test case for the unknown prefix behaviour specified in section 3.5.2 Session-Local Mappings: If a JCR method is passed a name or path containing a prefix which does not exist in the local mapping an exception is thrown.
 void testExceptionsFromRemapping()
          Test case for the exception clauses of section 5.11 Namespace Mapping: However, the method will throw an exception if the specified prefix begins with the characters “xml” (in any combination of case) or, the specified prefix is the empty string or, the specified namespace URI is the empty string.
 void testGetNamespacePrefix()
          Tests that Session.getNamespacePrefix returns the session scoped mapping.
 void testGetNamespacePrefixes()
          Tests if Session.getNamespacePrefixes() returns all prefixes currently set for this session, including all those registered in the NamespaceRegistry but not over-ridden by a Session.setNamespacePrefix, plus those currently set locally by Session.setNamespacePrefix.
 void testGetNamespaceURI()
          Tests that Session.getNamespaceURI() returns according the session scoped mapping
 void testInitialLocalNamespaceMappings()
          Test case for the initial set of local namespace mappings as specified in section 3.5.2 Session-Local Mappings: When a new session is acquired, the mappings present in the persistent namespace registry are copied to the local namespace mappings of that session.
 void testNamespaceRemapping()
          Tests if the remapping of jcr:primaryType to a different prefix works and returns the property with the correct primaryType value.
 void testScopeOfLocalNamepaceMappings()
          Test case for the scope of the local namespace mappings as specified in section 3.5.2 Session-Local Mappings: The resulting mapping table applies only within the scope of that session
 
Methods inherited from class org.apache.jackrabbit.test.AbstractJCRTest
checkSupportedOption, cleanUp, cleanUpTestRoot, createRandomString, ensureCanSetProperty, ensureCanSetProperty, ensureCanSetProperty, ensureKnowsNodeType, ensureMixinType, ensureMultipleWorkspacesSupported, getHelper, getJcrValue, getLocalName, 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
 

Constructor Detail

NamespaceRemappingTest

public NamespaceRemappingTest()
Method Detail

setUp

protected void setUp()
              throws Exception
Sets up the fixture for the tests.

Overrides:
setUp in class AbstractJCRTest
Throws:
Exception

tearDown

protected void tearDown()
                 throws Exception
Overrides:
tearDown in class AbstractJCRTest
Throws:
Exception

testNamespaceRemapping

public void testNamespaceRemapping()
                            throws RepositoryException
Tests if the remapping of jcr:primaryType to a different prefix works and returns the property with the correct primaryType value.

Throws:
RepositoryException

testAutomaticNewLocalPrefix

public void testAutomaticNewLocalPrefix()
                                 throws RepositoryException
Test case for the automatic generation of a new local prefix for a registered namespace URI that doesn't have a local mapping, as specified in section 3.5.2 Session-Local Mappings:
If a JCR method returns a name from the repository with a namespace URI for which no local mapping exists, a prefix is created automatically and a mapping between that prefix and the namespace URI in question is added to the set of local mappings. The new prefix must differ from those already present among the set of local mappings.

Throws:
RepositoryException

testExceptionOnUnknownPrefix

public void testExceptionOnUnknownPrefix()
                                  throws RepositoryException
Test case for the unknown prefix behaviour specified in section 3.5.2 Session-Local Mappings:
If a JCR method is passed a name or path containing a prefix which does not exist in the local mapping an exception is thrown.

Throws:
RepositoryException

testInitialLocalNamespaceMappings

public void testInitialLocalNamespaceMappings()
                                       throws RepositoryException
Test case for the initial set of local namespace mappings as specified in section 3.5.2 Session-Local Mappings:
When a new session is acquired, the mappings present in the persistent namespace registry are copied to the local namespace mappings of that session.

Throws:
RepositoryException

testScopeOfLocalNamepaceMappings

public void testScopeOfLocalNamepaceMappings()
                                      throws RepositoryException
Test case for the scope of the local namespace mappings as specified in section 3.5.2 Session-Local Mappings:
The resulting mapping table applies only within the scope of that session

Also specified in the javadoc of Session.setNamespacePrefix(String, String):

The remapping only affects operations done through this Session. To clear all remappings, the client must acquire a new Session.

Throws:
RepositoryException

testExceptionsFromRemapping

public void testExceptionsFromRemapping()
                                 throws RepositoryException
Test case for the exception clauses of section 5.11 Namespace Mapping:
However, the method will throw an exception if
  • the specified prefix begins with the characters “xml” (in any combination of case) or,
  • the specified prefix is the empty string or,
  • the specified namespace URI is the empty string.

Also specified in the javadoc for throwing a NamespaceException from Session.setNamespacePrefix(String, String):

if an attempt is made to map a namespace URI to a prefix beginning with the characters "xml" (in any combination of case) or if an attempt is made to map either the empty prefix or the empty namespace (i.e., if either prefix or uri are the empty string).

Section 3.2 Names also contains extra constraints on the prefix and namespace URI syntax:

 Namespace   ::= EmptyString | Uri
 EmptyString ::= The empty string
 Uri         ::= A URI, as defined in Section 3 in
                 http://tools.ietf.org/html/rfc3986#section-3
 Prefix      ::= Any string that matches the NCName production in
                 http://www.w3.org/TR/REC-xml-names
 

It is unspecified whether an implementation should actually enforce these constraints, so for now this test case does not check this behaviour.

Throws:
RepositoryException

testGetNamespaceURI

public void testGetNamespaceURI()
                         throws RepositoryException
Tests that Session.getNamespaceURI() returns according the session scoped mapping

Throws:
RepositoryException

testGetNamespacePrefix

public void testGetNamespacePrefix()
                            throws RepositoryException
Tests that Session.getNamespacePrefix returns the session scoped mapping.

Throws:
RepositoryException

testGetNamespacePrefixes

public void testGetNamespacePrefixes()
                              throws RepositoryException
Tests if Session.getNamespacePrefixes() returns all prefixes currently set for this session, including all those registered in the NamespaceRegistry but not over-ridden by a Session.setNamespacePrefix, plus those currently set locally by Session.setNamespacePrefix.

Throws:
RepositoryException


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