Better support custom PropertyPathNotificationExtractor (#508)
* Make it possible to add custom webhook handling behavior without overriding default behavior * move PropertyPathNotificationExtractorConfiguration to an inner class of EnvironmentMonitorAutoConfiguration * fix formatting
This commit is contained in:
@@ -27,6 +27,7 @@ import org.springframework.context.annotation.Import;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Will Boyd
|
||||
*
|
||||
*/
|
||||
@Configuration
|
||||
@@ -42,22 +43,27 @@ public class EnvironmentMonitorAutoConfiguration {
|
||||
return new PropertyPathEndpoint(new CompositePropertyPathNotificationExtractor(this.extractors));
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(value="spring.cloud.config.server.monitor.github.enabled", havingValue="true", matchIfMissing=true)
|
||||
public GithubPropertyPathNotificationExtractor githubPropertyPathNotificationExtractor() {
|
||||
return new GithubPropertyPathNotificationExtractor();
|
||||
}
|
||||
@Configuration
|
||||
protected static class PropertyPathNotificationExtractorConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(value="spring.cloud.config.server.monitor.gitlab.enabled", havingValue="true", matchIfMissing=true)
|
||||
public GitlabPropertyPathNotificationExtractor gitlabPropertyPathNotificationExtractor() {
|
||||
return new GitlabPropertyPathNotificationExtractor();
|
||||
}
|
||||
@Bean
|
||||
@ConditionalOnProperty(value="spring.cloud.config.server.monitor.github.enabled", havingValue="true", matchIfMissing=true)
|
||||
public GithubPropertyPathNotificationExtractor githubPropertyPathNotificationExtractor() {
|
||||
return new GithubPropertyPathNotificationExtractor();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(value="spring.cloud.config.server.monitor.gitlab.enabled", havingValue="true", matchIfMissing=true)
|
||||
public GitlabPropertyPathNotificationExtractor gitlabPropertyPathNotificationExtractor() {
|
||||
return new GitlabPropertyPathNotificationExtractor();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(value="spring.cloud.config.server.monitor.bitbucket.enabled", havingValue="true", matchIfMissing=true)
|
||||
public BitbucketPropertyPathNotificationExtractor bitbucketPropertyPathNotificationExtractor() {
|
||||
return new BitbucketPropertyPathNotificationExtractor();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(value="spring.cloud.config.server.monitor.bitbucket.enabled", havingValue="true", matchIfMissing=true)
|
||||
public BitbucketPropertyPathNotificationExtractor bitbucketPropertyPathNotificationExtractor() {
|
||||
return new BitbucketPropertyPathNotificationExtractor();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.cloud.config.monitor;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
@@ -26,7 +27,10 @@ import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoCo
|
||||
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -48,5 +52,34 @@ public class EnvironmentMonitorAutoConfigurationTests {
|
||||
"extractors")).size());
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCanAddCustomPropertyPathNotificationExtractor() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
CustomPropertyPathNotificationExtractorConfig.class,
|
||||
EnvironmentMonitorAutoConfiguration.class,
|
||||
EmbeddedServletContainerAutoConfiguration.class, ServerPropertiesAutoConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class).properties("server.port=-1")
|
||||
.run();
|
||||
PropertyPathEndpoint endpoint = context.getBean(PropertyPathEndpoint.class);
|
||||
assertEquals(5,
|
||||
((Collection<?>) ReflectionTestUtils.getField(
|
||||
ReflectionTestUtils.getField(endpoint, "extractor"),
|
||||
"extractors")).size());
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class CustomPropertyPathNotificationExtractorConfig {
|
||||
@Bean
|
||||
public PropertyPathNotificationExtractor customNotificationExtractor() {
|
||||
return new PropertyPathNotificationExtractor() {
|
||||
@Override
|
||||
public PropertyPathNotification extract(MultiValueMap<String, String> headers, Map<String, Object> payload) {
|
||||
throw new UnsupportedOperationException("doesn't do anything");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user