1 package org.jbpm.file.def; 2 3 import java.io.ByteArrayInputStream ; 4 import java.io.ByteArrayOutputStream ; 5 import java.io.InputStream ; 6 7 import junit.framework.TestCase; 8 9 public class FileDefinitionDbConfigTest extends TestCase { 10 11 private FileDefinition fileDefinition = new FileDefinition(); 12 13 public void setUp() { 14 FileDefinition.rootDir = null; 17 } 18 19 private InputStream getTestInputStream(String text) { 20 return new ByteArrayInputStream (text.getBytes()); 21 } 22 23 public void testStoreInputStreamGetInputStream() throws Exception { 24 fileDefinition.addFile("a/b/c/hello.txt", getTestInputStream("hello world") ); 26 InputStream in = fileDefinition.getInputStream("a/b/c/hello.txt"); 28 29 ByteArrayOutputStream out = new ByteArrayOutputStream (); 31 FileDefinition.transfer(in, out); 32 String retrievedText = out.toString(); 33 34 assertEquals( "hello world", retrievedText ); 36 } 37 38 public void testStoreInputStreamGetBytes() throws Exception { 39 fileDefinition.addFile("a/b/c/hello.txt", getTestInputStream("hello world") ); 41 byte[] retrievedBytes = fileDefinition.getBytes("a/b/c/hello.txt"); 43 44 assertEquals( "hello world", new String (retrievedBytes) ); 46 } 47 48 public void testStoreBytesGetInputStream() throws Exception { 49 fileDefinition.addFile("a/b/c/hello.txt", "hello world".getBytes() ); 51 52 InputStream in = fileDefinition.getInputStream("a/b/c/hello.txt"); 54 55 ByteArrayOutputStream out = new ByteArrayOutputStream (); 57 FileDefinition.transfer(in, out); 58 String retrievedText = out.toString(); 59 60 assertEquals( "hello world", retrievedText ); 62 } 63 64 public void testStoreBytesGetBytes() throws Exception { 65 fileDefinition.addFile("a/b/c/hello.txt", "hello world".getBytes() ); 67 68 byte[] retrievedBytes = fileDefinition.getBytes("a/b/c/hello.txt"); 70 71 assertEquals( "hello world", new String (retrievedBytes) ); 73 } 74 } 75 | Popular Tags |