1
2
3
4
5
6
7 package org.mule.transport.email.issues;
8
9 import org.mule.api.transport.Connector;
10 import org.mule.transport.email.AbstractRetrieveMailConnector;
11 import org.mule.transport.email.connectors.ImapConnectorTestCase;
12 import org.mule.util.FileUtils;
13
14 import java.io.File;
15
16 import static org.junit.Assert.assertFalse;
17 import static org.junit.Assert.assertTrue;
18
19 public abstract class AbstractBaseBackupMule2050TestCase extends ImapConnectorTestCase
20 {
21
22 private boolean backupEnabled;
23
24 public AbstractBaseBackupMule2050TestCase(boolean backupEnabled)
25 {
26 this.backupEnabled = backupEnabled;
27 }
28
29 @Override
30 public Connector createConnector() throws Exception
31 {
32 Connector connector = super.createConnector();
33 ((AbstractRetrieveMailConnector) connector).setBackupEnabled(backupEnabled);
34 return connector;
35 }
36
37 @Override
38 public void testReceiver() throws Exception
39 {
40 File dir = FileUtils.newFile(muleContext.getConfiguration().getWorkingDirectory() + "/mail/INBOX");
41 FileUtils.deleteTree(new File(muleContext.getConfiguration().getWorkingDirectory() + "/mail"));
42 assertFalse("Mail backup file already exists: " + dir.getAbsolutePath(), dir.exists());
43 debug(dir);
44 super.testReceiver();
45 debug(dir);
46 assertTrue(dir.getAbsolutePath(), dir.exists() == backupEnabled);
47 }
48
49 protected void debug(File dir)
50 {
51 logger.debug(dir.getAbsolutePath() + " exists? " + dir.exists());
52 }
53
54 }