Class 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.
    • Constructor Detail

      • NamespaceRemappingTest

        public NamespaceRemappingTest()
    • Method Detail

      • 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