summaryrefslogtreecommitdiffstats
path: root/sdo-java/branches/emf-2.5/impl/src/test/java/org/apache/tuscany/sdo/test/TypeConversionTestCase.java
blob: 80dce4aaebcd288be57ba07e4237497282f3bf5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
/**
 *
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */

package org.apache.tuscany.sdo.test;

import junit.framework.TestCase;


import java.io.InputStream;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.Date;
import java.util.TimeZone;

import org.apache.tuscany.sdo.util.DataObjectUtil;

import commonj.sdo.DataObject;
import commonj.sdo.Property;
import commonj.sdo.Type;
import commonj.sdo.helper.DataFactory;
import commonj.sdo.helper.TypeHelper;
import commonj.sdo.helper.XSDHelper;

public class TypeConversionTestCase extends TestCase
{
    // The following constants are used to get Types from XSDs
    
    private static final String TEST_MODEL = "/api_test.xsd";
    private static final String TEST_NAMESPACE = "http://www.example.com/api_test";    

    // The following constants describe the index for the fields in api_test.xsd.
    
    private static final int STRING_VAL_INDEX = 0;
    private static final int BOOLEAN_VAL_INDEX = 1;
    private static final int BYTE_VAL_INDEX = 3;
    private static final int DECIMAL_VAL_INDEX = 5;
    private static final int INT_VAL_INDEX = 7;
    private static final int FLOAT_VAL_INDEX = 8;
    private static final int DOUBLE_VAL_INDEX = 9;
    private static final int DATE_VAL_INDEX = 10;
    private static final int SHORT_VAL_INDEX = 11;
    private static final int LONG_VAL_INDEX = 12;
    private static final int BYTES_VAL_INDEX = 14;
    private static final int INTEGER_VAL_INDEX = 15;
    private static final int CHAR_VAL_INDEX = 16;
    
    // The following variables are Method arrays.  Each array refers to a specific get<Type>, but within
    // the array exist the get<Type>(index), get<Type>(property), and get<Type>(path).  Rather than
    // referring to each of the three in every circumstance, the more compact array appears.
    private static ConversionType TO_BOOLEAN = new ConversionType("Boolean", boolean.class );
    private static ConversionType TO_BYTE = new ConversionType("Byte", byte.class );
    private static ConversionType TO_CHAR = new ConversionType("Char", char.class );
    private static ConversionType TO_DOUBLE = new ConversionType("Double", double.class );
    private static ConversionType TO_FLOAT = new ConversionType("Float", float.class );
    private static ConversionType TO_INT = new ConversionType("Int", int.class );
    private static ConversionType TO_LONG = new ConversionType("Long", long.class );
    private static ConversionType TO_SHORT = new ConversionType("Short", short.class );
    private static ConversionType TO_BYTES = new ConversionType("Bytes", byte[].class );
    private static ConversionType TO_BIGDECIMAL = new ConversionType("BigDecimal", java.math.BigDecimal.class );
    private static ConversionType TO_BIGINTEGER = new ConversionType("BigInteger", java.math.BigInteger.class );
    private static ConversionType TO_DATAOBJECT = new ConversionType("DataObject", commonj.sdo.DataObject.class );
    private static ConversionType TO_DATE = new ConversionType("Date", java.util.Date.class );
    private static ConversionType TO_STRING = new ConversionType("String", java.lang.String.class );
    private static ConversionType TO_LIST = new ConversionType("List", java.util.List.class );
    // There is no setXXXX methods for sequence...
    private static ConversionType TO_SEQUENCE = new ConversionType("Sequence", null );
    
    private static GeneralComparator COMPARE_ANY;
    
    //  There will be several instances where a Property must be passed as a parameter.  Have available the Type
    //  to call getProperty() as needed.
    
    private static Type API_TEST_TYPE;
    
    // The default constructor establishes each of the Method and Method[] variables.
    
    public TypeConversionTestCase() throws Exception
    {       
        COMPARE_ANY = new GeneralComparator();
        
        // Populate the meta data for the test model
        URL url = getClass().getResource(TEST_MODEL);
        InputStream inputStream = url.openStream();
        XSDHelper.INSTANCE.define(inputStream, url.toString());
        inputStream.close();

        API_TEST_TYPE = TypeHelper.INSTANCE.getType(TEST_NAMESPACE, "APITest");
 
    }
    
    private static class ConversionType
    {
        // The following constants are used because the getMethod function requires an Class
        // array describing the parameters to the functions.  
        
        private static final Class[] GET_INT_CLASS_ARRAY = {int.class};
        private static final Class[] GET_PROPERTY_CLASS_ARRAY = {Property.class};
        private static final Class[] GET_STRING_CLASS_ARRAY = {String.class};
        private static final Class[] SET_INT_CLASS_ARRAY = {int.class, Class.class};
        private static final Class[] SET_PROPERTY_CLASS_ARRAY = {Property.class, Class.class};
        private static final Class[] SET_STRING_CLASS_ARRAY = {String.class, Class.class};
        
        Method get_index_method;
        Method get_property_method;
        Method get_path_method;
        Method set_index_method;
        Method set_property_method;
        Method set_path_method;
        
        public ConversionType (String method_name, Class type )
        {
            try
            {
                this.get_index_method = DataObject.class.getMethod("get"+method_name, GET_INT_CLASS_ARRAY);
                this.get_property_method = DataObject.class.getMethod("get"+method_name, GET_PROPERTY_CLASS_ARRAY);
                this.get_path_method = DataObject.class.getMethod("get"+method_name, GET_STRING_CLASS_ARRAY);
                if( type != null )
                {
                    SET_INT_CLASS_ARRAY[1] = type;
                    this.set_index_method = DataObject.class.getMethod("set"+method_name, SET_INT_CLASS_ARRAY);
                    SET_PROPERTY_CLASS_ARRAY[1] = type;
                    this.set_property_method = DataObject.class.getMethod("set"+method_name, SET_PROPERTY_CLASS_ARRAY);
                    SET_STRING_CLASS_ARRAY[1] = type;
                    this.set_path_method = DataObject.class.getMethod("set"+method_name, SET_STRING_CLASS_ARRAY);
                }
                else
                {
                    this.set_index_method = null;
                    this.set_property_method = null;
                    this.set_path_method = null;
                }
            }
            catch (NoSuchMethodException e)
            {
                this.get_index_method = null;
                this.get_property_method = null;
                this.get_path_method = null;
                this.set_index_method = null;
                this.set_property_method = null;
                this.set_path_method = null;
            }
        }
        
        public Method getIndexGetMethod()
        {
            return this.get_index_method;
        }
        
        public Method getPropertyGetMethod()
        {
            return this.get_property_method;
        }
        
        public Method getPathGetMethod()
        {
            return this.get_path_method;
        }
        public Method getIndexSetMethod()
        {
            return this.set_index_method;
        }
        
        public Method getPropertySetMethod()
        {
            return this.set_property_method;
        }
        
        public Method getPathSetMethod()
        {
            return this.set_path_method;
        }
    }
 
    // Each instance of Test describes a convert-from type.  The index, property and path parms
    // will refer to the same field, which is a field of the convert-from type.
    
    private static class Test
    {
        DataObject test_obj;
        Object[] get_index_parm;
        Object[] get_property_parm;
        Object[] get_path_parm;
        Object[] set_index_parm;
        Object[] set_property_parm;
        Object[] set_path_parm;
        Object expected_value;
        String from_type;
        Class  from_type_class;

        // The constructor prepares a test DataObject and determines how to access the field
        // in three different ways - index, property, and path.
        
        Test(String path, int index)
        {
            this.test_obj = DataFactory.INSTANCE.create(API_TEST_TYPE);
            this.get_index_parm = new Object[] {new Integer(index)};
            this.get_property_parm = new Object[] {API_TEST_TYPE.getProperty(path)};
            this.get_path_parm = new Object[] {path};
            this.set_index_parm = new Object[] {new Integer(index), null};
            this.set_property_parm = new Object[] {API_TEST_TYPE.getProperty(path), null};
            this.set_path_parm = new Object[] {path, null};
            this.expected_value = null;
        }
        
        // The initialize() function establishes the initial value of the test field.
        
        public void initialize(Class type, String type_name, Object initial_value) throws Exception
        {
            this.expected_value = initial_value;    
            this.from_type = type_name;
            this.from_type_class = type;
            
            setDefaultValue();
        }
        
        private void setDefaultValue() throws Exception
        {
            Class[] classArray = {int.class, from_type_class};
            Object[] initValueArray = new Object[] {this.get_index_parm[0], expected_value};
            Method setter = DataObject.class.getMethod("set" + from_type, classArray);
            setter.invoke(test_obj, initValueArray);  
        }
        
        // Attempts the conversion to the specified type, using DataObject.get____().
        // The get___() function can be called with an index, path, and property.  attemptConversion()
        // calls each of those three.
        
        public void attemptConversion(ConversionType to_type) throws Exception
        {     
            performConversion(to_type.getIndexGetMethod(), this.get_index_parm, to_type.getIndexSetMethod(), this.set_index_parm);
            performConversion(to_type.getPathGetMethod(), this.get_path_parm, to_type.getPathSetMethod(), this.set_path_parm );
            performConversion(to_type.getPropertyGetMethod(), this.get_property_parm, to_type.getPropertySetMethod(), this.set_property_parm );
        }
        
        public void checkConversionException(ConversionType to_type, Class expected_exception) throws Exception
        {
            boolean index_err, path_err, property_err, consistency_err = false;
            
            index_err = executeExceptionCase(to_type.getIndexGetMethod(), this.get_index_parm, expected_exception);
            path_err = executeExceptionCase(to_type.getPathGetMethod(), this.get_path_parm, expected_exception);
            property_err = executeExceptionCase(to_type.getPropertyGetMethod(), this.get_property_parm, expected_exception);
            
            if (index_err != path_err || path_err != property_err)
                consistency_err = true;
            else if (index_err == false)
                attemptConversion(to_type);
            
            assertFalse("An exception inconsistency exists for " + to_type.getPathGetMethod().getName() + " when called " 
                    + "for a " + this.from_type + " property.", consistency_err);
        }
        
        private void performConversion (Method getMeth, Object[] getParm, Method setMeth, Object[] setParm ) throws Exception
        {       
            // First use the set
            try
            {
                // get the set value 
                setParm[1] = getMeth.invoke(test_obj, getParm);;
                // now set it...
                setMeth.invoke(test_obj, setParm);
            }
            catch (Exception e)
            {
                Throwable cause = e.getCause();
                if (cause == null)
                {
                    System.err.println("An exception of type " + e.getClass() + " occurred while performing " + setMeth.getName()
                          + " on a " + this.from_type + " property.");
                }
                else
                {
                    System.err.println("An exception of type " + cause.getClass() + " occurred while performing " + setMeth.getName()
                          + " on a " + this.from_type + " property.");
                }
                  
                throw e;
            }
            
            try
            {
                
                assertTrue("Conversion did not yield expected value for get" + getMeth.getName() + " on a " + this.from_type + " property.",
                         COMPARE_ANY.compare(getMeth.invoke(test_obj, getParm), this.expected_value) == 0);
            }
            catch (Exception e)
            {
                Throwable cause = e.getCause();
                if (cause == null)
                {
                    System.err.println("An exception of type " + e.getClass() + " occurred while performing " + getMeth.getName()
                          + " on a " + this.from_type + " property.");
                }
                else
                {
                    System.err.println("An exception of type " + cause.getClass() + " occurred while performing " + getMeth.getName()
                          + " on a " + this.from_type + " property.");
                }
                  
                throw e;
            }

            // reset to default
            setDefaultValue();
        }
        

        
        private boolean executeExceptionCase (Method convert, Object[] parm, Class expected_exception) throws Exception
        {
            boolean exception_thrown = false;
            try
            {
                convert.invoke(test_obj, parm);
            }
            catch (Exception e)
            {
                exception_thrown = true;
                Throwable cause = e.getCause();
                if (cause == null)
                {
                    assertEquals("An unexpected exception occurred while performing " + convert.getName()
                              + " on a " + this.from_type + " property.", expected_exception, e.getClass());
                }
                else 
                {
                    assertEquals("An unexpected exception occurred while performing " + convert.getName()
                              + " on a " + this.from_type + " property.", expected_exception, cause.getClass());
                }
            }
              
            return exception_thrown;
        }
    }

    private static class GeneralComparator implements Comparator
    {
        public int compare(Object obj1, Object obj2)
        {        
            if (obj1.getClass() == obj2.getClass())
            {
                if (obj1.equals(obj2))
                    return 0;
                else
                    return 1;
            }
            
            else if ( (obj1.getClass() == byte[].class && obj2.getClass() == String.class) ||
                 (obj2.getClass() == byte[].class && obj1.getClass() == String.class) )
            {
                String strVal;
                byte [] byteVal; 
                
                if( obj1.getClass() == String.class )
                {
                    strVal = (String)obj1;
                    byteVal = (byte [])obj2;
                }
                else
                {
                    strVal = (String)obj2;
                    byteVal = (byte [])obj1;
                }
                
                if( strVal.length()/2 != byteVal.length )
                    return -1;
                
                for( int i=0; i<byteVal.length; i++ )
                {
                    if( byteVal[i] != (Byte.decode("0x"+strVal.substring(i*2,(i*2)+2))).byteValue() )
                        return -1;
                }
                
                return 0; 
            }
            
            else if (obj1.getClass() == Date.class)
            {
                if (obj2.getClass() == String.class)
                {
                    try
                    {                
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy'-'MM'-'dd'T'H':'mm':'ss.S");
                        
                        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
                        obj2 = sdf.parse((String) obj2);
                                                
                        if (obj1.equals(obj2))
                            return 0;                        
                    }
                    catch (Exception e)
                    {
                        System.out.println(e.getMessage());
                    }

                    return 1;
                }
                
                else
                {
                    Date temp = (Date) obj1;
                    
                    return compare(new Long(temp.getTime()), obj2);
                }                                      
                
            }

            else if (obj2.getClass() == Date.class)
            {                
                return compare(obj2, obj1);
            }                
            
            else if (obj1.getClass() == Boolean.class)
            {
                Boolean temp = (Boolean) obj1;
                
                if (temp.booleanValue())
                {
                    if (obj2.toString().equalsIgnoreCase("true"))
                       return 0;
                    else
                        return 1;
                }
                
                else
                {
                    if (obj2.toString().equalsIgnoreCase("true"))
                       return 1;
                    else
                        return 0;
                }
            }
            
            else if (obj2.getClass() == Boolean.class)
               return compare(obj2, obj1);
            
            else if (obj1.getClass() == Byte.class || obj2.getClass() == Byte.class)
            {
                byte b1 = (Double.valueOf(obj1.toString())).byteValue();
                byte b2 = (Double.valueOf(obj2.toString())).byteValue();
                
                if (b1 == b2)
                    return 0;
                else if (b1 < b2)
                    return -1;
                else
                    return 1;
            }
            
            else if (obj1.getClass().toString().charAt(6) == '[')
            {
                long result = 0;
                long multiplier = 1;
                
                byte[] array = (byte[]) obj1;
                for (int i = 0; i < array.length; i++)
                {
                    result += array[array.length - i - 1] * multiplier;
                    multiplier *= 256;
                }

                return compare(obj2, new Long(result));
            }
            
            else if (obj2.getClass().toString().charAt(6) == '[')
            {
                return compare(obj2, obj1);
            }
            
            else if (obj1.getClass() == Short.class || obj2.getClass() == Short.class)
            {
                short s1 = (Double.valueOf(obj1.toString())).shortValue();
                short s2 = (Double.valueOf(obj2.toString())).shortValue();
                
                if (s1 == s2)
                    return 0;
                else if (s1 < s2)
                    return -1;
                else
                    return 1;                
            }
            
            else if (obj1.getClass() == Integer.class || obj2.getClass() == Integer.class)
            {                
                int i1 = (Double.valueOf(obj1.toString())).intValue();
                int i2 = (Double.valueOf(obj2.toString())).intValue();
                
                if (i1 == i2)
                    return 0;
                else if (i1 < i2)
                    return -1;
                else
                    return 1;                
            }            
            
            else if (   obj1.getClass() == Long.class || obj2.getClass() == Long.class
                     || obj1.getClass() == BigInteger.class || obj2.getClass() == BigInteger.class)
            {
                long l1 = (Double.valueOf(obj1.toString())).longValue();
                long l2 = (Double.valueOf(obj2.toString())).longValue();
                
                if (l1 == l2)
                    return 0;
                else if (l1 < l2)
                    return -1;
                else
                    return 1;                
            }

            else if (obj1.getClass() == Float.class || obj2.getClass() == Float.class)
            {
                float f1 = (Double.valueOf(obj1.toString())).floatValue();
                float f2 = (Double.valueOf(obj2.toString())).floatValue();
                
                if (f1 == f2)
                    return 0;
                else if (f1 < f2)
                    return -1;
                else
                    return 1;                
            }
            
            else if (obj1.getClass() == Double.class || obj2.getClass() == Double.class)
            {
                Double b1 = Double.valueOf(obj1.toString());
                Double b2 = Double.valueOf(obj2.toString());
                
                return b1.compareTo(b2);                
            }
        
            else if (obj1.getClass() == BigDecimal.class || obj2.getClass() == BigDecimal.class)
            {
                BigDecimal b1 = new BigDecimal(obj1.toString());
                BigDecimal b2 = new BigDecimal(obj2.toString());
                
                return b1.compareTo(b2);                
            }
            
            else
            {
                if (obj1.toString().equals(obj2.toString()))
                    return 0;
                else
                    return 1;
            }
        }
        
    }    

    /**********************************************************
     * In the following test cases, several instances are commented out.
     * For these cases, the test case currently fails.  A JIRA issue (TUSCANY-581) has 
     * been opened to either correct the behavior (then uncomment the lines) or to 
     * alter the specification against which the test cases were designed (and then
     * remove the lines - assuming the alteration is to remove stating the 
     * nature of the exception).  
     */
    
    public void testBooleanConversion() throws Exception
    {
        Test FromBoolean = new Test("booleanVal", BOOLEAN_VAL_INDEX);
        
        FromBoolean.initialize(boolean.class, "Boolean", Boolean.valueOf(true));
        
        FromBoolean.attemptConversion(TO_BOOLEAN);
        FromBoolean.attemptConversion(TO_STRING);
    } 
    
    public void testBooleanExceptions() throws Exception
    {
        Test FromBoolean = new Test("booleanVal", BOOLEAN_VAL_INDEX);

        FromBoolean.initialize(boolean.class, "Boolean", Boolean.valueOf(true));

//        FromBoolean.checkConversionException(TO_BYTE, ClassCastException.class);
//        FromBoolean.checkConversionException(TO_CHAR, ClassCastException.class);
//        FromBoolean.checkConversionException(TO_DOUBLE, ClassCastException.class);
//        FromBoolean.checkConversionException(TO_FLOAT, ClassCastException.class);
//        FromBoolean.checkConversionException(TO_INT, ClassCastException.class);
//        FromBoolean.checkConversionException(TO_LONG, ClassCastException.class);
//        FromBoolean.checkConversionException(TO_SHORT, ClassCastException.class);
//        FromBoolean.checkConversionException(TO_BYTES, ClassCastException.class);
//        FromBoolean.checkConversionException(TO_BIGDECIMAL, ClassCastException.class);
//        FromBoolean.checkConversionException(TO_BIGINTEGER, ClassCastException.class);
        FromBoolean.checkConversionException(TO_DATAOBJECT, ClassCastException.class);
//        FromBoolean.checkConversionException(TO_DATE, ClassCastException.class);
        FromBoolean.checkConversionException(TO_LIST, ClassCastException.class);
        FromBoolean.checkConversionException(TO_SEQUENCE, ClassCastException.class);
    }
    
    public void testByteConversion() throws Exception
    {
        Test FromByte = new Test("byteVal", BYTE_VAL_INDEX);
        
        FromByte.initialize(byte.class, "Byte", Byte.valueOf("-127"));
        
        FromByte.attemptConversion(TO_BYTE);
        FromByte.attemptConversion(TO_DOUBLE);
        FromByte.attemptConversion(TO_FLOAT);
        FromByte.attemptConversion(TO_INT);
        FromByte.attemptConversion(TO_LONG);
        FromByte.attemptConversion(TO_SHORT);
        FromByte.attemptConversion(TO_STRING);
    }
    
    public void testByteExceptions() throws Exception
    {
        Test FromByte = new Test("byteVal", BYTE_VAL_INDEX);
        
        FromByte.initialize(byte.class, "Byte", Byte.valueOf("-127"));

//        FromByte.checkConversionException(TO_BOOLEAN, ClassCastException.class);
//        FromByte.checkConversionException(TO_CHAR, ClassCastException.class);
//        FromByte.checkConversionException(TO_BYTES, ClassCastException.class);
        FromByte.checkConversionException(TO_BIGDECIMAL, ClassCastException.class);
        FromByte.checkConversionException(TO_BIGINTEGER, ClassCastException.class);
        FromByte.checkConversionException(TO_DATAOBJECT, ClassCastException.class);
//        FromByte.checkConversionException(TO_DATE, ClassCastException.class);
        FromByte.checkConversionException(TO_LIST, ClassCastException.class);
        FromByte.checkConversionException(TO_SEQUENCE, ClassCastException.class);
    }

    public void testCharConversion() throws Exception
    {
        Test FromChar = new Test("charVal", CHAR_VAL_INDEX);
        
        FromChar.initialize(char.class, "Char", new Character('?'));
        
        FromChar.attemptConversion(TO_CHAR);
        FromChar.attemptConversion(TO_STRING);
    }
    
    public void testCharExceptions() throws Exception
    {
        Test FromChar = new Test("charVal", CHAR_VAL_INDEX);
        
        FromChar.initialize(char.class, "Char", new Character('?'));

//        FromChar.checkConversionException(TO_BOOLEAN, ClassCastException.class);        
//        FromChar.checkConversionException(TO_BYTE, ClassCastException.class);
//        FromChar.checkConversionException(TO_DOUBLE, ClassCastException.class);
//        FromChar.checkConversionException(TO_FLOAT, ClassCastException.class);
//        FromChar.checkConversionException(TO_INT, ClassCastException.class);
//        FromChar.checkConversionException(TO_LONG, ClassCastException.class);
//        FromChar.checkConversionException(TO_SHORT, ClassCastException.class);
//        FromChar.checkConversionException(TO_BYTES, ClassCastException.class);
//        FromChar.checkConversionException(TO_BIGDECIMAL, ClassCastException.class);
//        FromChar.checkConversionException(TO_BIGINTEGER, ClassCastException.class);
        FromChar.checkConversionException(TO_DATAOBJECT, ClassCastException.class);
//        FromChar.checkConversionException(TO_DATE, ClassCastException.class);
        FromChar.checkConversionException(TO_LIST, ClassCastException.class);
        FromChar.checkConversionException(TO_SEQUENCE, ClassCastException.class);
    }
    
    public void testDoubleConversion() throws Exception
    {
        Test FromDouble = new Test("doubleVal", DOUBLE_VAL_INDEX);
        
        FromDouble.initialize(double.class, "Double", new Double(Double.MAX_VALUE));
        
        FromDouble.attemptConversion(TO_BYTE);
        FromDouble.attemptConversion(TO_DOUBLE);
        FromDouble.attemptConversion(TO_FLOAT);
        FromDouble.attemptConversion(TO_INT);
        FromDouble.attemptConversion(TO_LONG);
        FromDouble.attemptConversion(TO_SHORT);
        FromDouble.attemptConversion(TO_BIGDECIMAL);
        FromDouble.attemptConversion(TO_BIGINTEGER);
        FromDouble.attemptConversion(TO_STRING);
    }
    
    public void testDoubleExceptions() throws Exception
    {
        Test FromDouble = new Test("doubleVal", DOUBLE_VAL_INDEX);
        
        FromDouble.initialize(double.class, "Double", new Double(Double.MAX_VALUE));

//        FromDouble.checkConversionException(TO_BOOLEAN, ClassCastException.class);
//        FromDouble.checkConversionException(TO_CHAR, ClassCastException.class);
//        FromDouble.checkConversionException(TO_BYTES, ClassCastException.class);
        FromDouble.checkConversionException(TO_DATAOBJECT, ClassCastException.class);
//        FromDouble.checkConversionException(TO_DATE, ClassCastException.class);
        FromDouble.checkConversionException(TO_LIST, ClassCastException.class);
        FromDouble.checkConversionException(TO_SEQUENCE, ClassCastException.class);
    }
    
    public void testFloatConversion() throws Exception
    {
        Test FromFloat = new Test("floatVal", FLOAT_VAL_INDEX);
        
        FromFloat.initialize(float.class, "Float", new Float(Float.MIN_VALUE));
        
        FromFloat.attemptConversion(TO_BYTE);
        FromFloat.attemptConversion(TO_DOUBLE);
        FromFloat.attemptConversion(TO_FLOAT);
        FromFloat.attemptConversion(TO_INT);
        FromFloat.attemptConversion(TO_LONG);
        FromFloat.attemptConversion(TO_SHORT);
        FromFloat.attemptConversion(TO_BIGDECIMAL);
        FromFloat.attemptConversion(TO_BIGINTEGER);
        FromFloat.attemptConversion(TO_STRING);
    }

    public void testFloatExceptions() throws Exception
    {
        Test FromFloat = new Test("floatVal", FLOAT_VAL_INDEX);
        
        FromFloat.initialize(float.class, "Float", new Float(Float.MIN_VALUE));

//        FromFloat.checkConversionException(TO_BOOLEAN, ClassCastException.class);
//        FromFloat.checkConversionException(TO_CHAR, ClassCastException.class);
//        FromFloat.checkConversionException(TO_BYTES, ClassCastException.class);
        FromFloat.checkConversionException(TO_DATAOBJECT, ClassCastException.class);
//        FromFloat.checkConversionException(TO_DATE, ClassCastException.class);
        FromFloat.checkConversionException(TO_LIST, ClassCastException.class);
        FromFloat.checkConversionException(TO_SEQUENCE, ClassCastException.class);
    }
    
    public void testIntConversion() throws Exception
    {
        Test FromInt = new Test("intVal", INT_VAL_INDEX);
        
        FromInt.initialize(int.class, "Int", new Integer(5));
        
        FromInt.attemptConversion(TO_BYTE);
        FromInt.attemptConversion(TO_DOUBLE);
        FromInt.attemptConversion(TO_FLOAT);
        FromInt.attemptConversion(TO_INT);
        FromInt.attemptConversion(TO_LONG);
        FromInt.attemptConversion(TO_SHORT);
        FromInt.attemptConversion(TO_BIGDECIMAL);
        FromInt.attemptConversion(TO_BIGINTEGER);
        FromInt.attemptConversion(TO_STRING);
    }
    
    public void testIntExceptions() throws Exception
    {
        Test FromInt = new Test("intVal", INT_VAL_INDEX);
        
        FromInt.initialize(int.class, "Int", new Integer(5));

//        FromInt.checkConversionException(TO_BOOLEAN, ClassCastException.class);
//        FromInt.checkConversionException(TO_CHAR, ClassCastException.class);
//        FromInt.checkConversionException(TO_BYTES, ClassCastException.class);
        FromInt.checkConversionException(TO_DATAOBJECT, ClassCastException.class);
//        FromInt.checkConversionException(TO_DATE, ClassCastException.class);
        FromInt.checkConversionException(TO_LIST, ClassCastException.class);
        FromInt.checkConversionException(TO_SEQUENCE, ClassCastException.class);
    }
    
    public void testLongConversion() throws Exception
    {
        Test FromLong = new Test("longVal", LONG_VAL_INDEX);
        
        FromLong.initialize(long.class, "Long", new Long(7000L));
        
        FromLong.attemptConversion(TO_BYTE);
        FromLong.attemptConversion(TO_DOUBLE);
        FromLong.attemptConversion(TO_FLOAT);
        FromLong.attemptConversion(TO_INT);
        FromLong.attemptConversion(TO_LONG);
        FromLong.attemptConversion(TO_SHORT);
        FromLong.attemptConversion(TO_BIGDECIMAL);
        FromLong.attemptConversion(TO_BIGINTEGER);
        FromLong.attemptConversion(TO_DATE);
        FromLong.attemptConversion(TO_STRING);
    }
    
    public void testLongExceptions() throws Exception
    {
        Test FromLong = new Test("longVal", LONG_VAL_INDEX);
        
        FromLong.initialize(long.class, "Long", new Long(7000L));

//        FromLong.checkConversionException(TO_BOOLEAN, ClassCastException.class);
//        FromLong.checkConversionException(TO_CHAR, ClassCastException.class);
//        FromLong.checkConversionException(TO_BYTES, ClassCastException.class);
        FromLong.checkConversionException(TO_DATAOBJECT, ClassCastException.class);
        FromLong.checkConversionException(TO_LIST, ClassCastException.class);
        FromLong.checkConversionException(TO_SEQUENCE, ClassCastException.class);
    }
    
    public void testShortConversion() throws Exception
    {
        Test FromShort = new Test("shortVal", SHORT_VAL_INDEX);
        
        FromShort.initialize(short.class, "Short", new Short("-8000"));
        
        FromShort.attemptConversion(TO_BYTE);
        FromShort.attemptConversion(TO_DOUBLE);
        FromShort.attemptConversion(TO_FLOAT);
        FromShort.attemptConversion(TO_INT);
        FromShort.attemptConversion(TO_LONG);
        FromShort.attemptConversion(TO_SHORT);
        FromShort.attemptConversion(TO_STRING);
    }    
    
    public void testShortExceptions() throws Exception
    {
        Test FromShort = new Test("shortVal", SHORT_VAL_INDEX);
        
        FromShort.initialize(short.class, "Short", new Short("-8000"));

//        FromShort.checkConversionException(TO_BOOLEAN, ClassCastException.class);
//        FromShort.checkConversionException(TO_CHAR, ClassCastException.class);
//        FromShort.checkConversionException(TO_BYTES, ClassCastException.class);
        FromShort.checkConversionException(TO_BIGDECIMAL, ClassCastException.class);
        FromShort.checkConversionException(TO_BIGINTEGER, ClassCastException.class);
        FromShort.checkConversionException(TO_DATAOBJECT, ClassCastException.class);
//        FromShort.checkConversionException(TO_DATE, ClassCastException.class);
        FromShort.checkConversionException(TO_LIST, ClassCastException.class);
        FromShort.checkConversionException(TO_SEQUENCE, ClassCastException.class);
    }
    
    public void testStringConversion() throws Exception
    {
        Test FromString = new Test("stringVal", STRING_VAL_INDEX);
        
        FromString.initialize(String.class, "String", "5");
        
        FromString.attemptConversion(TO_BOOLEAN);
        FromString.attemptConversion(TO_BYTE);
        FromString.attemptConversion(TO_CHAR);
        FromString.attemptConversion(TO_DOUBLE);
        FromString.attemptConversion(TO_FLOAT);
        FromString.attemptConversion(TO_INT);
        FromString.attemptConversion(TO_LONG);
        FromString.attemptConversion(TO_SHORT);
        FromString.attemptConversion(TO_BIGDECIMAL);
        FromString.attemptConversion(TO_BIGINTEGER);
        FromString.attemptConversion(TO_STRING);

        FromString.initialize(String.class, "String", "1999-07-25T8:50:14.33Z");
        FromString.attemptConversion(TO_DATE);
        
        FromString.initialize(String.class, "String", "0A64");
        FromString.attemptConversion(TO_BYTES);
    }

    public void testStringExceptions() throws Exception
    {
        Test FromString = new Test("stringVal", STRING_VAL_INDEX);
        
        FromString.initialize(String.class, "String", "5");
        
//        FromString.checkConversionException(TO_BYTES, ClassCastException.class);
        FromString.checkConversionException(TO_DATAOBJECT, ClassCastException.class);
        FromString.checkConversionException(TO_LIST, ClassCastException.class);
        FromString.checkConversionException(TO_SEQUENCE, ClassCastException.class);
    }
    
    public void testBytesConversion() throws Exception
    {
        Test FromBytes = new Test("bytesVal", BYTES_VAL_INDEX);
        
        FromBytes.initialize(byte[].class, "Bytes", new byte[] {10,100});
        
        FromBytes.attemptConversion(TO_BYTES);
        FromBytes.attemptConversion(TO_BIGINTEGER);
        FromBytes.attemptConversion(TO_STRING);
    }

    public void testBytesExceptions() throws Exception
    {
        Test FromBytes = new Test("bytesVal", BYTES_VAL_INDEX);
        
        FromBytes.initialize(byte[].class, "Bytes", new byte[] {10,100});
        
//        FromBytes.checkConversionException(TO_BOOLEAN, ClassCastException.class);
//        FromBytes.checkConversionException(TO_BYTE, ClassCastException.class);
//        FromBytes.checkConversionException(TO_CHAR, ClassCastException.class);
//        FromBytes.checkConversionException(TO_DOUBLE, ClassCastException.class);
//        FromBytes.checkConversionException(TO_FLOAT, ClassCastException.class);
//        FromBytes.checkConversionException(TO_INT, ClassCastException.class);
//        FromBytes.checkConversionException(TO_LONG, ClassCastException.class);
//        FromBytes.checkConversionException(TO_SHORT, ClassCastException.class);
//        FromBytes.checkConversionException(TO_BIGDECIMAL, ClassCastException.class);
        FromBytes.checkConversionException(TO_DATAOBJECT, ClassCastException.class);
//        FromBytes.checkConversionException(TO_DATE, ClassCastException.class);
//        FromBytes.checkConversionException(TO_STRING, ClassCastException.class);
        FromBytes.checkConversionException(TO_LIST, ClassCastException.class);
        FromBytes.checkConversionException(TO_SEQUENCE, ClassCastException.class);
    }
      
    public void testBigDecimalConversion() throws Exception
    {
        Test FromBigDecimal = new Test("decimalVal", DECIMAL_VAL_INDEX);
        
        FromBigDecimal.initialize(BigDecimal.class, "BigDecimal", new BigDecimal("-3"));
        
        FromBigDecimal.attemptConversion(TO_DOUBLE);
        FromBigDecimal.attemptConversion(TO_FLOAT);
        FromBigDecimal.attemptConversion(TO_INT);
        FromBigDecimal.attemptConversion(TO_LONG);
        FromBigDecimal.attemptConversion(TO_BIGDECIMAL);
        FromBigDecimal.attemptConversion(TO_BIGINTEGER);
        FromBigDecimal.attemptConversion(TO_STRING);
    }
    
    public void testBigDecimalExceptions() throws Exception
    {
        Test FromBigDecimal = new Test("decimalVal", DECIMAL_VAL_INDEX);
        
        FromBigDecimal.initialize(BigDecimal.class, "BigDecimal", new BigDecimal("-3"));

//        FromBigDecimal.checkConversionException(TO_BOOLEAN, ClassCastException.class);
//        FromBigDecimal.checkConversionException(TO_BYTE, ClassCastException.class);
//        FromBigDecimal.checkConversionException(TO_CHAR, ClassCastException.class);
//        FromBigDecimal.checkConversionException(TO_SHORT, ClassCastException.class);
//        FromBigDecimal.checkConversionException(TO_BYTES, ClassCastException.class);
        FromBigDecimal.checkConversionException(TO_DATAOBJECT, ClassCastException.class);
//        FromBigDecimal.checkConversionException(TO_DATE, ClassCastException.class);
        FromBigDecimal.checkConversionException(TO_LIST, ClassCastException.class);
        FromBigDecimal.checkConversionException(TO_SEQUENCE, ClassCastException.class);
    }
    
    public void testBigIntegerConversion() throws Exception
    {
        Test FromBigInteger = new Test("integerVal", INTEGER_VAL_INDEX);
        
        FromBigInteger.initialize(BigInteger.class, "BigInteger", new BigInteger("31500"));
        
        FromBigInteger.attemptConversion(TO_DOUBLE);
        FromBigInteger.attemptConversion(TO_FLOAT);
        FromBigInteger.attemptConversion(TO_INT);
        FromBigInteger.attemptConversion(TO_LONG);
        FromBigInteger.attemptConversion(TO_SHORT); 
        FromBigInteger.attemptConversion(TO_BYTES);
        FromBigInteger.attemptConversion(TO_BIGDECIMAL);
        FromBigInteger.attemptConversion(TO_BIGINTEGER);
        FromBigInteger.attemptConversion(TO_STRING);
    }
    
    public void testBigIntegerExceptions() throws Exception
    {
        Test FromBigInteger = new Test("integerVal", INTEGER_VAL_INDEX);
        
        FromBigInteger.initialize(BigInteger.class, "BigInteger", new BigInteger("31500"));

//        FromBigInteger.checkConversionException(TO_BOOLEAN, ClassCastException.class);
//        FromBigInteger.checkConversionException(TO_BYTE, ClassCastException.class);
//        FromBigInteger.checkConversionException(TO_CHAR, ClassCastException.class);
        FromBigInteger.checkConversionException(TO_DATAOBJECT, ClassCastException.class);
//        FromBigInteger.checkConversionException(TO_DATE, ClassCastException.class);
        FromBigInteger.checkConversionException(TO_LIST, ClassCastException.class);
        FromBigInteger.checkConversionException(TO_SEQUENCE, ClassCastException.class);
    }

    public void testDateConversion() throws Exception
    {
        Test FromDate = new Test("dateVal", DATE_VAL_INDEX);
        
        FromDate.initialize(Date.class, "Date", new Date(System.currentTimeMillis()));
        
        FromDate.attemptConversion(TO_LONG);
        FromDate.attemptConversion(TO_DATE);
        FromDate.attemptConversion(TO_STRING);
    }    
    
    public void testDateExceptions() throws Exception
    {
        Test FromDate = new Test("dateVal", DATE_VAL_INDEX);
        
        FromDate.initialize(Date.class, "Date", new Date(System.currentTimeMillis()));
        
//        FromDate.checkConversionException(TO_BOOLEAN, ClassCastException.class);
//        FromDate.checkConversionException(TO_BYTE, ClassCastException.class);
//        FromDate.checkConversionException(TO_CHAR, ClassCastException.class);
//        FromDate.checkConversionException(TO_DOUBLE, ClassCastException.class);
//        FromDate.checkConversionException(TO_FLOAT, ClassCastException.class);
//        FromDate.checkConversionException(TO_INT, ClassCastException.class);
//        FromDate.checkConversionException(TO_SHORT, ClassCastException.class);
//        FromDate.checkConversionException(TO_BYTES, ClassCastException.class);
//        FromDate.checkConversionException(TO_BIGDECIMAL, ClassCastException.class);
//        FromDate.checkConversionException(TO_BIGINTEGER, ClassCastException.class);
        FromDate.checkConversionException(TO_DATAOBJECT, ClassCastException.class);
        FromDate.checkConversionException(TO_LIST, ClassCastException.class);
        FromDate.checkConversionException(TO_SEQUENCE, ClassCastException.class);
    }
    
    public void testTuscany_836() {
      if (System.getProperty("java.version").indexOf("1.4") == -1) {
    	// Work around a bug in SUN and IBM 1.4 JDKs
        assertEquals(DataObjectUtil.getBigDecimal(new Long(Long.MAX_VALUE)).longValue(), Long.MAX_VALUE);
      }
    }
}