From 86a246f424d2a38378289670ce353bdce9e1f32b Mon Sep 17 00:00:00 2001 From: Randall Hauch Date: Tue, 3 Jul 2012 09:42:14 -0500 Subject: [PATCH] JCR-3371 Corrected ShareableNodeTest logic that tests removing 'mix:shareable' mixin The existing ShareableNodeTest.testRemoveMixin() test method assumed that an implementation would always throw an UnsupportedOperationException. This is not only checking for the incorrect exception, section 14.15 "RemoveMixin" specifically states that it *is* possible for an implementation to support removing the 'mix:shareable' mixin. This change fixes that test method to check only for the ConstraintViolationException or an UnsupportedOperationException, or if neither of those happen then the test verifies that the implementation correctly removed the mixin. This test attempts to remove the mixin only after creating the node, adding the mixin, and then saving the session. In other words, the shareable node was never used to create a shared node. An additional test was added to test trying to remove the mixin from a node that has already been shared. Again, either the ConstraintViolationException or UnsupportedOperationException are thrown, or the test verifies that the implementation correctly removed the mixin. --- .../jackrabbit/test/api/ShareableNodeTest.java | 49 +++++++++++++++++++- 1 files changed, 47 insertions(+), 2 deletions(-) diff --git a/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ShareableNodeTest.java b/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ShareableNodeTest.java index 5bd389a..8d29f4e 100644 --- a/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ShareableNodeTest.java +++ b/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ShareableNodeTest.java @@ -1092,13 +1092,58 @@ public class ShareableNodeTest extends AbstractJCRTest { ensureMixinType(b, mixShareable); b.save(); + // Removing the mixin will either succeed or will fail with a ConstraintViolationException + // (per Section 14.15 of JSR-283 specification) try { // remove mixin b.removeMixin(mixShareable); b.save(); - fail("Removing mix:shareable should fail."); + // If this happens, then b shouldn't be shareable anymore ... + assertEquals(false,b.isNodeType(mixShareable)); + } catch (ConstraintViolationException e) { + // one possible outcome if removing 'mix:shareable' isn't supported } catch (UnsupportedRepositoryOperationException e) { - // expected + // also possible if the implementation doesn't support this capability + } + } + + /** + * Remove mix:shareable from a shareable node that has 2 nodes in the shared set. + * This is unsupported in Jackrabbit (6.13.22). + */ + public void testRemoveMixinFromSharedNode() throws Exception { + // setup parent nodes and first child + Node a1 = testRootNode.addNode("a1"); + Node a2 = testRootNode.addNode("a2"); + Node b1 = a1.addNode("b1"); + testRootNode.getSession().save(); + + // add mixin + ensureMixinType(b1, mixShareable); + b1.save(); + + // clone + Workspace workspace = b1.getSession().getWorkspace(); + workspace.clone(workspace.getName(), b1.getPath(), + a2.getPath() + "/b2", false); + + Node[] shared = getSharedSet(b1); + assertEquals(2, shared.length); + b1 = shared[0]; + Node b2 = shared[1]; + + // Removing the mixin will either succeed or will fail with a ConstraintViolationException + // (per Section 14.15 of JSR-283 specification) + try { + // remove mixin + b1.removeMixin(mixShareable); + b1.save(); + // If this happens, then b shouldn't be shareable anymore ... + assertEquals(false,b1.isNodeType(mixShareable)); + } catch (ConstraintViolationException e) { + // one possible outcome if removing 'mix:shareable' isn't supported + } catch (UnsupportedRepositoryOperationException e) { + // also possible if the implementation doesn't support this capability } } -- 1.7.6