Changeset 1496 for trunk/autoquest-plugin-html-test/src
- Timestamp:
- 04/11/14 12:12:52 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-html-test/src/test/java/de/ugoe/cs/autoquest/plugin/html/HTMLLogParserTest.java
r1340 r1496 18 18 19 19 import java.io.File; 20 import java.io.FileOutputStream; 21 import java.io.PrintWriter; 20 22 import java.util.Collection; 21 import java.util.HashMap;22 23 import java.util.Iterator; 23 import java.util.LinkedList;24 24 import java.util.List; 25 import java.util.Map;26 25 import java.util.logging.Level; 27 26 27 import org.junit.After; 28 28 import org.junit.Before; 29 29 import org.junit.Test; … … 42 42 public class HTMLLogParserTest { 43 43 44 /** 45 * 46 */ 47 @Before 48 public void setUp() { 49 new TextConsole(Level.FINEST); 50 } 51 52 /** 53 * Tests the parseFile method with a given trace file. 54 * @throws Exception 55 */ 56 @Test 57 public void testParseFile_1() throws Exception { 58 HTMLLogParser parser = new HTMLLogParser(new HashMap<String, List<String>>()); 59 parser.parseFile 60 (new File(ClassLoader.getSystemResource("htmlmonitor_testtrace_1.xml").getFile())); 61 Collection<List<Event>> events = parser.getSequences(); 62 63 assertNotNull(events); 64 assertEquals(1, events.size()); 65 66 Iterator<List<Event>> iterator = events.iterator(); 67 assertNotNull(iterator); 68 assertEquals(1, iterator.next().size()); 69 assertFalse(iterator.hasNext()); 70 71 System.err.println("{"); 72 for (List<Event> session : events) { 73 System.err.println(" {"); 74 for (Event event : session) { 75 System.err.print(" "); 76 System.err.print(event); 77 System.err.println(","); 78 } 79 System.err.println(" }"); 80 } 81 System.err.println("}"); 82 System.err.println("\n\n"); 83 84 GUIModel guiModel = parser.getGuiModel(); 85 assertNotNull(guiModel); 86 87 for (IGUIElement root : guiModel.getRootElements()) { 88 dumpGUIElement(root, guiModel, ""); 89 } 90 } 91 92 /** 93 * Tests the parseFile method with a given trace file. 94 * @throws Exception 95 */ 96 @Test 97 public void testParseFile_2() throws Exception { 98 HTMLLogParser parser = new HTMLLogParser(new HashMap<String, List<String>>()); 99 parser.parseFile 100 (new File(ClassLoader.getSystemResource("htmlmonitor_testtrace_2.xml").getFile())); 101 Collection<List<Event>> events = parser.getSequences(); 102 103 assertNotNull(events); 104 assertEquals(1, events.size()); 105 106 Iterator<List<Event>> iterator = events.iterator(); 107 assertNotNull(iterator); 108 assertEquals(2, iterator.next().size()); 109 assertFalse(iterator.hasNext()); 110 111 System.err.println("{"); 112 for (List<Event> session : events) { 113 System.err.println(" {"); 114 for (Event event : session) { 115 System.err.print(" "); 116 System.err.print(event); 117 System.err.println(","); 118 } 119 System.err.println(" }"); 120 } 121 System.err.println("}"); 122 System.err.println("\n\n"); 123 124 GUIModel guiModel = parser.getGuiModel(); 125 assertNotNull(guiModel); 126 127 for (IGUIElement root : guiModel.getRootElements()) { 128 dumpGUIElement(root, guiModel, ""); 129 } 130 } 131 132 /** 133 * Tests the parseFile method with a given trace file. 134 * @throws Exception 135 */ 136 @Test 137 public void testParseFile_3() throws Exception { 138 Map<String, List<String>> params = new HashMap<String, List<String>>(); 139 List<String> list = new LinkedList<String>(); 140 list.add("td[2]"); 141 list.add("th"); 142 params.put("clearIndex", list); 143 HTMLLogParser parser = new HTMLLogParser(params); 144 145 parser.parseFile 146 (new File(ClassLoader.getSystemResource("htmlmonitor_testtrace_3.xml").getFile())); 147 Collection<List<Event>> events = parser.getSequences(); 148 149 assertNotNull(events); 150 assertEquals(1, events.size()); 151 152 Iterator<List<Event>> iterator = events.iterator(); 153 assertNotNull(iterator); 154 assertEquals(2, iterator.next().size()); 155 assertFalse(iterator.hasNext()); 156 157 System.err.println("{"); 158 for (List<Event> session : events) { 159 System.err.println(" {"); 160 for (Event event : session) { 161 System.err.print(" "); 162 System.err.print(event); 163 System.err.println(","); 164 } 165 System.err.println(" }"); 166 } 167 System.err.println("}"); 168 System.err.println("\n\n"); 169 170 GUIModel guiModel = parser.getGuiModel(); 171 assertNotNull(guiModel); 172 173 for (IGUIElement root : guiModel.getRootElements()) { 174 dumpGUIElement(root, guiModel, ""); 175 } 176 } 177 178 /** 179 * Tests the parseFile method with a given trace file. 180 * @throws Exception 181 */ 182 @Test 183 public void testParseFile_4() throws Exception { 184 Map<String, List<String>> params = new HashMap<String, List<String>>(); 185 List<String> list = new LinkedList<String>(); 186 list.add("html/body[1]/h1"); 187 params.put("clearId", list); 188 HTMLLogParser parser = new HTMLLogParser(params); 189 190 parser.parseFile 191 (new File(ClassLoader.getSystemResource("htmlmonitor_testtrace_4.xml").getFile())); 192 Collection<List<Event>> events = parser.getSequences(); 193 194 assertNotNull(events); 195 assertEquals(1, events.size()); 196 197 Iterator<List<Event>> iterator = events.iterator(); 198 assertNotNull(iterator); 199 assertEquals(2, iterator.next().size()); 200 assertFalse(iterator.hasNext()); 201 202 System.err.println("{"); 203 for (List<Event> session : events) { 204 System.err.println(" {"); 205 for (Event event : session) { 206 System.err.print(" "); 207 System.err.print(event); 208 System.err.println(","); 209 } 210 System.err.println(" }"); 211 } 212 System.err.println("}"); 213 System.err.println("\n\n"); 214 215 GUIModel guiModel = parser.getGuiModel(); 216 assertNotNull(guiModel); 217 218 for (IGUIElement root : guiModel.getRootElements()) { 219 dumpGUIElement(root, guiModel, ""); 220 } 221 } 222 223 /** 224 * Tests the parseFile method with a given trace file. 225 * @throws Exception 226 */ 227 @Test 228 public void testParseFile_5() throws Exception { 229 Map<String, List<String>> params = new HashMap<String, List<String>>(); 230 List<String> list = new LinkedList<String>(); 231 list.add("html/body[1]/h1(htmlId=id_h1)"); 232 params.put("clearId", list); 233 HTMLLogParser parser = new HTMLLogParser(params); 234 235 parser.parseFile 236 (new File(ClassLoader.getSystemResource("htmlmonitor_testtrace_4.xml").getFile())); 237 Collection<List<Event>> events = parser.getSequences(); 238 239 assertNotNull(events); 240 assertEquals(1, events.size()); 241 242 Iterator<List<Event>> iterator = events.iterator(); 243 assertNotNull(iterator); 244 assertEquals(2, iterator.next().size()); 245 assertFalse(iterator.hasNext()); 246 247 System.err.println("{"); 248 for (List<Event> session : events) { 249 System.err.println(" {"); 250 for (Event event : session) { 251 System.err.print(" "); 252 System.err.print(event); 253 System.err.println(","); 254 } 255 System.err.println(" }"); 256 } 257 System.err.println("}"); 258 System.err.println("\n\n"); 259 260 GUIModel guiModel = parser.getGuiModel(); 261 assertNotNull(guiModel); 262 263 for (IGUIElement root : guiModel.getRootElements()) { 264 dumpGUIElement(root, guiModel, ""); 265 } 266 } 267 268 /** 269 * Helper method to print out GUIElements 270 * @param guiElement 271 * @param guiModel 272 * @param indent 273 */ 274 private void dumpGUIElement(IGUIElement guiElement, GUIModel guiModel, String indent) { 275 assertTrue(guiElement instanceof HTMLGUIElement); 276 277 System.err.print(indent); 278 System.err.print(guiElement); 279 280 List<IGUIElement> children = guiModel.getChildren(guiElement); 281 282 if ((children != null) && (children.size() > 0)) { 283 System.err.println(" {"); 284 285 for (IGUIElement child : children) { 286 dumpGUIElement(child, guiModel, indent + " "); 287 } 288 289 System.err.print(indent); 290 System.err.print("}"); 291 } 292 293 System.err.println(); 294 } 44 /** */ 45 private static final String PARSE_PARAM_FILE = "tmpParseParamFile"; 46 47 /** 48 * 49 */ 50 @Before 51 public void setUp() { 52 new TextConsole(Level.FINEST); 53 } 54 55 /** 56 * 57 */ 58 @After 59 public void tearDown() { 60 new File(PARSE_PARAM_FILE).delete(); 61 } 62 63 /** 64 * Tests the parseFile method with a given trace file. 65 * @throws Exception 66 */ 67 @Test 68 public void testParseFile_1() throws Exception { 69 HTMLLogParser parser = new HTMLLogParser(null); 70 parser.parseFile 71 (new File(ClassLoader.getSystemResource("htmlmonitor_testtrace_1.xml").getFile())); 72 Collection<List<Event>> events = parser.getSequences(); 73 74 assertNotNull(events); 75 assertEquals(1, events.size()); 76 77 Iterator<List<Event>> iterator = events.iterator(); 78 assertNotNull(iterator); 79 assertEquals(1, iterator.next().size()); 80 assertFalse(iterator.hasNext()); 81 82 System.err.println("{"); 83 for (List<Event> session : events) { 84 System.err.println(" {"); 85 for (Event event : session) { 86 System.err.print(" "); 87 System.err.print(event); 88 System.err.println(","); 89 } 90 System.err.println(" }"); 91 } 92 System.err.println("}"); 93 System.err.println("\n\n"); 94 95 GUIModel guiModel = parser.getGuiModel(); 96 assertNotNull(guiModel); 97 98 for (IGUIElement root : guiModel.getRootElements()) { 99 dumpGUIElement(root, guiModel, ""); 100 } 101 } 102 103 /** 104 * Tests the parseFile method with a given trace file. 105 * @throws Exception 106 */ 107 @Test 108 public void testParseFile_2() throws Exception { 109 HTMLLogParser parser = new HTMLLogParser(null); 110 parser.parseFile 111 (new File(ClassLoader.getSystemResource("htmlmonitor_testtrace_2.xml").getFile())); 112 Collection<List<Event>> events = parser.getSequences(); 113 114 assertNotNull(events); 115 assertEquals(1, events.size()); 116 117 Iterator<List<Event>> iterator = events.iterator(); 118 assertNotNull(iterator); 119 assertEquals(2, iterator.next().size()); 120 assertFalse(iterator.hasNext()); 121 122 System.err.println("{"); 123 for (List<Event> session : events) { 124 System.err.println(" {"); 125 for (Event event : session) { 126 System.err.print(" "); 127 System.err.print(event); 128 System.err.println(","); 129 } 130 System.err.println(" }"); 131 } 132 System.err.println("}"); 133 System.err.println("\n\n"); 134 135 GUIModel guiModel = parser.getGuiModel(); 136 assertNotNull(guiModel); 137 138 for (IGUIElement root : guiModel.getRootElements()) { 139 dumpGUIElement(root, guiModel, ""); 140 } 141 } 142 143 /** 144 * Tests the parseFile method with a given trace file. 145 * @throws Exception 146 */ 147 @Test 148 public void testParseFile_3() throws Exception { 149 PrintWriter out = new PrintWriter(new FileOutputStream(new File(PARSE_PARAM_FILE))); 150 out.println("td[2]=CLEAR_INDEX"); 151 out.println("th=CLEAR_INDEX"); 152 out.close(); 153 154 HTMLLogParser parser = new HTMLLogParser(PARSE_PARAM_FILE); 155 156 parser.parseFile 157 (new File(ClassLoader.getSystemResource("htmlmonitor_testtrace_3.xml").getFile())); 158 Collection<List<Event>> events = parser.getSequences(); 159 160 assertNotNull(events); 161 assertEquals(1, events.size()); 162 163 Iterator<List<Event>> iterator = events.iterator(); 164 assertNotNull(iterator); 165 assertEquals(2, iterator.next().size()); 166 assertFalse(iterator.hasNext()); 167 168 System.err.println("{"); 169 for (List<Event> session : events) { 170 System.err.println(" {"); 171 for (Event event : session) { 172 System.err.print(" "); 173 System.err.print(event); 174 System.err.println(","); 175 } 176 System.err.println(" }"); 177 } 178 System.err.println("}"); 179 System.err.println("\n\n"); 180 181 GUIModel guiModel = parser.getGuiModel(); 182 assertNotNull(guiModel); 183 184 for (IGUIElement root : guiModel.getRootElements()) { 185 dumpGUIElement(root, guiModel, ""); 186 } 187 } 188 189 /** 190 * Tests the parseFile method with a given trace file. 191 * @throws Exception 192 */ 193 @Test 194 public void testParseFile_4() throws Exception { 195 PrintWriter out = new PrintWriter(new FileOutputStream(new File(PARSE_PARAM_FILE))); 196 out.println("html/body[1]/h1="); 197 out.close(); 198 199 HTMLLogParser parser = new HTMLLogParser(PARSE_PARAM_FILE); 200 201 parser.parseFile 202 (new File(ClassLoader.getSystemResource("htmlmonitor_testtrace_4.xml").getFile())); 203 Collection<List<Event>> events = parser.getSequences(); 204 205 assertNotNull(events); 206 assertEquals(1, events.size()); 207 208 Iterator<List<Event>> iterator = events.iterator(); 209 assertNotNull(iterator); 210 assertEquals(2, iterator.next().size()); 211 assertFalse(iterator.hasNext()); 212 213 System.err.println("{"); 214 for (List<Event> session : events) { 215 System.err.println(" {"); 216 for (Event event : session) { 217 System.err.print(" "); 218 System.err.print(event); 219 System.err.println(","); 220 } 221 System.err.println(" }"); 222 } 223 System.err.println("}"); 224 System.err.println("\n\n"); 225 226 GUIModel guiModel = parser.getGuiModel(); 227 assertNotNull(guiModel); 228 229 for (IGUIElement root : guiModel.getRootElements()) { 230 dumpGUIElement(root, guiModel, ""); 231 } 232 } 233 234 /** 235 * Tests the parseFile method with a given trace file. 236 * @throws Exception 237 */ 238 @Test 239 public void testParseFile_5() throws Exception { 240 PrintWriter out = new PrintWriter(new FileOutputStream(new File(PARSE_PARAM_FILE))); 241 out.println("html/body[1]/h1(htmlId\\=id_h1)="); 242 out.close(); 243 244 HTMLLogParser parser = new HTMLLogParser(PARSE_PARAM_FILE); 245 246 parser.parseFile 247 (new File(ClassLoader.getSystemResource("htmlmonitor_testtrace_4.xml").getFile())); 248 Collection<List<Event>> events = parser.getSequences(); 249 250 assertNotNull(events); 251 assertEquals(1, events.size()); 252 253 Iterator<List<Event>> iterator = events.iterator(); 254 assertNotNull(iterator); 255 assertEquals(2, iterator.next().size()); 256 assertFalse(iterator.hasNext()); 257 258 System.err.println("{"); 259 for (List<Event> session : events) { 260 System.err.println(" {"); 261 for (Event event : session) { 262 System.err.print(" "); 263 System.err.print(event); 264 System.err.println(","); 265 } 266 System.err.println(" }"); 267 } 268 System.err.println("}"); 269 System.err.println("\n\n"); 270 271 GUIModel guiModel = parser.getGuiModel(); 272 assertNotNull(guiModel); 273 274 for (IGUIElement root : guiModel.getRootElements()) { 275 dumpGUIElement(root, guiModel, ""); 276 } 277 } 278 279 /** 280 * Helper method to print out GUIElements 281 * @param guiElement 282 * @param guiModel 283 * @param indent 284 */ 285 private void dumpGUIElement(IGUIElement guiElement, GUIModel guiModel, String indent) { 286 assertTrue(guiElement instanceof HTMLGUIElement); 287 288 System.err.print(indent); 289 System.err.print(guiElement); 290 291 List<IGUIElement> children = guiModel.getChildren(guiElement); 292 293 if ((children != null) && (children.size() > 0)) { 294 System.err.println(" {"); 295 296 for (IGUIElement child : children) { 297 dumpGUIElement(child, guiModel, indent + " "); 298 } 299 300 System.err.print(indent); 301 System.err.print("}"); 302 } 303 304 System.err.println(); 305 } 295 306 296 307 }
Note: See TracChangeset
for help on using the changeset viewer.