Search in sources :

Example 21 with WikiDescriptorManager

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"));
}
Also used : WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) WikiPropertyGroup(org.xwiki.wiki.properties.WikiPropertyGroup) Test(org.junit.Test)

Example 22 with WikiDescriptorManager

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;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) ArrayList(java.util.ArrayList) WikiReference(org.xwiki.model.reference.WikiReference)

Example 23 with WikiDescriptorManager

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);
    }
}
Also used : QueryFilter(org.xwiki.query.QueryFilter) Query(org.xwiki.query.Query) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) XWikiException(com.xpn.xwiki.XWikiException) QueryException(org.xwiki.query.QueryException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException)

Example 24 with WikiDescriptorManager

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"));
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) WebJarsResourceReference(org.xwiki.webjars.internal.WebJarsResourceReference) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) ExtensionId(org.xwiki.extension.ExtensionId) ExtendedURL(org.xwiki.url.ExtendedURL) InstalledExtensionRepository(org.xwiki.extension.repository.InstalledExtensionRepository) Test(org.junit.Test)

Example 25 with WikiDescriptorManager

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()));
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) WebJarsResourceReference(org.xwiki.webjars.internal.WebJarsResourceReference) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) ExtensionId(org.xwiki.extension.ExtensionId) ExtendedURL(org.xwiki.url.ExtendedURL) InstalledExtensionRepository(org.xwiki.extension.repository.InstalledExtensionRepository) Test(org.junit.Test)

Aggregations

WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)40 Test (org.junit.Test)17 DocumentReference (org.xwiki.model.reference.DocumentReference)14 Before (org.junit.Before)13 XWikiContext (com.xpn.xwiki.XWikiContext)11 Execution (org.xwiki.context.Execution)9 ExecutionContext (org.xwiki.context.ExecutionContext)9 XWiki (com.xpn.xwiki.XWiki)8 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)8 ExtensionId (org.xwiki.extension.ExtensionId)6 AuthorizationManager (org.xwiki.security.authorization.AuthorizationManager)6 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)6 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)6 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)5 ExtendedURL (org.xwiki.url.ExtendedURL)5 WebJarsResourceReference (org.xwiki.webjars.internal.WebJarsResourceReference)5 InstalledExtension (org.xwiki.extension.InstalledExtension)4 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)4 Query (org.xwiki.query.Query)4 BaseObject (com.xpn.xwiki.objects.BaseObject)3