@Test public void shouldAllowAddingMixinIfNoConflict() throws Exception { session.getRootNode().addNode("a", PRIMARY_TYPE_A).addMixin("mix:referenceable"); session.save(); Node rootNode = session.getRootNode(); Node nodeA = rootNode.getNode("a"); assertThat(nodeA.canAddMixin(MIXIN_TYPE_B), is(true)); }
@Test public void shouldAllowAddingMixinIfPrimaryTypeConflicts() throws Exception { session.getRootNode().addNode("a", PRIMARY_TYPE_A).addMixin("mix:referenceable"); session.save(); Node rootNode = session.getRootNode(); Node nodeA = rootNode.getNode("a"); assertThat(nodeA.canAddMixin(MIXIN_TYPE_C), is(true)); }
@Test public void shouldAllowAddingMixinIfMixinTypeConflicts() throws Exception { session.getRootNode().addNode("a", PRIMARY_TYPE_A).addMixin(MIXIN_TYPE_B); session.save(); Node rootNode = session.getRootNode(); Node nodeA = rootNode.getNode("a"); assertThat(nodeA.canAddMixin(MIXIN_TYPE_C), is(true)); }
@Test public void shouldAllowSettingNewPropertyAfterAddingMixin() throws Exception { session.getRootNode().addNode("a", PRIMARY_TYPE_A).addMixin("mix:referenceable"); session.save(); Node rootNode = session.getRootNode(); Node nodeA = rootNode.getNode("a"); assertThat(nodeA.canAddMixin(MIXIN_TYPE_B), is(true)); nodeA.addMixin(MIXIN_TYPE_B); nodeA.setProperty(PROPERTY_B, "some string"); session.save(); rootNode = session.getRootNode(); nodeA = rootNode.getNode("a"); Property propB = nodeA.getProperty(PROPERTY_B); assertThat(propB, is(notNullValue())); assertThat(propB.getValue().getString(), is("some string")); }
newNode.addMixin(mixin);
newNode.addMixin(mixin);
@Test public void shouldAllowAddingNewChildNodeAfterAddingMixin() throws Exception { session.getRootNode().addNode("a", PRIMARY_TYPE_A).addMixin("mix:referenceable"); session.save(); Node rootNode = session.getRootNode(); Node nodeA = rootNode.getNode("a"); assertThat(nodeA.canAddMixin(MIXIN_TYPE_B), is(true)); nodeA.addMixin(MIXIN_TYPE_B); nodeA.addNode(CHILD_NODE_B); session.save(); Node newRootNode = session.getRootNode(); Node newNodeA = newRootNode.getNode("a"); Node newNodeB = newNodeA.getNode(CHILD_NODE_B); assertThat(newNodeB, is(notNullValue())); assertThat(newNodeB.getDefinition().getDeclaringNodeType().getName(), is(MIXIN_TYPE_B)); }
@Test @FixFor( "MODE-2424" ) public void shouldAllowAddingMixinOnLockedNodeForLockOwner() throws Exception { final AbstractJcrNode testNode = session.getRootNode().addNode("test"); final String path = testNode.getPath(); testNode.addMixin("mix:lockable"); session.save(); session.getWorkspace().getLockManager().lock(path, false, true, Long.MAX_VALUE, session.getUserID()); testNode.addMixin("mix:created"); session.save(); }
@Test @FixFor( "MODE-2047" ) public void shouldNotAllowLockOnTransientNode() throws Exception { AbstractJcrNode testNode = session.getRootNode().addNode("test"); testNode.addMixin("mix:lockable"); JcrLockManager lockManager = session.lockManager(); try { lockManager.lock(testNode, true, false, Long.MAX_VALUE, null); fail("Transient nodes should not be locked"); } catch (InvalidItemStateException e) { // expected } }
@Test @FixFor( "MODE-2156" ) public void settingTheSameReferencePropertyMultipleTimeShouldNotIncreaseTheRefCount() throws Exception { JcrRootNode rootNode = session.getRootNode(); AbstractJcrNode a = rootNode.addNode("A"); a.addMixin("mix:referenceable"); org.modeshape.jcr.api.ValueFactory valueFactory = session.getValueFactory(); Node testNode = rootNode.addNode("test"); Value simpleReference = valueFactory.createValue(a); testNode.setProperty("ref", simpleReference); testNode.setProperty("ref", simpleReference); testNode.setProperty("ref", simpleReference); session.save(); testNode.getProperty("ref").remove(); session.save(); try { testNode.getProperty("ref").getNode(); fail("Target node for simple reference property should not be found"); } catch (javax.jcr.PathNotFoundException pne) { // expected } a.remove(); session.save(); testNode.remove(); session.save(); }
public void shouldSetMergeFailedPropertyIfNodeIsCheckedIn() throws Exception { session.getRootNode().addNode("record").addMixin("mix:versionable"); session.save(); VersionManager versionManager = session.getWorkspace().getVersionManager();
@Override @Before public void beforeEach() throws Exception { super.beforeEach(); stringFactory = session.stringFactory(); binaryValue = "This is a binary value".getBytes(); dateValue = session.dateFactory().create(); doubleValue = 3.14159d; longValue = 100L; booleanValue = true; stringValue = "stringValue"; nameValue = "acme:SomeName"; pathValue = "/Cars/Hybrid/Toyota Highlander/acme:SomethingElse"; // Add the mixin to the 'Cars' node ... cars = session.getNode("/Cars"); cars.addMixin("mixinWithAllPropTypes"); altima = session.getNode("/Cars/Hybrid/Nissan Altima"); altima.addMixin("mix:referenceable"); // Set each property ... cars.setProperty("booleanProperty", booleanValue); cars.setProperty("dateProperty", dateValue.toCalendar()); cars.setProperty("doubleProperty", doubleValue); cars.setProperty("binaryProperty", new ByteArrayInputStream(binaryValue)); cars.setProperty("longProperty", longValue); cars.setProperty("referenceProperty", altima); cars.setProperty("stringProperty", stringValue); cars.setProperty("pathProperty", pathValue); cars.setProperty("nameProperty", nameValue); cars.setProperty("undefinedProperty", "100"); }
public void shouldSetMergeFailedPropertyIfNodeIsCheckedIn2() throws Exception { session.getRootNode().addNode("record").addMixin("mix:versionable"); session.save(); VersionManager versionManager = session.getWorkspace().getVersionManager();
public void shouldMergeEventualSuccessorVersions() throws Exception { session.getRootNode().addNode("record").addMixin("mix:versionable"); session.save(); VersionManager versionManager = session.getWorkspace().getVersionManager();
outputNode.addMixin(DERIVED_NODE_TYPE_NAME); outputNode.setProperty(DERIVED_FROM_PROPERTY_NAME, work.getSelectedPath());
@Test @FixFor( "MODE-2342" ) public void lockTokensShouldBeRemovedFromSessionUponLogout() throws Exception { final AbstractJcrNode testNode = session.getRootNode().addNode("test"); final String path = testNode.getPath(); testNode.addMixin("mix:lockable"); session.save(); final Lock lock = session.getWorkspace().getLockManager().lock(path, false, false, Long.MAX_VALUE, session.getUserID()); final String token = lock.getLockToken(); Assert.assertNotNull(token); session.logout(); Session session2 = repository.login(); final LockManager lockManager = session2.getWorkspace().getLockManager(); lockManager.addLockToken(token); Assert.assertTrue("New session should now own the lock.", lockManager.getLock(path).isLockOwningSession()); }
@Test @FixFor( "MODE-2450" ) public void shouldCleanupCorruptedLocks() throws Exception { final AbstractJcrNode testNode = session.getRootNode().addNode("test"); final String path = testNode.getPath(); testNode.addMixin("mix:lockable"); session.save(); final org.modeshape.jcr.RepositoryLockManager.Lock lock = (RepositoryLockManager.Lock) session.getWorkspace().getLockManager().lock(path, false, false, Long.MAX_VALUE, session.getUserID()); Assert.assertNotNull(lock); session.logout(); //forcibly remove the lock node from the system area... String lockKey = lock.lockKey().toString(); assertTrue(runInTransaction(() -> repository.documentStore().remove(lockKey))); //and then force a refresh RepositoryLockManager lockManager = repository.lockManager(); lockManager.refreshFromSystem(); //check that the lock has been removed session = repository.login(); assertFalse(session.getWorkspace().getLockManager().isLocked("/test")); // issue another refresh and verify the node is still unlocked lockManager.refreshFromSystem(); assertFalse(session.getWorkspace().getLockManager().isLocked("/test")); }
PropertyFactory propertyFactory = session.context().getPropertyFactory(); AbstractJcrNode node = session.getRootNode().addNode("/test"); node.addMixin("mix:lockable"); session.save(); session.lockManager().lock(node, true, false, Long.MAX_VALUE, null);