/** * Tests if <code>Version.getSession()</code> returns the right session */ public void testGetSession() throws Exception { assertSame("Version.getSession() did not return the right session", superuser, version.getSession()); }
/** * Tests if <code>Version.addNode(String)</code> and * <code>Version.addNode(String, String)</code> throw a {@link * javax.jcr.nodetype.ConstraintViolationException} */ public void testAddNode() throws Exception { try { version.addNode(nodeName4); version.getSession().save(); fail("Version should be read-only: Version.addNode(String) did not throw a ConstraintViolationException"); } catch (ConstraintViolationException success) { } try { version.addNode(nodeName4, ntBase); version.getSession().save(); fail("Version should be read-only: Version.addNode(String,String) did not throw a ConstraintViolationException"); } catch (ConstraintViolationException success) { } }
public static void restore(Version version) { try { getVersionManager(version.getSession()).restore(version, true); } catch (RepositoryException e) { throw new MetadataRepositoryException("Failed to restore version: " + version, e); } }
/** * Tests if <code>Version.unlock()</code> throws a {@link * javax.jcr.lock.LockException} */ public void testUnlockJcr2() throws Exception { ensureLockingSupported(); try { version.getSession().getWorkspace().getLockManager().unlock(version.getPath()); fail("Version should not be lockable: Version.unlock() did not throw a LockException"); } catch (LockException success) { } }
/** * Tests if <code>Version.holdsLock()</code> returns <code>false</code> */ public void testHoldsLockJcr2() throws Exception { ensureLockingSupported(); assertFalse("Version.holdsLock() did not return false", version.getSession().getWorkspace().getLockManager().holdsLock(version.getPath())); }
/** * Tests if <code>Version.isLocked()</code> returns <code>false</code> */ public void testIsLockedJcr2() throws Exception { ensureLockingSupported(); assertFalse("Version.isLocked() did not return false", version.getSession().getWorkspace().getLockManager().isLocked(version.getPath())); }
/** * Tests if <code>Version.getLock()</code> throws a {@link * javax.jcr.lock.LockException} */ public void testGetLockJcr2() throws Exception { ensureLockingSupported(); try { version.getSession().getWorkspace().getLockManager().getLock(version.getPath()); fail("Version should not be lockable: Version.getLock() did not throw a LockException"); } catch (LockException success) { } }
version.getSession().save(); fail("Version should be read-only: Version.setProperty(String,String[]) did not throw a ConstraintViolationException"); } catch (ConstraintViolationException success) { version.getSession().save(); fail("Version should be read-only: Version.setProperty(String,String[],int) did not throw a ConstraintViolationException"); } catch (ConstraintViolationException success) { version.getSession().save(); fail("Version should be read-only: Version.setProperty(String,Value[]) did not throw a ConstraintViolationException"); } catch (ConstraintViolationException success) { version.getSession().save(); fail("Version should be read-only: Version.setProperty(String,Value[],int]) did not throw a ConstraintViolationException"); } catch (ConstraintViolationException success) { version.getSession().save(); fail("Version should be read-only: Version.setProperty(String,boolean) did not throw a ConstraintViolationException"); } catch (ConstraintViolationException success) { version.getSession().save(); fail("Version should be read-only: Version.setProperty(String,double) did not throw a ConstraintViolationException"); } catch (ConstraintViolationException success) { InputStream inpStream = new ByteArrayInputStream(bytes); version.setProperty(propertyName1, inpStream); version.getSession().save(); fail("Version should be read-only: Version.setProperty(String,InputStream) did not throw a ConstraintViolationException"); } catch (ConstraintViolationException 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); }
/** * Tests if <code>Version.lock(boolean, boolean)</code> throws a {@link * LockException} */ public void testLockJcr2() throws Exception { ensureLockingSupported(); LockManager lockManager = version.getSession().getWorkspace().getLockManager(); String path = version.getPath(); try { lockManager.lock(path, true, true, 60, ""); fail("Version should not be lockable: Version.lock(true,true) did not throw a LockException"); } catch (LockException success) { } try { lockManager.lock(path, true, false, 60, ""); fail("Version should not be lockable: Version.lock(true,false) did not throw a LockException"); } catch (LockException success) { } try { lockManager.lock(path, false, true, 60, ""); fail("Version should not be lockable: Version.lock(false,true) did not throw a LockException"); } catch (LockException success) { } try { lockManager.lock(path, false, false, 60, ""); fail("Version should not be lockable: Version.lock(false,false) did not throw a LockException"); } catch (LockException success) { } }
/** * Returns the NodeState of the given Node and asserts that the state is * listed in the hierarchy built by this Session. If the version * was obtained from a different session, the 'corresponding' version * state for this session is retrieved. * * @param version * @return the NodeState associated with the specified version. */ NodeState getVersionState(Version version) throws RepositoryException { NodeState nodeState; if (version.getSession() == this) { nodeState = (NodeState) ((NodeImpl) version).getItemState(); } else { Path p = getQPath(version.getPath()); Path parentPath = p.getAncestor(1); HierarchyEntry parentEntry = getHierarchyManager().lookup(parentPath); if (parentEntry != null) { // make sure the parent entry is up to date parentEntry.invalidate(false); } nodeState = getHierarchyManager().getNodeState(p); } return nodeState; } //------------------------------------------------------< check methods >---
/** * Returns the NodeState of the given Node and asserts that the state is * listed in the hierarchy built by this Session. If the version * was obtained from a different session, the 'corresponding' version * state for this session is retrieved. * * @param version * @return the NodeState associated with the specified version. */ NodeState getVersionState(Version version) throws RepositoryException { NodeState nodeState; if (version.getSession() == this) { nodeState = (NodeState) ((NodeImpl) version).getItemState(); } else { Path p = getQPath(version.getPath()); Path parentPath = p.getAncestor(1); HierarchyEntry parentEntry = getHierarchyManager().lookup(parentPath); if (parentEntry != null) { // make sure the parent entry is up to date parentEntry.invalidate(false); } nodeState = getHierarchyManager().getNodeState(p); } return nodeState; } //------------------------------------------------------< check methods >---
protected WorkflowDescriptor load() { try { Session session = UserSession.get().getJcrSession(); WorkflowManager workflowManager = ((HippoWorkspace) session.getWorkspace()).getWorkflowManager(); Node node = getNode(session); if (node.isNodeType(JcrConstants.NT_FROZEN_NODE)) { Version version = (Version) node.getParent(); String docId = version.getContainingHistory().getVersionableIdentifier(); Node docNode = version.getSession().getNodeByIdentifier(docId); if (docNode.getParent().isNodeType(HippoNodeType.NT_HANDLE)) { Node handle = docNode.getParent(); return workflowManager.getWorkflowDescriptor(category, handle); } else { return workflowManager.getWorkflowDescriptor(category, docNode); } } else { return workflowManager.getWorkflowDescriptor(category, node); } } catch (RepositoryException ex) { return null; } }
if (!v.getSession().getWorkspace().getName().equals(session.getWorkspace().getName())) ((SessionImpl)v.getSession()).getTransientNodesManager().getTransactManager(); corrNode = (NodeData)vDataManager.getItemData(versionableIdentifier); if (corrNode != null)