-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Add documentation for profile-based conditional test execution (#16300) #36013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
83af97b
69261dc
79cb2ef
629d93d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * Copyright 2002-present 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.test.context.junit.jupiter.nested; | ||
|
|
||
| import org.junit.jupiter.api.Nested; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import org.springframework.test.annotation.DirtiesContext; | ||
| import org.springframework.test.context.jdbc.EmptyDatabaseConfig; | ||
| import org.springframework.test.context.jdbc.Sql; | ||
| import org.springframework.test.context.jdbc.Sql.ExecutionPhase; | ||
| import org.springframework.test.context.jdbc.SqlMergeMode; | ||
| import org.springframework.test.context.jdbc.SqlMergeMode.MergeMode; | ||
| import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; | ||
|
|
||
| import static org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_CLASS; | ||
| import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.BEFORE_TEST_CLASS; | ||
|
|
||
| /** | ||
| * Integration tests that verify support for excluding inherited class-level | ||
| * execution phase SQL scripts in {@code @Nested} test classes using | ||
| * {@link SqlMergeMode.MergeMode#OVERRIDE_AND_EXCLUDE_INHERITED_EXECUTION_PHASE_SCRIPTS}. | ||
| * | ||
| * <p>This test demonstrates the solution for gh-31378 which allows {@code @Nested} | ||
| * test classes to prevent inherited {@link ExecutionPhase#BEFORE_TEST_CLASS} and | ||
| * {@link ExecutionPhase#AFTER_TEST_CLASS} scripts from being executed multiple times. | ||
| * | ||
| * @author Sam Brannen | ||
| * @since 6.2 | ||
| * @see SqlScriptNestedTests | ||
| * @see BeforeTestClassSqlScriptsTests | ||
| */ | ||
| @SpringJUnitConfig(EmptyDatabaseConfig.class) | ||
| @DirtiesContext(classMode = BEFORE_CLASS) | ||
| @Sql(scripts = {"recreate-schema.sql", "data-add-catbert.sql"}, executionPhase = BEFORE_TEST_CLASS) | ||
| class SqlScriptExecutionPhaseNestedTests extends AbstractTransactionalTests { | ||
|
|
||
| @Test | ||
| void outerClassLevelScriptsHaveBeenRun() { | ||
| assertUsers("Catbert"); | ||
| } | ||
|
|
||
| /** | ||
| * This nested test class demonstrates the default behavior where inherited | ||
| * class-level execution phase scripts ARE executed. | ||
| */ | ||
| @Nested | ||
| class DefaultBehaviorNestedTests { | ||
|
|
||
| @Test | ||
| void inheritedClassLevelScriptsAreExecuted() { | ||
| // The outer class's BEFORE_TEST_CLASS scripts are inherited and executed | ||
| assertUsers("Catbert"); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * This nested test class demonstrates the NEW behavior using | ||
| * {@link MergeMode#OVERRIDE_AND_EXCLUDE_INHERITED_EXECUTION_PHASE_SCRIPTS} | ||
| * where inherited class-level execution phase scripts are NOT executed. | ||
| */ | ||
| @Nested | ||
| @SqlMergeMode(MergeMode.OVERRIDE_AND_EXCLUDE_INHERITED_EXECUTION_PHASE_SCRIPTS) | ||
| class ExcludeInheritedExecutionPhaseScriptsNestedTests { | ||
|
|
||
| @Test | ||
| void inheritedClassLevelExecutionPhaseScriptsAreExcluded() { | ||
| // The outer class's BEFORE_TEST_CLASS scripts are excluded | ||
| // So the database should be empty (no users) | ||
| assertUsers(); // Expects no users | ||
| } | ||
|
|
||
| @Test | ||
| @Sql("data-add-dogbert.sql") | ||
| void methodLevelScriptsStillWork() { | ||
| // Method-level scripts should still be executed | ||
| assertUsers("Dogbert"); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * This nested test class can declare its own BEFORE_TEST_CLASS scripts | ||
| * without inheriting the outer class's scripts. | ||
| */ | ||
| @Nested | ||
| @SqlMergeMode(MergeMode.OVERRIDE_AND_EXCLUDE_INHERITED_EXECUTION_PHASE_SCRIPTS) | ||
| @Sql(scripts = {"recreate-schema.sql", "data-add-dogbert.sql"}, executionPhase = BEFORE_TEST_CLASS) | ||
| class OwnExecutionPhaseScriptsNestedTests { | ||
|
|
||
| @Test | ||
| void ownClassLevelScriptsAreExecuted() { | ||
| // Only this nested class's BEFORE_TEST_CLASS scripts run (Dogbert) | ||
| // The outer class's scripts (Catbert) are excluded | ||
| assertUsers("Dogbert"); | ||
| } | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -42,7 +42,8 @@ | |||||
| /** | ||||||
| * {@code HttpMessageWriter} that wraps and delegates to an {@link Encoder}. | ||||||
| * | ||||||
| * <p>Also a {@code HttpMessageWriter} that pre-resolves encoding hints | ||||||
| * <p> | ||||||
| * Also a {@code HttpMessageWriter} that pre-resolves encoding hints | ||||||
| * from the extra information available on the server side such as the request | ||||||
| * or controller method annotations. | ||||||
| * | ||||||
|
|
@@ -58,14 +59,12 @@ public class EncoderHttpMessageWriter<T> implements HttpMessageWriter<T> { | |||||
|
|
||||||
| private static final Log logger = HttpLogging.forLogName(EncoderHttpMessageWriter.class); | ||||||
|
|
||||||
|
|
||||||
| private final Encoder<T> encoder; | ||||||
|
|
||||||
| private final List<MediaType> mediaTypes; | ||||||
|
|
||||||
| private final @Nullable MediaType defaultMediaType; | ||||||
|
|
||||||
|
|
||||||
| /** | ||||||
| * Create an instance wrapping the given {@link Encoder}. | ||||||
| */ | ||||||
|
|
@@ -89,7 +88,6 @@ private static void initLogger(Encoder<?> encoder) { | |||||
| return mediaTypes.stream().filter(MediaType::isConcrete).findFirst().orElse(null); | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| /** | ||||||
| * Return the {@code Encoder} of this writer. | ||||||
| */ | ||||||
|
|
@@ -131,6 +129,8 @@ public Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType eleme | |||||
| })) | ||||||
| .flatMap(buffer -> { | ||||||
| Hints.touchDataBuffer(buffer, hints, logger); | ||||||
| // Only set Content-Length header for GET requests if value > 0 | ||||||
| // This prevents sending unnecessary headers for other request types | ||||||
|
Comment on lines
+132
to
+133
|
||||||
| // Only set Content-Length header for GET requests if value > 0 | |
| // This prevents sending unnecessary headers for other request types |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file contains unrelated changes that don't align with the PR's stated purpose of documenting profile-based conditional test execution. The PR description explicitly states "Documentation only - zero production code changes", but this file modifies production code in the spring-web module. These changes (formatting adjustments and a comment about Content-Length headers) should either be removed from this PR or the PR description should be updated to explain why these changes are included.
| // Server side only... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This note about recommending Java/Annotation-Based configuration over XML appears unrelated to the PR's stated purpose of documenting profile-based conditional test execution. The PR description makes no mention of adding guidance about configuration approaches. This change should either be removed from this PR or the PR description should be updated to explain its inclusion.