Adds test for existence of ManagementServerProperties class.
fixes gh-435
This commit is contained in:
@@ -27,16 +27,22 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public class ManagementServerPortUtils {
|
||||
private static final boolean hasActuator;
|
||||
/** for testing */ static final boolean hasActuator;
|
||||
static {
|
||||
boolean hasEndpointClass = hasClass("org.springframework.boot.actuate.endpoint.annotation.Endpoint");
|
||||
boolean hasManagementServerPropertiesClass = hasClass("org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties");
|
||||
hasActuator = hasEndpointClass && hasManagementServerPropertiesClass;
|
||||
}
|
||||
|
||||
private static boolean hasClass(String className) {
|
||||
boolean hasClass;
|
||||
try {
|
||||
Class.forName("org.springframework.boot.actuate.endpoint.annotation.Endpoint");
|
||||
Class.forName(className);
|
||||
hasClass = true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
hasClass = false;
|
||||
}
|
||||
hasActuator = hasClass;
|
||||
return hasClass;
|
||||
}
|
||||
|
||||
public static ManagementServerPort get(BeanFactory beanFactory) {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.client.discovery;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.test.ClassPathExclusions;
|
||||
import org.springframework.cloud.test.ModifiedClassPathRunner;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(ModifiedClassPathRunner.class)
|
||||
@ClassPathExclusions({ "spring-boot-actuator-autoconfigure-*" })
|
||||
public class ManagementServerPortUtilsTests {
|
||||
|
||||
@Test
|
||||
public void contextStarts() {
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder()
|
||||
.web(WebApplicationType.NONE).sources(TestApp.class).run()) {
|
||||
|
||||
assertThat(ManagementServerPortUtils.hasActuator).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
@EnableAutoConfiguration
|
||||
protected static class TestApp {}
|
||||
}
|
||||
Reference in New Issue
Block a user