-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Resolve TODO: Add ServerWebExchange expression value test #36014
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
6921bcb
4ff9adc
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 |
|---|---|---|
|
|
@@ -48,6 +48,7 @@ class ExpressionValueMethodArgumentResolverTests { | |
| private MethodParameter paramSystemProperty; | ||
| private MethodParameter paramNotSupported; | ||
| private MethodParameter paramAlsoNotSupported; | ||
| private MethodParameter paramCustomProperty; | ||
|
|
||
|
|
||
| @BeforeEach | ||
|
|
@@ -61,6 +62,7 @@ void setup() throws Exception { | |
| this.paramSystemProperty = new MethodParameter(method, 0); | ||
| this.paramNotSupported = new MethodParameter(method, 1); | ||
| this.paramAlsoNotSupported = new MethodParameter(method, 2); | ||
| this.paramCustomProperty = new MethodParameter(method, 3); | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -93,14 +95,32 @@ void resolveSystemProperty() { | |
|
|
||
| } | ||
|
|
||
| // TODO: test with expression for ServerWebExchange | ||
| @Test | ||
| void resolveWithServerWebExchange() { | ||
| System.setProperty("customProperty", "42"); | ||
| try { | ||
| // Configure the exchange | ||
| MockServerHttpRequest request = MockServerHttpRequest.get("/test").build(); | ||
| MockServerWebExchange exchange = MockServerWebExchange.from(request); | ||
|
|
||
| Mono<Object> mono = this.resolver.resolveArgument( | ||
| this.paramCustomProperty, new BindingContext(), exchange); | ||
|
|
||
| Object value = mono.block(); | ||
| assertThat(value).isEqualTo(42); | ||
| } | ||
| finally { | ||
| System.clearProperty("customProperty"); | ||
| } | ||
| } | ||
|
Comment on lines
+98
to
+115
|
||
|
|
||
|
|
||
| @SuppressWarnings("unused") | ||
| public void params( | ||
| @Value("#{systemProperties.systemProperty}") int param1, | ||
| String notSupported, | ||
| @Value("#{systemProperties.foo}") Mono<String> alsoNotSupported) { | ||
| @Value("#{systemProperties.foo}") Mono<String> alsoNotSupported, | ||
| @Value("#{systemProperties.customProperty}") int param4) { | ||
| } | ||
|
|
||
| } | ||
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.
The comment suggests this is specific to GET requests, but the code unconditionally sets Content-Length for all request types. The comment is misleading because:
Either remove this comment or clarify that Content-Length is set for all requests when processing Mono publishers.