15
15
*/
16
16
package org .springframework .data .r2dbc .core ;
17
17
18
- import static org .assertj . core . api .Assertions .*;
18
+ import static org .springframework . data . r2dbc . testing .Assertions .*;
19
19
20
20
import lombok .RequiredArgsConstructor ;
21
21
33
33
import org .springframework .data .r2dbc .dialect .PostgresDialect ;
34
34
import org .springframework .data .r2dbc .mapping .OutboundRow ;
35
35
import org .springframework .data .relational .core .sql .SqlIdentifier ;
36
- import org .springframework .r2dbc .core .Parameter ;
37
36
38
37
/**
39
38
* {@link PostgresDialect} specific tests for {@link ReactiveDataAccessStrategy}.
@@ -54,26 +53,23 @@ void shouldConvertPrimitiveMultidimensionArrayToWrapper() {
54
53
55
54
OutboundRow row = strategy .getOutboundRow (new WithMultidimensionalArray (new int [][] { { 1 , 2 , 3 }, { 4 , 5 } }));
56
55
57
- assertThat (row .get (SqlIdentifier .unquoted ("myarray" )).hasValue ()).isTrue ();
58
- assertThat (row .get (SqlIdentifier .unquoted ("myarray" )).getValue ()).isInstanceOf (Integer [][].class );
56
+ assertThat (row ).withColumn ("myarray" ).hasValueInstanceOf (Integer [][].class );
59
57
}
60
58
61
59
@ Test // gh-161
62
60
void shouldConvertNullArrayToDriverArrayType () {
63
61
64
62
OutboundRow row = strategy .getOutboundRow (new WithMultidimensionalArray (null ));
65
63
66
- assertThat (row .get (SqlIdentifier .unquoted ("myarray" )).hasValue ()).isFalse ();
67
- assertThat (row .get (SqlIdentifier .unquoted ("myarray" )).getType ()).isEqualTo (Integer [].class );
64
+ assertThat (row ).withColumn ("myarray" ).isEmpty ().hasType (Integer [].class );
68
65
}
69
66
70
67
@ Test // gh-161
71
68
void shouldConvertCollectionToArray () {
72
69
73
70
OutboundRow row = strategy .getOutboundRow (new WithIntegerCollection (Arrays .asList (1 , 2 , 3 )));
74
71
75
- assertThat (row .get (SqlIdentifier .unquoted ("myarray" )).hasValue ()).isTrue ();
76
- assertThat (row .get (SqlIdentifier .unquoted ("myarray" )).getValue ()).isInstanceOf (Integer [].class );
72
+ assertThat (row ).withColumn ("myarray" ).hasValueInstanceOf (Integer [].class );
77
73
assertThat ((Integer []) row .get (SqlIdentifier .unquoted ("myarray" )).getValue ()).contains (1 , 2 , 3 );
78
74
}
79
75
@@ -88,9 +84,8 @@ void shouldConvertToArray() {
88
84
89
85
OutboundRow outboundRow = strategy .getOutboundRow (withArray );
90
86
91
- assertThat (outboundRow ) //
92
- .containsEntry (SqlIdentifier .unquoted ("string_array" ), Parameter .from (new String [] { "hello" , "world" }))
93
- .containsEntry (SqlIdentifier .unquoted ("string_list" ), Parameter .from (new String [] { "hello" , "world" }));
87
+ assertThat (outboundRow ).containsColumnWithValue ("string_array" , new String [] { "hello" , "world" })
88
+ .containsColumnWithValue ("string_list" , new String [] { "hello" , "world" });
94
89
}
95
90
96
91
@ Test // gh-139
@@ -104,8 +99,7 @@ void shouldApplyCustomConversion() {
104
99
105
100
OutboundRow outboundRow = strategy .getOutboundRow (withConversion );
106
101
107
- assertThat (outboundRow ) //
108
- .containsEntry (SqlIdentifier .unquoted ("my_objects" ), Parameter .from ("[one, two]" ));
102
+ assertThat (outboundRow ).containsColumnWithValue ("my_objects" , "[one, two]" );
109
103
}
110
104
111
105
@ Test // gh-139
@@ -119,12 +113,7 @@ void shouldApplyCustomConversionForNull() {
119
113
120
114
OutboundRow outboundRow = strategy .getOutboundRow (withConversion );
121
115
122
- assertThat (outboundRow ) //
123
- .containsKey (SqlIdentifier .unquoted ("my_objects" ));
124
-
125
- Parameter value = outboundRow .get ("my_objects" );
126
- assertThat (value .isEmpty ()).isTrue ();
127
- assertThat (value .getType ()).isEqualTo (String .class );
116
+ assertThat (outboundRow ).containsColumn ("my_objects" ).withColumn ("my_objects" ).isEmpty ().hasType (String .class );
128
117
}
129
118
130
119
@ Test // gh-252, gh-593
@@ -139,16 +128,10 @@ void shouldConvertCollectionOfEnumToString() {
139
128
140
129
OutboundRow outboundRow = strategy .getOutboundRow (withEnums );
141
130
142
- assertThat (outboundRow ).containsKey (SqlIdentifier .unquoted ("enum_set" ));
143
- assertThat (outboundRow .get (SqlIdentifier .unquoted ("enum_set" )).getValue ()).isEqualTo (new String [] { "ONE" , "TWO" });
144
-
145
- assertThat (outboundRow ).containsKey (SqlIdentifier .unquoted ("enum_array" ));
146
- assertThat (outboundRow .get (SqlIdentifier .unquoted ("enum_array" )).getValue ())
147
- .isEqualTo (new String [] { "ONE" , "TWO" });
148
-
149
- assertThat (outboundRow ).containsKey (SqlIdentifier .unquoted ("enum_list" ));
150
- assertThat (outboundRow .get (SqlIdentifier .unquoted ("enum_list" )).getValue ())
151
- .isEqualTo (new String [] { "ONE" , "TWO" });
131
+ assertThat (outboundRow ).containsColumns ("enum_set" , "enum_array" , "enum_list" );
132
+ assertThat (outboundRow ).withColumn ("enum_set" ).hasValue (new String [] { "ONE" , "TWO" }).hasType (String [].class );
133
+ assertThat (outboundRow ).withColumn ("enum_array" ).hasValue (new String [] { "ONE" , "TWO" }).hasType (String [].class );
134
+ assertThat (outboundRow ).withColumn ("enum_list" ).hasValue (new String [] { "ONE" , "TWO" }).hasType (String [].class );
152
135
}
153
136
154
137
@ Test // gh-593
@@ -160,14 +143,10 @@ void shouldCorrectlyWriteConvertedEnumNullValues() {
160
143
161
144
OutboundRow outboundRow = strategy .getOutboundRow (withEnums );
162
145
163
- assertThat (outboundRow ).containsKey (SqlIdentifier .unquoted ("enum_set" ));
164
- assertThat (outboundRow .get (SqlIdentifier .unquoted ("enum_set" )).getType ()).isEqualTo (String [].class );
165
-
166
- assertThat (outboundRow ).containsKey (SqlIdentifier .unquoted ("enum_array" ));
167
- assertThat (outboundRow .get (SqlIdentifier .unquoted ("enum_array" )).getType ()).isEqualTo (String [].class );
168
-
169
- assertThat (outboundRow ).containsKey (SqlIdentifier .unquoted ("enum_list" ));
170
- assertThat (outboundRow .get (SqlIdentifier .unquoted ("enum_list" )).getType ()).isEqualTo (String [].class );
146
+ assertThat (outboundRow ).containsColumns ("enum_set" , "enum_array" , "enum_list" );
147
+ assertThat (outboundRow ).withColumn ("enum_set" ).isEmpty ().hasType (String [].class );
148
+ assertThat (outboundRow ).withColumn ("enum_array" ).isEmpty ().hasType (String [].class );
149
+ assertThat (outboundRow ).withColumn ("enum_list" ).isEmpty ().hasType (String [].class );
171
150
}
172
151
173
152
@ Test // gh-593
@@ -183,14 +162,10 @@ void shouldConvertCollectionOfEnumNatively() {
183
162
184
163
OutboundRow outboundRow = strategy .getOutboundRow (withEnums );
185
164
186
- assertThat (outboundRow ).containsKey (SqlIdentifier .unquoted ("enum_set" ));
187
- assertThat (outboundRow .get (SqlIdentifier .unquoted ("enum_set" )).getValue ()).isInstanceOf (MyEnum [].class );
188
-
189
- assertThat (outboundRow ).containsKey (SqlIdentifier .unquoted ("enum_array" ));
190
- assertThat (outboundRow .get (SqlIdentifier .unquoted ("enum_array" )).getValue ()).isInstanceOf (MyEnum [].class );
191
-
192
- assertThat (outboundRow ).containsKey (SqlIdentifier .unquoted ("enum_list" ));
193
- assertThat (outboundRow .get (SqlIdentifier .unquoted ("enum_list" )).getValue ()).isInstanceOf (MyEnum [].class );
165
+ assertThat (outboundRow ).containsColumns ("enum_set" , "enum_array" , "enum_list" );
166
+ assertThat (outboundRow ).withColumn ("enum_set" ).hasValue ().hasType (MyEnum [].class );
167
+ assertThat (outboundRow ).withColumn ("enum_array" ).hasValue ().hasType (MyEnum [].class );
168
+ assertThat (outboundRow ).withColumn ("enum_list" ).hasValue ().hasType (MyEnum [].class );
194
169
}
195
170
196
171
@ Test // gh-593
@@ -203,14 +178,10 @@ void shouldCorrectlyWriteNativeEnumNullValues() {
203
178
204
179
OutboundRow outboundRow = strategy .getOutboundRow (withEnums );
205
180
206
- assertThat (outboundRow ).containsKey (SqlIdentifier .unquoted ("enum_set" ));
207
- assertThat (outboundRow .get (SqlIdentifier .unquoted ("enum_set" )).getType ()).isEqualTo (MyEnum [].class );
208
-
209
- assertThat (outboundRow ).containsKey (SqlIdentifier .unquoted ("enum_array" ));
210
- assertThat (outboundRow .get (SqlIdentifier .unquoted ("enum_array" )).getType ()).isEqualTo (MyEnum [].class );
211
-
212
- assertThat (outboundRow ).containsKey (SqlIdentifier .unquoted ("enum_list" ));
213
- assertThat (outboundRow .get (SqlIdentifier .unquoted ("enum_list" )).getType ()).isEqualTo (MyEnum [].class );
181
+ assertThat (outboundRow ).containsColumns ("enum_set" , "enum_array" , "enum_list" );
182
+ assertThat (outboundRow ).withColumn ("enum_set" ).isEmpty ().hasType (MyEnum [].class );
183
+ assertThat (outboundRow ).withColumn ("enum_array" ).isEmpty ().hasType (MyEnum [].class );
184
+ assertThat (outboundRow ).withColumn ("enum_list" ).isEmpty ().hasType (MyEnum [].class );
214
185
}
215
186
216
187
@ RequiredArgsConstructor
0 commit comments