Moves away from @EventListener to interface implementations for framework 5.1 changes
fixes gh-405
This commit is contained in:
@@ -16,10 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.endpoint;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -28,8 +24,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.Banner.Mode;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
@@ -43,7 +39,7 @@ import org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEven
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.context.event.SmartApplicationListener;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
@@ -51,6 +47,10 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Venil Noronha
|
||||
@@ -132,7 +132,6 @@ public class RefreshEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore //FIXME: 2.1.0
|
||||
public void eventsPublishedInOrder() throws Exception {
|
||||
this.context = new SpringApplicationBuilder(Empty.class)
|
||||
.web(WebApplicationType.NONE).bannerMode(Mode.OFF).run();
|
||||
@@ -148,7 +147,6 @@ public class RefreshEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore //FIXME: 2.1.0
|
||||
public void shutdownHooksCleaned() {
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(Empty.class)
|
||||
.web(WebApplicationType.NONE).bannerMode(Mode.OFF).run()) {
|
||||
@@ -174,17 +172,22 @@ public class RefreshEndpointTests {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
protected static class Empty {
|
||||
protected static class Empty implements SmartApplicationListener {
|
||||
private List<ApplicationEvent> events = new ArrayList<ApplicationEvent>();
|
||||
|
||||
@EventListener(EnvironmentChangeEvent.class)
|
||||
public void changed(EnvironmentChangeEvent event) {
|
||||
this.events.add(event);
|
||||
|
||||
@Override
|
||||
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
|
||||
return EnvironmentChangeEvent.class.isAssignableFrom(eventType)
|
||||
|| RefreshScopeRefreshedEvent.class.isAssignableFrom(eventType);
|
||||
}
|
||||
|
||||
@EventListener(RefreshScopeRefreshedEvent.class)
|
||||
public void refreshed(RefreshScopeRefreshedEvent event) {
|
||||
this.events.add(event);
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
if (event instanceof EnvironmentChangeEvent ||
|
||||
event instanceof RefreshScopeRefreshedEvent) {
|
||||
this.events.add(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user