@Test void existsWhenDocumentIsNotAUser() throws Exception { DocumentReference reference = new DocumentReference("wiki", "space", "user"); XWiki xwiki = mock(XWiki.class); XWikiContext xcontext = mock(XWikiContext.class); when(xcontext.getWiki()).thenReturn(xwiki); when(this.contextProvider.get()).thenReturn(xcontext); XWikiDocument document = mock(XWikiDocument.class); when(document.isNew()).thenReturn(false); when(xwiki.getDocument(reference, xcontext)).thenReturn(document); when(document.getXObject(new EntityReference("XWikiUsers", EntityType.DOCUMENT, new EntityReference("XWiki", EntityType.SPACE)))).thenReturn(null); assertFalse(this.userManager.exists(new DocumentUserReference(reference, null))); }
@Override public boolean exists(UserReference userReference) { boolean result; XWikiContext xcontext = this.xwikiContextProvider.get(); XWiki xwiki = xcontext.getWiki(); DocumentReference userDocumentReference = ((DocumentUserReference) userReference).getReference(); try { XWikiDocument document = xwiki.getDocument(userDocumentReference, xcontext); result = !document.isNew() && document.getXObject(USERS_XCLASS_REFERENCE) != null; } catch (Exception e) { this.logger.warn(String.format("Failed to check if document [%s] holds an XWiki user or not. " + "Considering it's not the case. Root error: [%s]", userDocumentReference, ExceptionUtils.getRootCauseMessage(e))); result = false; } return result; }
DocumentUserManager implements UserManager { @Override public boolean exists(UserReference userReference) { boolean result; XWikiContext xcontext = this.xwikiContextProvider.get(); XWiki xwiki = xcontext.getWiki(); DocumentReference userDocumentReference = ((DocumentUserReference) userReference).getReference(); try { XWikiDocument document = xwiki.getDocument(userDocumentReference, xcontext); result = !document.isNew() && document.getXObject(USERS_XCLASS_REFERENCE) != null; } catch (Exception e) { this.logger.warn(String.format("Failed to check if document [%s] holds an XWiki user or not. " + "Considering it's not the case. Root error: [%s]", userDocumentReference, ExceptionUtils.getRootCauseMessage(e))); result = false; } return result; } }
DocumentUserManager implements UserManager { @Override public boolean exists(UserReference userReference) { boolean result; XWikiContext xcontext = this.xwikiContextProvider.get(); XWiki xwiki = xcontext.getWiki(); DocumentReference userDocumentReference = ((DocumentUserReference) userReference).getReference(); try { XWikiDocument document = xwiki.getDocument(userDocumentReference, xcontext); result = !document.isNew() && document.getXObject(USERS_XCLASS_REFERENCE) != null; } catch (Exception e) { this.logger.warn(String.format("Failed to check if document [%s] holds an XWiki user or not. " + "Considering it's not the case. Root error: [%s]", userDocumentReference, ExceptionUtils.getRootCauseMessage(e))); result = false; } return result; }  }
DocumentUserManager implements UserManager { @Override public boolean exists(UserReference userReference) { boolean result; XWikiContext xcontext = this.xwikiContextProvider.get(); XWiki xwiki = xcontext.getWiki(); DocumentReference userDocumentReference = ((DocumentUserReference) userReference).getReference(); try { XWikiDocument document = xwiki.getDocument(userDocumentReference, xcontext); result = !document.isNew() && document.getXObject(USERS_XCLASS_REFERENCE) != null; } catch (Exception e) { this.logger.warn(String.format("Failed to check if document [%s] holds an XWiki user or not. " + "Considering it's not the case. Root error: [%s]", userDocumentReference, ExceptionUtils.getRootCauseMessage(e))); result = false; } return result; }  @Override boolean exists(UserReference userReference); }
DocumentUserManager implements UserManager { @Override public boolean exists(UserReference userReference) { boolean result; XWikiContext xcontext = this.xwikiContextProvider.get(); XWiki xwiki = xcontext.getWiki(); DocumentReference userDocumentReference = ((DocumentUserReference) userReference).getReference(); try { XWikiDocument document = xwiki.getDocument(userDocumentReference, xcontext); result = !document.isNew() && document.getXObject(USERS_XCLASS_REFERENCE) != null; } catch (Exception e) { this.logger.warn(String.format("Failed to check if document [%s] holds an XWiki user or not. " + "Considering it's not the case. Root error: [%s]", userDocumentReference, ExceptionUtils.getRootCauseMessage(e))); result = false; } return result; }  @Override boolean exists(UserReference userReference);  }