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));
}
Aggregations