use of org.xwiki.platform.wiki.creationjob.WikiCreationException in project xwiki-platform by xwiki.
the class CreateWikiStepTest method executeWhenException.
@Test
public void executeWhenException() throws Exception {
WikiCreationRequest request = new WikiCreationRequest();
request.setWikiId("wikiId");
request.setAlias("wikiAlias");
request.setFailOnExist(true);
Exception exception = new WikiManagerException("Execption in WikiManager.");
doThrow(exception).when(wikiManager).create(any(), any(), anyBoolean());
// Test
WikiCreationException caughtException = null;
try {
mocker.getComponentUnderTest().execute(request);
} catch (WikiCreationException e) {
caughtException = e;
}
// Verify
assertNotNull(caughtException);
assertEquals("Failed to create the wiki [wikiId].", caughtException.getMessage());
assertEquals(exception, caughtException.getCause());
}
use of org.xwiki.platform.wiki.creationjob.WikiCreationException in project xwiki-platform by xwiki.
the class SaveWikiMetaDataStepTest method executeWithException.
@Test
public void executeWithException() throws Exception {
WikiCreationRequest request = new WikiCreationRequest();
request.setWikiId("wikiId");
// Mock
WikiDescriptor descriptor = new WikiDescriptor("wikiId", "alias");
when(wikiDescriptorManager.getById("wikiId")).thenReturn(descriptor);
Exception exception = new WikiManagerException("Exception on WikiManager.");
doThrow(exception).when(wikiDescriptorManager).saveDescriptor(descriptor);
// Test
WikiCreationException caughtException = null;
try {
mocker.getComponentUnderTest().execute(request);
} catch (WikiCreationException e) {
caughtException = e;
}
// Verify
assertEquals("Failed to set metadata to the wiki [wikiId].", caughtException.getMessage());
assertEquals(exception, caughtException.getCause());
}
use of org.xwiki.platform.wiki.creationjob.WikiCreationException in project xwiki-platform by xwiki.
the class SaveWikiMetaDataStep method execute.
@Override
public void execute(WikiCreationRequest request) throws WikiCreationException {
try {
String wikiId = request.getWikiId();
// Meta data about the wiki
WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId);
descriptor.setDescription(request.getDescription());
descriptor.setPrettyName(request.getPrettyName());
descriptor.setOwnerId(request.getOwnerId());
wikiDescriptorManager.saveDescriptor(descriptor);
// Meta data about the templates
wikiTemplateManager.setTemplate(wikiId, request.isTemplate());
// Meta data about the users
wikiUserManager.setUserScope(wikiId, request.getUserScope());
wikiUserManager.setMembershipType(wikiId, request.getMembershipType());
} catch (WikiManagerException | WikiTemplateManagerException | WikiUserManagerException e) {
throw new WikiCreationException(String.format("Failed to set metadata to the wiki [%s].", request.getWikiId()), e);
}
}
use of org.xwiki.platform.wiki.creationjob.WikiCreationException in project xwiki-platform by xwiki.
the class DefaultWikiCreatorTest method createWikiWithException.
@Test
public void createWikiWithException() throws Exception {
WikiCreationRequest request = new WikiCreationRequest();
request.setWikiId("wikiId");
// Mock
JobException jobException = new JobException("Error in JobException");
when(jobExecutor.execute("wikicreationjob", request)).thenThrow(jobException);
// Test
WikiCreationException caughtException = null;
try {
mocker.getComponentUnderTest().createWiki(request);
} catch (WikiCreationException e) {
caughtException = e;
}
// Verify
assertNotNull(caughtException);
}
use of org.xwiki.platform.wiki.creationjob.WikiCreationException in project xwiki-platform by xwiki.
the class ProvisionWikiStepTest method executeWhenException.
@Test
public void executeWhenException() throws Exception {
WikiCreationRequest request = new WikiCreationRequest();
request.setWikiId("wikiId");
request.setWikiSource(WikiSource.EXTENSION);
ExtensionId extensionId = new ExtensionId("id", "version");
request.setExtensionId(extensionId);
// Mocks
WikiCreationException exception = new WikiCreationException("Exception in ExtensionInstaller");
doThrow(exception).when(extensionInstaller).installExtension("wikiId", extensionId);
// Test
WikiCreationException caughtException = null;
try {
mocker.getComponentUnderTest().execute(request);
} catch (WikiCreationException e) {
caughtException = e;
}
// Verify
assertNotNull(caughtException);
assertEquals("Failed to provision the wiki [wikiId].", caughtException.getMessage());
assertEquals(exception, caughtException.getCause());
verify(observationManager).notify(eq(new WikiProvisioningEvent("wikiId")), eq("wikiId"), eq(xcontext));
verify(observationManager).notify(eq(new WikiProvisioningFailedEvent("wikiId")), eq("wikiId"), eq(xcontext));
}
Aggregations