Changeset 2286 for trunk/autoquest-generic-event-monitor-test/src/test/java
- Timestamp:
- 01/28/20 14:35:03 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-generic-event-monitor-test/src/test/java/de/ugoe/cs/autoquest/genericeventmonitor/GenericEventMonitorTest.java
r2232 r2286 17 17 import static org.junit.Assert.*; 18 18 19 import java.lang.String; 20 19 21 import java.io.File; 22 import java.util.ArrayList; 23 import java.util.Collection; 24 import java.util.HashMap; 25 import java.util.HashSet; 26 import java.util.Iterator; 27 import java.util.List; 28 import java.util.Map; 20 29 21 30 import org.apache.http.HttpEntity; … … 29 38 import org.junit.Test; 30 39 40 import de.ugoe.cs.autoquest.eventcore.Event; 41 import de.ugoe.cs.autoquest.eventcore.HierarchicalEventTargetModel; 42 import de.ugoe.cs.autoquest.eventcore.IEventTarget; 43 import de.ugoe.cs.autoquest.eventcore.StringEventType; 31 44 import de.ugoe.cs.autoquest.genericeventmonitor.GenericEventMonitor; 45 import de.ugoe.cs.autoquest.plugin.genericevents.GenericEventLogParser; 46 import de.ugoe.cs.autoquest.plugin.genericevents.eventCore.GenericEventTarget; 32 47 import de.ugoe.cs.util.console.TextConsole; 33 48 … … 138 153 assertTrue(logFile.exists()); 139 154 140 /*HTMLLogParser parser = new HTMLLogParser(null);155 GenericEventLogParser parser = new GenericEventLogParser(new HashSet<String>()); 141 156 142 157 parser.parseFile(logFile); 143 158 144 159 // check the GUI model 145 GUIModel guiModel = parser.getGuiModel();160 HierarchicalEventTargetModel<GenericEventTarget> guiModel = parser.getHierarchicalEventTargetModel(); 146 161 assertNotNull(guiModel); 147 162 148 List< IGUIElement> nodes = guiModel.getRootElements();163 List<GenericEventTarget> nodes = guiModel.getRootElements(); 149 164 assertNotNull(nodes); 150 165 assertEquals(1, nodes.size()); 151 166 152 // get servernode153 IGUIElement node = nodes.get(0);167 // get root node 168 GenericEventTarget node = nodes.get(0); 154 169 assertNotNull(node); 155 assertTrue(node instanceof HTMLServer); 156 assertEquals("HTML", node.getPlatform()); 157 assertFalse(node.isUsed()); 170 assertEquals("target1", node.getStringIdentifier()); 171 assertEquals("Generic Event", node.getPlatform()); 158 172 159 173 nodes = guiModel.getChildren(node); 160 174 assertNotNull(nodes); 161 assertEquals( 1, nodes.size());162 163 // get documentnode175 assertEquals(2, nodes.size()); 176 177 // get children node 164 178 node = nodes.get(0); 165 179 assertNotNull(node); 166 assertTrue(node instanceof HTMLDocument); 167 assertEquals("HTML", node.getPlatform()); 168 assertFalse(node.isUsed()); 169 170 nodes = guiModel.getChildren(node); 171 assertNotNull(nodes); 172 assertEquals(1, nodes.size()); 173 174 // get html node 175 node = nodes.get(0); 180 assertTrue("target2".equals(node.getStringIdentifier()) || "target3".equals(node.getStringIdentifier())); 181 assertEquals("Generic Event", node.getPlatform()); 182 183 node = nodes.get(1); 176 184 assertNotNull(node); 177 assertTrue(node instanceof HTMLPageElement); 178 assertEquals("HTML", node.getPlatform()); 179 assertFalse(node.isUsed()); 180 181 nodes = guiModel.getChildren(node); 182 assertNotNull(nodes); 183 assertEquals(1, nodes.size()); // only one child as the head tag should have been ignored 184 185 // get body node 186 node = nodes.get(0); 187 assertNotNull(node); 188 assertTrue(node instanceof HTMLPageElement); 189 assertEquals("HTML", node.getPlatform()); 190 assertTrue(node.isUsed()); 191 192 nodes = guiModel.getChildren(node); 193 assertNotNull(nodes); 194 assertEquals(0, nodes.size()); 195 196 // check the sequences 185 assertTrue("target2".equals(node.getStringIdentifier()) || "target3".equals(node.getStringIdentifier())); 186 assertEquals("Generic Event", node.getPlatform()); 187 197 188 Collection<List<Event>> sequences = parser.getSequences(); 198 189 … … 208 199 assertEquals(1, sequence.size()); 209 200 210 assertEvent(sequence.get(0), 12345, MouseClick.class, node, 194, 7);*/ 201 IEventTarget target = null; 202 for (IEventTarget candidate : nodes) { 203 if ("target2".equals(candidate.getStringIdentifier())) { 204 target = candidate; 205 break; 206 } 207 } 208 209 assertEvent(sequence.get(0), "gaze", target); 210 211 211 } 212 212 … … 231 231 " \"children\":" + 232 232 " [ {" + 233 " \"targetId\":\"head\"," +234 " \"index\":\"0\"," +235 " }," +236 " {" +237 233 " \"tagName\":\"body\"," + 238 234 " \"targetId\":\"gsr\"," + … … 353 349 assertTrue(logFile.exists()); 354 350 355 /*HTMLLogParser parser = new HTMLLogParser(null); 351 352 GenericEventLogParser parser = new GenericEventLogParser(new HashSet<String>()); 356 353 357 354 parser.parseFile(logFile); 358 355 359 356 // check the GUI model 360 GUIModel guiModel = parser.getGuiModel();357 HierarchicalEventTargetModel<GenericEventTarget> guiModel = parser.getHierarchicalEventTargetModel(); 361 358 assertNotNull(guiModel); 362 359 363 List< IGUIElement> nodes = guiModel.getRootElements();360 List<GenericEventTarget> nodes = guiModel.getRootElements(); 364 361 assertNotNull(nodes); 365 362 assertEquals(1, nodes.size()); 366 363 367 // get servernode368 IGUIElement node = nodes.get(0);364 // get root node 365 GenericEventTarget node = nodes.get(0); 369 366 assertNotNull(node); 370 assertTrue(node instanceof HTMLServer); 371 assertEquals("HTML", node.getPlatform()); 372 assertFalse(node.isUsed()); 367 assertEquals("html", node.getStringIdentifier()); 368 assertEquals("Generic Event", node.getPlatform()); 373 369 374 370 nodes = guiModel.getChildren(node); … … 376 372 assertEquals(1, nodes.size()); 377 373 378 // get document node 379 node = nodes.get(0); 380 assertNotNull(node); 381 assertTrue(node instanceof HTMLDocument); 382 assertEquals("HTML", node.getPlatform()); 383 assertFalse(node.isUsed()); 384 385 nodes = guiModel.getChildren(node); 386 assertNotNull(nodes); 387 assertEquals(1, nodes.size()); 388 389 // get html node 390 node = nodes.get(0); 391 assertNotNull(node); 392 assertTrue(node instanceof HTMLPageElement); 393 assertEquals("HTML", node.getPlatform()); 394 assertFalse(node.isUsed()); 395 396 nodes = guiModel.getChildren(node); 397 assertNotNull(nodes); 398 assertEquals(1, nodes.size()); // only one child as the head tag should have been ignored 399 400 // get body node 401 IGUIElement body = nodes.get(0); 374 // get root child node 375 GenericEventTarget body = nodes.get(0); 402 376 assertNotNull(body); 403 assertTrue(body instanceof HTMLPageElement); 404 assertEquals("HTML", body.getPlatform()); 405 assertTrue(body.isUsed()); 406 377 assertEquals("gsr", body.getStringIdentifier()); 378 assertEquals("Generic Event", body.getPlatform()); 379 407 380 nodes = guiModel.getChildren(body); 408 381 assertNotNull(nodes); 409 410 // wait for all 10 GUI elements on the same page to be logged although only 9 are used411 382 assertEquals(10, nodes.size()); 412 383 413 Map<String, IGUIElement> inputs = new HashMap<>(); 414 415 // get input nodes 416 for (int i = 0; i < nodes.size(); i++) { 417 node = nodes.get(i); 418 assertNotNull(node); 419 assertTrue(node instanceof HTMLPageElement); 420 assertEquals("HTML", node.getPlatform()); 384 // get children node 385 Map<String, GenericEventTarget> inputs = new HashMap<>(); 386 387 for (GenericEventTarget candidate: nodes) { 388 assertNotNull(candidate); 389 assertTrue(candidate.getStringIdentifier().startsWith("input")); 390 assertEquals("Generic Event", candidate.getPlatform()); 421 391 422 if (!"input9".equals(((HTMLPageElement) node).getHtmlId())) { 423 assertTrue(node.isUsed()); 424 } 425 else { 426 assertFalse(node.isUsed()); 427 } 428 429 inputs.put(((HTMLPageElement) node).getHtmlId(), node); 430 431 assertNotNull(guiModel.getChildren(node)); 432 assertEquals(0, guiModel.getChildren(node).size()); 433 } 392 inputs.put(candidate.getStringIdentifier(), candidate); 393 394 assertNotNull(guiModel.getChildren(candidate)); 395 assertEquals(0, guiModel.getChildren(candidate).size()); 396 } 397 434 398 435 399 // check the sequences … … 447 411 assertEquals(10, sequence.size()); 448 412 449 assertEvent(sequence.get(0), 1, MouseClick.class, inputs.get("input1"), 194, 7);450 assertEvent(sequence.get(1), 2, MouseDoubleClick.class, inputs.get("input2"), 194, 7);451 assertEvent(sequence.get(2), 3, KeyboardFocusChange.class, inputs.get("input3"), 0, 0);452 assertEvent(sequence.get(3), 4, MouseClick.class, inputs.get("input4"), 125, 14);453 assertEvent(sequence.get(4), 5, KeyboardFocusChange.class, inputs.get("input5"), 0, 0);454 assertEvent(sequence.get(5), 6, KeyboardFocusChange.class, inputs.get("input6"), 0, 0);455 assertEvent(sequence.get(6), 7, KeyboardFocusChange.class, inputs.get("input7"), 0, 0);456 assertEvent(sequence.get(7), 8, MouseClick.class, inputs.get("input8"), 255, 4);457 assertEvent(sequence.get(8), 9, Scroll.class, body, 0, 0);458 assertEvent(sequence.get(9), 10, MouseClick.class, inputs.get("input10"), 516, 154);*/413 assertEvent(sequence.get(0), "onclick", inputs.get("input1")); 414 assertEvent(sequence.get(1), "ondblclick", inputs.get("input2")); 415 assertEvent(sequence.get(2), "onfocus", inputs.get("input3")); 416 assertEvent(sequence.get(3), "onclick", inputs.get("input4")); 417 assertEvent(sequence.get(4), "onfocus", inputs.get("input5")); 418 assertEvent(sequence.get(5), "onfocus", inputs.get("input6")); 419 assertEvent(sequence.get(6), "onfocus", inputs.get("input7")); 420 assertEvent(sequence.get(7), "onclick", inputs.get("input8")); 421 assertEvent(sequence.get(8), "onscroll", inputs.get("input9")); 422 assertEvent(sequence.get(9), "onclick", inputs.get("input10")); 459 423 460 424 } … … 466 430 public void testSeveralSessions() throws Exception { 467 431 String clientId = "123"; 432 String appId = "456"; 468 433 469 434 String message = … … 472 437 " \"clientInfos\": {" + 473 438 " \"clientId\":\"" + clientId + "\"," + 474 " \"userAgent\":\"Agent\"," + 475 " \"title\":\"Title\"," + 476 " \"url\":\"http://host/path\"" + 439 " \"appId\":\"" + appId + "\"," + 477 440 " }," + 478 " \"guiModel\": {" + 479 " \"tagName\":\"html\"," + 480 " \"index\":\"0\"," + 441 " \"targetStructure\": [{" + 442 " \"targetId\":\"target1\"," + 443 " \"param1\":\"value1\"," + 444 " \"param3\":\"value3\"," + 445 " \"param2\":\"value2\"," + 481 446 " \"children\":" + 482 447 " [ {" + 483 " \"ta gName\":\"head\"," +448 " \"targetId\":\"target3\"," + 484 449 " \"index\":\"0\"," + 485 450 " }," + 486 451 " {" + 487 " \"ta gName\":\"body\"," +452 " \"targetId\":\"target2\"," + 488 453 " \"htmlId\":\"gsr\"," + 489 454 " }" + 490 455 " ]" + 491 " } ," +456 " }]," + 492 457 " \"events\":" + 493 458 " [ {" + 494 459 " \"time\":\"12345\"," + 495 " \"path\":\"/html[0]/body(htmlId=gsr)\"," + 496 " \"type\":\"onclick\"" + 497 " \"coordinates\": [\"194\", \"7\"]" + 460 " \"targetId\":\"target2\"," + 461 " \"type\":\"gaze\"," + 462 " \"xcoordinate\": \"194\"," + 463 " \"ycoordinate\": \"12\"" + 498 464 " }" + 499 465 " ]" + … … 517 483 genericEventMonitor = null; 518 484 519 /*HTMLLogParser parser = new HTMLLogParser(null);485 GenericEventLogParser parser = new GenericEventLogParser(new HashSet<String>()); 520 486 521 487 // assert 9 already rotated log files 522 488 for (int i = 0; i < numberOfSessions; i++) { 523 File logFile = new File(LOG_FILE_DIR + File.separator + "host"+ File.separator +524 clientId + File.separator + " htmlmonitor_" + clientId + "_00" +489 File logFile = new File(LOG_FILE_DIR + File.separator + appId + File.separator + 490 clientId + File.separator + "genericevents_" + clientId + "_00" + 525 491 i + ".log"); 526 492 … … 531 497 532 498 // check the GUI model 533 GUIModel guiModel = parser.getGuiModel();499 HierarchicalEventTargetModel<GenericEventTarget> guiModel = parser.getHierarchicalEventTargetModel(); 534 500 assertNotNull(guiModel); 535 501 536 List< IGUIElement> nodes = guiModel.getRootElements();502 List<GenericEventTarget> nodes = guiModel.getRootElements(); 537 503 assertNotNull(nodes); 538 504 assertEquals(1, nodes.size()); 539 505 540 // get servernode541 IGUIElement node = nodes.get(0);506 // get root node 507 GenericEventTarget node = nodes.get(0); 542 508 assertNotNull(node); 543 assertTrue(node instanceof HTMLServer); 544 assertEquals("HTML", node.getPlatform()); 545 assertFalse(node.isUsed()); 509 assertEquals("target1", node.getStringIdentifier()); 510 assertEquals("Generic Event", node.getPlatform()); 546 511 547 512 nodes = guiModel.getChildren(node); 548 513 assertNotNull(nodes); 549 assertEquals( 1, nodes.size());550 551 // get documentnode514 assertEquals(2, nodes.size()); 515 516 // get children node 552 517 node = nodes.get(0); 553 518 assertNotNull(node); 554 assertTrue(node instanceof HTMLDocument); 555 assertEquals("HTML", node.getPlatform()); 556 assertFalse(node.isUsed()); 557 558 nodes = guiModel.getChildren(node); 559 assertNotNull(nodes); 560 assertEquals(1, nodes.size()); 561 562 // get html node 563 node = nodes.get(0); 519 assertTrue("target2".equals(node.getStringIdentifier()) || "target3".equals(node.getStringIdentifier())); 520 assertEquals("Generic Event", node.getPlatform()); 521 522 node = nodes.get(1); 564 523 assertNotNull(node); 565 assertTrue(node instanceof HTMLPageElement); 566 assertEquals("HTML", node.getPlatform()); 567 assertFalse(node.isUsed()); 568 569 nodes = guiModel.getChildren(node); 570 assertNotNull(nodes); 571 assertEquals(1, nodes.size()); // only one child as the head tag should have been ignored 572 573 // get body node 574 node = nodes.get(0); 575 assertNotNull(node); 576 assertTrue(node instanceof HTMLPageElement); 577 assertEquals("HTML", node.getPlatform()); 578 assertTrue(node.isUsed()); 579 580 nodes = guiModel.getChildren(node); 581 assertNotNull(nodes); 582 assertEquals(0, nodes.size()); 524 assertTrue("target2".equals(node.getStringIdentifier()) || "target3".equals(node.getStringIdentifier())); 525 assertEquals("Generic Event", node.getPlatform()); 526 583 527 584 528 // check the sequences … … 590 534 Iterator<List<Event>> iterator = sequences.iterator(); 591 535 536 IEventTarget target = null; 537 for (IEventTarget candidate : nodes) { 538 if ("target2".equals(candidate.getStringIdentifier())) { 539 target = candidate; 540 break; 541 } 542 } 543 592 544 while (iterator.hasNext()) { 593 545 List<Event> sequence = iterator.next(); … … 595 547 assertNotNull(sequence); 596 548 assertEquals(1, sequence.size()); 549 550 assertEvent(sequence.get(0), "gaze", target); 551 } 552 553 } 554 555 /** 556 * 557 */ 558 @Test 559 public void testManyRequestsInOneSession() throws Exception { 560 int noOfMessages = 100; 561 int noOfEventsPerMessage = 1000; 562 String clientId = "123"; 563 String appId = "456"; 597 564 598 assertEvent(sequence.get(0), 12345, MouseClick.class, node, 194, 7); 599 }*/ 565 List<String> messages = new ArrayList<>(); 566 567 int eventId = 0; 568 569 for (int i = 0; i < noOfMessages; i++) { 570 StringBuffer message = new StringBuffer( 571 "{" + 572 " \"message\": {" + 573 " \"clientInfos\": {" + 574 " \"clientId\":\"" + clientId + "\"," + 575 " \"appId\":\"" + appId + "\"," + 576 " }," + 577 " \"targetStructure\": [{" + 578 " \"targetId\":\"target1\"," + 579 " \"children\":" + 580 " [ {" + 581 " \"targetId\":\"target2\"," + 582 " }" + 583 " ]" + 584 " }]," + 585 " \"events\":" + 586 " ["); 587 588 for (int j = 0; j < noOfEventsPerMessage; j++) { 589 message.append( 590 " {" + 591 " \"time\":\"" + eventId++ + "\"," + 592 " \"targetId\":\"target2\"," + 593 " \"type\":\"gaze\"," + 594 " },"); 595 } 596 597 message.append( 598 " ]" + 599 " }" + 600 "}"); 601 602 messages.add(message.toString()); 603 } 604 605 List<Thread> threads = new ArrayList<>(); 606 607 for (String message : messages) { 608 threads.add(sendMessage(message)); 609 } 610 611 for (Thread thread : threads) { 612 thread.join(); 613 } 614 615 genericEventMonitor.stop(); 616 genericEventMonitor = null; 617 618 GenericEventLogParser parser = new GenericEventLogParser(new HashSet<String>()); 619 620 File logFile = new File(LOG_FILE_DIR + File.separator + appId + File.separator + 621 clientId + File.separator + "genericevents_" + clientId + "_000.log"); 622 623 assertTrue(logFile.exists()); 624 625 parser.parseFile(logFile); 626 627 // check the GUI model 628 HierarchicalEventTargetModel<GenericEventTarget> guiModel = parser.getHierarchicalEventTargetModel(); 629 assertNotNull(guiModel); 630 631 List<GenericEventTarget> nodes = guiModel.getRootElements(); 632 assertNotNull(nodes); 633 assertEquals(1, nodes.size()); 634 635 // get root node 636 GenericEventTarget node = nodes.get(0); 637 assertNotNull(node); 638 assertEquals("target1", node.getStringIdentifier()); 639 assertEquals("Generic Event", node.getPlatform()); 640 641 nodes = guiModel.getChildren(node); 642 assertNotNull(nodes); 643 assertEquals(1, nodes.size()); 644 645 // get children node 646 GenericEventTarget target = nodes.get(0); 647 assertNotNull(target); 648 assertEquals("target2", target.getStringIdentifier()); 649 assertEquals("Generic Event", target.getPlatform()); 650 651 652 // check the sequences 653 Collection<List<Event>> sequences = parser.getSequences(); 654 655 assertNotNull(sequences); 656 assertEquals(1, sequences.size()); 657 658 Iterator<List<Event>> iterator = sequences.iterator(); 659 660 while (iterator.hasNext()) { 661 List<Event> sequence = iterator.next(); 662 663 assertNotNull(sequence); 664 assertEquals(noOfMessages * noOfEventsPerMessage, sequence.size()); 665 666 for (Event event : sequence) { 667 assertEvent(event, "gaze", target); 668 } 669 } 670 600 671 } 601 672 … … 605 676 private void sendMessageAndAssertResponse(String message) throws Exception { 606 677 DefaultHttpClient httpclient = new DefaultHttpClient(); 678 //HttpPost httpPost = new HttpPost("https://swe-tooling.informatik.uni-goettingen.de/autoquest-genericmonitor/"); 607 679 HttpPost httpPost = new HttpPost("http://localhost:" + PORT + "/"); 608 680 HttpEntity entity = new StringEntity(message, ContentType.APPLICATION_JSON); … … 629 701 * 630 702 */ 631 /*private void assertEvent(Event event, 632 int timestamp, 633 Class<? extends IEventType> eventType, 634 IGUIElement eventTarget, 635 int xCoordinate, 636 int yCoordinate) 637 { 638 assertEquals(timestamp, event.getTimestamp()); 639 assertTrue(eventType.isInstance(event.getType())); 640 assertEquals(eventTarget, event.getTarget()); 641 642 if (event.getType() instanceof MouseButtonInteraction) { 643 assertEquals(xCoordinate, ((MouseButtonInteraction) event.getType()).getX()); 644 assertEquals(yCoordinate, ((MouseButtonInteraction) event.getType()).getY()); 645 } 703 private Thread sendMessage(final String message) throws Exception { 704 Thread thread = new Thread(new Runnable() { 705 @Override 706 public void run() { 707 try { 708 System.out.println("sending data"); 709 sendMessageAndAssertResponse(message); 710 System.out.println("data send"); 711 } 712 catch (Exception e) { 713 e.printStackTrace(); 714 } 715 } 716 }); 717 718 thread.start(); 719 720 return thread; 721 } 722 723 724 /** 725 * 726 */ 727 private void assertEvent(Event event, String name, IEventTarget target) { 728 assertEquals(StringEventType.class, event.getType().getClass()); 729 assertEquals(name, ((StringEventType) event.getType()).toString()); 730 assertEquals(target, event.getTarget()); 646 731 } 647 732
Note: See TracChangeset
for help on using the changeset viewer.