spring-cloud / spring-cloud/spring-cloud-stream
Add a test slice and autoconfiguration for the new test binder
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 646
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 8
Description
When using Spring Cloud Contract, in order to integrate with the new testing binder, we need to, in the base class, start a Spring Boot context AND manually import the testing binder configuration.
What we would like to achieve is that the testing binder configuration gets automatically discovered and applied in the context of a test. Also a test slice with @ImportAutoConfiguration that imports all of the configuration classes would come in handy.
Production code
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Bean
EmitterProcessor<Fraud> emitterProcessor() {
return EmitterProcessor.create();
}
@Bean
Supplier<Flux<Fraud>> frauds(EmitterProcessor<Fraud> emitterProcessor) {
return () -> emitterProcessor;
}
}
@RestController
class FraudController {
private final EmitterProcessor<Fraud> emitter;
FraudController(EmitterProcessor<Fraud> emitter) {
this.emitter = emitter;
}
@PostMapping("/trigger")
void trigger() {
Fraud fraud = new Fraud("g");
System.out.println("GOT " + fraud);
emitter.onNext(fraud);
}
}
class Fraud {
String surname;
public Fraud(String surname) {
this.surname = surname;
}
public Fraud() {
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
}
Base class (the one that requires configuration setup)
import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureMessageVerifier;
@SpringBootTest(classes = BaseClass.SampleConfiguration.class)
@AutoConfigureMessageVerifier
public class BaseClass {
@Autowired
FraudController fraudController;
public void trigger() {
fraudController.trigger();
}
@EnableAutoConfiguration
@Import({TestChannelBinderConfiguration.class, DemoApplication.class})
public static class SampleConfiguration {
}
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the @AutoConfigureMessageVerifier entry point and the TestChannelBinderConfiguration used in BaseClass.SampleConfiguration. The work is done when testing binder configuration is discovered automatically and a test slice using @ImportAutoConfiguration imports the required configuration classes without the manual imports shown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring, spring-boot
- Domain
- backend, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100