1
1
/*
2
- * Copyright 2002-2015 the original author or authors.
2
+ * Copyright 2002-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
27
27
import org .junit .Before ;
28
28
import org .junit .Test ;
29
29
30
- import static org .junit .Assert .*;
31
30
import static org .mockito .BDDMockito .*;
32
31
33
32
/**
@@ -59,13 +58,21 @@ public void testSetParameterValueWithNullAndTypeName() throws SQLException {
59
58
60
59
@ Test
61
60
public void testSetParameterValueWithNullAndUnknownType () throws SQLException {
61
+ StatementCreatorUtils .shouldIgnoreGetParameterType = true ;
62
+ Connection con = mock (Connection .class );
63
+ DatabaseMetaData dbmd = mock (DatabaseMetaData .class );
64
+ given (preparedStatement .getConnection ()).willReturn (con );
65
+ given (dbmd .getDatabaseProductName ()).willReturn ("Oracle" );
66
+ given (dbmd .getDriverName ()).willReturn ("Oracle Driver" );
67
+ given (con .getMetaData ()).willReturn (dbmd );
62
68
StatementCreatorUtils .setParameterValue (preparedStatement , 1 , SqlTypeValue .TYPE_UNKNOWN , null , null );
63
69
verify (preparedStatement ).setNull (1 , Types .NULL );
70
+ StatementCreatorUtils .shouldIgnoreGetParameterType = false ;
64
71
}
65
72
66
73
@ Test
67
74
public void testSetParameterValueWithNullAndUnknownTypeOnInformix () throws SQLException {
68
- StatementCreatorUtils .driversWithNoSupportForGetParameterType . clear () ;
75
+ StatementCreatorUtils .shouldIgnoreGetParameterType = true ;
69
76
Connection con = mock (Connection .class );
70
77
DatabaseMetaData dbmd = mock (DatabaseMetaData .class );
71
78
given (preparedStatement .getConnection ()).willReturn (con );
@@ -76,12 +83,12 @@ public void testSetParameterValueWithNullAndUnknownTypeOnInformix() throws SQLEx
76
83
verify (dbmd ).getDatabaseProductName ();
77
84
verify (dbmd ).getDriverName ();
78
85
verify (preparedStatement ).setObject (1 , null );
79
- assertEquals ( 1 , StatementCreatorUtils .driversWithNoSupportForGetParameterType . size ()) ;
86
+ StatementCreatorUtils .shouldIgnoreGetParameterType = false ;
80
87
}
81
88
82
89
@ Test
83
90
public void testSetParameterValueWithNullAndUnknownTypeOnDerbyEmbedded () throws SQLException {
84
- StatementCreatorUtils .driversWithNoSupportForGetParameterType . clear () ;
91
+ StatementCreatorUtils .shouldIgnoreGetParameterType = true ;
85
92
Connection con = mock (Connection .class );
86
93
DatabaseMetaData dbmd = mock (DatabaseMetaData .class );
87
94
given (preparedStatement .getConnection ()).willReturn (con );
@@ -92,82 +99,18 @@ public void testSetParameterValueWithNullAndUnknownTypeOnDerbyEmbedded() throws
92
99
verify (dbmd ).getDatabaseProductName ();
93
100
verify (dbmd ).getDriverName ();
94
101
verify (preparedStatement ).setNull (1 , Types .VARCHAR );
95
- assertEquals ( 1 , StatementCreatorUtils .driversWithNoSupportForGetParameterType . size ()) ;
102
+ StatementCreatorUtils .shouldIgnoreGetParameterType = false ;
96
103
}
97
104
98
105
@ Test
99
106
public void testSetParameterValueWithNullAndGetParameterTypeWorking () throws SQLException {
100
- StatementCreatorUtils .driversWithNoSupportForGetParameterType .clear ();
101
107
ParameterMetaData pmd = mock (ParameterMetaData .class );
102
108
given (preparedStatement .getParameterMetaData ()).willReturn (pmd );
103
109
given (pmd .getParameterType (1 )).willReturn (Types .SMALLINT );
104
110
StatementCreatorUtils .setParameterValue (preparedStatement , 1 , SqlTypeValue .TYPE_UNKNOWN , null , null );
105
111
verify (pmd ).getParameterType (1 );
106
112
verify (preparedStatement , never ()).getConnection ();
107
113
verify (preparedStatement ).setNull (1 , Types .SMALLINT );
108
- assertTrue (StatementCreatorUtils .driversWithNoSupportForGetParameterType .isEmpty ());
109
- }
110
-
111
- @ Test
112
- public void testSetParameterValueWithNullAndGetParameterTypeWorkingButNotForOtherDriver () throws SQLException {
113
- StatementCreatorUtils .driversWithNoSupportForGetParameterType .clear ();
114
- StatementCreatorUtils .driversWithNoSupportForGetParameterType .add ("Oracle JDBC Driver" );
115
- Connection con = mock (Connection .class );
116
- DatabaseMetaData dbmd = mock (DatabaseMetaData .class );
117
- ParameterMetaData pmd = mock (ParameterMetaData .class );
118
- given (preparedStatement .getConnection ()).willReturn (con );
119
- given (con .getMetaData ()).willReturn (dbmd );
120
- given (dbmd .getDriverName ()).willReturn ("Apache Derby Embedded Driver" );
121
- given (preparedStatement .getParameterMetaData ()).willReturn (pmd );
122
- given (pmd .getParameterType (1 )).willReturn (Types .SMALLINT );
123
- StatementCreatorUtils .setParameterValue (preparedStatement , 1 , SqlTypeValue .TYPE_UNKNOWN , null , null );
124
- verify (dbmd ).getDriverName ();
125
- verify (pmd ).getParameterType (1 );
126
- verify (preparedStatement ).setNull (1 , Types .SMALLINT );
127
- assertEquals (1 , StatementCreatorUtils .driversWithNoSupportForGetParameterType .size ());
128
- }
129
-
130
- @ Test
131
- public void testSetParameterValueWithNullAndUnknownTypeAndGetParameterTypeNotWorking () throws SQLException {
132
- StatementCreatorUtils .driversWithNoSupportForGetParameterType .clear ();
133
- Connection con = mock (Connection .class );
134
- DatabaseMetaData dbmd = mock (DatabaseMetaData .class );
135
- given (preparedStatement .getConnection ()).willReturn (con );
136
- given (con .getMetaData ()).willReturn (dbmd );
137
- given (dbmd .getDatabaseProductName ()).willReturn ("Apache Derby" );
138
- given (dbmd .getDriverName ()).willReturn ("Apache Derby Embedded Driver" );
139
- StatementCreatorUtils .setParameterValue (preparedStatement , 1 , SqlTypeValue .TYPE_UNKNOWN , null , null );
140
- verify (dbmd ).getDatabaseProductName ();
141
- verify (dbmd ).getDriverName ();
142
- verify (preparedStatement ).setNull (1 , Types .VARCHAR );
143
- assertEquals (1 , StatementCreatorUtils .driversWithNoSupportForGetParameterType .size ());
144
-
145
- reset (preparedStatement , con , dbmd );
146
- ParameterMetaData pmd = mock (ParameterMetaData .class );
147
- given (preparedStatement .getConnection ()).willReturn (con );
148
- given (con .getMetaData ()).willReturn (dbmd );
149
- given (preparedStatement .getParameterMetaData ()).willReturn (pmd );
150
- given (pmd .getParameterType (1 )).willThrow (new SQLException ("unsupported" ));
151
- given (dbmd .getDatabaseProductName ()).willReturn ("Informix Dynamic Server" );
152
- given (dbmd .getDriverName ()).willReturn ("Informix Driver" );
153
- StatementCreatorUtils .setParameterValue (preparedStatement , 1 , SqlTypeValue .TYPE_UNKNOWN , null , null );
154
- verify (pmd ).getParameterType (1 );
155
- verify (dbmd ).getDatabaseProductName ();
156
- verify (dbmd ).getDriverName ();
157
- verify (preparedStatement ).setObject (1 , null );
158
- assertEquals (2 , StatementCreatorUtils .driversWithNoSupportForGetParameterType .size ());
159
-
160
- reset (preparedStatement , con , dbmd , pmd );
161
- given (preparedStatement .getConnection ()).willReturn (con );
162
- given (con .getMetaData ()).willReturn (dbmd );
163
- given (dbmd .getDatabaseProductName ()).willReturn ("Informix Dynamic Server" );
164
- given (dbmd .getDriverName ()).willReturn ("Informix Driver" );
165
- StatementCreatorUtils .setParameterValue (preparedStatement , 1 , SqlTypeValue .TYPE_UNKNOWN , null , null );
166
- verify (preparedStatement , never ()).getParameterMetaData ();
167
- verify (dbmd ).getDatabaseProductName ();
168
- verify (dbmd ).getDriverName ();
169
- verify (preparedStatement ).setObject (1 , null );
170
- assertEquals (2 , StatementCreatorUtils .driversWithNoSupportForGetParameterType .size ());
171
114
}
172
115
173
116
@ Test
@@ -277,8 +220,16 @@ public void testSetParameterValueWithStringAndVendorSpecificType() throws SQLExc
277
220
278
221
@ Test // SPR-8571
279
222
public void testSetParameterValueWithNullAndVendorSpecificType () throws SQLException {
223
+ StatementCreatorUtils .shouldIgnoreGetParameterType = true ;
224
+ Connection con = mock (Connection .class );
225
+ DatabaseMetaData dbmd = mock (DatabaseMetaData .class );
226
+ given (preparedStatement .getConnection ()).willReturn (con );
227
+ given (dbmd .getDatabaseProductName ()).willReturn ("Oracle" );
228
+ given (dbmd .getDriverName ()).willReturn ("Oracle Driver" );
229
+ given (con .getMetaData ()).willReturn (dbmd );
280
230
StatementCreatorUtils .setParameterValue (preparedStatement , 1 , Types .OTHER , null , null );
281
231
verify (preparedStatement ).setNull (1 , Types .NULL );
232
+ StatementCreatorUtils .shouldIgnoreGetParameterType = false ;
282
233
}
283
234
284
235
}
0 commit comments