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 return configureConnector(inFile, stream, move, delete, false, messageFactoryClass);
28 }
29
30 protected File configureConnector(File inFile, boolean stream, boolean move, boolean delete,
31 boolean useWorkDir, Class<? extends AbstractMuleMessageFactory> messageFactoryClass) throws Exception
32 {
33 FileConnector fc = new FileConnector(muleContext);
34
35
36
37 fc.setPollingFrequency(3000000);
38
39 if (messageFactoryClass != null)
40 {
41 Map<String, String> overrides = new HashMap<String, String>();
42 overrides.put("message.factory", messageFactoryClass.getName());
43 fc.setServiceOverrides(overrides);
44 }
45
46 fc.setName("moveDeleteConnector");
47 File moveToDir = new File(inFile.getParent() + "/moveto/");
48 moveToDir.mkdir();
49 File workDir = new File(inFile.getParent() + "/work/");
50 workDir.mkdir();
51 muleContext.getRegistry().registerConnector(fc);
52 if (move)
53 {
54 fc.setMoveToDirectory(moveToDir.getPath());
55 }
56 if (useWorkDir)
57 {
58 fc.setWorkDirectory(workDir.getPath());
59 }
60 fc.setAutoDelete(delete);
61 fc.setStreaming(stream);
62
63 return moveToDir;
64 }
65
66 protected void assertFiles(File inFile, File moveToDir, boolean move, boolean delete) throws Exception
67 {
68 waitForFileSystem();
69
70 boolean inFileShouldExst = !delete && !move;
71
72 assertTrue(inFile.exists() == inFileShouldExst);
73
74 if (inFileShouldExst)
75 {
76 assertEquals(TEST_MESSAGE, new BufferedReader(new FileReader(inFile)).readLine());
77 }
78
79 File movedFile = new File(moveToDir.getPath() + "/" + inFile.getName());
80 assertTrue(movedFile.exists() == move);
81
82 if (move)
83 {
84 assertEquals(TEST_MESSAGE, new BufferedReader(new FileReader(movedFile)).readLine());
85 }
86 }
87
88 protected void assertFilesUntouched(File inFile)
89 {
90 assertTrue(inFile.exists());
91
92 File movedFile = new File(inFile.getParent() + "/moveto/" + inFile.getName());
93 assertFalse(movedFile.exists());
94 }
95
96 }