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 org.mule.transport.AbstractMuleMessageFactoryTestCase;
10  import org.mule.util.FileUtils;
11  
12  import java.io.File;
13  
14  import static org.junit.Assert.assertTrue;
15  
16  public abstract class AbstractFileMuleMessageFactoryTestCase extends AbstractMuleMessageFactoryTestCase
17  {
18      protected File tempFile;
19      private File tmpDirectory;
20  
21      @Override
22      protected void doSetUp() throws Exception
23      {
24          super.doSetUp();
25  
26          createWorkDirectory();
27          tempFile = File.createTempFile("simple", ".mule", tmpDirectory);
28      }
29  
30      private void createWorkDirectory()
31      {
32          // The working directory is deleted on tearDown (see AbstractMuleTestCase.disposeManager)
33          tmpDirectory = FileUtils.newFile(muleContext.getConfiguration().getWorkingDirectory(), "tmp");
34          if (!tmpDirectory.exists())
35          {
36              assertTrue(tmpDirectory.mkdirs());
37          }
38      }
39      
40      @Override
41      protected Object getValidTransportMessage()
42      {
43          return tempFile;
44      }
45  
46      @Override
47      protected Object getUnsupportedTransportMessage()
48      {
49          return "this is an invalid payload for " + getClass().getSimpleName();
50      }
51  }