1 36 package org.columba.ristretto.message.io; 37 38 import java.io.ByteArrayInputStream ; 39 import java.io.IOException ; 40 import java.io.InputStream ; 41 import java.util.Random ; 42 43 import junit.framework.TestCase; 44 45 import org.columba.ristretto.io.ByteBufferSource; 46 import org.columba.ristretto.io.FileSource; 47 import org.columba.ristretto.io.Source; 48 import org.columba.ristretto.io.TempSourceFactory; 49 50 public class TempSourceFactoryTest extends TestCase { 51 52 private StringBuffer bufferSmall; 53 private StringBuffer bufferBig; 54 55 private static final int SMALL = 1000; 56 private static final int BIG = 100000; 57 58 61 protected void setUp() throws Exception { 62 Random random = new Random (); 63 bufferSmall = new StringBuffer (SMALL); 64 for( long i=0; i<SMALL; i++ ) { 65 bufferSmall.append( (char) ((random.nextFloat() * 48.) + 'A')); 66 } 67 68 69 bufferBig = new StringBuffer (BIG); 70 for( long i=0; i<BIG; i++ ) { 71 bufferBig.append( (char) ((random.nextFloat() * 48.) + 'A')); 72 } 73 } 74 75 public void testSmallInput() throws IOException { 76 InputStream in = new ByteArrayInputStream ( bufferSmall.toString().getBytes("ISO-8859-1") ); 77 Source tempSource = TempSourceFactory.createTempSource(in, SMALL); 78 79 assertTrue( tempSource instanceof ByteBufferSource ); 80 assertEquals( bufferSmall.toString(), tempSource.toString() ); 81 } 82 83 public void testSmallInputUnknownSize() throws IOException { 84 InputStream in = new ByteArrayInputStream ( bufferSmall.toString().getBytes("ISO-8859-1") ); 85 Source tempSource = TempSourceFactory.createTempSource(in); 86 87 assertTrue( tempSource instanceof FileSource ); 88 assertEquals( bufferSmall.toString(), tempSource.toString() ); 89 } 90 91 public void testBigInput() throws IOException { 92 InputStream in = new ByteArrayInputStream ( bufferBig.toString().getBytes("ISO-8859-1") ); 93 Source tempSource = TempSourceFactory.createTempSource(in, BIG); 94 95 assertTrue( tempSource instanceof FileSource ); 96 assertEquals( bufferBig.toString(), tempSource.toString() ); 97 } 98 99 public void testBigInputUnknownSize() throws IOException { 100 InputStream in = new ByteArrayInputStream ( bufferBig.toString().getBytes("ISO-8859-1") ); 101 Source tempSource = TempSourceFactory.createTempSource(in); 102 103 assertTrue( tempSource instanceof FileSource ); 104 assertEquals( bufferBig.toString(), tempSource.toString() ); 105 } 106 107 } 108 | Popular Tags |