View Javadoc

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