1

As someone new to Spring but with a streams processing background, I'm pretty confused about how I should be testing processors written in Spring Cloud Stream. The testing docs (written for 2.2.0 but seemingly the most recent, so still valid for 3.0.7 I guess?) indicate that a processor should be autowired into the test class via annotation, but there's no mention of where this 'Processor' bean comes from. I've tried to make it available via:

import org.springframework.cloud.stream.messaging.Processor;
...

@Autowired
private Processor processor;

but when running the tests, the exception is always the same:

Unsatisfied dependency expressed through field 'processor'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.cloud.stream.messaging.Processor' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Am I even on the right path here? There seems to be lots of deprecated features in the past year so any pointers to more recent documentation would be appreciated.

terryf82
  • 91
  • 1
  • 7
  • FYI this is the latest doc: https://cloud.spring.io/spring-cloud-static/spring-cloud-stream/current/reference/html/spring-cloud-stream.html#_testing) – Marc Aug 31 '20 at 06:31
  • As described in the doc that is linked in the previous comment, the testing approaches are different now. You should try migrating to the new approach. – sobychacko Aug 31 '20 at 20:49
  • Thanks for the link. I'm trying to emulate the [simple unit test](https://cloud.spring.io/spring-cloud-static/spring-cloud-stream/current/reference/html/spring-cloud-stream.html#_test_binder_usage). I have the dependency declared in gradle as testCompile 'org.springframework.cloud:spring-cloud-stream:3.0.7.RELEASE:test-binder' and a simple send & assert test setup. The test seems to be running the processor outside of a testing context, e.g it's trying to connect to a real broker: Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available. – terryf82 Aug 31 '20 at 23:51

0 Answers0