Source Code Cross Referenced for BatchUpdateExceptionTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » sql » tests » java » sql » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.sql.tests.java.sql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.harmony.sql.tests.java.sql;
019:
020:        import java.io.Serializable;
021:        import java.sql.BatchUpdateException;
022:        import java.util.Arrays;
023:
024:        import junit.framework.TestCase;
025:
026:        import org.apache.harmony.testframework.serialization.SerializationTest;
027:        import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
028:
029:        public class BatchUpdateExceptionTest extends TestCase {
030:
031:            /*
032:             * ConstructorTest
033:             */
034:            public void testBatchUpdateException() {
035:
036:                int[] theFinalStates1 = { 0 }; // Error Code state
037:                int[][] theFinalStates2 = { null }; // Update Counts array state
038:                String[] theFinalStates3 = { null }; // SQL State state value
039:                String[] theFinalStates4 = { null }; // Message state
040:
041:                Exception[] theExceptions = { null };
042:
043:                BatchUpdateException aBatchUpdateException;
044:                int loopCount = 1;
045:                for (int i = 0; i < loopCount; i++) {
046:                    try {
047:                        aBatchUpdateException = new BatchUpdateException();
048:                        if (theExceptions[i] != null) {
049:                            fail();
050:                        }
051:                        assertEquals(i + " Final state mismatch: ",
052:                                aBatchUpdateException.getErrorCode(),
053:                                theFinalStates1[i]);
054:                        assertEquals(i + " Final state mismatch: ",
055:                                aBatchUpdateException.getUpdateCounts(),
056:                                theFinalStates2[i]);
057:                        assertEquals(i + " Final state mismatch: ",
058:                                aBatchUpdateException.getSQLState(),
059:                                theFinalStates3[i]);
060:                        assertEquals(i + " Final state mismatch: ",
061:                                aBatchUpdateException.getMessage(),
062:                                theFinalStates4[i]);
063:
064:                    } catch (Exception e) {
065:                        if (theExceptions[i] == null) {
066:                            fail(i + "Unexpected exception");
067:                        }
068:                        assertEquals(i + "Exception mismatch", e.getClass(),
069:                                theExceptions[i].getClass());
070:                        assertEquals(i + "Exception mismatch", e.getMessage(),
071:                                theExceptions[i].getMessage());
072:                    } // end try
073:                } // end for
074:
075:            } // end method testBatchUpdateException
076:
077:            /*
078:             * ConstructorTest
079:             */
080:            public void testBatchUpdateExceptionintArray() {
081:
082:                int[][] init1 = { { 1, 2, 3 }, null };
083:
084:                int[] theFinalStates1 = { 0, 0 }; // Error Code state
085:                int[][] theFinalStates2 = init1; // Update Counts array state
086:                String[] theFinalStates3 = { null, null }; // SQL State state value
087:                String[] theFinalStates4 = { null, null }; // Message state
088:
089:                Exception[] theExceptions = { null, null };
090:
091:                BatchUpdateException aBatchUpdateException;
092:                int loopCount = init1.length;
093:                for (int i = 0; i < loopCount; i++) {
094:                    try {
095:                        aBatchUpdateException = new BatchUpdateException(
096:                                init1[i]);
097:                        if (theExceptions[i] != null) {
098:                            fail();
099:                        }
100:                        assertEquals(i + " Final state mismatch: ",
101:                                aBatchUpdateException.getErrorCode(),
102:                                theFinalStates1[i]);
103:                        assertEquals(i + " Final state mismatch: ",
104:                                aBatchUpdateException.getUpdateCounts(),
105:                                theFinalStates2[i]);
106:                        assertEquals(i + " Final state mismatch: ",
107:                                aBatchUpdateException.getSQLState(),
108:                                theFinalStates3[i]);
109:                        assertEquals(i + " Final state mismatch: ",
110:                                aBatchUpdateException.getMessage(),
111:                                theFinalStates4[i]);
112:
113:                    } catch (Exception e) {
114:                        if (theExceptions[i] == null) {
115:                            fail(i + "Unexpected exception");
116:                        }
117:                        assertEquals(i + "Exception mismatch", e.getClass(),
118:                                theExceptions[i].getClass());
119:                        assertEquals(i + "Exception mismatch", e.getMessage(),
120:                                theExceptions[i].getMessage());
121:                    } // end try
122:                } // end for
123:
124:            } // end method testBatchUpdateExceptionintArray
125:
126:            /*
127:             * ConstructorTest
128:             */
129:            public void testBatchUpdateExceptionStringintArray() {
130:
131:                String[] init1 = { "a", "1", "valid1", "----", "&valid*", null,
132:                        "", ".", "a" };
133:                int[][] init2 = { { 1, 2, 3 }, {}, { 3 }, null, { 5, 5 },
134:                        { 6 }, { 121, 2, 1 }, { 1 }, { 1, 2 } };
135:
136:                int[] theFinalStates1 = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Error Code
137:                // state
138:                // Update Counts array state
139:                int[][] theFinalStates2 = init2;
140:                // SQL State state value
141:                String[] theFinalStates3 = { null, null, null, null, null,
142:                        null, null, null, null };
143:                String[] theFinalStates4 = init1; // Message state
144:
145:                Exception[] theExceptions = { null, null, null, null, null,
146:                        null, null, null, null };
147:
148:                BatchUpdateException aBatchUpdateException;
149:                int loopCount = init1.length;
150:                for (int i = 0; i < loopCount; i++) {
151:                    try {
152:                        aBatchUpdateException = new BatchUpdateException(
153:                                init1[i], init2[i]);
154:                        if (theExceptions[i] != null) {
155:                            fail();
156:                        }
157:                        assertEquals(i + " Final state mismatch: ",
158:                                aBatchUpdateException.getErrorCode(),
159:                                theFinalStates1[i]);
160:                        assertEquals(i + " Final state mismatch: ",
161:                                aBatchUpdateException.getUpdateCounts(),
162:                                theFinalStates2[i]);
163:                        assertEquals(i + " Final state mismatch: ",
164:                                aBatchUpdateException.getSQLState(),
165:                                theFinalStates3[i]);
166:                        assertEquals(i + " Final state mismatch: ",
167:                                aBatchUpdateException.getMessage(),
168:                                theFinalStates4[i]);
169:
170:                    } catch (Exception e) {
171:                        if (theExceptions[i] == null) {
172:                            fail(i + "Unexpected exception");
173:                        }
174:                        assertEquals(i + "Exception mismatch", e.getClass(),
175:                                theExceptions[i].getClass());
176:                        assertEquals(i + "Exception mismatch", e.getMessage(),
177:                                theExceptions[i].getMessage());
178:                    } // end try
179:                } // end for
180:
181:            } // end method testBatchUpdateExceptionStringintArray
182:
183:            /*
184:             * ConstructorTest
185:             */
186:            public void testBatchUpdateExceptionStringStringintArray() {
187:
188:                String[] init1 = { "a", "1", "valid1", "----", "&valid*", null,
189:                        "", ".", "a", "a" };
190:                String[] init2 = { "a", "1", "valid1", "----", "&valid*", "a",
191:                        null, "", ".", "a" };
192:                int[][] init3 = { { 1, 2, 3 }, {}, { 3 }, { 5, 5 }, { 6 },
193:                        { 121, 2, 1 }, { 1 }, { 1, 2 }, { 1 }, { 2 }, null };
194:
195:                int[] theFinalStates1 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Error
196:                // Code
197:                // state
198:                // Update Counts array state
199:                int[][] theFinalStates2 = init3;
200:                // SQL State state value
201:                String[] theFinalStates3 = init2;
202:                String[] theFinalStates4 = init1; // Message state
203:
204:                Exception[] theExceptions = { null, null, null, null, null,
205:                        null, null, null, null, null, null };
206:
207:                BatchUpdateException aBatchUpdateException;
208:                int loopCount = init1.length;
209:                for (int i = 0; i < loopCount; i++) {
210:                    try {
211:                        aBatchUpdateException = new BatchUpdateException(
212:                                init1[i], init2[i], init3[i]);
213:                        if (theExceptions[i] != null) {
214:                            fail();
215:                        }
216:                        assertEquals(i + " Final state mismatch: ",
217:                                aBatchUpdateException.getErrorCode(),
218:                                theFinalStates1[i]);
219:                        assertEquals(i + " Final state mismatch: ",
220:                                aBatchUpdateException.getUpdateCounts(),
221:                                theFinalStates2[i]);
222:                        assertEquals(i + " Final state mismatch: ",
223:                                aBatchUpdateException.getSQLState(),
224:                                theFinalStates3[i]);
225:                        assertEquals(i + " Final state mismatch: ",
226:                                aBatchUpdateException.getMessage(),
227:                                theFinalStates4[i]);
228:
229:                    } catch (Exception e) {
230:                        if (theExceptions[i] == null) {
231:                            fail(i + "Unexpected exception");
232:                        }
233:                        assertEquals(i + "Exception mismatch", e.getClass(),
234:                                theExceptions[i].getClass());
235:                        assertEquals(i + "Exception mismatch", e.getMessage(),
236:                                theExceptions[i].getMessage());
237:                    } // end try
238:                } // end for
239:
240:            } // end method testBatchUpdateExceptionStringStringintArray
241:
242:            /*
243:             * ConstructorTest
244:             */
245:            public void testBatchUpdateExceptionStringStringintintArray() {
246:
247:                String[] init1 = { "a", "1", "valid1", "----", "&valid*", null,
248:                        "", ".", "a", "a" };
249:                String[] init2 = { "a", "1", "valid1", "----", "&valid*", "a",
250:                        null, "", ".", "a" };
251:                int[] init3 = { -2147483648, 2147483647, 0, -492417162,
252:                        -156220255, -173012890, -631026360, -2147483648,
253:                        -2147483648, -2147483648, -2147483648 };
254:                int[][] init4 = { { 1, 2, 3 }, {}, { 3 }, { 5, 5 }, { 6 },
255:                        { 121, 2, 1 }, { 1 }, { 1, 2 }, { 1 }, { 2 }, null };
256:
257:                int[] theFinalStates1 = init3; // Error Code state
258:                // Update Counts array state
259:                int[][] theFinalStates2 = init4;
260:                // SQL State state value
261:                String[] theFinalStates3 = init2;
262:                String[] theFinalStates4 = init1; // Message state
263:
264:                Exception[] theExceptions = { null, null, null, null, null,
265:                        null, null, null, null, null, null };
266:
267:                BatchUpdateException aBatchUpdateException;
268:                int loopCount = init1.length;
269:                for (int i = 0; i < loopCount; i++) {
270:                    try {
271:                        aBatchUpdateException = new BatchUpdateException(
272:                                init1[i], init2[i], init3[i], init4[i]);
273:                        if (theExceptions[i] != null) {
274:                            fail();
275:                        }
276:                        assertEquals(i + " Final state mismatch: ",
277:                                aBatchUpdateException.getErrorCode(),
278:                                theFinalStates1[i]);
279:                        assertEquals(i + " Final state mismatch: ",
280:                                aBatchUpdateException.getUpdateCounts(),
281:                                theFinalStates2[i]);
282:                        assertEquals(i + " Final state mismatch: ",
283:                                aBatchUpdateException.getSQLState(),
284:                                theFinalStates3[i]);
285:                        assertEquals(i + " Final state mismatch: ",
286:                                aBatchUpdateException.getMessage(),
287:                                theFinalStates4[i]);
288:
289:                    } catch (Exception e) {
290:                        if (theExceptions[i] == null) {
291:                            fail(i + "Unexpected exception");
292:                        }
293:                        assertEquals(i + "Exception mismatch", e.getClass(),
294:                                theExceptions[i].getClass());
295:                        assertEquals(i + "Exception mismatch", e.getMessage(),
296:                                theExceptions[i].getMessage());
297:                    } // end try
298:                } // end for
299:
300:            } // end method testBatchUpdateExceptionStringStringintintArray
301:
302:            /*
303:             * Method test for getUpdateCounts
304:             */
305:            public void testGetUpdateCounts() {
306:
307:                BatchUpdateException aBatchUpdateException;
308:                int[][] init1 = { { 1, 2, 3 }, {}, null };
309:
310:                int[] theReturn;
311:                int[][] theReturns = init1;
312:
313:                int[] theFinalStates1 = { 0, 0, 0 }; // Error Code state
314:                int[][] theFinalStates2 = init1; // Update Counts array state
315:                String[] theFinalStates3 = { null, null, null }; // SQL State state
316:                // value
317:                String[] theFinalStates4 = { null, null, null }; // Message state
318:
319:                Exception[] theExceptions = { null, null, null };
320:
321:                int loopCount = init1.length;
322:                for (int i = 0; i < loopCount; i++) {
323:                    try {
324:                        aBatchUpdateException = new BatchUpdateException(
325:                                init1[i]);
326:                        theReturn = aBatchUpdateException.getUpdateCounts();
327:                        if (theExceptions[i] != null) {
328:                            fail(i + "Exception missed");
329:                        }
330:                        assertEquals(i + "Return value mismatch", theReturn,
331:                                theReturns[i]);
332:                        assertEquals(i + " Final state mismatch: ",
333:                                aBatchUpdateException.getErrorCode(),
334:                                theFinalStates1[i]);
335:                        assertEquals(i + " Final state mismatch: ",
336:                                aBatchUpdateException.getUpdateCounts(),
337:                                theFinalStates2[i]);
338:                        assertEquals(i + " Final state mismatch: ",
339:                                aBatchUpdateException.getSQLState(),
340:                                theFinalStates3[i]);
341:                        assertEquals(i + " Final state mismatch: ",
342:                                aBatchUpdateException.getMessage(),
343:                                theFinalStates4[i]);
344:
345:                    } catch (Exception e) {
346:                        if (theExceptions[i] == null) {
347:                            fail(i + "Unexpected exception");
348:                        }
349:                        assertEquals(i + "Exception mismatch", e.getClass(),
350:                                theExceptions[i].getClass());
351:                        assertEquals(i + "Exception mismatch", e.getMessage(),
352:                                theExceptions[i].getMessage());
353:                    } // end try
354:                } // end for
355:
356:            } // end method testGetUpdateCounts
357:
358:            /**
359:             * @tests serialization/deserialization compatibility.
360:             */
361:            public void testSerializationSelf() throws Exception {
362:                BatchUpdateException object = new BatchUpdateException();
363:                SerializationTest.verifySelf(object,
364:                        BATCHUPDATEEXCEPTION_COMPARATOR);
365:            }
366:
367:            /**
368:             * @tests serialization/deserialization compatibility with RI.
369:             */
370:            public void testSerializationCompatibility() throws Exception {
371:                int vendorCode = 10;
372:                int[] updateCounts = { 1, 2, 3, 4 };
373:                BatchUpdateException object = new BatchUpdateException(
374:                        "reason", "SQLState", vendorCode, updateCounts);
375:                SerializationTest.verifyGolden(this , object,
376:                        BATCHUPDATEEXCEPTION_COMPARATOR);
377:            }
378:
379:            // comparator for BatchUpdateException field updateCounts
380:            private static final SerializableAssert BATCHUPDATEEXCEPTION_COMPARATOR = new SerializableAssert() {
381:                public void assertDeserialized(Serializable initial,
382:                        Serializable deserialized) {
383:
384:                    // do common checks for all throwable objects
385:                    SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(
386:                            initial, deserialized);
387:
388:                    BatchUpdateException initThr = (BatchUpdateException) initial;
389:                    BatchUpdateException dserThr = (BatchUpdateException) deserialized;
390:
391:                    // verify updateCounts
392:                    int[] initUpdateCounts = initThr.getUpdateCounts();
393:                    int[] dserUpdateCounts = dserThr.getUpdateCounts();
394:                    assertTrue(Arrays
395:                            .equals(initUpdateCounts, dserUpdateCounts));
396:                }
397:            };
398:
399:        } // end class BatchUpdateExceptionTest
w_w_w.j___av__a___2__s___.c_o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.