Merge pull request #39382 from snicoll

* pr/39382:
  Polish

Closes gh-39382
This commit is contained in:
Scott Frederick 2024-02-02 16:05:01 -06:00
commit 5f87949e30
15 changed files with 52 additions and 91 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,8 +18,8 @@ package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentatio
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -56,7 +56,7 @@ class AuditEventsEndpointDocumentationTests extends MockMvcEndpointDocumentation
void allAuditEvents() throws Exception { void allAuditEvents() throws Exception {
String queryTimestamp = "2017-11-07T09:37Z"; String queryTimestamp = "2017-11-07T09:37Z";
given(this.repository.find(any(), any(), any())) given(this.repository.find(any(), any(), any()))
.willReturn(Arrays.asList(new AuditEvent("alice", "logout", Collections.emptyMap()))); .willReturn(List.of(new AuditEvent("alice", "logout", Collections.emptyMap())));
this.mockMvc.perform(get("/actuator/auditevents").param("after", queryTimestamp)) this.mockMvc.perform(get("/actuator/auditevents").param("after", queryTimestamp))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andDo(document("auditevents/all", .andDo(document("auditevents/all",
@ -72,7 +72,7 @@ class AuditEventsEndpointDocumentationTests extends MockMvcEndpointDocumentation
OffsetDateTime now = OffsetDateTime.now(); OffsetDateTime now = OffsetDateTime.now();
String queryTimestamp = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(now); String queryTimestamp = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(now);
given(this.repository.find("alice", now.toInstant(), "logout")) given(this.repository.find("alice", now.toInstant(), "logout"))
.willReturn(Arrays.asList(new AuditEvent("alice", "logout", Collections.emptyMap()))); .willReturn(List.of(new AuditEvent("alice", "logout", Collections.emptyMap())));
this.mockMvc this.mockMvc
.perform(get("/actuator/auditevents").param("principal", "alice") .perform(get("/actuator/auditevents").param("principal", "alice")
.param("after", queryTimestamp) .param("after", queryTimestamp)

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,7 +16,6 @@
package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation; package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -50,7 +49,7 @@ class BeansEndpointDocumentationTests extends MockMvcEndpointDocumentationTests
@Test @Test
void beans() throws Exception { void beans() throws Exception {
List<FieldDescriptor> beanFields = Arrays.asList(fieldWithPath("aliases").description("Names of any aliases."), List<FieldDescriptor> beanFields = List.of(fieldWithPath("aliases").description("Names of any aliases."),
fieldWithPath("scope").description("Scope of the bean."), fieldWithPath("scope").description("Scope of the bean."),
fieldWithPath("type").description("Fully qualified type of the bean."), fieldWithPath("type").description("Fully qualified type of the bean."),
fieldWithPath("resource").description("Resource in which the bean was defined, if any.") fieldWithPath("resource").description("Resource in which the bean was defined, if any.")

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,7 +16,6 @@
package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation; package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -50,8 +49,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*/ */
class CachesEndpointDocumentationTests extends MockMvcEndpointDocumentationTests { class CachesEndpointDocumentationTests extends MockMvcEndpointDocumentationTests {
private static final List<FieldDescriptor> levelFields = Arrays.asList( private static final List<FieldDescriptor> levelFields = List.of(fieldWithPath("name").description("Cache name."),
fieldWithPath("name").description("Cache name."),
fieldWithPath("cacheManager").description("Cache manager name."), fieldWithPath("cacheManager").description("Cache manager name."),
fieldWithPath("target").description("Fully qualified name of the native cache.")); fieldWithPath("target").description("Fully qualified name of the native cache."));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,13 +16,10 @@
package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation; package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation;
import java.util.Arrays;
import java.util.List; import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.condition.ConditionsReportEndpoint; import org.springframework.boot.actuate.autoconfigure.condition.ConditionsReportEndpoint;
import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
@ -30,13 +27,9 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.restdocs.RestDocumentationContextProvider;
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation;
import org.springframework.restdocs.payload.FieldDescriptor; import org.springframework.restdocs.payload.FieldDescriptor;
import org.springframework.restdocs.payload.JsonFieldType; import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse; import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
@ -51,26 +44,13 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*/ */
class ConditionsReportEndpointDocumentationTests extends MockMvcEndpointDocumentationTests { class ConditionsReportEndpointDocumentationTests extends MockMvcEndpointDocumentationTests {
private MockMvc mockMvc;
@Autowired
private WebApplicationContext applicationContext;
@Override
@BeforeEach
void setup(RestDocumentationContextProvider restDocumentation) {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.applicationContext)
.apply(MockMvcRestDocumentation.documentationConfiguration(restDocumentation).uris())
.build();
}
@Test @Test
void conditions() throws Exception { void conditions() throws Exception {
List<FieldDescriptor> positiveMatchFields = Arrays.asList( List<FieldDescriptor> positiveMatchFields = List.of(
fieldWithPath("").description("Classes and methods with conditions that were matched."), fieldWithPath("").description("Classes and methods with conditions that were matched."),
fieldWithPath(".*.[].condition").description("Name of the condition."), fieldWithPath(".*.[].condition").description("Name of the condition."),
fieldWithPath(".*.[].message").description("Details of why the condition was matched.")); fieldWithPath(".*.[].message").description("Details of why the condition was matched."));
List<FieldDescriptor> negativeMatchFields = Arrays.asList( List<FieldDescriptor> negativeMatchFields = List.of(
fieldWithPath("").description("Classes and methods with conditions that were not matched."), fieldWithPath("").description("Classes and methods with conditions that were not matched."),
fieldWithPath(".*.notMatched").description("Conditions that were matched."), fieldWithPath(".*.notMatched").description("Conditions that were matched."),
fieldWithPath(".*.notMatched.[].condition").description("Name of the condition."), fieldWithPath(".*.notMatched.[].condition").description("Name of the condition."),
@ -104,7 +84,7 @@ class ConditionsReportEndpointDocumentationTests extends MockMvcEndpointDocument
ConditionEvaluationReport conditionEvaluationReport = ConditionEvaluationReport ConditionEvaluationReport conditionEvaluationReport = ConditionEvaluationReport
.get(context.getBeanFactory()); .get(context.getBeanFactory());
conditionEvaluationReport conditionEvaluationReport
.recordEvaluationCandidates(Arrays.asList(PropertyPlaceholderAutoConfiguration.class.getName())); .recordEvaluationCandidates(List.of(PropertyPlaceholderAutoConfiguration.class.getName()));
return new ConditionsReportEndpoint(context); return new ConditionsReportEndpoint(context);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,7 +16,6 @@
package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation; package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation;
import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.sql.DataSource; import javax.sql.DataSource;
@ -61,7 +60,7 @@ class FlywayEndpointDocumentationTests extends MockMvcEndpointDocumentationTests
} }
private List<FieldDescriptor> migrationFieldDescriptors() { private List<FieldDescriptor> migrationFieldDescriptors() {
return Arrays.asList(fieldWithPath("checksum").description("Checksum of the migration, if any.").optional(), return List.of(fieldWithPath("checksum").description("Checksum of the migration, if any.").optional(),
fieldWithPath("description").description("Description of the migration, if any.").optional(), fieldWithPath("description").description("Description of the migration, if any.").optional(),
fieldWithPath("executionTime").description("Execution time in milliseconds of an applied migration.") fieldWithPath("executionTime").description("Execution time in milliseconds of an applied migration.")
.optional(), .optional(),

View File

@ -17,7 +17,6 @@
package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation; package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation;
import java.io.File; import java.io.File;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@ -68,7 +67,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*/ */
class HealthEndpointDocumentationTests extends MockMvcEndpointDocumentationTests { class HealthEndpointDocumentationTests extends MockMvcEndpointDocumentationTests {
private static final List<FieldDescriptor> componentFields = Arrays.asList( private static final List<FieldDescriptor> componentFields = List.of(
fieldWithPath("status").description("Status of a specific part of the application"), fieldWithPath("status").description("Status of a specific part of the application"),
subsectionWithPath("details").description("Details of the health of a specific part of the application.")); subsectionWithPath("details").description("Details of the health of a specific part of the application."));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,9 +22,9 @@ import java.time.Clock;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -66,11 +66,11 @@ class HttpExchangesEndpointDocumentationTests extends MockMvcEndpointDocumentati
given(request.getUri()).willReturn(URI.create("https://api.example.com")); given(request.getUri()).willReturn(URI.create("https://api.example.com"));
given(request.getMethod()).willReturn("GET"); given(request.getMethod()).willReturn("GET");
given(request.getHeaders()) given(request.getHeaders())
.willReturn(Collections.singletonMap(HttpHeaders.ACCEPT, Arrays.asList("application/json"))); .willReturn(Collections.singletonMap(HttpHeaders.ACCEPT, List.of("application/json")));
RecordableHttpResponse response = mock(RecordableHttpResponse.class); RecordableHttpResponse response = mock(RecordableHttpResponse.class);
given(response.getStatus()).willReturn(200); given(response.getStatus()).willReturn(200);
given(response.getHeaders()) given(response.getHeaders())
.willReturn(Collections.singletonMap(HttpHeaders.CONTENT_TYPE, Arrays.asList("application/json"))); .willReturn(Collections.singletonMap(HttpHeaders.CONTENT_TYPE, List.of("application/json")));
Principal principal = mock(Principal.class); Principal principal = mock(Principal.class);
given(principal.getName()).willReturn("alice"); given(principal.getName()).willReturn("alice");
Instant instant = Instant.parse("2022-12-22T13:43:41.00Z"); Instant instant = Instant.parse("2022-12-22T13:43:41.00Z");
@ -78,7 +78,7 @@ class HttpExchangesEndpointDocumentationTests extends MockMvcEndpointDocumentati
Clock end = Clock.offset(start, Duration.ofMillis(23)); Clock end = Clock.offset(start, Duration.ofMillis(23));
HttpExchange exchange = HttpExchange.start(start, request) HttpExchange exchange = HttpExchange.start(start, request)
.finish(end, response, () -> principal, () -> UUID.randomUUID().toString(), EnumSet.allOf(Include.class)); .finish(end, response, () -> principal, () -> UUID.randomUUID().toString(), EnumSet.allOf(Include.class));
given(this.repository.findAll()).willReturn(Arrays.asList(exchange)); given(this.repository.findAll()).willReturn(List.of(exchange));
this.mockMvc.perform(get("/actuator/httpexchanges")) this.mockMvc.perform(get("/actuator/httpexchanges"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andDo(document("httpexchanges", responseFields( .andDo(document("httpexchanges", responseFields(

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,7 +16,6 @@
package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation; package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation;
import java.util.Arrays;
import java.util.List; import java.util.List;
import liquibase.changelog.ChangeSet.ExecType; import liquibase.changelog.ChangeSet.ExecType;
@ -59,7 +58,7 @@ class LiquibaseEndpointDocumentationTests extends MockMvcEndpointDocumentationTe
} }
private List<FieldDescriptor> getChangeSetFieldDescriptors() { private List<FieldDescriptor> getChangeSetFieldDescriptors() {
return Arrays.asList(fieldWithPath("author").description("Author of the change set."), return List.of(fieldWithPath("author").description("Author of the change set."),
fieldWithPath("changeLog").description("Change log that contains the change set."), fieldWithPath("changeLog").description("Change log that contains the change set."),
fieldWithPath("comments").description("Comments on the change set."), fieldWithPath("comments").description("Comments on the change set."),
fieldWithPath("contexts").description("Contexts of the change set."), fieldWithPath("contexts").description("Contexts of the change set."),

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,7 +16,6 @@
package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation; package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
@ -55,18 +54,14 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*/ */
class LoggersEndpointDocumentationTests extends MockMvcEndpointDocumentationTests { class LoggersEndpointDocumentationTests extends MockMvcEndpointDocumentationTests {
private static final List<FieldDescriptor> levelFields = Arrays.asList( private static final List<FieldDescriptor> levelFields = List.of(
fieldWithPath("configuredLevel").description("Configured level of the logger, if any.").optional(), fieldWithPath("configuredLevel").description("Configured level of the logger, if any.").optional(),
fieldWithPath("effectiveLevel").description("Effective level of the logger.")); fieldWithPath("effectiveLevel").description("Effective level of the logger."));
private static final List<FieldDescriptor> groupLevelFields; private static final List<FieldDescriptor> groupLevelFields = List
.of(fieldWithPath("configuredLevel").description("Configured level of the logger group, if any.")
static { .type(JsonFieldType.STRING)
groupLevelFields = Arrays .optional(), fieldWithPath("members").description("Loggers that are part of this group"));
.asList(fieldWithPath("configuredLevel").description("Configured level of the logger group, if any.")
.type(JsonFieldType.STRING)
.optional(), fieldWithPath("members").description("Loggers that are part of this group"));
}
@MockBean @MockBean
private LoggingSystem loggingSystem; private LoggingSystem loggingSystem;
@ -78,7 +73,7 @@ class LoggersEndpointDocumentationTests extends MockMvcEndpointDocumentationTest
void allLoggers() throws Exception { void allLoggers() throws Exception {
given(this.loggingSystem.getSupportedLogLevels()).willReturn(EnumSet.allOf(LogLevel.class)); given(this.loggingSystem.getSupportedLogLevels()).willReturn(EnumSet.allOf(LogLevel.class));
given(this.loggingSystem.getLoggerConfigurations()) given(this.loggingSystem.getLoggerConfigurations())
.willReturn(Arrays.asList(new LoggerConfiguration("ROOT", LogLevel.INFO, LogLevel.INFO), .willReturn(List.of(new LoggerConfiguration("ROOT", LogLevel.INFO, LogLevel.INFO),
new LoggerConfiguration("com.example", LogLevel.DEBUG, LogLevel.DEBUG))); new LoggerConfiguration("com.example", LogLevel.DEBUG, LogLevel.DEBUG)));
this.mockMvc.perform(get("/actuator/loggers")) this.mockMvc.perform(get("/actuator/loggers"))
.andExpect(status().isOk()) .andExpect(status().isOk())
@ -164,7 +159,7 @@ class LoggersEndpointDocumentationTests extends MockMvcEndpointDocumentationTest
} }
private Map<String, List<String>> getLoggerGroups() { private Map<String, List<String>> getLoggerGroups() {
return Collections.singletonMap("test", Arrays.asList("test.member1", "test.member2")); return Collections.singletonMap("test", List.of("test.member1", "test.member2"));
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,7 +18,6 @@ package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentatio
import java.time.Duration; import java.time.Duration;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -81,7 +80,7 @@ class MappingsEndpointReactiveDocumentationTests extends AbstractEndpointDocumen
@Test @Test
void mappings() { void mappings() {
List<FieldDescriptor> requestMappingConditions = Arrays.asList( List<FieldDescriptor> requestMappingConditions = List.of(
requestMappingConditionField("").description("Details of the request mapping conditions.").optional(), requestMappingConditionField("").description("Details of the request mapping conditions.").optional(),
requestMappingConditionField(".consumes").description("Details of the consumes condition"), requestMappingConditionField(".consumes").description("Details of the consumes condition"),
requestMappingConditionField(".consumes.[].mediaType").description("Consumed media type."), requestMappingConditionField(".consumes.[].mediaType").description("Consumed media type."),
@ -101,7 +100,7 @@ class MappingsEndpointReactiveDocumentationTests extends AbstractEndpointDocumen
requestMappingConditionField(".produces").description("Details of the produces condition."), requestMappingConditionField(".produces").description("Details of the produces condition."),
requestMappingConditionField(".produces.[].mediaType").description("Produced media type."), requestMappingConditionField(".produces.[].mediaType").description("Produced media type."),
requestMappingConditionField(".produces.[].negated").description("Whether the media type is negated.")); requestMappingConditionField(".produces.[].negated").description("Whether the media type is negated."));
List<FieldDescriptor> handlerMethod = Arrays.asList( List<FieldDescriptor> handlerMethod = List.of(
fieldWithPath("*.[].details.handlerMethod").optional() fieldWithPath("*.[].details.handlerMethod").optional()
.type(JsonFieldType.OBJECT) .type(JsonFieldType.OBJECT)
.description("Details of the method, if any, that will handle requests to this mapping."), .description("Details of the method, if any, that will handle requests to this mapping."),
@ -111,13 +110,13 @@ class MappingsEndpointReactiveDocumentationTests extends AbstractEndpointDocumen
.description("Name of the method."), .description("Name of the method."),
fieldWithPath("*.[].details.handlerMethod.descriptor").type(JsonFieldType.STRING) fieldWithPath("*.[].details.handlerMethod.descriptor").type(JsonFieldType.STRING)
.description("Descriptor of the method as specified in the Java Language Specification.")); .description("Descriptor of the method as specified in the Java Language Specification."));
List<FieldDescriptor> handlerFunction = Arrays.asList( List<FieldDescriptor> handlerFunction = List.of(
fieldWithPath("*.[].details.handlerFunction").optional() fieldWithPath("*.[].details.handlerFunction").optional()
.type(JsonFieldType.OBJECT) .type(JsonFieldType.OBJECT)
.description("Details of the function, if any, that will handle requests to this mapping."), .description("Details of the function, if any, that will handle requests to this mapping."),
fieldWithPath("*.[].details.handlerFunction.className").type(JsonFieldType.STRING) fieldWithPath("*.[].details.handlerFunction.className").type(JsonFieldType.STRING)
.description("Fully qualified name of the class of the function.")); .description("Fully qualified name of the class of the function."));
List<FieldDescriptor> dispatcherHandlerFields = new ArrayList<>(Arrays.asList( List<FieldDescriptor> dispatcherHandlerFields = new ArrayList<>(List.of(
fieldWithPath("*") fieldWithPath("*")
.description("Dispatcher handler mappings, if any, keyed by dispatcher handler bean name."), .description("Dispatcher handler mappings, if any, keyed by dispatcher handler bean name."),
fieldWithPath("*.[].details").optional() fieldWithPath("*.[].details").optional()

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,7 +18,6 @@ package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentatio
import java.time.Duration; import java.time.Duration;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -94,7 +93,7 @@ class MappingsEndpointServletDocumentationTests extends AbstractEndpointDocument
.optional() .optional()
.type(JsonFieldType.OBJECT), .type(JsonFieldType.OBJECT),
parentIdField()); parentIdField());
List<FieldDescriptor> dispatcherServletFields = new ArrayList<>(Arrays.asList( List<FieldDescriptor> dispatcherServletFields = new ArrayList<>(List.of(
fieldWithPath("*") fieldWithPath("*")
.description("Dispatcher servlet mappings, if any, keyed by dispatcher servlet bean name."), .description("Dispatcher servlet mappings, if any, keyed by dispatcher servlet bean name."),
fieldWithPath("*.[].details").optional() fieldWithPath("*.[].details").optional()
@ -102,7 +101,7 @@ class MappingsEndpointServletDocumentationTests extends AbstractEndpointDocument
.description("Additional implementation-specific details about the mapping. Optional."), .description("Additional implementation-specific details about the mapping. Optional."),
fieldWithPath("*.[].handler").description("Handler for the mapping."), fieldWithPath("*.[].handler").description("Handler for the mapping."),
fieldWithPath("*.[].predicate").description("Predicate for the mapping."))); fieldWithPath("*.[].predicate").description("Predicate for the mapping.")));
List<FieldDescriptor> requestMappingConditions = Arrays.asList( List<FieldDescriptor> requestMappingConditions = List.of(
requestMappingConditionField("").description("Details of the request mapping conditions.").optional(), requestMappingConditionField("").description("Details of the request mapping conditions.").optional(),
requestMappingConditionField(".consumes").description("Details of the consumes condition"), requestMappingConditionField(".consumes").description("Details of the consumes condition"),
requestMappingConditionField(".consumes.[].mediaType").description("Consumed media type."), requestMappingConditionField(".consumes.[].mediaType").description("Consumed media type."),
@ -122,7 +121,7 @@ class MappingsEndpointServletDocumentationTests extends AbstractEndpointDocument
requestMappingConditionField(".produces").description("Details of the produces condition."), requestMappingConditionField(".produces").description("Details of the produces condition."),
requestMappingConditionField(".produces.[].mediaType").description("Produced media type."), requestMappingConditionField(".produces.[].mediaType").description("Produced media type."),
requestMappingConditionField(".produces.[].negated").description("Whether the media type is negated.")); requestMappingConditionField(".produces.[].negated").description("Whether the media type is negated."));
List<FieldDescriptor> handlerMethod = Arrays.asList( List<FieldDescriptor> handlerMethod = List.of(
fieldWithPath("*.[].details.handlerMethod").optional() fieldWithPath("*.[].details.handlerMethod").optional()
.type(JsonFieldType.OBJECT) .type(JsonFieldType.OBJECT)
.description("Details of the method, if any, that will handle requests to this mapping."), .description("Details of the method, if any, that will handle requests to this mapping."),

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -130,10 +130,10 @@ class QuartzEndpointDocumentationTests extends MockMvcEndpointDocumentationTests
.withInterval(1, IntervalUnit.HOUR)) .withInterval(1, IntervalUnit.HOUR))
.build(); .build();
private static final List<FieldDescriptor> triggerSummary = Arrays.asList(previousFireTime(""), nextFireTime(""), private static final List<FieldDescriptor> triggerSummary = List.of(previousFireTime(""), nextFireTime(""),
priority("")); priority(""));
private static final List<FieldDescriptor> cronTriggerSummary = Arrays.asList( private static final List<FieldDescriptor> cronTriggerSummary = List.of(
fieldWithPath("expression").description("Cron expression to use."), fieldWithPath("expression").description("Cron expression to use."),
fieldWithPath("timeZone").type(JsonFieldType.STRING) fieldWithPath("timeZone").type(JsonFieldType.STRING)
.optional() .optional()
@ -158,8 +158,8 @@ class QuartzEndpointDocumentationTests extends MockMvcEndpointDocumentationTests
fieldWithPath("timeZone").type(JsonFieldType.STRING) fieldWithPath("timeZone").type(JsonFieldType.STRING)
.description("Time zone within which time calculations will be performed, if any.")); .description("Time zone within which time calculations will be performed, if any."));
private static final List<FieldDescriptor> customTriggerSummary = Collections.singletonList( private static final List<FieldDescriptor> customTriggerSummary = List
fieldWithPath("trigger").description("A toString representation of the custom trigger instance.")); .of(fieldWithPath("trigger").description("A toString representation of the custom trigger instance."));
private static final FieldDescriptor[] commonCronDetails = new FieldDescriptor[] { private static final FieldDescriptor[] commonCronDetails = new FieldDescriptor[] {
fieldWithPath("group").description("Name of the group."), fieldWithPath("group").description("Name of the group."),
@ -280,7 +280,7 @@ class QuartzEndpointDocumentationTests extends MockMvcEndpointDocumentationTests
setPreviousNextFireTime(secondTrigger, "2020-12-04T03:00:00Z", "2020-12-04T12:00:00Z"); setPreviousNextFireTime(secondTrigger, "2020-12-04T03:00:00Z", "2020-12-04T12:00:00Z");
mockTriggers(firstTrigger, secondTrigger); mockTriggers(firstTrigger, secondTrigger);
given(this.scheduler.getTriggersOfJob(jobOne.getKey())) given(this.scheduler.getTriggersOfJob(jobOne.getKey()))
.willAnswer((invocation) -> Arrays.asList(firstTrigger, secondTrigger)); .willAnswer((invocation) -> List.of(firstTrigger, secondTrigger));
this.mockMvc.perform(get("/actuator/quartz/jobs/samples/jobOne")) this.mockMvc.perform(get("/actuator/quartz/jobs/samples/jobOne"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andDo(document("quartz/job-details", responseFields( .andDo(document("quartz/job-details", responseFields(
@ -398,7 +398,7 @@ class QuartzEndpointDocumentationTests extends MockMvcEndpointDocumentationTests
.andWithPrefix("custom.", customTriggerSummary))); .andWithPrefix("custom.", customTriggerSummary)));
} }
private <T extends Trigger> T setupTriggerDetails(TriggerBuilder<T> builder, TriggerState state) private <T extends Trigger> void setupTriggerDetails(TriggerBuilder<T> builder, TriggerState state)
throws SchedulerException { throws SchedulerException {
T trigger = builder.withIdentity("example", "samples") T trigger = builder.withIdentity("example", "samples")
.withDescription("Example trigger") .withDescription("Example trigger")
@ -409,7 +409,6 @@ class QuartzEndpointDocumentationTests extends MockMvcEndpointDocumentationTests
setPreviousNextFireTime(trigger, "2020-12-04T03:00:00Z", "2020-12-07T03:00:00Z"); setPreviousNextFireTime(trigger, "2020-12-04T03:00:00Z", "2020-12-07T03:00:00Z");
given(this.scheduler.getTriggerState(trigger.getKey())).willReturn(state); given(this.scheduler.getTriggerState(trigger.getKey())).willReturn(state);
mockTriggers(trigger); mockTriggers(trigger);
return trigger;
} }
private static FieldDescriptor startTime(String prefix) { private static FieldDescriptor startTime(String prefix) {
@ -481,7 +480,7 @@ class QuartzEndpointDocumentationTests extends MockMvcEndpointDocumentationTests
} }
} }
private <T extends Trigger> T setPreviousNextFireTime(T trigger, String previousFireTime, String nextFireTime) { private <T extends Trigger> void setPreviousNextFireTime(T trigger, String previousFireTime, String nextFireTime) {
OperableTrigger operableTrigger = (OperableTrigger) trigger; OperableTrigger operableTrigger = (OperableTrigger) trigger;
if (previousFireTime != null) { if (previousFireTime != null) {
operableTrigger.setPreviousFireTime(fromUtc(previousFireTime)); operableTrigger.setPreviousFireTime(fromUtc(previousFireTime));
@ -489,7 +488,6 @@ class QuartzEndpointDocumentationTests extends MockMvcEndpointDocumentationTests
if (nextFireTime != null) { if (nextFireTime != null) {
operableTrigger.setNextFireTime(fromUtc(nextFireTime)); operableTrigger.setNextFireTime(fromUtc(nextFireTime));
} }
return trigger;
} }
private static Date fromUtc(String utcTime) { private static Date fromUtc(String utcTime) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -33,7 +33,6 @@ import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.annotation.SchedulingConfigurer; import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskHolder; import org.springframework.scheduling.config.ScheduledTaskHolder;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse; import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
@ -73,8 +72,7 @@ class ScheduledTasksEndpointDocumentationTests extends MockMvcEndpointDocumentat
initialDelayWithPrefix("fixedRate.[]."), initialDelayWithPrefix("fixedRate.[]."),
fieldWithPath("custom").description("Tasks with custom triggers, if any."), fieldWithPath("custom").description("Tasks with custom triggers, if any."),
targetFieldWithPrefix("custom.[]."), targetFieldWithPrefix("custom.[]."),
fieldWithPath("custom.[].trigger").description("Trigger for the task.")))) fieldWithPath("custom.[].trigger").description("Trigger for the task."))));
.andDo(MockMvcResultHandlers.print());
} }
private FieldDescriptor targetFieldWithPrefix(String prefix) { private FieldDescriptor targetFieldWithPrefix(String prefix) {

View File

@ -17,7 +17,6 @@
package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation; package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation;
import java.time.Instant; import java.time.Instant;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -65,7 +64,7 @@ class SessionsEndpointDocumentationTests extends MockMvcEndpointDocumentationTes
private static final Session sessionThree = createSession(Instant.now().minusSeconds(60 * 60 * 2), private static final Session sessionThree = createSession(Instant.now().minusSeconds(60 * 60 * 2),
Instant.now().minusSeconds(12)); Instant.now().minusSeconds(12));
private static final List<FieldDescriptor> sessionFields = Arrays.asList( private static final List<FieldDescriptor> sessionFields = List.of(
fieldWithPath("id").description("ID of the session."), fieldWithPath("id").description("ID of the session."),
fieldWithPath("attributeNames").description("Names of the attributes stored in the session."), fieldWithPath("attributeNames").description("Names of the attributes stored in the session."),
fieldWithPath("creationTime").description("Timestamp of when the session was created."), fieldWithPath("creationTime").description("Timestamp of when the session was created."),

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,7 +23,6 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
@ -51,7 +50,7 @@ class ShutdownEndpointDocumentationTests extends MockMvcEndpointDocumentationTes
static class TestConfiguration { static class TestConfiguration {
@Bean @Bean
ShutdownEndpoint endpoint(Environment environment) { ShutdownEndpoint endpoint() {
ShutdownEndpoint endpoint = new ShutdownEndpoint(); ShutdownEndpoint endpoint = new ShutdownEndpoint();
endpoint.setApplicationContext(new AnnotationConfigApplicationContext()); endpoint.setApplicationContext(new AnnotationConfigApplicationContext());
return endpoint; return endpoint;