From 26085499c038fa1f4d6b869ca36bc794e6388394 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 30 Sep 2015 17:42:51 +0100 Subject: [PATCH] Enable github/lab webhooks by default --- .../EnvironmentMonitorAutoConfiguration.java | 14 +++++ ...ironmentMonitorAutoConfigurationTests.java | 52 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/EnvironmentMonitorAutoConfigurationTests.java diff --git a/spring-cloud-config-monitor/src/main/java/org/springframework/cloud/config/monitor/EnvironmentMonitorAutoConfiguration.java b/spring-cloud-config-monitor/src/main/java/org/springframework/cloud/config/monitor/EnvironmentMonitorAutoConfiguration.java index 2e937799..9ac46537 100644 --- a/spring-cloud-config-monitor/src/main/java/org/springframework/cloud/config/monitor/EnvironmentMonitorAutoConfiguration.java +++ b/spring-cloud-config-monitor/src/main/java/org/springframework/cloud/config/monitor/EnvironmentMonitorAutoConfiguration.java @@ -19,6 +19,7 @@ package org.springframework.cloud.config.monitor; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -40,4 +41,17 @@ public class EnvironmentMonitorAutoConfiguration { public PropertyPathEndpoint propertyPathEndpoint() { 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(); + } + + @Bean + @ConditionalOnProperty(value="spring.cloud.config.server.monitor.gitlab.enabled", havingValue="true", matchIfMissing=true) + public GitlabPropertyPathNotificationExtractor gitlabPropertyPathNotificationExtractor() { + return new GitlabPropertyPathNotificationExtractor(); + } + } diff --git a/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/EnvironmentMonitorAutoConfigurationTests.java b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/EnvironmentMonitorAutoConfigurationTests.java new file mode 100644 index 00000000..176bf765 --- /dev/null +++ b/spring-cloud-config-monitor/src/test/java/org/springframework/cloud/config/monitor/EnvironmentMonitorAutoConfigurationTests.java @@ -0,0 +1,52 @@ +/* + * Copyright 2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.config.monitor; + +import static org.junit.Assert.assertEquals; + +import java.util.Collection; + +import org.junit.Test; +import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.test.util.ReflectionTestUtils; + +/** + * @author Dave Syer + * + */ +public class EnvironmentMonitorAutoConfigurationTests { + + @Test + public void test() { + ConfigurableApplicationContext context = new SpringApplicationBuilder( + EnvironmentMonitorAutoConfiguration.class, + EmbeddedServletContainerAutoConfiguration.class, ServerPropertiesAutoConfiguration.class, + PropertyPlaceholderAutoConfiguration.class).properties("server.port=-1") + .run(); + PropertyPathEndpoint endpoint = context.getBean(PropertyPathEndpoint.class); + assertEquals(3, + ((Collection) ReflectionTestUtils.getField( + ReflectionTestUtils.getField(endpoint, "extractor"), + "extractors")).size()); + context.close(); + } + +}