Search in sources :

Example 1 with ApplicationReadyEvent

use of org.xwiki.bridge.event.ApplicationReadyEvent in project xwiki-platform by xwiki.

the class AuthenticatingIntegrationTest method initialize.

@Before
public void initialize() throws Exception {
    // Create a user in the SMTP server.
    this.mail.setUser("peter@doe.com", "peter", "password");
    this.defaultBodyPartFactory = this.componentManager.getInstance(new DefaultParameterizedType(null, MimeBodyPartFactory.class, String.class));
    this.sender = this.componentManager.getInstance(MailSender.class);
    // 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 : ApplicationReadyEvent(org.xwiki.bridge.event.ApplicationReadyEvent) 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 ApplicationReadyEvent

use of org.xwiki.bridge.event.ApplicationReadyEvent 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 3 with ApplicationReadyEvent

use of org.xwiki.bridge.event.ApplicationReadyEvent in project xwiki-platform by xwiki.

the class DefaultWikiComponentManagerEventListenerTest method onApplicationReady.

@Test
public void onApplicationReady() throws Exception {
    mocker.getComponentUnderTest().onEvent(new ApplicationReadyEvent(), null, null);
    verify(this.wikiComponentManagerEventListenerHelper, times(1)).registerComponentList(any());
}
Also used : ApplicationReadyEvent(org.xwiki.bridge.event.ApplicationReadyEvent) Test(org.junit.Test)

Example 4 with ApplicationReadyEvent

use of org.xwiki.bridge.event.ApplicationReadyEvent in project xwiki-platform by xwiki.

the class DefaultWikiComponentManagerEventListenerTest method onDocumentCreatedOrUpdated.

private void onDocumentCreatedOrUpdated(Event event) throws Exception {
    DocumentModelBridge componentDocument = mock(DocumentModelBridge.class);
    when(componentDocument.getDocumentReference()).thenReturn(DOC_REFERENCE);
    /**
     * Here, {@link WikiComponentManagerEventListenerHelper#registerComponentList(List)} is called two times
     * because we have to "initialize" the tested event listener with an ApplicationReadyEvent() before sending
     * our custom event. Therefore, the tested WikiComponent will be registered two times.
     */
    mocker.getComponentUnderTest().onEvent(new ApplicationReadyEvent(), null, null);
    mocker.getComponentUnderTest().onEvent(event, componentDocument, null);
}
Also used : DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) ApplicationReadyEvent(org.xwiki.bridge.event.ApplicationReadyEvent)

Example 5 with ApplicationReadyEvent

use of org.xwiki.bridge.event.ApplicationReadyEvent in project xwiki-platform by xwiki.

the class UntypedEventListenerTest method onEventWithWrongEvent.

@Test
public void onEventWithWrongEvent() throws Exception {
    // Mocks
    mockDescriptor();
    // Test
    mocker.getComponentUnderTest().onEvent(new ApplicationReadyEvent(), mock(Object.class), null);
    // Verify
    verify(this.observationManager, never()).notify(any(), any(), any());
    assertNull(answer.getSentEvent());
}
Also used : ApplicationReadyEvent(org.xwiki.bridge.event.ApplicationReadyEvent) Test(org.junit.Test)

Aggregations

ApplicationReadyEvent (org.xwiki.bridge.event.ApplicationReadyEvent)8 XWikiContext (com.xpn.xwiki.XWikiContext)3 Before (org.junit.Before)3 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)3 MailSenderInitializerListener (org.xwiki.mail.internal.thread.MailSenderInitializerListener)3 Test (org.junit.Test)2 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)2 Execution (org.xwiki.context.Execution)2 ExecutionContext (org.xwiki.context.ExecutionContext)2 MailSender (org.xwiki.mail.MailSender)2 DefaultMailSender (org.xwiki.mail.internal.DefaultMailSender)2 Copier (org.xwiki.mail.internal.thread.context.Copier)2 XWiki (com.xpn.xwiki.XWiki)1 DocumentCreatedEvent (org.xwiki.bridge.event.DocumentCreatedEvent)1 DocumentDeletedEvent (org.xwiki.bridge.event.DocumentDeletedEvent)1 DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)1 WikiReadyEvent (org.xwiki.bridge.event.WikiReadyEvent)1 DefaultExecution (org.xwiki.context.internal.DefaultExecution)1 MailSenderScriptService (org.xwiki.mail.script.MailSenderScriptService)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1