1 package org.xmlhammer.cli;
2
3 import java.io.File;
4 import java.io.FileInputStream;
5
6 import junit.framework.Test;
7 import junit.framework.TestSuite;
8
9 public class TransformationTest extends CLITestCase {
10 protected TransformationTest(String test) {
11 super(test);
12 }
13
14 public void testSimpleSAXTransform() throws Exception {
15 assertOutput(
16 new File("src/test/resources/output/cli/golden-simple-sax-transform.out"),
17 run("src/test/resources/projects/transformer/simple-sax-transformer.xhp"));
18 }
19
20 public void testAssociatedSAXTransform() throws Exception {
21 assertOutput(
22 new File("src/test/resources/output/cli/golden-associated-sax-transform.out"),
23 run("src/test/resources/projects/transformer/associated-sax-transformer.xhp"));
24 }
25
26 public void testAssociatedInvalidSAXTransform() throws Exception {
27 assertOutput(
28 new File("src/test/resources/output/cli/golden-associated-invalid-sax-transform.out"),
29 run("src/test/resources/projects/transformer/associated-invalid-sax-transformer.xhp"));
30 }
31
32 public void testDefaultSAXTransform() throws Exception {
33 assertOutput(
34 new File("src/test/resources/output/cli/golden-default-sax-transform.out"),
35 run("src/test/resources/projects/transformer/default-sax-transformer.xhp"));
36 }
37
38 public void testMultipleSAXTransform() throws Exception {
39 assertOutput(
40 new File("src/test/resources/output/cli/golden-multiple-sax-transform.out"),
41 run("src/test/resources/projects/transformer/multiple-sax-transformer.xhp"));
42 }
43
44 public void testAssociatedDOMTransform() throws Exception {
45 assertOutput(
46 new File("src/test/resources/output/cli/golden-associated-dom-transform.out"),
47 run("src/test/resources/projects/transformer/associated-dom-transformer.xhp"));
48 }
49
50 public void testSimpleDOMTransform() throws Exception {
51 assertOutput(
52 new File("src/test/resources/output/cli/golden-associated-dom-transform.out"),
53 run("src/test/resources/projects/transformer/simple-dom-transformer.xhp"));
54 }
55
56 public void testDefaultDOMTransform() throws Exception {
57 assertOutput(
58 new File("src/test/resources/output/cli/golden-default-dom-transform.out"),
59 run("src/test/resources/projects/transformer/default-dom-transformer.xhp"));
60 }
61
62 public void testMultipleDOMTransform() throws Exception {
63 assertOutput(
64 new File("src/test/resources/output/cli/golden-multiple-dom-transform.out"),
65 run("src/test/resources/projects/transformer/multiple-dom-transformer.xhp"));
66 }
67
68 public void testMultipleInvalidDOMTransform() throws Exception {
69 assertOutput(
70 new File("src/test/resources/output/cli/golden-multiple-invalid-dom-transform.out"),
71 run("src/test/resources/projects/transformer/multiple-invalid-dom-transformer.xhp"));
72 }
73
74 public void checkOutput() throws Exception {
75 File golden = new File("src/test/resources/output/golden-example.out");
76 File out = new File("src/test/resources/input/example.out");
77
78 assertTrue(out.exists());
79
80 assertTrue(compareFilesIgnoreWhitespace(out, golden));
81
82 if (out.exists()) {
83 out.delete();
84 }
85 }
86
87 public void checkDefaultOutput() throws Exception {
88 File golden = new File("src/test/resources/output/golden-default-example.out");
89 File out = new File("src/test/resources/input/example.out");
90
91 assertTrue(out.exists());
92
93 assertTrue(compareFilesIgnoreWhitespace(out, golden));
94
95 if (out.exists()) {
96 out.delete();
97 }
98 }
99
100 public void checkMultipleOutput() throws Exception {
101 File golden = new File("src/test/resources/output/golden-multiple-example.out");
102 File out = new File("src/test/resources/input/example.out");
103
104 assertTrue(out.exists());
105
106 assertTrue(compareFilesIgnoreWhitespace(out, golden));
107
108 if (out.exists()) {
109 out.delete();
110 }
111 }
112
113
114
115
116
117
118
119
120
121
122
123
124
125 private boolean compareFilesIgnoreWhitespace(File file1, File file2) throws Exception {
126 FileInputStream stream1 = new FileInputStream(file1);
127 FileInputStream stream2 = new FileInputStream(file2);
128
129 int ch = getNextNonWhitespaceCharacter(stream1);
130 while (ch != -1 && ch == getNextNonWhitespaceCharacter(stream2)) {
131 ch = getNextNonWhitespaceCharacter(stream1);
132 }
133
134 return -1 == ch;
135 }
136
137 private int getNextNonWhitespaceCharacter(FileInputStream stream) throws Exception {
138
139 int ch = stream.read();
140 while (ch != -1 && Character.isWhitespace(ch)) {
141 ch = stream.read();
142 }
143
144 return ch;
145 }
146
147 public static Test suite() {
148 TestSuite suite = new TestSuite("Transformation Command Line Test");
149
150 suite.addTest(new TransformationTest("testSimpleSAXTransform"));
151 suite.addTest(new TransformationTest("checkOutput"));
152 suite.addTest(new TransformationTest("testAssociatedSAXTransform"));
153 suite.addTest(new TransformationTest("checkOutput"));
154 suite.addTest(new TransformationTest("testAssociatedInvalidSAXTransform"));
155 suite.addTest(new TransformationTest("testDefaultSAXTransform"));
156 suite.addTest(new TransformationTest("checkDefaultOutput"));
157 suite.addTest(new TransformationTest("testMultipleSAXTransform"));
158 suite.addTest(new TransformationTest("checkMultipleOutput"));
159 suite.addTest(new TransformationTest("testSimpleDOMTransform"));
160 suite.addTest(new TransformationTest("checkOutput"));
161 suite.addTest(new TransformationTest("testAssociatedDOMTransform"));
162 suite.addTest(new TransformationTest("checkOutput"));
163 suite.addTest(new TransformationTest("testDefaultDOMTransform"));
164 suite.addTest(new TransformationTest("checkDefaultOutput"));
165 suite.addTest(new TransformationTest("testMultipleDOMTransform"));
166 suite.addTest(new TransformationTest("checkMultipleOutput"));
167 suite.addTest(new TransformationTest("testMultipleInvalidDOMTransform"));
168
169 return suite;
170 }
171 }