View Javadoc

1   /*
2    * $Id: FileToTcpStreamingTestCase.java 22450 2011-07-19 08:20:41Z dirk.olmes $
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  import org.mule.tck.AbstractServiceAndFlowTestCase;
14  import org.mule.tck.junit4.rule.DynamicPort;
15  import org.mule.util.FileUtils;
16  
17  import java.io.File;
18  import java.util.Arrays;
19  import java.util.Collection;
20  
21  import org.junit.Rule;
22  import org.junit.Test;
23  import org.junit.runners.Parameterized.Parameters;
24  
25  import static org.junit.Assert.assertEquals;
26  
27  public class FileToTcpStreamingTestCase extends AbstractServiceAndFlowTestCase
28  {
29      @Rule
30      public DynamicPort port1 = new DynamicPort("port1");
31  
32      @Parameters
33      public static Collection<Object[]> parameters()
34      {
35          return Arrays.asList(new Object[][]{
36              {ConfigVariant.SERVICE, "org/mule/test/integration/streaming/file-to-tcp-streaming-service.xml"},
37              {ConfigVariant.FLOW, "org/mule/test/integration/streaming/file-to-tcp-streaming-flow.xml"}
38          });
39      }
40  
41      public FileToTcpStreamingTestCase(ConfigVariant variant, String configResources)
42      {
43          super(variant, configResources);
44      }
45  
46      @Override
47      protected void doTearDown() throws Exception
48      {
49          FileUtils.deleteDirectory(FileUtils.newFile(muleContext.getConfiguration().getWorkingDirectory()
50                                                      + "/test-data"));
51      }
52  
53      @Test
54      public void testStreamingFromFileToTcp() throws Exception
55      {
56          String text = "\nblah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah "
57                        + "\nblah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah "
58                        + "\nblah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah "
59                        + "\nblah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n";
60  
61          String basepath = muleContext.getConfiguration().getWorkingDirectory() + "/test-data";
62  
63          FileUtils.stringToFile(basepath + "/in/foo.txt", text);
64  
65          Thread.sleep(4000);
66  
67          File file = FileUtils.newFile(basepath, "out/foo.txt.processed");
68          System.out.println("reading " + file.getAbsolutePath());
69          String result = FileUtils.readFileToString(file, "UTF8");
70          assertEquals(text, result);
71      }
72  }