mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +08:00
Polish "Add AOT support for actuator"
See gh-31671
This commit is contained in:
parent
584b7d1343
commit
51cba6ec72
@ -19,17 +19,15 @@ package org.springframework.boot.actuate.autoconfigure.cloudfoundry.reactive;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.aot.hint.ExecutableMode;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
import org.springframework.aot.hint.TypeReference;
|
||||
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.AccessLevel;
|
||||
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.SecurityResponse;
|
||||
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.reactive.CloudFoundryWebFluxEndpointHandlerMapping.CloudFoundryWebFluxEndpointHandlerMappingRuntimeHints;
|
||||
@ -46,6 +44,7 @@ import org.springframework.context.aot.BindingReflectionHintsRegistrar;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.reactive.result.method.RequestMappingInfoHandlerMapping;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
@ -160,10 +159,8 @@ class CloudFoundryWebFluxEndpointHandlerMapping extends AbstractWebFluxEndpointH
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||
hints.reflection().registerType(CloudFoundryLinksHandler.class,
|
||||
(hint) -> hint.onReachableType(TypeReference.of(CloudFoundryLinksHandler.class)).withMethod("links",
|
||||
List.of(TypeReference.of(ServerWebExchange.class)),
|
||||
(method) -> method.setModes(ExecutableMode.INVOKE)));
|
||||
hints.reflection().registerMethod(Objects.requireNonNull(
|
||||
ReflectionUtils.findMethod(CloudFoundryLinksHandler.class, "links", ServerWebExchange.class)));
|
||||
this.bindingRegistrar.registerReflectionHints(hints.reflection(), Link.class);
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,8 @@ package org.springframework.boot.actuate.autoconfigure.cloudfoundry.servlet;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
@ -28,10 +28,8 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.aot.hint.ExecutableMode;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
import org.springframework.aot.hint.TypeReference;
|
||||
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.AccessLevel;
|
||||
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.SecurityResponse;
|
||||
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.servlet.CloudFoundryWebEndpointServletHandlerMapping.CloudFoundryWebEndpointServletHandlerMappingRuntimeHints;
|
||||
@ -47,6 +45,7 @@ import org.springframework.context.annotation.ImportRuntimeHints;
|
||||
import org.springframework.context.aot.BindingReflectionHintsRegistrar;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
|
||||
@ -162,11 +161,9 @@ class CloudFoundryWebEndpointServletHandlerMapping extends AbstractWebMvcEndpoin
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||
hints.reflection().registerType(CloudFoundryLinksHandler.class,
|
||||
(hint) -> hint.onReachableType(TypeReference.of(CloudFoundryLinksHandler.class)).withMethod("links",
|
||||
List.of(TypeReference.of(HttpServletRequest.class),
|
||||
TypeReference.of(HttpServletResponse.class)),
|
||||
(method) -> method.setModes(ExecutableMode.INVOKE)));
|
||||
hints.reflection()
|
||||
.registerMethod(Objects.requireNonNull(ReflectionUtils.findMethod(CloudFoundryLinksHandler.class,
|
||||
"links", HttpServletRequest.class, HttpServletResponse.class)));
|
||||
this.bindingRegistrar.registerReflectionHints(hints.reflection(), Link.class);
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.aot;
|
||||
package org.springframework.boot.actuate.autoconfigure.endpoint;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ -29,12 +29,11 @@ import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
|
||||
import org.springframework.core.annotation.SynthesizedAnnotation;
|
||||
|
||||
/**
|
||||
* Registrar which registers the annotations needed for actuator support.
|
||||
* {@link RuntimeHintsRegistrar} for actuator support.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public class ActuatorAnnotationsRuntimeHintsRegistrar implements RuntimeHintsRegistrar {
|
||||
class ActuatorAnnotationsRuntimeHints implements RuntimeHintsRegistrar {
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
@ -20,7 +20,6 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.actuate.aot.ActuatorAnnotationsRuntimeHintsRegistrar;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.EndpointConverter;
|
||||
import org.springframework.boot.actuate.endpoint.invoke.ParameterValueMapper;
|
||||
@ -47,7 +46,7 @@ import org.springframework.core.env.Environment;
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@ImportRuntimeHints(ActuatorAnnotationsRuntimeHintsRegistrar.class)
|
||||
@ImportRuntimeHints(ActuatorAnnotationsRuntimeHints.class)
|
||||
public class EndpointAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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.autoconfigure.cloudfoundry;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryWebEndpointDiscoverer.CloudFoundryWebEndpointDiscovererRuntimeHints;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link CloudFoundryWebEndpointDiscovererRuntimeHints}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class CloudFoundryWebEndpointDiscovererRuntimeHintsTests {
|
||||
|
||||
private final CloudFoundryWebEndpointDiscovererRuntimeHints sut = new CloudFoundryWebEndpointDiscovererRuntimeHints();
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(CloudFoundryEndpointFilter.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(runtimeHints);
|
||||
}
|
||||
|
||||
}
|
@ -23,6 +23,10 @@ import java.util.function.Function;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryWebEndpointDiscoverer.CloudFoundryWebEndpointDiscovererRuntimeHints;
|
||||
import org.springframework.boot.actuate.endpoint.EndpointId;
|
||||
import org.springframework.boot.actuate.endpoint.InvocationContext;
|
||||
import org.springframework.boot.actuate.endpoint.SecurityContext;
|
||||
@ -50,6 +54,7 @@ import static org.mockito.Mockito.mock;
|
||||
* Tests for {@link CloudFoundryWebEndpointDiscoverer}.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class CloudFoundryWebEndpointDiscovererTests {
|
||||
|
||||
@ -69,6 +74,14 @@ class CloudFoundryWebEndpointDiscovererTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
new CloudFoundryWebEndpointDiscovererRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(CloudFoundryEndpointFilter.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(runtimeHints);
|
||||
}
|
||||
|
||||
private WebOperation findMainReadOperation(ExposableWebEndpoint endpoint) {
|
||||
for (WebOperation operation : endpoint.getOperations()) {
|
||||
if (operation.getRequestPredicate().getPath().equals("health")) {
|
||||
|
@ -26,18 +26,17 @@ import org.springframework.boot.actuate.autoconfigure.cloudfoundry.reactive.Clou
|
||||
import org.springframework.boot.actuate.endpoint.web.Link;
|
||||
|
||||
/**
|
||||
* Tests for {@link CloudFoundryWebFluxEndpointHandlerMappingRuntimeHints}.
|
||||
* Tests for {@link CloudFoundryWebFluxEndpointHandlerMapping}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class CloudFoundryWebFluxEndpointHandlerMappingRuntimeHintsTests {
|
||||
|
||||
private final CloudFoundryWebFluxEndpointHandlerMappingRuntimeHints sut = new CloudFoundryWebFluxEndpointHandlerMappingRuntimeHints();
|
||||
class CloudFoundryWebFluxEndpointHandlerMappingTests {
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
new CloudFoundryWebFluxEndpointHandlerMappingRuntimeHints().registerHints(runtimeHints,
|
||||
getClass().getClassLoader());
|
||||
Assertions.assertThat(RuntimeHintsPredicates.reflection().onMethod(CloudFoundryLinksHandler.class, "links"))
|
||||
.accepts(runtimeHints);
|
||||
Assertions.assertThat(RuntimeHintsPredicates.reflection().onType(Link.class)).accepts(runtimeHints);
|
@ -27,18 +27,17 @@ import org.springframework.boot.actuate.endpoint.web.Link;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link CloudFoundryWebEndpointServletHandlerMappingRuntimeHints}.
|
||||
* Tests for {@link CloudFoundryWebEndpointServletHandlerMapping}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class CloudFoundryWebEndpointServletHandlerMappingRuntimeHintsTests {
|
||||
|
||||
private final CloudFoundryWebEndpointServletHandlerMappingRuntimeHints sut = new CloudFoundryWebEndpointServletHandlerMappingRuntimeHints();
|
||||
class CloudFoundryWebEndpointServletHandlerMappingTests {
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
new CloudFoundryWebEndpointServletHandlerMappingRuntimeHints().registerHints(runtimeHints,
|
||||
getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(CloudFoundryLinksHandler.class, "links"))
|
||||
.accepts(runtimeHints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(Link.class)).accepts(runtimeHints);
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.aot;
|
||||
package org.springframework.boot.actuate.autoconfigure.endpoint;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@ -34,20 +34,20 @@ import org.springframework.core.annotation.SynthesizedAnnotation;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ActuatorAnnotationsRuntimeHintsRegistrar}.
|
||||
* Tests for {@link ActuatorAnnotationsRuntimeHints}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class ActuatorAnnotationsRuntimeHintsRegistrarTests {
|
||||
class ActuatorAnnotationsRuntimeHintsTests {
|
||||
|
||||
private final ActuatorAnnotationsRuntimeHintsRegistrar sut = new ActuatorAnnotationsRuntimeHintsRegistrar();
|
||||
private final ActuatorAnnotationsRuntimeHints registrar = new ActuatorAnnotationsRuntimeHints();
|
||||
|
||||
private RuntimeHints runtimeHints;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
this.runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(this.runtimeHints, getClass().getClassLoader());
|
||||
this.registrar.registerHints(this.runtimeHints, getClass().getClassLoader());
|
||||
}
|
||||
|
||||
@Test
|
@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Support classes for actuator in AOT mode.
|
||||
*/
|
||||
package org.springframework.boot.actuate.aot;
|
@ -16,52 +16,43 @@
|
||||
|
||||
package org.springframework.boot.actuate.endpoint.annotation;
|
||||
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import org.springframework.aot.hint.ExecutableMode;
|
||||
import org.springframework.aot.hint.ReflectionHints;
|
||||
import org.springframework.aot.hint.annotation.ReflectiveProcessor;
|
||||
import org.springframework.aot.hint.annotation.SimpleReflectiveProcessor;
|
||||
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
|
||||
import org.springframework.context.aot.BindingReflectionHintsRegistrar;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* Processor which registers the annotated operation method and its return type for
|
||||
* reflection.
|
||||
* {@link ReflectiveProcessor} that registers the annotated operation method and its
|
||||
* return type for reflection.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class OperationReflectiveProcessor implements ReflectiveProcessor {
|
||||
class OperationReflectiveProcessor extends SimpleReflectiveProcessor {
|
||||
|
||||
private final BindingReflectionHintsRegistrar bindingRegistrar = new BindingReflectionHintsRegistrar();
|
||||
|
||||
@Override
|
||||
public void registerReflectionHints(ReflectionHints hints, AnnotatedElement element) {
|
||||
if (!(element instanceof Method method)) {
|
||||
throw new IllegalArgumentException("This processor can only be invoked for annotated methods");
|
||||
protected void registerMethodHint(ReflectionHints hints, Method method) {
|
||||
super.registerMethodHint(hints, method);
|
||||
Type returnType = extractReturnType(method);
|
||||
if (returnType != null) {
|
||||
registerReflectionHints(hints, returnType);
|
||||
}
|
||||
hints.registerMethod(method, (hint) -> hint.setModes(ExecutableMode.INVOKE));
|
||||
registerReturnValueHints(hints, method);
|
||||
}
|
||||
|
||||
private void registerReturnValueHints(ReflectionHints hints, Method method) {
|
||||
private Type extractReturnType(Method method) {
|
||||
ResolvableType returnType = ResolvableType.forMethodReturnType(method);
|
||||
if (WebEndpointResponse.class.isAssignableFrom(method.getReturnType())) {
|
||||
registerWebEndpointResponse(hints, returnType);
|
||||
}
|
||||
else {
|
||||
registerReflectionHints(hints, returnType.getType());
|
||||
}
|
||||
}
|
||||
|
||||
private void registerWebEndpointResponse(ReflectionHints hints, ResolvableType returnType) {
|
||||
ResolvableType genericParameter = returnType.getGeneric(0);
|
||||
if (genericParameter.getRawClass() != null) {
|
||||
registerReflectionHints(hints, genericParameter.getType());
|
||||
return returnType.as(WebEndpointResponse.class).getGeneric(0).getType();
|
||||
}
|
||||
return returnType.getType();
|
||||
}
|
||||
|
||||
private void registerReflectionHints(ReflectionHints hints, Type type) {
|
||||
|
@ -22,8 +22,8 @@ import java.security.Principal;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
@ -31,10 +31,8 @@ import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import org.springframework.aot.hint.ExecutableMode;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
import org.springframework.aot.hint.TypeReference;
|
||||
import org.springframework.boot.actuate.endpoint.InvalidEndpointRequestException;
|
||||
import org.springframework.boot.actuate.endpoint.InvocationContext;
|
||||
import org.springframework.boot.actuate.endpoint.OperationArgumentResolver;
|
||||
@ -496,13 +494,11 @@ public abstract class AbstractWebFluxEndpointHandlerMapping extends RequestMappi
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||
hints.reflection().registerType(WriteOperationHandler.class,
|
||||
(hint) -> hint.withMethod("handle",
|
||||
List.of(TypeReference.of(ServerWebExchange.class), TypeReference.of(Map.class)),
|
||||
(method) -> method.withMode(ExecutableMode.INVOKE)));
|
||||
hints.reflection().registerType(ReadOperationHandler.class,
|
||||
(hint) -> hint.withMethod("handle", List.of(TypeReference.of(ServerWebExchange.class)),
|
||||
(method) -> method.withMode(ExecutableMode.INVOKE)));
|
||||
hints.reflection()
|
||||
.registerMethod(Objects.requireNonNull(ReflectionUtils.findMethod(WriteOperationHandler.class,
|
||||
"handle", ServerWebExchange.class, Map.class)))
|
||||
.registerMethod(Objects.requireNonNull(
|
||||
ReflectionUtils.findMethod(ReadOperationHandler.class, "handle", ServerWebExchange.class)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,13 +18,11 @@ package org.springframework.boot.actuate.endpoint.web.reactive;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.springframework.aot.hint.ExecutableMode;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
import org.springframework.aot.hint.TypeReference;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver;
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
|
||||
@ -34,6 +32,7 @@ import org.springframework.boot.actuate.endpoint.web.Link;
|
||||
import org.springframework.boot.actuate.endpoint.web.reactive.WebFluxEndpointHandlerMapping.WebFluxEndpointHandlerMappingRuntimeHints;
|
||||
import org.springframework.context.annotation.ImportRuntimeHints;
|
||||
import org.springframework.context.aot.BindingReflectionHintsRegistrar;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.reactive.HandlerMapping;
|
||||
@ -104,10 +103,8 @@ public class WebFluxEndpointHandlerMapping extends AbstractWebFluxEndpointHandle
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||
hints.reflection().registerType(WebFluxLinksHandler.class,
|
||||
(hint) -> hint.onReachableType(TypeReference.of(WebFluxLinksHandler.class)).withMethod("links",
|
||||
List.of(TypeReference.of(ServerWebExchange.class)),
|
||||
(method) -> method.setModes(ExecutableMode.INVOKE)));
|
||||
hints.reflection().registerMethod(Objects.requireNonNull(
|
||||
ReflectionUtils.findMethod(WebFluxLinksHandler.class, "links", ServerWebExchange.class)));
|
||||
this.bindingRegistrar.registerReflectionHints(hints.reflection(), Link.class);
|
||||
}
|
||||
|
||||
|
@ -26,16 +26,15 @@ import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.aot.hint.ExecutableMode;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
import org.springframework.aot.hint.TypeReference;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.boot.actuate.endpoint.InvalidEndpointRequestException;
|
||||
import org.springframework.boot.actuate.endpoint.InvocationContext;
|
||||
@ -487,10 +486,8 @@ public abstract class AbstractWebMvcEndpointHandlerMapping extends RequestMappin
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||
hints.reflection().registerType(OperationHandler.class,
|
||||
(hint) -> hint.withMethod("handle",
|
||||
List.of(TypeReference.of(HttpServletRequest.class), TypeReference.of(Map.class)),
|
||||
(method) -> method.withMode(ExecutableMode.INVOKE)));
|
||||
hints.reflection().registerMethod(Objects.requireNonNull(
|
||||
ReflectionUtils.findMethod(OperationHandler.class, "handle", HttpServletRequest.class, Map.class)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,16 +18,14 @@ package org.springframework.boot.actuate.endpoint.web.servlet;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.aot.hint.ExecutableMode;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
import org.springframework.aot.hint.TypeReference;
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver;
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes;
|
||||
@ -36,6 +34,7 @@ import org.springframework.boot.actuate.endpoint.web.Link;
|
||||
import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping.WebMvcEndpointHandlerMappingRuntimeHints;
|
||||
import org.springframework.context.annotation.ImportRuntimeHints;
|
||||
import org.springframework.context.aot.BindingReflectionHintsRegistrar;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
@ -101,11 +100,9 @@ public class WebMvcEndpointHandlerMapping extends AbstractWebMvcEndpointHandlerM
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||
hints.reflection().registerType(WebMvcLinksHandler.class,
|
||||
(hint) -> hint.onReachableType(TypeReference.of(WebMvcLinksHandler.class)).withMethod("links",
|
||||
List.of(TypeReference.of(HttpServletRequest.class),
|
||||
TypeReference.of(HttpServletResponse.class)),
|
||||
(method) -> method.setModes(ExecutableMode.INVOKE)));
|
||||
hints.reflection()
|
||||
.registerMethod(Objects.requireNonNull(ReflectionUtils.findMethod(WebMvcLinksHandler.class, "links",
|
||||
HttpServletRequest.class, HttpServletResponse.class)));
|
||||
this.bindingRegistrar.registerReflectionHints(hints.reflection(), Link.class);
|
||||
}
|
||||
|
||||
|
@ -17,17 +17,15 @@
|
||||
package org.springframework.boot.actuate.metrics.cache;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.hazelcast.spring.cache.HazelcastCache;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
import io.micrometer.core.instrument.binder.MeterBinder;
|
||||
import io.micrometer.core.instrument.binder.cache.HazelcastCacheMetrics;
|
||||
|
||||
import org.springframework.aot.hint.ExecutableMode;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
import org.springframework.aot.hint.TypeReference;
|
||||
import org.springframework.boot.actuate.metrics.cache.HazelcastCacheMeterBinderProvider.HazelcastCacheMeterBinderProviderRuntimeHints;
|
||||
import org.springframework.context.annotation.ImportRuntimeHints;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
@ -68,12 +66,16 @@ public class HazelcastCacheMeterBinderProvider implements CacheMeterBinderProvid
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||
hints.reflection().registerType(HazelcastCache.class, (hint) -> hint.withMethod("getNativeCache", List.of(),
|
||||
(method) -> method.withMode(ExecutableMode.INVOKE)));
|
||||
hints.reflection().registerType(HazelcastCacheMetrics.class,
|
||||
(hint) -> hint.withConstructor(
|
||||
List.of(TypeReference.of(Object.class), TypeReference.of(Iterable.class)),
|
||||
(ctor) -> ctor.withMode(ExecutableMode.INVOKE)));
|
||||
try {
|
||||
hints.reflection()
|
||||
.registerMethod(Objects
|
||||
.requireNonNull(ReflectionUtils.findMethod(HazelcastCache.class, "getNativeCache")))
|
||||
.registerConstructor(HazelcastCacheMetrics.class.getConstructor(Object.class, Iterable.class));
|
||||
}
|
||||
catch (NoSuchMethodException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,8 +17,9 @@
|
||||
package org.springframework.boot.actuate.endpoint.annotation;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
@ -34,17 +35,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* Tests for {@link OperationReflectiveProcessor}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class OperationReflectiveProcessorTests {
|
||||
|
||||
private final OperationReflectiveProcessor sut = new OperationReflectiveProcessor();
|
||||
private final OperationReflectiveProcessor processor = new OperationReflectiveProcessor();
|
||||
|
||||
private RuntimeHints runtimeHints;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
this.runtimeHints = new RuntimeHints();
|
||||
}
|
||||
private final RuntimeHints runtimeHints = new RuntimeHints();
|
||||
|
||||
@Test
|
||||
void shouldRegisterMethodAsInvokable() {
|
||||
@ -57,24 +54,21 @@ class OperationReflectiveProcessorTests {
|
||||
void shouldRegisterReturnType() {
|
||||
Method method = ReflectionUtils.findMethod(Methods.class, "dto");
|
||||
runProcessor(method);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(Dto.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(this.runtimeHints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(NestedDto.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(this.runtimeHints);
|
||||
assertHintsForDto();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRegisterMapValueFromReturnType() {
|
||||
Method method = ReflectionUtils.findMethod(Methods.class, "dtos");
|
||||
runProcessor(method);
|
||||
assertHintsForDto();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRegisterWebEndpointResponseReturnType() {
|
||||
Method method = ReflectionUtils.findMethod(Methods.class, "webEndpointResponse");
|
||||
runProcessor(method);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(Dto.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(this.runtimeHints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(NestedDto.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(this.runtimeHints);
|
||||
assertHintsForDto();
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(WebEndpointResponse.class)).rejects(this.runtimeHints);
|
||||
}
|
||||
|
||||
@ -85,16 +79,30 @@ class OperationReflectiveProcessorTests {
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(Resource.class)).rejects(this.runtimeHints);
|
||||
}
|
||||
|
||||
private void runProcessor(Method method) {
|
||||
this.sut.registerReflectionHints(this.runtimeHints.reflection(), method);
|
||||
private void assertHintsForDto() {
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(Dto.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(this.runtimeHints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(NestedDto.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(this.runtimeHints);
|
||||
}
|
||||
|
||||
private void runProcessor(Method method) {
|
||||
this.processor.registerReflectionHints(this.runtimeHints.reflection(), method);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class Methods {
|
||||
|
||||
private String string() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map<String, List<Dto>> dtos() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Dto dto() {
|
||||
return null;
|
||||
}
|
||||
@ -109,6 +117,7 @@ class OperationReflectiveProcessorTests {
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static class Dto {
|
||||
|
||||
private final NestedDto nestedDto = new NestedDto();
|
||||
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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.jmx.annotation;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.endpoint.jmx.annotation.JmxEndpointDiscoverer.JmxEndpointDiscovererRuntimeHints;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link JmxEndpointDiscovererRuntimeHints}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class JmxEndpointDiscovererRuntimeHintsTests {
|
||||
|
||||
private final JmxEndpointDiscovererRuntimeHints sut = new JmxEndpointDiscovererRuntimeHints();
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(JmxEndpointFilter.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(runtimeHints);
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2022 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.
|
||||
@ -26,6 +26,9 @@ import java.util.function.Function;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.endpoint.EndpointId;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
@ -37,6 +40,7 @@ import org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationI
|
||||
import org.springframework.boot.actuate.endpoint.jmx.ExposableJmxEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.jmx.JmxOperation;
|
||||
import org.springframework.boot.actuate.endpoint.jmx.JmxOperationParameter;
|
||||
import org.springframework.boot.actuate.endpoint.jmx.annotation.JmxEndpointDiscoverer.JmxEndpointDiscovererRuntimeHints;
|
||||
import org.springframework.boot.actuate.endpoint.web.annotation.WebEndpoint;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@ -55,6 +59,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Phillip Webb
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class JmxEndpointDiscovererTests {
|
||||
|
||||
@ -201,6 +206,14 @@ class JmxEndpointDiscovererTests {
|
||||
"Endpoint bean 'nonJmxEndpoint' cannot support the extension bean 'nonJmxJmxEndpointExtension'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
new JmxEndpointDiscovererRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(JmxEndpointFilter.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(runtimeHints);
|
||||
}
|
||||
|
||||
private Object getInvoker(JmxOperation operation) {
|
||||
return ReflectionTestUtils.getField(operation, "invoker");
|
||||
}
|
||||
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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.annotation;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpointDiscoverer.ControllerEndpointDiscovererRuntimeHints;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ControllerEndpointDiscovererRuntimeHints}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class ControllerEndpointDiscovererRuntimeHintsTests {
|
||||
|
||||
private final ControllerEndpointDiscovererRuntimeHints sut = new ControllerEndpointDiscovererRuntimeHints();
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(ControllerEndpointFilter.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(runtimeHints);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2022 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.
|
||||
@ -24,10 +24,14 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.endpoint.EndpointId;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.DiscoveredEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
||||
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpointDiscoverer.ControllerEndpointDiscovererRuntimeHints;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
|
||||
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
||||
@ -45,6 +49,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class ControllerEndpointDiscovererTests {
|
||||
|
||||
@ -126,6 +131,15 @@ class ControllerEndpointDiscovererTests {
|
||||
.withMessageContaining("ControllerEndpoints must not declare operations")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
new ControllerEndpointDiscovererRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(ControllerEndpointFilter.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(runtimeHints);
|
||||
|
||||
}
|
||||
|
||||
private ContextConsumer<AssertableApplicationContext> assertDiscoverer(
|
||||
Consumer<ControllerEndpointDiscoverer> consumer) {
|
||||
return (context) -> {
|
||||
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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.annotation;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointDiscoverer.ServletEndpointDiscovererRuntimeHints;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ServletEndpointDiscovererRuntimeHints}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class ServletEndpointDiscovererRuntimeHintsTests {
|
||||
|
||||
private final ServletEndpointDiscovererRuntimeHints sut = new ServletEndpointDiscovererRuntimeHints();
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(ServletEndpointFilter.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(runtimeHints);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -30,12 +30,16 @@ import jakarta.servlet.ServletRequest;
|
||||
import jakarta.servlet.ServletResponse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.endpoint.EndpointId;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.DiscoveredEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointServlet;
|
||||
import org.springframework.boot.actuate.endpoint.web.ExposableServletEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointDiscoverer.ServletEndpointDiscovererRuntimeHints;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
|
||||
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
||||
@ -53,6 +57,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class ServletEndpointDiscovererTests {
|
||||
|
||||
@ -129,6 +134,14 @@ class ServletEndpointDiscovererTests {
|
||||
.isThrownBy(discoverer::getEndpoints).withMessageContaining("must not supply null")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
new ServletEndpointDiscovererRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(ServletEndpointFilter.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(runtimeHints);
|
||||
}
|
||||
|
||||
private ContextConsumer<AssertableApplicationContext> assertDiscoverer(
|
||||
Consumer<ServletEndpointDiscoverer> consumer) {
|
||||
return (context) -> {
|
||||
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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.annotation;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.endpoint.web.annotation.WebEndpointDiscoverer.WebEndpointDiscovererRuntimeHints;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link WebEndpointDiscovererRuntimeHints}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class WebEndpointDiscovererRuntimeHintsTests {
|
||||
|
||||
private final WebEndpointDiscovererRuntimeHints sut = new WebEndpointDiscovererRuntimeHints();
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(WebEndpointFilter.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(runtimeHints);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2022 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.
|
||||
@ -31,6 +31,9 @@ import java.util.stream.Stream;
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.endpoint.EndpointId;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.DeleteOperation;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
@ -47,6 +50,7 @@ import org.springframework.boot.actuate.endpoint.web.PathMapper;
|
||||
import org.springframework.boot.actuate.endpoint.web.WebEndpointHttpMethod;
|
||||
import org.springframework.boot.actuate.endpoint.web.WebOperation;
|
||||
import org.springframework.boot.actuate.endpoint.web.WebOperationRequestPredicate;
|
||||
import org.springframework.boot.actuate.endpoint.web.annotation.WebEndpointDiscoverer.WebEndpointDiscovererRuntimeHints;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@ -65,6 +69,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
* @author Andy Wilkinson
|
||||
* @author Stephane Nicoll
|
||||
* @author Phillip Webb
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class WebEndpointDiscovererTests {
|
||||
|
||||
@ -216,6 +221,15 @@ class WebEndpointDiscovererTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
new WebEndpointDiscovererRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(WebEndpointFilter.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(runtimeHints);
|
||||
|
||||
}
|
||||
|
||||
private void load(Class<?> configuration, Consumer<WebEndpointDiscoverer> consumer) {
|
||||
load((id) -> null, EndpointId::toString, configuration, consumer);
|
||||
}
|
||||
|
@ -26,18 +26,17 @@ import org.springframework.boot.actuate.endpoint.web.reactive.AbstractWebFluxEnd
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link AbstractWebFluxEndpointHandlerMappingRuntimeHints}.
|
||||
* Tests for {@link AbstractWebFluxEndpointHandlerMapping}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class AbstractWebFluxEndpointHandlerMappingRuntimeHintsTests {
|
||||
|
||||
private final AbstractWebFluxEndpointHandlerMappingRuntimeHints sut = new AbstractWebFluxEndpointHandlerMappingRuntimeHints();
|
||||
class AbstractWebFluxEndpointHandlerMappingTests {
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
new AbstractWebFluxEndpointHandlerMappingRuntimeHints().registerHints(runtimeHints,
|
||||
getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(TypeReference.of(
|
||||
"org.springframework.boot.actuate.endpoint.web.reactive.AbstractWebFluxEndpointHandlerMapping.WriteOperationHandler")))
|
||||
.accepts(runtimeHints);
|
@ -27,18 +27,16 @@ import org.springframework.boot.actuate.endpoint.web.reactive.WebFluxEndpointHan
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link WebFluxEndpointHandlerMappingRuntimeHints}.
|
||||
* Tests for {@link WebFluxEndpointHandlerMapping}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class WebFluxEndpointHandlerMappingRuntimeHintsTests {
|
||||
|
||||
private final WebFluxEndpointHandlerMappingRuntimeHints sut = new WebFluxEndpointHandlerMappingRuntimeHints();
|
||||
class WebFluxEndpointHandlerMappingTests {
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
new WebFluxEndpointHandlerMappingRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(WebFluxLinksHandler.class, "links"))
|
||||
.accepts(runtimeHints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(Link.class)).accepts(runtimeHints);
|
@ -26,18 +26,16 @@ import org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpo
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link AbstractWebMvcEndpointHandlerMappingRuntimeHints}.
|
||||
* Tests for {@link AbstractWebMvcEndpointHandlerMapping}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class AbstractWebMvcEndpointHandlerMappingRuntimeHintsTests {
|
||||
|
||||
private final AbstractWebMvcEndpointHandlerMappingRuntimeHints sut = new AbstractWebMvcEndpointHandlerMappingRuntimeHints();
|
||||
class AbstractWebMvcEndpointHandlerMappingTests {
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
new AbstractWebMvcEndpointHandlerMappingRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(TypeReference.of(
|
||||
"org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping.OperationHandler")))
|
||||
.accepts(runtimeHints);
|
@ -27,18 +27,16 @@ import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandl
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link WebMvcEndpointHandlerMappingRuntimeHints}.
|
||||
* Tests for {@link WebMvcEndpointHandlerMapping}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class WebMvcEndpointHandlerMappingRuntimeHintsTests {
|
||||
|
||||
private final WebMvcEndpointHandlerMappingRuntimeHints sut = new WebMvcEndpointHandlerMappingRuntimeHints();
|
||||
class WebMvcEndpointHandlerMappingTests {
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
new WebMvcEndpointHandlerMappingRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(WebMvcLinksHandler.class, "links"))
|
||||
.accepts(runtimeHints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(Link.class)).accepts(runtimeHints);
|
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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 java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.health.HealthEndpointWebExtension.HealthEndpointWebExtensionRuntimeHints;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link HealthEndpointWebExtensionRuntimeHints}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class HealthEndpointWebExtensionRuntimeHintsTests {
|
||||
|
||||
private final HealthEndpointWebExtensionRuntimeHints sut = new HealthEndpointWebExtensionRuntimeHints();
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
Set<Class<?>> bindingTypes = Set.of(Health.class, SystemHealth.class, CompositeHealth.class);
|
||||
for (Class<?> bindingType : bindingTypes) {
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(bindingType)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(runtimeHints);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -19,14 +19,19 @@ package org.springframework.boot.actuate.health;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
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 org.springframework.boot.actuate.health.HealthEndpointWebExtension.HealthEndpointWebExtensionRuntimeHints;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@ -36,6 +41,7 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Scott Frederick
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class HealthEndpointWebExtensionTests extends
|
||||
HealthEndpointSupportTests<HealthEndpointWebExtension, HealthContributorRegistry, HealthContributor, HealthComponent> {
|
||||
@ -81,6 +87,18 @@ class HealthEndpointWebExtensionTests extends
|
||||
assertThat(response.getStatus()).isEqualTo(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
new HealthEndpointWebExtensionRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
Set<Class<?>> bindingTypes = Set.of(Health.class, SystemHealth.class, CompositeHealth.class);
|
||||
for (Class<?> bindingType : bindingTypes) {
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(bindingType)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(runtimeHints);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HealthEndpointWebExtension create(HealthContributorRegistry registry, HealthEndpointGroups groups,
|
||||
Duration slowIndicatorLoggingThreshold) {
|
||||
|
@ -27,18 +27,16 @@ import org.springframework.boot.info.BuildProperties;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link BuildInfoContributorRuntimeHints}.
|
||||
* Tests for {@link BuildInfoContributor}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class BuildInfoContributorRuntimeHintsTests {
|
||||
|
||||
private final BuildInfoContributorRuntimeHints sut = new BuildInfoContributorRuntimeHints();
|
||||
class BuildInfoContributorTests {
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
new BuildInfoContributorRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(BuildProperties.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(runtimeHints);
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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.info;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.info.GitInfoContributor.GitInfoContributorRuntimeHints;
|
||||
import org.springframework.boot.info.GitProperties;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests forr {@link GitInfoContributorRuntimeHints}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class GitInfoContributorRuntimeHintsTests {
|
||||
|
||||
private final GitInfoContributorRuntimeHints sut = new GitInfoContributorRuntimeHints();
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(GitProperties.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(runtimeHints);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2022 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.
|
||||
@ -22,6 +22,10 @@ import java.util.Properties;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.info.GitInfoContributor.GitInfoContributorRuntimeHints;
|
||||
import org.springframework.boot.actuate.info.InfoPropertiesInfoContributor.Mode;
|
||||
import org.springframework.boot.info.GitProperties;
|
||||
|
||||
@ -31,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* Tests for {@link GitInfoContributor}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class GitInfoContributorTests {
|
||||
|
||||
@ -79,4 +84,14 @@ class GitInfoContributorTests {
|
||||
assertThat(id.get("abbrev")).isEqualTo("1b3cec3");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
new GitInfoContributorRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(GitProperties.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(runtimeHints);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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.info;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.info.JavaInfoContributor.JavaInfoContributorRuntimeHints;
|
||||
import org.springframework.boot.info.JavaInfo;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link JavaInfoContributorRuntimeHints}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class JavaInfoContributorRuntimeHintsTests {
|
||||
|
||||
private final JavaInfoContributorRuntimeHints sut = new JavaInfoContributorRuntimeHints();
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(JavaInfo.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(runtimeHints);
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 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.
|
||||
@ -18,6 +18,10 @@ package org.springframework.boot.actuate.info;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.info.JavaInfoContributor.JavaInfoContributorRuntimeHints;
|
||||
import org.springframework.boot.info.JavaInfo;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ -26,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* Tests for {@link JavaInfoContributor}
|
||||
*
|
||||
* @author Jonatan Ivanov
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class JavaInfoContributorTests {
|
||||
|
||||
@ -38,4 +43,13 @@ class JavaInfoContributorTests {
|
||||
assertThat(info.getDetails().get("java")).isInstanceOf(JavaInfo.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
new JavaInfoContributorRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(JavaInfo.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(runtimeHints);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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.info;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.info.OsInfoContributor.OsInfoContributorRuntimeHints;
|
||||
import org.springframework.boot.info.OsInfo;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link OsInfoContributorRuntimeHints}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class OsInfoContributorRuntimeHintsTests {
|
||||
|
||||
private final OsInfoContributorRuntimeHints sut = new OsInfoContributorRuntimeHints();
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(OsInfo.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(runtimeHints);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -18,6 +18,10 @@ package org.springframework.boot.actuate.info;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.info.OsInfoContributor.OsInfoContributorRuntimeHints;
|
||||
import org.springframework.boot.info.OsInfo;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ -26,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* Tests for {@link OsInfoContributor}
|
||||
*
|
||||
* @author Jonatan Ivanov
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class OsInfoContributorTests {
|
||||
|
||||
@ -38,4 +43,13 @@ class OsInfoContributorTests {
|
||||
assertThat(info.getDetails().get("os")).isInstanceOf(OsInfo.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
new OsInfoContributorRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(OsInfo.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(runtimeHints);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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.integration;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.integration.IntegrationGraphEndpoint.IntegrationGraphEndpointRuntimeHints;
|
||||
import org.springframework.integration.graph.CompositeMessageHandlerNode;
|
||||
import org.springframework.integration.graph.DiscardingMessageHandlerNode;
|
||||
import org.springframework.integration.graph.EndpointNode;
|
||||
import org.springframework.integration.graph.ErrorCapableCompositeMessageHandlerNode;
|
||||
import org.springframework.integration.graph.ErrorCapableDiscardingMessageHandlerNode;
|
||||
import org.springframework.integration.graph.ErrorCapableEndpointNode;
|
||||
import org.springframework.integration.graph.ErrorCapableMessageHandlerNode;
|
||||
import org.springframework.integration.graph.ErrorCapableRoutingNode;
|
||||
import org.springframework.integration.graph.Graph;
|
||||
import org.springframework.integration.graph.MessageChannelNode;
|
||||
import org.springframework.integration.graph.MessageGatewayNode;
|
||||
import org.springframework.integration.graph.MessageHandlerNode;
|
||||
import org.springframework.integration.graph.MessageProducerNode;
|
||||
import org.springframework.integration.graph.MessageSourceNode;
|
||||
import org.springframework.integration.graph.PollableChannelNode;
|
||||
import org.springframework.integration.graph.RoutingMessageHandlerNode;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link IntegrationGraphEndpointRuntimeHints}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class IntegrationGraphEndpointRuntimeHintsTests {
|
||||
|
||||
private final IntegrationGraphEndpointRuntimeHints sut = new IntegrationGraphEndpointRuntimeHints();
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
Set<Class<?>> bindingTypes = Set.of(Graph.class, EndpointNode.class, CompositeMessageHandlerNode.class,
|
||||
DiscardingMessageHandlerNode.class, ErrorCapableCompositeMessageHandlerNode.class,
|
||||
ErrorCapableDiscardingMessageHandlerNode.class, ErrorCapableEndpointNode.class,
|
||||
ErrorCapableMessageHandlerNode.class, ErrorCapableRoutingNode.class, MessageGatewayNode.class,
|
||||
MessageProducerNode.class, PollableChannelNode.class, MessageChannelNode.class,
|
||||
MessageHandlerNode.class, MessageSourceNode.class, RoutingMessageHandlerNode.class);
|
||||
for (Class<?> bindingType : bindingTypes) {
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(bindingType)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(runtimeHints);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -16,10 +16,31 @@
|
||||
|
||||
package org.springframework.boot.actuate.integration;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.integration.IntegrationGraphEndpoint.IntegrationGraphEndpointRuntimeHints;
|
||||
import org.springframework.integration.graph.CompositeMessageHandlerNode;
|
||||
import org.springframework.integration.graph.DiscardingMessageHandlerNode;
|
||||
import org.springframework.integration.graph.EndpointNode;
|
||||
import org.springframework.integration.graph.ErrorCapableCompositeMessageHandlerNode;
|
||||
import org.springframework.integration.graph.ErrorCapableDiscardingMessageHandlerNode;
|
||||
import org.springframework.integration.graph.ErrorCapableEndpointNode;
|
||||
import org.springframework.integration.graph.ErrorCapableMessageHandlerNode;
|
||||
import org.springframework.integration.graph.ErrorCapableRoutingNode;
|
||||
import org.springframework.integration.graph.Graph;
|
||||
import org.springframework.integration.graph.IntegrationGraphServer;
|
||||
import org.springframework.integration.graph.MessageChannelNode;
|
||||
import org.springframework.integration.graph.MessageGatewayNode;
|
||||
import org.springframework.integration.graph.MessageHandlerNode;
|
||||
import org.springframework.integration.graph.MessageProducerNode;
|
||||
import org.springframework.integration.graph.MessageSourceNode;
|
||||
import org.springframework.integration.graph.PollableChannelNode;
|
||||
import org.springframework.integration.graph.RoutingMessageHandlerNode;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@ -30,6 +51,7 @@ import static org.mockito.Mockito.mock;
|
||||
* Tests for {@link IntegrationGraphEndpoint}.
|
||||
*
|
||||
* @author Tim Ysewyn
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class IntegrationGraphEndpointTests {
|
||||
|
||||
@ -52,4 +74,21 @@ class IntegrationGraphEndpointTests {
|
||||
then(this.server).should().rebuild();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
new IntegrationGraphEndpointRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
Set<Class<?>> bindingTypes = Set.of(Graph.class, EndpointNode.class, CompositeMessageHandlerNode.class,
|
||||
DiscardingMessageHandlerNode.class, ErrorCapableCompositeMessageHandlerNode.class,
|
||||
ErrorCapableDiscardingMessageHandlerNode.class, ErrorCapableEndpointNode.class,
|
||||
ErrorCapableMessageHandlerNode.class, ErrorCapableRoutingNode.class, MessageGatewayNode.class,
|
||||
MessageProducerNode.class, PollableChannelNode.class, MessageChannelNode.class,
|
||||
MessageHandlerNode.class, MessageSourceNode.class, RoutingMessageHandlerNode.class);
|
||||
for (Class<?> bindingType : bindingTypes) {
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(bindingType)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(runtimeHints);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,21 +34,21 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
class ThreadDumpEndpointWebExtensionTests {
|
||||
|
||||
private ThreadDumpEndpointWebExtension sut;
|
||||
private ThreadDumpEndpointWebExtension extension;
|
||||
|
||||
private ThreadDumpEndpoint delegateMock;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
this.delegateMock = Mockito.mock(ThreadDumpEndpoint.class);
|
||||
this.sut = new ThreadDumpEndpointWebExtension(this.delegateMock);
|
||||
this.extension = new ThreadDumpEndpointWebExtension(this.delegateMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldHandleThreadDumperUnavailable() {
|
||||
Mockito.when(this.delegateMock.threadDump())
|
||||
.thenThrow(new ThreadDumperUnavailableException("No thread dumper available"));
|
||||
WebEndpointResponse<ThreadDumpDescriptor> response = this.sut.threadDump();
|
||||
WebEndpointResponse<ThreadDumpDescriptor> response = this.extension.threadDump();
|
||||
assertThat(response.getStatus()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE.value());
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ class ThreadDumpEndpointWebExtensionTests {
|
||||
void shouldHandleThreadDumperUnavailableText() {
|
||||
Mockito.when(this.delegateMock.textThreadDump())
|
||||
.thenThrow(new ThreadDumperUnavailableException("No thread dumper available"));
|
||||
WebEndpointResponse<String> response = this.sut.textThreadDump();
|
||||
WebEndpointResponse<String> response = this.extension.textThreadDump();
|
||||
assertThat(response.getStatus()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE.value());
|
||||
}
|
||||
|
||||
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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.metrics.cache;
|
||||
|
||||
import com.hazelcast.spring.cache.HazelcastCache;
|
||||
import io.micrometer.core.instrument.binder.cache.HazelcastCacheMetrics;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.metrics.cache.HazelcastCacheMeterBinderProvider.HazelcastCacheMeterBinderProviderRuntimeHints;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link HazelcastCacheMeterBinderProviderRuntimeHints}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class HazelcastCacheMeterBinderProviderRuntimeHintsTests {
|
||||
|
||||
private final HazelcastCacheMeterBinderProviderRuntimeHints sut = new HazelcastCacheMeterBinderProviderRuntimeHints();
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(HazelcastCache.class, "getNativeCache"))
|
||||
.accepts(runtimeHints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(HazelcastCacheMetrics.class)).accepts(runtimeHints);
|
||||
}
|
||||
|
||||
}
|
@ -24,6 +24,10 @@ import io.micrometer.core.instrument.binder.MeterBinder;
|
||||
import io.micrometer.core.instrument.binder.cache.HazelcastCacheMetrics;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.metrics.cache.HazelcastCacheMeterBinderProvider.HazelcastCacheMeterBinderProviderRuntimeHints;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@ -32,6 +36,7 @@ import static org.mockito.Mockito.mock;
|
||||
* Tests for {@link HazelcastCacheMeterBinderProvider}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class HazelcastCacheMeterBinderProviderTests {
|
||||
|
||||
@ -46,4 +51,13 @@ class HazelcastCacheMeterBinderProviderTests {
|
||||
assertThat(meterBinder).isInstanceOf(HazelcastCacheMetrics.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
new HazelcastCacheMeterBinderProviderRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(HazelcastCache.class, "getNativeCache"))
|
||||
.accepts(runtimeHints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(HazelcastCacheMetrics.class)).accepts(runtimeHints);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,18 +32,16 @@ import org.springframework.boot.actuate.quartz.QuartzEndpointWebExtension.Quartz
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link QuartzEndpointWebExtensionRuntimeHints}.
|
||||
* Tests for {@link QuartzEndpointWebExtension}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class QuartzEndpointWebExtensionRuntimeHintsTests {
|
||||
|
||||
private final QuartzEndpointWebExtensionRuntimeHints sut = new QuartzEndpointWebExtensionRuntimeHints();
|
||||
class QuartzEndpointWebExtensionTests {
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
new QuartzEndpointWebExtensionRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
Set<Class<?>> bindingTypes = Set.of(QuartzGroups.class, QuartzJobDetails.class, QuartzJobGroupSummary.class,
|
||||
QuartzTriggerGroupSummary.class);
|
||||
for (Class<?> bindingType : bindingTypes) {
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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.scheduling;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint.CronTaskDescription;
|
||||
import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint.CustomTriggerTaskDescription;
|
||||
import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint.FixedDelayTaskDescription;
|
||||
import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint.FixedRateTaskDescription;
|
||||
import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint.ScheduledTasksEndpointRuntimeHints;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ScheduledTasksEndpointRuntimeHints}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class ScheduledTasksEndpointRuntimeHintsTests {
|
||||
|
||||
private final ScheduledTasksEndpointRuntimeHints sut = new ScheduledTasksEndpointRuntimeHints();
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
Set<Class<?>> bindingTypes = Set.of(FixedRateTaskDescription.class, FixedDelayTaskDescription.class,
|
||||
CronTaskDescription.class, CustomTriggerTaskDescription.class);
|
||||
for (Class<?> bindingType : bindingTypes) {
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(bindingType)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(runtimeHints);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -19,14 +19,19 @@ package org.springframework.boot.actuate.scheduling;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint.CronTaskDescription;
|
||||
import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint.CustomTriggerTaskDescription;
|
||||
import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint.FixedDelayTaskDescription;
|
||||
import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint.FixedRateTaskDescription;
|
||||
import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint.ScheduledTasksEndpointRuntimeHints;
|
||||
import org.springframework.boot.actuate.scheduling.ScheduledTasksEndpoint.ScheduledTasksReport;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@ -46,6 +51,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* Tests for {@link ScheduledTasksEndpoint}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class ScheduledTasksEndpointTests {
|
||||
|
||||
@ -149,6 +155,19 @@ class ScheduledTasksEndpointTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
new ScheduledTasksEndpointRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
Set<Class<?>> bindingTypes = Set.of(FixedRateTaskDescription.class, FixedDelayTaskDescription.class,
|
||||
CronTaskDescription.class, CustomTriggerTaskDescription.class);
|
||||
for (Class<?> bindingType : bindingTypes) {
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(bindingType)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(runtimeHints);
|
||||
}
|
||||
}
|
||||
|
||||
private void run(Class<?> configuration, Consumer<ScheduledTasksReport> consumer) {
|
||||
this.contextRunner.withUserConfiguration(configuration)
|
||||
.run((context) -> consumer.accept(context.getBean(ScheduledTasksEndpoint.class).scheduledTasks()));
|
||||
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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.startup;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.TypeReference;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.actuate.startup.StartupEndpoint.StartupEndpointRuntimeHints;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link StartupEndpointRuntimeHints}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class StartupEndpointRuntimeHintsTests {
|
||||
|
||||
private final StartupEndpointRuntimeHints sut = new StartupEndpointRuntimeHints();
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
Set<TypeReference> bindingTypes = Set.of(
|
||||
TypeReference.of("org.springframework.boot.context.metrics.buffering.BufferedStartupStep$DefaultTag"),
|
||||
TypeReference.of("org.springframework.core.metrics.jfr.FlightRecorderStartupStep$FlightRecorderTag"));
|
||||
for (TypeReference bindingType : bindingTypes) {
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(bindingType)
|
||||
.withMemberCategories(MemberCategory.INVOKE_PUBLIC_METHODS)).accepts(runtimeHints);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 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.
|
||||
@ -16,11 +16,17 @@
|
||||
|
||||
package org.springframework.boot.actuate.startup;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.TypeReference;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.SpringBootVersion;
|
||||
import org.springframework.boot.actuate.startup.StartupEndpoint.StartupEndpointRuntimeHints;
|
||||
import org.springframework.boot.actuate.startup.StartupEndpoint.StartupResponse;
|
||||
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
@ -35,6 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @author Chris Bono
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class StartupEndpointTests {
|
||||
|
||||
@ -69,6 +76,19 @@ class StartupEndpointTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
new StartupEndpointRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
Set<TypeReference> bindingTypes = Set.of(
|
||||
TypeReference.of("org.springframework.boot.context.metrics.buffering.BufferedStartupStep$DefaultTag"),
|
||||
TypeReference.of("org.springframework.core.metrics.jfr.FlightRecorderStartupStep$FlightRecorderTag"));
|
||||
for (TypeReference bindingType : bindingTypes) {
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(bindingType)
|
||||
.withMemberCategories(MemberCategory.INVOKE_PUBLIC_METHODS)).accepts(runtimeHints);
|
||||
}
|
||||
}
|
||||
|
||||
private void testStartupEndpoint(ApplicationStartup applicationStartup, Consumer<StartupEndpoint> startupEndpoint) {
|
||||
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withInitializer((context) -> context.setApplicationStartup(applicationStartup))
|
||||
|
@ -26,18 +26,17 @@ import org.springframework.boot.actuate.web.mappings.reactive.DispatcherHandlers
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link DispatcherHandlersMappingDescriptionProviderRuntimeHints}.
|
||||
* Tests for {@link DispatcherHandlersMappingDescriptionProvider}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class DispatcherHandlersMappingDescriptionProviderRuntimeHintsTests {
|
||||
|
||||
private final DispatcherHandlersMappingDescriptionProviderRuntimeHints sut = new DispatcherHandlersMappingDescriptionProviderRuntimeHints();
|
||||
class DispatcherHandlersMappingDescriptionProviderTests {
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
new DispatcherHandlersMappingDescriptionProviderRuntimeHints().registerHints(runtimeHints,
|
||||
getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(DispatcherHandlerMappingDescription.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(runtimeHints);
|
@ -26,18 +26,17 @@ import org.springframework.boot.actuate.web.mappings.servlet.DispatcherServletsM
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link DispatcherServletsMappingDescriptionProviderRuntimeHints}.
|
||||
* Tests for {@link DispatcherServletsMappingDescriptionProvider}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class DispatcherServletsMappingDescriptionProviderRuntimeHintsTests {
|
||||
|
||||
private final DispatcherServletsMappingDescriptionProviderRuntimeHints sut = new DispatcherServletsMappingDescriptionProviderRuntimeHints();
|
||||
class DispatcherServletsMappingDescriptionProviderTests {
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
new DispatcherServletsMappingDescriptionProviderRuntimeHints().registerHints(runtimeHints,
|
||||
getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(DispatcherServletMappingDescription.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(runtimeHints);
|
@ -26,18 +26,16 @@ import org.springframework.boot.actuate.web.mappings.servlet.FiltersMappingDescr
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link FiltersMappingDescriptionProviderRuntimeHints}.
|
||||
* Tests for {@link FiltersMappingDescriptionProvider}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class FiltersMappingDescriptionProviderRuntimeHintsTests {
|
||||
|
||||
private final FiltersMappingDescriptionProviderRuntimeHints sut = new FiltersMappingDescriptionProviderRuntimeHints();
|
||||
class FiltersMappingDescriptionProviderTests {
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
new FiltersMappingDescriptionProviderRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(FilterRegistrationMappingDescription.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(runtimeHints);
|
@ -26,18 +26,16 @@ import org.springframework.boot.actuate.web.mappings.servlet.ServletsMappingDesc
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ServletsMappingDescriptionProviderRuntimeHints}.
|
||||
* Tests for {@link ServletsMappingDescriptionProvider}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class ServletsMappingDescriptionProviderRuntimeHintsTests {
|
||||
|
||||
private final ServletsMappingDescriptionProviderRuntimeHints sut = new ServletsMappingDescriptionProviderRuntimeHints();
|
||||
class ServletsMappingDescriptionProviderTests {
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
new ServletsMappingDescriptionProviderRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(ServletRegistrationMappingDescription.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
|
||||
.accepts(runtimeHints);
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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.info;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.info.BuildProperties.BuildPropertiesRuntimeHints;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link BuildPropertiesRuntimeHints}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class BuildPropertiesRuntimeHintsTests {
|
||||
|
||||
private final BuildPropertiesRuntimeHints sut = new BuildPropertiesRuntimeHints();
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.resource().forResource("META-INF/build-info.properties"))
|
||||
.accepts(runtimeHints);
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2022 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.
|
||||
@ -23,12 +23,16 @@ import java.util.Properties;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link BuildProperties}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class BuildPropertiesTests {
|
||||
|
||||
@ -53,6 +57,14 @@ class BuildPropertiesTests {
|
||||
assertThat(properties.getTime()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
new BuildProperties.BuildPropertiesRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.resource().forResource("META-INF/build-info.properties"))
|
||||
.accepts(runtimeHints);
|
||||
}
|
||||
|
||||
private static Properties createProperties(String group, String artifact, String version, String buildTime) {
|
||||
Properties properties = new Properties();
|
||||
properties.put("group", group);
|
||||
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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.info;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.boot.info.GitProperties.GitPropertiesRuntimeHints;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link GitPropertiesRuntimeHints}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class GitPropertiesRuntimeHintsTests {
|
||||
|
||||
private final GitPropertiesRuntimeHints sut = new GitPropertiesRuntimeHints();
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
this.sut.registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.resource().forResource("git.properties")).accepts(runtimeHints);
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2022 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.
|
||||
@ -20,12 +20,16 @@ import java.util.Properties;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link GitProperties}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class GitPropertiesTests {
|
||||
|
||||
@ -94,6 +98,13 @@ class GitPropertiesTests {
|
||||
assertThat(properties.getShortCommitId()).isEqualTo("abcdefg");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRegisterHints() {
|
||||
RuntimeHints runtimeHints = new RuntimeHints();
|
||||
new GitProperties.GitPropertiesRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
|
||||
assertThat(RuntimeHintsPredicates.resource().forResource("git.properties")).accepts(runtimeHints);
|
||||
}
|
||||
|
||||
private static Properties createProperties(String branch, String commitId, String commitIdAbbrev,
|
||||
String commitTime) {
|
||||
Properties properties = new Properties();
|
||||
|
Loading…
Reference in New Issue
Block a user