Search in sources :

Example 31 with VersionIterator

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

the class ReadVersionContentTest method testGetAllVersions.

/**
 * @since oak
 */
@Test
public void testGetAllVersions() throws Exception {
    // accessing the version history must be allowed if the versionable node
    // is readable to the editing test session.
    Node testNode = testSession.getNode(versionablePath);
    VersionHistory vh = testNode.getVersionHistory();
    VersionIterator versionIterator = vh.getAllVersions();
}
Also used : Node(javax.jcr.Node) VersionIterator(javax.jcr.version.VersionIterator) VersionHistory(javax.jcr.version.VersionHistory) Test(org.junit.Test)

Example 32 with VersionIterator

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

the class ReadVersionContentTest method testGetAllLinearVersions.

/**
 * @since oak
 */
@Test
public void testGetAllLinearVersions() throws Exception {
    // accessing the version history must be allowed if the versionable node
    // is readable to the editing test session.
    Node testNode = testSession.getNode(versionablePath);
    VersionHistory vh = testNode.getVersionHistory();
    VersionIterator versionIterator = vh.getAllLinearVersions();
}
Also used : Node(javax.jcr.Node) VersionIterator(javax.jcr.version.VersionIterator) VersionHistory(javax.jcr.version.VersionHistory) Test(org.junit.Test)

Example 33 with VersionIterator

use of javax.jcr.version.VersionIterator in project acs-aem-commons by Adobe-Consulting-Services.

the class ReplicateVersionImplTest method testReplicate.

@Test
public final void testReplicate() throws Exception {
    final String[] agents = new String[] { "agent1" };
    final String[] rootPaths = new String[] { "/content/geometrixx/en" };
    final Date date = getDate("2013-12-21T00:00:00");
    final Date vDate = getDate("2013-12-01T00:00:00");
    final Date vDate1 = getDate("2013-12-22T00:00:00");
    final Calendar cal = GregorianCalendar.getInstance();
    cal.setTime(vDate);
    final Calendar cal1 = GregorianCalendar.getInstance();
    cal1.setTime(vDate1);
    final ResourceResolver resourceResolver = mock(ResourceResolver.class);
    final Session session = mock(Session.class);
    final Workspace wk = mock(Workspace.class);
    final VersionManager vm = mock(VersionManager.class);
    final VersionHistory vh = mock(VersionHistory.class);
    final VersionIterator vi = mock(VersionIterator.class);
    final Version v = mock(Version.class);
    final Version v1 = mock(Version.class);
    when(v.getCreated()).thenReturn(cal);
    when(v1.getCreated()).thenReturn(cal1);
    when(v.getName()).thenReturn("version1");
    when(vi.nextVersion()).thenReturn(v, v1);
    when(vi.hasNext()).thenReturn(true, true, false);
    when(session.getWorkspace()).thenReturn(wk);
    when(wk.getVersionManager()).thenReturn(vm);
    when(resourceResolver.adaptTo(Session.class)).thenReturn(session);
    when(vm.getVersionHistory(rootPaths[0])).thenReturn(vh);
    when(vh.getAllVersions()).thenReturn(vi);
    final Resource res = mock(Resource.class);
    when(res.getPath()).thenReturn(rootPaths[0]);
    final Node node = mock(Node.class);
    when(resourceResolver.getResource(rootPaths[0])).thenReturn(res);
    when(res.adaptTo(Node.class)).thenReturn(node);
    when(session.getNode(rootPaths[0])).thenReturn(node);
    when(node.hasNode(NameConstants.NN_CONTENT)).thenReturn(true);
    final Node node1 = mock(Node.class);
    when(node1.getPath()).thenReturn(rootPaths[0]);
    when(node.getNode(NameConstants.NN_CONTENT)).thenReturn(node1);
    when(node1.isNodeType(JcrConstants.MIX_VERSIONABLE)).thenReturn(true);
    when(node.isNodeType("nt:hierarchyNode")).thenReturn(true);
    final Resource res1 = mock(Resource.class);
    final Resource res2 = mock(Resource.class);
    @SuppressWarnings("unchecked") final Iterator<Resource> itr = mock(Iterator.class);
    when(resourceResolver.listChildren(res)).thenReturn(itr);
    when(itr.hasNext()).thenReturn(true, true, false);
    when(itr.next()).thenReturn(res1, res2);
    when(res1.adaptTo(Node.class)).thenReturn(node1);
    when(res2.adaptTo(Node.class)).thenReturn(node1);
    when(node1.isNodeType("nt:hierarchyNode")).thenReturn(false);
    List<ReplicationResult> list = rpvs.replicate(resourceResolver, rootPaths, agents, date);
    Assert.assertEquals("/content/geometrixx/en", list.get(0).getPath());
    Assert.assertEquals(Status.replicated, list.get(0).getStatus());
    Assert.assertEquals("version1", list.get(0).getVersion());
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Node(javax.jcr.Node) Resource(org.apache.sling.api.resource.Resource) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory) Date(java.util.Date) ReplicationResult(com.adobe.acs.commons.replication.ReplicationResult) Version(javax.jcr.version.Version) ReplicateVersion(com.adobe.acs.commons.replication.ReplicateVersion) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) VersionIterator(javax.jcr.version.VersionIterator) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace) Test(org.junit.Test)

Example 34 with VersionIterator

use of javax.jcr.version.VersionIterator in project acs-aem-commons by Adobe-Consulting-Services.

the class VersionServiceImplTest method lastVersion_oneVersion_returnVersion.

@Test
public void lastVersion_oneVersion_returnVersion() throws Exception {
    // given
    VersionIterator versionIterator = mock(VersionIterator.class, withSettings().extraInterfaces(Iterator.class));
    when(versionIterator.hasNext()).thenReturn(true, false);
    Version last = mock(Version.class);
    when(versionIterator.next()).thenReturn(last);
    Resource resource = mockResource(versionIterator);
    // when
    Version result = underTest.lastVersion(resource);
    // then
    assertThat(result, is(last));
}
Also used : Version(javax.jcr.version.Version) Iterator(java.util.Iterator) VersionIterator(javax.jcr.version.VersionIterator) Resource(org.apache.sling.api.resource.Resource) VersionIterator(javax.jcr.version.VersionIterator) Test(org.junit.Test)

Example 35 with VersionIterator

use of javax.jcr.version.VersionIterator in project acs-aem-commons by Adobe-Consulting-Services.

the class VersionServiceImplTest method lastVersion_error_returnNull.

@Test
public void lastVersion_error_returnNull() throws Exception {
    // given
    VersionIterator versionIterator = mock(VersionIterator.class, withSettings().extraInterfaces(Iterator.class));
    when(versionIterator.hasNext()).thenThrow(RepositoryException.class);
    Resource resource = mockResource(versionIterator);
    // when
    Version result = underTest.lastVersion(resource);
    // then
    assertNull(result);
}
Also used : Version(javax.jcr.version.Version) Iterator(java.util.Iterator) VersionIterator(javax.jcr.version.VersionIterator) Resource(org.apache.sling.api.resource.Resource) VersionIterator(javax.jcr.version.VersionIterator) Test(org.junit.Test)

Aggregations

VersionIterator (javax.jcr.version.VersionIterator)45 Version (javax.jcr.version.Version)31 VersionHistory (javax.jcr.version.VersionHistory)23 Node (javax.jcr.Node)18 RepositoryException (javax.jcr.RepositoryException)12 VersionManager (javax.jcr.version.VersionManager)12 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 Session (javax.jcr.Session)8 Resource (org.apache.sling.api.resource.Resource)7 VersionException (javax.jcr.version.VersionException)5 Iterator (java.util.Iterator)4 NodeType (javax.jcr.nodetype.NodeType)4 List (java.util.List)3 NodeIterator (javax.jcr.NodeIterator)3 Workspace (javax.jcr.Workspace)3 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)3 JcrDavException (org.apache.jackrabbit.webdav.jcr.JcrDavException)3 KyloVersion (com.thinkbiganalytics.KyloVersion)2 JcrMetadataAccess (com.thinkbiganalytics.metadata.modeshape.JcrMetadataAccess)2