[1059] | 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; |
---|
[1069] | 21 | import java.util.Iterator; |
---|
[1059] | 22 | import java.util.List; |
---|
| 23 | import java.util.logging.Level; |
---|
| 24 | |
---|
| 25 | import org.junit.Before; |
---|
| 26 | import org.junit.Test; |
---|
| 27 | |
---|
| 28 | import de.ugoe.cs.autoquest.eventcore.Event; |
---|
| 29 | import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel; |
---|
| 30 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; |
---|
| 31 | import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLGUIElement; |
---|
| 32 | import de.ugoe.cs.util.console.TextConsole; |
---|
| 33 | |
---|
| 34 | /** |
---|
| 35 | * Test for the new HTMLLogParser |
---|
| 36 | * @author Fabian Glaser |
---|
| 37 | * |
---|
| 38 | */ |
---|
[1066] | 39 | public class HTMLLogParserTest { |
---|
[1059] | 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 { |
---|
[1066] | 56 | HTMLLogParser parser = new HTMLLogParser(); |
---|
[1069] | 57 | parser.parseFile(new File(ClassLoader.getSystemResource("htmlmonitor_testtrace_1.xml").getFile())); |
---|
| 58 | parser.parseFile(new File(ClassLoader.getSystemResource("htmlmonitor_testtrace_2.xml").getFile())); |
---|
[1059] | 59 | Collection<List<Event>> events = parser.getSequences(); |
---|
| 60 | |
---|
| 61 | assertNotNull(events); |
---|
[1069] | 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()); |
---|
[1059] | 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 | } |
---|