Search in sources :

Example 21 with VersionIterator

use of javax.jcr.version.VersionIterator in project jackrabbit by apache.

the class RestoreTest method testRestoreInvalidVersion2.

/**
     * VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.
     *
     * @throws RepositoryException
     */
@SuppressWarnings("deprecation")
public void testRestoreInvalidVersion2() throws RepositoryException {
    String invalidName;
    do {
        invalidName = createRandomString(3);
        for (VersionIterator it = versionableNode.getVersionHistory().getAllVersions(); it.hasNext(); ) {
            Version v = it.nextVersion();
            if (invalidName.equals(v.getName())) {
                invalidName = null;
                break;
            }
        }
    } while (invalidName == null);
    try {
        versionableNode.restore(invalidName, true);
        fail("VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.");
    } catch (VersionException e) {
    // ok
    }
}
Also used : Version(javax.jcr.version.Version) VersionIterator(javax.jcr.version.VersionIterator) VersionException(javax.jcr.version.VersionException)

Example 22 with VersionIterator

use of javax.jcr.version.VersionIterator in project jackrabbit by apache.

the class RestoreTest method testRestoreInvalidVersion2Jcr2.

/**
     * VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.
     *
     * @throws RepositoryException
     */
public void testRestoreInvalidVersion2Jcr2() throws RepositoryException {
    String invalidName;
    do {
        invalidName = createRandomString(3);
        for (VersionIterator it = versionManager.getVersionHistory(versionableNode.getPath()).getAllVersions(); it.hasNext(); ) {
            Version v = it.nextVersion();
            if (invalidName.equals(v.getName())) {
                invalidName = null;
                break;
            }
        }
    } while (invalidName == null);
    try {
        versionManager.restore(versionableNode.getPath(), invalidName, true);
        fail("VersionException expected on Node.restore(String, boolean) if the specified version is not part of this node's version history.");
    } catch (VersionException e) {
    // ok
    }
}
Also used : Version(javax.jcr.version.Version) VersionIterator(javax.jcr.version.VersionIterator) VersionException(javax.jcr.version.VersionException)

Example 23 with VersionIterator

use of javax.jcr.version.VersionIterator in project jackrabbit by apache.

the class VersionHistoryTest method testInitiallyGetAllLinearVersionsContainsTheRootAndTheBaseVersion.

/**
     * Test if the iterator returned by {@link javax.jcr.version.VersionHistory#getAllLinearVersions()}
     * contains both the root and the base version upon creation of the version history.
     * @since JCR 2.0
     */
public void testInitiallyGetAllLinearVersionsContainsTheRootAndTheBaseVersion() throws RepositoryException {
    VersionManager vm = versionableNode.getSession().getWorkspace().getVersionManager();
    List<String> lvh = new ArrayList<String>();
    for (VersionIterator it = vHistory.getAllLinearVersions(); it.hasNext(); ) {
        lvh.add(it.nextVersion().getName());
    }
    String rootVersion = vm.getVersionHistory(versionableNode.getPath()).getRootVersion().getName();
    String baseVersion = vm.getBaseVersion(versionableNode.getPath()).getName();
    assertTrue("root version " + rootVersion + " must be part of the linear version history: " + lvh, lvh.contains(rootVersion));
    assertTrue("base version " + baseVersion + " must be part of the linear version history: " + lvh, lvh.contains(baseVersion));
}
Also used : ArrayList(java.util.ArrayList) VersionIterator(javax.jcr.version.VersionIterator) VersionManager(javax.jcr.version.VersionManager)

Example 24 with VersionIterator

use of javax.jcr.version.VersionIterator in project jackrabbit by apache.

the class VersionHistoryTest method testGetAllVersions.

/**
     * Test that {@link VersionHistory#getAllVersions()} returns an iterator
     * containing the root version and all versions that have been created by
     * Node.checkin().
     *
     * @see javax.jcr.version.VersionHistory#getAllVersions()
     */
@SuppressWarnings("deprecation")
public void testGetAllVersions() throws RepositoryException {
    int cnt = 5;
    Map<String, Version> versions = new HashMap<String, Version>();
    Version v = vHistory.getRootVersion();
    versions.put(v.getUUID(), v);
    for (int i = 0; i < cnt; i++) {
        v = versionableNode.checkin();
        versions.put(v.getUUID(), v);
        versionableNode.checkout();
    }
    VersionIterator it = vHistory.getAllVersions();
    while (it.hasNext()) {
        v = it.nextVersion();
        if (!versions.containsKey(v.getUUID())) {
            fail("VersionHistory.getAllVersions() must only contain the root version and versions, that have been created by a Node.checkin() call.");
        }
        versions.remove(v.getUUID());
    }
    assertTrue("VersionHistory.getAllVersions() must contain the root version and all versions that have been created with a Node.checkin() call.", versions.isEmpty());
}
Also used : HashMap(java.util.HashMap) Version(javax.jcr.version.Version) VersionIterator(javax.jcr.version.VersionIterator)

Example 25 with VersionIterator

use of javax.jcr.version.VersionIterator in project jackrabbit by apache.

the class LsVersions method execute.

/**
     * {@inheritDoc}
     */
public boolean execute(Context ctx) throws Exception {
    String path = (String) ctx.get(this.pathKey);
    Node n = CommandHelper.getNode(ctx, path);
    // header
    int[] width = new int[] { 20, 50 };
    String[] header = new String[] { bundle.getString("word.version"), bundle.getString("word.labels") };
    // print header
    PrintHelper.printRow(ctx, width, header);
    // print separator
    PrintHelper.printSeparatorRow(ctx, width, '-');
    VersionIterator iter = n.getVersionHistory().getAllVersions();
    while (iter.hasNext()) {
        Version v = iter.nextVersion();
        Collection row = new ArrayList();
        row.add(v.getName());
        row.add(Arrays.asList(n.getVersionHistory().getVersionLabels(v)));
        PrintHelper.printRow(ctx, width, row);
    }
    return false;
}
Also used : Version(javax.jcr.version.Version) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) VersionIterator(javax.jcr.version.VersionIterator) Collection(java.util.Collection)

Aggregations

VersionIterator (javax.jcr.version.VersionIterator)29 Version (javax.jcr.version.Version)16 VersionHistory (javax.jcr.version.VersionHistory)12 Node (javax.jcr.Node)9 ArrayList (java.util.ArrayList)8 RepositoryException (javax.jcr.RepositoryException)6 VersionException (javax.jcr.version.VersionException)5 VersionManager (javax.jcr.version.VersionManager)4 Test (org.junit.Test)4 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)3 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)3 HashMap (java.util.HashMap)2 Session (javax.jcr.Session)2 DavException (org.apache.jackrabbit.webdav.DavException)2 DavResource (org.apache.jackrabbit.webdav.DavResource)2 HrefProperty (org.apache.jackrabbit.webdav.property.HrefProperty)2 VersionResource (org.apache.jackrabbit.webdav.version.VersionResource)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1