/** * Tests if <code>VersionHistory.getSession()</code> returns the right * session */ public void testGetSession() throws Exception { assertSame("VersionHistory.getSession() did not return the right session", superuser, vHistory.getSession()); }
/** * Tests if <code>VersionHistory.addMixin(String)</code> throws a {@link * javax.jcr.nodetype.ConstraintViolationException} */ public void testAddMixin() throws Exception { try { vHistory.addMixin(mixVersionable); vHistory.getSession().save(); fail("VersionHistory should be read-only: VersionHistory.addMixin(String) did not throw a ConstraintViolationException"); } catch (ConstraintViolationException success) { } }
/** * Tests if <code>VersionHistory.addNode(String)</code> and * <code>VersionHistory.addNode(String, String)</code> throw a {@link * javax.jcr.nodetype.ConstraintViolationException} */ public void testAddNode() throws Exception { try { vHistory.addNode(nodeName4); vHistory.getSession().save(); fail("VersionHistory should be read-only: VersionHistory.addNode(String) did not throw a ConstraintViolationException"); } catch (ConstraintViolationException success) { } try { vHistory.addNode(nodeName4, ntBase); vHistory.getSession().save(); fail("VersionHistory should be read-only: VersionHistory.addNode(String,String) did not throw a ConstraintViolationException"); } catch (ConstraintViolationException success) { } }
/** * Tests if <code>VersionHistory.getLock()</code> throws an {@link * javax.jcr.lock.LockException} */ public void testGetLockJcr2() throws Exception { ensureLockingSupported(); try { vHistory.getSession().getWorkspace().getLockManager().getLock(vHistory.getPath()); fail("VersionHistory should not be lockable: VersionHistory.getLock() did not throw a LockException"); } catch (LockException success) { } }
/** * Tests if <code>VersionHistory.holdsLock()</code> returns * <code>false</code> */ public void testHoldsLockJcr2() throws Exception { ensureLockingSupported(); assertFalse("VersionHistory.holdsLock() did not return false", vHistory.getSession().getWorkspace().getLockManager().holdsLock(vHistory.getPath())); }
/** * Tests if <code>VersionHistory.isLocked()</code> returns * <code>false</code> */ public void testIsLockedJcr2() throws Exception { ensureLockingSupported(); assertFalse("VersionHistory.isLocked() did not return false", vHistory.getSession().getWorkspace().getLockManager().isLocked(vHistory.getPath())); }
/** * Tests if <code>VersionHistory.unlock()</code> throws a {@link * javax.jcr.lock.LockException} */ public void testUnlockJcr2() throws Exception { ensureLockingSupported(); try { vHistory.getSession().getWorkspace().getLockManager().unlock(vHistory.getPath()); fail("VersionHistory should not be lockable: VersionHistory.unlock() did not throw a LockException"); } catch (LockException success) { } }
vHistory.getSession().save(); fail("VersionHistory should be read-only: VersionHistory.setProperty(String,String[]) did not throw a ConstraintViolationException"); } catch (ConstraintViolationException success) { vHistory.getSession().save(); fail("VersionHistory should be read-only: VersionHistory.setProperty(String,String[],int) did not throw a ConstraintViolationException"); } catch (ConstraintViolationException success) { vHistory.getSession().save(); fail("VersionHistory should be read-only: VersionHistory.setProperty(String,Value[]) did not throw a ConstraintViolationException"); } catch (ConstraintViolationException success) { vHistory.getSession().save(); fail("VersionHistory should be read-only: VersionHistory.setProperty(String,Value[],int]) did not throw a ConstraintViolationException"); } catch (ConstraintViolationException success) { vHistory.getSession().save(); fail("VersionHistory should be read-only: VersionHistory.setProperty(String,boolean) did not throw a ConstraintViolationException"); } catch (ConstraintViolationException success) { vHistory.getSession().save(); fail("VersionHistory should be read-only: VersionHistory.setProperty(String,double) did not throw a ConstraintViolationException"); } catch (ConstraintViolationException success) { InputStream inpStream = new ByteArrayInputStream(bytes); vHistory.setProperty(propertyName1, inpStream); vHistory.getSession().save(); fail("VersionHistory should be read-only: VersionHistory.setProperty(String,InputStream) did not throw a ConstraintViolationException"); } catch (ConstraintViolationException success) {
private static void assertVersionablePath(final VersionHistory history, final String versionablePath) throws RepositoryException { final String workspaceName = history.getSession().getWorkspace().getName(); assertTrue(history.isNodeType(MIX_REP_VERSIONABLE_PATHS)); assertTrue(history.hasProperty(workspaceName)); final Property pathProperty = history.getProperty(workspaceName); assertEquals(PropertyType.PATH, pathProperty.getType()); assertEquals(versionablePath, pathProperty.getString()); }
/** * Tests if <code>VersionHistory.lock(boolean, boolean)</code> throws a * {@link javax.jcr.lock.LockException} */ public void testLockJcr2() throws Exception { ensureLockingSupported(); LockManager lockManager = vHistory.getSession().getWorkspace().getLockManager(); String path = vHistory.getPath(); try { lockManager.lock(path, true, true, 60, ""); fail("VersionHistory should not be lockable: VersionHistory.lock(true,true) did not throw a LockException"); } catch (LockException success) { } try { lockManager.lock(path, true, false, 60, ""); fail("VersionHistory should not be lockable: VersionHistory.lock(true,false) did not throw a LockException"); } catch (LockException success) { } try { lockManager.lock(path, false, true, 60, ""); fail("VersionHistory should not be lockable: VersionHistory.lock(false,true) did not throw a LockException"); } catch (LockException success) { } try { lockManager.lock(path, false, false, 60, ""); fail("VersionHistory should not be lockable: VersionHistory.lock(false,false) did not throw a UnsupportedRepositoryOperationException"); } catch (LockException success) { } }
@Test public void getVersionForALabel() throws RepositoryException { // GIVEN String label = "label"; VersionManager versionManager = VersionManager.getInstance(); // Create node structure Node node = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE).getRootNode().addNode("test", NodeTypes.Content.NAME); Node firstLevel = node.addNode("first-level", NodeTypes.Content.NAME); firstLevel.setProperty("text", " firstLevel V1"); Node secondLevel = firstLevel.addNode("second-level", NodeTypes.Content.NAME); secondLevel.setProperty("text", " secondLevel V1"); node.getSession().save(); // Create version Version v1 = versionManager.addVersion(node); // Add label v1.getContainingHistory().addVersionLabel(v1.getName(), label, true); Version v2 = versionManager.addVersion(node); assertEquals("magnolia-mgnlVersion", v2.getSession().getWorkspace().getName()); // WHEN Version baseVersion = versionManager.getBaseVersion(node); assertEquals("magnolia-mgnlVersion", baseVersion.getSession().getWorkspace().getName()); VersionHistory versionHistory = versionManager.getVersionHistory(node); assertEquals("magnolia-mgnlVersion", versionHistory.getSession().getWorkspace().getName()); // WHEN boolean haveLabel = versionHistory.hasVersionLabel(v1, label); // THEN assertTrue(haveLabel); }