Skip to content

Commit

Permalink
Prevent endpoint's shutdown() method from being a destroy method
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona authored and htztomic committed Jul 3, 2019
1 parent 0f6d0d1 commit c3cd17c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
@ConditionalOnAvailableEndpoint(endpoint = ShutdownEndpoint.class)
public class ShutdownEndpointAutoConfiguration {

@Bean
@Bean(destroyMethod = "")
@ConditionalOnMissingBean
public ShutdownEndpoint shutdownEndpoint() {
return new ShutdownEndpoint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@

package org.springframework.boot.actuate.autoconfigure.context;

import org.junit.jupiter.api.Test;
import java.util.Map;

import org.junit.Test;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.actuate.context.ShutdownEndpoint;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.test.util.ReflectionTestUtils;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -29,26 +33,25 @@
*
* @author Phillip Webb
*/
class ShutdownEndpointAutoConfigurationTests {
public class ShutdownEndpointAutoConfigurationTests {

private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(ShutdownEndpointAutoConfiguration.class));

@Test
void runShouldHaveEndpointBean() {
this.contextRunner.withPropertyValues("management.endpoint.shutdown.enabled:true")
.withPropertyValues("management.endpoints.web.exposure.include=shutdown")
.run((context) -> assertThat(context).hasSingleBean(ShutdownEndpoint.class));
}

@Test
void runWhenNotExposedShouldNotHaveEndpointBean() {
this.contextRunner.withPropertyValues("management.endpoint.shutdown.enabled:true")
.run((context) -> assertThat(context).doesNotHaveBean(ShutdownEndpoint.class));
@SuppressWarnings("unchecked")
public void runShouldHaveEndpointBeanThatIsNotDisposable() {
this.contextRunner.withPropertyValues("management.endpoint.shutdown.enabled:true").run((context) -> {
assertThat(context).hasSingleBean(ShutdownEndpoint.class);
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
Map<String, Object> disposableBeans = (Map<String, Object>) ReflectionTestUtils.getField(beanFactory,
"disposableBeans");
assertThat(disposableBeans).isEmpty();
});
}

@Test
void runWhenEnabledPropertyIsFalseShouldNotHaveEndpointBean() {
public void runWhenEnabledPropertyIsFalseShouldNotHaveEndpointBean() {
this.contextRunner.withPropertyValues("management.endpoint.shutdown.enabled:false")
.run((context) -> assertThat(context).doesNotHaveBean(ShutdownEndpoint.class));
}
Expand Down

0 comments on commit c3cd17c

Please sign in to comment.