Skip to content

Commit

Permalink
finished setting up test that reproduces the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
lpandzic committed Mar 11, 2024
1 parent ae89348 commit 0309679
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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<Person> givenSavedPerson(String firstName, String lastName) {
return repository.save(new Person(null, firstName, lastName));
}

private Predicate<? super Person> person(String firstName, String lastName) {
return person -> {
BDDAssertions.then(person).isEqualTo(new Person(person.id(), firstName, lastName));
return true;
};
}
}
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 0309679

Please sign in to comment.