12
12
import org .zalando .typemapper .namedresult .results .InheritedClassWithPrimitives ;
13
13
import org .zalando .typemapper .namedresult .results .InheritedClassWithPrimitivesDeprecated ;
14
14
import org .zalando .typemapper .namedresult .transformer .Hans ;
15
+
16
+
15
17
import org .junit .After ;
16
18
import org .junit .Before ;
17
19
import org .junit .Test ;
26
28
import java .sql .Types ;
27
29
import java .util .*;
28
30
31
+
29
32
import static org .zalando .typemapper .postgres .PgArray .ARRAY ;
30
33
import static org .zalando .typemapper .postgres .PgRow .ROW ;
34
+
35
+
31
36
import static org .hamcrest .CoreMatchers .is ;
32
- import static org .junit . Assert .assertThat ;
37
+ import static org .hamcrest . MatcherAssert .assertThat ;
33
38
34
39
35
40
@ RunWith (Parameterized .class )
@@ -68,7 +73,7 @@ public void createJdbcTemplate() {
68
73
* @Parameters.
69
74
*/
70
75
public PgSerializerToDatabaseTestIT (final Object objectToSerialize , final String expectedString ,
71
- final Integer expectedSQLType ) {
76
+ final Integer expectedSQLType ) {
72
77
this .objectToSerialize = objectToSerialize ;
73
78
this .expectedString = expectedString ;
74
79
this .expectedSQLType = expectedSQLType ;
@@ -89,127 +94,132 @@ private static Map<String, String> createSimpleMap(final String key, final Strin
89
94
@ Parameters
90
95
public static Collection <Object []> generateData () throws SQLException {
91
96
return Arrays .asList (
92
- new Object [][] {
93
- /* 23 */
94
- {PgTypeHelper .asPGobject (new InheritedClassWithPrimitivesDeprecated (1L , "1" , 12 )), "(1,12,1)" , Types .OTHER },
95
-
96
- /* 0 */
97
- {1 , "1" , Types .INTEGER },
98
-
99
- /* 1 */
100
- {69 , "69" , Types .INTEGER },
101
-
102
- /* 2 */
103
- {true , "true" , Types .BOOLEAN },
104
-
105
- /* 3 */
106
- {ARRAY (1 , 2 , 3 , 4 ).asJdbcArray ("int4" ), "{1,2,3,4}" , Types .ARRAY },
107
-
108
- /* 4 */
109
- {ARRAY (null , 2 , 3 , 4 ).asJdbcArray ("int4" ), "{NULL,2,3,4}" , Types .ARRAY },
110
-
111
- /* 5 */
112
- {ARRAY ("a" , "b" ).asJdbcArray ("text" ), "{a,b}" , Types .ARRAY },
113
-
114
- /* 6 */
115
- {
116
- ARRAY ("first element" , "second \" quoted\" element" ).asJdbcArray ("text" ),
117
- "{\" first element\" ,\" second \\ \" quoted\\ \" element\" }" , Types .ARRAY
118
- },
119
-
120
- /* 7 */
121
- {ROW (1 , 2 ).asPGobject ("int_duplet" ), "(1,2)" , Types .OTHER },
122
-
123
- /* 8 */
124
- {
125
- ROW (1 , 2 , ARRAY ("a" , "b" )).asPGobject ("int_duplet_with_text_array" ), "(1,2,\" {a,b}\" )" ,
126
- Types .OTHER
127
- },
128
-
129
- /* 9 */
130
- {
131
- ROW ("a" , "b" , new int [] {1 , 2 , 3 , 4 }).asPGobject ("text_duplet_with_int_array" ),
132
- "(a,b,\" {1,2,3,4}\" )" , Types .OTHER
133
- },
134
-
135
- /* 10 */
136
- {
137
- ROW ("a" , null , ARRAY (ROW (1 , 10 ), ROW (2 , 20 ), null )).asPGobject (
138
- "text_duplet_with_int_duplet_array" ), "(a,,\" {\" \" (1,10)\" \" ,\" \" (2,20)\" \" ,NULL}\" )" ,
139
- Types .OTHER
140
- },
141
-
142
- /* 11 */
143
- {
144
- ROW ("a" , null , ARRAY (ROW (1 , 11 ), ROW (2 , 22 ), null )).asPGobject (
145
- "text_duplet_with_int_duplet_array" ), "(a,,\" {\" \" (1,11)\" \" ,\" \" (2,22)\" \" ,NULL}\" )" ,
146
- Types .OTHER
147
- },
148
-
149
- /* 12 */
150
- {
151
- ROW (1 , new ClassWithPrimitives (1 , 2L , 'c' )).asPGobject ("int_with_additional_type" ),
152
- "(1,\" (c,1,2)\" )" , Types .OTHER
153
- },
154
-
155
- /* 13 */
156
- {
157
- ROW (1 ,
158
- new ClassWithPrimitives [] {
159
- new ClassWithPrimitives (1 , 100L , 'a' ), new ClassWithPrimitives (2 , 200L , 'b' )
160
- }).asPGobject ("int_with_additional_type_array" ),
161
- "(1,\" {\" \" (a,1,100)\" \" ,\" \" (b,2,200)\" \" }\" )" , Types .OTHER
162
- },
163
-
164
- /* 14 */
165
- {PgTypeHelper .asPGobject (new ClassWithPrimitives (1 , 100L , 'a' )), "(a,1,100)" , Types .OTHER },
166
-
167
- /* 15 */
168
- {
169
- PgTypeHelper .asPGobject (new ClassWithPrimitivesAndMap (1 , 2 , 'a' , createSimpleMap ("b" , "c" ))),
170
- "(1,2,a,\" \" \" b\" \" =>\" \" c\" \" \" )" , Types .OTHER
171
- },
172
-
173
- /* 16 */
174
- {
175
- PgTypeHelper .asPGobject (new ClassWithEnum (Enumeration .VALUE_1 , Enumeration .VALUE_2 )),
176
- "(VALUE_1,VALUE_2)" , Types .OTHER
177
- },
178
-
179
- /* 17 */
180
- {
181
- PgTypeHelper .asPGobject (
182
- new ClassWithSimpleTransformers (GenderCode .MALE , GenderCode .MALE , GenderCode .MALE , "path" ,
183
- "listElement1" , "listElement2" , "listElement3" )),
184
- "(path,homme,0,MALE,listElement1#listElement2#listElement3)" , Types .OTHER
185
- },
186
-
187
- /* 18 */
188
- {
189
- PgTypeHelper .asPGobject (
190
- new ClassWithPredefinedTransformer (
191
- new Hans ("This is a complex object using an implicit transformer." ))),
192
- "(\" This is a complex object using an implicit transformer.\" ,{})" , Types .OTHER
193
- },
194
-
195
- /* 19 */
196
- {
197
- PgTypeHelper .asPGobject (
198
- new ClassWithPredefinedTransformer (
199
- new Hans ("This is a complex object using an implicit transformer." ),
200
- new Hans ("list element 1" ), new Hans ("list element 2" ))),
201
- "(\" This is a complex object using an implicit transformer.\" ,\" {\" \" list element 1\" \" ,\" \" list element 2\" \" }\" )" ,
202
- Types .OTHER
203
- },
204
-
205
- /* 20 */
206
- {new Date (1354338366000L ), "2012-12-01 06:06:06+01" , Types .TIMESTAMP },
207
-
208
- /* 21 */
209
- {new Date (1349064366000L ), "2012-10-01 06:06:06+02" , Types .TIMESTAMP },
210
-
211
- /* 22 */
212
- {PgTypeHelper .asPGobject (new InheritedClassWithPrimitives (1L , "1" , 12 )), "(1,12,1)" , Types .OTHER },
97
+ new Object [][]{
98
+ /* 23 */
99
+ {PgTypeHelper .asPGobject (
100
+ new InheritedClassWithPrimitivesDeprecated (1L , "1" , 12 )), "(1,12,1)" , Types .OTHER },
101
+
102
+ /* 0 */
103
+ {1 , "1" , Types .INTEGER },
104
+
105
+ /* 1 */
106
+ {69 , "69" , Types .INTEGER },
107
+
108
+ /* 2 */
109
+ {true , "true" , Types .BOOLEAN },
110
+
111
+ /* 3 */
112
+ {ARRAY (1 , 2 , 3 , 4 ).asJdbcArray ("int4" ), "{1,2,3,4}" , Types .ARRAY },
113
+
114
+ /* 4 */
115
+ {ARRAY (null , 2 , 3 , 4 ).asJdbcArray ("int4" ), "{NULL,2,3,4}" , Types .ARRAY },
116
+
117
+ /* 5 */
118
+ {ARRAY ("a" , "b" ).asJdbcArray ("text" ), "{a,b}" , Types .ARRAY },
119
+
120
+ /* 6 */
121
+ {
122
+ ARRAY ("first element" , "second \" quoted\" element" ).asJdbcArray ("text" ),
123
+ "{\" first element\" ,\" second \\ \" quoted\\ \" element\" }" , Types .ARRAY
124
+ },
125
+
126
+ /* 7 */
127
+ {ROW (1 , 2 ).asPGobject ("int_duplet" ), "(1,2)" , Types .OTHER },
128
+
129
+ /* 8 */
130
+ {
131
+ ROW (1 , 2 , ARRAY ("a" , "b" )).asPGobject ("int_duplet_with_text_array" ), "(1,2,\" {a,b}\" )" ,
132
+ Types .OTHER
133
+ },
134
+
135
+ /* 9 */
136
+ {
137
+ ROW ("a" , "b" , new int []{1 , 2 , 3 , 4 }).asPGobject ("text_duplet_with_int_array" ),
138
+ "(a,b,\" {1,2,3,4}\" )" , Types .OTHER
139
+ },
140
+
141
+ /* 10 */
142
+ {
143
+ ROW ("a" , null , ARRAY (ROW (1 , 10 ), ROW (2 , 20 ), null )).asPGobject (
144
+ "text_duplet_with_int_duplet_array" ), "(a,,\" {\" \" (1,10)\" \" ,\" \" (2,20)\" \" ,NULL}\" )" ,
145
+ Types .OTHER
146
+ },
147
+
148
+ /* 11 */
149
+ {
150
+ ROW ("a" , null , ARRAY (ROW (1 , 11 ), ROW (2 , 22 ), null )).asPGobject (
151
+ "text_duplet_with_int_duplet_array" ), "(a,,\" {\" \" (1,11)\" \" ,\" \" (2,22)\" \" ,NULL}\" )" ,
152
+ Types .OTHER
153
+ },
154
+
155
+ /* 12 */
156
+ {
157
+ ROW (1 , new ClassWithPrimitives (1 , 2L , 'c' )).asPGobject ("int_with_additional_type" ),
158
+ "(1,\" (c,1,2)\" )" , Types .OTHER
159
+ },
160
+
161
+ /* 13 */
162
+ {
163
+ ROW (1 ,
164
+ new ClassWithPrimitives []{
165
+ new ClassWithPrimitives (1 , 100L , 'a' ), new ClassWithPrimitives (2 , 200L ,
166
+ 'b' )
167
+ }).asPGobject ("int_with_additional_type_array" ),
168
+ "(1,\" {\" \" (a,1,100)\" \" ,\" \" (b,2,200)\" \" }\" )" , Types .OTHER
169
+ },
170
+
171
+ /* 14 */
172
+ {PgTypeHelper .asPGobject (new ClassWithPrimitives (1 , 100L , 'a' )), "(a,1,100)" , Types .OTHER },
173
+
174
+ /* 15 */
175
+ {
176
+ PgTypeHelper .asPGobject (
177
+ new ClassWithPrimitivesAndMap (1 , 2 , 'a' , createSimpleMap ("b" , "c" ))),
178
+ "(1,2,a,\" \" \" b\" \" =>\" \" c\" \" \" )" , Types .OTHER
179
+ },
180
+
181
+ /* 16 */
182
+ {
183
+ PgTypeHelper .asPGobject (new ClassWithEnum (Enumeration .VALUE_1 , Enumeration .VALUE_2 )),
184
+ "(VALUE_1,VALUE_2)" , Types .OTHER
185
+ },
186
+
187
+ /* 17 */
188
+ {
189
+ PgTypeHelper .asPGobject (
190
+ new ClassWithSimpleTransformers (GenderCode .MALE , GenderCode .MALE ,
191
+ GenderCode .MALE , "path" ,
192
+ "listElement1" , "listElement2" , "listElement3" )),
193
+ "(path,homme,0,MALE,listElement1#listElement2#listElement3)" , Types .OTHER
194
+ },
195
+
196
+ /* 18 */
197
+ {
198
+ PgTypeHelper .asPGobject (
199
+ new ClassWithPredefinedTransformer (
200
+ new Hans ("This is a complex object using an implicit transformer." ))),
201
+ "(\" This is a complex object using an implicit transformer.\" ,{})" , Types .OTHER
202
+ },
203
+
204
+ /* 19 */
205
+ {
206
+ PgTypeHelper .asPGobject (
207
+ new ClassWithPredefinedTransformer (
208
+ new Hans ("This is a complex object using an implicit transformer." ),
209
+ new Hans ("list element 1" ), new Hans ("list element 2" ))),
210
+ "(\" This is a complex object using an implicit transformer.\" ,\" {\" \" list element 1\" \" ,\" \" list element 2\" \" }\" )" ,
211
+ Types .OTHER
212
+ },
213
+
214
+ /* 20 */
215
+ {new Date (1354338366000L ), "2012-12-01 06:06:06+01" , Types .TIMESTAMP },
216
+
217
+ /* 21 */
218
+ {new Date (1349064366000L ), "2012-10-01 06:06:06+02" , Types .TIMESTAMP },
219
+
220
+ /* 22 */
221
+ {PgTypeHelper .asPGobject (
222
+ new InheritedClassWithPrimitives (1L , "1" , 12 )), "(1,12,1)" , Types .OTHER },
213
223
214
224
});
215
225
}
@@ -235,7 +245,7 @@ public void createNeededTypes() throws SQLException {
235
245
// type with gender code
236
246
execute ("CREATE TYPE gender_enum_type AS ENUM ('MALE', 'FEMALE');" );
237
247
execute (
238
- "CREATE TYPE tmp.class_with_simple_transformers AS (file_column text, gender_as_code text, gender_as_int integer, gender_as_name gender_enum_type, string_list_with_separtion_char text);" );
248
+ "CREATE TYPE tmp.class_with_simple_transformers AS (file_column text, gender_as_code text, gender_as_int integer, gender_as_name gender_enum_type, string_list_with_separtion_char text);" );
239
249
240
250
execute ("CREATE TYPE tmp.inherited_class_with_primitives AS (l bigint, cc text, i int);" );
241
251
execute ("CREATE TYPE tmp.inherited_class_with_primitives_deprecated AS (l bigint, cc text, i int);" );
@@ -256,8 +266,8 @@ public void dropUsedTypes() throws SQLException {
256
266
257
267
@ Test
258
268
public void passingParametersToQueryTest () {
259
- assertThat (template .queryForObject ("SELECT (?)::text " , new Object [] {this .objectToSerialize },
260
- new int [] {this .expectedSQLType }, String .class ), is (this .expectedString ));
269
+ assertThat (template .queryForObject ("SELECT (?)::TEXT " , new Object []{this .objectToSerialize },
270
+ new int []{this .expectedSQLType }, String .class ), is (this .expectedString ));
261
271
}
262
272
}
263
273
//J+
0 commit comments