1   /*
2    * $Id: OutputPatternFromEndpointTestCase.java 10789 2008-02-12 20:04:43Z 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  
19  public class OutputPatternFromEndpointTestCase extends FunctionalTestCase
20  {
21  
22      protected String getConfigResources()
23      {
24          return "org/mule/test/integration/providers/file/mule-file-output-pattern-from-endpoint.xml";
25      }
26  
27      public void testBasic() throws Exception
28      {
29          String myFirstDirName = "FirstWrite";
30          String mySecondDirName = "SecondWrite";
31          String myFileName1 = "export.txt";
32          String myFileName2 = "export.txt.OK";
33  
34          // make sure there is no directory and file
35          File myDir = FileUtils.newFile(myFirstDirName);
36          if (myDir.isDirectory())
37          {
38              // Delete Any Existing Files
39              File[] files = myDir.listFiles();
40              for (int i = 0; i < files.length; i++)
41              {
42                  assertTrue(files[i].delete());
43              }
44              // This may fail if this directory contains other directories.
45              assertTrue(myDir.delete());
46          }
47  
48          File myDir2 = FileUtils.newFile(mySecondDirName);
49          if (myDir2.isDirectory())
50          {
51              // Delete Any Existing Files
52              File[] files = myDir2.listFiles();
53              for (int i = 0; i < files.length; i++)
54              {
55                  assertTrue(files[i].delete());
56              }
57              // This may fail if this directory contains other directories.
58              assertTrue(myDir2.delete());
59          }
60  
61          try
62          {
63              assertFalse(FileUtils.newFile(myDir, myFileName1).exists());
64              assertFalse(FileUtils.newFile(myDir2, myFileName2).exists());
65  
66              MuleClient client = new MuleClient();
67              client.send("vm://filesend", "Hello", null);
68  
69              // the output file should exist now
70              // check that the files with the correct output pattern were generated
71              assertTrue(FileUtils.newFile(myDir, myFileName1).exists());
72              assertTrue(FileUtils.newFile(myDir2, myFileName2).exists());
73          }
74          finally
75          {
76              assertTrue(FileUtils.newFile(myDir, myFileName1).delete());
77              assertTrue(FileUtils.newFile(myDir2, myFileName2).delete());
78              assertTrue(myDir.delete());
79              assertTrue(myDir2.delete());
80          }
81      }
82  }