View Javadoc

1   /*
2    * $Id: FileToTcpStreamingTestCase.java 20321 2010-11-24 15:21:24Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.test.integration.streaming;
12  
13  
14  import org.mule.tck.DynamicPortTestCase;
15  import org.mule.util.FileUtils;
16  
17  import java.io.File;
18  
19  public class FileToTcpStreamingTestCase extends DynamicPortTestCase
20  {
21      @Override
22      protected void doTearDown() throws Exception
23      {
24          FileUtils.deleteDirectory(FileUtils.newFile(muleContext.getConfiguration().getWorkingDirectory() + "/test-data"));
25      }
26  
27      @Override
28      protected String getConfigResources()
29      {
30          return "org/mule/test/integration/streaming/file-to-tcp-streaming.xml";
31      }
32  
33      @Override
34      protected int getNumPortsToFind()
35      {
36          return 1;
37      }
38  
39      public void testStreamingFromFileToTcp() throws Exception
40      {
41          String text = "\nblah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah " +
42                  "\nblah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah " +
43                  "\nblah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah " +
44                  "\nblah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n";
45  
46          String basepath = muleContext.getConfiguration().getWorkingDirectory() + "/test-data";
47          
48          FileUtils.stringToFile(basepath + "/in/foo.txt", text);
49  
50          Thread.sleep(4000);
51  
52          File file = FileUtils.newFile(basepath, "out/foo.txt.processed");
53          System.out.println("reading " + file.getAbsolutePath());
54          String result = FileUtils.readFileToString(file, "UTF8");
55          assertEquals(text, result);
56      }
57  }