jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Torsten Curdt" <tcu...@apache.org>
Subject versioning test
Date Tue, 09 Dec 2008 12:41:35 GMT
Could someone please point out what is wrong with this use of the API?
I only get 2 versions.

	private Node write(Session session, String path, String content)
throws RepositoryException {
		
		Node root = session.getRootNode();
		Node node;
		
		if (root.hasNode(path)) {
			node = root.getNode(path);			
		} else {
			node = root.addNode("jcr:content", "nt:resource");
			node.setProperty("jcr:mimeType", "text/plain");
		    node.setProperty("jcr:encoding", "utf-8");	    	
		    node.addMixin("mix:versionable");
		}

		node.setProperty("jcr:data", content);

		Calendar lastModified = Calendar.getInstance();
	    lastModified.setTimeInMillis(System.currentTimeMillis());
	    node.setProperty("jcr:lastModified", lastModified);
		
	    session.save();
	
	    node.checkin();
	
		return node;
	}
	
	public void testVersioning() throws Exception {
		
		write(session, "test", "test1");
		write(session, "test", "test2");
		write(session, "test", "test3");
		Node node = write(session, "test", "test4");
		
        VersionHistory history = node.getVersionHistory();

        int versions = 0;

        for (VersionIterator it = history.getAllVersions(); it.hasNext();) {
			Version version = (Version) it.next();			
			System.out.println(version.getUUID() + " (" +
version.getCreated().getTime() + ")");
			versions++;
        }

        assertEquals(4, versions);
	}

Mime
View raw message