KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > file > def > FileDefinitionDbConfigTest


1 package org.jbpm.file.def;
2
3 import java.io.ByteArrayInputStream JavaDoc;
4 import java.io.ByteArrayOutputStream JavaDoc;
5 import java.io.InputStream JavaDoc;
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     // this is the default configuration
15
// we set it here because it may have been overwritten in previous tests
16
FileDefinition.rootDir = null;
17   }
18   
19   private InputStream JavaDoc getTestInputStream(String JavaDoc text) {
20     return new ByteArrayInputStream JavaDoc(text.getBytes());
21   }
22   
23   public void testStoreInputStreamGetInputStream() throws Exception JavaDoc {
24     // store the value of hello world as an input stream
25
fileDefinition.addFile("a/b/c/hello.txt", getTestInputStream("hello world") );
26     // retrieve the input stream for the given file name
27
InputStream JavaDoc in = fileDefinition.getInputStream("a/b/c/hello.txt");
28     
29     // extract the stream
30
ByteArrayOutputStream JavaDoc out = new ByteArrayOutputStream JavaDoc();
31     FileDefinition.transfer(in, out);
32     String JavaDoc retrievedText = out.toString();
33
34     // check the result
35
assertEquals( "hello world", retrievedText );
36   }
37
38   public void testStoreInputStreamGetBytes() throws Exception JavaDoc {
39     // store the value of hello world as an input stream
40
fileDefinition.addFile("a/b/c/hello.txt", getTestInputStream("hello world") );
41     // retrieve the input stream for the given file name
42
byte[] retrievedBytes = fileDefinition.getBytes("a/b/c/hello.txt");
43
44     // check the result
45
assertEquals( "hello world", new String JavaDoc(retrievedBytes) );
46   }
47
48   public void testStoreBytesGetInputStream() throws Exception JavaDoc {
49     // store the value of 'hello world'
50
fileDefinition.addFile("a/b/c/hello.txt", "hello world".getBytes() );
51
52     // retrieve the input stream for the given file name
53
InputStream JavaDoc in = fileDefinition.getInputStream("a/b/c/hello.txt");
54     
55     // extract the stream
56
ByteArrayOutputStream JavaDoc out = new ByteArrayOutputStream JavaDoc();
57     FileDefinition.transfer(in, out);
58     String JavaDoc retrievedText = out.toString();
59
60     // check the result
61
assertEquals( "hello world", retrievedText );
62   }
63
64   public void testStoreBytesGetBytes() throws Exception JavaDoc {
65     // store the value of 'hello world'
66
fileDefinition.addFile("a/b/c/hello.txt", "hello world".getBytes() );
67     
68     // retrieve the input stream for the given file name
69
byte[] retrievedBytes = fileDefinition.getBytes("a/b/c/hello.txt");
70
71     // check the result
72
assertEquals( "hello world", new String JavaDoc(retrievedBytes) );
73   }
74 }
75
Popular Tags