1   
2   package org.weda.converter;
3   
4   import org.weda.test.WedaTestCase;
5   
6   /**
7    *
8    * @author tim
9    */
10  public class ConverterRegistryTest extends WedaTestCase {
11      ValueTypeConverter conv;
12      public ConverterRegistryTest(String name) throws Exception {
13          super(name);
14      }
15      
16      public void setUp(){
17          conv = (ValueTypeConverter)registry.getService(ValueTypeConverter.class);        
18      }
19      
20      public void test_registry() throws Exception {
21          assertNotNull(conv);
22      }    
23      
24      public void test_object_to_string_converter() throws Exception {
25          ObjectToStringConverterTest test = 
26                  new ObjectToStringConverterTest("test");
27          test.check(conv);
28      }
29      
30      public void test_number_converter() throws Exception{
31          NumberConverterTest numberTest = new NumberConverterTest("number-test");
32          numberTest.checkConvertToString(conv);
33          numberTest.checkConvertToStringWithoutPattern(conv);
34          numberTest.checkConvertToStringWithPattern(conv);
35          //
36          assertEquals((float)1.1, conv.convert(Float.TYPE, "1.1", null));
37          assertEquals(1.1, conv.convert(Double.TYPE, "1.1", null));
38          assertEquals((short)1, conv.convert(Short.TYPE, "1", null));
39          assertEquals(1, conv.convert(Integer.TYPE, "1", null));
40          assertEquals((long)1, conv.convert(Long.TYPE, "1", null));
41          
42      }
43      
44      public void test_date_converter() throws Exception {
45          DateConverterTest dateTest = new DateConverterTest("date-test");
46          dateTest.checkConvertToString(conv);
47          dateTest.checkConvertToDate(conv);
48      }
49      
50      public void test_inputStreamToByte_converter() throws Exception {
51          InputStreamToByteConverterTest test = 
52                  new InputStreamToByteConverterTest("test");
53          test.checkConvert(conv);
54      }
55      
56      public void test_byteToInputStream_converter() throws Exception {
57          ByteToInputStreamConverterTest test = 
58                  new ByteToInputStreamConverterTest("test");
59          test.checkConverter(conv);
60      }
61      
62      public void test_inputStreamToBlob_converter() throws Exception {
63          InputStreamToBlobConverterTest test = 
64                  new InputStreamToBlobConverterTest("test");
65          test.checkConvert(conv);
66      }
67      
68      public void test_blobToInputStream_converter() throws Exception {
69          BlobToInputStreamConverterTest test = 
70                  new BlobToInputStreamConverterTest("test");
71          test.checkConvert(conv);
72      }
73      
74      public void test_stringToBoolean_converter() throws Exception {
75          StringToBooleanConverterTest test = 
76                  new StringToBooleanConverterTest("test");
77          test.checkConverter(conv);
78      }
79      
80      public void test() throws Exception {
81          byte[] arr = new byte[3];
82          Class arrClass = Class.forName("[B");
83          //Class doubleClass = Class.forName("D");
84          System.out.println("TYPE: "+arrClass.getSimpleName());
85          System.out.println("TYPE: "+arrClass.getName());
86          //System.out.println("TYPE: "+Double.TYPE.getName());
87          //System.out.println("TYPE: "+doubleClass.getName());
88      }
89  }