source: trunk/autoquest-plugin-html-test/src/test/java/de/ugoe/cs/autoquest/plugin/html/HTMLLogParserTest.java @ 1069

Last change on this file since 1069 was 1069, checked in by pharms, 11 years ago
  • support of new HTML logging format
  • Property svn:mime-type set to text/plain
File size: 3.5 KB
Line 
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
15package de.ugoe.cs.autoquest.plugin.html;
16
17import static org.junit.Assert.*;
18
19import java.io.File;
20import java.util.Collection;
21import java.util.Iterator;
22import java.util.List;
23import java.util.logging.Level;
24
25import org.junit.Before;
26import org.junit.Test;
27
28import de.ugoe.cs.autoquest.eventcore.Event;
29import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel;
30import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement;
31import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElement;
32import de.ugoe.cs.util.console.TextConsole;
33
34/**
35 * Test for the new HTMLLogParser
36 * @author Fabian Glaser
37 *
38 */
39public class HTMLLogParserTest {
40
41    /**
42    *
43    */
44   @Before
45   public void setUp() {
46       new TextConsole(Level.FINEST);
47   }
48
49   
50   /**
51    * Tests the parseFile method with a given trace file.
52    * @throws Exception
53    */
54   @Test
55   public void testParseFile() throws Exception {
56       HTMLLogParser parser = new HTMLLogParser();
57       parser.parseFile(new File(ClassLoader.getSystemResource("htmlmonitor_testtrace_1.xml").getFile()));
58       parser.parseFile(new File(ClassLoader.getSystemResource("htmlmonitor_testtrace_2.xml").getFile()));
59       Collection<List<Event>> events = parser.getSequences();
60
61       assertNotNull(events);
62       assertEquals(2, events.size());
63       
64       Iterator<List<Event>> iterator = events.iterator();
65       assertNotNull(iterator);
66       assertEquals(1, iterator.next().size());
67       assertEquals(3, iterator.next().size());
68       assertFalse(iterator.hasNext());
69
70       System.err.println("{");
71       for (List<Event> session : events) {
72           System.err.println("  {");
73           for (Event event : session) {
74               System.err.print("    ");
75               System.err.print(event);
76               System.err.println(",");
77           }
78           System.err.println("  }");
79       }
80       System.err.println("}");
81       System.err.println("\n\n");
82
83       GUIModel guiModel = parser.getGuiModel();
84       assertNotNull(guiModel);
85
86       for (IGUIElement root : guiModel.getRootElements()) {
87           dumpGUIElement(root, guiModel, "");
88       }
89   }
90
91   /**
92    * Helper method to print out GUIElements
93    * @param guiElement
94    * @param guiModel
95    * @param indent
96    */
97   private void dumpGUIElement(IGUIElement guiElement, GUIModel guiModel, String indent) {
98       assertTrue(guiElement instanceof HTMLGUIElement);
99
100       System.err.print(indent);
101       System.err.print(guiElement);
102
103       List<IGUIElement> children = guiModel.getChildren(guiElement);
104
105       if ((children != null) && (children.size() > 0)) {
106           System.err.println(" {");
107
108           for (IGUIElement child : children) {
109               dumpGUIElement(child, guiModel, indent + "  ");
110           }
111
112           System.err.print(indent);
113           System.err.print("}");
114       }
115
116       System.err.println();
117   }
118
119}
Note: See TracBrowser for help on using the repository browser.