Search in sources :

Example 6 with XarInstalledExtension

use of org.xwiki.extension.xar.internal.repository.XarInstalledExtension in project xwiki-platform by xwiki.

the class XarExtensionHandlerTest method installOnNamespace.

private XarInstalledExtension installOnNamespace(ExtensionId extensionId, String namespace, DocumentReference user) throws Throwable {
    InstallRequest installRequest = new InstallRequest();
    if (user != null) {
        installRequest.setProperty("user.reference", getXWikiContext().getUserReference());
        installRequest.setProperty("checkrights", true);
    }
    installRequest.addExtension(extensionId);
    if (namespace != null) {
        installRequest.addNamespace(namespace);
    }
    Job installJob = this.jobExecutor.execute(InstallJob.JOBTYPE, installRequest);
    installJob.join();
    List<LogEvent> errors = installJob.getStatus().getLog().getLogsFrom(LogLevel.WARN);
    if (!errors.isEmpty()) {
        if (errors.get(0).getThrowable() != null) {
            throw errors.get(0).getThrowable();
        } else {
            throw new Exception(errors.get(0).getFormattedMessage());
        }
    }
    return (XarInstalledExtension) this.xarExtensionRepository.resolve(extensionId);
}
Also used : LogEvent(org.xwiki.logging.event.LogEvent) XarInstalledExtension(org.xwiki.extension.xar.internal.repository.XarInstalledExtension) InstallRequest(org.xwiki.extension.job.InstallRequest) UninstallJob(org.xwiki.extension.job.internal.UninstallJob) InstallJob(org.xwiki.extension.job.internal.InstallJob) Job(org.xwiki.job.Job) UninstallException(org.xwiki.extension.UninstallException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) InstallException(org.xwiki.extension.InstallException)

Example 7 with XarInstalledExtension

use of org.xwiki.extension.xar.internal.repository.XarInstalledExtension 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

XarInstalledExtension (org.xwiki.extension.xar.internal.repository.XarInstalledExtension)7 DocumentReference (org.xwiki.model.reference.DocumentReference)5 Job (org.xwiki.job.Job)4 Test (org.junit.Test)3 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 HashMap (java.util.HashMap)2 DocumentsDeletingEvent (org.xwiki.bridge.event.DocumentsDeletingEvent)2 ExtensionId (org.xwiki.extension.ExtensionId)2 InstallException (org.xwiki.extension.InstallException)2 UninstallException (org.xwiki.extension.UninstallException)2 Request (org.xwiki.job.Request)2 JobStatus (org.xwiki.job.event.status.JobStatus)2 EntityReference (org.xwiki.model.reference.EntityReference)2 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)2 EntitySelection (org.xwiki.refactoring.job.question.EntitySelection)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 MandatoryDocumentInitializer (com.xpn.xwiki.doc.MandatoryDocumentInitializer)1 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)1