-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes: #9492 Issue link: #9492 Switches `MockIntegrationContextCustomizerFactory` & `SpringIntegrationTestExecutionListener` to use `TestContextAnnotationUtils` in order to properly support `@NestedTestConfiguration` semantics. Adds an integration test with a base class and several `@Nested` inner test classes to verify the various permutations of `@SpringIntegrationTest` inherit/override behavior when used w/ `@NestedTestConfiguration`. (cherry picked from commit 3a8e3ab)
- Loading branch information
1 parent
a83b100
commit fd80c55
Showing
6 changed files
with
161 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...t/src/test/java/org/springframework/integration/test/context/AbstractIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2024 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.integration.test.context; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.integration.config.EnableIntegration; | ||
import org.springframework.integration.endpoint.AbstractEndpoint; | ||
import org.springframework.integration.endpoint.ReactiveMessageSourceProducer; | ||
import org.springframework.messaging.support.GenericMessage; | ||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; | ||
|
||
/** | ||
* Base integration test that specifies a default {@link SpringIntegrationTest} | ||
* to be inherited by concrete subclasses. | ||
* | ||
* @author Chris Bono | ||
* | ||
* @since 6.2.10 | ||
*/ | ||
@SpringJUnitConfig | ||
@SpringIntegrationTest(noAutoStartup = "*") | ||
class AbstractIntegrationTest { | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
@EnableIntegration | ||
static class MockEndpointConfig { | ||
|
||
@Bean | ||
AbstractEndpoint mockEndpoint() { | ||
ReactiveMessageSourceProducer endpoint = | ||
new ReactiveMessageSourceProducer(() -> new GenericMessage<>("testFromMockEndpoint")); | ||
endpoint.setOutputChannelName("nullChannel"); | ||
return endpoint; | ||
} | ||
|
||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
.../springframework/integration/test/context/NestedSpringIntegrationTestAnnotationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright 2024 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.integration.test.context; | ||
|
||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.integration.endpoint.AbstractEndpoint; | ||
import org.springframework.lang.Nullable; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.NestedTestConfiguration; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Concrete specialization of {@link AbstractIntegrationTest} used to | ||
* test inherit and override behavior of {@link SpringIntegrationTest} | ||
* when used with {@link Nested} and {@link NestedTestConfiguration}. | ||
* | ||
* @author Chris Bono | ||
* @author Artem Bilan | ||
* | ||
* @since 6.2.10 | ||
*/ | ||
class NestedSpringIntegrationTestAnnotationTests extends AbstractIntegrationTest { | ||
|
||
@Test | ||
void annotationDefinedOnParentIsInheritedByDefault(@Autowired AbstractEndpoint mockEndpoint) { | ||
assertThat(mockEndpoint.isRunning()).isFalse(); | ||
} | ||
|
||
@Nested | ||
class NestedTestDefaultEnclosingConfiguration { | ||
|
||
@Test | ||
void annotationDefinedOnParentOfEnclosingIsInheritedByDefault(@Autowired AbstractEndpoint mockEndpoint) { | ||
assertThat(mockEndpoint.isRunning()).isFalse(); | ||
} | ||
|
||
} | ||
|
||
@Nested | ||
@NestedTestConfiguration(NestedTestConfiguration.EnclosingConfiguration.INHERIT) | ||
class NestedTestWithInheritEnclosingConfiguration { | ||
|
||
@Test | ||
void annotationDefinedOnParentOfEnclosingIsInherited(@Autowired AbstractEndpoint mockEndpoint) { | ||
assertThat(mockEndpoint.isRunning()).isFalse(); | ||
} | ||
|
||
} | ||
|
||
@Nested | ||
@NestedTestConfiguration(NestedTestConfiguration.EnclosingConfiguration.INHERIT) | ||
@SpringIntegrationTest(noAutoStartup = "noSuchEndpointWithThisPatternExists") | ||
class NestedTestWithInheritEnclosingConfigurationButOverrideAnnotation { | ||
|
||
@Test | ||
void annotationDefinedOnParentOfEnclosingIsOverridden(@Autowired AbstractEndpoint mockEndpoint) { | ||
assertThat(mockEndpoint.isRunning()).isTrue(); | ||
} | ||
|
||
} | ||
|
||
@Nested | ||
@NestedTestConfiguration(NestedTestConfiguration.EnclosingConfiguration.OVERRIDE) | ||
@ContextConfiguration(classes = MockEndpointConfig.class) | ||
class NestedTestWithOverrideEnclosingConfiguration { | ||
|
||
@Test | ||
void annotationDefinedOnParentOfEnclosingIsIgnored(@Autowired AbstractEndpoint mockEndpoint, | ||
@Nullable @Autowired MockIntegrationContext mockIntegrationContext) { | ||
|
||
assertThat(mockEndpoint.isRunning()).isTrue(); | ||
assertThat(mockIntegrationContext).isNull(); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters