-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.infobip</groupId> | ||
<artifactId>infobip-spring-data-querydsl</artifactId> | ||
<version>9.0.8-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>infobip-spring-data-r2dbc-custom-fragment</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>infobip-spring-data-r2dbc-querydsl-boot-starter</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<!--TEST--> | ||
<dependency> | ||
<groupId>io.r2dbc</groupId> | ||
<artifactId>r2dbc-mssql</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.projectreactor</groupId> | ||
<artifactId>reactor-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.zaxxer</groupId> | ||
<artifactId>HikariCP</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
14 changes: 14 additions & 0 deletions
14
infobip-spring-data-r2dbc-custom-fragment/src/test/java/com/infobip/test/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.infobip.test; | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
|
||
@SpringBootApplication | ||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
|
||
new SpringApplicationBuilder(Main.class).run(args); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
infobip-spring-data-r2dbc-custom-fragment/src/test/java/com/infobip/test/Person.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.infobip.test; | ||
|
||
import lombok.With; | ||
import org.springframework.data.annotation.Id; | ||
|
||
public record Person( | ||
@With | ||
@Id | ||
Long id, | ||
|
||
String firstName, | ||
|
||
String lastName | ||
) { | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
...ip-spring-data-r2dbc-custom-fragment/src/test/java/com/infobip/test/PersonRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.infobip.test; | ||
|
||
import com.infobip.spring.data.r2dbc.QuerydslR2dbcRepository; | ||
|
||
public interface PersonRepository extends QuerydslR2dbcRepository<Person, Long>, ReactivePagingRepository<Person> { | ||
} |
15 changes: 15 additions & 0 deletions
15
...ata-r2dbc-custom-fragment/src/test/java/com/infobip/test/QuerydslR2dbcRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.infobip.test; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@AllArgsConstructor | ||
public class QuerydslR2dbcRepositoryTest extends TestBase { | ||
|
||
private final PersonRepository repository; | ||
|
||
@Test | ||
void shouldSaveWithVarArgs() { | ||
repository.simplePaging(""); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...g-data-r2dbc-custom-fragment/src/test/java/com/infobip/test/ReactivePagingRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.infobip.test; | ||
|
||
import reactor.core.publisher.Mono; | ||
|
||
public interface ReactivePagingRepository<T> { | ||
|
||
Mono<T> simplePaging(String string); | ||
} |
19 changes: 19 additions & 0 deletions
19
...ta-r2dbc-custom-fragment/src/test/java/com/infobip/test/ReactivePagingRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.infobip.test; | ||
|
||
import com.infobip.spring.data.r2dbc.QuerydslR2dbcFragment; | ||
import org.springframework.context.annotation.Lazy; | ||
import reactor.core.publisher.Mono; | ||
|
||
public class ReactivePagingRepositoryImpl<T> implements ReactivePagingRepository<T> { | ||
|
||
private final QuerydslR2dbcFragment querydslR2dbcFragment; | ||
|
||
public ReactivePagingRepositoryImpl(@Lazy QuerydslR2dbcFragment querydslR2dbcFragment) { | ||
this.querydslR2dbcFragment = querydslR2dbcFragment; | ||
} | ||
|
||
@Override | ||
public Mono<T> simplePaging(String string) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
infobip-spring-data-r2dbc-custom-fragment/src/test/java/com/infobip/test/TestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.infobip.test; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.data.repository.reactive.ReactiveCrudRepository; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.TestConstructor; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; | ||
|
||
@ActiveProfiles("mssql") | ||
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL) | ||
@TestInstance(PER_CLASS) | ||
@SpringBootTest(classes = Main.class) | ||
public abstract class TestBase { | ||
|
||
@Autowired | ||
private List<ReactiveCrudRepository<?, ?>> repositories; | ||
|
||
@AfterEach | ||
public void clearRepositories() { | ||
block(Flux.concat(repositories.stream() | ||
.map(ReactiveCrudRepository::deleteAll) | ||
.collect(Collectors.toList())) | ||
.collectList()); | ||
} | ||
|
||
private <T> T block(Mono<T> mono) { | ||
return mono.block(Duration.ofSeconds(10)); | ||
} | ||
|
||
<T> List<T> block(Flux<T> flux) { | ||
return block(flux.collectList()); | ||
} | ||
|
||
protected Mono<Void> given(Mono<?>... ts) { | ||
return Flux.concat(Stream.of(ts).collect(Collectors.toList())).last().then(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...p-spring-data-r2dbc-custom-fragment/src/test/java/com/infobip/test/TestConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.infobip.test; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.flywaydb.core.Flyway; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.env.Environment; | ||
|
||
@AllArgsConstructor | ||
@Configuration | ||
public class TestConfiguration { | ||
|
||
private final Environment env; | ||
|
||
@Bean(initMethod = "migrate") | ||
public Flyway flyway() { | ||
return new Flyway(Flyway.configure() | ||
.baselineOnMigrate(true) | ||
.locations(env.getRequiredProperty("spring.flyway.locations")) | ||
.dataSource( | ||
env.getRequiredProperty("spring.flyway.url"), | ||
env.getRequiredProperty("spring.flyway.username"), | ||
env.getRequiredProperty("spring.flyway.password")) | ||
); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
infobip-spring-data-r2dbc-custom-fragment/src/test/resources/application-mssql.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
spring: | ||
r2dbc: | ||
url: r2dbc:pool:mssql://<host>:<port>/InfobipSpringDataJdbcQuerydslTest | ||
flyway: | ||
locations: "classpath:db/migration/mssql" | ||
url: jdbc:sqlserver://<host>:<port>;database=InfobipSpringDataJdbcQuerydslTest;trustServerCertificate=true |
37 changes: 37 additions & 0 deletions
37
...-data-r2dbc-custom-fragment/src/test/resources/db/migration/mssql/V1_0_0__base_schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
CREATE TABLE Person ( | ||
Id BIGINT IDENTITY, | ||
FirstName NVARCHAR(20) NOT NULL, | ||
LastName NVARCHAR(50) NOT NULL, | ||
CONSTRAINT PK_Person PRIMARY KEY (Id) | ||
); | ||
|
||
CREATE TABLE PersonSettings ( | ||
Id BIGINT IDENTITY, | ||
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 IDENTITY, | ||
Value NVARCHAR(20), | ||
CONSTRAINT PK_NoArgsEntity PRIMARY KEY (Id), | ||
); | ||
|
||
CREATE TABLE TransientEntity ( | ||
Id BIGINT IDENTITY, | ||
Value NVARCHAR(20), | ||
CONSTRAINT PK_TransientEntity PRIMARY KEY (Id), | ||
); | ||
|
||
CREATE TABLE PagingEntity ( | ||
Id BIGINT IDENTITY, | ||
Value NVARCHAR(20), | ||
CONSTRAINT PK_PagingEntity PRIMARY KEY (Id), | ||
); | ||
|
||
CREATE TABLE sorting_entity ( | ||
id BIGINT IDENTITY, | ||
foo_bar NVARCHAR(20), | ||
CONSTRAINT PK_sorting_entity PRIMARY KEY (id), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters