- Timestamp:
- 09/10/12 20:52:49 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-plugin-jfc-test/src/test/java/de/ugoe/cs/quest/plugin/jfc/JFCReplayIDCalculatorTest.java
r797 r806 26 26 import de.ugoe.cs.quest.plugin.jfc.guimodel.JFCGUIElement; 27 27 import de.ugoe.cs.quest.plugin.jfc.guimodel.JFCGUIElementSpec; 28 import de.ugoe.cs.quest.plugin.mfc.eventcore.MFCEventType; 29 import de.ugoe.cs.quest.plugin.mfc.guimodel.MFCToolBar; 28 30 import de.ugoe.cs.util.console.TextConsole; 29 31 … … 34 36 * @pattern JUnit Test Case 35 37 * 36 * @generatedBy CodePro at 7/30/12 4:50 PM37 *38 38 * @author fabian.glaser 39 39 * … … 41 41 */ 42 42 public class JFCReplayIDCalculatorTest extends TestCase { 43 44 Set<String> knownIDs = new HashSet<String>(); 43 45 44 46 /** … … 107 109 108 110 /** 109 * Run the String calculateReplayID(List<JFCGUIElementSpec>) method test. 111 * Method to test if calculated IDs are included in guitar efg file. 112 * If not more than 75 % can be matched, test fails. 110 113 * 111 114 * @throws Exception … … 115 118 throws Exception { 116 119 // generate list of known replayIDs from guitar efg file 117 File guiFile = new File(ClassLoader.getSystemResource("freemind.efg").getFile()); 118 119 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 120 DocumentBuilder builder = factory.newDocumentBuilder(); 121 Document freemindGUI = builder.parse(guiFile); 122 123 Node currentNode = freemindGUI.getFirstChild().getFirstChild(); 124 NodeList eventNodes = null; 125 List<String> knownIDs = new ArrayList<String>(); 126 127 while ((currentNode = currentNode.getNextSibling()) != null){ 128 if (currentNode.getNodeName().equals("Events")) 129 eventNodes = currentNode.getChildNodes(); 130 } 131 132 for (int i = 0; i < eventNodes.getLength(); i++){ 133 if (eventNodes.item(i).getNodeName().equals("Event")){ 134 NodeList attributes = eventNodes.item(i).getChildNodes(); 135 for (int j = 0; j < attributes.getLength(); j++){ 136 if (attributes.item(j).getNodeName().equals("EventId")){ 137 knownIDs.add(attributes.item(j).getTextContent()); 138 } 139 } 140 } 141 } 120 File guiFile = new File(ClassLoader.getSystemResource("freemind.xml").getFile()); 121 JFCReplayIDValidator validator = new JFCReplayIDValidator(guiFile); 142 122 143 123 // calculate replayIDs from trace file … … 145 125 ignoredEvents.add(JFCEventId.FOCUS_GAINED); 146 126 JFCLogParser parser = new JFCLogParser(ignoredEvents); 147 parser.parseFile(new File(ClassLoader.getSystemResource("freemind_trace 2.xml").getFile()));148 JFCReplayIDCalculator calculator = new JFCReplayIDCalculator( );127 parser.parseFile(new File(ClassLoader.getSystemResource("freemind_trace3.xml").getFile())); 128 JFCReplayIDCalculator calculator = new JFCReplayIDCalculator(validator); 149 129 150 130 Set<String> generatedIDs = new HashSet<String>(); … … 153 133 154 134 assertTrue(sequences.size() > 0); 155 156 135 157 136 for (List<Event> currentSequence: sequences){ … … 160 139 generatedIDs.add(replayID); 161 140 System.out.println("Generated ID: " + replayID); 141 System.out.println(); 162 142 } 163 143 } … … 168 148 int known = 0; 169 149 for (String replayID: generatedIDs){ 170 if ( knownIDs.contains(replayID)){150 if (validator.validateReplayID("w" + replayID.substring(1))){ 171 151 System.out.println(replayID + "\t is known."); 172 152 known++; … … 180 160 System.out.println(percentage + "% of the generated IDs are known."); 181 161 182 assertTrue(percentage > 75); 183 184 162 assertTrue(percentage > 75); 163 } 164 165 166 /** 167 * Method to test if calculateReplayID throws the right exception when 168 * it is called with a target of the wrong type. 169 */ 170 @Test 171 public void testCalculateReplayIDIllegalArgumentException(){ 172 try{ 173 JFCReplayIDCalculator calculator = new JFCReplayIDCalculator(); 174 Event event = new Event(new MFCEventType(null), new MFCToolBar(null, null)); 175 176 calculator.calculateReplayID(event); 177 178 fail("Expected IllegalArgumentException!"); 179 } 180 catch(IllegalArgumentException e){ 181 System.out.println("Expected exception thrown."); 182 } 185 183 } 186 184
Note: See TracChangeset
for help on using the changeset viewer.