View Javadoc

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