diff --git a/infobip-spring-data-r2dbc-querydsl/src/test/java/com/infobip/spring/data/r2dbc/mysql/MysqlNamedParametersSupportTest.java b/infobip-spring-data-r2dbc-querydsl/src/test/java/com/infobip/spring/data/r2dbc/mysql/MysqlNamedParametersSupportTest.java index 2896395..829684f 100644 --- a/infobip-spring-data-r2dbc-querydsl/src/test/java/com/infobip/spring/data/r2dbc/mysql/MysqlNamedParametersSupportTest.java +++ b/infobip-spring-data-r2dbc-querydsl/src/test/java/com/infobip/spring/data/r2dbc/mysql/MysqlNamedParametersSupportTest.java @@ -1,18 +1,58 @@ package com.infobip.spring.data.r2dbc.mysql; -import com.infobip.spring.data.r2dbc.TestBase; +import com.infobip.spring.data.r2dbc.*; +import lombok.AllArgsConstructor; +import org.assertj.core.api.BDDAssertions; import org.junit.jupiter.api.Test; import org.springframework.test.context.*; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; +import java.util.function.Predicate; + +import static com.infobip.spring.data.r2dbc.QPerson.person; + +@AllArgsConstructor @ContextConfiguration(loader = MssqlExclusionContextLoader.class) @ActiveProfiles("mysql") @TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL) public class MysqlNamedParametersSupportTest extends TestBase { + private final PersonRepository repository; + @Test void shouldNotFail() { // given + var given = given(givenSavedPerson("John", "Doe"), + givenSavedPerson("Johny", "Roe"), + givenSavedPerson("Jane", "Doe"), + givenSavedPerson("John", "Roe"), + givenSavedPerson("Janie", "Doe")); + // when + var actual = given.thenMany(repository.query(query -> query.select(repository.entityProjection()) + .from(person) + .where(person.firstName.in("John", "Jane")) + .orderBy(person.firstName.asc(), + person.lastName.asc()) + .limit(1) + .offset(1)) + .all()); + // then + StepVerifier.create(actual) + .expectNextMatches(person("John", "Doe")) + .verifyComplete(); + } + + private Mono givenSavedPerson(String firstName, String lastName) { + return repository.save(new Person(null, firstName, lastName)); + } + + private Predicate person(String firstName, String lastName) { + return person -> { + BDDAssertions.then(person).isEqualTo(new Person(person.id(), firstName, lastName)); + return true; + }; } } diff --git a/infobip-spring-data-r2dbc-querydsl/src/test/resources/db/migration/mysql/V1_0_0__base_schema.sql b/infobip-spring-data-r2dbc-querydsl/src/test/resources/db/migration/mysql/V1_0_0__base_schema.sql index c20fc1a..9649848 100644 --- a/infobip-spring-data-r2dbc-querydsl/src/test/resources/db/migration/mysql/V1_0_0__base_schema.sql +++ b/infobip-spring-data-r2dbc-querydsl/src/test/resources/db/migration/mysql/V1_0_0__base_schema.sql @@ -1,30 +1,30 @@ -CREATE TABLE Person ( +CREATE TABLE person ( Id BIGINT AUTO_INCREMENT, FirstName NVARCHAR(20) NOT NULL, LastName NVARCHAR(50) NOT NULL, CONSTRAINT PK_Person PRIMARY KEY (Id) ); -CREATE TABLE PersonSettings ( +CREATE TABLE personsettings ( Id BIGINT AUTO_INCREMENT, PersonId BIGINT NOT NULL, CONSTRAINT PK_PersonSettings PRIMARY KEY (Id), - CONSTRAINT FK_PersonSettings_PersonId FOREIGN KEY (PersonId) REFERENCES Person(Id) ON DELETE CASCADE + CONSTRAINT FK_PersonSettings_PersonId FOREIGN KEY (PersonId) REFERENCES person(Id) ON DELETE CASCADE ); -CREATE TABLE NoArgsEntity ( +CREATE TABLE noargsentity ( Id BIGINT AUTO_INCREMENT, Value NVARCHAR(20), CONSTRAINT PK_NoArgsEntity PRIMARY KEY (Id) ); -CREATE TABLE TransientEntity ( +CREATE TABLE transiententity ( Id BIGINT AUTO_INCREMENT, Value NVARCHAR(20), CONSTRAINT PK_TransientEntity PRIMARY KEY (Id) ); -CREATE TABLE PagingEntity ( +CREATE TABLE pagingentity ( Id BIGINT AUTO_INCREMENT, Value NVARCHAR(20), CONSTRAINT PK_PagingEntity PRIMARY KEY (Id)