KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bus > transports > jms > JMSInputStreamContextTest


1 package org.objectweb.celtix.bus.transports.jms;
2
3 import java.io.ByteArrayInputStream JavaDoc;
4 import java.io.InputStream JavaDoc;
5
6 import junit.framework.TestCase;
7
8 public class JMSInputStreamContextTest extends TestCase {
9     
10     static final String JavaDoc HELLO_WORLD_STRING = "Hello World";
11     static final String JavaDoc ANOTHER_STRING_STRING = "Another String";
12
13     public JMSInputStreamContextTest(String JavaDoc arg0) {
14         super(arg0);
15     }
16
17     public static void main(String JavaDoc[] args) {
18         junit.textui.TestRunner.run(JMSInputStreamContextTest.class);
19     }
20
21     public void testJMSInputStreamContext() throws Exception JavaDoc {
22         
23         JMSInputStreamContext inCtx =
24             new JMSInputStreamContext(
25                 new ByteArrayInputStream JavaDoc(HELLO_WORLD_STRING.getBytes())
26             );
27          
28         InputStream JavaDoc ins = inCtx.getInputStream();
29         byte [] retResult = new byte[HELLO_WORLD_STRING.length()];
30          
31         ins.read(retResult, 0 , HELLO_WORLD_STRING.length());
32          
33         assertTrue("Should get the same InputStream that was passed : Hello World ",
34                 HELLO_WORLD_STRING.equals(new String JavaDoc(retResult)));
35          
36         InputStream JavaDoc insNew = new ByteArrayInputStream JavaDoc(ANOTHER_STRING_STRING.getBytes());
37          
38         inCtx.setInputStream(insNew);
39          
40         ins = inCtx.getInputStream();
41          
42         retResult = new byte[ANOTHER_STRING_STRING.length()];
43         ins.read(retResult, 0, ANOTHER_STRING_STRING.length());
44          
45         assertTrue("Should get the same InputStream that was passed : Another String ",
46                 ANOTHER_STRING_STRING.equals(new String JavaDoc(retResult)));
47          
48         inCtx.setFault(true);
49          
50         assertFalse(inCtx.isFault());
51     }
52 }
53
Popular Tags