1 package org.apache.torque.generator.control;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertTrue;
24
25 import java.io.File;
26 import java.io.IOException;
27 import java.util.ArrayList;
28 import java.util.List;
29
30 import org.apache.commons.io.FileUtils;
31 import org.apache.torque.generator.BaseTest;
32 import org.apache.torque.generator.configuration.UnitDescriptor;
33 import org.apache.torque.generator.configuration.paths.CustomProjectPaths;
34 import org.apache.torque.generator.configuration.paths.DefaultTorqueGeneratorPaths;
35 import org.apache.torque.generator.configuration.paths.Maven2DirectoryProjectPaths;
36 import org.junit.Test;
37
38
39
40
41 public class OutputEncodingTest extends BaseTest
42 {
43 @Test
44 public void testOutputEncoding() throws Exception
45 {
46 File targetDir = new File("target/test/outputEncoding");
47 FileUtils.deleteDirectory(targetDir);
48 Controller controller = new Controller();
49 List<UnitDescriptor> unitDescriptors = new ArrayList<UnitDescriptor>();
50 CustomProjectPaths projectPaths = new CustomProjectPaths(
51 new Maven2DirectoryProjectPaths(
52 new File("src/test/outputEncoding")));
53 projectPaths.setOutputDirectory(null, targetDir);
54 unitDescriptors.add(new UnitDescriptor(
55 UnitDescriptor.Packaging.DIRECTORY,
56 projectPaths,
57 new DefaultTorqueGeneratorPaths()));
58 controller.run(unitDescriptors);
59
60 assertTrue(targetDir.exists());
61
62
63
64
65 assertTrue(new File(targetDir, "defaultEncoding.txt").exists());
66 checkFile(
67 new File(targetDir, "iso-8859-1.txt"),
68 "iso-8859-1");
69 checkFile(
70 new File(targetDir, "utf8.txt"),
71 "utf-8");
72 }
73
74 private void checkFile(File file, String encoding)
75 throws IOException
76 {
77 assertTrue(file.exists());
78 String content = FileUtils.readFileToString(file, encoding);
79 assertEquals("Test Outlet output; foo=öäü; bar=ÖÄÜ", content);
80 }
81 }