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);
}
}
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()));
}
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());
}
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));
}
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());
}
}
}
Aggregations