use of org.springframework.context.event.ContextRefreshedEvent in project tephra by heisedebaise.
the class ContainerTest method contextRefreshed.
@Test
public void contextRefreshed() throws Exception {
Assert.assertEquals(2, contextRefreshedList.size());
for (int i = 0; i < contextRefreshedList.size(); i++) Assert.assertEquals(i + 1, numeric.toInt(contextRefreshedList.get(i)));
for (int i = 0; i < 2; i++) {
((ContainerImpl) container).onApplicationEvent(new ContextRefreshedEvent(getApplicationContext()));
Assert.assertEquals(4 + i * 2, contextRefreshedList.size());
for (int j = 0; j < contextRefreshedList.size(); j++) Assert.assertEquals(j % 2 + 1, numeric.toInt(contextRefreshedList.get(j)));
}
Field field = ContainerImpl.class.getDeclaredField("refreshedListeners");
field.setAccessible(true);
Object object = field.get(container);
field.set(container, Optional.empty());
for (int i = 0; i < 2; i++) {
((ContainerImpl) container).onApplicationEvent(new ContextRefreshedEvent(getApplicationContext()));
Assert.assertEquals(6, contextRefreshedList.size());
for (int j = 0; j < contextRefreshedList.size(); j++) Assert.assertEquals(j % 2 + 1, numeric.toInt(contextRefreshedList.get(j)));
}
((ContainerImpl) container).onApplicationEvent(new ApplicationContextEvent(getApplicationContext()) {
});
Assert.assertEquals(6, contextRefreshedList.size());
for (int i = 0; i < contextRefreshedList.size(); i++) Assert.assertEquals(i % 2 + 1, numeric.toInt(contextRefreshedList.get(i)));
field.set(container, object);
}
use of org.springframework.context.event.ContextRefreshedEvent in project spring-integration by spring-projects.
the class DelayHandlerTests method testDoubleOnApplicationEvent.
// INT-1132
@Test
public // Can happen in the parent-child context e.g. Spring-MVC applications
void testDoubleOnApplicationEvent() throws Exception {
this.delayHandler = Mockito.spy(this.delayHandler);
Mockito.doAnswer(invocation -> null).when(this.delayHandler).reschedulePersistedMessages();
ContextRefreshedEvent contextRefreshedEvent = new ContextRefreshedEvent(TestUtils.createTestApplicationContext());
this.delayHandler.onApplicationEvent(contextRefreshedEvent);
this.delayHandler.onApplicationEvent(contextRefreshedEvent);
Mockito.verify(this.delayHandler, Mockito.times(1)).reschedulePersistedMessages();
}
use of org.springframework.context.event.ContextRefreshedEvent in project spring-integration by spring-projects.
the class NotificationListeningMessageProducerTests method simpleNotification.
@Test
public void simpleNotification() throws Exception {
QueueChannel outputChannel = new QueueChannel();
NotificationListeningMessageProducer adapter = new NotificationListeningMessageProducer();
adapter.setServer(this.server);
adapter.setObjectName(this.objectName);
adapter.setOutputChannel(outputChannel);
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());
assertNull(message.getHeaders().get(JmxHeaders.NOTIFICATION_HANDBACK));
}
use of org.springframework.context.event.ContextRefreshedEvent in project x-pipe by ctripcorp.
the class SpringComponentLifecycleManager method onApplicationEvent.
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ContextRefreshedEvent) {
try {
logger.info("[onApplicationEvent][ContextRefreshedEvent, startAll]");
startAll();
} catch (Exception e) {
throw new XpipeRuntimeException("[startAll][fail]", e);
}
}
if (event instanceof ContextClosedEvent) {
try {
logger.info("[onApplicationEvent][ContextClosedEvent, stopAll]");
stopAll();
} catch (Exception e) {
logger.error("[onApplicationEvent][stop all]", e);
throw new XpipeRuntimeException("[stopAll][fail]", e);
}
}
}
use of org.springframework.context.event.ContextRefreshedEvent in project molgenis by molgenis.
the class ImportServiceIT method beforeClass.
@BeforeClass
public void beforeClass() {
ContextRefreshedEvent contextRefreshedEvent = Mockito.mock(ContextRefreshedEvent.class);
Mockito.when(contextRefreshedEvent.getApplicationContext()).thenReturn(applicationContext);
importServiceRegistrar.register(contextRefreshedEvent);
RunAsSystemAspect.runAsSystem(() -> dataService.add(USER, getTestUser()));
}
Aggregations