@Test /** * Name of a versioned node is available in the parent history. Translator takes care of this when * hippo:paths is present on the node, with the parent as one of its values. */ public void testVersionedNode() throws Exception { Node parent = session.getRootNode().addNode("test", "nt:unstructured"); parent.addMixin("mix:versionable"); Node child = parent.addNode("child", "nt:unstructured"); child.addMixin("mix:versionable"); child.setProperty("hippo:paths", new String[] {child.getUUID(), parent.getUUID()}); session.save(); child.checkin(); parent.checkin(); VersionHistory vh = child.getVersionHistory(); parent.checkout(); child.remove(); session.save(); parent.checkin(); VersionIterator versionIter = vh.getAllVersions(); versionIter.nextVersion(); // ignore root Version version = versionIter.nextVersion(); NodeTranslator nt = new NodeTranslator(new JcrNodeModel(version.getNode("jcr:frozenNode"))); assertEquals("child", nt.getNodeName().getObject()); assertTrue(version.getNode("jcr:frozenNode").isNodeType("mix:referenceable")); }
/** * Return the <code>List</code> that contains this <code>DocumentMetadata</code>. * * @return the <code>List</code> that contains this <code>DocumentMetadata</code>. * @throws EcmException if an error occurs. */ public List<DocumentMetadata> getVersionHistory(String filePath) throws EcmException { logger.debug("Loading document version history using path : " + filePath); List<DocumentMetadata> list = new ArrayList<DocumentMetadata>(); try { /** Validate the node path */ this.validateNodePath(filePath); /** Get the version manager */ VersionManager vm = this.session.getWorkspace().getVersionManager(); VersionHistory history = vm.getVersionHistory(filePath); VersionIterator iterator = history.getAllVersions(); iterator.skip(1); while (iterator.hasNext()) { Version version = iterator.nextVersion(); DocumentMetadata meta = this.loadFileVersionMetadata(version); list.add(meta); } } catch (UnsupportedRepositoryOperationException e) { throw new EcmException( "Fail to retrieve version history, check is not supported", e, ErrorCodes.REPOSITROY_ERR_OPERATION_NOT_SUPPORTED); } catch (RepositoryException e) { throw new EcmException( "Fail to retrieve version history", e, ErrorCodes.REPOSITROY_ERR_GENERIC); } logger.debug("Version history loaded for file :" + filePath); return list; }
private void purgeHistory(Node fileNode, Session session, PentahoJcrConstants pentahoJcrConstants) throws RepositoryException { // Delete all previous versions of this node VersionManager versionManager = session.getWorkspace().getVersionManager(); if (JcrRepositoryFileUtils.isPentahoFolder(pentahoJcrConstants, fileNode)) { // go down to children NodeIterator nodes = fileNode.getNodes(); while (nodes.hasNext()) { Node next = (Node) nodes.next(); purgeHistory(next, session, pentahoJcrConstants); } } else if (JcrRepositoryFileUtils.isPentahoFile(pentahoJcrConstants, fileNode) && fileNode.isNodeType(pentahoJcrConstants.getPHO_MIX_VERSIONABLE())) { VersionHistory versionHistory = versionManager.getVersionHistory(fileNode.getPath()); VersionIterator allVersions = versionHistory.getAllVersions(); while (allVersions.hasNext()) { Version next = (Version) allVersions.next(); String name = next.getName(); // Root version cannot be deleted, the remove below will take care of that. if (!JCR_ROOT_VERSION.equals(name)) { versionHistory.removeVersion(name); } } } }
@Override public Node getNodeVersion(final String label) { try { final Session session = getSession(); final Node n = getFrozenNode(label); if (n != null) { return n; } if (isVersioned()) { final VersionHistory hist = session.getWorkspace().getVersionManager().getVersionHistory(getPath()); if (hist.hasVersionLabel(label)) { LOGGER.debug("Found version for {} by label {}.", this, label); return hist.getVersionByLabel(label).getFrozenNode(); } } LOGGER.warn("Unknown version {} with label or uuid {}!", this, label); return null; } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } }
@Override public void updateFile( long companyId, long repositoryId, String fileName, String versionLabel, InputStream is) throws PortalException, SystemException { Session session = null; try { session = JCRFactoryUtil.createSession(); Workspace workspace = session.getWorkspace(); VersionManager versionManager = workspace.getVersionManager(); Node rootNode = getRootNode(session, companyId); Node repositoryNode = getFolderNode(rootNode, repositoryId); if (fileName.contains(StringPool.SLASH)) { String path = fileName.substring(0, fileName.lastIndexOf(StringPool.SLASH)); fileName = fileName.substring(path.length() + 1); repositoryNode = getFolderNode(repositoryNode, path); } Node fileNode = repositoryNode.getNode(fileName); Node contentNode = fileNode.getNode(JCRConstants.JCR_CONTENT); versionManager.checkout(contentNode.getPath()); contentNode.setProperty(JCRConstants.JCR_MIME_TYPE, "text/plain"); ValueFactory valueFactory = session.getValueFactory(); Binary binary = valueFactory.createBinary(is); contentNode.setProperty(JCRConstants.JCR_DATA, binary); contentNode.setProperty(JCRConstants.JCR_LAST_MODIFIED, Calendar.getInstance()); session.save(); Version version = versionManager.checkin(contentNode.getPath()); VersionHistory versionHistory = versionManager.getVersionHistory(contentNode.getPath()); versionHistory.addVersionLabel( version.getName(), versionLabel, PropsValues.DL_STORE_JCR_MOVE_VERSION_LABELS); } catch (PathNotFoundException pnfe) { throw new NoSuchFileException( "{fileName=" + fileName + ", versionLabel=" + versionLabel + "}"); } catch (RepositoryException re) { throw new SystemException(re); } finally { JCRFactoryUtil.closeSession(session); } }
@Override public void addFile(long companyId, long repositoryId, String fileName, InputStream is) throws PortalException, SystemException { Session session = null; try { session = JCRFactoryUtil.createSession(); Workspace workspace = session.getWorkspace(); VersionManager versionManager = workspace.getVersionManager(); Node rootNode = getRootNode(session, companyId); Node repositoryNode = getFolderNode(rootNode, repositoryId); if (fileName.contains(StringPool.SLASH)) { String path = fileName.substring(0, fileName.lastIndexOf(StringPool.SLASH)); fileName = fileName.substring(path.length() + 1); repositoryNode = getFolderNode(repositoryNode, path); } if (repositoryNode.hasNode(fileName)) { throw new DuplicateFileException(fileName); } else { Node fileNode = repositoryNode.addNode(fileName, JCRConstants.NT_FILE); Node contentNode = fileNode.addNode(JCRConstants.JCR_CONTENT, JCRConstants.NT_RESOURCE); contentNode.addMixin(JCRConstants.MIX_VERSIONABLE); contentNode.setProperty(JCRConstants.JCR_MIME_TYPE, "text/plain"); ValueFactory valueFactory = session.getValueFactory(); Binary binary = valueFactory.createBinary(is); contentNode.setProperty(JCRConstants.JCR_DATA, binary); contentNode.setProperty(JCRConstants.JCR_LAST_MODIFIED, Calendar.getInstance()); session.save(); Version version = versionManager.checkin(contentNode.getPath()); VersionHistory versionHistory = versionManager.getVersionHistory(contentNode.getPath()); versionHistory.addVersionLabel(version.getName(), VERSION_DEFAULT, false); } } catch (RepositoryException re) { throw new SystemException(re); } finally { JCRFactoryUtil.closeSession(session); } }
@FixFor("MODE-1624") @Test public void shouldAllowRemovingVersionFromVersionHistoryByRemovingVersionNode() throws Exception { print = false; Node outerNode = session.getRootNode().addNode("outerFolder"); Node innerNode = outerNode.addNode("innerFolder"); Node fileNode = innerNode.addNode("testFile.dat"); fileNode.setProperty("jcr:mimeType", "text/plain"); fileNode.setProperty("jcr:data", "Original content"); session.save(); fileNode.addMixin("mix:versionable"); session.save(); // Make several changes ... String path = fileNode.getPath(); for (int i = 2; i != 7; ++i) { versionManager.checkout(path); fileNode.setProperty("jcr:data", "Original content " + i); session.save(); versionManager.checkin(path); } // Get the version history ... VersionHistory history = versionManager.getVersionHistory(path); if (print) System.out.println("Before: \n" + history); assertThat(history, is(notNullValue())); assertThat(history.getAllLinearVersions().getSize(), is(6L)); // Get the versions ... VersionIterator iter = history.getAllLinearVersions(); Version v1 = iter.nextVersion(); Version v2 = iter.nextVersion(); Version v3 = iter.nextVersion(); Version v4 = iter.nextVersion(); Version v5 = iter.nextVersion(); Version v6 = iter.nextVersion(); assertThat(iter.hasNext(), is(false)); assertThat(v1, is(notNullValue())); assertThat(v2, is(notNullValue())); assertThat(v3, is(notNullValue())); assertThat(v4, is(notNullValue())); assertThat(v5, is(notNullValue())); assertThat(v6, is(notNullValue())); // Remove the 3rd version (that is, i=3) ... // history.removeVersion(versionName); try { v3.remove(); fail("Should not allow removing a protected node"); } catch (ConstraintViolationException e) { // expected } }
/** * Builds from the root version node and from a language the object representation of a versioned * document and its history. * * @param rootVersionNode the root version node (master). * @param lang the aimed content language. * @return the instance of a versioned document. * @throws RepositoryException */ HistorisedDocument buildHistorisedDocument(Node rootVersionNode, String lang) throws RepositoryException { VersionManager versionManager = rootVersionNode.getSession().getWorkspace().getVersionManager(); HistorisedDocument historisedDocument = new HistorisedDocument(fillDocument(rootVersionNode, lang)); try { String path = rootVersionNode.getPath(); VersionHistory history = versionManager.getVersionHistory(path); Version root = history.getRootVersion(); String rootId = ""; if (root != null) { rootId = root.getIdentifier(); } Version base = versionManager.getBaseVersion(path); String baseId = ""; if (base != null) { baseId = base.getIdentifier(); } VersionIterator versionsIterator = history.getAllVersions(); List<SimpleDocumentVersion> documentHistory = new ArrayList<SimpleDocumentVersion>((int) versionsIterator.getSize()); int versionIndex = 0; SimpleDocumentVersion previousVersion = null; while (versionsIterator.hasNext()) { Version version = versionsIterator.nextVersion(); if (!version.getIdentifier().equals(rootId) && !version.getIdentifier().equals(baseId)) { SimpleDocumentVersion versionDocument = new SimpleDocumentVersion( fillDocument(version.getFrozenNode(), lang), historisedDocument); versionDocument.setNodeName(rootVersionNode.getName()); versionDocument.setVersionIndex(versionIndex++); versionDocument.setPreviousVersion(previousVersion); documentHistory.add(versionDocument); previousVersion = versionDocument; } } HistoryDocumentSorter.sortHistory((List) documentHistory); historisedDocument.setHistory(documentHistory); historisedDocument.setVersionIndex(versionIndex); } catch (RepositoryException ex) { if (ex.getCause() instanceof NoSuchItemStateException) { historisedDocument.setHistory(new ArrayList<SimpleDocumentVersion>(0)); } else { throw ex; } } return historisedDocument; }
@Override public void deleteFile(long companyId, long repositoryId, String fileName, String versionLabel) throws PortalException, SystemException { Session session = null; try { session = JCRFactoryUtil.createSession(); Workspace workspace = session.getWorkspace(); VersionManager versionManager = workspace.getVersionManager(); Node rootNode = getRootNode(session, companyId); Node repositoryNode = getFolderNode(rootNode, repositoryId); Node fileNode = repositoryNode.getNode(fileName); Node contentNode = fileNode.getNode(JCRConstants.JCR_CONTENT); VersionHistory versionHistory = versionManager.getVersionHistory(contentNode.getPath()); if (!versionHistory.hasVersionLabel(versionLabel)) { throw new NoSuchFileException( "{fileName=" + fileName + ", versionLabel=" + versionLabel + "}"); } Version version = versionHistory.getVersionByLabel(versionLabel); versionManager.restore(version.getPredecessors()[0], true); versionHistory.removeVersion(version.getName()); session.save(); } catch (PathNotFoundException pnfe) { throw new NoSuchFileException( "{fileName=" + fileName + ", versionLabel=" + versionLabel + "}"); } catch (RepositoryException re) { throw new SystemException(re); } finally { JCRFactoryUtil.closeSession(session); } }
@Test public void testGet() throws VersionException, UnsupportedRepositoryOperationException, InvalidItemStateException, LockException, RepositoryException, IOException, ServletException { SlingHttpServletRequest request = createNiceMock(SlingHttpServletRequest.class); SlingHttpServletResponse response = createNiceMock(SlingHttpServletResponse.class); Resource resource = createNiceMock(Resource.class); Node node = createNiceMock(Node.class); Version version = createNiceMock(Version.class); PropertyIterator propertyIterator = createNiceMock(PropertyIterator.class); VersionHistory versionHistory = createNiceMock(VersionHistory.class); VersionIterator versionIterator = createNiceMock(VersionIterator.class); Node versionNode = createNiceMock(Node.class); Session session = createNiceMock(Session.class); Workspace workspace = createNiceMock(Workspace.class); VersionManager versionManager = createNiceMock(VersionManager.class); EasyMock.expect(request.getResource()).andReturn(resource).anyTimes(); EasyMock.expect(resource.adaptTo(Node.class)).andReturn(node).anyTimes(); PrintWriter pw = new PrintWriter(new ByteArrayOutputStream()); EasyMock.expect(response.getWriter()).andReturn(pw).anyTimes(); EasyMock.expect(node.getSession()).andReturn(session); EasyMock.expect(session.getWorkspace()).andReturn(workspace); EasyMock.expect(workspace.getVersionManager()).andReturn(versionManager); EasyMock.expect(versionManager.getVersionHistory("/foo")).andReturn(versionHistory); EasyMock.expect(node.getPath()).andReturn("/foo").anyTimes(); EasyMock.expect(versionHistory.getAllVersions()).andReturn(versionIterator); EasyMock.expect(versionIterator.getSize()).andReturn(2L); EasyMock.expect(versionIterator.hasNext()).andReturn(true); EasyMock.expect(versionIterator.nextVersion()).andReturn(version); EasyMock.expect(versionIterator.hasNext()).andReturn(true); EasyMock.expect(versionIterator.nextVersion()).andReturn(version); EasyMock.expect(version.getName()).andReturn("NameVersioNode").anyTimes(); EasyMock.expect(version.getNode(JcrConstants.JCR_FROZENNODE)).andReturn(versionNode).anyTimes(); EasyMock.expect(version.getProperties()).andReturn(propertyIterator).anyTimes(); EasyMock.expect(propertyIterator.hasNext()).andReturn(false).anyTimes(); replay(); listVersionsServlet.doGet(request, response); verify(); }
protected Node getFileContentNode( Session session, long companyId, long repositoryId, String fileName, String versionLabel) throws PortalException, SystemException { Node contentNode = null; try { Workspace workspace = session.getWorkspace(); VersionManager versionManager = workspace.getVersionManager(); Node rootNode = getRootNode(session, companyId); Node repositoryNode = getFolderNode(rootNode, repositoryId); Node fileNode = repositoryNode.getNode(fileName); contentNode = fileNode.getNode(JCRConstants.JCR_CONTENT); if (Validator.isNotNull(versionLabel)) { VersionHistory versionHistory = versionManager.getVersionHistory(contentNode.getPath()); if (!versionHistory.hasVersionLabel(versionLabel)) { throw new NoSuchFileException( "{fileName=" + fileName + ", versionLabel=" + versionLabel + "}"); } Version version = versionHistory.getVersionByLabel(versionLabel); contentNode = version.getNode(JCRConstants.JCR_FROZEN_NODE); } } catch (PathNotFoundException pnfe) { throw new NoSuchFileException( "{fileName=" + fileName + ", versionLabel=" + versionLabel + "}"); } catch (RepositoryException re) { throw new SystemException(re); } return contentNode; }
/** * Load the version of file name and version no specified * * @param filePath the full file path * @param versionNo version no of the document * @return the generated Version instance * @throws RepositoryException if there is any problem during loading Version */ private Version getDocumentVersion(String filePath, String versionNo) throws RepositoryException { Version version = null; /** Get the version manager */ VersionManager vm = this.session.getWorkspace().getVersionManager(); VersionHistory history = vm.getVersionHistory(filePath); /** * Get the version iterator and find the exact version, we always need to skip the first node * because this not a real version , just like a head node. */ VersionIterator iterator = history.getAllVersions(); iterator.skip(1); while (iterator.hasNext()) { Version v = iterator.nextVersion(); if (v.getName().equals(versionNo)) { version = v; break; } } return version; }
public void updateFile(long companyId, long repositoryId, String fileName, String newFileName) throws PortalException, SystemException { Session session = null; try { session = JCRFactoryUtil.createSession(); Workspace workspace = session.getWorkspace(); VersionManager versionManager = workspace.getVersionManager(); Node rootNode = getRootNode(session, companyId); Node repositoryNode = getFolderNode(rootNode, repositoryId); if (fileName.contains(StringPool.SLASH)) { String path = fileName.substring(0, fileName.lastIndexOf(StringPool.SLASH)); fileName = fileName.substring(path.length() + 1); repositoryNode = getFolderNode(repositoryNode, path); } Node fileNode = repositoryNode.getNode(fileName); Node contentNode = fileNode.getNode(JCRConstants.JCR_CONTENT); Node newFileNode = repositoryNode.addNode(newFileName, JCRConstants.NT_FILE); Node newContentNode = newFileNode.addNode(JCRConstants.JCR_CONTENT, JCRConstants.NT_RESOURCE); VersionHistory versionHistory = versionManager.getVersionHistory(contentNode.getPath()); String[] versionLabels = versionHistory.getVersionLabels(); for (int i = (versionLabels.length - 1); i >= 0; i--) { Version version = versionHistory.getVersionByLabel(versionLabels[i]); Node frozenContentNode = version.getNode(JCRConstants.JCR_FROZEN_NODE); if (i == (versionLabels.length - 1)) { newContentNode.addMixin(JCRConstants.MIX_VERSIONABLE); } else { versionManager.checkout(newContentNode.getPath()); } newContentNode.setProperty(JCRConstants.JCR_MIME_TYPE, "text/plain"); copyBinaryProperty(frozenContentNode, newContentNode, JCRConstants.JCR_DATA); newContentNode.setProperty(JCRConstants.JCR_LAST_MODIFIED, Calendar.getInstance()); session.save(); Version newVersion = versionManager.checkin(newContentNode.getPath()); VersionHistory newVersionHistory = versionManager.getVersionHistory(newContentNode.getPath()); newVersionHistory.addVersionLabel( newVersion.getName(), versionLabels[i], PropsValues.DL_STORE_JCR_MOVE_VERSION_LABELS); } fileNode.remove(); session.save(); } catch (PathNotFoundException pnfe) { throw new NoSuchFileException(fileName); } catch (RepositoryException re) { throw new SystemException(re); } finally { JCRFactoryUtil.closeSession(session); } }
@Override public void deleteFile(long companyId, long repositoryId, String fileName) throws PortalException, SystemException { Session session = null; // A bug in Jackrabbit requires us to create a dummy node and delete the // version tree manually to successfully delete a file // Create a dummy node try { session = JCRFactoryUtil.createSession(); Workspace workspace = session.getWorkspace(); VersionManager versionManager = workspace.getVersionManager(); Node rootNode = getRootNode(session, companyId); Node repositoryNode = getFolderNode(rootNode, repositoryId); Node fileNode = repositoryNode.getNode(fileName); Node contentNode = fileNode.getNode(JCRConstants.JCR_CONTENT); versionManager.checkout(contentNode.getPath()); contentNode.setProperty(JCRConstants.JCR_MIME_TYPE, "text/plain"); contentNode.setProperty(JCRConstants.JCR_DATA, ""); contentNode.setProperty(JCRConstants.JCR_LAST_MODIFIED, Calendar.getInstance()); session.save(); Version version = versionManager.checkin(contentNode.getPath()); VersionHistory versionHistory = versionManager.getVersionHistory(contentNode.getPath()); versionHistory.addVersionLabel(version.getName(), "0.0", false); } catch (PathNotFoundException pnfe) { throw new NoSuchFileException(fileName); } catch (RepositoryException re) { throw new SystemException(re); } finally { JCRFactoryUtil.closeSession(session); } // Delete version tree try { session = JCRFactoryUtil.createSession(); Workspace workspace = session.getWorkspace(); VersionManager versionManager = workspace.getVersionManager(); Node rootNode = getRootNode(session, companyId); Node repositoryNode = getFolderNode(rootNode, repositoryId); Node fileNode = repositoryNode.getNode(fileName); Node contentNode = fileNode.getNode(JCRConstants.JCR_CONTENT); VersionHistory versionHistory = versionManager.getVersionHistory(contentNode.getPath()); VersionIterator itr = versionHistory.getAllVersions(); while (itr.hasNext()) { Version version = itr.nextVersion(); if (itr.getPosition() == itr.getSize()) { break; } else { if (!StringUtils.equals(JCRConstants.JCR_ROOT_VERSION, version.getName())) { versionHistory.removeVersion(version.getName()); } } } session.save(); } catch (PathNotFoundException pnfe) { throw new NoSuchFileException(fileName); } catch (RepositoryException re) { throw new SystemException(re); } finally { JCRFactoryUtil.closeSession(session); } // Delete file try { session = JCRFactoryUtil.createSession(); Node rootNode = getRootNode(session, companyId); Node repositoryNode = getFolderNode(rootNode, repositoryId); Node fileNode = repositoryNode.getNode(fileName); fileNode.remove(); session.save(); } catch (PathNotFoundException pnfe) { throw new NoSuchFileException(fileName); } catch (RepositoryException re) { throw new SystemException(re); } finally { JCRFactoryUtil.closeSession(session); } }
@FixFor("MODE-1624") @Test public void shouldAllowRemovingVersionFromVersionHistory() throws Exception { print = false; Node outerNode = session.getRootNode().addNode("outerFolder"); Node innerNode = outerNode.addNode("innerFolder"); Node fileNode = innerNode.addNode("testFile.dat"); fileNode.setProperty("jcr:mimeType", "text/plain"); fileNode.setProperty("jcr:data", "Original content"); session.save(); fileNode.addMixin("mix:versionable"); session.save(); // Make several changes ... String path = fileNode.getPath(); for (int i = 2; i != 7; ++i) { versionManager.checkout(path); fileNode.setProperty("jcr:data", "Original content " + i); session.save(); versionManager.checkin(path); } // Get the version history ... VersionHistory history = versionManager.getVersionHistory(path); if (print) System.out.println("Before: \n" + history); assertThat(history, is(notNullValue())); assertThat(history.getAllLinearVersions().getSize(), is(6L)); // Get the versions ... VersionIterator iter = history.getAllLinearVersions(); Version v1 = iter.nextVersion(); Version v2 = iter.nextVersion(); Version v3 = iter.nextVersion(); Version v4 = iter.nextVersion(); Version v5 = iter.nextVersion(); Version v6 = iter.nextVersion(); assertThat(iter.hasNext(), is(false)); String versionName = v3.getName(); assertThat(v1, is(notNullValue())); assertThat(v2, is(notNullValue())); assertThat(v3, is(notNullValue())); assertThat(v4, is(notNullValue())); assertThat(v5, is(notNullValue())); assertThat(v6, is(notNullValue())); // Remove the 3rd version (that is, i=3) ... history.removeVersion(versionName); if (print) System.out.println("After (same history used to remove): \n" + history); assertThat(history.getAllLinearVersions().getSize(), is(5L)); // Get the versions using the history node we already have ... iter = history.getAllLinearVersions(); Version v1a = iter.nextVersion(); Version v2a = iter.nextVersion(); Version v4a = iter.nextVersion(); Version v5a = iter.nextVersion(); Version v6a = iter.nextVersion(); assertThat(iter.hasNext(), is(false)); assertThat(v1a.getName(), is(v1.getName())); assertThat(v2a.getName(), is(v2.getName())); assertThat(v4a.getName(), is(v4.getName())); assertThat(v5a.getName(), is(v5.getName())); assertThat(v6a.getName(), is(v6.getName())); // Get the versions using a fresh history node ... VersionHistory history2 = versionManager.getVersionHistory(path); if (print) System.out.println("After (fresh history): \n" + history2); assertThat(history.getAllLinearVersions().getSize(), is(5L)); iter = history2.getAllLinearVersions(); Version v1b = iter.nextVersion(); Version v2b = iter.nextVersion(); Version v4b = iter.nextVersion(); Version v5b = iter.nextVersion(); Version v6b = iter.nextVersion(); assertThat(iter.hasNext(), is(false)); assertThat(v1b.getName(), is(v1.getName())); assertThat(v2b.getName(), is(v2.getName())); assertThat(v4b.getName(), is(v4.getName())); assertThat(v5b.getName(), is(v5.getName())); assertThat(v6b.getName(), is(v6.getName())); }
@SuppressWarnings("unchecked") @Test public void test() throws ServletException, IOException, UnsupportedRepositoryOperationException, RepositoryException { SlingHttpServletRequest request = createNiceMock(SlingHttpServletRequest.class); SlingHttpServletResponse response = createNiceMock(SlingHttpServletResponse.class); RequestPathInfo requestPathInfo = createNiceMock(RequestPathInfo.class); Resource resource = createNiceMock(Resource.class); Node node = createNiceMock(Node.class); VersionHistory versionHistory = createNiceMock(VersionHistory.class); Version version = createNiceMock(Version.class); Node frozenNode = createNiceMock(Node.class); Property resourceTypeProperty = createNiceMock(Property.class); Capture<Resource> capturedResource = new Capture<Resource>(); RequestDispatcher requestDispatcher = createNiceMock(RequestDispatcher.class); Capture<ServletRequest> capturedRequest = new Capture<ServletRequest>(); Capture<ServletResponse> capturedResponse = new Capture<ServletResponse>(); VersionManager versionManager = createNiceMock(VersionManager.class); Session session = createNiceMock(Session.class); Workspace workspace = createNiceMock(Workspace.class); EasyMock.expect(request.getRequestPathInfo()).andReturn(requestPathInfo); EasyMock.expect(requestPathInfo.getSelectorString()).andReturn("version.,1.1,.tidy.json"); EasyMock.expect(request.getResource()).andReturn(resource); EasyMock.expect(resource.adaptTo(Node.class)).andReturn(node); EasyMock.expect(node.getPath()).andReturn("/foo"); EasyMock.expect(node.getSession()).andReturn(session); EasyMock.expect(session.getWorkspace()).andReturn(workspace); EasyMock.expect(workspace.getVersionManager()).andReturn(versionManager); EasyMock.expect(versionManager.getVersionHistory("/foo")).andReturn(versionHistory); EasyMock.expect(versionHistory.getVersion("1.1")).andReturn(version); EasyMock.expect(version.getNode(JcrConstants.JCR_FROZENNODE)).andReturn(frozenNode); EasyMock.expect(frozenNode.getPath()).andReturn("/testnode"); EasyMock.expect(frozenNode.hasProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY)) .andReturn(true); EasyMock.expect(frozenNode.getProperty(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY)) .andReturn(resourceTypeProperty); EasyMock.expect(resourceTypeProperty.getString()).andReturn("sakai/testing"); EasyMock.expect(frozenNode.hasProperty(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY)) .andReturn(true); EasyMock.expect(frozenNode.getProperty(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY)) .andReturn(resourceTypeProperty); EasyMock.expect(resourceTypeProperty.getString()).andReturn("sakai/super-type-testing"); EasyMock.expect(request.getRequestDispatcher(EasyMock.capture(capturedResource))) .andReturn(requestDispatcher); requestDispatcher.forward( EasyMock.capture(capturedRequest), EasyMock.capture(capturedResponse)); EasyMock.expectLastCall(); replay(); getVersionServlet.doGet(request, response); Assert.assertTrue(capturedRequest.hasCaptured()); Assert.assertTrue(capturedResource.hasCaptured()); Assert.assertTrue(capturedResponse.hasCaptured()); Resource cresource = capturedResource.getValue(); Node capturedNode = cresource.adaptTo(Node.class); Assert.assertEquals(capturedNode, frozenNode); Map<String, String> map = cresource.adaptTo(Map.class); Assert.assertNotNull(map); verify(); }