|
|
|
@ -20,13 +20,20 @@ import java.io.File;
|
|
|
|
|
import java.io.FileReader;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.function.BiFunction;
|
|
|
|
|
|
|
|
|
|
import org.junit.After;
|
|
|
|
|
import org.junit.Before;
|
|
|
|
|
import org.junit.Rule;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.junit.rules.TemporaryFolder;
|
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
|
import org.junit.runners.Parameterized;
|
|
|
|
|
import org.junit.runners.Parameterized.Parameters;
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.web.context.WebServerInitializedEvent;
|
|
|
|
|
import org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext;
|
|
|
|
|
import org.springframework.boot.web.reactive.context.ReactiveWebServerInitializedEvent;
|
|
|
|
|
import org.springframework.boot.web.server.WebServer;
|
|
|
|
|
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
|
|
|
|
|
import org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent;
|
|
|
|
@ -44,10 +51,44 @@ import static org.mockito.Mockito.mock;
|
|
|
|
|
* @author Phillip Webb
|
|
|
|
|
* @author Andy Wilkinson
|
|
|
|
|
*/
|
|
|
|
|
@RunWith(Parameterized.class)
|
|
|
|
|
public class EmbeddedServerPortFileWriterTests {
|
|
|
|
|
|
|
|
|
|
@Rule
|
|
|
|
|
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
|
|
|
|
public final TemporaryFolder temporaryFolder = new TemporaryFolder();
|
|
|
|
|
|
|
|
|
|
@Parameters(name = "{0}")
|
|
|
|
|
public static Object[] parameters() {
|
|
|
|
|
BiFunction<String, Integer, ? extends WebServerInitializedEvent> servletEvent = (
|
|
|
|
|
String name, Integer port) -> {
|
|
|
|
|
ServletWebServerApplicationContext applicationContext = mock(
|
|
|
|
|
ServletWebServerApplicationContext.class);
|
|
|
|
|
given(applicationContext.getNamespace()).willReturn(name);
|
|
|
|
|
WebServer source = mock(WebServer.class);
|
|
|
|
|
given(source.getPort()).willReturn(port);
|
|
|
|
|
ServletWebServerInitializedEvent event = new ServletWebServerInitializedEvent(
|
|
|
|
|
applicationContext, source);
|
|
|
|
|
return event;
|
|
|
|
|
};
|
|
|
|
|
BiFunction<String, Integer, ? extends WebServerInitializedEvent> reactiveEvent = (
|
|
|
|
|
String name, Integer port) -> {
|
|
|
|
|
ReactiveWebServerApplicationContext applicationContext = mock(
|
|
|
|
|
ReactiveWebServerApplicationContext.class);
|
|
|
|
|
given(applicationContext.getNamespace()).willReturn(name);
|
|
|
|
|
WebServer source = mock(WebServer.class);
|
|
|
|
|
given(source.getPort()).willReturn(port);
|
|
|
|
|
return new ReactiveWebServerInitializedEvent(source, applicationContext);
|
|
|
|
|
};
|
|
|
|
|
return new Object[] { new Object[] { "Servlet", servletEvent },
|
|
|
|
|
new Object[] { "Reactive", reactiveEvent } };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private final BiFunction<String, Integer, ? extends WebServerInitializedEvent> eventFactory;
|
|
|
|
|
|
|
|
|
|
public EmbeddedServerPortFileWriterTests(String name,
|
|
|
|
|
BiFunction<String, Integer, ? extends WebServerInitializedEvent> eventFactory) {
|
|
|
|
|
this.eventFactory = eventFactory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
|
@After
|
|
|
|
@ -117,15 +158,8 @@ public class EmbeddedServerPortFileWriterTests {
|
|
|
|
|
assertThat(collectFileNames(file.getParentFile())).contains(managementFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ServletWebServerInitializedEvent mockEvent(String name, int port) {
|
|
|
|
|
ServletWebServerApplicationContext applicationContext = mock(
|
|
|
|
|
ServletWebServerApplicationContext.class);
|
|
|
|
|
WebServer source = mock(WebServer.class);
|
|
|
|
|
given(applicationContext.getNamespace()).willReturn(name);
|
|
|
|
|
given(source.getPort()).willReturn(port);
|
|
|
|
|
ServletWebServerInitializedEvent event = new ServletWebServerInitializedEvent(
|
|
|
|
|
applicationContext, source);
|
|
|
|
|
return event;
|
|
|
|
|
private WebServerInitializedEvent mockEvent(String name, int port) {
|
|
|
|
|
return this.eventFactory.apply(name, port);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Set<String> collectFileNames(File directory) {
|
|
|
|
|