33
33
import org .springframework .data .convert .ReadingConverter ;
34
34
import org .springframework .data .convert .WritingConverter ;
35
35
import org .springframework .data .r2dbc .convert .EnumWriteSupport ;
36
+ import org .springframework .data .r2dbc .convert .MappingR2dbcConverter ;
37
+ import org .springframework .data .r2dbc .convert .R2dbcCustomConversions ;
36
38
import org .springframework .data .r2dbc .core .StatementMapper .InsertSpec ;
37
39
import org .springframework .data .r2dbc .dialect .PostgresDialect ;
38
40
import org .springframework .data .r2dbc .mapping .OutboundRow ;
41
+ import org .springframework .data .r2dbc .mapping .R2dbcMappingContext ;
39
42
import org .springframework .data .relational .core .sql .SqlIdentifier ;
40
43
import org .springframework .r2dbc .core .Parameter ;
41
44
import org .springframework .r2dbc .core .PreparedOperation ;
45
48
* {@link PostgresDialect} specific tests for {@link ReactiveDataAccessStrategy}.
46
49
*
47
50
* @author Mark Paluch
51
+ * @author Jens Schauder
48
52
*/
49
53
public class PostgresReactiveDataAccessStrategyTests extends ReactiveDataAccessStrategyTestSupport {
50
54
51
- private final ReactiveDataAccessStrategy strategy = new DefaultReactiveDataAccessStrategy (PostgresDialect .INSTANCE ,
52
- Arrays .asList (DurationToIntervalConverter .INSTANCE , IntervalToDurationConverter .INSTANCE ));
55
+ private R2dbcMappingContext context ;
56
+ private final ReactiveDataAccessStrategy strategy ;
57
+
58
+ {
59
+ context = new R2dbcMappingContext ();
60
+ context .setForceQuote (false );
61
+
62
+ DefaultReactiveDataAccessStrategy strategy1 = createReactiveDataAccessStrategy (DurationToIntervalConverter .INSTANCE ,
63
+ IntervalToDurationConverter .INSTANCE );
64
+ strategy = strategy1 ;
65
+ }
66
+
67
+ private DefaultReactiveDataAccessStrategy createReactiveDataAccessStrategy (Object ... converters ) {
68
+ R2dbcCustomConversions customConversions = R2dbcCustomConversions .of (PostgresDialect .INSTANCE , converters );
69
+
70
+ MappingR2dbcConverter converter = new MappingR2dbcConverter (context , customConversions );
71
+ DefaultReactiveDataAccessStrategy strategy1 = new DefaultReactiveDataAccessStrategy (PostgresDialect .INSTANCE ,
72
+ converter );
73
+ return strategy1 ;
74
+ }
53
75
54
76
@ Override
55
77
protected ReactiveDataAccessStrategy getStrategy () {
78
+
56
79
return strategy ;
57
80
}
58
81
@@ -98,8 +121,6 @@ void shouldConvertCollectionToArray() {
98
121
@ Test // gh-139
99
122
void shouldConvertToArray () {
100
123
101
- DefaultReactiveDataAccessStrategy strategy = new DefaultReactiveDataAccessStrategy (PostgresDialect .INSTANCE );
102
-
103
124
WithArray withArray = new WithArray ();
104
125
withArray .stringArray = new String [] { "hello" , "world" };
105
126
withArray .stringList = Arrays .asList ("hello" , "world" );
@@ -113,8 +134,7 @@ void shouldConvertToArray() {
113
134
@ Test // gh-139
114
135
void shouldApplyCustomConversion () {
115
136
116
- DefaultReactiveDataAccessStrategy strategy = new DefaultReactiveDataAccessStrategy (PostgresDialect .INSTANCE ,
117
- Collections .singletonList (MyObjectsToStringConverter .INSTANCE ));
137
+ DefaultReactiveDataAccessStrategy strategy = createReactiveDataAccessStrategy (MyObjectsToStringConverter .INSTANCE );
118
138
119
139
WithConversion withConversion = new WithConversion ();
120
140
withConversion .myObjects = Arrays .asList (new MyObject ("one" ), new MyObject ("two" ));
@@ -127,8 +147,7 @@ void shouldApplyCustomConversion() {
127
147
@ Test // gh-139
128
148
void shouldApplyCustomConversionForNull () {
129
149
130
- DefaultReactiveDataAccessStrategy strategy = new DefaultReactiveDataAccessStrategy (PostgresDialect .INSTANCE ,
131
- Collections .singletonList (MyObjectsToStringConverter .INSTANCE ));
150
+ DefaultReactiveDataAccessStrategy strategy = createReactiveDataAccessStrategy (MyObjectsToStringConverter .INSTANCE );
132
151
133
152
WithConversion withConversion = new WithConversion ();
134
153
withConversion .myObjects = null ;
@@ -152,8 +171,6 @@ void shouldApplyCustomConversionForEmptyList() {
152
171
@ Test // gh-252, gh-593
153
172
void shouldConvertCollectionOfEnumToString () {
154
173
155
- DefaultReactiveDataAccessStrategy strategy = new DefaultReactiveDataAccessStrategy (PostgresDialect .INSTANCE );
156
-
157
174
WithEnumCollections withEnums = new WithEnumCollections ();
158
175
withEnums .enumSet = EnumSet .of (MyEnum .ONE , MyEnum .TWO );
159
176
withEnums .enumList = Arrays .asList (MyEnum .ONE , MyEnum .TWO );
@@ -170,8 +187,6 @@ void shouldConvertCollectionOfEnumToString() {
170
187
@ Test // gh-593
171
188
void shouldCorrectlyWriteConvertedEnumNullValues () {
172
189
173
- DefaultReactiveDataAccessStrategy strategy = new DefaultReactiveDataAccessStrategy (PostgresDialect .INSTANCE );
174
-
175
190
WithEnumCollections withEnums = new WithEnumCollections ();
176
191
177
192
OutboundRow outboundRow = strategy .getOutboundRow (withEnums );
@@ -185,8 +200,6 @@ void shouldCorrectlyWriteConvertedEnumNullValues() {
185
200
@ Test // gh-1544
186
201
void shouldCorrectlyWriteConvertedEmptyEnumCollections () {
187
202
188
- DefaultReactiveDataAccessStrategy strategy = new DefaultReactiveDataAccessStrategy (PostgresDialect .INSTANCE );
189
-
190
203
WithEnumCollections withEnums = new WithEnumCollections ();
191
204
withEnums .enumArray = new MyEnum [0 ];
192
205
withEnums .enumList = Collections .emptyList ();
@@ -203,8 +216,7 @@ void shouldCorrectlyWriteConvertedEmptyEnumCollections() {
203
216
@ Test // gh-593
204
217
void shouldConvertCollectionOfEnumNatively () {
205
218
206
- DefaultReactiveDataAccessStrategy strategy = new DefaultReactiveDataAccessStrategy (PostgresDialect .INSTANCE ,
207
- Collections .singletonList (new MyEnumSupport ()));
219
+ DefaultReactiveDataAccessStrategy strategy = createReactiveDataAccessStrategy (new MyEnumSupport ());
208
220
209
221
WithEnumCollections withEnums = new WithEnumCollections ();
210
222
withEnums .enumSet = EnumSet .of (MyEnum .ONE , MyEnum .TWO );
@@ -222,8 +234,7 @@ void shouldConvertCollectionOfEnumNatively() {
222
234
@ Test // gh-593
223
235
void shouldCorrectlyWriteNativeEnumNullValues () {
224
236
225
- DefaultReactiveDataAccessStrategy strategy = new DefaultReactiveDataAccessStrategy (PostgresDialect .INSTANCE ,
226
- Collections .singletonList (new MyEnumSupport ()));
237
+ DefaultReactiveDataAccessStrategy strategy = createReactiveDataAccessStrategy (new MyEnumSupport ());
227
238
228
239
WithEnumCollections withEnums = new WithEnumCollections ();
229
240
0 commit comments