1   /*
2    * BlobToInputStreamConverterTest.java
3    * Created on 4 Август 2006 г., 16:21
4    */
5   
6   package org.weda.converter;
7   
8   import java.io.ByteArrayInputStream;
9   import java.io.InputStream;
10  import java.sql.Blob;
11  import java.util.Arrays;
12  import junit.framework.TestCase;
13  import org.apache.commons.io.IOUtils;
14  import org.hibernate.Hibernate;
15  
16  /**
17   *
18   * @author Mikhail Titov
19   */
20  public class BlobToInputStreamConverterTest extends TestCase {
21      
22      public BlobToInputStreamConverterTest(String name) {
23          super(name);
24      }
25      
26      public void test() throws Exception{
27          //ValueTypeConverter converter = new InputStreamToBlobConverter();
28          //checkConvert(converter);
29      }
30      
31      public void checkConvert(ValueTypeConverter converter) throws Exception{
32          byte[] arr = new byte[]{1,2,3,4,5,6};
33          ByteArrayInputStream is = new ByteArrayInputStream(arr);
34          //Blob blob = (Blob)converter.convert(Blob.class, is, null);
35          Blob blob = Hibernate.createBlob(arr);
36          InputStream isRes = 
37                  (InputStream)converter.convert(InputStream.class, blob, null);
38          byte[] res = IOUtils.toByteArray(isRes);
39          assertTrue(Arrays.equals(arr, res));        
40      }                
41     
42      
43  }