1212import org .zalando .typemapper .namedresult .results .InheritedClassWithPrimitives ;
1313import org .zalando .typemapper .namedresult .results .InheritedClassWithPrimitivesDeprecated ;
1414import org .zalando .typemapper .namedresult .transformer .Hans ;
15+
16+
1517import org .junit .After ;
1618import org .junit .Before ;
1719import org .junit .Test ;
2628import java .sql .Types ;
2729import java .util .*;
2830
31+
2932import static org .zalando .typemapper .postgres .PgArray .ARRAY ;
3033import static org .zalando .typemapper .postgres .PgRow .ROW ;
34+
35+
3136import static org .hamcrest .CoreMatchers .is ;
32- import static org .junit . Assert .assertThat ;
37+ import static org .hamcrest . MatcherAssert .assertThat ;
3338
3439
3540@ RunWith (Parameterized .class )
@@ -68,7 +73,7 @@ public void createJdbcTemplate() {
6873 * @Parameters.
6974 */
7075 public PgSerializerToDatabaseTestIT (final Object objectToSerialize , final String expectedString ,
71- final Integer expectedSQLType ) {
76+ final Integer expectedSQLType ) {
7277 this .objectToSerialize = objectToSerialize ;
7378 this .expectedString = expectedString ;
7479 this .expectedSQLType = expectedSQLType ;
@@ -89,127 +94,132 @@ private static Map<String, String> createSimpleMap(final String key, final Strin
8994 @ Parameters
9095 public static Collection <Object []> generateData () throws SQLException {
9196 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 },
213223
214224 });
215225 }
@@ -235,7 +245,7 @@ public void createNeededTypes() throws SQLException {
235245 // type with gender code
236246 execute ("CREATE TYPE gender_enum_type AS ENUM ('MALE', 'FEMALE');" );
237247 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);" );
239249
240250 execute ("CREATE TYPE tmp.inherited_class_with_primitives AS (l bigint, cc text, i int);" );
241251 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 {
256266
257267 @ Test
258268 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 ));
261271 }
262272}
263273//J+
0 commit comments