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.DataTruncation;
022: import org.apache.harmony.testframework.serialization.SerializationTest;
023: import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
024:
025: import junit.framework.TestCase;
026:
027: public class DataTruncationTest extends TestCase {
028:
029: /*
030: * ConstructorTest
031: */
032: public void testDataTruncationintbooleanbooleanintint() {
033:
034: int[] init1 = { -2147483648, 2147483647, 0, 329751502,
035: 318587557, -1217247045, 329474146 };
036: boolean[] init2 = { false, true, false, false, false, true,
037: false };
038: boolean[] init3 = { false, true, false, false, false, false,
039: true };
040: int[] init4 = { -2147483648, 2147483647, 0, 1761409290,
041: -1331044048, -576231606, 661635011 };
042: int[] init5 = { -2147483648, 2147483647, 0, 540816689,
043: -1890783845, -105552912, -85923935 };
044:
045: String[] theFinalStates1 = { "01004", "01004", "01004",
046: "01004", "01004", "01004", "01004" };
047: String state2 = "Data truncation";
048: String[] theFinalStates2 = { state2, state2, state2, state2,
049: state2, state2, state2 };
050: int[] theFinalStates3 = { 0, 0, 0, 0, 0, 0, 0 };
051: int[] theFinalStates4 = init1;
052: int[] theFinalStates5 = init4;
053: int[] theFinalStates6 = init5;
054: boolean[] theFinalStates7 = init2;
055: boolean[] theFinalStates8 = init3;
056:
057: Exception[] theExceptions = { null, null, null, null, null,
058: null, null };
059:
060: DataTruncation aDataTruncation;
061: int loopCount = init1.length;
062: for (int i = 0; i < loopCount; i++) {
063: try {
064: aDataTruncation = new DataTruncation(init1[i],
065: init2[i], init3[i], init4[i], init5[i]);
066: if (theExceptions[i] != null) {
067: fail();
068: }
069: assertEquals(i + " Final state mismatch",
070: aDataTruncation.getSQLState(),
071: theFinalStates1[i]);
072: assertEquals(i + " Final state mismatch",
073: aDataTruncation.getMessage(),
074: theFinalStates2[i]);
075: assertEquals(i + " Final state mismatch",
076: aDataTruncation.getErrorCode(),
077: theFinalStates3[i]);
078: assertEquals(i + " Final state mismatch",
079: aDataTruncation.getIndex(), theFinalStates4[i]);
080: assertEquals(i + " Final state mismatch",
081: aDataTruncation.getDataSize(),
082: theFinalStates5[i]);
083: assertEquals(i + " Final state mismatch",
084: aDataTruncation.getTransferSize(),
085: theFinalStates6[i]);
086: assertEquals(i + " Final state mismatch",
087: aDataTruncation.getParameter(),
088: theFinalStates7[i]);
089: assertEquals(i + " Final state mismatch",
090: aDataTruncation.getRead(), theFinalStates8[i]);
091:
092: } catch (Exception e) {
093: if (theExceptions[i] == null) {
094: fail(i + "Unexpected exception");
095: }
096: assertEquals(i + "Exception mismatch", e.getClass(),
097: theExceptions[i].getClass());
098: assertEquals(i + "Exception mismatch", e.getMessage(),
099: theExceptions[i].getMessage());
100: } // end try
101: } // end for
102:
103: } // end method testDataTruncationintbooleanbooleanintint
104:
105: /*
106: * Method test for getIndex
107: */
108: public void testGetIndex() {
109:
110: DataTruncation aDataTruncation;
111: int[] init1 = { -2147483648, 2147483647, 0, -2045829673,
112: 1977156911, 478985827, 1687271915 };
113: boolean[] init2 = { false, true, false, false, true, true, true };
114: boolean[] init3 = { false, true, false, false, true, true, true };
115: int[] init4 = { -2147483648, 2147483647, 0, -631377748,
116: 21025030, 1215194589, 1064137121 };
117: int[] init5 = { -2147483648, 2147483647, 0, -897998505,
118: 997578180, 735015866, 264619424 };
119:
120: int theReturn;
121: int[] theReturns = init1;
122: String[] theFinalStates1 = { "01004", "01004", "01004",
123: "01004", "01004", "01004", "01004" };
124: String state2 = "Data truncation";
125: String[] theFinalStates2 = { state2, state2, state2, state2,
126: state2, state2, state2 };
127: int[] theFinalStates3 = { 0, 0, 0, 0, 0, 0, 0 };
128: int[] theFinalStates4 = init1;
129: int[] theFinalStates5 = init4;
130: int[] theFinalStates6 = init5;
131: boolean[] theFinalStates7 = init2;
132: boolean[] theFinalStates8 = init3;
133:
134: Exception[] theExceptions = { null, null, null, null, null,
135: null, null };
136:
137: int loopCount = 1;
138: for (int i = 0; i < loopCount; i++) {
139: try {
140: aDataTruncation = new DataTruncation(init1[i],
141: init2[i], init3[i], init4[i], init5[i]);
142: theReturn = aDataTruncation.getIndex();
143: if (theExceptions[i] != null) {
144: fail(i + "Exception missed");
145: }
146: assertEquals(i + "Return value mismatch", theReturn,
147: theReturns[i]);
148: assertEquals(i + " Final state mismatch",
149: aDataTruncation.getSQLState(),
150: theFinalStates1[i]);
151: assertEquals(i + " Final state mismatch",
152: aDataTruncation.getMessage(),
153: theFinalStates2[i]);
154: assertEquals(i + " Final state mismatch",
155: aDataTruncation.getErrorCode(),
156: theFinalStates3[i]);
157: assertEquals(i + " Final state mismatch",
158: aDataTruncation.getIndex(), theFinalStates4[i]);
159: assertEquals(i + " Final state mismatch",
160: aDataTruncation.getDataSize(),
161: theFinalStates5[i]);
162: assertEquals(i + " Final state mismatch",
163: aDataTruncation.getTransferSize(),
164: theFinalStates6[i]);
165: assertEquals(i + " Final state mismatch",
166: aDataTruncation.getParameter(),
167: theFinalStates7[i]);
168: assertEquals(i + " Final state mismatch",
169: aDataTruncation.getRead(), theFinalStates8[i]);
170:
171: } catch (Exception e) {
172: if (theExceptions[i] == null) {
173: fail(i + "Unexpected exception");
174: }
175: assertEquals(i + "Exception mismatch", e.getClass(),
176: theExceptions[i].getClass());
177: assertEquals(i + "Exception mismatch", e.getMessage(),
178: theExceptions[i].getMessage());
179: } // end try
180: } // end for
181:
182: } // end method testGetIndex
183:
184: /*
185: * Method test for getParameter
186: */
187: public void testGetParameter() {
188:
189: DataTruncation aDataTruncation;
190: int[] init1 = { -2147483648, 2147483647, 0, -492314242,
191: 1637665948, -305785075, 258819883 };
192: boolean[] init2 = { false, true, false, true, true, false, true };
193: boolean[] init3 = { false, true, false, false, false, true,
194: true };
195: int[] init4 = { -2147483648, 2147483647, 0, 1134512579,
196: 533874007, 1709608139, 990656593 };
197: int[] init5 = { -2147483648, 2147483647, 0, -1566784226,
198: -744009101, -444614454, 356465980 };
199:
200: boolean theReturn;
201: boolean[] theReturns = init2;
202: String[] theFinalStates1 = { "01004", "01004", "01004",
203: "01004", "01004", "01004", "01004" };
204: String state2 = "Data truncation";
205: String[] theFinalStates2 = { state2, state2, state2, state2,
206: state2, state2, state2 };
207: int[] theFinalStates3 = { 0, 0, 0, 0, 0, 0, 0 };
208: int[] theFinalStates4 = init1;
209: int[] theFinalStates5 = init4;
210: int[] theFinalStates6 = init5;
211: boolean[] theFinalStates7 = init2;
212: boolean[] theFinalStates8 = init3;
213:
214: Exception[] theExceptions = { null, null, null, null, null,
215: null, null };
216:
217: int loopCount = 1;
218: for (int i = 0; i < loopCount; i++) {
219: try {
220: aDataTruncation = new DataTruncation(init1[i],
221: init2[i], init3[i], init4[i], init5[i]);
222: theReturn = aDataTruncation.getParameter();
223: if (theExceptions[i] != null) {
224: fail(i + "Exception missed");
225: }
226: assertEquals(i + "Return value mismatch", theReturn,
227: theReturns[i]);
228: assertEquals(i + " Final state mismatch",
229: aDataTruncation.getSQLState(),
230: theFinalStates1[i]);
231: assertEquals(i + " Final state mismatch",
232: aDataTruncation.getMessage(),
233: theFinalStates2[i]);
234: assertEquals(i + " Final state mismatch",
235: aDataTruncation.getErrorCode(),
236: theFinalStates3[i]);
237: assertEquals(i + " Final state mismatch",
238: aDataTruncation.getIndex(), theFinalStates4[i]);
239: assertEquals(i + " Final state mismatch",
240: aDataTruncation.getDataSize(),
241: theFinalStates5[i]);
242: assertEquals(i + " Final state mismatch",
243: aDataTruncation.getTransferSize(),
244: theFinalStates6[i]);
245: assertEquals(i + " Final state mismatch",
246: aDataTruncation.getParameter(),
247: theFinalStates7[i]);
248: assertEquals(i + " Final state mismatch",
249: aDataTruncation.getRead(), theFinalStates8[i]);
250:
251: } catch (Exception e) {
252: if (theExceptions[i] == null) {
253: fail(i + "Unexpected exception");
254: }
255: assertEquals(i + "Exception mismatch", e.getClass(),
256: theExceptions[i].getClass());
257: assertEquals(i + "Exception mismatch", e.getMessage(),
258: theExceptions[i].getMessage());
259: } // end try
260: } // end for
261:
262: } // end method testGetParameter
263:
264: /*
265: * Method test for getRead
266: */
267: public void testGetRead() {
268:
269: DataTruncation aDataTruncation;
270: int[] init1 = { -2147483648, 2147483647, 0, 2092420209,
271: -1695764964, 1832837995, -80199594 };
272: boolean[] init2 = { false, true, false, false, false, true,
273: true };
274: boolean[] init3 = { false, true, false, false, true, true,
275: false };
276: int[] init4 = { -2147483648, 2147483647, 0, 1762375167,
277: -604897453, 1362491587, 1007466498 };
278: int[] init5 = { -2147483648, 2147483647, 0, 1494407222,
279: -1696982311, -940493360, -1777579868 };
280:
281: boolean theReturn;
282: boolean[] theReturns = init3;
283: String[] theFinalStates1 = { "01004", "01004", "01004",
284: "01004", "01004", "01004", "01004" };
285: String state2 = "Data truncation";
286: String[] theFinalStates2 = { state2, state2, state2, state2,
287: state2, state2, state2 };
288: int[] theFinalStates3 = { 0, 0, 0, 0, 0, 0, 0 };
289: int[] theFinalStates4 = init1;
290: int[] theFinalStates5 = init4;
291: int[] theFinalStates6 = init5;
292: boolean[] theFinalStates7 = init2;
293: boolean[] theFinalStates8 = init3;
294:
295: Exception[] theExceptions = { null, null, null, null, null,
296: null, null };
297:
298: int loopCount = 1;
299: for (int i = 0; i < loopCount; i++) {
300: try {
301: aDataTruncation = new DataTruncation(init1[i],
302: init2[i], init3[i], init4[i], init5[i]);
303: theReturn = aDataTruncation.getRead();
304: if (theExceptions[i] != null) {
305: fail(i + "Exception missed");
306: }
307: assertEquals(i + "Return value mismatch", theReturn,
308: theReturns[i]);
309: assertEquals(i + " Final state mismatch",
310: aDataTruncation.getSQLState(),
311: theFinalStates1[i]);
312: assertEquals(i + " Final state mismatch",
313: aDataTruncation.getMessage(),
314: theFinalStates2[i]);
315: assertEquals(i + " Final state mismatch",
316: aDataTruncation.getErrorCode(),
317: theFinalStates3[i]);
318: assertEquals(i + " Final state mismatch",
319: aDataTruncation.getIndex(), theFinalStates4[i]);
320: assertEquals(i + " Final state mismatch",
321: aDataTruncation.getDataSize(),
322: theFinalStates5[i]);
323: assertEquals(i + " Final state mismatch",
324: aDataTruncation.getTransferSize(),
325: theFinalStates6[i]);
326: assertEquals(i + " Final state mismatch",
327: aDataTruncation.getParameter(),
328: theFinalStates7[i]);
329: assertEquals(i + " Final state mismatch",
330: aDataTruncation.getRead(), theFinalStates8[i]);
331:
332: } catch (Exception e) {
333: if (theExceptions[i] == null) {
334: fail(i + "Unexpected exception");
335: }
336: assertEquals(i + "Exception mismatch", e.getClass(),
337: theExceptions[i].getClass());
338: assertEquals(i + "Exception mismatch", e.getMessage(),
339: theExceptions[i].getMessage());
340: } // end try
341: } // end for
342:
343: } // end method testGetRead
344:
345: /*
346: * Method test for getDataSize
347: */
348: public void testGetDataSize() {
349:
350: DataTruncation aDataTruncation;
351: int[] init1 = { -2147483648, 2147483647, 0, 1146707040,
352: -2020665632, 1268632617, -1595624039 };
353: boolean[] init2 = { false, true, false, true, false, true, true };
354: boolean[] init3 = { false, true, false, true, true, false,
355: false };
356: int[] init4 = { -2147483648, 2147483647, 0, -367493363,
357: 328996907, -1581326731, 835022052 };
358: int[] init5 = { -2147483648, 2147483647, 0, -886134194,
359: 908213800, 1123419516, -429606389 };
360:
361: int theReturn;
362: int[] theReturns = init4;
363: String[] theFinalStates1 = { "01004", "01004", "01004",
364: "01004", "01004", "01004", "01004" };
365: String state2 = "Data truncation";
366: String[] theFinalStates2 = { state2, state2, state2, state2,
367: state2, state2, state2 };
368: int[] theFinalStates3 = { 0, 0, 0, 0, 0, 0, 0 };
369: int[] theFinalStates4 = init1;
370: int[] theFinalStates5 = init4;
371: int[] theFinalStates6 = init5;
372: boolean[] theFinalStates7 = init2;
373: boolean[] theFinalStates8 = init3;
374:
375: Exception[] theExceptions = { null, null, null, null, null,
376: null, null };
377:
378: int loopCount = 1;
379: for (int i = 0; i < loopCount; i++) {
380: try {
381: aDataTruncation = new DataTruncation(init1[i],
382: init2[i], init3[i], init4[i], init5[i]);
383: theReturn = aDataTruncation.getDataSize();
384: if (theExceptions[i] != null) {
385: fail(i + "Exception missed");
386: }
387: assertEquals(i + "Return value mismatch", theReturn,
388: theReturns[i]);
389: assertEquals(i + " Final state mismatch",
390: aDataTruncation.getSQLState(),
391: theFinalStates1[i]);
392: assertEquals(i + " Final state mismatch",
393: aDataTruncation.getMessage(),
394: theFinalStates2[i]);
395: assertEquals(i + " Final state mismatch",
396: aDataTruncation.getErrorCode(),
397: theFinalStates3[i]);
398: assertEquals(i + " Final state mismatch",
399: aDataTruncation.getIndex(), theFinalStates4[i]);
400: assertEquals(i + " Final state mismatch",
401: aDataTruncation.getDataSize(),
402: theFinalStates5[i]);
403: assertEquals(i + " Final state mismatch",
404: aDataTruncation.getTransferSize(),
405: theFinalStates6[i]);
406: assertEquals(i + " Final state mismatch",
407: aDataTruncation.getParameter(),
408: theFinalStates7[i]);
409: assertEquals(i + " Final state mismatch",
410: aDataTruncation.getRead(), theFinalStates8[i]);
411:
412: } catch (Exception e) {
413: if (theExceptions[i] == null) {
414: fail(i + "Unexpected exception");
415: }
416: assertEquals(i + "Exception mismatch", e.getClass(),
417: theExceptions[i].getClass());
418: assertEquals(i + "Exception mismatch", e.getMessage(),
419: theExceptions[i].getMessage());
420: } // end try
421: } // end for
422:
423: } // end method testGetDataSize
424:
425: /*
426: * Method test for getTransferSize
427: */
428: public void testGetTransferSize() {
429:
430: DataTruncation aDataTruncation;
431: int[] init1 = { -2147483648, 2147483647, 0, 78096124,
432: 1719192600, -1661234694, -1205825753 };
433: boolean[] init2 = { false, true, false, false, true, false,
434: true };
435: boolean[] init3 = { false, true, false, false, false, false,
436: false };
437: int[] init4 = { -2147483648, 2147483647, 0, -493779295,
438: -2042560243, -217347438, 1357818664 };
439: int[] init5 = { -2147483648, 2147483647, 0, -1647009002,
440: -717544563, -1368171905, -918209633 };
441:
442: int theReturn;
443: int[] theReturns = init5;
444: String[] theFinalStates1 = { "01004", "01004", "01004",
445: "01004", "01004", "01004", "01004" };
446: String state2 = "Data truncation";
447: String[] theFinalStates2 = { state2, state2, state2, state2,
448: state2, state2, state2 };
449: int[] theFinalStates3 = { 0, 0, 0, 0, 0, 0, 0 };
450: int[] theFinalStates4 = init1;
451: int[] theFinalStates5 = init4;
452: int[] theFinalStates6 = init5;
453: boolean[] theFinalStates7 = init2;
454: boolean[] theFinalStates8 = init3;
455:
456: Exception[] theExceptions = { null, null, null, null, null,
457: null, null };
458:
459: int loopCount = 1;
460: for (int i = 0; i < loopCount; i++) {
461: try {
462: aDataTruncation = new DataTruncation(init1[i],
463: init2[i], init3[i], init4[i], init5[i]);
464: theReturn = aDataTruncation.getTransferSize();
465: if (theExceptions[i] != null) {
466: fail(i + "Exception missed");
467: }
468: assertEquals(i + "Return value mismatch", theReturn,
469: theReturns[i]);
470: assertEquals(i + " Final state mismatch",
471: aDataTruncation.getSQLState(),
472: theFinalStates1[i]);
473: assertEquals(i + " Final state mismatch",
474: aDataTruncation.getMessage(),
475: theFinalStates2[i]);
476: assertEquals(i + " Final state mismatch",
477: aDataTruncation.getErrorCode(),
478: theFinalStates3[i]);
479: assertEquals(i + " Final state mismatch",
480: aDataTruncation.getIndex(), theFinalStates4[i]);
481: assertEquals(i + " Final state mismatch",
482: aDataTruncation.getDataSize(),
483: theFinalStates5[i]);
484: assertEquals(i + " Final state mismatch",
485: aDataTruncation.getTransferSize(),
486: theFinalStates6[i]);
487: assertEquals(i + " Final state mismatch",
488: aDataTruncation.getParameter(),
489: theFinalStates7[i]);
490: assertEquals(i + " Final state mismatch",
491: aDataTruncation.getRead(), theFinalStates8[i]);
492:
493: } catch (Exception e) {
494: if (theExceptions[i] == null) {
495: fail(i + "Unexpected exception");
496: }
497: assertEquals(i + "Exception mismatch", e.getClass(),
498: theExceptions[i].getClass());
499: assertEquals(i + "Exception mismatch", e.getMessage(),
500: theExceptions[i].getMessage());
501: } // end try
502: } // end for
503:
504: } // end method testGetTransferSize
505:
506: /**
507: * @tests serialization/deserialization compatibility.
508: */
509: public void testSerializationSelf() throws Exception {
510: DataTruncation object = new DataTruncation(10, true, true, 10,
511: 10);
512: SerializationTest.verifySelf(object, DATATRUNCATION_COMPARATOR);
513: }
514:
515: /**
516: * @tests serialization/deserialization compatibility with RI.
517: */
518: public void testSerializationCompatibility() throws Exception {
519: DataTruncation object = new DataTruncation(10, true, true, 10,
520: 10);
521: SerializationTest.verifyGolden(this , object,
522: DATATRUNCATION_COMPARATOR);
523: }
524:
525: // comparator for DataTruncation objects
526: private static final SerializableAssert DATATRUNCATION_COMPARATOR = new SerializableAssert() {
527: public void assertDeserialized(Serializable initial,
528: Serializable deserialized) {
529:
530: // do common checks for all throwable objects
531: SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(
532: initial, deserialized);
533:
534: DataTruncation initThr = (DataTruncation) initial;
535: DataTruncation dserThr = (DataTruncation) deserialized;
536:
537: // verify index
538: assertEquals(initThr.getIndex(), dserThr.getIndex());
539:
540: // verify parameter
541: assertEquals(initThr.getParameter(), dserThr.getParameter());
542:
543: // verify read
544: assertEquals(initThr.getRead(), dserThr.getRead());
545:
546: // verify dataSize
547: assertEquals(initThr.getDataSize(), dserThr.getDataSize());
548:
549: // verify transferSize
550: assertEquals(initThr.getTransferSize(), dserThr
551: .getTransferSize());
552: }
553: };
554:
555: } // end class DataTruncationTest
|