1   /*
2    * $Id: AbstractBaseBackupMule2050TestCase.java 11058 2008-02-27 03:02:33Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.email.issues;
12  
13  import org.mule.api.transport.Connector;
14  import org.mule.transport.email.AbstractRetrieveMailConnector;
15  import org.mule.transport.email.connectors.ImapConnectorTestCase;
16  import org.mule.util.FileUtils;
17  
18  import java.io.File;
19  
20  public abstract class AbstractBaseBackupMule2050TestCase extends ImapConnectorTestCase
21  {
22  
23      private boolean backupEnabled;
24  
25      public AbstractBaseBackupMule2050TestCase(int port, boolean backupEnabled)
26      {
27          super(port);
28          this.backupEnabled = backupEnabled;
29      }
30  
31      // @Override
32      public Connector createConnector() throws Exception
33      {
34          Connector connector = super.createConnector();
35          ((AbstractRetrieveMailConnector) connector).setBackupEnabled(backupEnabled);
36          return connector;
37      }
38  
39      public void testReceiver() throws Exception
40      {
41          File dir = FileUtils.newFile(muleContext.getConfiguration().getWorkingDirectory() + "/mail/INBOX");
42          FileUtils.deleteTree(new File(muleContext.getConfiguration().getWorkingDirectory() + "/mail"));
43          assertFalse("Mail backup file already exists: " + dir.getAbsolutePath(), dir.exists());
44          debug(dir);
45          super.testReceiver();
46          debug(dir);
47          assertTrue(dir.getAbsolutePath(), dir.exists() == backupEnabled);
48      }
49  
50      protected void debug(File dir)
51      {
52          logger.debug(dir.getAbsolutePath() + " exists? " + dir.exists());
53      }
54  
55  }