reschke commented on code in PR #2306: URL: https://github.com/apache/jackrabbit-oak/pull/2306#discussion_r2107511524
########## oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/session/JackrabbitSessionTest.java: ########## @@ -86,20 +89,46 @@ public void testGetExpandedName() throws RepositoryException { assertEquals("{}testroot", s.getExpandedName(testRootNode)); Node n = testRootNode.addNode("test:bar"); assertEquals("{http://www.apache.org/jackrabbit/test}bar", s.getExpandedName(n)); - // now remap namespace uri + // now remap namespace uri - should not affect expanded name + assertEquals("prefix 'test' has unexpected mapping", + "http://www.apache.org/jackrabbit/test", s.getNamespaceURI("test")); s.setNamespacePrefix("test", "urn:foo"); - assertEquals("{urn:foo}bar", s.getExpandedName(n)); + assertEquals("{http://www.apache.org/jackrabbit/test}bar", s.getExpandedName(n)); // use special namespace uri n = testRootNode.addNode("rep:bar"); assertEquals("{internal}bar", s.getExpandedName(n)); } + public void testGetExpandedNameBrokenNamespace() throws RepositoryException { + // empty namespace uri + assertEquals("{}testroot", s.getExpandedName(testRootNode)); + + String randomNamespacePrefix = "prefix-" + UUID.randomUUID(); + // below is not a valid namespace a.k.a. namespace URI + String randomNamespaceName = "name-" + UUID.randomUUID(); + + // register broken namespace prefix/name mapping + s.getWorkspace().getNamespaceRegistry().registerNamespace(randomNamespacePrefix, randomNamespaceName); + + try { + Node n = testRootNode.addNode(randomNamespacePrefix + ":qux"); + + // there is no expanded name, thus we expect an exception here + String result = s.getExpandedName(n); + fail("there is no expanded name in this case, so we expect the call to fail, however we get: " + result); + } catch (NamespaceException ex) { + // expected + } finally { + s.getWorkspace().getNamespaceRegistry().unregisterNamespace(randomNamespacePrefix); + } + } + Review Comment: Junit4 does not have `assertThrows`, right? In any case, in case of no exception I wanted the return value to be dumped. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: oak-dev-unsubscr...@jackrabbit.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org