Search in sources :

Example 26 with WikiDescriptor

use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.

the class DefaultWikiDescriptorManager method getAll.

@Override
public Collection<WikiDescriptor> getAll() throws WikiManagerException {
    // Note: Ideally to improve performance we could imagine loading all XWikiServerClasses at initialization time
    // (in initialize()) and thereafter only use the cache. The problem with this approach is that our Cache will
    // need to be unbounded which is not the case right now. This would mean being able to put all descriptors in
    // the cache and thus it might not scale if there were a very large number of wikis.
    // Note that the full list of ids is cached since it takes a lot less memory that descriptors.
    Collection<String> wikiIds = getAllIds();
    List<WikiDescriptor> result = new ArrayList<WikiDescriptor>(wikiIds.size());
    for (String wikiId : wikiIds) {
        // Get the descriptor
        WikiDescriptor descriptor = getById(wikiId);
        // Add it to the result list
        if (descriptor != null) {
            result.add(descriptor);
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor)

Example 27 with WikiDescriptor

use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.

the class DomainWikiReferenceExtractorTest method extractWhenNoWikiDescriptorForFullDomainButDescriptorForSubdomain.

@Test
public void extractWhenNoWikiDescriptorForFullDomainButDescriptorForSubdomain() throws Exception {
    setUpConfiguration(WikiNotFoundBehavior.REDIRECT_TO_MAIN_WIKI);
    WikiDescriptorManager wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getByAlias("wiki.server.com")).thenReturn(null);
    when(wikiDescriptorManager.getById("wiki")).thenReturn(new WikiDescriptor("dummy", "dummy"));
    testAndAssert("http://wiki.server.com/xwiki/bin/view/Main/WebHome", "wiki");
}
Also used : WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 28 with WikiDescriptor

use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.

the class PathWikiReferenceExtractorTest method extractWhenNoDescriptorMatchingAliasButDescriptorMatchingId.

@Test
public void extractWhenNoDescriptorMatchingAliasButDescriptorMatchingId() throws Exception {
    setUpConfiguration(WikiNotFoundBehavior.REDIRECT_TO_MAIN_WIKI);
    WikiDescriptorManager wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getByAlias("someWiki")).thenReturn(null);
    when(wikiDescriptorManager.getById("someWiki")).thenReturn(new WikiDescriptor("dummy", "dummy"));
    testAndAssert("http://localhost/xwiki/wiki/someWiki/view/Main/WebHome", "somewiki");
}
Also used : WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 29 with WikiDescriptor

use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.

the class DefaultWikiDescriptorManagerTest method getAll.

@Test
public void getAll() throws Exception {
    // Get the XWikiDocuments for the Document References
    XWikiDocument document1 = mock(XWikiDocument.class);
    XWikiDocument document2 = mock(XWikiDocument.class);
    XWikiDocument maindocument = mock(XWikiDocument.class);
    DefaultWikiDescriptor descriptor3 = new DefaultWikiDescriptor("wikiid3", "wikialias3");
    // Get documents
    when(descriptorDocumentHelper.getAllXWikiServerClassDocumentNames()).thenReturn(Arrays.asList("XWiki.XWikiServerWikiid1", "XWiki.XWikiServerWikiid2", "XWiki.XWikiServerWikiid3"));
    when(descriptorDocumentHelper.getWikiIdFromDocumentFullname("XWiki.XWikiServerWikiid1")).thenReturn("wikiid1");
    when(descriptorDocumentHelper.getWikiIdFromDocumentFullname("XWiki.XWikiServerWikiid2")).thenReturn("wikiid2");
    when(descriptorDocumentHelper.getWikiIdFromDocumentFullname("XWiki.XWikiServerWikiid3")).thenReturn("wikiid3");
    when(cache.getFromId("wikiid3")).thenReturn(descriptor3);
    when(descriptorDocumentHelper.getDocumentFromWikiId("wikiid1")).thenReturn(document1);
    when(descriptorDocumentHelper.getDocumentFromWikiId("wikiid2")).thenReturn(document2);
    when(descriptorDocumentHelper.getDocumentFromWikiId("xwiki")).thenReturn(maindocument);
    when(maindocument.isNew()).thenReturn(true);
    // Get all XWiki.XWikiServerClass XObjects to pass to the Wiki Descriptor Builder
    List<BaseObject> baseObjects = Arrays.asList(mock(BaseObject.class));
    when(document1.getXObjects(any(EntityReference.class))).thenReturn(baseObjects);
    when(document2.getXObjects(any(EntityReference.class))).thenReturn(baseObjects);
    // Get a Wiki from the Wiki Descriptor Builder
    DefaultWikiDescriptor descriptor1 = new DefaultWikiDescriptor("wikiid1", "wikialias1");
    DefaultWikiDescriptor descriptor2 = new DefaultWikiDescriptor("wikiid2", "wikialias2");
    when(wikiDescriptorBuilder.buildDescriptorObject(anyListOf(BaseObject.class), any(XWikiDocument.class))).thenReturn(descriptor1, descriptor2);
    Collection<WikiDescriptor> descriptors = this.mocker.getComponentUnderTest().getAll();
    assertEquals(4, descriptors.size());
    // Verify that XWiki.XWikiServerWikiid3 has not be loaded
    verify(descriptorDocumentHelper, never()).getDocumentFromWikiId("wikiid3");
    // Verify all descriptors were put in cache except those which was already there
    verify(cache).add(descriptor1);
    verify(cache).add(descriptor2);
    verify(cache, never()).add(descriptor3);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) EntityReference(org.xwiki.model.reference.EntityReference) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 30 with WikiDescriptor

use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.

the class DefaultWikiDescriptorBuilderTest method buildDescriptorObjectWhenInvalidWiki.

@Test
public void buildDescriptorObjectWhenInvalidWiki() throws Exception {
    // Mocks
    List<BaseObject> objects = new ArrayList<>();
    BaseObject object1 = mock(BaseObject.class);
    objects.add(object1);
    when(object1.getStringValue(XWikiServerClassDocumentInitializer.FIELD_SERVER)).thenReturn(" ");
    XWikiDocument document = mock(XWikiDocument.class);
    // Test
    WikiDescriptor result = mocker.getComponentUnderTest().buildDescriptorObject(objects, document);
    assertNull(result);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ArrayList(java.util.ArrayList) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Aggregations

WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)60 Test (org.junit.Test)40 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)28 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)17 WikiReference (org.xwiki.model.reference.WikiReference)11 XWikiContext (com.xpn.xwiki.XWikiContext)9 WikiTemplateManagerException (org.xwiki.wiki.template.WikiTemplateManagerException)9 ArrayList (java.util.ArrayList)7 DocumentReference (org.xwiki.model.reference.DocumentReference)6 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 BaseObject (com.xpn.xwiki.objects.BaseObject)5 DefaultWikiDescriptor (org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor)5 WikiCreationRequest (org.xwiki.platform.wiki.creationjob.WikiCreationRequest)3 AuthorizationException (org.xwiki.security.authorization.AuthorizationException)3 WikiCopiedEvent (org.xwiki.bridge.event.WikiCopiedEvent)2 WikiCreatedEvent (org.xwiki.bridge.event.WikiCreatedEvent)2 WikiCreatingEvent (org.xwiki.bridge.event.WikiCreatingEvent)2 WikiCreationException (org.xwiki.platform.wiki.creationjob.WikiCreationException)2 WikiDescriptorBuilderException (org.xwiki.wiki.internal.descriptor.builder.WikiDescriptorBuilderException)2