Search in sources :

Example 6 with JobStatus

use of org.xwiki.job.event.status.JobStatus in project xwiki-platform by xwiki.

the class DocumentsDeletingListenerTest method testCancel.

@Test
public void testCancel() throws Exception {
    Request request = mock(Request.class);
    Job job = mock(Job.class);
    JobStatus status = mock(JobStatus.class);
    when(job.getRequest()).thenReturn(request);
    when(request.isInteractive()).thenReturn(true);
    when(job.getStatus()).thenReturn(status);
    Map<EntityReference, EntitySelection> concernedEntities = new HashMap<>();
    DocumentReference doc1 = new DocumentReference("a", "b", "c1");
    concernedEntities.put(doc1, new EntitySelection(doc1));
    XarInstalledExtension ext1 = mock(XarInstalledExtension.class);
    when(ext1.getId()).thenReturn(new ExtensionId("ext1"));
    when(repository.getXarInstalledExtensions(doc1)).thenReturn(Arrays.asList(ext1));
    InterruptedException e = new InterruptedException();
    doThrow(e).when(status).ask(any(), anyLong(), any());
    // Test
    DocumentsDeletingEvent event = mock(DocumentsDeletingEvent.class);
    mocker.getComponentUnderTest().onEvent(event, job, concernedEntities);
    // Check
    verify(status, times(1)).ask(any(), eq(5L), eq(TimeUnit.MINUTES));
    verify(event).cancel(eq("Question has been interrupted."));
    verify(mocker.getMockedLogger()).warn("Confirm question has been interrupted.");
}
Also used : JobStatus(org.xwiki.job.event.status.JobStatus) HashMap(java.util.HashMap) XarInstalledExtension(org.xwiki.extension.xar.internal.repository.XarInstalledExtension) EntitySelection(org.xwiki.refactoring.job.question.EntitySelection) Request(org.xwiki.job.Request) EntityReference(org.xwiki.model.reference.EntityReference) ExtensionId(org.xwiki.extension.ExtensionId) Job(org.xwiki.job.Job) DocumentReference(org.xwiki.model.reference.DocumentReference) DocumentsDeletingEvent(org.xwiki.bridge.event.DocumentsDeletingEvent) Test(org.junit.Test)

Example 7 with JobStatus

use of org.xwiki.job.event.status.JobStatus in project xwiki-platform by xwiki.

the class DefaultWikiCreatorTest method getJobStatus.

@Test
public void getJobStatus() throws Exception {
    // Mocks
    Job job = mock(Job.class);
    JobStatus jobStatus1 = mock(JobStatus.class);
    when(job.getStatus()).thenReturn(jobStatus1);
    when(jobExecutor.getJob(Arrays.asList("wikicreation", "createandinstall", "wiki1"))).thenReturn(job);
    JobStatus jobStatus2 = mock(JobStatus.class);
    when(jobStatusStore.getJobStatus(Arrays.asList("wikicreation", "createandinstall", "wiki2"))).thenReturn(jobStatus2);
    // Tests
    assertEquals(jobStatus1, mocker.getComponentUnderTest().getJobStatus("wiki1"));
    assertEquals(jobStatus2, mocker.getComponentUnderTest().getJobStatus("wiki2"));
}
Also used : JobStatus(org.xwiki.job.event.status.JobStatus) Job(org.xwiki.job.Job) Test(org.junit.Test)

Example 8 with JobStatus

use of org.xwiki.job.event.status.JobStatus in project xwiki-platform by xwiki.

the class WikiCreationJobScriptServicesTest method getJobStatus.

@Test
public void getJobStatus() throws Exception {
    JobStatus jobStatus = mock(JobStatus.class);
    when(wikiCreator.getJobStatus("wikiId")).thenReturn(jobStatus);
    assertEquals(jobStatus, mocker.getComponentUnderTest().getJobStatus("wikiId"));
}
Also used : JobStatus(org.xwiki.job.event.status.JobStatus) Test(org.junit.Test)

Example 9 with JobStatus

use of org.xwiki.job.event.status.JobStatus in project xwiki-platform by xwiki.

the class XarExtensionScriptService method reset.

/**
 * @param reference the reference of the document to reset to its standard state (what it looks like in the
 *            extension XAR)
 * @param jobId the id of the job which computed the diff if any
 * @return true if the reset actually did something, false otherwise (any produced error can be accessed using
 *         {@link #getLastError()})
 * @since 9.3RC1
 */
public boolean reset(DocumentReference reference, List<String> jobId) {
    setError(null);
    try {
        // Only current author is allowed to modify (and so reset) the target document
        this.genericAuthorization.checkAccess(Right.EDIT, this.xcontextProvider.get().getAuthorReference(), reference);
        // Reset the document in the DB
        this.packager.reset(reference, this.xcontextProvider.get().getUserReference());
        // Update the existing job status if any
        if (jobId != null) {
            JobStatus jobStatus = getJobStatus(jobId);
            if (jobStatus != null && jobStatus instanceof DiffXarJobStatus) {
                ((DiffXarJobStatus) jobStatus).reset(reference);
            }
        }
        return true;
    } catch (Exception e) {
        setError(e);
    }
    return false;
}
Also used : JobStatus(org.xwiki.job.event.status.JobStatus) DiffXarJobStatus(org.xwiki.extension.xar.job.diff.DiffXarJobStatus) DiffXarJobStatus(org.xwiki.extension.xar.job.diff.DiffXarJobStatus) IOException(java.io.IOException) JobException(org.xwiki.job.JobException) XarException(org.xwiki.xar.XarException)

Example 10 with JobStatus

use of org.xwiki.job.event.status.JobStatus in project xwiki-platform by xwiki.

the class DocumentsDeletingListenerTest method test.

@Test
public void test() throws Exception {
    Request request = mock(Request.class);
    Job job = mock(Job.class);
    JobStatus status = mock(JobStatus.class);
    when(job.getRequest()).thenReturn(request);
    when(request.isInteractive()).thenReturn(true);
    when(job.getStatus()).thenReturn(status);
    Map<EntityReference, EntitySelection> concernedEntities = new HashMap<>();
    DocumentReference doc1 = new DocumentReference("a", "b", "c1");
    DocumentReference doc2 = new DocumentReference("a", "b", "c2");
    DocumentReference doc3 = new DocumentReference("a", "b", "c3");
    concernedEntities.put(doc1, new EntitySelection(doc1));
    concernedEntities.put(doc2, new EntitySelection(doc2));
    concernedEntities.put(doc3, new EntitySelection(doc3));
    XarInstalledExtension ext1 = mock(XarInstalledExtension.class);
    XarInstalledExtension ext2 = mock(XarInstalledExtension.class);
    when(ext1.getId()).thenReturn(new ExtensionId("ext1"));
    when(ext2.getId()).thenReturn(new ExtensionId("ext2"));
    when(repository.getXarInstalledExtensions(doc1)).thenReturn(Arrays.asList(ext1, ext2));
    when(repository.getXarInstalledExtensions(doc2)).thenReturn(Collections.emptyList());
    when(repository.getXarInstalledExtensions(doc3)).thenReturn(Arrays.asList(ext2));
    doAnswer(invocationOnMock -> {
        ExtensionBreakingQuestion question = invocationOnMock.getArgument(0);
        assertEquals(concernedEntities, question.getConcernedEntities());
        // Ext 1
        assertEquals(1, question.getExtension("ext1").getPages().size());
        assertTrue(question.getExtension("ext1").getPages().contains(concernedEntities.get(doc1)));
        // Ext 2
        assertEquals(2, question.getExtension("ext2").getPages().size());
        assertTrue(question.getExtension("ext2").getPages().contains(concernedEntities.get(doc1)));
        assertTrue(question.getExtension("ext2").getPages().contains(concernedEntities.get(doc3)));
        // Free pages
        assertEquals(1, question.getFreePages().size());
        assertTrue(question.getFreePages().contains(concernedEntities.get(doc2)));
        // Assert nothing is select by default
        for (EntitySelection selection : question.getConcernedEntities().values()) {
            assertFalse(selection.isSelected());
        }
        return null;
    }).when(status).ask(any(), anyLong(), any());
    // Test
    DocumentsDeletingEvent event = new DocumentsDeletingEvent();
    mocker.getComponentUnderTest().onEvent(event, job, concernedEntities);
    // Check
    verify(status, times(1)).ask(any(), eq(5L), eq(TimeUnit.MINUTES));
}
Also used : JobStatus(org.xwiki.job.event.status.JobStatus) HashMap(java.util.HashMap) XarInstalledExtension(org.xwiki.extension.xar.internal.repository.XarInstalledExtension) EntitySelection(org.xwiki.refactoring.job.question.EntitySelection) Request(org.xwiki.job.Request) EntityReference(org.xwiki.model.reference.EntityReference) ExtensionBreakingQuestion(org.xwiki.extension.xar.internal.delete.question.ExtensionBreakingQuestion) ExtensionId(org.xwiki.extension.ExtensionId) Job(org.xwiki.job.Job) DocumentReference(org.xwiki.model.reference.DocumentReference) DocumentsDeletingEvent(org.xwiki.bridge.event.DocumentsDeletingEvent) Test(org.junit.Test)

Aggregations

JobStatus (org.xwiki.job.event.status.JobStatus)17 Job (org.xwiki.job.Job)10 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)4 DocumentsDeletingEvent (org.xwiki.bridge.event.DocumentsDeletingEvent)3 Request (org.xwiki.job.Request)3 HashMap (java.util.HashMap)2 ExtensionId (org.xwiki.extension.ExtensionId)2 DistributionJobStatus (org.xwiki.extension.distribution.internal.job.DistributionJobStatus)2 XarInstalledExtension (org.xwiki.extension.xar.internal.repository.XarInstalledExtension)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 EntityReference (org.xwiki.model.reference.EntityReference)2 EntitySelection (org.xwiki.refactoring.job.question.EntitySelection)2 XWikiInitializerJob (com.xpn.xwiki.internal.XWikiInitializerJob)1 XWikiInitializerJobStatus (com.xpn.xwiki.internal.XWikiInitializerJobStatus)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 DistributionState (org.xwiki.extension.distribution.internal.DistributionManager.DistributionState)1 DistributionJob (org.xwiki.extension.distribution.internal.job.DistributionJob)1