Search in sources :

Example 21 with ContextRefreshedEvent

use of org.springframework.context.event.ContextRefreshedEvent in project molgenis by molgenis.

the class BootstrapTestUtils method bootstrap.

public void bootstrap(WebApplicationContext context) {
    ContextRefreshedEvent event = mock(ContextRefreshedEvent.class);
    when(event.getApplicationContext()).thenReturn(context);
    TransactionTemplate template = new TransactionTemplate();
    template.setTransactionManager(transactionManager);
    try {
        runAsSystem(() -> initialize(template, event));
    } catch (Exception unexpected) {
        LOG.error("Error bootstrapping tests!", unexpected);
        throw new RuntimeException(unexpected);
    }
}
Also used : TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent)

Example 22 with ContextRefreshedEvent

use of org.springframework.context.event.ContextRefreshedEvent in project spring-integration by spring-projects.

the class DelayHandlerTests method startDelayerHandler.

private void startDelayerHandler() {
    delayHandler.afterPropertiesSet();
    delayHandler.onApplicationEvent(new ContextRefreshedEvent(TestUtils.createTestApplicationContext()));
}
Also used : ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent)

Example 23 with ContextRefreshedEvent

use of org.springframework.context.event.ContextRefreshedEvent in project spring-integration by spring-projects.

the class NotificationListeningMessageProducerTests method notificationWithFilter.

@Test
@SuppressWarnings("serial")
public void notificationWithFilter() throws Exception {
    QueueChannel outputChannel = new QueueChannel();
    NotificationListeningMessageProducer adapter = new NotificationListeningMessageProducer();
    adapter.setServer(this.server);
    adapter.setObjectName(this.objectName);
    adapter.setOutputChannel(outputChannel);
    adapter.setFilter(notification -> !notification.getMessage().equals("bad"));
    adapter.setBeanFactory(mock(BeanFactory.class));
    adapter.afterPropertiesSet();
    adapter.start();
    adapter.onApplicationEvent(new ContextRefreshedEvent(Mockito.mock(ApplicationContext.class)));
    this.numberHolder.publish("bad");
    Message<?> message = outputChannel.receive(0);
    assertNull(message);
    this.numberHolder.publish("okay");
    message = outputChannel.receive(0);
    assertNotNull(message);
    assertTrue(message.getPayload() instanceof Notification);
    Notification notification = (Notification) message.getPayload();
    assertEquals("okay", notification.getMessage());
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) Notification(javax.management.Notification) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) Test(org.junit.Test)

Example 24 with ContextRefreshedEvent

use of org.springframework.context.event.ContextRefreshedEvent in project spring-integration by spring-projects.

the class NotificationListeningMessageProducerTests method notificationWithHandback.

@Test
public void notificationWithHandback() throws Exception {
    QueueChannel outputChannel = new QueueChannel();
    NotificationListeningMessageProducer adapter = new NotificationListeningMessageProducer();
    adapter.setServer(this.server);
    adapter.setObjectName(this.objectName);
    adapter.setOutputChannel(outputChannel);
    Integer handback = 123;
    adapter.setHandback(handback);
    adapter.setBeanFactory(mock(BeanFactory.class));
    adapter.afterPropertiesSet();
    adapter.start();
    adapter.onApplicationEvent(new ContextRefreshedEvent(Mockito.mock(ApplicationContext.class)));
    this.numberHolder.publish("foo");
    Message<?> message = outputChannel.receive(0);
    assertNotNull(message);
    assertTrue(message.getPayload() instanceof Notification);
    Notification notification = (Notification) message.getPayload();
    assertEquals("foo", notification.getMessage());
    assertEquals(objectName, notification.getSource());
    assertEquals(handback, message.getHeaders().get(JmxHeaders.NOTIFICATION_HANDBACK));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueueChannel(org.springframework.integration.channel.QueueChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) Notification(javax.management.Notification) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) Test(org.junit.Test)

Example 25 with ContextRefreshedEvent

use of org.springframework.context.event.ContextRefreshedEvent in project alfresco-remote-api by Alfresco.

the class RepositoryContainer method onApplicationEvent.

/* (non-Javadoc)
     * @see org.alfresco.web.scripts.AbstractRuntimeContainer#onApplicationEvent(org.springframework.context.ApplicationEvent)
     */
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ContextRefreshedEvent) {
        ContextRefreshedEvent refreshEvent = (ContextRefreshedEvent) event;
        ApplicationContext refreshContext = refreshEvent.getApplicationContext();
        if (refreshContext != null && refreshContext.equals(applicationContext)) {
            RunAsWork<Object> work = new RunAsWork<Object>() {

                public Object doWork() throws Exception {
                    reset();
                    return null;
                }
            };
            AuthenticationUtil.runAs(work, AuthenticationUtil.getSystemUserName());
        }
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent)

Aggregations

ContextRefreshedEvent (org.springframework.context.event.ContextRefreshedEvent)28 Test (org.junit.Test)8 Test (org.junit.jupiter.api.Test)8 ApplicationContext (org.springframework.context.ApplicationContext)6 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 ContextClosedEvent (org.springframework.context.event.ContextClosedEvent)4 Notification (javax.management.Notification)3 BeanFactory (org.springframework.beans.factory.BeanFactory)3 AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)3 QueueChannel (org.springframework.integration.channel.QueueChannel)3 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)2 XpipeRuntimeException (com.ctrip.xpipe.exception.XpipeRuntimeException)1 Field (java.lang.reflect.Field)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 ObjectName (javax.management.ObjectName)1 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)1 RoutesCollector (org.apache.camel.spring.boot.RoutesCollector)1 BeansException (org.springframework.beans.BeansException)1