Skip to content

Commit

Permalink
fixed test, probably broke other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lpandzic committed Mar 12, 2024
1 parent c9e724b commit ad55856
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.infobip.spring.data.r2dbc.mysql;

import com.infobip.spring.data.r2dbc.EnableQuerydslR2dbcRepositories;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;

@EnableQuerydslR2dbcRepositories
@SpringBootApplication
public class Main {

public static void main(String[] args) {

new SpringApplicationBuilder(Main.class).run(args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.infobip.spring.data.r2dbc.mysql;

import com.infobip.spring.data.r2dbc.TestConfiguration;
import org.springframework.context.annotation.*;

@Import(TestConfiguration.class)
@Profile("mysql")
@Configuration
public class MySqlConfiguration {
}
Original file line number Diff line number Diff line change
@@ -1,58 +1,29 @@
package com.infobip.spring.data.r2dbc.mysql;

import com.infobip.spring.data.r2dbc.*;
import com.infobip.spring.data.r2dbc.TestBase;
import lombok.AllArgsConstructor;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.r2dbc.core.DatabaseClient;
import org.springframework.test.context.*;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

import java.time.Duration;
import java.util.function.Predicate;

import static com.infobip.spring.data.r2dbc.QPerson.person;
import static com.infobip.spring.data.r2dbc.mysql.QPerson.person;
import static org.assertj.core.api.BDDAssertions.then;

@AllArgsConstructor
@ContextConfiguration(loader = MssqlExclusionContextLoader.class)
@ActiveProfiles("mysql")
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL)
@SpringBootTest(classes = Main.class)
public class MysqlNamedParametersSupportTest extends TestBase {

private final PersonRepository repository;
private final DatabaseClient databaseClient;

@Test
void shouldNotFailCustomQuery() {
// given
var given = given(givenSavedPerson("John", "Doe"),
givenSavedPerson("Johny", "Roe"),
givenSavedPerson("Jane", "Doe"),
givenSavedPerson("John", "Roe"),
givenSavedPerson("Janie", "Doe")).block(Duration.ofSeconds(10));

// when
var actual = databaseClient.sql("""
select *
from person
where FirstName IN (?, ?)
order by FirstName ASC, LastName
ASC LIMIT ? OFFSET ?
""")
.bind(0, "John")
.bind(1, "Jane")
.bind(2, 1)
.bind(3, 1)
.fetch()
.all()
.collectList();

// then
var all = actual.block(Duration.ofSeconds(10));
then(all).isNotEmpty();
}

@Test
void shouldNotFailQuerydslQuery() {
// given
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.infobip.spring.data.r2dbc.mysql;

import lombok.With;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;

@Table("person")
public record Person(
@With
@Id
Long id,

String firstName,

String lastName
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.infobip.spring.data.r2dbc.mysql;

import com.infobip.spring.data.r2dbc.QuerydslR2dbcRepository;

public interface PersonRepository extends QuerydslR2dbcRepository<Person, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,4 @@ CREATE TABLE person (
FirstName NVARCHAR(20) NOT NULL,
LastName NVARCHAR(50) NOT NULL,
CONSTRAINT PK_Person PRIMARY KEY (Id)
);

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
);

CREATE TABLE noargsentity (
Id BIGINT AUTO_INCREMENT,
Value NVARCHAR(20),
CONSTRAINT PK_NoArgsEntity PRIMARY KEY (Id)
);

CREATE TABLE transiententity (
Id BIGINT AUTO_INCREMENT,
Value NVARCHAR(20),
CONSTRAINT PK_TransientEntity PRIMARY KEY (Id)
);

CREATE TABLE pagingentity (
Id BIGINT AUTO_INCREMENT,
Value NVARCHAR(20),
CONSTRAINT PK_PagingEntity PRIMARY KEY (Id)
);

CREATE TABLE sorting_entity (
id BIGINT AUTO_INCREMENT,
foo_bar NVARCHAR(20),
CONSTRAINT PK_sorting_entity PRIMARY KEY (id)
);

0 comments on commit ad55856

Please sign in to comment.