Reputation: 133
I want to write unit/integration tests for my config server so I checked this link. There's a class annotated with @SpringBootTest
and also a function startConfigServer()
inside annotated with @BeforeClass
. Why exactly is this function needed because there's the @SpringBootTest
annotation?
And what other unit test cases and integration tests can I write for the config server? I'm also using Spring Cloud Stream Kafka and Spring Cloud Bus, along with Spring Security basic authentication enabled.
Upvotes: 0
Views: 341
Reputation: 1055
Spring-cloud-bus is a mechanism for mutiple application nodes to communicate, offering the ability to broadcast events.
This communication in place, the application can use it, for example, to get the configuration from a configuration-server in a dynamic way (a change in configuration will lead to broadcasting the appropriate event).
So when testing such an application, the test must first provide a configuration-server to get the configuration from, hence the startConfigServer()
method in the example you linked.
Spring blog references spring-cloud-stream-test-support to ease testing of this messaging abstraction, but I have not used it myself.
However, an other way to test this is to mock all accesses to this configuration-server (through HTTP and spring-cloud-stream underlying broker).
Here is an example of all the mocking stuff (using RabbitMQ, but the idea will be the same with Kafka).
Testing the configuration-server is just the other way around (modify a configuration file and assert that a message is published on the underlying broker).
For the record, I am not sure that spring-cloud-bus can be used with Kafka, as the official documentation says only AMQP (0.9) is supported : https://spring.io/projects/spring-cloud-bus
Upvotes: 1