|
1 | 1 | package com.infobip.spring.data.r2dbc.mysql;
|
2 | 2 |
|
3 |
| -import com.infobip.spring.data.r2dbc.TestBase; |
| 3 | +import com.infobip.spring.data.r2dbc.*; |
| 4 | +import lombok.AllArgsConstructor; |
| 5 | +import org.assertj.core.api.BDDAssertions; |
4 | 6 | import org.junit.jupiter.api.Test;
|
5 | 7 | import org.springframework.test.context.*;
|
| 8 | +import reactor.core.publisher.Mono; |
| 9 | +import reactor.test.StepVerifier; |
6 | 10 |
|
| 11 | +import java.util.function.Predicate; |
| 12 | + |
| 13 | +import static com.infobip.spring.data.r2dbc.QPerson.person; |
| 14 | + |
| 15 | +@AllArgsConstructor |
7 | 16 | @ContextConfiguration(loader = MssqlExclusionContextLoader.class)
|
8 | 17 | @ActiveProfiles("mysql")
|
9 | 18 | @TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL)
|
10 | 19 | public class MysqlNamedParametersSupportTest extends TestBase {
|
11 | 20 |
|
| 21 | + private final PersonRepository repository; |
| 22 | + |
12 | 23 | @Test
|
13 | 24 | void shouldNotFail() {
|
14 | 25 | // given
|
| 26 | + var given = given(givenSavedPerson("John", "Doe"), |
| 27 | + givenSavedPerson("Johny", "Roe"), |
| 28 | + givenSavedPerson("Jane", "Doe"), |
| 29 | + givenSavedPerson("John", "Roe"), |
| 30 | + givenSavedPerson("Janie", "Doe")); |
| 31 | + |
15 | 32 | // when
|
| 33 | + var actual = given.thenMany(repository.query(query -> query.select(repository.entityProjection()) |
| 34 | + .from(person) |
| 35 | + .where(person.firstName.in("John", "Jane")) |
| 36 | + .orderBy(person.firstName.asc(), |
| 37 | + person.lastName.asc()) |
| 38 | + .limit(1) |
| 39 | + .offset(1)) |
| 40 | + .all()); |
| 41 | + |
16 | 42 | // then
|
| 43 | + StepVerifier.create(actual) |
| 44 | + .expectNextMatches(person("John", "Doe")) |
| 45 | + .verifyComplete(); |
| 46 | + } |
| 47 | + |
| 48 | + private Mono<Person> givenSavedPerson(String firstName, String lastName) { |
| 49 | + return repository.save(new Person(null, firstName, lastName)); |
| 50 | + } |
| 51 | + |
| 52 | + private Predicate<? super Person> person(String firstName, String lastName) { |
| 53 | + return person -> { |
| 54 | + BDDAssertions.then(person).isEqualTo(new Person(person.id(), firstName, lastName)); |
| 55 | + return true; |
| 56 | + }; |
17 | 57 | }
|
18 | 58 | }
|
0 commit comments