View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.file;
8   
9   import static org.junit.Assert.assertEquals;
10  import static org.junit.Assert.assertTrue;
11  import org.mule.api.MuleMessage;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  
14  import java.io.File;
15  import java.io.FileOutputStream;
16  import java.io.IOException;
17  import java.util.Map;
18  
19  import org.junit.Before;
20  import org.junit.Test;
21  
22  public class WorkDirectoryPropertiesTestCase extends FunctionalTestCase
23  {
24  
25      private File dataFolder;
26  
27      public WorkDirectoryPropertiesTestCase()
28      {
29          setStartContext(false);
30      }
31  
32      @Override
33      protected String getConfigResources()
34      {
35          return "work-directory-properties-config.xml";
36      }
37  
38      @Before
39      public void createDataFolder() throws Exception
40      {
41          dataFolder = new File(muleContext.getConfiguration().getWorkingDirectory(), "data");
42  
43          if (!dataFolder.exists())
44          {
45              assertTrue("Unable to create test folder", dataFolder.mkdirs());
46          }
47      }
48  
49      @Test
50      public void testName() throws Exception
51      {
52          File testfile = createTestFile(dataFolder, "sample.txt");
53  
54          muleContext.start();
55  
56          MuleMessage response = muleContext.getClient().request("vm://testOut", RECEIVE_TIMEOUT * 6);
57  
58          assertTrue(response.getPayload() instanceof Map);
59          Map<String, String> payload = (Map<String, String>) response.getPayload();
60          assertEquals(dataFolder.getCanonicalPath(), payload.get(FileConnector.PROPERTY_SOURCE_DIRECTORY));
61          assertEquals(testfile.getName(), payload.get(FileConnector.PROPERTY_SOURCE_FILENAME));
62      }
63  
64      private File createTestFile(File parentFolder, String fileName) throws IOException
65      {
66          File result = new File(parentFolder, fileName);
67  
68          FileOutputStream out = new FileOutputStream(result);
69          out.write(TEST_MESSAGE.getBytes());
70          out.close();
71  
72          return result;
73      }
74  }