1   /*
2    * $Id: FileAppendConnectorTestCase.java 12332 2008-07-14 20:30:57Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.transport.file;
12  
13  import org.mule.module.client.MuleClient;
14  import org.mule.tck.FunctionalTestCase;
15  import org.mule.util.FileUtils;
16  
17  import java.io.File;
18  import java.io.FileInputStream;
19  
20  import org.apache.commons.io.IOUtils;
21  
22  public class FileAppendConnectorTestCase extends FunctionalTestCase
23  {
24  
25      public void testBasic() throws Exception
26      {
27          String myDirName = "myout";
28          String myFileName = "out.txt";
29          FileInputStream myFileStream = null;
30  
31          // make sure there is no directory and file
32          File myDir = FileUtils.newFile(myDirName);
33          if (myDir.isDirectory())
34          {
35              // Delete Any Existing Files
36              File[] files = myDir.listFiles();
37              for (int i = 0; i < files.length; i++)
38              {
39                  assertTrue(files[i].delete());
40              }
41              // This may fail if this directory contains other directories.
42              assertTrue(myDir.delete());
43          }
44  
45          try
46          {
47              assertFalse(FileUtils.newFile(myDir, myFileName).exists());
48  
49              MuleClient client = new MuleClient();
50              client.send("vm://fileappend", "Hello1", null);
51              client.send("vm://fileappend", "Hello2", null);
52  
53              // the output file should exist now
54              myFileStream = new FileInputStream(FileUtils.newFile(myDir, myFileName));
55              assertEquals("Hello1Hello2", IOUtils.toString(myFileStream));
56          }
57          finally
58          {
59              IOUtils.closeQuietly(myFileStream);
60              assertTrue(FileUtils.newFile(myDir, myFileName).delete());
61              assertTrue(myDir.delete());
62          }
63      }
64  
65      protected String getConfigResources()
66      {
67          return "org/mule/test/integration/providers/file/mule-fileappend-connector-config.xml";
68      }
69  }