1 package org.objectweb.celtix.bus.transports.jms; 2 3 import java.io.ByteArrayInputStream ; 4 import java.io.InputStream ; 5 6 import junit.framework.TestCase; 7 8 public class JMSInputStreamContextTest extends TestCase { 9 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 = 24 new JMSInputStreamContext( 25 new ByteArrayInputStream (HELLO_WORLD_STRING.getBytes()) 26 ); 27 28 InputStream 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 (retResult))); 35 36 InputStream insNew = new ByteArrayInputStream (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 (retResult))); 47 48 inCtx.setFault(true); 49 50 assertFalse(inCtx.isFault()); 51 } 52 } 53 | Popular Tags |