use of org.xwiki.bridge.event.WikiCreateFailedEvent 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.bridge.event.WikiCreateFailedEvent in project xwiki-platform by xwiki.
the class DefaultWikiManager method create.
@Override
public WikiDescriptor create(String wikiId, String wikiAlias, boolean failOnExist) throws WikiManagerException {
// Check that the wiki Id is available
if (failOnExist && !idAvailable(wikiId)) {
throw new WikiManagerException(String.format("wiki id [%s] is already used and is thus not available", wikiId));
}
XWikiContext context = xcontextProvider.get();
WikiDescriptor descriptor;
try {
// Send the begin event
observationManager.notify(new WikiCreatingEvent(wikiId), wikiId, context);
// Create the wiki
descriptor = wikiCreator.create(wikiId, wikiAlias);
// Send the end event
observationManager.notify(new WikiCreatedEvent(wikiId), wikiId, context);
} catch (WikiManagerException e) {
// Send the failed event
observationManager.notify(new WikiCreateFailedEvent(wikiId), wikiId, context);
// Throw the exception
throw e;
}
return descriptor;
}
Aggregations