16
16
package org .springframework .data .r2dbc .repository ;
17
17
18
18
import io .r2dbc .spi .ConnectionFactory ;
19
+ import lombok .Getter ;
20
+ import lombok .NoArgsConstructor ;
21
+ import lombok .Setter ;
19
22
import reactor .core .publisher .Flux ;
20
23
import reactor .core .publisher .Mono ;
21
24
import reactor .test .StepVerifier ;
22
25
26
+ import java .util .Arrays ;
27
+
23
28
import javax .sql .DataSource ;
24
29
25
30
import org .junit .Test ;
26
31
import org .junit .runner .RunWith ;
32
+ import static org .assertj .core .api .Assertions .*;
27
33
28
34
import org .springframework .beans .factory .annotation .Autowired ;
29
35
import org .springframework .context .annotation .Bean ;
30
36
import org .springframework .context .annotation .ComponentScan .Filter ;
31
37
import org .springframework .context .annotation .Configuration ;
32
38
import org .springframework .context .annotation .FilterType ;
39
+ import org .springframework .data .annotation .Id ;
33
40
import org .springframework .data .r2dbc .config .AbstractR2dbcConfiguration ;
34
41
import org .springframework .data .r2dbc .repository .config .EnableR2dbcRepositories ;
35
42
import org .springframework .data .r2dbc .repository .support .R2dbcRepositoryFactory ;
36
43
import org .springframework .data .r2dbc .testing .H2TestSupport ;
44
+ import org .springframework .data .relational .core .mapping .Table ;
45
+ import org .springframework .data .repository .reactive .ReactiveCrudRepository ;
37
46
import org .springframework .test .context .ContextConfiguration ;
38
47
import org .springframework .test .context .junit4 .SpringRunner ;
39
48
47
56
public class H2R2dbcRepositoryIntegrationTests extends AbstractR2dbcRepositoryIntegrationTests {
48
57
49
58
@ Autowired private H2LegoSetRepository repository ;
59
+ @ Autowired private IdOnlyEntityRepository idOnlyEntityRepository ;
50
60
51
61
@ Configuration
52
62
@ EnableR2dbcRepositories (considerNestedRepositories = true ,
53
- includeFilters = @ Filter (classes = H2LegoSetRepository .class , type = FilterType .ASSIGNABLE_TYPE ))
63
+ includeFilters = @ Filter (classes = { H2LegoSetRepository .class , IdOnlyEntityRepository . class } , type = FilterType .ASSIGNABLE_TYPE ))
54
64
static class IntegrationTestConfiguration extends AbstractR2dbcConfiguration {
55
65
56
66
@ Bean
@@ -60,6 +70,17 @@ public ConnectionFactory connectionFactory() {
60
70
}
61
71
}
62
72
73
+ interface IdOnlyEntityRepository extends ReactiveCrudRepository <IdOnlyEntity , Integer > {
74
+ }
75
+
76
+ @ Getter
77
+ @ Setter
78
+ @ Table ("id_only" )
79
+ @ NoArgsConstructor
80
+ static class IdOnlyEntity {
81
+ @ Id Integer id ;
82
+ }
83
+
63
84
@ Override
64
85
protected DataSource createDataSource () {
65
86
return H2TestSupport .createDataSource ();
@@ -112,6 +133,18 @@ public void shouldNotReturnUpdateCount() {
112
133
repository .updateManualAndReturnNothing (42 ).as (StepVerifier ::create ).verifyComplete ();
113
134
}
114
135
136
+ @ Test
137
+ public void shouldInsertIdOnlyEntity () {
138
+ this .jdbc .execute ("CREATE TABLE ID_ONLY(id serial CONSTRAINT id_only_pk PRIMARY KEY)" );
139
+
140
+ IdOnlyEntity entity1 = new IdOnlyEntity ();
141
+ idOnlyEntityRepository .saveAll (Arrays .asList (entity1 ))
142
+ .as (StepVerifier ::create ) //
143
+ .consumeNextWith ( actual -> {
144
+ assertThat (actual .getId ()).isNotNull ();
145
+ }).verifyComplete ();
146
+ }
147
+
115
148
interface H2LegoSetRepository extends LegoSetRepository {
116
149
117
150
@ Override
0 commit comments