|
17 | 17 |
|
18 | 18 | import static org.assertj.core.api.Assertions.*; |
19 | 19 |
|
20 | | -import example.springdata.couchbase.model.Airline; |
21 | | -import example.springdata.couchbase.util.CouchbaseAvailableRule; |
22 | | -import reactor.core.publisher.Mono; |
23 | | -import reactor.test.StepVerifier; |
| 20 | +import org.junit.jupiter.api.BeforeEach; |
| 21 | +import org.junit.jupiter.api.Test; |
24 | 22 |
|
25 | | -import org.junit.Before; |
26 | | -import org.junit.ClassRule; |
27 | | -import org.junit.Test; |
28 | | -import org.junit.runner.RunWith; |
29 | 23 | import org.springframework.beans.factory.annotation.Autowired; |
30 | 24 | import org.springframework.boot.test.context.SpringBootTest; |
31 | 25 | import org.springframework.data.couchbase.core.CouchbaseOperations; |
32 | | -import org.springframework.test.context.junit4.SpringRunner; |
| 26 | + |
| 27 | +import example.springdata.couchbase.model.Airline; |
| 28 | +import example.springdata.couchbase.util.EnabledOnCouchbaseAvailable; |
| 29 | +import reactor.core.publisher.Mono; |
| 30 | +import reactor.test.StepVerifier; |
33 | 31 |
|
34 | 32 | /** |
35 | 33 | * Integration tests showing basic CRUD operations through {@link ReactiveAirlineRepository} |
36 | 34 | * |
37 | 35 | * @author Mark Paluch |
38 | 36 | */ |
39 | | -@RunWith(SpringRunner.class) |
40 | 37 | @SpringBootTest |
| 38 | +@EnabledOnCouchbaseAvailable |
41 | 39 | public class ReactiveAirlineRepositoryIntegrationTests { |
42 | 40 |
|
43 | | - @ClassRule // |
44 | | - public static CouchbaseAvailableRule COUCHBASE = CouchbaseAvailableRule.onLocalhost(); |
45 | | - |
46 | | - @Autowired ReactiveAirlineRepository airlineRepository; |
47 | | - |
48 | | - @Autowired CouchbaseOperations couchbaseOperations; |
49 | | - |
50 | | - @Before |
51 | | - public void before() { |
52 | | - if (couchbaseOperations.existsById().one("LH")) { |
53 | | - couchbaseOperations.removeById().one("LH"); |
54 | | - } |
55 | | - } |
56 | | - |
57 | | - /** |
58 | | - * The derived query executes a N1QL query emitting a single element. |
59 | | - */ |
60 | | - @Test |
61 | | - public void shouldFindAirlineN1ql() { |
62 | | - |
63 | | - airlineRepository.findByIata("TQ") // |
64 | | - .as(StepVerifier::create) // |
65 | | - .assertNext(it -> { |
66 | | - assertThat(it.getCallsign()).isEqualTo("TXW"); |
67 | | - }).verifyComplete(); |
68 | | - } |
69 | | - |
70 | | - /** |
71 | | - * The derived query executes a N1QL query and the emitted element is used to invoke |
72 | | - * {@link org.springframework.data.repository.reactive.ReactiveCrudRepository#findById(Object)} for an Id-based |
73 | | - * lookup. Queries without a result do not emit a value. |
74 | | - */ |
75 | | - @Test |
76 | | - public void shouldFindById() { |
77 | | - |
78 | | - Mono<Airline> airline = airlineRepository.findByIata("TQ") // |
79 | | - .map(Airline::getId) // |
80 | | - .flatMap(airlineRepository::findById); |
81 | | - |
82 | | - airline.as(StepVerifier::create) // |
83 | | - .assertNext(it -> { |
84 | | - |
85 | | - assertThat(it.getCallsign()).isEqualTo("TXW"); |
86 | | - }).verifyComplete(); |
87 | | - |
88 | | - } |
89 | | - |
90 | | - /** |
91 | | - * Find all {@link Airline}s applying the {@code airlines/all} view. |
92 | | - */ |
93 | | - @Test |
94 | | - public void shouldFindAll() { |
95 | | - airlineRepository.findAllBy().count() // |
96 | | - .as(StepVerifier::create) // |
97 | | - .assertNext(count -> { |
98 | | - |
99 | | - assertThat(count).isGreaterThan(100); |
100 | | - }).verifyComplete(); |
101 | | - } |
102 | | - |
103 | | - /** |
104 | | - * Created elements are emitted by the |
105 | | - * {@link org.springframework.data.repository.reactive.ReactiveCrudRepository#save(Object)} method. |
106 | | - */ |
107 | | - @Test |
108 | | - public void shouldCreateAirline() { |
109 | | - |
110 | | - Airline airline = new Airline(); |
111 | | - |
112 | | - airline.setId("LH"); |
113 | | - airline.setIata("LH"); |
114 | | - airline.setIcao("DLH"); |
115 | | - airline.setCallsign("Lufthansa"); |
116 | | - airline.setName("Lufthansa"); |
117 | | - airline.setCountry("Germany"); |
118 | | - |
119 | | - Mono<Airline> airlineMono = airlineRepository.save(airline) // |
120 | | - .map(Airline::getId) // |
121 | | - .flatMap(airlineRepository::findById); |
122 | | - |
123 | | - airlineMono.as(StepVerifier::create) // |
124 | | - .expectNext(airline) // |
125 | | - .verifyComplete(); |
126 | | - } |
| 41 | + @Autowired |
| 42 | + ReactiveAirlineRepository airlineRepository; |
| 43 | + |
| 44 | + @Autowired |
| 45 | + CouchbaseOperations couchbaseOperations; |
| 46 | + |
| 47 | + @BeforeEach |
| 48 | + public void before() { |
| 49 | + if (couchbaseOperations.existsById().one("LH")) { |
| 50 | + couchbaseOperations.removeById().one("LH"); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * The derived query executes a N1QL query emitting a single element. |
| 56 | + */ |
| 57 | + @Test |
| 58 | + public void shouldFindAirlineN1ql() { |
| 59 | + |
| 60 | + airlineRepository.findByIata("TQ") // |
| 61 | + .as(StepVerifier::create) // |
| 62 | + .assertNext(it -> { |
| 63 | + assertThat(it.getCallsign()).isEqualTo("TXW"); |
| 64 | + }).verifyComplete(); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * The derived query executes a N1QL query and the emitted element is used to invoke |
| 69 | + * {@link org.springframework.data.repository.reactive.ReactiveCrudRepository#findById(Object)} for an Id-based lookup. |
| 70 | + * Queries without a result do not emit a value. |
| 71 | + */ |
| 72 | + @Test |
| 73 | + public void shouldFindById() { |
| 74 | + |
| 75 | + Mono<Airline> airline = airlineRepository.findByIata("TQ") // |
| 76 | + .map(Airline::getId) // |
| 77 | + .flatMap(airlineRepository::findById); |
| 78 | + |
| 79 | + airline.as(StepVerifier::create) // |
| 80 | + .assertNext(it -> { |
| 81 | + |
| 82 | + assertThat(it.getCallsign()).isEqualTo("TXW"); |
| 83 | + }).verifyComplete(); |
| 84 | + |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * Find all {@link Airline}s applying the {@code airlines/all} view. |
| 89 | + */ |
| 90 | + @Test |
| 91 | + public void shouldFindAll() { |
| 92 | + airlineRepository.findAllBy().count() // |
| 93 | + .as(StepVerifier::create) // |
| 94 | + .assertNext(count -> { |
| 95 | + |
| 96 | + assertThat(count).isGreaterThan(100); |
| 97 | + }).verifyComplete(); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Created elements are emitted by the |
| 102 | + * {@link org.springframework.data.repository.reactive.ReactiveCrudRepository#save(Object)} method. |
| 103 | + */ |
| 104 | + @Test |
| 105 | + public void shouldCreateAirline() { |
| 106 | + |
| 107 | + Airline airline = new Airline(); |
| 108 | + |
| 109 | + airline.setId("LH"); |
| 110 | + airline.setIata("LH"); |
| 111 | + airline.setIcao("DLH"); |
| 112 | + airline.setCallsign("Lufthansa"); |
| 113 | + airline.setName("Lufthansa"); |
| 114 | + airline.setCountry("Germany"); |
| 115 | + |
| 116 | + Mono<Airline> airlineMono = airlineRepository.save(airline) // |
| 117 | + .map(Airline::getId) // |
| 118 | + .flatMap(airlineRepository::findById); |
| 119 | + |
| 120 | + airlineMono.as(StepVerifier::create) // |
| 121 | + .expectNext(airline) // |
| 122 | + .verifyComplete(); |
| 123 | + } |
127 | 124 | } |
0 commit comments