Search in sources :

Example 6 with WikiPropertyGroupException

use of org.xwiki.wiki.properties.WikiPropertyGroupException in project xwiki-platform by xwiki.

the class WikiTemplatePropertyGroupProvider method get.

@Override
public WikiPropertyGroup get(String wikiId) throws WikiPropertyGroupException {
    WikiTemplatePropertyGroup group = new WikiTemplatePropertyGroup(GROUP_NAME);
    try {
        XWikiDocument descriptorDocument = wikiDescriptorDocumentHelper.getDocumentFromWikiId(wikiId);
        // Get the object
        BaseObject object = descriptorDocument.getXObject(WikiTemplateClassDocumentInitializer.SERVER_CLASS);
        if (object != null) {
            group.setTemplate(object.getIntValue(WikiTemplateClassDocumentInitializer.FIELD_ISWIKITEMPLATE, 0) != 0);
        }
    } catch (WikiManagerException e) {
        throw new WikiPropertyGroupException(String.format(ERROR_MESSAGE_NO_DESCRIPTOR_DOCUMENT, wikiId), e);
    }
    return group;
}
Also used : WikiTemplatePropertyGroup(org.xwiki.wiki.template.WikiTemplatePropertyGroup) WikiPropertyGroupException(org.xwiki.wiki.properties.WikiPropertyGroupException) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 7 with WikiPropertyGroupException

use of org.xwiki.wiki.properties.WikiPropertyGroupException in project xwiki-platform by xwiki.

the class WikiTemplatePropertyGroupProviderTest method getWhenException.

@Test
public void getWhenException() throws Exception {
    WikiManagerException exception = new WikiManagerException("error in WikiManager");
    when(wikiDescriptorDocumentHelper.getDocumentFromWikiId("wikiId")).thenThrow(exception);
    // Test
    boolean exceptionCaught = false;
    try {
        mocker.getComponentUnderTest().get("wikiId");
    } catch (WikiPropertyGroupException e) {
        exceptionCaught = true;
        assertEquals("Unable to load descriptor document for wiki [wikiId].", e.getMessage());
        assertEquals(exception, e.getCause());
    }
    assertTrue(exceptionCaught);
}
Also used : WikiPropertyGroupException(org.xwiki.wiki.properties.WikiPropertyGroupException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) Test(org.junit.Test)

Aggregations

WikiPropertyGroupException (org.xwiki.wiki.properties.WikiPropertyGroupException)7 BaseObject (com.xpn.xwiki.objects.BaseObject)5 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)5 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)4 WikiTemplatePropertyGroup (org.xwiki.wiki.template.WikiTemplatePropertyGroup)3 XWiki (com.xpn.xwiki.XWiki)2 XWikiContext (com.xpn.xwiki.XWikiContext)2 XWikiException (com.xpn.xwiki.XWikiException)2 Test (org.junit.Test)2 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)2 WikiPropertyGroupManager (org.xwiki.wiki.internal.descriptor.properties.WikiPropertyGroupManager)2 ArrayList (java.util.ArrayList)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 DefaultWikiDescriptor (org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor)1 WikiTemplateManagerException (org.xwiki.wiki.template.WikiTemplateManagerException)1