@Test void canOverwriteSilently() throws Exception { DocumentReference documentReference = new DocumentReference("wiki", Arrays.asList("Path", "To"), "Page"); XWikiDocument document = mock(XWikiDocument.class); when(this.xwiki.getDocument(documentReference, this.xcontext)).thenReturn(document); assertFalse(this.modelBridge.canOverwriteSilently(documentReference)); DocumentReference redirectClassReference = new DocumentReference("wiki", "XWiki", "RedirectClass"); when(document.getXObject(redirectClassReference)).thenReturn(mock(BaseObject.class)); assertTrue(this.modelBridge.canOverwriteSilently(documentReference)); }
@Override public boolean canOverwriteSilently(DocumentReference documentReference) { try { XWikiContext xcontext = this.xcontextProvider.get(); XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext); DocumentReference redirectClassReference = new DocumentReference(REDIRECT_CLASS_REFERENCE, documentReference.getWikiReference()); return document.getXObject(redirectClassReference) != null; } catch (XWikiException e) { this.logger.warn("Failed to get document [{}]. Root cause: [{}].", documentReference, ExceptionUtils.getRootCauseMessage(e)); return false; } }
DefaultModelBridge implements ModelBridge { @Override public boolean canOverwriteSilently(DocumentReference documentReference) { try { XWikiContext xcontext = this.xcontextProvider.get(); XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext); DocumentReference redirectClassReference = new DocumentReference(REDIRECT_CLASS_REFERENCE, documentReference.getWikiReference()); return document.getXObject(redirectClassReference) != null; } catch (XWikiException e) { this.logger.warn("Failed to get document [{}]. Root cause: [{}].", documentReference, ExceptionUtils.getRootCauseMessage(e)); return false; } } }
DefaultModelBridge implements ModelBridge { @Override public boolean canOverwriteSilently(DocumentReference documentReference) { try { XWikiContext xcontext = this.xcontextProvider.get(); XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext); DocumentReference redirectClassReference = new DocumentReference(REDIRECT_CLASS_REFERENCE, documentReference.getWikiReference()); return document.getXObject(redirectClassReference) != null; } catch (XWikiException e) { this.logger.warn("Failed to get document [{}]. Root cause: [{}].", documentReference, ExceptionUtils.getRootCauseMessage(e)); return false; } }  }
DefaultModelBridge implements ModelBridge { @Override public boolean canOverwriteSilently(DocumentReference documentReference) { try { XWikiContext xcontext = this.xcontextProvider.get(); XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext); DocumentReference redirectClassReference = new DocumentReference(REDIRECT_CLASS_REFERENCE, documentReference.getWikiReference()); return document.getXObject(redirectClassReference) != null; } catch (XWikiException e) { this.logger.warn("Failed to get document [{}]. Root cause: [{}].", documentReference, ExceptionUtils.getRootCauseMessage(e)); return false; } }  @Override boolean create(DocumentReference documentReference); @Override boolean copy(DocumentReference source, DocumentReference destination); @Override boolean delete(DocumentReference reference); @Override boolean delete(DocumentReference reference, boolean skipRecycleBin); @Override boolean removeLock(DocumentReference reference); @Override void createRedirect(DocumentReference oldReference, DocumentReference newReference); @Override boolean canOverwriteSilently(DocumentReference documentReference); @Override boolean exists(DocumentReference reference); @Override List<DocumentReference> getBackLinkedReferences(DocumentReference documentReference, String wikiId); @Override List<DocumentReference> getDocumentReferences(SpaceReference spaceReference); @Override boolean updateParentField(final DocumentReference oldParentReference,
        final DocumentReference newParentReference); @Override DocumentReference setContextUserReference(DocumentReference userReference); @Override void update(DocumentReference documentReference, Map<String, String> parameters); @Override boolean restoreDeletedDocument(long deletedDocumentId, AbstractCheckRightsRequest request); @Override List<Long> getDeletedDocumentIds(String batchId); @Override boolean permanentlyDeleteDocument(long deletedDocumentId, AbstractCheckRightsRequest request); @Override boolean permanentlyDeleteAllDocuments(PermanentlyDeleteJob deleteJob, AbstractCheckRightsRequest request); @Override boolean rename(DocumentReference source, DocumentReference destination); }
DefaultModelBridge implements ModelBridge { @Override public boolean canOverwriteSilently(DocumentReference documentReference) { try { XWikiContext xcontext = this.xcontextProvider.get(); XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext); DocumentReference redirectClassReference = new DocumentReference(REDIRECT_CLASS_REFERENCE, documentReference.getWikiReference()); return document.getXObject(redirectClassReference) != null; } catch (XWikiException e) { this.logger.warn("Failed to get document [{}]. Root cause: [{}].", documentReference, ExceptionUtils.getRootCauseMessage(e)); return false; } }  @Override boolean create(DocumentReference documentReference); @Override boolean copy(DocumentReference source, DocumentReference destination); @Override boolean delete(DocumentReference reference); @Override boolean delete(DocumentReference reference, boolean skipRecycleBin); @Override boolean removeLock(DocumentReference reference); @Override void createRedirect(DocumentReference oldReference, DocumentReference newReference); @Override boolean canOverwriteSilently(DocumentReference documentReference); @Override boolean exists(DocumentReference reference); @Override List<DocumentReference> getBackLinkedReferences(DocumentReference documentReference, String wikiId); @Override List<DocumentReference> getDocumentReferences(SpaceReference spaceReference); @Override boolean updateParentField(final DocumentReference oldParentReference,
        final DocumentReference newParentReference); @Override DocumentReference setContextUserReference(DocumentReference userReference); @Override void update(DocumentReference documentReference, Map<String, String> parameters); @Override boolean restoreDeletedDocument(long deletedDocumentId, AbstractCheckRightsRequest request); @Override List<Long> getDeletedDocumentIds(String batchId); @Override boolean permanentlyDeleteDocument(long deletedDocumentId, AbstractCheckRightsRequest request); @Override boolean permanentlyDeleteAllDocuments(PermanentlyDeleteJob deleteJob, AbstractCheckRightsRequest request); @Override boolean rename(DocumentReference source, DocumentReference destination);  }