1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
2 | // |
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
4 | // you may not use this file except in compliance with the License. |
---|
5 | // You may obtain a copy of the License at |
---|
6 | // |
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
8 | // |
---|
9 | // Unless required by applicable law or agreed to in writing, software |
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
12 | // See the License for the specific language governing permissions and |
---|
13 | // limitations under the License. |
---|
14 | |
---|
15 | package de.ugoe.cs.autoquest.plugin.html; |
---|
16 | |
---|
17 | import static org.junit.Assert.*; |
---|
18 | |
---|
19 | import java.io.File; |
---|
20 | import java.util.Collection; |
---|
21 | import java.util.List; |
---|
22 | import java.util.logging.Level; |
---|
23 | |
---|
24 | import org.junit.Before; |
---|
25 | import org.junit.Test; |
---|
26 | |
---|
27 | import de.ugoe.cs.autoquest.eventcore.Event; |
---|
28 | import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel; |
---|
29 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; |
---|
30 | import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElement; |
---|
31 | import de.ugoe.cs.util.console.TextConsole; |
---|
32 | |
---|
33 | /** |
---|
34 | * Test for the new HTMLLogParser |
---|
35 | * @author Fabian Glaser |
---|
36 | * |
---|
37 | */ |
---|
38 | public class HTMLLogParserTest { |
---|
39 | |
---|
40 | /** |
---|
41 | * |
---|
42 | */ |
---|
43 | @Before |
---|
44 | public void setUp() { |
---|
45 | new TextConsole(Level.FINEST); |
---|
46 | } |
---|
47 | |
---|
48 | |
---|
49 | /** |
---|
50 | * Tests the parseFile method with a given trace file. |
---|
51 | * @throws Exception |
---|
52 | */ |
---|
53 | @Test |
---|
54 | public void testParseFile() throws Exception { |
---|
55 | HTMLLogParser parser = new HTMLLogParser(); |
---|
56 | parser.parseFile(new File(ClassLoader.getSystemResource("htmlmonitor_testtrace.xml").getFile())); |
---|
57 | Collection<List<Event>> events = parser.getSequences(); |
---|
58 | |
---|
59 | assertNotNull(events); |
---|
60 | assertTrue(events.size() > 0); |
---|
61 | |
---|
62 | System.err.println("{"); |
---|
63 | for (List<Event> session : events) { |
---|
64 | System.err.println(" {"); |
---|
65 | for (Event event : session) { |
---|
66 | System.err.print(" "); |
---|
67 | System.err.print(event); |
---|
68 | System.err.println(","); |
---|
69 | } |
---|
70 | System.err.println(" }"); |
---|
71 | } |
---|
72 | System.err.println("}"); |
---|
73 | System.err.println("\n\n"); |
---|
74 | |
---|
75 | GUIModel guiModel = parser.getGuiModel(); |
---|
76 | assertNotNull(guiModel); |
---|
77 | |
---|
78 | for (IGUIElement root : guiModel.getRootElements()) { |
---|
79 | dumpGUIElement(root, guiModel, ""); |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | /** |
---|
84 | * Helper method to print out GUIElements |
---|
85 | * @param guiElement |
---|
86 | * @param guiModel |
---|
87 | * @param indent |
---|
88 | */ |
---|
89 | private void dumpGUIElement(IGUIElement guiElement, GUIModel guiModel, String indent) { |
---|
90 | assertTrue(guiElement instanceof HTMLGUIElement); |
---|
91 | |
---|
92 | System.err.print(indent); |
---|
93 | System.err.print(guiElement); |
---|
94 | |
---|
95 | List<IGUIElement> children = guiModel.getChildren(guiElement); |
---|
96 | |
---|
97 | if ((children != null) && (children.size() > 0)) { |
---|
98 | System.err.println(" {"); |
---|
99 | |
---|
100 | for (IGUIElement child : children) { |
---|
101 | dumpGUIElement(child, guiModel, indent + " "); |
---|
102 | } |
---|
103 | |
---|
104 | System.err.print(indent); |
---|
105 | System.err.print("}"); |
---|
106 | } |
---|
107 | |
---|
108 | System.err.println(); |
---|
109 | } |
---|
110 | |
---|
111 | } |
---|