1 17 package org.apache.servicemix.components.file; 18 19 import java.io.ByteArrayOutputStream ; 20 import java.io.File ; 21 import java.io.FileInputStream ; 22 import java.io.FileWriter ; 23 24 import org.apache.servicemix.jbi.util.FileUtil; 25 import org.apache.servicemix.tck.TestSupport; 26 import org.springframework.context.support.AbstractXmlApplicationContext; 27 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext; 28 29 32 public class BinaryFileTest extends TestSupport { 33 34 protected void setUp() throws Exception { 35 FileUtil.deleteFile(new File ("target/test-data/in")); 36 FileUtil.deleteFile(new File ("target/test-data/out")); 37 super.setUp(); 38 } 39 40 public void testSendBinary() throws Exception { 41 String contents = "Binary content"; 42 FileWriter fw = new FileWriter("target/test-data/in/file.txt"); 43 fw.write(contents); 44 fw.close(); 45 46 File output = null; 47 long start = System.currentTimeMillis(); 48 while (System.currentTimeMillis() - start < 5000) { 49 File outDir = new File ("target/test-data/out"); 50 File [] files = outDir.listFiles(); 51 if (files != null && files.length > 0) { 52 output = files[0]; 53 break; 54 } 55 Thread.sleep(50); 56 } 57 if (output == null) { 58 fail("No output file found"); 59 } 60 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 61 FileUtil.copyInputStream(new FileInputStream (output), baos); 62 String outContents = baos.toString(); 63 assertEquals(contents, outContents); 64 } 65 66 protected AbstractXmlApplicationContext createBeanFactory() { 67 return new ClassPathXmlApplicationContext("org/apache/servicemix/components/file/binary-example.xml"); 68 } 69 } 70 | Popular Tags |