Allow health groups to be configured at an additional path
Closes gh-25471 Co-authored-by: Phillip Webb <pwebb@vmware.com>
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2012-2021 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
|
||||
*
|
||||
* https://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.boot.actuate.endpoint.web;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link WebServerNamespace}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
class WebServerNamespaceTests {
|
||||
|
||||
@Test
|
||||
void fromWhenValueHasText() {
|
||||
assertThat(WebServerNamespace.from("management")).isEqualTo(WebServerNamespace.MANAGEMENT);
|
||||
}
|
||||
|
||||
@Test
|
||||
void fromWhenValueIsNull() {
|
||||
assertThat(WebServerNamespace.from(null)).isEqualTo(WebServerNamespace.SERVER);
|
||||
}
|
||||
|
||||
@Test
|
||||
void fromWhenValueIsEmpty() {
|
||||
assertThat(WebServerNamespace.from("")).isEqualTo(WebServerNamespace.SERVER);
|
||||
}
|
||||
|
||||
@Test
|
||||
void namespaceWithSameValueAreEqual() {
|
||||
assertThat(WebServerNamespace.from("value")).isEqualTo(WebServerNamespace.from("value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void namespaceWithDifferentValuesAreNotEqual() {
|
||||
assertThat(WebServerNamespace.from("value")).isNotEqualTo(WebServerNamespace.from("other"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -137,7 +137,7 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
|
||||
@Test
|
||||
void matchAllRemainingPathsSelectorShouldDecodePath() {
|
||||
load(MatchAllRemainingEndpointConfiguration.class,
|
||||
(client) -> client.get().uri("/matchallremaining/one/two%20three/").exchange().expectStatus().isOk()
|
||||
(client) -> client.get().uri("/matchallremaining/one/two three/").exchange().expectStatus().isOk()
|
||||
.expectBody().jsonPath("selection").isEqualTo("one|two three"));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright 2012-2021 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
|
||||
*
|
||||
* https://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.boot.actuate.health;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.web.WebServerNamespace;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link AdditionalHealthEndpointPath}.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
class AdditionalHealthEndpointPathTests {
|
||||
|
||||
@Test
|
||||
void fromValidPathShouldCreatePath() {
|
||||
AdditionalHealthEndpointPath path = AdditionalHealthEndpointPath.from("server:/my-path");
|
||||
assertThat(path.getValue()).isEqualTo("/my-path");
|
||||
assertThat(path.getNamespace()).isEqualTo(WebServerNamespace.SERVER);
|
||||
}
|
||||
|
||||
@Test
|
||||
void fromValidPathWithoutSlashShouldCreatePath() {
|
||||
AdditionalHealthEndpointPath path = AdditionalHealthEndpointPath.from("server:my-path");
|
||||
assertThat(path.getValue()).isEqualTo("my-path");
|
||||
assertThat(path.getNamespace()).isEqualTo(WebServerNamespace.SERVER);
|
||||
}
|
||||
|
||||
@Test
|
||||
void fromNullPathShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> AdditionalHealthEndpointPath.from(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fromEmptyPathShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> AdditionalHealthEndpointPath.from(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fromPathWithNoNamespaceShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> AdditionalHealthEndpointPath.from("my-path"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fromPathWithEmptyNamespaceShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> AdditionalHealthEndpointPath.from(":my-path"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fromPathWithMultipleSegmentsShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> AdditionalHealthEndpointPath.from("server:/my-path/my-sub-path"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fromPathWithMultipleSegmentsNotStartingWithSlashShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> AdditionalHealthEndpointPath.from("server:my-path/my-sub-path"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void pathsWithTheSameNamespaceAndValueAreEqual() {
|
||||
assertThat(AdditionalHealthEndpointPath.from("server:/my-path"))
|
||||
.isEqualTo(AdditionalHealthEndpointPath.from("server:/my-path"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void pathsWithTheDifferentNamespaceAndSameValueAreNotEqual() {
|
||||
assertThat(AdditionalHealthEndpointPath.from("server:/my-path"))
|
||||
.isNotEqualTo((AdditionalHealthEndpointPath.from("management:/my-path")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void pathsWithTheSameNamespaceAndValuesWithNoSlashAreEqual() {
|
||||
assertThat(AdditionalHealthEndpointPath.from("server:/my-path"))
|
||||
.isEqualTo((AdditionalHealthEndpointPath.from("server:my-path")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void ofWithNullNamespaceShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> AdditionalHealthEndpointPath.of(null, "my-sub-path"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void ofWithNullPathShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> AdditionalHealthEndpointPath.of(WebServerNamespace.SERVER, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void ofWithMultipleSegmentValueShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> AdditionalHealthEndpointPath.of(WebServerNamespace.SERVER, "/my-path/my-subpath"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void ofShouldCreatePath() {
|
||||
AdditionalHealthEndpointPath additionalPath = AdditionalHealthEndpointPath.of(WebServerNamespace.SERVER,
|
||||
"my-path");
|
||||
assertThat(additionalPath.getValue()).isEqualTo("my-path");
|
||||
assertThat(additionalPath.getNamespace()).isEqualTo(WebServerNamespace.SERVER);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.ApiVersion;
|
||||
import org.springframework.boot.actuate.endpoint.SecurityContext;
|
||||
import org.springframework.boot.actuate.endpoint.web.WebServerNamespace;
|
||||
import org.springframework.boot.actuate.health.HealthEndpointSupport.HealthResult;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -72,7 +73,7 @@ abstract class HealthEndpointSupportTests<R extends ContributorRegistry<C>, C, T
|
||||
@Test
|
||||
void getHealthWhenPathIsEmptyUsesPrimaryGroup() {
|
||||
this.registry.registerContributor("test", createContributor(this.up));
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, SecurityContext.NONE,
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, null, SecurityContext.NONE,
|
||||
false);
|
||||
assertThat(result.getGroup()).isEqualTo(this.primaryGroup);
|
||||
assertThat(getHealth(result)).isNotSameAs(this.up);
|
||||
@@ -82,7 +83,7 @@ abstract class HealthEndpointSupportTests<R extends ContributorRegistry<C>, C, T
|
||||
@Test
|
||||
void getHealthWhenPathIsNotGroupReturnsResultFromPrimaryGroup() {
|
||||
this.registry.registerContributor("test", createContributor(this.up));
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, SecurityContext.NONE,
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, null, SecurityContext.NONE,
|
||||
false, "test");
|
||||
assertThat(result.getGroup()).isEqualTo(this.primaryGroup);
|
||||
assertThat(getHealth(result)).isEqualTo(this.up);
|
||||
@@ -92,7 +93,7 @@ abstract class HealthEndpointSupportTests<R extends ContributorRegistry<C>, C, T
|
||||
@Test
|
||||
void getHealthWhenPathIsGroupReturnsResultFromGroup() {
|
||||
this.registry.registerContributor("atest", createContributor(this.up));
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, SecurityContext.NONE,
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, null, SecurityContext.NONE,
|
||||
false, "alltheas", "atest");
|
||||
assertThat(result.getGroup()).isEqualTo(this.allTheAs);
|
||||
assertThat(getHealth(result)).isEqualTo(this.up);
|
||||
@@ -103,7 +104,7 @@ abstract class HealthEndpointSupportTests<R extends ContributorRegistry<C>, C, T
|
||||
C contributor = createContributor(this.up);
|
||||
C compositeContributor = createCompositeContributor(Collections.singletonMap("spring", contributor));
|
||||
this.registry.registerContributor("test", compositeContributor);
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, SecurityContext.NONE,
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, null, SecurityContext.NONE,
|
||||
false, "test");
|
||||
CompositeHealth health = (CompositeHealth) getHealth(result);
|
||||
assertThat(health.getComponents()).containsKey("spring");
|
||||
@@ -116,9 +117,9 @@ abstract class HealthEndpointSupportTests<R extends ContributorRegistry<C>, C, T
|
||||
C compositeContributor = createCompositeContributor(Collections.singletonMap("spring", contributor));
|
||||
this.registry.registerContributor("test", compositeContributor);
|
||||
HealthEndpointSupport<C, T> endpoint = create(this.registry, this.groups);
|
||||
HealthResult<T> rootResult = endpoint.getHealth(ApiVersion.V3, SecurityContext.NONE, false);
|
||||
HealthResult<T> rootResult = endpoint.getHealth(ApiVersion.V3, null, SecurityContext.NONE, false);
|
||||
assertThat(((CompositeHealth) getHealth(rootResult)).getComponents()).isNullOrEmpty();
|
||||
HealthResult<T> componentResult = endpoint.getHealth(ApiVersion.V3, SecurityContext.NONE, false, "test");
|
||||
HealthResult<T> componentResult = endpoint.getHealth(ApiVersion.V3, null, SecurityContext.NONE, false, "test");
|
||||
assertThat(componentResult).isNull();
|
||||
}
|
||||
|
||||
@@ -129,16 +130,16 @@ abstract class HealthEndpointSupportTests<R extends ContributorRegistry<C>, C, T
|
||||
C compositeContributor = createCompositeContributor(Collections.singletonMap("spring", contributor));
|
||||
this.registry.registerContributor("test", compositeContributor);
|
||||
HealthEndpointSupport<C, T> endpoint = create(this.registry, this.groups);
|
||||
HealthResult<T> rootResult = endpoint.getHealth(ApiVersion.V3, SecurityContext.NONE, false);
|
||||
HealthResult<T> rootResult = endpoint.getHealth(ApiVersion.V3, null, SecurityContext.NONE, false);
|
||||
assertThat(((CompositeHealth) getHealth(rootResult)).getComponents()).containsKey("test");
|
||||
HealthResult<T> componentResult = endpoint.getHealth(ApiVersion.V3, SecurityContext.NONE, false, "test");
|
||||
HealthResult<T> componentResult = endpoint.getHealth(ApiVersion.V3, null, SecurityContext.NONE, false, "test");
|
||||
assertThat(((CompositeHealth) getHealth(componentResult)).getComponents()).containsKey("spring");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getHealthWhenAlwaysShowIsFalseAndGroupIsTrueShowsDetails() {
|
||||
this.registry.registerContributor("test", createContributor(this.up));
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, SecurityContext.NONE,
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, null, SecurityContext.NONE,
|
||||
false, "test");
|
||||
assertThat(((Health) getHealth(result)).getDetails()).containsEntry("spring", "boot");
|
||||
}
|
||||
@@ -148,8 +149,8 @@ abstract class HealthEndpointSupportTests<R extends ContributorRegistry<C>, C, T
|
||||
this.primaryGroup.setShowDetails(false);
|
||||
this.registry.registerContributor("test", createContributor(this.up));
|
||||
HealthEndpointSupport<C, T> endpoint = create(this.registry, this.groups);
|
||||
HealthResult<T> rootResult = endpoint.getHealth(ApiVersion.V3, SecurityContext.NONE, false);
|
||||
HealthResult<T> componentResult = endpoint.getHealth(ApiVersion.V3, SecurityContext.NONE, false, "test");
|
||||
HealthResult<T> rootResult = endpoint.getHealth(ApiVersion.V3, null, SecurityContext.NONE, false);
|
||||
HealthResult<T> componentResult = endpoint.getHealth(ApiVersion.V3, null, SecurityContext.NONE, false, "test");
|
||||
assertThat(((CompositeHealth) getHealth(rootResult)).getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(componentResult).isNull();
|
||||
}
|
||||
@@ -158,8 +159,8 @@ abstract class HealthEndpointSupportTests<R extends ContributorRegistry<C>, C, T
|
||||
void getHealthWhenAlwaysShowIsTrueShowsDetails() {
|
||||
this.primaryGroup.setShowDetails(false);
|
||||
this.registry.registerContributor("test", createContributor(this.up));
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, SecurityContext.NONE, true,
|
||||
"test");
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, null, SecurityContext.NONE,
|
||||
true, "test");
|
||||
assertThat(((Health) getHealth(result)).getDetails()).containsEntry("spring", "boot");
|
||||
}
|
||||
|
||||
@@ -169,7 +170,7 @@ abstract class HealthEndpointSupportTests<R extends ContributorRegistry<C>, C, T
|
||||
contributors.put("a", createContributor(this.up));
|
||||
contributors.put("b", createContributor(this.down));
|
||||
this.registry.registerContributor("test", createCompositeContributor(contributors));
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, SecurityContext.NONE,
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, null, SecurityContext.NONE,
|
||||
false);
|
||||
CompositeHealth root = (CompositeHealth) getHealth(result);
|
||||
CompositeHealth component = (CompositeHealth) root.getComponents().get("test");
|
||||
@@ -180,7 +181,7 @@ abstract class HealthEndpointSupportTests<R extends ContributorRegistry<C>, C, T
|
||||
|
||||
@Test
|
||||
void getHealthWhenPathDoesNotExistReturnsNull() {
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, SecurityContext.NONE,
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, null, SecurityContext.NONE,
|
||||
false, "missing");
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
@@ -188,7 +189,7 @@ abstract class HealthEndpointSupportTests<R extends ContributorRegistry<C>, C, T
|
||||
@Test
|
||||
void getHealthWhenPathIsEmptyIncludesGroups() {
|
||||
this.registry.registerContributor("test", createContributor(this.up));
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, SecurityContext.NONE,
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, null, SecurityContext.NONE,
|
||||
false);
|
||||
assertThat(((SystemHealth) getHealth(result)).getGroups()).containsOnly("alltheas");
|
||||
}
|
||||
@@ -196,7 +197,7 @@ abstract class HealthEndpointSupportTests<R extends ContributorRegistry<C>, C, T
|
||||
@Test
|
||||
void getHealthWhenPathIsGroupDoesNotIncludesGroups() {
|
||||
this.registry.registerContributor("atest", createContributor(this.up));
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, SecurityContext.NONE,
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, null, SecurityContext.NONE,
|
||||
false, "alltheas");
|
||||
assertThat(getHealth(result)).isNotInstanceOf(SystemHealth.class);
|
||||
}
|
||||
@@ -204,7 +205,7 @@ abstract class HealthEndpointSupportTests<R extends ContributorRegistry<C>, C, T
|
||||
@Test
|
||||
void getHealthWithEmptyCompositeReturnsNullResult() { // gh-18687
|
||||
this.registry.registerContributor("test", createCompositeContributor(Collections.emptyMap()));
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, SecurityContext.NONE,
|
||||
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, null, SecurityContext.NONE,
|
||||
false);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
@@ -217,12 +218,53 @@ abstract class HealthEndpointSupportTests<R extends ContributorRegistry<C>, C, T
|
||||
TestHealthEndpointGroup testGroup = new TestHealthEndpointGroup((name) -> name.startsWith("test"));
|
||||
HealthEndpointGroups groups = HealthEndpointGroups.of(this.primaryGroup,
|
||||
Collections.singletonMap("testGroup", testGroup));
|
||||
HealthResult<T> result = create(this.registry, groups).getHealth(ApiVersion.V3, SecurityContext.NONE, false,
|
||||
"testGroup");
|
||||
HealthResult<T> result = create(this.registry, groups).getHealth(ApiVersion.V3, null, SecurityContext.NONE,
|
||||
false, "testGroup");
|
||||
CompositeHealth health = (CompositeHealth) getHealth(result);
|
||||
assertThat(health.getComponents()).containsKey("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getHealthWhenGroupHasAdditionalPath() {
|
||||
this.registry.registerContributor("test", createContributor(this.up));
|
||||
TestHealthEndpointGroup testGroup = new TestHealthEndpointGroup((name) -> name.startsWith("test"));
|
||||
testGroup.setAdditionalPath(AdditionalHealthEndpointPath.from("server:/healthz"));
|
||||
HealthEndpointGroups groups = HealthEndpointGroups.of(this.primaryGroup,
|
||||
Collections.singletonMap("testGroup", testGroup));
|
||||
HealthResult<T> result = create(this.registry, groups).getHealth(ApiVersion.V3, WebServerNamespace.SERVER,
|
||||
SecurityContext.NONE, false, "healthz");
|
||||
CompositeHealth health = (CompositeHealth) getHealth(result);
|
||||
assertThat(health.getComponents()).containsKey("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getHealthWhenGroupHasAdditionalPathAndShowComponentsFalse() {
|
||||
this.registry.registerContributor("test", createContributor(this.up));
|
||||
TestHealthEndpointGroup testGroup = new TestHealthEndpointGroup((name) -> name.startsWith("test"));
|
||||
testGroup.setAdditionalPath(AdditionalHealthEndpointPath.from("server:/healthz"));
|
||||
testGroup.setShowComponents(false);
|
||||
HealthEndpointGroups groups = HealthEndpointGroups.of(this.primaryGroup,
|
||||
Collections.singletonMap("testGroup", testGroup));
|
||||
HealthResult<T> result = create(this.registry, groups).getHealth(ApiVersion.V3, WebServerNamespace.SERVER,
|
||||
SecurityContext.NONE, false, "healthz");
|
||||
CompositeHealth health = (CompositeHealth) getHealth(result);
|
||||
assertThat(health.getStatus().getCode()).isEqualTo("UP");
|
||||
assertThat(health.getComponents()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getComponentHealthWhenGroupHasAdditionalPathAndShowComponentsFalse() {
|
||||
this.registry.registerContributor("test", createContributor(this.up));
|
||||
TestHealthEndpointGroup testGroup = new TestHealthEndpointGroup((name) -> name.startsWith("test"));
|
||||
testGroup.setAdditionalPath(AdditionalHealthEndpointPath.from("server:/healthz"));
|
||||
testGroup.setShowComponents(false);
|
||||
HealthEndpointGroups groups = HealthEndpointGroups.of(this.primaryGroup,
|
||||
Collections.singletonMap("testGroup", testGroup));
|
||||
HealthResult<T> result = create(this.registry, groups).getHealth(ApiVersion.V3, WebServerNamespace.SERVER,
|
||||
SecurityContext.NONE, false, "healthz", "test");
|
||||
assertThat(result).isEqualTo(null);
|
||||
}
|
||||
|
||||
protected abstract HealthEndpointSupport<C, T> create(R registry, HealthEndpointGroups groups);
|
||||
|
||||
protected abstract R createRegistry();
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.actuate.endpoint.ApiVersion;
|
||||
import org.springframework.boot.actuate.endpoint.SecurityContext;
|
||||
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
|
||||
import org.springframework.boot.actuate.endpoint.web.WebServerNamespace;
|
||||
import org.springframework.boot.actuate.health.HealthEndpointSupport.HealthResult;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -42,7 +43,7 @@ class HealthEndpointWebExtensionTests
|
||||
void healthReturnsSystemHealth() {
|
||||
this.registry.registerContributor("test", createContributor(this.up));
|
||||
WebEndpointResponse<HealthComponent> response = create(this.registry, this.groups).health(ApiVersion.LATEST,
|
||||
SecurityContext.NONE);
|
||||
WebServerNamespace.SERVER, SecurityContext.NONE);
|
||||
HealthComponent health = response.getBody();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(health).isInstanceOf(SystemHealth.class);
|
||||
@@ -54,7 +55,7 @@ class HealthEndpointWebExtensionTests
|
||||
assertThat(this.registry).isEmpty();
|
||||
WebEndpointResponse<HealthComponent> response = create(this.registry,
|
||||
HealthEndpointGroups.of(mock(HealthEndpointGroup.class), Collections.emptyMap()))
|
||||
.health(ApiVersion.LATEST, SecurityContext.NONE);
|
||||
.health(ApiVersion.LATEST, WebServerNamespace.SERVER, SecurityContext.NONE);
|
||||
assertThat(response.getStatus()).isEqualTo(200);
|
||||
HealthComponent health = response.getBody();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
@@ -65,7 +66,7 @@ class HealthEndpointWebExtensionTests
|
||||
void healthWhenPathDoesNotExistReturnsHttp404() {
|
||||
this.registry.registerContributor("test", createContributor(this.up));
|
||||
WebEndpointResponse<HealthComponent> response = create(this.registry, this.groups).health(ApiVersion.LATEST,
|
||||
SecurityContext.NONE, "missing");
|
||||
WebServerNamespace.SERVER, SecurityContext.NONE, "missing");
|
||||
assertThat(response.getBody()).isNull();
|
||||
assertThat(response.getStatus()).isEqualTo(404);
|
||||
}
|
||||
@@ -74,7 +75,7 @@ class HealthEndpointWebExtensionTests
|
||||
void healthWhenPathExistsReturnsHealth() {
|
||||
this.registry.registerContributor("test", createContributor(this.up));
|
||||
WebEndpointResponse<HealthComponent> response = create(this.registry, this.groups).health(ApiVersion.LATEST,
|
||||
SecurityContext.NONE, "test");
|
||||
WebServerNamespace.SERVER, SecurityContext.NONE, "test");
|
||||
assertThat(response.getBody()).isEqualTo(this.up);
|
||||
assertThat(response.getStatus()).isEqualTo(200);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ class ReactiveHealthEndpointWebExtensionTests extends
|
||||
void healthReturnsSystemHealth() {
|
||||
this.registry.registerContributor("test", createContributor(this.up));
|
||||
WebEndpointResponse<? extends HealthComponent> response = create(this.registry, this.groups)
|
||||
.health(ApiVersion.LATEST, SecurityContext.NONE).block();
|
||||
.health(ApiVersion.LATEST, null, SecurityContext.NONE).block();
|
||||
HealthComponent health = response.getBody();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(health).isInstanceOf(SystemHealth.class);
|
||||
@@ -55,7 +55,7 @@ class ReactiveHealthEndpointWebExtensionTests extends
|
||||
assertThat(this.registry).isEmpty();
|
||||
WebEndpointResponse<? extends HealthComponent> response = create(this.registry,
|
||||
HealthEndpointGroups.of(mock(HealthEndpointGroup.class), Collections.emptyMap()))
|
||||
.health(ApiVersion.LATEST, SecurityContext.NONE).block();
|
||||
.health(ApiVersion.LATEST, null, SecurityContext.NONE).block();
|
||||
assertThat(response.getStatus()).isEqualTo(200);
|
||||
HealthComponent health = response.getBody();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
@@ -66,7 +66,7 @@ class ReactiveHealthEndpointWebExtensionTests extends
|
||||
void healthWhenPathDoesNotExistReturnsHttp404() {
|
||||
this.registry.registerContributor("test", createContributor(this.up));
|
||||
WebEndpointResponse<? extends HealthComponent> response = create(this.registry, this.groups)
|
||||
.health(ApiVersion.LATEST, SecurityContext.NONE, "missing").block();
|
||||
.health(ApiVersion.LATEST, null, SecurityContext.NONE, "missing").block();
|
||||
assertThat(response.getBody()).isNull();
|
||||
assertThat(response.getStatus()).isEqualTo(404);
|
||||
}
|
||||
@@ -75,7 +75,7 @@ class ReactiveHealthEndpointWebExtensionTests extends
|
||||
void healthWhenPathExistsReturnsHealth() {
|
||||
this.registry.registerContributor("test", createContributor(this.up));
|
||||
WebEndpointResponse<? extends HealthComponent> response = create(this.registry, this.groups)
|
||||
.health(ApiVersion.LATEST, SecurityContext.NONE, "test").block();
|
||||
.health(ApiVersion.LATEST, null, SecurityContext.NONE, "test").block();
|
||||
assertThat(response.getBody()).isEqualTo(this.up);
|
||||
assertThat(response.getStatus()).isEqualTo(200);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2021 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.
|
||||
@@ -37,6 +37,8 @@ class TestHealthEndpointGroup implements HealthEndpointGroup {
|
||||
|
||||
private boolean showDetails = true;
|
||||
|
||||
private AdditionalHealthEndpointPath additionalPath;
|
||||
|
||||
TestHealthEndpointGroup() {
|
||||
this((name) -> true);
|
||||
}
|
||||
@@ -78,4 +80,13 @@ class TestHealthEndpointGroup implements HealthEndpointGroup {
|
||||
return this.httpCodeStatusMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AdditionalHealthEndpointPath getAdditionalPath() {
|
||||
return this.additionalPath;
|
||||
}
|
||||
|
||||
void setAdditionalPath(AdditionalHealthEndpointPath additionalPath) {
|
||||
this.additionalPath = additionalPath;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user