|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2023 the original author or authors. |
| 2 | + * Copyright 2012-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
36 | 36 | import org.junit.jupiter.api.extension.ParameterResolver;
|
37 | 37 | import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
|
38 | 38 | import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
|
| 39 | +import org.junit.platform.commons.util.AnnotationUtils; |
39 | 40 |
|
40 | 41 | import org.springframework.boot.actuate.endpoint.invoke.convert.ConversionServiceParameterValueMapper;
|
41 | 42 | import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver;
|
|
45 | 46 | import org.springframework.boot.actuate.endpoint.web.jersey.JerseyEndpointResourceFactory;
|
46 | 47 | import org.springframework.boot.actuate.endpoint.web.reactive.WebFluxEndpointHandlerMapping;
|
47 | 48 | import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping;
|
| 49 | +import org.springframework.boot.actuate.endpoint.web.test.WebEndpointTest.Infrastructure; |
48 | 50 | import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
49 | 51 | import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
|
50 | 52 | import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
@@ -91,32 +93,30 @@ public boolean supportsTestTemplate(ExtensionContext context) {
|
91 | 93 | @Override
|
92 | 94 | public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(
|
93 | 95 | ExtensionContext extensionContext) {
|
94 |
| - return Stream.of( |
95 |
| - new WebEndpointsInvocationContext("Jersey", |
96 |
| - WebEndpointTestInvocationContextProvider::createJerseyContext), |
97 |
| - new WebEndpointsInvocationContext("WebMvc", |
98 |
| - WebEndpointTestInvocationContextProvider::createWebMvcContext), |
99 |
| - new WebEndpointsInvocationContext("WebFlux", |
100 |
| - WebEndpointTestInvocationContextProvider::createWebFluxContext)); |
| 96 | + WebEndpointTest webEndpointTest = AnnotationUtils |
| 97 | + .findAnnotation(extensionContext.getRequiredTestMethod(), WebEndpointTest.class) |
| 98 | + .orElseThrow(() -> new IllegalStateException("Unable to find WebEndpointTest annotation on %s" |
| 99 | + .formatted(extensionContext.getRequiredTestMethod()))); |
| 100 | + return Stream.of(webEndpointTest.infrastructure()).distinct().map(Infrastructure::createInvocationContext); |
101 | 101 | }
|
102 | 102 |
|
103 |
| - private static ConfigurableApplicationContext createJerseyContext(List<Class<?>> classes) { |
| 103 | + static ConfigurableApplicationContext createJerseyContext(List<Class<?>> classes) { |
104 | 104 | AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext();
|
105 | 105 | classes.add(JerseyEndpointConfiguration.class);
|
106 | 106 | context.register(ClassUtils.toClassArray(classes));
|
107 | 107 | context.refresh();
|
108 | 108 | return context;
|
109 | 109 | }
|
110 | 110 |
|
111 |
| - private static ConfigurableApplicationContext createWebMvcContext(List<Class<?>> classes) { |
| 111 | + static ConfigurableApplicationContext createWebMvcContext(List<Class<?>> classes) { |
112 | 112 | AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext();
|
113 | 113 | classes.add(WebMvcEndpointConfiguration.class);
|
114 | 114 | context.register(ClassUtils.toClassArray(classes));
|
115 | 115 | context.refresh();
|
116 | 116 | return context;
|
117 | 117 | }
|
118 | 118 |
|
119 |
| - private static ConfigurableApplicationContext createWebFluxContext(List<Class<?>> classes) { |
| 119 | + static ConfigurableApplicationContext createWebFluxContext(List<Class<?>> classes) { |
120 | 120 | AnnotationConfigReactiveWebServerApplicationContext context = new AnnotationConfigReactiveWebServerApplicationContext();
|
121 | 121 | classes.add(WebFluxEndpointConfiguration.class);
|
122 | 122 | context.register(ClassUtils.toClassArray(classes));
|
|
0 commit comments