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;
}
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");
}
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");
}
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);
}
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);
}
Aggregations