use of org.xwiki.extension.job.history.ExtensionJobHistoryRecord 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));
}
use of org.xwiki.extension.job.history.ExtensionJobHistoryRecord 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());
}
use of org.xwiki.extension.job.history.ExtensionJobHistoryRecord 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"));
}
use of org.xwiki.extension.job.history.ExtensionJobHistoryRecord in project xwiki-platform by xwiki.
the class ExtensionHistoryScriptServiceTest method replayWithPR.
@Test
public void replayWithPR() 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.xcontext.getAction()).thenReturn("foo");
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(true);
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(StringUtils.join(request.getId(), '/').startsWith("extension/history/"));
assertTrue(request.isInteractive());
assertEquals(Arrays.asList(install), request.getRecords());
assertEquals(this.xcontext.getWikiId(), request.getProperty("context.wiki"));
assertEquals(this.xcontext.getAction(), request.getProperty("context.action"));
assertEquals(this.documentAccessBridge.getCurrentUserReference(), request.getProperty("user.reference"));
assertEquals(Arrays.asList("wiki:drafts"), install.getRequest().getNamespaces());
assertEquals(new DocumentReference("drafts", "Users", "Alice"), install.getRequest().getProperty("user.reference"));
}
Aggregations