Spring cloud Stream Solace Unit Test

Solace Spring Cloud BOM  2.4.0
Solace Spring Cloud Stream Starter 3.4.0

org.springframework.cloud
spring-cloud-stream
test-jar
test
test-binder



com.solace.spring.cloud
spring-cloud-starter-stream-solace

Class:
@Component
@EnableAutoConfiguration
public class MessageReceiver {
 @Bean
 @SuppressWarnings(“unchecked”)
 Function<Message<List<?>>, Collection<Message>> receiveMessage() {   return batchMsg -> {    List<?> batchedPayloads = batchMsg.getPayload();
   ArrayList<Message> msgList = new ArrayList<Message>();
   // System.out.println("size " + batchedPayloads.get(0));
   
List<Map<String, Object>> batchedHeaders =
     (List<Map<String, Object>>)
       batchMsg.getHeaders().get(SolaceBinderHeaders.BATCHED_HEADERS);
   msgList.add(
       MessageBuilder.withPayload(“dgjk”).build());
   return msgList;
  };
 }
}

TestClass:

@RunWith(SpringRunner.class)
 @SpringBootTest
 public class MessageReceiverTest {
 @Test
public void receiveMessageTest() throws InterruptedException {

	try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
			TestChannelBinderConfiguration.getCompleteConfiguration(
					MessageReceiver.class))
			.run("--spring.cloud.function.definition=receiveMessage")) {
		InputDestination source = context.getBean(InputDestination.class);
		OutputDestination target = context.getBean(OutputDestination.class);
		Message<?> msgInput = MessageBuilder.withPayload(inputObj).build();

		assertNotNull(msgInput.toString());
		source.send(msgInput);


		target.receive().getHeaders();

		assertNotNull(target.receive().getPayload());
	}}

}
 Error Log:  java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration , you need to use @ContextConfiguration or @SpringBootTest(classes=…) with your test
at org.springframework.util.Assert.state(Assert.java:76)
at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.getOrFindConfigurationClasses(SpringBootTestContextBootstrapper.java:236)
at org.springframework.boot.test.context.SpringBootTestContextBootstrapper.processMergedContextConfiguration(SpringBootTestContextBootstrapper.java:152)
at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:393)

Sorry, the unit tests are missing on this sample. From the exception, it seems like a spring/junit configuration issue, please refer to other samples and update the code and try.
solace-samples-spring/cloud-stream-processor/src/test/java/com/solace/samples/spring/scs/ConvertFtoCProcessorTest.java at master · SolaceSamples/solace-samples-spring · GitHub has a valid configuration that can be used.

Hi, I am using TestChannelBinderConfiguration. I have resolved the dependency issues by adding other classes in the argument,
new SpringApplicationBuilder(
TestChannelBinderConfiguration.getCompleteConfiguration(
MessageReceiver.class, xxx.class, yyy.class ))
in my yyy.class, i have mongotemplate and mongoclient used. How to mock them, Please suggest if any inputs.
“Catching”,“thrown”:{“commonElementCount”:0,“localizedMessage”:“Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}]”,“message”:"Timed out after 30000 ms while waiting to connect.

How to mock this ?
@Autowired
 public SafeStoreDaoImpl(MongoClient mongoClient) {
  this.mongoClient = mongoClient;
 }

This seems to be a mongo connection error - connection timeout while connecting, please check your mongo installation.

https://github.com/spring-cloud/spring-cloud-stream/blob/main/docs/src/main/asciidoc/spring-cloud-stream.adoc#spring_integration_test_binder

How to mock the mongo client in the above sample code ? @Autowired
 public SafeStoreDaoImpl(MongoClient mongoClient) {
  this.mongoClient = mongoClient;
 }
2.Should we give connection details to use the real mongo db for integration testing?