use of org.xwiki.wiki.manager.WikiManagerException in project xwiki-platform by xwiki.
the class DefaultWikiManagerTest method createWhenWikiIdIsValidButFail.
@Test
public void createWhenWikiIdIsValidButFail() throws Exception {
// The wiki does not already exist
when(wikiDescriptorManager.exists("wikiid1")).thenReturn(false);
// The wiki id is valid
when(xwiki.Param("xwiki.virtual.reserved_wikis")).thenReturn("forbidden");
// The wiki name is available
when(store.isWikiNameAvailable(eq("wikiid1"), any(XWikiContext.class))).thenReturn(true);
DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("wikiid1", "wikialias1");
when(wikiCreator.create("wikiid1", "wikialias1")).thenThrow(new WikiManagerException("..."));
// Create
boolean exceptionCaught = false;
try {
this.mocker.getComponentUnderTest().create("wikiid1", "wikialias1", true);
} catch (WikiManagerException e) {
exceptionCaught = true;
}
// verify the exception
assertTrue(exceptionCaught);
// Verify the events has been sent
verify(observationManager).notify(new WikiCreatingEvent("wikiid1"), "wikiid1", xcontext);
verify(observationManager).notify(new WikiCreateFailedEvent("wikiid1"), "wikiid1", xcontext);
}
use of org.xwiki.wiki.manager.WikiManagerException in project xwiki-platform by xwiki.
the class WikiManagerScriptServiceTest method existsError.
@Test
public void existsError() throws Exception {
Exception exception = new WikiManagerException("error in exists");
when(wikiDescriptorManager.exists("wikiId")).thenThrow(exception);
Boolean result = mocker.getComponentUnderTest().exists("wikiId");
assertNull(result);
assertEquals(exception, mocker.getComponentUnderTest().getLastError());
}
use of org.xwiki.wiki.manager.WikiManagerException in project xwiki-platform by xwiki.
the class WikiManagerScriptServiceTest method getAllError.
@Test
public void getAllError() throws Exception {
Exception exception = new WikiManagerException("error in getAll");
when(wikiDescriptorManager.getAll()).thenThrow(exception);
Collection<WikiDescriptor> result = mocker.getComponentUnderTest().getAll();
assertTrue(result.isEmpty());
assertEquals(exception, mocker.getComponentUnderTest().getLastError());
}
use of org.xwiki.wiki.manager.WikiManagerException in project xwiki-platform by xwiki.
the class WikiManagerScriptServiceTest method getByAliasError.
@Test
public void getByAliasError() throws Exception {
Exception exception = new WikiManagerException("error in getByAlias");
when(wikiDescriptorManager.getByAlias("wikiAlias")).thenThrow(exception);
WikiDescriptor result = mocker.getComponentUnderTest().getByAlias("wikiAlias");
assertNull(result);
assertEquals(exception, mocker.getComponentUnderTest().getLastError());
}
use of org.xwiki.wiki.manager.WikiManagerException in project xwiki-platform by xwiki.
the class DefaultWikiTemplateManager method setTemplate.
@Override
public void setTemplate(String wikiId, boolean value) throws WikiTemplateManagerException {
try {
// Get the descriptor
WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId);
// Get the property group
WikiTemplatePropertyGroup group = (WikiTemplatePropertyGroup) descriptor.getPropertyGroup(WikiTemplatePropertyGroupProvider.GROUP_NAME);
// Set the value
group.setTemplate(value);
// Save the property groups
templateWikiPropertyGroupProvider.save(group, wikiId);
} catch (WikiPropertyGroupException e) {
throw new WikiTemplateManagerException(String.format("Failed to save the property group [%s]", WikiTemplatePropertyGroupProvider.GROUP_NAME), e);
} catch (WikiManagerException e) {
throw new WikiTemplateManagerException(String.format(errorMessageNoDescriptor, wikiId), e);
}
}
Aggregations