Add integration test for RPC with Spring Boot AMQP for the server.
This commit is contained in:
@@ -34,7 +34,7 @@ public class EventPublisher {
|
||||
|
||||
@Scheduled(fixedDelay = 3000)
|
||||
public void send() {
|
||||
String key = "vw";
|
||||
String key = "old.car";
|
||||
Car car = Car.builder()
|
||||
.id(UUID.randomUUID())
|
||||
.color("white")
|
||||
@@ -53,7 +53,7 @@ public class EventPublisher {
|
||||
|
||||
@Scheduled(fixedDelay = 3000, initialDelay = 1500)
|
||||
public void sendAsynchronously() {
|
||||
String key = "vw";
|
||||
String key = "old.car";
|
||||
Car car = Car.builder()
|
||||
.id(UUID.randomUUID())
|
||||
.color("black")
|
||||
|
||||
@@ -15,6 +15,8 @@ repositories {
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-amqp'
|
||||
implementation 'org.springframework.boot:spring-boot-starter'
|
||||
|
||||
testImplementation 'org.springframework.amqp:spring-rabbit-test'
|
||||
testImplementation('org.springframework.boot:spring-boot-starter-test') {
|
||||
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class ServerConfiguration {
|
||||
Queue queue) {
|
||||
return BindingBuilder.bind(queue)
|
||||
.to(directExchange)
|
||||
.with("vw");
|
||||
.with("old.car");
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package io.reflectoring.server.rpc;
|
||||
|
||||
import io.reflectoring.server.dto.Car;
|
||||
import io.reflectoring.server.dto.Registration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.amqp.core.DirectExchange;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SpringBootTest
|
||||
class EventConsumerTest {
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Autowired
|
||||
private DirectExchange directExchange;
|
||||
|
||||
@Test
|
||||
void send() {
|
||||
// given
|
||||
UUID id = UUID.randomUUID();
|
||||
Car car = Car.builder()
|
||||
.id(id)
|
||||
.name("vw")
|
||||
.color("white")
|
||||
.build();
|
||||
|
||||
// when
|
||||
ParameterizedTypeReference<Registration> responseType =
|
||||
new ParameterizedTypeReference<>() {};
|
||||
Registration registration = rabbitTemplate.convertSendAndReceiveAsType(directExchange.getName(), "old.car", car, responseType);
|
||||
|
||||
// then
|
||||
assertThat(registration).isNotNull();
|
||||
assertThat(registration.getId()).isEqualTo(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user