use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.
the class WikiUserManagerScriptService method join.
/**
* Join a wiki.
*
* @param userId userId to add to the wiki
* @param wikiId id of the wiki
* @return true if it succeed
*/
public boolean join(String userId, String wikiId) {
// Check if the current user is userId
XWikiContext context = xcontextProvider.get();
DocumentReference candidacyUser = documentReferenceResolver.resolve(userId);
if (!context.getUserReference().equals(candidacyUser)) {
setLastError(new WikiUserManagerException(String.format("User [%s] cannot call " + "$services.wiki.user.join() with an other userId.", context.getUserReference())));
return false;
}
try {
wikiUserManager.join(userId, wikiId);
} catch (WikiUserManagerException e) {
setLastError(e);
return false;
}
return true;
}
use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.
the class WikiUserManagerScriptServiceTest method leaveWhenError.
@Test
public void leaveWhenError() throws Exception {
String userId = "mainWiki:XWiki.User";
String wikiId = "wikiId";
// Mocks
WikiUserManagerException expectedException = new WikiUserManagerException("error in wikiUserManager#leave()");
doThrow(expectedException).when(wikiUserManager).leave(userId, wikiId);
// Test
boolean result = this.mocker.getComponentUnderTest().leave(userId, wikiId);
// Asserts
assertFalse(result);
assertEquals(expectedException, this.mocker.getComponentUnderTest().getLastError());
}
use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.
the class WikiUserManagerScriptServiceTest method getUserScopeWithError.
@Test
public void getUserScopeWithError() throws Exception {
// Mocks
Exception expectedException = new WikiUserManagerException("Error in getUserScope");
when(wikiUserManager.getUserScope("test")).thenThrow(expectedException);
// Test
UserScope result = mocker.getComponentUnderTest().getUserScope("test");
// Asserts
assertNull(result);
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
}
use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.
the class WikiUserManagerScriptServiceTest method setMembershipTypeError.
@Test
public void setMembershipTypeError() throws Exception {
// Mocks
WikiUserManagerException expectedException = new WikiUserManagerException("error in setMembershipType");
doThrow(expectedException).when(wikiUserManager).setMembershipType(any(), any(MembershipType.class));
// Test
boolean result = mocker.getComponentUnderTest().setMembershipType("subwiki", "INVITE");
// Asserts
assertEquals(false, result);
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
}
use of org.xwiki.wiki.user.WikiUserManagerException in project xwiki-platform by xwiki.
the class WikiUserManagerScriptServiceTest method getMembersError.
@Test
public void getMembersError() throws Exception {
// Mocks
Exception expectedException = new WikiUserManagerException("error in getMembers");
when(wikiUserManager.getMembers("subwiki")).thenThrow(expectedException);
// Test
Collection<String> result = mocker.getComponentUnderTest().getMembers("subwiki");
// Asserts
assertNull(result);
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
}
Aggregations