|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2024 the original author or authors. |
| 2 | + * Copyright 2012-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
30 | 30 | import org.springframework.boot.availability.ReadinessState;
|
31 | 31 | import org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer;
|
32 | 32 | import org.springframework.boot.web.reactive.server.MockReactiveWebServerFactory;
|
| 33 | +import org.springframework.boot.web.server.WebServer; |
33 | 34 | import org.springframework.context.ApplicationContextException;
|
34 | 35 | import org.springframework.context.ApplicationEvent;
|
35 | 36 | import org.springframework.context.ApplicationListener;
|
|
42 | 43 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
43 | 44 | import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
44 | 45 | import static org.mockito.BDDMockito.then;
|
| 46 | +import static org.mockito.Mockito.times; |
45 | 47 |
|
46 | 48 | /**
|
47 | 49 | * Tests for {@link ReactiveWebServerApplicationContext}.
|
@@ -121,13 +123,25 @@ void whenContextIsRefreshedThenLocalServerPortIsAvailableFromTheEnvironment() {
|
121 | 123 | }
|
122 | 124 |
|
123 | 125 | @Test
|
124 |
| - void whenContextIsClosedThenWebServerIsStopped() { |
| 126 | + void whenContextRefreshFailedThenWebServerIsStoppedAndDestroyed() { |
| 127 | + addWebServerFactoryBean(); |
| 128 | + addHttpHandlerBean(); |
| 129 | + this.context.registerBeanDefinition("refreshFailure", new RootBeanDefinition(RefreshFailure.class)); |
| 130 | + assertThatExceptionOfType(BeanCreationException.class).isThrownBy(this.context::refresh); |
| 131 | + WebServer webServer = this.context.getWebServer(); |
| 132 | + then(webServer).should(times(2)).stop(); |
| 133 | + then(webServer).should().destroy(); |
| 134 | + } |
| 135 | + |
| 136 | + @Test |
| 137 | + void whenContextIsClosedThenWebServerIsStoppedAndDestroyed() { |
125 | 138 | addWebServerFactoryBean();
|
126 | 139 | addHttpHandlerBean();
|
127 | 140 | this.context.refresh();
|
128 | 141 | MockReactiveWebServerFactory factory = this.context.getBean(MockReactiveWebServerFactory.class);
|
129 | 142 | this.context.close();
|
130 |
| - then(factory.getWebServer()).should().stop(); |
| 143 | + then(factory.getWebServer()).should(times(2)).stop(); |
| 144 | + then(factory.getWebServer()).should().destroy(); |
131 | 145 | }
|
132 | 146 |
|
133 | 147 | @Test
|
|
0 commit comments