Search in sources :

Example 1 with Execution

use of org.xwiki.context.Execution in project xwiki-platform by xwiki.

the class JavaIntegrationTest method initialize.

@Before
public void initialize() throws Exception {
    this.defaultBodyPartFactory = this.componentManager.getInstance(new DefaultParameterizedType(null, MimeBodyPartFactory.class, String.class));
    this.htmlBodyPartFactory = this.componentManager.getInstance(new DefaultParameterizedType(null, MimeBodyPartFactory.class, String.class), "text/html");
    this.sender = this.componentManager.getInstance(MailSender.class);
    // Set the EC
    Execution execution = this.componentManager.getInstance(Execution.class);
    ExecutionContext executionContext = new ExecutionContext();
    XWikiContext xContext = new XWikiContext();
    xContext.setWikiId("wiki");
    executionContext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, xContext);
    when(execution.getContext()).thenReturn(executionContext);
    Copier<ExecutionContext> executionContextCloner = this.componentManager.getInstance(new DefaultParameterizedType(null, Copier.class, ExecutionContext.class));
    // Just return the same execution context
    when(executionContextCloner.copy(executionContext)).thenReturn(executionContext);
    // Simulate receiving the Application Ready Event to start the mail threads
    MailSenderInitializerListener listener = this.componentManager.getInstance(EventListener.class, MailSenderInitializerListener.LISTENER_NAME);
    listener.onEvent(new ApplicationReadyEvent(), null, null);
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) Copier(org.xwiki.mail.internal.thread.context.Copier) ApplicationReadyEvent(org.xwiki.bridge.event.ApplicationReadyEvent) XWikiContext(com.xpn.xwiki.XWikiContext) MailSender(org.xwiki.mail.MailSender) DefaultMailSender(org.xwiki.mail.internal.DefaultMailSender) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) MailSenderInitializerListener(org.xwiki.mail.internal.thread.MailSenderInitializerListener) Before(org.junit.Before)

Example 2 with Execution

use of org.xwiki.context.Execution in project xwiki-platform by xwiki.

the class GroupMimeMessageIterator method getXWikiContext.

private XWikiContext getXWikiContext() throws MessagingException {
    XWikiContext xWikiContext;
    try {
        Execution execution = this.componentManager.getInstance(Execution.class);
        xWikiContext = (XWikiContext) execution.getContext().getProperty(XWikiContext.EXECUTIONCONTEXT_KEY);
    } catch (ComponentLookupException e) {
        throw new MessagingException("Failed to find default Execution context", e);
    }
    return xWikiContext;
}
Also used : Execution(org.xwiki.context.Execution) MessagingException(javax.mail.MessagingException) XWikiContext(com.xpn.xwiki.XWikiContext) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 3 with Execution

use of org.xwiki.context.Execution in project xwiki-platform by xwiki.

the class AbstractXWikiRunnable method initExecutionContext.

/**
 * Initialize execution context for the current thread.
 *
 * @return the new execution context
 * @throws ExecutionContextException error when try to initialize execution context
 */
protected ExecutionContext initExecutionContext() throws ExecutionContextException {
    // Keep a reference to the Execution component to avoid a lookup in #cleanupExecutionContext() in case this
    // thread is stopped after the Component Manager disposes its components.
    this.execution = Utils.getComponent(Execution.class);
    ExecutionContextManager ecim = Utils.getComponent(ExecutionContextManager.class);
    ExecutionContext context = new ExecutionContext();
    declareProperties(context);
    ecim.initialize(context);
    context.setProperties(this.properties);
    return context;
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) ExecutionContextManager(org.xwiki.context.ExecutionContextManager)

Example 4 with Execution

use of org.xwiki.context.Execution in project xwiki-platform by xwiki.

the class RestoreJobTest method configure.

@Override
public void configure() throws Exception {
    super.configure();
    Execution execution = mocker.getInstance(Execution.class);
    ExecutionContext executionContext = mock(ExecutionContext.class);
    when(execution.getContext()).thenReturn(executionContext);
    modelContext = mocker.getInstance(ModelContext.class);
}
Also used : ModelContext(org.xwiki.model.ModelContext) Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext)

Example 5 with Execution

use of org.xwiki.context.Execution in project xwiki-platform by xwiki.

the class RefactoringScriptServiceTest method configure.

@Before
public void configure() throws Exception {
    this.jobExecutor = this.mocker.getInstance(JobExecutor.class);
    Execution execution = this.mocker.getInstance(Execution.class);
    when(execution.getContext()).thenReturn(executionContext);
    DocumentAccessBridge documentAccessBridge = this.mocker.getInstance(DocumentAccessBridge.class);
    when(documentAccessBridge.getCurrentUserReference()).thenReturn(this.userReference);
    EntityReferenceProvider defaultEntityReferenceProvider = this.mocker.getInstance(EntityReferenceProvider.class);
    when(defaultEntityReferenceProvider.getDefaultReference(EntityType.DOCUMENT)).thenReturn(new EntityReference("WebHome", EntityType.DOCUMENT, null));
}
Also used : EntityReferenceProvider(org.xwiki.model.reference.EntityReferenceProvider) Execution(org.xwiki.context.Execution) JobExecutor(org.xwiki.job.JobExecutor) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) EntityReference(org.xwiki.model.reference.EntityReference) Before(org.junit.Before)

Aggregations

Execution (org.xwiki.context.Execution)82 ExecutionContext (org.xwiki.context.ExecutionContext)58 Before (org.junit.Before)36 XWikiContext (com.xpn.xwiki.XWikiContext)30 Test (org.junit.Test)19 DocumentReference (org.xwiki.model.reference.DocumentReference)17 XWiki (com.xpn.xwiki.XWiki)13 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)13 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)11 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)10 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)8 ComponentManager (org.xwiki.component.manager.ComponentManager)8 HashMap (java.util.HashMap)7 Expectations (org.jmock.Expectations)7 VelocityContext (org.apache.velocity.VelocityContext)5 ExecutionContextManager (org.xwiki.context.ExecutionContextManager)5 BaseObject (com.xpn.xwiki.objects.BaseObject)4 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)4 XDOM (org.xwiki.rendering.block.XDOM)4 AuthorizationManager (org.xwiki.security.authorization.AuthorizationManager)4