@@ -45,7 +45,7 @@ public void testDefaultInstanceWithNoSuchDatabase() {
45
45
assertTrue (sec .getBadSqlGrammarCodes ().length == 0 );
46
46
assertTrue (sec .getDataIntegrityViolationCodes ().length == 0 );
47
47
}
48
-
48
+
49
49
/**
50
50
* Check that a known database produces recognizable codes.
51
51
*/
@@ -62,7 +62,7 @@ private void assertIsOracle(SQLErrorCodes sec) {
62
62
// This had better NOT be
63
63
assertFalse (Arrays .binarySearch (sec .getBadSqlGrammarCodes (), "9xx42" ) >= 0 );
64
64
}
65
-
65
+
66
66
private void assertIsHsql (SQLErrorCodes sec ) {
67
67
assertTrue (sec .getBadSqlGrammarCodes ().length > 0 );
68
68
assertTrue (sec .getDataIntegrityViolationCodes ().length > 0 );
@@ -75,12 +75,12 @@ private void assertIsHsql(SQLErrorCodes sec) {
75
75
private void assertIsDB2 (SQLErrorCodes sec ) {
76
76
assertTrue (sec .getBadSqlGrammarCodes ().length > 0 );
77
77
assertTrue (sec .getDataIntegrityViolationCodes ().length > 0 );
78
-
78
+
79
79
assertFalse (Arrays .binarySearch (sec .getBadSqlGrammarCodes (), "942" ) >= 0 );
80
80
// This had better NOT be
81
81
assertTrue (Arrays .binarySearch (sec .getBadSqlGrammarCodes (), "-204" ) >= 0 );
82
82
}
83
-
83
+
84
84
public void testLookupOrder () {
85
85
class TestSQLErrorCodesFactory extends SQLErrorCodesFactory {
86
86
private int lookups = 0 ;
@@ -98,13 +98,13 @@ protected Resource loadResource(String path) {
98
98
}
99
99
}
100
100
}
101
-
101
+
102
102
// Should have failed to load without error
103
103
TestSQLErrorCodesFactory sf = new TestSQLErrorCodesFactory ();
104
104
assertTrue (sf .getErrorCodes ("XX" ).getBadSqlGrammarCodes ().length == 0 );
105
105
assertTrue (sf .getErrorCodes ("Oracle" ).getDataIntegrityViolationCodes ().length == 0 );
106
106
}
107
-
107
+
108
108
/**
109
109
* Check that user defined error codes take precedence.
110
110
*/
@@ -117,15 +117,15 @@ protected Resource loadResource(String path) {
117
117
return null ;
118
118
}
119
119
}
120
-
120
+
121
121
// Should have loaded without error
122
122
TestSQLErrorCodesFactory sf = new TestSQLErrorCodesFactory ();
123
123
assertTrue (sf .getErrorCodes ("XX" ).getBadSqlGrammarCodes ().length == 0 );
124
124
assertEquals (2 , sf .getErrorCodes ("Oracle" ).getBadSqlGrammarCodes ().length );
125
125
assertEquals ("1" , sf .getErrorCodes ("Oracle" ).getBadSqlGrammarCodes ()[0 ]);
126
126
assertEquals ("2" , sf .getErrorCodes ("Oracle" ).getBadSqlGrammarCodes ()[1 ]);
127
127
}
128
-
128
+
129
129
public void testInvalidUserDefinedCodeFormat () {
130
130
class TestSQLErrorCodesFactory extends SQLErrorCodesFactory {
131
131
protected Resource loadResource (String path ) {
@@ -142,7 +142,7 @@ protected Resource loadResource(String path) {
142
142
assertTrue (sf .getErrorCodes ("XX" ).getBadSqlGrammarCodes ().length == 0 );
143
143
assertEquals (0 , sf .getErrorCodes ("Oracle" ).getBadSqlGrammarCodes ().length );
144
144
}
145
-
145
+
146
146
/**
147
147
* Check that custom error codes take precedence.
148
148
*/
@@ -155,7 +155,7 @@ protected Resource loadResource(String path) {
155
155
return null ;
156
156
}
157
157
}
158
-
158
+
159
159
// Should have loaded without error
160
160
TestSQLErrorCodesFactory sf = new TestSQLErrorCodesFactory ();
161
161
assertEquals (1 , sf .getErrorCodes ("Oracle" ).getCustomTranslations ().length );
@@ -164,9 +164,9 @@ protected Resource loadResource(String path) {
164
164
assertEquals (CustomErrorCodeException .class , translation .getExceptionClass ());
165
165
assertEquals (1 , translation .getErrorCodes ().length );
166
166
}
167
-
167
+
168
168
public void testDataSourceWithNullMetadata () throws Exception {
169
-
169
+
170
170
MockControl ctrlConnection = MockControl .createControl (Connection .class );
171
171
Connection mockConnection = (Connection ) ctrlConnection .getMock ();
172
172
mockConnection .getMetaData ();
@@ -180,16 +180,16 @@ public void testDataSourceWithNullMetadata() throws Exception {
180
180
mockDataSource .getConnection ();
181
181
ctrlDataSource .setDefaultReturnValue (mockConnection );
182
182
ctrlDataSource .replay ();
183
-
183
+
184
184
SQLErrorCodes sec = SQLErrorCodesFactory .getInstance ().getErrorCodes (mockDataSource );
185
185
assertIsEmpty (sec );
186
-
186
+
187
187
ctrlConnection .verify ();
188
188
ctrlDataSource .verify ();
189
189
}
190
-
190
+
191
191
public void testGetFromDataSourceWithSQLException () throws Exception {
192
-
192
+
193
193
SQLException expectedSQLException = new SQLException ();
194
194
195
195
MockControl ctrlDataSource = MockControl .createControl (DataSource .class );
@@ -216,7 +216,7 @@ private SQLErrorCodes getErrorCodesFromDataSource(String productName, SQLErrorCo
216
216
md .getDatabaseProductName ();
217
217
mdControl .setReturnValue (productName );
218
218
mdControl .replay ();
219
-
219
+
220
220
MockControl ctrlConnection = MockControl .createControl (Connection .class );
221
221
Connection mockConnection = (Connection ) ctrlConnection .getMock ();
222
222
mockConnection .getMetaData ();
@@ -250,12 +250,12 @@ private SQLErrorCodes getErrorCodesFromDataSource(String productName, SQLErrorCo
250
250
251
251
return sec ;
252
252
}
253
-
253
+
254
254
public void testOracleRecognizedFromMetadata () throws Exception {
255
255
SQLErrorCodes sec = getErrorCodesFromDataSource ("Oracle" , null );
256
256
assertIsOracle (sec );
257
257
}
258
-
258
+
259
259
public void testHsqlRecognizedFromMetadata () throws Exception {
260
260
SQLErrorCodes sec = getErrorCodesFromDataSource ("HSQL Database Engine" , null );
261
261
assertIsHsql (sec );
@@ -282,13 +282,13 @@ protected Resource loadResource(String path) {
282
282
return null ;
283
283
}
284
284
}
285
-
285
+
286
286
WildcardSQLErrorCodesFactory factory = new WildcardSQLErrorCodesFactory ();
287
287
SQLErrorCodes sec = getErrorCodesFromDataSource ("DB2" , factory );
288
288
assertIsDB2 (sec );
289
289
sec = getErrorCodesFromDataSource ("DB2 UDB for Xxxxx" , factory );
290
290
assertIsDB2 (sec );
291
-
291
+
292
292
sec = getErrorCodesFromDataSource ("DB3" , factory );
293
293
assertIsDB2 (sec );
294
294
sec = getErrorCodesFromDataSource ("DB3/" , factory );
0 commit comments