1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.file.transformers;
12
13 import org.mule.api.transformer.TransformerException;
14 import org.mule.api.transformer.Transformer;
15 import org.mule.transformer.AbstractTransformerTestCase;
16 import org.mule.transport.file.transformers.FileToString;
17 import org.mule.util.FileUtils;
18 import org.mule.util.SystemUtils;
19
20 import java.io.File;
21 import java.io.FileWriter;
22
23
24
25
26 public class FileToStringTestCase extends AbstractTransformerTestCase
27 {
28 FileToString _fts;
29 File _testData = null;
30 final String _resultData = "The dog is on the table, where's the dog?";
31
32
33
34
35
36
37 protected void doSetUp() throws Exception
38 {
39 super.doSetUp();
40 _testData = FileUtils.newFile(SystemUtils.JAVA_IO_TMPDIR, "FileToStringTestData");
41 FileWriter fw = new FileWriter(_testData);
42 fw.write(_resultData);
43 fw.close();
44 }
45
46
47
48
49
50
51 protected void doTearDown() throws Exception
52 {
53 assertTrue(_testData.delete());
54 super.doTearDown();
55 }
56
57
58
59
60
61
62 public Object getResultData()
63 {
64 return _resultData;
65 }
66
67
68
69
70
71
72 public Transformer getRoundTripTransformer() throws Exception
73 {
74 return null;
75 }
76
77
78
79
80
81
82 public Object getTestData()
83 {
84 return _testData;
85 }
86
87
88
89
90
91
92 public Transformer getTransformer() throws Exception
93 {
94 return new FileToString();
95 }
96
97
98
99
100 public void testTransformExcEnc() throws Exception
101 {
102 try
103 {
104 FileToString fts = (FileToString)getTransformer();
105 fts.doTransform(getTestData(), "NO-SUCH_ENCODING");
106 fail("Should fail when the specified encoding is not supported");
107 }
108 catch (TransformerException tfe)
109 {
110
111 }
112 }
113
114 }