Commit 7e32dfcc by Johannes Edmeier

Update to Spring Boot 2.0.0.M4

parent 232bb5f1
......@@ -21,7 +21,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.M3</version>
<version>2.0.0.M4</version>
<relativePath/>
</parent>
<groupId>de.codecentric</groupId>
......@@ -34,7 +34,7 @@
<properties>
<java.version>1.8</java.version>
<main.basedir>${basedir}</main.basedir>
<spring-boot.version>2.0.0.M3</spring-boot.version>
<spring-boot.version>2.0.0.M4</spring-boot.version>
<spring-cloud.version>Finchley.BUILD-SNAPSHOT</spring-cloud.version>
<build-plugin.jacoco.version>0.7.9</build-plugin.jacoco.version>
<build-plugin.coveralls.version>4.3.0</build-plugin.coveralls.version>
......
......@@ -31,6 +31,9 @@ import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
@Configuration
@EnableAutoConfiguration
......@@ -61,9 +64,28 @@ public class SpringBootAdminApplication {
// Enable so that the clients can authenticate via HTTP basic for registering
http.httpBasic();
}
@Bean
@Override
public UserDetailsService userDetailsService() {
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
manager.createUser(User.withUsername("user").password("pass").build());
return manager;
}
}
// end::configuration-spring-security[]
@Profile("insecure")
@Configuration
public static class DisableSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.authorizeRequests().antMatchers("/**").permitAll();
}
}
@Configuration
public static class NotifierConfig {
private final InstanceRepository repository;
......
......@@ -25,30 +25,17 @@ spring:
spring:
profiles: insecure
management:
security:
enabled: false
security:
basic:
enabled: false
---
spring:
profiles: secure
boot:
admin:
client:
username: "${security.user.name}" #These two are needed so that the client
password: "${security.user.password}" #can register at the protected server api
instance:
metadata:
user.name: "${security.user.name}" #These two are needed so that the server
user.password: "${security.user.password}" #can access the proteceted client endpoints
security:
user:
name: user
password: pass
client:
username: "user" #These two are needed so that the client
password: "pass" #can register at the protected server api
instance:
metadata:
user.name: "user" #These two are needed so that the server
user.password: "pass" #can access the proteceted client endpoints
......@@ -29,7 +29,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import org.springframework.boot.actuate.endpoint.mvc.ActuatorMediaTypes;
import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType;
import org.springframework.http.HttpMethod;
public class QueryIndexEndpointStrategy implements EndpointDetectionStrategy {
......@@ -50,7 +50,7 @@ public class QueryIndexEndpointStrategy implements EndpointDetectionStrategy {
.filter(response -> response.statusCode().is2xxSuccessful() &&
response.headers()
.contentType()
.map(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON::isCompatibleWith)
.map(ActuatorMediaType.V2_JSON::isCompatibleWith)
.orElse(false))
.flatMap(r -> r.bodyToMono(Response.class))
.flatMap(this::convert);
......
......@@ -24,7 +24,7 @@ import java.net.URI;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.endpoint.mvc.ActuatorMediaTypes;
import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
......@@ -66,7 +66,7 @@ public class InstanceOperations {
public Mono<ClientResponse> exchange(HttpMethod method, Instance instance, URI uri) {
return webClient.method(method)
.uri(uri)
.accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON, MediaType.APPLICATION_JSON)
.accept(ActuatorMediaType.V2_JSON, MediaType.APPLICATION_JSON)
.headers(headers -> headers.putAll(httpHeadersProvider.getHeaders(instance)))
.exchange()
.doOnSubscribe((s) -> log.debug("Do {} on '{}' for {}", method, uri, instance));
......
......@@ -132,7 +132,7 @@ public abstract class AbstractAdminApplicationTest {
private Registration createRegistration() {
return Registration.builder()
.name("Test-Instance")
.healthUrl("http://localhost:" + port + "/mgmt/health")
.healthUrl("http://localhost:" + port + "/mgmt/status")
.managementUrl("http://localhost:" + port + "/mgmt")
.serviceUrl("http://localhost:" + port)
.build();
......
......@@ -42,7 +42,7 @@ public class AdminApplicationDiscoveryTest extends AbstractAdminApplicationTest
public void setUp() throws Exception {
instance = (ServletWebServerApplicationContext) SpringApplication.run(TestAdminApplication.class,
"--server.port=0", "--management.context-path=/mgmt", "--info.test=foobar",
"--management.security.enabled=false");
"--endpoints.health.enabled=true");
simpleDiscovery = instance.getBean(SimpleDiscoveryProperties.class);
......
......@@ -54,10 +54,10 @@ public class AdminApplicationHazelcastTest extends AbstractAdminApplicationTest
System.setProperty("hazelcast.wait.seconds.before.join", "0");
instance1 = (ServletWebServerApplicationContext) SpringApplication.run(TestAdminApplication.class,
"--server.port=0", "--spring.jmx.enabled=false", "--management.context-path=/mgmt",
"--management.security.enabled=false", "--info.test=foobar");
"--info.test=foobar");
instance2 = (ServletWebServerApplicationContext) SpringApplication.run(TestAdminApplication.class,
"--server.port=0", "--spring.jmx.enabled=false", "--management.context-path=/mgmt",
"--management.security.enabled=false", "--info.test=foobar");
"--info.test=foobar");
super.setUp(instance1.getWebServer().getPort());
this.webClient2 = createWebClient(instance2.getWebServer().getPort());
......@@ -89,7 +89,7 @@ public class AdminApplicationHazelcastTest extends AbstractAdminApplicationTest
.getResponseBody()
.collect(Collectors.joining());
StepVerifier.create(events1.and(events2))
StepVerifier.create(events1.zipWith(events2))
.assertNext(t -> assertThat(t.getT1()).isEqualTo(t.getT2()))
.verifyComplete();
}
......
......@@ -30,8 +30,7 @@ public class AdminApplicationTest extends AbstractAdminApplicationTest {
@Before
public void setUp() throws Exception {
instance = (ServletWebServerApplicationContext) SpringApplication.run(TestAdminApplication.class,
"--server.port=0", "--management.context-path=/mgmt", "--management.security.enabled=false",
"--info.test=foobar");
"--server.port=0", "--management.context-path=/mgmt", "--info.test=foobar");
super.setUp(instance.getWebServer().getPort());
}
......
......@@ -29,7 +29,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.junit.Test;
import org.springframework.boot.actuate.endpoint.mvc.ActuatorMediaTypes;
import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
......@@ -43,11 +43,10 @@ public class QueryIndexEndpointStrategyTest {
private Mono<ClientResponse> responseNotFound = mockResponse(HttpStatus.NOT_FOUND, null, null);
private Mono<ClientResponse> responseOkWrongContentType = mockResponse(HttpStatus.OK, MediaType.APPLICATION_JSON,
null);
private Mono<ClientResponse> responseOk = mockResponse(HttpStatus.OK,
ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON,
private Mono<ClientResponse> responseOk = mockResponse(HttpStatus.OK, ActuatorMediaType.V2_JSON,
createBody("metrics=http://app/mgmt/stats", "info=http://app/mgmt/info", "self=http://app/mgmt"));
private Mono<ClientResponse> responseOkEmpty = mockResponse(HttpStatus.OK,
ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON, createBody("self=http://app/mgmt"));
private Mono<ClientResponse> responseOkEmpty = mockResponse(HttpStatus.OK, ActuatorMediaType.V2_JSON,
createBody("self=http://app/mgmt"));
private Instance instance = Instance.create(InstanceId.of("id"))
.register(Registration.create("test", "http://app/mgmt/health")
......
......@@ -23,8 +23,10 @@ import de.codecentric.boot.admin.client.registration.ServletApplicationFactory;
import javax.servlet.ServletContext;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.EndpointPathProvider;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.servlet.WebMvcEndpointManagementContextConfiguration;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.web.ServerProperties;
......@@ -43,6 +45,7 @@ import static org.springframework.boot.autoconfigure.condition.ConditionalOnWebA
@Configuration
@EnableConfigurationProperties({ClientProperties.class, InstanceProperties.class})
@Conditional(SpringBootAdminClientEnabledCondition.class)
@AutoConfigureAfter(WebMvcEndpointManagementContextConfiguration.class)
public class SpringBootAdminClientAutoConfiguration {
@Configuration
......@@ -53,9 +56,9 @@ public class SpringBootAdminClientAutoConfiguration {
public ApplicationFactory applicationFactory(InstanceProperties instance,
ManagementServerProperties management,
ServerProperties server,
@Value("${endpoints.health.path:/${endpoints.health.id:health}}") String healthEndpointPath,
ServletContext servletContext) {
return new ServletApplicationFactory(instance, management, server, servletContext, healthEndpointPath);
ServletContext servletContext,
EndpointPathProvider endpointPathProvider) {
return new ServletApplicationFactory(instance, management, server, servletContext, endpointPathProvider);
}
}
......@@ -79,8 +82,8 @@ public class SpringBootAdminClientAutoConfiguration {
public ApplicationFactory applicationFactory(InstanceProperties instance,
ManagementServerProperties management,
ServerProperties server,
@Value("${endpoints.health.path:/${endpoints.health.id:health}}") String healthEndpointPath) {
return new DefaultApplicationFactory(instance, management, server, healthEndpointPath);
EndpointPathProvider endpointPathProvider) {
return new DefaultApplicationFactory(instance, management, server, endpointPathProvider);
}
@Bean
......
......@@ -21,7 +21,8 @@ import de.codecentric.boot.admin.client.config.InstanceProperties;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Map;
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.EndpointPathProvider;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.web.server.Ssl;
......@@ -43,16 +44,16 @@ public class DefaultApplicationFactory implements ApplicationFactory {
private ManagementServerProperties management;
private Integer localServerPort;
private Integer localManagementPort;
private String healthEndpointPath;
private EndpointPathProvider endpointPathProvider;
public DefaultApplicationFactory(InstanceProperties instance,
ManagementServerProperties management,
ServerProperties server,
String healthEndpointPath) {
EndpointPathProvider endpointPathProvider) {
this.instance = instance;
this.management = management;
this.server = server;
this.healthEndpointPath = healthEndpointPath;
this.endpointPathProvider = endpointPathProvider;
}
@Override
......@@ -89,7 +90,7 @@ public class DefaultApplicationFactory implements ApplicationFactory {
.port(getLocalServerPort());
}
return builder.path("/").path(getServerContextPath()).path("/").toUriString();
return builder.path("/").path(getServerContextPath()).toUriString();
}
protected String getServerContextPath() {
......@@ -101,22 +102,32 @@ public class DefaultApplicationFactory implements ApplicationFactory {
return instance.getManagementUrl();
}
return UriComponentsBuilder.fromUriString(getManagementBaseUrl())
.path("/")
.path(getManagementContextPath())
.toUriString();
}
protected String getManagementBaseUrl() {
String baseUrl = instance.getManagementBaseUrl();
UriComponentsBuilder builder;
if (!StringUtils.isEmpty(baseUrl)) {
builder = UriComponentsBuilder.fromUriString(baseUrl);
} else if (isManagementPortEqual()) {
builder = UriComponentsBuilder.fromHttpUrl(getServiceUrl()).path("/").path(getDispatcherServletPrefix());
} else {
Ssl ssl = management.getSsl() != null ? management.getSsl() : server.getSsl();
builder = UriComponentsBuilder.newInstance()
.scheme(getScheme(ssl))
.host(getManagementHost())
.port(getLocalManagementPort());
return baseUrl;
}
if (isManagementPortEqual()) {
return UriComponentsBuilder.fromHttpUrl(getServiceUrl())
.path("/")
.path(getDispatcherServletPrefix())
.toUriString();
}
return builder.path("/").path(getManagementContextPath()).path("/").toUriString();
Ssl ssl = management.getSsl() != null ? management.getSsl() : server.getSsl();
return UriComponentsBuilder.newInstance()
.scheme(getScheme(ssl))
.host(getManagementHost())
.port(getLocalManagementPort())
.toUriString();
}
protected String getDispatcherServletPrefix() {
......@@ -135,10 +146,9 @@ public class DefaultApplicationFactory implements ApplicationFactory {
if (instance.getHealthUrl() != null) {
return instance.getHealthUrl();
}
return UriComponentsBuilder.fromHttpUrl(getManagementUrl())
return UriComponentsBuilder.fromHttpUrl(getManagementBaseUrl())
.path("/")
.path(getHealthEndpointPath())
.path("/")
.toUriString();
}
......@@ -179,7 +189,15 @@ public class DefaultApplicationFactory implements ApplicationFactory {
}
protected String getHealthEndpointPath() {
return healthEndpointPath;
String health = endpointPathProvider.getPath("health");
if (StringUtils.hasText(health)) {
return health;
}
String status = endpointPathProvider.getPath("status");
if (StringUtils.hasText(status)) {
return status;
}
throw new IllegalStateException("Either health or status endpoint must be enabled!");
}
protected String getScheme(Ssl ssl) {
......
......@@ -19,7 +19,8 @@ package de.codecentric.boot.admin.client.registration;
import de.codecentric.boot.admin.client.config.InstanceProperties;
import javax.servlet.ServletContext;
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.EndpointPathProvider;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties;
public class ServletApplicationFactory extends DefaultApplicationFactory {
......@@ -30,8 +31,8 @@ public class ServletApplicationFactory extends DefaultApplicationFactory {
ManagementServerProperties management,
ServerProperties server,
ServletContext servletContext,
String healthEndpointPath) {
super(instance, management, server, healthEndpointPath);
EndpointPathProvider endpointPathProvider) {
super(instance, management, server, endpointPathProvider);
this.servletContext = servletContext;
this.servlet = server.getServlet();
}
......
......@@ -42,7 +42,6 @@ import static com.github.tomakehurst.wiremock.client.WireMock.verify;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
public class ClientServletApplicationTest {
private ConfigurableApplicationContext instance;
private WireMockServer wiremock;
......@@ -60,8 +59,8 @@ public class ClientServletApplicationTest {
stubFor(post(urlEqualTo("/instances")).willReturn(response));
instance = SpringApplication.run(TestClientApplication.class, "--spring.main.web-application-type=servlet",
"--spring.application.name=Test-Client", "--server.port=0", "--management.port=0",
"--management.context-path=/mgmt",
"--spring.application.name=Test-Client", "--server.port=0", "--management.context-path=/mgmt",
"--endpoints.health.enabled=true",
"--spring.boot.admin.client.url=http://localhost:" + wiremock.port());
}
......@@ -71,8 +70,8 @@ public class ClientServletApplicationTest {
String serviceHost = "http://localhost:" + instance.getEnvironment().getProperty("local.server.port");
String managementHost = "http://localhost:" + instance.getEnvironment().getProperty("local.management.port");
String body = "{ \"name\" : \"Test-Client\"," + //
" \"managementUrl\" : \"" + managementHost + "/mgmt/\"," + //
" \"healthUrl\" : \"" + managementHost + "/mgmt/health/\"," + //
" \"managementUrl\" : \"" + managementHost + "/mgmt\"," + //
" \"healthUrl\" : \"" + managementHost + "/mgmt/health\"," + //
" \"serviceUrl\" : \"" + serviceHost + "/\", " + //
" \"metadata\" : {} }";
RequestPatternBuilder request = postRequestedFor(urlEqualTo("/instances")).withHeader("Content-Type",
......
......@@ -23,7 +23,8 @@ import java.net.UnknownHostException;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.EndpointPathProvider;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.web.server.Ssl;
......@@ -39,8 +40,10 @@ public class DefaultApplicationFactoryTest {
private InstanceProperties instanceProperties = new InstanceProperties();
private ServerProperties server = new ServerProperties();
private ManagementServerProperties management = new ManagementServerProperties();
private EndpointPathProvider endpointPathProvider = mock(EndpointPathProvider.class);
private DefaultApplicationFactory factory = new DefaultApplicationFactory(instanceProperties, management, server,
"/health");
endpointPathProvider);
@Before
public void setup() {
......@@ -50,24 +53,23 @@ public class DefaultApplicationFactoryTest {
@Test
public void test_mgmtPortPath() {
management.setContextPath("/admin");
DefaultApplicationFactory factory = new DefaultApplicationFactory(instanceProperties, management, server,
"/alive");
when(endpointPathProvider.getPath("health")).thenReturn("/admin/alive");
publishApplicationReadyEvent(factory, 8080, 8081);
Application app = factory.createApplication();
assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":8081/admin/");
assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":8081/admin/alive/");
assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":8081/admin");
assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":8081/admin/alive");
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":8080/");
}
@Test
public void test_default() {
when(endpointPathProvider.getPath("health")).thenReturn("/application/health");
publishApplicationReadyEvent(factory, 8080, null);
Application app = factory.createApplication();
assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":8080/application/");
assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":8080/application/health/");
assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":8080/application");
assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":8080/application/health");
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":8080/");
}
......@@ -75,11 +77,12 @@ public class DefaultApplicationFactoryTest {
public void test_ssl() {
server.setSsl(new Ssl());
server.getSsl().setEnabled(true);
when(endpointPathProvider.getPath("health")).thenReturn("/application/health");
publishApplicationReadyEvent(factory, 8080, null);
Application app = factory.createApplication();
assertThat(app.getManagementUrl()).isEqualTo("https://" + getHostname() + ":8080/application/");
assertThat(app.getHealthUrl()).isEqualTo("https://" + getHostname() + ":8080/application/health/");
assertThat(app.getManagementUrl()).isEqualTo("https://" + getHostname() + ":8080/application");
assertThat(app.getHealthUrl()).isEqualTo("https://" + getHostname() + ":8080/application/health");
assertThat(app.getServiceUrl()).isEqualTo("https://" + getHostname() + ":8080/");
}
......@@ -87,17 +90,19 @@ public class DefaultApplicationFactoryTest {
public void test_ssl_management() {
management.setSsl(new Ssl());
management.getSsl().setEnabled(true);
when(endpointPathProvider.getPath("health")).thenReturn("/application/alive");
publishApplicationReadyEvent(factory, 8080, 9090);
Application app = factory.createApplication();
assertThat(app.getManagementUrl()).isEqualTo("https://" + getHostname() + ":9090/application/");
assertThat(app.getHealthUrl()).isEqualTo("https://" + getHostname() + ":9090/application/health/");
assertThat(app.getManagementUrl()).isEqualTo("https://" + getHostname() + ":9090/application");
assertThat(app.getHealthUrl()).isEqualTo("https://" + getHostname() + ":9090/application/alive");
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":8080/");
}
@Test
public void test_preferIpAddress_serveraddress_missing() {
instanceProperties.setPreferIp(true);
when(endpointPathProvider.getPath("health")).thenReturn("/application/alive");
publishApplicationReadyEvent(factory, 8080, null);
Application app = factory.createApplication();
......@@ -107,11 +112,11 @@ public class DefaultApplicationFactoryTest {
@Test
public void test_preferIpAddress_managementaddress_missing() {
instanceProperties.setPreferIp(true);
when(endpointPathProvider.getPath("health")).thenReturn("/application/alive");
publishApplicationReadyEvent(factory, 8080, 8081);
Application app = factory.createApplication();
assertThat(app.getManagementUrl()).matches(
"http://\\d{0,3}\\.\\d{0,3}\\.\\d{0,3}\\.\\d{0,3}:8081/application/");
assertThat(app.getManagementUrl()).matches("http://\\d{0,3}\\.\\d{0,3}\\.\\d{0,3}\\.\\d{0,3}:8081/application");
}
@Test
......@@ -119,11 +124,12 @@ public class DefaultApplicationFactoryTest {
instanceProperties.setPreferIp(true);
server.setAddress(InetAddress.getByName("127.0.0.1"));
management.setAddress(InetAddress.getByName("127.0.0.2"));
when(endpointPathProvider.getPath("health")).thenReturn("/application/health");
publishApplicationReadyEvent(factory, 8080, 8081);
Application app = factory.createApplication();
assertThat(app.getManagementUrl()).isEqualTo("http://127.0.0.2:8081/application/");
assertThat(app.getHealthUrl()).isEqualTo("http://127.0.0.2:8081/application/health/");
assertThat(app.getManagementUrl()).isEqualTo("http://127.0.0.2:8081/application");
assertThat(app.getHealthUrl()).isEqualTo("http://127.0.0.2:8081/application/health");
assertThat(app.getServiceUrl()).isEqualTo("http://127.0.0.1:8080/");
}
......@@ -144,22 +150,24 @@ public class DefaultApplicationFactoryTest {
instanceProperties.setManagementBaseUrl("http://management:8090");
instanceProperties.setServiceBaseUrl("http://service:80");
management.setContextPath("/admin");
when(endpointPathProvider.getPath("health")).thenReturn("/admin/health");
Application app = factory.createApplication();
assertThat(app.getServiceUrl()).isEqualTo("http://service:80/");
assertThat(app.getManagementUrl()).isEqualTo("http://management:8090/admin/");
assertThat(app.getHealthUrl()).isEqualTo("http://management:8090/admin/health/");
assertThat(app.getManagementUrl()).isEqualTo("http://management:8090/admin");
assertThat(app.getHealthUrl()).isEqualTo("http://management:8090/admin/health");
}
@Test
public void test_service_baseUrl() {
instanceProperties.setServiceBaseUrl("http://service:80");
management.setContextPath("/admin");
when(endpointPathProvider.getPath("health")).thenReturn("/admin/health");
Application app = factory.createApplication();
assertThat(app.getServiceUrl()).isEqualTo("http://service:80/");
assertThat(app.getManagementUrl()).isEqualTo("http://service:80/admin/");
assertThat(app.getHealthUrl()).isEqualTo("http://service:80/admin/health/");
assertThat(app.getManagementUrl()).isEqualTo("http://service:80/admin");
assertThat(app.getHealthUrl()).isEqualTo("http://service:80/admin/health");
}
@Test
......
......@@ -23,7 +23,8 @@ import java.net.UnknownHostException;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.EndpointPathProvider;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.mock.env.MockEnvironment;
......@@ -39,8 +40,9 @@ public class ServletApplicationFactoryTest {
private ServerProperties server = new ServerProperties();
private ManagementServerProperties management = new ManagementServerProperties();
private MockServletContext servletContext = new MockServletContext();
private EndpointPathProvider endpointPathProvider = mock(EndpointPathProvider.class);
private ServletApplicationFactory factory = new ServletApplicationFactory(instance, management, server,
servletContext, "/health");
servletContext, endpointPathProvider);
@Before
public void setup() {
......@@ -51,47 +53,51 @@ public class ServletApplicationFactoryTest {
public void test_contextPath_mgmtPath() {
servletContext.setContextPath("app");
management.setContextPath("/admin");
when(endpointPathProvider.getPath("health")).thenReturn("/admin/health");
publishApplicationReadyEvent(factory, 8080, null);
Application app = factory.createApplication();
assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":8080/app/admin/");
assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":8080/app/admin/health/");
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":8080/app/");
assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":8080/app/admin");
assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":8080/app/admin/health");
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":8080/app");
}
@Test
public void test_contextPath_mgmtPortPath() {
servletContext.setContextPath("app");
management.setContextPath("/admin");
when(endpointPathProvider.getPath("health")).thenReturn("/admin/health");
publishApplicationReadyEvent(factory, 8080, 8081);
Application app = factory.createApplication();
assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":8081/admin/");
assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":8081/admin/health/");
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":8080/app/");
assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":8081/admin");
assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":8081/admin/health");
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":8080/app");
}
@Test
public void test_contextPath() {
servletContext.setContextPath("app");
when(endpointPathProvider.getPath("health")).thenReturn("/application/health");
publishApplicationReadyEvent(factory, 80, null);
Application app = factory.createApplication();
assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":80/app/application/");
assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":80/app/application/health/");
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":80/app/");
assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":80/app/application");
assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":80/app/application/health");
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":80/app");
}
@Test
public void test_servletPath() {
server.getServlet().setPath("app");
servletContext.setContextPath("srv");
when(endpointPathProvider.getPath("health")).thenReturn("/application/health");
publishApplicationReadyEvent(factory, 80, null);
Application app = factory.createApplication();
assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":80/srv/app/application/");
assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":80/srv/app/application/health/");
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":80/srv/");
assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":80/srv/app/application");
assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":80/srv/app/application/health");
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":80/srv");
}
private String getHostname() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment