Search in sources :

Example 1 with ExtensionJobHistory

use of org.xwiki.extension.job.history.ExtensionJobHistory 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)

Aggregations

Predicate (org.apache.commons.collections4.Predicate)1 Test (org.junit.Test)1 InstallRequest (org.xwiki.extension.job.InstallRequest)1 UninstallRequest (org.xwiki.extension.job.UninstallRequest)1 ExtensionJobHistory (org.xwiki.extension.job.history.ExtensionJobHistory)1 ExtensionJobHistoryRecord (org.xwiki.extension.job.history.ExtensionJobHistoryRecord)1