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