Search in sources :

Example 6 with WikiCreationException

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());
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) Test(org.junit.Test)

Example 7 with WikiCreationException

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());
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) Test(org.junit.Test)

Example 8 with WikiCreationException

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);
    }
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException)

Example 9 with WikiCreationException

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);
}
Also used : JobException(org.xwiki.job.JobException) WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) Test(org.junit.Test)

Example 10 with WikiCreationException

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));
}
Also used : WikiProvisioningFailedEvent(org.xwiki.bridge.event.WikiProvisioningFailedEvent) WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) WikiProvisioningEvent(org.xwiki.bridge.event.WikiProvisioningEvent) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) ExtensionId(org.xwiki.extension.ExtensionId) Test(org.junit.Test)

Aggregations

WikiCreationException (org.xwiki.platform.wiki.creationjob.WikiCreationException)12 Test (org.junit.Test)7 WikiCreationRequest (org.xwiki.platform.wiki.creationjob.WikiCreationRequest)6 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)4 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)3 WikiProvisioningFailedEvent (org.xwiki.bridge.event.WikiProvisioningFailedEvent)2 ExtensionId (org.xwiki.extension.ExtensionId)2 WikiCreationStep (org.xwiki.platform.wiki.creationjob.WikiCreationStep)2 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)2 WikiUserManagerException (org.xwiki.wiki.user.WikiUserManagerException)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 ArrayList (java.util.ArrayList)1 Marker (org.slf4j.Marker)1 WikiCopiedEvent (org.xwiki.bridge.event.WikiCopiedEvent)1 WikiProvisioningEvent (org.xwiki.bridge.event.WikiProvisioningEvent)1 InstallRequest (org.xwiki.extension.job.InstallRequest)1 InstallJob (org.xwiki.extension.job.internal.InstallJob)1 JobException (org.xwiki.job.JobException)1 WikiReference (org.xwiki.model.reference.WikiReference)1 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)1