Search in sources :

Example 1 with InstallJob

use of org.xwiki.extension.job.internal.InstallJob in project xwiki-platform by xwiki.

the class ExtensionInstallerTest method installExtension.

@Test
public void installExtension() throws Exception {
    // Mocks
    InstallJob installJob = mock(InstallJob.class);
    mocker.registerComponent(Job.class, InstallJob.JOBTYPE, installJob);
    final InstallRequest[] installRequest = { null };
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            installRequest[0] = (InstallRequest) invocation.getArguments()[0];
            return null;
        }
    }).when(installJob).initialize(any(Request.class));
    // Test
    mocker.getComponentUnderTest().installExtension("wikiId", new ExtensionId("extensionId", "version"));
    // Verify
    assertNotNull(installRequest[0]);
    assertEquals(Arrays.asList("wiki:wikiId"), installRequest[0].getNamespaces());
    assertEquals(Arrays.asList("wikicreation", "install", "wikiId"), installRequest[0].getId());
    assertEquals(Arrays.asList(new ExtensionId("extensionId", "version")), installRequest[0].getExtensions());
    assertEquals(new DocumentReference("xwiki", "XWiki", "superadmin"), installRequest[0].getProperty("user.reference"));
    verify(installJob).run();
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InstallRequest(org.xwiki.extension.job.InstallRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Request(org.xwiki.job.Request) InstallRequest(org.xwiki.extension.job.InstallRequest) ExtensionId(org.xwiki.extension.ExtensionId) DocumentReference(org.xwiki.model.reference.DocumentReference) InstallJob(org.xwiki.extension.job.internal.InstallJob) Test(org.junit.Test)

Example 2 with InstallJob

use of org.xwiki.extension.job.internal.InstallJob in project xwiki-platform by xwiki.

the class ExtensionInstaller method installExtension.

/**
 * Install an extension on a wiki.
 *
 * @param wikiId id of the wiki
 * @param extensionId id of the extension to install
 * @throws org.xwiki.platform.wiki.creationjob.WikiCreationException if problem occurs
 */
public void installExtension(String wikiId, ExtensionId extensionId) throws WikiCreationException {
    try {
        // Create the install request
        InstallRequest installRequest = new InstallRequest();
        installRequest.setId(Arrays.asList(WikiCreationJob.JOB_ID_PREFIX, "install", wikiId));
        installRequest.addExtension(extensionId);
        installRequest.addNamespace("wiki:" + wikiId);
        // To avoid problem with Programming Rights, we install everything with superadmin
        installRequest.setProperty(PROPERTY_USERREFERENCE, SUPERADMIN_REFERENCE);
        InstallJob job = componentManager.getInstance(Job.class, InstallJob.JOBTYPE);
        job.initialize(installRequest);
        job.run();
    } catch (ComponentLookupException e) {
        throw new WikiCreationException(String.format("Failed to install the extension [%s] on the wiki [%s].", extensionId.toString(), wikiId), e);
    }
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) InstallRequest(org.xwiki.extension.job.InstallRequest) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) InstallJob(org.xwiki.extension.job.internal.InstallJob)

Example 3 with InstallJob

use of org.xwiki.extension.job.internal.InstallJob in project xwiki-platform by xwiki.

the class XarExtensionHandlerTest method installOnNamespace.

private XarInstalledExtension installOnNamespace(ExtensionId extensionId, String namespace, DocumentReference user) throws Throwable {
    InstallRequest installRequest = new InstallRequest();
    if (user != null) {
        installRequest.setProperty("user.reference", getXWikiContext().getUserReference());
        installRequest.setProperty("checkrights", true);
    }
    installRequest.addExtension(extensionId);
    if (namespace != null) {
        installRequest.addNamespace(namespace);
    }
    Job installJob = this.jobExecutor.execute(InstallJob.JOBTYPE, installRequest);
    installJob.join();
    List<LogEvent> errors = installJob.getStatus().getLog().getLogsFrom(LogLevel.WARN);
    if (!errors.isEmpty()) {
        if (errors.get(0).getThrowable() != null) {
            throw errors.get(0).getThrowable();
        } else {
            throw new Exception(errors.get(0).getFormattedMessage());
        }
    }
    return (XarInstalledExtension) this.xarExtensionRepository.resolve(extensionId);
}
Also used : LogEvent(org.xwiki.logging.event.LogEvent) XarInstalledExtension(org.xwiki.extension.xar.internal.repository.XarInstalledExtension) InstallRequest(org.xwiki.extension.job.InstallRequest) UninstallJob(org.xwiki.extension.job.internal.UninstallJob) InstallJob(org.xwiki.extension.job.internal.InstallJob) Job(org.xwiki.job.Job) UninstallException(org.xwiki.extension.UninstallException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) InstallException(org.xwiki.extension.InstallException)

Aggregations

InstallRequest (org.xwiki.extension.job.InstallRequest)3 InstallJob (org.xwiki.extension.job.internal.InstallJob)3 Test (org.junit.Test)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 ExtensionId (org.xwiki.extension.ExtensionId)1 InstallException (org.xwiki.extension.InstallException)1 UninstallException (org.xwiki.extension.UninstallException)1 UninstallJob (org.xwiki.extension.job.internal.UninstallJob)1 XarInstalledExtension (org.xwiki.extension.xar.internal.repository.XarInstalledExtension)1 Job (org.xwiki.job.Job)1 Request (org.xwiki.job.Request)1 LogEvent (org.xwiki.logging.event.LogEvent)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 WikiCreationException (org.xwiki.platform.wiki.creationjob.WikiCreationException)1 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)1