Search in sources :

Example 1 with ApplicationEnvironmentPreparedEvent

use of org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent in project spring-boot by spring-projects.

the class ConfigFileApplicationListenerTests method postProcessorsAreOrderedCorrectly.

@Test
public void postProcessorsAreOrderedCorrectly() {
    TestConfigFileApplicationListener testListener = new TestConfigFileApplicationListener();
    testListener.onApplicationEvent(new ApplicationEnvironmentPreparedEvent(this.application, new String[0], this.environment));
}
Also used : ApplicationEnvironmentPreparedEvent(org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent) Test(org.junit.Test)

Example 2 with ApplicationEnvironmentPreparedEvent

use of org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent in project spring-boot by spring-projects.

the class DelegatingApplicationListenerTests method orderedInitialize.

@Test
public void orderedInitialize() throws Exception {
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "context.listener.classes=" + MockInitB.class.getName() + "," + MockInitA.class.getName());
    this.listener.onApplicationEvent(new ApplicationEnvironmentPreparedEvent(new SpringApplication(), new String[0], this.context.getEnvironment()));
    this.context.getBeanFactory().registerSingleton("testListener", this.listener);
    this.context.refresh();
    assertThat(this.context.getBeanFactory().getSingleton("a")).isEqualTo("a");
    assertThat(this.context.getBeanFactory().getSingleton("b")).isEqualTo("b");
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) ApplicationEnvironmentPreparedEvent(org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent) Test(org.junit.Test)

Example 3 with ApplicationEnvironmentPreparedEvent

use of org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent in project spring-boot by spring-projects.

the class DelegatingApplicationListener method onApplicationEvent.

@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationEnvironmentPreparedEvent) {
        List<ApplicationListener<ApplicationEvent>> delegates = getListeners(((ApplicationEnvironmentPreparedEvent) event).getEnvironment());
        if (delegates.isEmpty()) {
            return;
        }
        this.multicaster = new SimpleApplicationEventMulticaster();
        for (ApplicationListener<ApplicationEvent> listener : delegates) {
            this.multicaster.addApplicationListener(listener);
        }
    }
    if (this.multicaster != null) {
        this.multicaster.multicastEvent(event);
    }
}
Also used : SimpleApplicationEventMulticaster(org.springframework.context.event.SimpleApplicationEventMulticaster) ApplicationListener(org.springframework.context.ApplicationListener) ApplicationEvent(org.springframework.context.ApplicationEvent) ApplicationEnvironmentPreparedEvent(org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent)

Example 4 with ApplicationEnvironmentPreparedEvent

use of org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent in project spring-boot by spring-projects.

the class DelegatingApplicationListenerTests method emptyInitializers.

@Test
public void emptyInitializers() throws Exception {
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "context.listener.classes:");
    this.listener.onApplicationEvent(new ApplicationEnvironmentPreparedEvent(new SpringApplication(), new String[0], this.context.getEnvironment()));
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) ApplicationEnvironmentPreparedEvent(org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent) Test(org.junit.Test)

Aggregations

ApplicationEnvironmentPreparedEvent (org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent)4 Test (org.junit.Test)3 SpringApplication (org.springframework.boot.SpringApplication)2 ApplicationEvent (org.springframework.context.ApplicationEvent)1 ApplicationListener (org.springframework.context.ApplicationListener)1 SimpleApplicationEventMulticaster (org.springframework.context.event.SimpleApplicationEventMulticaster)1