use of org.xwiki.wiki.descriptor.WikiDescriptorManager in project xwiki-platform by xwiki.
the class DefaultWikiDescriptorManagerTest method testCacheProtection.
@Test
public void testCacheProtection() throws WikiManagerException, ComponentLookupException {
DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("xwiki", "xwiki");
descriptor.setPrettyName("pretty name");
WikiPropertyGroup propertyGroup = new WikiPropertyGroup("group");
propertyGroup.set("property", "value");
descriptor.addPropertyGroup(propertyGroup);
when(cache.getFromId("xwiki")).thenReturn(descriptor);
when(cache.getFromAlias("xwiki")).thenReturn(descriptor);
WikiDescriptorManager wikiDescriptorManager = this.mocker.getComponentUnderTest();
// Modify the descriptor without saving it
wikiDescriptorManager.getById("xwiki").setPrettyName("changed pretty name");
assertEquals("pretty name", wikiDescriptorManager.getById("xwiki").getPrettyName());
wikiDescriptorManager.getById("xwiki").getPropertyGroup("group").set("property", "modified value");
assertEquals("value", wikiDescriptorManager.getById("xwiki").getPropertyGroup("group").get("property"));
// Modify the descriptor without saving it
wikiDescriptorManager.getByAlias("xwiki").setPrettyName("changed pretty name");
assertEquals("pretty name", wikiDescriptorManager.getByAlias("xwiki").getPrettyName());
wikiDescriptorManager.getByAlias("xwiki").getPropertyGroup("group").set("property", "modified value");
assertEquals("value", wikiDescriptorManager.getByAlias("xwiki").getPropertyGroup("group").get("property"));
// Modify the descriptor without saving it
wikiDescriptorManager.getMainWikiDescriptor().setPrettyName("changed pretty name");
assertEquals("pretty name", wikiDescriptorManager.getMainWikiDescriptor().getPrettyName());
wikiDescriptorManager.getMainWikiDescriptor().getPropertyGroup("group").set("property", "modified value");
assertEquals("value", wikiDescriptorManager.getMainWikiDescriptor().getPropertyGroup("group").get("property"));
}
use of org.xwiki.wiki.descriptor.WikiDescriptorManager in project xwiki-platform by xwiki.
the class DefaultWikiDescriptorDocumentHelper method getAllXWikiServerClassDocument.
@Override
public List<XWikiDocument> getAllXWikiServerClassDocument() throws WikiManagerException {
WikiDescriptorManager wikiDescriptorManager = wikiDescriptorManagerProvider.get();
List<XWikiDocument> result = new ArrayList<XWikiDocument>();
List<String> documentNames = getAllXWikiServerClassDocumentNames();
if (documentNames != null) {
WikiReference mainWikiReference = new WikiReference(wikiDescriptorManager.getMainWikiId());
for (String documentName : documentNames) {
result.add(getDocument(documentReferenceResolver.resolve(documentName, mainWikiReference)));
}
}
return result;
}
use of org.xwiki.wiki.descriptor.WikiDescriptorManager in project xwiki-platform by xwiki.
the class DefaultWikiDescriptorDocumentHelper method getAllXWikiServerClassDocumentNames.
@Override
public List<String> getAllXWikiServerClassDocumentNames() throws WikiManagerException {
WikiDescriptorManager wikiDescriptorManager = wikiDescriptorManagerProvider.get();
try {
Query query = this.queryManager.createQuery("from doc.object(XWiki.XWikiServerClass) as descriptor where doc.name like 'XWikiServer%' " + "and doc.fullName <> 'XWiki.XWikiServerClassTemplate'", Query.XWQL);
query.setWiki(wikiDescriptorManager.getMainWikiId());
query.addFilter(componentManager.<QueryFilter>getInstance(QueryFilter.class, "unique"));
return query.execute();
} catch (Exception e) {
throw new WikiManagerException("Failed to locate XWiki.XWikiServerClass documents", e);
}
}
use of org.xwiki.wiki.descriptor.WikiDescriptorManager in project xwiki-platform by xwiki.
the class WebJarsScriptServiceTest method computeURLWithoutVersion.
@Test
public void computeURLWithoutVersion() throws Exception {
WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("math");
InstalledExtensionRepository installedExtensionRepository = this.mocker.getInstance(InstalledExtensionRepository.class);
InstalledExtension extension = mock(InstalledExtension.class);
when(installedExtensionRepository.getInstalledExtension("org.webjars:angular", "wiki:math")).thenReturn(extension);
when(extension.getId()).thenReturn(new ExtensionId("bar", "2.1.11"));
WebJarsResourceReference resourceReference = new WebJarsResourceReference("wiki:math", Arrays.asList("angular", "2.1.11", "angular.css"));
when(this.serializer.serialize(resourceReference)).thenReturn(new ExtendedURL(Arrays.asList("xwiki", "angular", "2.1.11", "angular.css")));
assertEquals("/xwiki/angular/2.1.11/angular.css", this.mocker.getComponentUnderTest().url("angular", "angular.css"));
}
use of org.xwiki.wiki.descriptor.WikiDescriptorManager in project xwiki-platform by xwiki.
the class WebJarsScriptServiceTest method computeURLWithParametersAndWikiIsNotSpecifiedInParameter.
@Test
public void computeURLWithParametersAndWikiIsNotSpecifiedInParameter() throws Exception {
WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("math");
InstalledExtensionRepository installedExtensionRepository = this.mocker.getInstance(InstalledExtensionRepository.class);
InstalledExtension extension = mock(InstalledExtension.class);
when(installedExtensionRepository.getInstalledExtension("org.webjars:angular", "wiki:math")).thenReturn(extension);
when(extension.getId()).thenReturn(new ExtensionId("bar", "2.1.11"));
WebJarsResourceReference resourceReference = new WebJarsResourceReference("wiki:math", Arrays.asList("angular", "2.1.11", "angular.css"));
when(this.serializer.serialize(resourceReference)).thenReturn(new ExtendedURL(Arrays.asList("xwiki", "angular", "2.1.11", "angular.css")));
assertEquals("/xwiki/angular/2.1.11/angular.css", this.mocker.getComponentUnderTest().url("angular", "angular.css", Collections.<String, Object>emptyMap()));
}
Aggregations