KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > file > BinaryFileTest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.components.file;
18
19 import java.io.ByteArrayOutputStream JavaDoc;
20 import java.io.File JavaDoc;
21 import java.io.FileInputStream JavaDoc;
22 import java.io.FileWriter JavaDoc;
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 /**
30  * @version $Revision: 359213 $
31  */

32 public class BinaryFileTest extends TestSupport {
33
34     protected void setUp() throws Exception JavaDoc {
35         FileUtil.deleteFile(new File JavaDoc("target/test-data/in"));
36         FileUtil.deleteFile(new File JavaDoc("target/test-data/out"));
37         super.setUp();
38     }
39     
40     public void testSendBinary() throws Exception JavaDoc {
41         String JavaDoc contents = "Binary content";
42         FileWriter fw = new FileWriter("target/test-data/in/file.txt");
43         fw.write(contents);
44         fw.close();
45         
46         File JavaDoc output = null;
47         long start = System.currentTimeMillis();
48         while (System.currentTimeMillis() - start < 5000) {
49             File JavaDoc outDir = new File JavaDoc("target/test-data/out");
50             File JavaDoc[] 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 JavaDoc baos = new ByteArrayOutputStream JavaDoc();
61         FileUtil.copyInputStream(new FileInputStream JavaDoc(output), baos);
62         String JavaDoc 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