Search in sources :

Example 6 with WikiManagerException

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);
}
Also used : WikiCreatingEvent(org.xwiki.bridge.event.WikiCreatingEvent) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) XWikiContext(com.xpn.xwiki.XWikiContext) WikiCreateFailedEvent(org.xwiki.bridge.event.WikiCreateFailedEvent) DefaultWikiDescriptor(org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor) Test(org.junit.Test)

Example 7 with WikiManagerException

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());
}
Also used : WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) Test(org.junit.Test)

Example 8 with WikiManagerException

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());
}
Also used : WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 9 with WikiManagerException

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());
}
Also used : WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 10 with WikiManagerException

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);
    }
}
Also used : WikiTemplatePropertyGroup(org.xwiki.wiki.template.WikiTemplatePropertyGroup) WikiPropertyGroupException(org.xwiki.wiki.properties.WikiPropertyGroupException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) WikiTemplateManagerException(org.xwiki.wiki.template.WikiTemplateManagerException)

Aggregations

WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)40 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)17 Test (org.junit.Test)13 XWikiContext (com.xpn.xwiki.XWikiContext)12 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)11 XWiki (com.xpn.xwiki.XWiki)7 XWikiException (com.xpn.xwiki.XWikiException)7 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)6 WikiTemplateManagerException (org.xwiki.wiki.template.WikiTemplateManagerException)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 WikiPropertyGroupException (org.xwiki.wiki.properties.WikiPropertyGroupException)5 BaseObject (com.xpn.xwiki.objects.BaseObject)4 WikiCreationException (org.xwiki.platform.wiki.creationjob.WikiCreationException)4 WikiTemplatePropertyGroup (org.xwiki.wiki.template.WikiTemplatePropertyGroup)4 ExtensionId (org.xwiki.extension.ExtensionId)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 WikiReference (org.xwiki.model.reference.WikiReference)3 Query (org.xwiki.query.Query)3 QueryException (org.xwiki.query.QueryException)3 DefaultWikiDescriptor (org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor)3