@Test public void copyDocuments() throws Exception { Query query = mock(Query.class); when(queryManager.createQuery("select distinct doc.fullName from Document as doc", Query.XWQL)).thenReturn( query); List<String> documentList = Arrays.asList("Space.Doc1", "Space.Doc2", "Space.Doc3"); when(query.<String>execute()).thenReturn(documentList); WikiReference fromWikiReference = new WikiReference("wikiA"); DocumentReference docRef1 = new DocumentReference("wikiA", "Space", "Doc1"); DocumentReference docRef2 = new DocumentReference("wikiA", "Space", "Doc2"); DocumentReference docRef3 = new DocumentReference("wikiA", "Space", "Doc3"); DocumentReference copydocRef1 = new DocumentReference("wikiB", "Space", "Doc1"); DocumentReference copydocRef2 = new DocumentReference("wikiB", "Space", "Doc2"); DocumentReference copydocRef3 = new DocumentReference("wikiB", "Space", "Doc3"); when(documentReferenceResolver.resolve(eq("Space.Doc1"), eq(fromWikiReference))).thenReturn(docRef1); when(documentReferenceResolver.resolve(eq("Space.Doc2"), eq(fromWikiReference))).thenReturn(docRef2); when(documentReferenceResolver.resolve(eq("Space.Doc3"), eq(fromWikiReference))).thenReturn(docRef3); mocker.getComponentUnderTest().copyDocuments("wikiA", "wikiB", false); verify(query).setWiki("wikiA"); InOrder inOrder = inOrder(progress, xwiki, mocker.getMockedLogger()); inOrder.verify(progress).pushLevelProgress(3, mocker.getComponentUnderTest()); inOrder.verify(progress).startStep(mocker.getComponentUnderTest()); inOrder.verify(mocker.getMockedLogger()).info("Copying document [{}] to [{}].", docRef1, copydocRef1); inOrder.verify(xwiki).copyDocument(docRef1, copydocRef1, null, true, true, xcontext); inOrder.verify(mocker.getMockedLogger()).info("Done copying document [{}] to [{}].", docRef1, copydocRef1); inOrder.verify(progress).startStep(mocker.getComponentUnderTest()); inOrder.verify(mocker.getMockedLogger()).info("Copying document [{}] to [{}].", docRef2, copydocRef2); inOrder.verify(xwiki).copyDocument(docRef2, copydocRef2, null, true, true, xcontext); inOrder.verify(mocker.getMockedLogger()).info("Done copying document [{}] to [{}].", docRef2, copydocRef2); inOrder.verify(progress).startStep(mocker.getComponentUnderTest()); inOrder.verify(mocker.getMockedLogger()).info("Copying document [{}] to [{}].", docRef3, copydocRef3); inOrder.verify(xwiki).copyDocument(docRef3, copydocRef3, null, true, true, xcontext); inOrder.verify(mocker.getMockedLogger()).info("Done copying document [{}] to [{}].", docRef3, copydocRef3); inOrder.verify(progress).popLevelProgress(mocker.getComponentUnderTest()); }
@Override public void copyDocuments(String fromWikiId, String toWikiId, boolean withHistory) throws WikiManagerException { XWikiContext context = xcontextProvider.get(); XWiki xwiki = context.getWiki(); this.progress.pushLevelProgress(2, this); try { this.progress.startStep(this, "Get documents to copy"); Query query = queryManager.createQuery("select distinct doc.fullName from Document as doc", Query.XWQL); query.setWiki(fromWikiId); List<String> documentFullnames = query.execute(); this.progress.endStep(this); this.progress.startStep(this, "Copy documents"); this.progress.pushLevelProgress(documentFullnames.size(), this); WikiReference fromWikiReference = new WikiReference(fromWikiId); try { for (String documentFullName : documentFullnames) { this.progress.startStep(this); DocumentReference origDocReference = documentReferenceResolver.resolve(documentFullName, fromWikiReference); DocumentReference newDocReference = origDocReference.setWikiReference(new WikiReference(toWikiId)); logger.info("Copying document [{}] to [{}].", origDocReference, newDocReference); xwiki.copyDocument(origDocReference, newDocReference, null, !withHistory, true, context); logger.info("Done copying document [{}] to [{}].", origDocReference, newDocReference); this.progress.endStep(this); } } finally { this.progress.popLevelProgress(this); this.progress.endStep(this); } } catch (QueryException e) { WikiManagerException thrownException = new WikiManagerException("Unable to get the list of wiki documents to copy.", e); logger.error(thrownException.getMessage(), thrownException); throw thrownException; } catch (XWikiException e) { WikiManagerException thrownException = new WikiManagerException("Failed to copy documents.", e); logger.error(thrownException.getMessage(), thrownException); throw thrownException; } finally { this.progress.popLevelProgress(this); } }
DefaultWikiCopier implements WikiCopier { @Override public void copyDocuments(String fromWikiId, String toWikiId, boolean withHistory) throws WikiManagerException { XWikiContext context = xcontextProvider.get(); XWiki xwiki = context.getWiki(); this.progress.pushLevelProgress(2, this); try { this.progress.startStep(this, "Get documents to copy"); Query query = queryManager.createQuery("select distinct doc.fullName from Document as doc", Query.XWQL); query.setWiki(fromWikiId); List<String> documentFullnames = query.execute(); this.progress.endStep(this); this.progress.startStep(this, "Copy documents"); this.progress.pushLevelProgress(documentFullnames.size(), this); WikiReference fromWikiReference = new WikiReference(fromWikiId); try { for (String documentFullName : documentFullnames) { this.progress.startStep(this); DocumentReference origDocReference = documentReferenceResolver.resolve(documentFullName, fromWikiReference); DocumentReference newDocReference = origDocReference.setWikiReference(new WikiReference(toWikiId)); logger.info("Copying document [{}] to [{}].", origDocReference, newDocReference); xwiki.copyDocument(origDocReference, newDocReference, null, !withHistory, true, context); logger.info("Done copying document [{}] to [{}].", origDocReference, newDocReference); this.progress.endStep(this); } } finally { this.progress.popLevelProgress(this); this.progress.endStep(this); } } catch (QueryException e) { WikiManagerException thrownException = new WikiManagerException("Unable to get the list of wiki documents to copy.", e); logger.error(thrownException.getMessage(), thrownException); throw thrownException; } catch (XWikiException e) { WikiManagerException thrownException = new WikiManagerException("Failed to copy documents.", e); logger.error(thrownException.getMessage(), thrownException); throw thrownException; } finally { this.progress.popLevelProgress(this); } } }
DefaultWikiCopier implements WikiCopier { @Override public void copyDocuments(String fromWikiId, String toWikiId, boolean withHistory) throws WikiManagerException { XWikiContext context = xcontextProvider.get(); XWiki xwiki = context.getWiki(); this.progress.pushLevelProgress(2, this); try { this.progress.startStep(this, "Get documents to copy"); Query query = queryManager.createQuery("select distinct doc.fullName from Document as doc", Query.XWQL); query.setWiki(fromWikiId); List<String> documentFullnames = query.execute(); this.progress.endStep(this); this.progress.startStep(this, "Copy documents"); this.progress.pushLevelProgress(documentFullnames.size(), this); WikiReference fromWikiReference = new WikiReference(fromWikiId); try { for (String documentFullName : documentFullnames) { this.progress.startStep(this); DocumentReference origDocReference = documentReferenceResolver.resolve(documentFullName, fromWikiReference); DocumentReference newDocReference = origDocReference.setWikiReference(new WikiReference(toWikiId)); logger.info("Copying document [{}] to [{}].", origDocReference, newDocReference); xwiki.copyDocument(origDocReference, newDocReference, null, !withHistory, true, context); logger.info("Done copying document [{}] to [{}].", origDocReference, newDocReference); this.progress.endStep(this); } } finally { this.progress.popLevelProgress(this); this.progress.endStep(this); } } catch (QueryException e) { WikiManagerException thrownException = new WikiManagerException("Unable to get the list of wiki documents to copy.", e); logger.error(thrownException.getMessage(), thrownException); throw thrownException; } catch (XWikiException e) { WikiManagerException thrownException = new WikiManagerException("Failed to copy documents.", e); logger.error(thrownException.getMessage(), thrownException); throw thrownException; } finally { this.progress.popLevelProgress(this); } }  }
DefaultWikiCopier implements WikiCopier { @Override public void copyDocuments(String fromWikiId, String toWikiId, boolean withHistory) throws WikiManagerException { XWikiContext context = xcontextProvider.get(); XWiki xwiki = context.getWiki(); this.progress.pushLevelProgress(2, this); try { this.progress.startStep(this, "Get documents to copy"); Query query = queryManager.createQuery("select distinct doc.fullName from Document as doc", Query.XWQL); query.setWiki(fromWikiId); List<String> documentFullnames = query.execute(); this.progress.endStep(this); this.progress.startStep(this, "Copy documents"); this.progress.pushLevelProgress(documentFullnames.size(), this); WikiReference fromWikiReference = new WikiReference(fromWikiId); try { for (String documentFullName : documentFullnames) { this.progress.startStep(this); DocumentReference origDocReference = documentReferenceResolver.resolve(documentFullName, fromWikiReference); DocumentReference newDocReference = origDocReference.setWikiReference(new WikiReference(toWikiId)); logger.info("Copying document [{}] to [{}].", origDocReference, newDocReference); xwiki.copyDocument(origDocReference, newDocReference, null, !withHistory, true, context); logger.info("Done copying document [{}] to [{}].", origDocReference, newDocReference); this.progress.endStep(this); } } finally { this.progress.popLevelProgress(this); this.progress.endStep(this); } } catch (QueryException e) { WikiManagerException thrownException = new WikiManagerException("Unable to get the list of wiki documents to copy.", e); logger.error(thrownException.getMessage(), thrownException); throw thrownException; } catch (XWikiException e) { WikiManagerException thrownException = new WikiManagerException("Failed to copy documents.", e); logger.error(thrownException.getMessage(), thrownException); throw thrownException; } finally { this.progress.popLevelProgress(this); } }  @Override void copyDocuments(String fromWikiId, String toWikiId, boolean withHistory); @Override void copyDeletedDocuments(String fromWikiId, String toWikiId); }
DefaultWikiCopier implements WikiCopier { @Override public void copyDocuments(String fromWikiId, String toWikiId, boolean withHistory) throws WikiManagerException { XWikiContext context = xcontextProvider.get(); XWiki xwiki = context.getWiki(); this.progress.pushLevelProgress(2, this); try { this.progress.startStep(this, "Get documents to copy"); Query query = queryManager.createQuery("select distinct doc.fullName from Document as doc", Query.XWQL); query.setWiki(fromWikiId); List<String> documentFullnames = query.execute(); this.progress.endStep(this); this.progress.startStep(this, "Copy documents"); this.progress.pushLevelProgress(documentFullnames.size(), this); WikiReference fromWikiReference = new WikiReference(fromWikiId); try { for (String documentFullName : documentFullnames) { this.progress.startStep(this); DocumentReference origDocReference = documentReferenceResolver.resolve(documentFullName, fromWikiReference); DocumentReference newDocReference = origDocReference.setWikiReference(new WikiReference(toWikiId)); logger.info("Copying document [{}] to [{}].", origDocReference, newDocReference); xwiki.copyDocument(origDocReference, newDocReference, null, !withHistory, true, context); logger.info("Done copying document [{}] to [{}].", origDocReference, newDocReference); this.progress.endStep(this); } } finally { this.progress.popLevelProgress(this); this.progress.endStep(this); } } catch (QueryException e) { WikiManagerException thrownException = new WikiManagerException("Unable to get the list of wiki documents to copy.", e); logger.error(thrownException.getMessage(), thrownException); throw thrownException; } catch (XWikiException e) { WikiManagerException thrownException = new WikiManagerException("Failed to copy documents.", e); logger.error(thrownException.getMessage(), thrownException); throw thrownException; } finally { this.progress.popLevelProgress(this); } }  @Override void copyDocuments(String fromWikiId, String toWikiId, boolean withHistory); @Override void copyDeletedDocuments(String fromWikiId, String toWikiId);  }