CopyResourceToRelativePath implements Action { @Override public String doAction(@Nonnull Resource resource) throws PersistenceException { ResourceResolver resourceResolver = context.getResolver(); Resource destinationParentResource = resourceResolver.getResource(resource, relativePath); if (destinationParentResource != null) { String sourcePath = resource.getPath(); String destinationName = StringUtils.isNotEmpty(newName) ? newName : resource.getName(); String destinationPath = destinationParentResource.getPath() + FileSystem.SEPARATOR + destinationName; PageUtil pageUtil = new PageUtil(); if (pageUtil.isPageResource(resource)) { PageManager pageManager = resourceResolver.adaptTo(PageManager.class); try { pageManager.copy(resource, destinationPath, null, false, false, false); } catch (WCMException | IllegalArgumentException e) { throw new PersistenceException( "Unable to copy " + sourcePath + " as " + destinationPath + ": " + e.getMessage()); } } else if (!context.isDryRun()) { try { Session session = resourceResolver.adaptTo(Session.class); session.getWorkspace().copy(sourcePath, destinationPath); } catch (RepositoryException e) { throw new PersistenceException( "Unable to copy " + sourcePath + " as " + destinationPath + ": " + e.getMessage()); } } return "Copied " + sourcePath + " to " + destinationPath; } return "WARNING: could not read copy destination resource " + relativePath; } CopyResourceToRelativePath(@Nonnull String relativePath, String newName, @Nonnull BindingContext context); @Override String doAction(@Nonnull Resource resource);  }
@Test public void testDoAction_copyResource_dryRun() throws PersistenceException, RepositoryException { CopyResourceToRelativePath copyAction = new CopyResourceToRelativePath("to/relative", "newName", contextMock); when(valueMapMock.get(JcrConstants.JCR_PRIMARYTYPE, String.class)).thenReturn(JcrConstants.NT_UNSTRUCTURED); when(contextMock.isDryRun()).thenReturn(true); copyAction.doAction(resourceMock); verify(workspaceMock, never()).copy(anyString(), anyString()); }