|
| 1 | +package com.baeldung.cassandra.reactive; |
| 2 | + |
| 3 | +import com.baeldung.cassandra.reactive.model.Employee; |
| 4 | +import com.baeldung.cassandra.reactive.repository.EmployeeRepository; |
| 5 | +import org.junit.Before; |
| 6 | +import org.junit.Test; |
| 7 | +import org.junit.runner.RunWith; |
| 8 | +import org.springframework.beans.factory.annotation.Autowired; |
| 9 | +import org.springframework.boot.test.context.SpringBootTest; |
| 10 | +import org.springframework.test.context.junit4.SpringRunner; |
| 11 | +import reactor.core.publisher.Flux; |
| 12 | +import reactor.core.publisher.Mono; |
| 13 | +import reactor.test.StepVerifier; |
| 14 | + |
| 15 | + |
| 16 | +@RunWith(SpringRunner.class) |
| 17 | +@SpringBootTest |
| 18 | +public class ReactiveEmployeeRepositoryIntegrationTest { |
| 19 | + |
| 20 | + @Autowired |
| 21 | + EmployeeRepository repository; |
| 22 | + |
| 23 | + @Before |
| 24 | + public void setUp() { |
| 25 | + |
| 26 | + Flux<Employee> deleteAndInsert = repository.deleteAll() // |
| 27 | + .thenMany(repository.saveAll(Flux.just( |
| 28 | + new Employee(111, "John Doe", "Delaware", "jdoe@xyz.com", 31), |
| 29 | + new Employee(222, "Adam Smith", "North Carolina", "asmith@xyz.com", 43), |
| 30 | + new Employee(333, "Kevin Dunner", "Virginia", "kdunner@xyz.com", 24), |
| 31 | + new Employee(444, "Mike Lauren", "New York", "mlauren@xyz.com", 41)))); |
| 32 | + |
| 33 | + StepVerifier.create(deleteAndInsert).expectNextCount(4).verifyComplete(); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + public void givenRecordsAreInserted_whenDbIsQueried_thenShouldIncludeNewRecords() { |
| 38 | + |
| 39 | + Mono<Long> saveAndCount = repository.count() |
| 40 | + .doOnNext(System.out::println) |
| 41 | + .thenMany(repository.saveAll(Flux.just(new Employee(325, "Kim Jones", "Florida", "kjones@xyz.com", 42), |
| 42 | + new Employee(654, "Tom Moody", "New Hampshire", "tmoody@xyz.com", 44)))) |
| 43 | + .last() |
| 44 | + .flatMap(v -> repository.count()) |
| 45 | + .doOnNext(System.out::println); |
| 46 | + |
| 47 | + StepVerifier.create(saveAndCount).expectNext(6L).verifyComplete(); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void givenAgeForFilter_whenDbIsQueried_thenShouldReturnFilteredRecords() { |
| 52 | + StepVerifier.create(repository.findByAgeGreaterThan(35)).expectNextCount(2).verifyComplete(); |
| 53 | + } |
| 54 | + |
| 55 | +} |
0 commit comments