| 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.Iterator; |
|---|
| 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 | */ |
|---|
| 39 | public class HTMLLogParserTest { |
|---|
| 40 | |
|---|
| 41 | /** |
|---|
| 42 | * |
|---|
| 43 | */ |
|---|
| 44 | @Before |
|---|
| 45 | public void setUp() { |
|---|
| 46 | new TextConsole(Level.FINEST); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | /** |
|---|
| 50 | * Tests the parseFile method with a given trace file. |
|---|
| 51 | * @throws Exception |
|---|
| 52 | */ |
|---|
| 53 | @Test |
|---|
| 54 | public void testParseFile_1() throws Exception { |
|---|
| 55 | HTMLLogParser parser = new HTMLLogParser(); |
|---|
| 56 | parser.parseFile(new File(ClassLoader.getSystemResource("htmlmonitor_testtrace_1.xml").getFile())); |
|---|
| 57 | Collection<List<Event>> events = parser.getSequences(); |
|---|
| 58 | |
|---|
| 59 | assertNotNull(events); |
|---|
| 60 | assertEquals(1, events.size()); |
|---|
| 61 | |
|---|
| 62 | Iterator<List<Event>> iterator = events.iterator(); |
|---|
| 63 | assertNotNull(iterator); |
|---|
| 64 | assertEquals(1, iterator.next().size()); |
|---|
| 65 | assertFalse(iterator.hasNext()); |
|---|
| 66 | |
|---|
| 67 | System.err.println("{"); |
|---|
| 68 | for (List<Event> session : events) { |
|---|
| 69 | System.err.println(" {"); |
|---|
| 70 | for (Event event : session) { |
|---|
| 71 | System.err.print(" "); |
|---|
| 72 | System.err.print(event); |
|---|
| 73 | System.err.println(","); |
|---|
| 74 | } |
|---|
| 75 | System.err.println(" }"); |
|---|
| 76 | } |
|---|
| 77 | System.err.println("}"); |
|---|
| 78 | System.err.println("\n\n"); |
|---|
| 79 | |
|---|
| 80 | GUIModel guiModel = parser.getGuiModel(); |
|---|
| 81 | assertNotNull(guiModel); |
|---|
| 82 | |
|---|
| 83 | for (IGUIElement root : guiModel.getRootElements()) { |
|---|
| 84 | dumpGUIElement(root, guiModel, ""); |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | /** |
|---|
| 89 | * Tests the parseFile method with a given trace file. |
|---|
| 90 | * @throws Exception |
|---|
| 91 | */ |
|---|
| 92 | @Test |
|---|
| 93 | public void testParseFile_2() throws Exception { |
|---|
| 94 | HTMLLogParser parser = new HTMLLogParser(); |
|---|
| 95 | parser.parseFile(new File(ClassLoader.getSystemResource("htmlmonitor_testtrace_2.xml").getFile())); |
|---|
| 96 | Collection<List<Event>> events = parser.getSequences(); |
|---|
| 97 | |
|---|
| 98 | assertNotNull(events); |
|---|
| 99 | assertEquals(1, events.size()); |
|---|
| 100 | |
|---|
| 101 | Iterator<List<Event>> iterator = events.iterator(); |
|---|
| 102 | assertNotNull(iterator); |
|---|
| 103 | assertEquals(2, iterator.next().size()); |
|---|
| 104 | assertFalse(iterator.hasNext()); |
|---|
| 105 | |
|---|
| 106 | System.err.println("{"); |
|---|
| 107 | for (List<Event> session : events) { |
|---|
| 108 | System.err.println(" {"); |
|---|
| 109 | for (Event event : session) { |
|---|
| 110 | System.err.print(" "); |
|---|
| 111 | System.err.print(event); |
|---|
| 112 | System.err.println(","); |
|---|
| 113 | } |
|---|
| 114 | System.err.println(" }"); |
|---|
| 115 | } |
|---|
| 116 | System.err.println("}"); |
|---|
| 117 | System.err.println("\n\n"); |
|---|
| 118 | |
|---|
| 119 | GUIModel guiModel = parser.getGuiModel(); |
|---|
| 120 | assertNotNull(guiModel); |
|---|
| 121 | |
|---|
| 122 | for (IGUIElement root : guiModel.getRootElements()) { |
|---|
| 123 | dumpGUIElement(root, guiModel, ""); |
|---|
| 124 | } |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | /** |
|---|
| 128 | * Helper method to print out GUIElements |
|---|
| 129 | * @param guiElement |
|---|
| 130 | * @param guiModel |
|---|
| 131 | * @param indent |
|---|
| 132 | */ |
|---|
| 133 | private void dumpGUIElement(IGUIElement guiElement, GUIModel guiModel, String indent) { |
|---|
| 134 | assertTrue(guiElement instanceof HTMLGUIElement); |
|---|
| 135 | |
|---|
| 136 | System.err.print(indent); |
|---|
| 137 | System.err.print(guiElement); |
|---|
| 138 | |
|---|
| 139 | List<IGUIElement> children = guiModel.getChildren(guiElement); |
|---|
| 140 | |
|---|
| 141 | if ((children != null) && (children.size() > 0)) { |
|---|
| 142 | System.err.println(" {"); |
|---|
| 143 | |
|---|
| 144 | for (IGUIElement child : children) { |
|---|
| 145 | dumpGUIElement(child, guiModel, indent + " "); |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | System.err.print(indent); |
|---|
| 149 | System.err.print("}"); |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | System.err.println(); |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | } |
|---|