Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Gth99spB1CzQmBFofXmU4Z
33 lines
1.1 KiB
Java
33 lines
1.1 KiB
Java
package com.ankurm.boot42;
|
|
|
|
import java.util.Map;
|
|
import org.springframework.boot.WebApplicationType;
|
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
|
import org.springframework.context.ConfigurableApplicationContext;
|
|
import org.springframework.core.env.Environment;
|
|
import org.springframework.web.client.RestClient;
|
|
|
|
/** Starts the real application with the given properties on a random port. */
|
|
final class BootRun {
|
|
|
|
private BootRun() {
|
|
}
|
|
|
|
static ConfigurableApplicationContext start(String... props) {
|
|
return new SpringApplicationBuilder(Boot42PreviewApplication.class)
|
|
.web(WebApplicationType.SERVLET)
|
|
.properties(props)
|
|
.properties("server.port=0", "spring.main.banner-mode=off", "logging.level.root=WARN")
|
|
.run();
|
|
}
|
|
|
|
static RestClient client(ConfigurableApplicationContext ctx) {
|
|
Environment env = ctx.getEnvironment();
|
|
return RestClient.create("http://localhost:" + env.getProperty("local.server.port"));
|
|
}
|
|
|
|
static Map<?, ?> whoAmI(ConfigurableApplicationContext ctx, Map<String, String> headers) {
|
|
return client(ctx).get().uri("/whoami").headers(h -> headers.forEach(h::add)).retrieve().body(Map.class);
|
|
}
|
|
}
|