Search in sources :

Example 11 with WikiDescriptorManager

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

the class UsersClassPropertyValuesProviderTest method getValuesGlobal.

@Test
public void getValuesGlobal() throws Exception {
    when(this.wikiUserManager.getUserScope(this.classReference.getWikiReference().getName())).thenReturn(UserScope.GLOBAL_ONLY);
    WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getMainWikiId()).thenReturn("math");
    this.mocker.getComponentUnderTest().getValues(this.propertyReference, 5, "foo");
    verify(this.allowedValuesQuery).setWiki("math");
    verify(this.allowedValuesQuery, times(1)).execute();
}
Also used : WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) Test(org.junit.Test)

Example 12 with WikiDescriptorManager

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

the class WebJarsScriptServiceTest method computeURLWithVersion.

@Test
public void computeURLWithVersion() throws Exception {
    WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("math");
    WebJarsResourceReference resourceReference = new WebJarsResourceReference("wiki:math", Arrays.asList("ang:ular", "2.1.11", "angular.css"));
    // Test that colon is not interpreted as groupId/artifactId separator (for backwards compatibility).
    when(this.serializer.serialize(resourceReference)).thenReturn(new ExtendedURL(Arrays.asList("xwiki", "ang:ular", "2.1.11", "angular.css")));
    assertEquals("/xwiki/ang%3Aular/2.1.11/angular.css", this.mocker.getComponentUnderTest().url("ang:ular/2.1.11/angular.css"));
}
Also used : WebJarsResourceReference(org.xwiki.webjars.internal.WebJarsResourceReference) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) ExtendedURL(org.xwiki.url.ExtendedURL) Test(org.junit.Test)

Example 13 with WikiDescriptorManager

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

the class WebJarsScriptServiceTest method computeURLWithoutVersionAndNoExtensionMatchingWebJarId.

@Test
public void computeURLWithoutVersionAndNoExtensionMatchingWebJarId() throws Exception {
    WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("math");
    WebJarsResourceReference resourceReference = new WebJarsResourceReference("wiki:math", Arrays.asList("angular", "angular.css"));
    when(this.serializer.serialize(resourceReference)).thenReturn(new ExtendedURL(Arrays.asList("xwiki", "angular", "angular.css")));
    assertEquals("/xwiki/angular/angular.css", this.mocker.getComponentUnderTest().url("angular", "angular.css"));
}
Also used : WebJarsResourceReference(org.xwiki.webjars.internal.WebJarsResourceReference) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) ExtendedURL(org.xwiki.url.ExtendedURL) Test(org.junit.Test)

Example 14 with WikiDescriptorManager

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

the class WikiCreationJobScriptServicesTest method setUp.

@Before
public void setUp() throws Exception {
    wikiCreator = mocker.getInstance(WikiCreator.class);
    execution = mocker.getInstance(Execution.class);
    authorizationManager = mocker.getInstance(AuthorizationManager.class);
    wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
    distributionManager = mocker.getInstance(DistributionManager.class);
    xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    xcontext = mock(XWikiContext.class);
    when(xcontextProvider.get()).thenReturn(xcontext);
    xwiki = mock(XWiki.class);
    when(xcontext.getWiki()).thenReturn(xwiki);
    when(wikiDescriptorManager.getMainWikiId()).thenReturn("mainWikiId");
    ExecutionContext executionContext = new ExecutionContext();
    when(execution.getContext()).thenReturn(executionContext);
    ExtensionId extensionId = new ExtensionId("authorized-extension", "1.0");
    when(distributionManager.getWikiUIExtensionId()).thenReturn(extensionId);
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) WikiCreator(org.xwiki.platform.wiki.creationjob.WikiCreator) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) ExtensionId(org.xwiki.extension.ExtensionId) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager) DistributionManager(org.xwiki.extension.distribution.internal.DistributionManager) Before(org.junit.Before)

Example 15 with WikiDescriptorManager

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

the class DefaultWikiDescriptorDocumentHelper method findXWikiServerClassDocumentReference.

@Override
public DocumentReference findXWikiServerClassDocumentReference(String wikiAlias) throws WikiManagerException {
    if (wikiAlias == null) {
        throw new IllegalArgumentException("Wiki alias cannot be null");
    }
    WikiDescriptorManager wikiDescriptorManager = wikiDescriptorManagerProvider.get();
    DocumentReference result = null;
    try {
        Query query = this.queryManager.createQuery("where doc.object(XWiki.XWikiServerClass).server = :wikiAlias and doc.name like 'XWikiServer%'", Query.XWQL);
        query.bindValue("wikiAlias", wikiAlias);
        query.setWiki(wikiDescriptorManager.getMainWikiId());
        List<String> documentNames = query.execute();
        // Resolve the document name into a references
        if (documentNames != null && !documentNames.isEmpty()) {
            result = documentReferenceResolver.resolve(documentNames.get(0));
        }
    } catch (QueryException e) {
        throw new WikiManagerException(String.format("Failed to locate XWiki.XWikiServerClass document for wiki alias [%s]", wikiAlias), e);
    }
    return result;
}
Also used : QueryException(org.xwiki.query.QueryException) Query(org.xwiki.query.Query) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) DocumentReference(org.xwiki.model.reference.DocumentReference)

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