View Javadoc

1   /*
2    * $Id: FilterOnGlobalFileEndpointTestCase.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.transport.file.filters;
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.IOException;
19  
20  public class FilterOnGlobalFileEndpointTestCase extends FunctionalTestCase
21  {
22      private static final String TEXT_FILE = "sample.txt";
23      private static final String XML_FILE = "sample.xml";
24      
25      private File pollDirectory;
26  
27      @Override
28      protected void doSetUp() throws Exception
29      {
30          createPollDirectoryAndInputFiles();
31          super.doSetUp();
32      }
33      
34      @Override
35      protected void doTearDown() throws Exception
36      {
37          // discard the test directory structure
38          assertTrue(FileUtils.deleteTree(pollDirectory.getParentFile()));
39          
40          super.doTearDown();
41      }
42  
43      private void createPollDirectoryAndInputFiles() throws IOException
44      {
45          pollDirectory = createDirectory("target/FilterOnGlobalFileEndpointTestCase/testdir");
46          createDirectory("target/FilterOnGlobalFileEndpointTestCase/testdir-moveto");
47  
48          createFileInPollDirectory(TEXT_FILE);
49          createFileInPollDirectory(XML_FILE);
50      }
51      
52      private File createDirectory(String path)
53      {
54          File directory = new File(path);
55          if (directory.exists() == false)
56          {
57              if (directory.mkdirs() == false)
58              {
59                  fail("could not create poll directory");
60              }
61          }
62          
63          return directory;
64      }
65      
66      private void createFileInPollDirectory(String filename) throws IOException
67      {
68          File file  = FileUtils.newFile(pollDirectory, filename);
69          
70          String path = file.getCanonicalPath();
71          
72          File newFile = FileUtils.createFile(path);
73          newFile.deleteOnExit();
74      }
75  
76      @Override
77      protected String getConfigResources()
78      {
79          return "global-file-ep-with-filter.xml";
80      }
81  
82      public void testMoveFiles() throws Exception
83      {
84          File txtFile = new File(pollDirectory, TEXT_FILE);
85          File xmlFile = new File(pollDirectory, XML_FILE);
86          assertTrue(txtFile.exists());
87          assertTrue(xmlFile.exists());
88  
89          MuleClient client = new MuleClient(muleContext);
90          client.request("globalEP", 1000);
91          
92          assertTrue(txtFile.exists());
93          assertFalse(xmlFile.exists());
94      }
95  }