1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.file;
12
13 import org.mule.transport.AbstractMuleMessageFactory;
14
15 import java.io.BufferedReader;
16 import java.io.File;
17 import java.io.FileReader;
18 import java.util.HashMap;
19 import java.util.Map;
20
21 public abstract class AbstractFileMoveDeleteTestCase extends AbstractFileFunctionalTestCase
22 {
23
24 protected File configureConnector(File inFile, boolean stream, boolean move, boolean delete,
25 Class<? extends AbstractMuleMessageFactory> messageFactoryClass) throws Exception
26 {
27 FileConnector fc = new FileConnector(muleContext);
28
29
30
31 fc.setPollingFrequency(3000000);
32
33 if (messageFactoryClass != null)
34 {
35 Map<String, String> overrides = new HashMap<String, String>();
36 overrides.put("message.factory", messageFactoryClass.getName());
37 fc.setServiceOverrides(overrides);
38 }
39
40 fc.setName("moveDeleteConnector");
41 File moveToDir = new File(inFile.getParent() + "/moveto/");
42 moveToDir.mkdir();
43 muleContext.getRegistry().registerConnector(fc);
44 if (move)
45 {
46 fc.setMoveToDirectory(moveToDir.getPath());
47 }
48 fc.setAutoDelete(delete);
49 fc.setStreaming(stream);
50
51 return moveToDir;
52 }
53
54 protected void assertFiles(File inFile, File moveToDir, boolean move, boolean delete) throws Exception
55 {
56 waitForFileSystem();
57
58 boolean inFileShouldExst = !delete && !move;
59
60 assertTrue(inFile.exists() == inFileShouldExst);
61
62 if (inFileShouldExst)
63 {
64 assertEquals(TEST_MESSAGE, new BufferedReader(new FileReader(inFile)).readLine());
65 }
66
67 File movedFile = new File(moveToDir.getPath() + "/" + inFile.getName());
68 assertTrue(movedFile.exists() == move);
69
70 if (move)
71 {
72 assertEquals(TEST_MESSAGE, new BufferedReader(new FileReader(movedFile)).readLine());
73 }
74 }
75
76 protected void assertFilesUntouched(File inFile)
77 {
78 assertTrue(inFile.exists());
79
80 File movedFile = new File(inFile.getParent() + "/moveto/" + inFile.getName());
81 assertFalse(movedFile.exists());
82 }
83
84 }