Skip to content

Commit fe928b9

Browse files
committed
added example for issue 105
1 parent 7f8086a commit fe928b9

File tree

12 files changed

+238
-0
lines changed

12 files changed

+238
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.infobip</groupId>
9+
<artifactId>infobip-spring-data-querydsl</artifactId>
10+
<version>9.0.8-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>infobip-spring-data-r2dbc-custom-fragment</artifactId>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>${project.groupId}</groupId>
18+
<artifactId>infobip-spring-data-r2dbc-querydsl-boot-starter</artifactId>
19+
<version>${project.version}</version>
20+
</dependency>
21+
22+
<!--TEST-->
23+
<dependency>
24+
<groupId>io.r2dbc</groupId>
25+
<artifactId>r2dbc-mssql</artifactId>
26+
<scope>test</scope>
27+
</dependency>
28+
29+
<dependency>
30+
<groupId>io.projectreactor</groupId>
31+
<artifactId>reactor-test</artifactId>
32+
<scope>test</scope>
33+
</dependency>
34+
35+
<dependency>
36+
<groupId>com.zaxxer</groupId>
37+
<artifactId>HikariCP</artifactId>
38+
<scope>test</scope>
39+
</dependency>
40+
</dependencies>
41+
42+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.infobip.test;
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication;
4+
import org.springframework.boot.builder.SpringApplicationBuilder;
5+
6+
@SpringBootApplication
7+
public class Main {
8+
9+
public static void main(String[] args) {
10+
11+
new SpringApplicationBuilder(Main.class).run(args);
12+
}
13+
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.infobip.test;
2+
3+
import lombok.With;
4+
import org.springframework.data.annotation.Id;
5+
6+
public record Person(
7+
@With
8+
@Id
9+
Long id,
10+
11+
String firstName,
12+
13+
String lastName
14+
) {
15+
16+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.infobip.test;
2+
3+
import com.infobip.spring.data.r2dbc.QuerydslR2dbcRepository;
4+
5+
public interface PersonRepository extends QuerydslR2dbcRepository<Person, Long>, ReactivePagingRepository<Person> {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.infobip.test;
2+
3+
import lombok.AllArgsConstructor;
4+
import org.junit.jupiter.api.Test;
5+
6+
@AllArgsConstructor
7+
public class QuerydslR2dbcRepositoryTest extends TestBase {
8+
9+
private final PersonRepository repository;
10+
11+
@Test
12+
void shouldSaveWithVarArgs() {
13+
repository.simplePaging("");
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.infobip.test;
2+
3+
import reactor.core.publisher.Mono;
4+
5+
public interface ReactivePagingRepository<T> {
6+
7+
Mono<T> simplePaging(String string);
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.infobip.test;
2+
3+
import com.infobip.spring.data.r2dbc.QuerydslR2dbcFragment;
4+
import org.springframework.context.annotation.Lazy;
5+
import reactor.core.publisher.Mono;
6+
7+
public class ReactivePagingRepositoryImpl<T> implements ReactivePagingRepository<T> {
8+
9+
private final QuerydslR2dbcFragment querydslR2dbcFragment;
10+
11+
public ReactivePagingRepositoryImpl(@Lazy QuerydslR2dbcFragment querydslR2dbcFragment) {
12+
this.querydslR2dbcFragment = querydslR2dbcFragment;
13+
}
14+
15+
@Override
16+
public Mono<T> simplePaging(String string) {
17+
throw new UnsupportedOperationException();
18+
}
19+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.infobip.test;
2+
3+
import org.junit.jupiter.api.AfterEach;
4+
import org.junit.jupiter.api.TestInstance;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.test.context.SpringBootTest;
7+
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
8+
import org.springframework.test.context.ActiveProfiles;
9+
import org.springframework.test.context.TestConstructor;
10+
import reactor.core.publisher.Flux;
11+
import reactor.core.publisher.Mono;
12+
13+
import java.time.Duration;
14+
import java.util.List;
15+
import java.util.stream.Collectors;
16+
import java.util.stream.Stream;
17+
18+
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
19+
20+
@ActiveProfiles("mssql")
21+
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL)
22+
@TestInstance(PER_CLASS)
23+
@SpringBootTest(classes = Main.class)
24+
public abstract class TestBase {
25+
26+
@Autowired
27+
private List<ReactiveCrudRepository<?, ?>> repositories;
28+
29+
@AfterEach
30+
public void clearRepositories() {
31+
block(Flux.concat(repositories.stream()
32+
.map(ReactiveCrudRepository::deleteAll)
33+
.collect(Collectors.toList()))
34+
.collectList());
35+
}
36+
37+
private <T> T block(Mono<T> mono) {
38+
return mono.block(Duration.ofSeconds(10));
39+
}
40+
41+
<T> List<T> block(Flux<T> flux) {
42+
return block(flux.collectList());
43+
}
44+
45+
protected Mono<Void> given(Mono<?>... ts) {
46+
return Flux.concat(Stream.of(ts).collect(Collectors.toList())).last().then();
47+
}
48+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.infobip.test;
2+
3+
import lombok.AllArgsConstructor;
4+
import org.flywaydb.core.Flyway;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
import org.springframework.core.env.Environment;
8+
9+
@AllArgsConstructor
10+
@Configuration
11+
public class TestConfiguration {
12+
13+
private final Environment env;
14+
15+
@Bean(initMethod = "migrate")
16+
public Flyway flyway() {
17+
return new Flyway(Flyway.configure()
18+
.baselineOnMigrate(true)
19+
.locations(env.getRequiredProperty("spring.flyway.locations"))
20+
.dataSource(
21+
env.getRequiredProperty("spring.flyway.url"),
22+
env.getRequiredProperty("spring.flyway.username"),
23+
env.getRequiredProperty("spring.flyway.password"))
24+
);
25+
}
26+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
spring:
2+
r2dbc:
3+
url: r2dbc:pool:mssql://<host>:<port>/InfobipSpringDataJdbcQuerydslTest
4+
flyway:
5+
locations: "classpath:db/migration/mssql"
6+
url: jdbc:sqlserver://<host>:<port>;database=InfobipSpringDataJdbcQuerydslTest;trustServerCertificate=true

0 commit comments

Comments
 (0)