01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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;
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: /**
30: * @version $Revision: 359213 $
31: */
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(
68: "org/apache/servicemix/components/file/binary-example.xml");
69: }
70: }
|