Search in sources :

Example 6 with InstallRequest

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

the class ExtensionManagerScriptService method createInstallRequest.

// Actions
/**
 * Create an {@link InstallRequest} instance based on passed parameters.
 *
 * @param id the identifier of the extension to install
 * @param version the version to install
 * @param namespace the (optional) namespace where to install the extension; if {@code null} or empty, the extension
 *            will be installed in root namespace (globally)
 * @return the {@link InstallRequest}
 */
public InstallRequest createInstallRequest(String id, String version, String namespace) {
    InstallRequest installRequest = createInstallPlanRequest(id, version, namespace);
    installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_ACTION_PREFIX, id, namespace));
    return installRequest;
}
Also used : InstallRequest(org.xwiki.extension.job.InstallRequest)

Example 7 with InstallRequest

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

the class ExtensionHistoryScriptServiceTest method getRecords.

@Test
public void getRecords() throws Exception {
    InstallRequest devInstallReq = new InstallRequest();
    devInstallReq.addNamespace("wiki:dev");
    ExtensionJobHistoryRecord devInstall = new ExtensionJobHistoryRecord("install", devInstallReq, null, null, null);
    UninstallRequest devUninstallReq = new UninstallRequest();
    devUninstallReq.addNamespace("wiki:dev");
    ExtensionJobHistoryRecord devUninstall = new ExtensionJobHistoryRecord("uninstall", devUninstallReq, null, null, null);
    ExtensionJobHistoryRecord globalInstall = new ExtensionJobHistoryRecord("install", new InstallRequest(), null, null, null);
    ExtensionJobHistoryRecord globalUninstall = new ExtensionJobHistoryRecord("uninstall", new UninstallRequest(), null, null, null);
    InstallRequest draftsInstallReq = new InstallRequest();
    draftsInstallReq.addNamespace("wiki:drafts");
    ExtensionJobHistoryRecord draftsInstall = new ExtensionJobHistoryRecord("install", draftsInstallReq, null, null, null);
    List<ExtensionJobHistoryRecord> records = Arrays.asList(devInstall, globalInstall);
    ExtensionJobHistory history = this.mocker.getInstance(ExtensionJobHistory.class);
    ArgumentCaptor<Predicate<ExtensionJobHistoryRecord>> predicateCaptor = ArgumentCaptor.forClass((Class) Predicate.class);
    when(history.getRecords(predicateCaptor.capture(), eq("offsetRecordId"), eq(5))).thenReturn(records);
    when(this.xcontext.getWikiId()).thenReturn("dev");
    assertEquals(records, this.mocker.getComponentUnderTest().getRecords().fromThisWiki().ofType(Arrays.asList("install")).list("offsetRecordId", 5));
    Predicate<ExtensionJobHistoryRecord> predicate = predicateCaptor.getValue();
    assertTrue(predicate.evaluate(devInstall));
    assertTrue(predicate.evaluate(globalInstall));
    assertFalse(predicate.evaluate(devUninstall));
    assertFalse(predicate.evaluate(globalUninstall));
    assertFalse(predicate.evaluate(draftsInstall));
}
Also used : ExtensionJobHistoryRecord(org.xwiki.extension.job.history.ExtensionJobHistoryRecord) InstallRequest(org.xwiki.extension.job.InstallRequest) ExtensionJobHistory(org.xwiki.extension.job.history.ExtensionJobHistory) UninstallRequest(org.xwiki.extension.job.UninstallRequest) Predicate(org.apache.commons.collections4.Predicate) Test(org.junit.Test)

Example 8 with InstallRequest

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

the class ExtensionHistoryScriptServiceTest method replayWithoutAdmin.

@Test
public void replayWithoutAdmin() throws Exception {
    InstallRequest installRequest = new InstallRequest();
    installRequest.addNamespace("wiki:dev");
    ExtensionJobHistoryRecord install = new ExtensionJobHistoryRecord("install", installRequest, null, null, null);
    List<ExtensionJobHistoryRecord> records = Arrays.asList(install);
    when(this.xcontext.getWikiId()).thenReturn("dev");
    when(this.authorization.hasAccess(Right.ADMIN, new WikiReference("dev"))).thenReturn(false);
    Job replayJob = mock(Job.class);
    ArgumentCaptor<ReplayRequest> requestCaptor = ArgumentCaptor.forClass(ReplayRequest.class);
    when(jobExecutor.execute(eq(ReplayJob.JOB_TYPE), requestCaptor.capture())).thenReturn(replayJob);
    assertSame(replayJob, this.mocker.getComponentUnderTest().replay(records));
    ReplayRequest request = requestCaptor.getValue();
    assertTrue(request.getRecords().isEmpty());
}
Also used : ExtensionJobHistoryRecord(org.xwiki.extension.job.history.ExtensionJobHistoryRecord) ReplayRequest(org.xwiki.extension.job.history.ReplayRequest) InstallRequest(org.xwiki.extension.job.InstallRequest) WikiReference(org.xwiki.model.reference.WikiReference) ReplayJob(org.xwiki.extension.job.history.internal.ReplayJob) Job(org.xwiki.job.Job) Test(org.junit.Test)

Example 9 with InstallRequest

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

the class ExtensionHistoryScriptServiceTest method replayWithAdminButNoPR.

@Test
public void replayWithAdminButNoPR() throws Exception {
    InstallRequest installRequest = new InstallRequest();
    installRequest.addNamespace("wiki:drafts");
    installRequest.setProperty("user.reference", new DocumentReference("drafts", "Users", "Alice"));
    ExtensionJobHistoryRecord install = new ExtensionJobHistoryRecord("install", installRequest, null, null, null);
    List<ExtensionJobHistoryRecord> records = Arrays.asList(install);
    when(this.xcontext.getWikiId()).thenReturn("dev");
    when(this.documentAccessBridge.getCurrentUserReference()).thenReturn(new DocumentReference("dev", "Users", "Bob"));
    when(this.authorization.hasAccess(Right.ADMIN, new WikiReference("dev"))).thenReturn(true);
    when(this.authorization.hasAccess(Right.PROGRAM)).thenReturn(false);
    Job replayJob = mock(Job.class);
    ArgumentCaptor<ReplayRequest> requestCaptor = ArgumentCaptor.forClass(ReplayRequest.class);
    when(jobExecutor.execute(eq(ReplayJob.JOB_TYPE), requestCaptor.capture())).thenReturn(replayJob);
    assertSame(replayJob, this.mocker.getComponentUnderTest().replay(records));
    ReplayRequest request = requestCaptor.getValue();
    assertEquals(Arrays.asList(install), request.getRecords());
    assertEquals(Arrays.asList("wiki:dev"), install.getRequest().getNamespaces());
    assertEquals(this.documentAccessBridge.getCurrentUserReference(), install.getRequest().getProperty("user.reference"));
}
Also used : ExtensionJobHistoryRecord(org.xwiki.extension.job.history.ExtensionJobHistoryRecord) ReplayRequest(org.xwiki.extension.job.history.ReplayRequest) InstallRequest(org.xwiki.extension.job.InstallRequest) WikiReference(org.xwiki.model.reference.WikiReference) ReplayJob(org.xwiki.extension.job.history.internal.ReplayJob) Job(org.xwiki.job.Job) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 10 with InstallRequest

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

the class ExtensionManagerScriptServiceTest method testOverwriteAllowedNamespaces.

@Test
public void testOverwriteAllowedNamespaces() throws Throwable {
    InstallRequest installRequest = this.scriptService.createInstallRequest("extension", "version", "namespace");
    // Indicate all extensions of type "test" should be installed on root
    ((ScriptExtensionRewriter) installRequest.getRewriter()).installExtensionTypeOnRootNamespace("test");
    // Allow redirect on root
    installRequest.setRootModificationsAllowed(true);
    Job job = this.scriptService.install(installRequest);
    if (job == null) {
        throw this.scriptService.getLastError();
    }
    job.join();
    List<LogEvent> errors = job.getStatus().getLog().getLogsFrom(LogLevel.WARN);
    if (!errors.isEmpty()) {
        throw errors.get(0).getThrowable();
    }
    // Validate
    InstalledExtensionRepository repository = mocker.getInstance(InstalledExtensionRepository.class);
    assertNotNull(repository.getInstalledExtension("extension", null));
}
Also used : LogEvent(org.xwiki.logging.event.LogEvent) InstallRequest(org.xwiki.extension.job.InstallRequest) Job(org.xwiki.job.Job) InstalledExtensionRepository(org.xwiki.extension.repository.InstalledExtensionRepository) Test(org.junit.Test)

Aggregations

InstallRequest (org.xwiki.extension.job.InstallRequest)21 DocumentReference (org.xwiki.model.reference.DocumentReference)8 Test (org.junit.Test)7 Job (org.xwiki.job.Job)7 ExtensionId (org.xwiki.extension.ExtensionId)6 ExtensionJobHistoryRecord (org.xwiki.extension.job.history.ExtensionJobHistoryRecord)4 ReplayRequest (org.xwiki.extension.job.history.ReplayRequest)3 ReplayJob (org.xwiki.extension.job.history.internal.ReplayJob)3 InstallJob (org.xwiki.extension.job.internal.InstallJob)3 WikiReference (org.xwiki.model.reference.WikiReference)3 IOException (java.io.IOException)2 InstallException (org.xwiki.extension.InstallException)2 InstalledExtension (org.xwiki.extension.InstalledExtension)2 UninstallRequest (org.xwiki.extension.job.UninstallRequest)2 ScriptExtensionRewriter (org.xwiki.extension.script.ScriptExtensionRewriter)2 JobException (org.xwiki.job.JobException)2 LogEvent (org.xwiki.logging.event.LogEvent)2 XarException (org.xwiki.xar.XarException)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 Predicate (org.apache.commons.collections4.Predicate)1