-
Notifications
You must be signed in to change notification settings - Fork 1.1k
GH-9492: Fix @SpringIntegration in @Nested test #9506
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
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,50 @@ | ||
/* | ||
* Copyright 2024-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.4.0 | ||
*/ | ||
@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; | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright 2024-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.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 | ||
* @since 6.4.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DITTO |
||
*/ | ||
class NestedSpringIntegrationTestAnnotationTests extends AbstractIntegrationTest { | ||
|
||
@Test | ||
void annotationDefinedOnParentIsInheritedByDefault(@Autowired AbstractEndpoint mockEndpoint) { | ||
// parent disables startup for all endpoints | ||
assertThat(mockEndpoint.isRunning()).isFalse(); | ||
} | ||
|
||
@Nested | ||
class NestedTestWithoutEnclosingConfiguration { | ||
|
||
@Test | ||
void annotationDefinedOnParentOfEnclosingIsInheritedByDefault(@Autowired AbstractEndpoint mockEndpoint) { | ||
assertThat(mockEndpoint.isRunning()).isFalse(); | ||
} | ||
} | ||
|
||
@Nested | ||
@NestedTestConfiguration(NestedTestConfiguration.EnclosingConfiguration.INHERIT) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need this specific test since |
||
class NestedTestWithInheritEnclosingConfiguration { | ||
|
||
@Test | ||
void annotationDefinedOnParentOfEnclosingIsInherited(@Autowired AbstractEndpoint mockEndpoint) { | ||
assertThat(mockEndpoint.isRunning()).isFalse(); | ||
} | ||
} | ||
|
||
@Nested | ||
@NestedTestConfiguration(NestedTestConfiguration.EnclosingConfiguration.INHERIT) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is redundant since |
||
@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 annotationDefinedOnParentOfEnclosingIsInherited(@Autowired AbstractEndpoint mockEndpoint) { | ||
assertThat(mockEndpoint.isRunning()).isTrue(); | ||
} | ||
} | ||
|
||
} |
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.
I think we can treat this as a bug, plus this is just a testing feature, so I'm going to back port the fix down to
6.2.x
.Therefore
@since 6.2.10
over here.