01: package org.objectweb.celtix.bus.transports.jms;
02:
03: import java.io.ByteArrayInputStream;
04: import java.io.InputStream;
05:
06: import junit.framework.TestCase;
07:
08: public class JMSInputStreamContextTest extends TestCase {
09:
10: static final String HELLO_WORLD_STRING = "Hello World";
11: static final String ANOTHER_STRING_STRING = "Another String";
12:
13: public JMSInputStreamContextTest(String arg0) {
14: super (arg0);
15: }
16:
17: public static void main(String[] args) {
18: junit.textui.TestRunner.run(JMSInputStreamContextTest.class);
19: }
20:
21: public void testJMSInputStreamContext() throws Exception {
22:
23: JMSInputStreamContext inCtx = new JMSInputStreamContext(
24: new ByteArrayInputStream(HELLO_WORLD_STRING.getBytes()));
25:
26: InputStream ins = inCtx.getInputStream();
27: byte[] retResult = new byte[HELLO_WORLD_STRING.length()];
28:
29: ins.read(retResult, 0, HELLO_WORLD_STRING.length());
30:
31: assertTrue(
32: "Should get the same InputStream that was passed : Hello World ",
33: HELLO_WORLD_STRING.equals(new String(retResult)));
34:
35: InputStream insNew = new ByteArrayInputStream(
36: 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(
46: "Should get the same InputStream that was passed : Another String ",
47: ANOTHER_STRING_STRING.equals(new String(retResult)));
48:
49: inCtx.setFault(true);
50:
51: assertFalse(inCtx.isFault());
52: }
53: }
|