View Javadoc

1   package org.xmlhammer.gui.acceptance;
2   
3   import java.io.File;
4   import java.io.FileInputStream;
5   
6   import javax.swing.tree.MutableTreeNode;
7   
8   import junit.framework.Test;
9   import junit.framework.TestSuite;
10  
11  import org.xmlhammer.gui.output.ResultTreeModel;
12  
13  public class TransformationTest extends ProjectTestCase {
14      private TransformationTest(String test) {
15          super(test);
16      }
17  
18      public void openSimpleSAXProject() throws Exception {
19          openProject(new File("src/test/resources/projects/transformer/simple-sax-transformer.xhp"));
20      }
21      
22      public void openAssociatedSAXProject() throws Exception {
23          openProject(new File("src/test/resources/projects/transformer/associated-sax-transformer.xhp"));
24      }
25  
26      public void openAssociatedInvalidSAXProject() throws Exception {
27          openProject(new File("src/test/resources/projects/transformer/associated-invalid-sax-transformer.xhp"));
28      }
29  
30      public void openAssociatedDOMProject() throws Exception {
31          openProject(new File("src/test/resources/projects/transformer/associated-dom-transformer.xhp"));
32      }
33  
34      public void openDefaultDOMProject() throws Exception {
35          openProject(new File("src/test/resources/projects/transformer/default-dom-transformer.xhp"));
36      }
37  
38      public void openDefaultSAXProject() throws Exception {
39          openProject(new File("src/test/resources/projects/transformer/default-sax-transformer.xhp"));
40      }
41  
42      public void openSimpleDOMProject() throws Exception {
43          openProject(new File("src/test/resources/projects/transformer/simple-dom-transformer.xhp"));
44      }
45  
46      public void openMultipleInvalidDOMProject() throws Exception {
47          openProject(new File("src/test/resources/projects/transformer/multiple-invalid-dom-transformer.xhp"));
48      }
49  
50      public void openMultipleDOMProject() throws Exception {
51          openProject(new File("src/test/resources/projects/transformer/multiple-dom-transformer.xhp"));
52      }
53  
54      public void openMultipleSAXProject() throws Exception {
55          openProject(new File("src/test/resources/projects/transformer/multiple-sax-transformer.xhp"));
56      }
57  
58      public void execute() {
59          super.execute();
60  
61          ResultTreeModel model = getApplication().getProjectsView().getSelectedView().getResultPanel().getModel();
62          assertEquals(1, ((MutableTreeNode)model.getRoot()).getChildCount());
63          assertEquals(2, ((MutableTreeNode)model.getRoot()).getChildAt(0).getChildCount());
64      }
65  
66      public void executeDefault() {
67          super.execute();
68  
69          ResultTreeModel model = getApplication().getProjectsView().getSelectedView().getResultPanel().getModel();
70          assertEquals(1, ((MutableTreeNode)model.getRoot()).getChildCount());
71          assertEquals(0, ((MutableTreeNode)model.getRoot()).getChildAt(0).getChildCount());
72      }
73  
74      public void executeInvalid() {
75          super.execute();
76  
77          ResultTreeModel model = getApplication().getProjectsView().getSelectedView().getResultPanel().getModel();
78          assertEquals(1, ((MutableTreeNode)model.getRoot()).getChildCount());
79          assertEquals(4, ((MutableTreeNode)model.getRoot()).getChildAt(0).getChildCount());
80      }
81  
82      public void executeMultiple() {
83          super.execute();
84  
85          ResultTreeModel model = getApplication().getProjectsView().getSelectedView().getResultPanel().getModel();
86          assertEquals(1, ((MutableTreeNode)model.getRoot()).getChildCount());
87          assertEquals(4, ((MutableTreeNode)model.getRoot()).getChildAt(0).getChildCount());
88      }
89  
90      public void executeMultipleInvalid() {
91          super.execute();
92  
93          ResultTreeModel model = getApplication().getProjectsView().getSelectedView().getResultPanel().getModel();
94          assertEquals(0, ((MutableTreeNode)model.getRoot()).getChildCount());
95      }
96  
97      public void checkOutput() throws Exception {
98          File golden = new File("src/test/resources/output/golden-example.out");
99          File out = new File("src/test/resources/input/example.out");
100 
101         assertTrue(out.exists());
102         
103         assertTrue(compareFilesIgnoreWhitespace(out, golden));
104 
105         if (out.exists()) {
106             out.delete();
107         }
108     }
109     
110     public void checkDefaultOutput() throws Exception {
111         File golden = new File("src/test/resources/output/golden-default-example.out");
112         File out = new File("src/test/resources/input/example.out");
113 
114         assertTrue(out.exists());
115         
116         assertTrue(compareFilesIgnoreWhitespace(out, golden));
117 
118         if (out.exists()) {
119             out.delete();
120         }
121     }
122 
123     public void checkMultipleOutput() throws Exception {
124         File golden = new File("src/test/resources/output/golden-multiple-example.out");
125         File out = new File("src/test/resources/input/example.out");
126 
127         assertTrue(out.exists());
128         
129         assertTrue(compareFilesIgnoreWhitespace(out, golden));
130 
131         if (out.exists()) {
132             out.delete();
133         }
134     }
135 
136 //    private boolean compareFiles(File file1, File file2) throws Exception {
137 //        FileInputStream stream1 = new FileInputStream(file1);
138 //        FileInputStream stream2 = new FileInputStream(file2);
139 //
140 //        int ch = stream1.read();
141 //        while (ch != -1 && ch == stream2.read()) {
142 //            ch = stream1.read();
143 //        }
144 //        
145 //        return -1 == ch;
146 //    }
147 
148     private boolean compareFilesIgnoreWhitespace(File file1, File file2) throws Exception {
149         FileInputStream stream1 = new FileInputStream(file1);
150         FileInputStream stream2 = new FileInputStream(file2);
151 
152         int ch = getNextNonWhitespaceCharacter(stream1);
153         while (ch != -1 && ch == getNextNonWhitespaceCharacter(stream2)) {
154             ch = getNextNonWhitespaceCharacter(stream1);
155         }
156         
157         return -1 == ch;
158     }
159     
160     private int getNextNonWhitespaceCharacter(FileInputStream stream) throws Exception {
161     	
162         int ch = stream.read();
163         while (ch != -1 && Character.isWhitespace(ch)) {
164             ch = stream.read();
165         }
166         
167         return ch;
168     }
169 
170     public static Test suite() {
171         TestSuite suite = new TestSuite("Transformation Projects");
172         
173         suite.addTest(new TransformationTest("openSimpleSAXProject"));
174         suite.addTest(new TransformationTest("initialPage"));
175         suite.addTest(new TransformationTest("hasChanged"));
176         suite.addTest(new TransformationTest("execute"));
177         suite.addTest(new TransformationTest("checkOutput"));
178         suite.addTest(new TransformationTest("closeProject"));
179         suite.addTest(new TransformationTest("openSimpleDOMProject"));
180         suite.addTest(new TransformationTest("initialPage"));
181         suite.addTest(new TransformationTest("hasChanged"));
182         suite.addTest(new TransformationTest("execute"));
183         suite.addTest(new TransformationTest("checkOutput"));
184         suite.addTest(new TransformationTest("closeProject"));
185         suite.addTest(new TransformationTest("openAssociatedInvalidSAXProject"));
186         suite.addTest(new TransformationTest("initialPage"));
187         suite.addTest(new TransformationTest("hasChanged"));
188         suite.addTest(new TransformationTest("executeInvalid"));
189         suite.addTest(new TransformationTest("closeProject"));
190         suite.addTest(new TransformationTest("openAssociatedSAXProject"));
191         suite.addTest(new TransformationTest("initialPage"));
192         suite.addTest(new TransformationTest("hasChanged"));
193         suite.addTest(new TransformationTest("execute"));
194         suite.addTest(new TransformationTest("checkOutput"));
195         suite.addTest(new TransformationTest("closeProject"));
196         suite.addTest(new TransformationTest("openAssociatedDOMProject"));
197         suite.addTest(new TransformationTest("initialPage"));
198         suite.addTest(new TransformationTest("hasChanged"));
199         suite.addTest(new TransformationTest("execute"));
200         suite.addTest(new TransformationTest("checkOutput"));
201         suite.addTest(new TransformationTest("closeProject"));
202         suite.addTest(new TransformationTest("openDefaultDOMProject"));
203         suite.addTest(new TransformationTest("initialPage"));
204         suite.addTest(new TransformationTest("hasChanged"));
205         suite.addTest(new TransformationTest("executeDefault"));
206         suite.addTest(new TransformationTest("checkDefaultOutput"));
207         suite.addTest(new TransformationTest("closeProject"));
208         suite.addTest(new TransformationTest("openDefaultSAXProject"));
209         suite.addTest(new TransformationTest("initialPage"));
210         suite.addTest(new TransformationTest("hasChanged"));
211         suite.addTest(new TransformationTest("executeDefault"));
212         suite.addTest(new TransformationTest("checkDefaultOutput"));
213         suite.addTest(new TransformationTest("closeProject"));
214         suite.addTest(new TransformationTest("openMultipleSAXProject"));
215         suite.addTest(new TransformationTest("initialPage"));
216         suite.addTest(new TransformationTest("hasChanged"));
217         suite.addTest(new TransformationTest("executeMultiple"));
218         suite.addTest(new TransformationTest("checkMultipleOutput"));
219         suite.addTest(new TransformationTest("closeProject"));
220         suite.addTest(new TransformationTest("openMultipleDOMProject"));
221         suite.addTest(new TransformationTest("initialPage"));
222         suite.addTest(new TransformationTest("hasChanged"));
223         suite.addTest(new TransformationTest("executeMultiple"));
224         suite.addTest(new TransformationTest("checkMultipleOutput"));
225         suite.addTest(new TransformationTest("closeProject"));
226         suite.addTest(new TransformationTest("openMultipleInvalidDOMProject"));
227         suite.addTest(new TransformationTest("initialPage"));
228         suite.addTest(new TransformationTest("hasChanged"));
229         suite.addTest(new TransformationTest("executeMultipleInvalid"));
230         suite.addTest(new TransformationTest("closeProject"));
231         suite.addTest(new TransformationTest("closeApplication"));
232 
233         return suite;
234     }
235 }