Changeset 1069 for trunk/autoquest-htmlmonitor-test/src/test/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorServerTest.java
- Timestamp:
- 02/14/13 15:20:07 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-htmlmonitor-test/src/test/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorServerTest.java
r943 r1069 56 56 * 57 57 */ 58 private HtmlGUIElement guiStructure; 59 60 /** 61 * 62 */ 58 63 private String eventHandlingError; 59 64 … … 97 102 @Test 98 103 public void testSimpleMessage() throws Exception { 104 String clientId = "123"; 105 99 106 String message = 100 107 "{" + 101 108 " \"message\": {" + 102 109 " \"clientInfos\": {" + 103 " \"clientId\":\" 123\"," +110 " \"clientId\":\"" + clientId + "\"," + 104 111 " \"userAgent\":\"Agent\"," + 105 112 " \"title\":\"Title\"," + 106 113 " \"url\":\"http://host/path\"" + 107 114 " }," + 115 " \"guiModel\": {" + 116 " \"tagName\":\"html\"," + 117 " \"index\":\"0\"," + 118 " \"children\":" + 119 " [ {" + 120 " \"tagName\":\"head\"," + 121 " \"index\":\"0\"," + 122 " }," + 123 " {" + 124 " \"tagName\":\"body\"," + 125 " \"htmlId\":\"gsr\"," + 126 " }" + 127 " ]" + 128 " }," + 108 129 " \"events\":" + 109 130 " [ {" + 110 131 " \"time\":\"12345\"," + 111 " \"path\":\"/html[0]/body(id=gsr)\"," + 112 " \"eventType\":\"onunload\"" + 132 " \"path\":\"/html[0]/body(htmlId=gsr)\"," + 133 " \"eventType\":\"onclick\"" + 134 " \"coordinates\": [\"194\", \"7\"]" + 113 135 " }" + 114 136 " ]" + … … 122 144 } 123 145 146 // check the GUI structure 147 HtmlGUIElement parent = null; 148 HtmlGUIElement element = guiStructure; 149 150 assertGuiElement(element, HtmlServer.class, parent, 1); 151 152 parent = element; 153 element = parent.getChildren().get(0); 154 assertGuiElement(element, HtmlDocument.class, parent, 1); 155 156 HtmlDocument document = (HtmlDocument) element; 157 158 parent = element; 159 element = parent.getChildren().get(0); 160 assertGuiElement(element, HtmlPageElement.class, parent, 2); 161 162 parent = element; 163 element = parent.getChildren().get(0); 164 assertGuiElement(element, HtmlPageElement.class, parent, 0); 165 element = parent.getChildren().get(1); 166 assertGuiElement(element, HtmlPageElement.class, parent, 0); 167 168 // check the event 124 169 assertNotNull(events); 125 170 assertEquals(1, events.length); 126 171 127 assertEquals(new Long(12345), events[0].getTime()); 128 assertEquals("/html[0]/body(id=gsr)", events[0].getPath()); 129 assertEquals("onunload", events[0].getEventType()); 130 131 assertNull(events[0].getKey()); 132 assertNull(events[0].getScrollPosition()); 133 assertNull(events[0].getCoordinates()); 134 135 assertEquals("Title", events[0].getClientInfos().getTitle()); 136 assertEquals("Agent", events[0].getClientInfos().getUserAgent()); 137 assertEquals("http://host/path", events[0].getClientInfos().getUrl().toString()); 138 assertEquals("123", events[0].getClientInfos().getClientId()); 172 assertEvent(0, 12345, "/html[0]/body(htmlId=gsr)", element, document, "onclick", 173 null, null, new Integer[] {194, 7}, 174 "Title", "Agent", "http://host/path", "123"); 175 139 176 } 140 177 … … 144 181 @Test 145 182 public void testComplexMessage() throws Exception { 183 String clientId = "123"; 184 146 185 String message = 147 186 "{" + 148 187 " \"message\": {" + 149 188 " \"clientInfos\": {" + 150 " \"clientId\":\" 123\"," +189 " \"clientId\":\"" + clientId + "\"," + 151 190 " \"userAgent\":\"Agent\"," + 152 191 " \"title\":\"Title\"," + 153 192 " \"url\":\"http://host/path\"" + 154 193 " }," + 194 " \"guiModel\": {" + 195 " \"tagName\":\"html\"," + 196 " \"index\":\"0\"," + 197 " \"children\":" + 198 " [ {" + 199 " \"tagName\":\"head\"," + 200 " \"index\":\"0\"," + 201 " }," + 202 " {" + 203 " \"tagName\":\"body\"," + 204 " \"htmlId\":\"gsr\"," + 205 " \"children\":" + 206 " [ {" + 207 " \"tagName\":\"input_button\"," + 208 " \"htmlId\":\"input1\"," + 209 " }," + 210 " {" + 211 " \"tagName\":\"input_button\"," + 212 " \"htmlId\":\"input2\"," + 213 " }," + 214 " {" + 215 " \"tagName\":\"input_button\"," + 216 " \"htmlId\":\"input3\"," + 217 " }," + 218 " {" + 219 " \"tagName\":\"input_button\"," + 220 " \"htmlId\":\"input4\"," + 221 " }," + 222 " {" + 223 " \"tagName\":\"input_button\"," + 224 " \"htmlId\":\"input5\"," + 225 " }," + 226 " {" + 227 " \"tagName\":\"input_button\"," + 228 " \"htmlId\":\"input6\"," + 229 " }," + 230 " {" + 231 " \"tagName\":\"input_button\"," + 232 " \"htmlId\":\"input7\"," + 233 " }," + 234 " {" + 235 " \"tagName\":\"input_button\"," + 236 " \"htmlId\":\"input8\"," + 237 " }," + 238 " {" + 239 " \"tagName\":\"input_button\"," + 240 " \"htmlId\":\"input9\"," + 241 " }," + 242 " {" + 243 " \"tagName\":\"input_button\"," + 244 " \"htmlId\":\"input10\"," + 245 " }," + 246 " ]" + 247 " }" + 248 " ]" + 249 " }," + 155 250 " \"events\":" + 156 " [" + 157 " {" + 251 " [ {" + 158 252 " \"time\":\"1\"," + 159 " \"path\":\"/html[0]/body( id=gsr)/input(id=input1)\"," +253 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input1)\"," + 160 254 " \"eventType\":\"onclick\"," + 161 255 " \"coordinates\": [\"194\", \"7\"]" + … … 163 257 " {" + 164 258 " \"time\":\"2\"," + 165 " \"path\":\"/html[0]/body( id=gsr)/input(id=input2)\"," +259 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input2)\"," + 166 260 " \"eventType\":\"ondblclick\"," + 167 261 " \"coordinates\": [\"194\", \"7\"]" + … … 169 263 " {" + 170 264 " \"time\":\"3\"," + 171 " \"path\":\"/html[0]/body( id=gsr)/input(id=input3)\"," +265 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input3)\"," + 172 266 " \"eventType\":\"onfocus\"" + 173 267 " }," + 174 268 " {" + 175 269 " \"time\":\"4\"," + 176 " \"path\":\"/html[0]/body( id=gsr)/input(id=input4)\"," +270 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input4)\"," + 177 271 " \"eventType\":\"onclick\"," + 178 272 " \"coordinates\": [\"125\", \"14\"]" + … … 180 274 " {" + 181 275 " \"time\":\"5\"," + 182 " \"path\":\"/html[0]/body( id=gsr)/input(id=input5)\"," +276 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input5)\"," + 183 277 " \"eventType\":\"onfocus\"" + 184 278 " }," + 185 279 " {" + 186 280 " \"time\":\"6\"," + 187 " \"path\":\"/html[0]/body( id=gsr)/input(id=input6)\"," +281 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input6)\"," + 188 282 " \"eventType\":\"onfocus\"" + 189 283 " }," + 190 284 " {" + 191 285 " \"time\":\"7\"," + 192 " \"path\":\"/html[0]/body( id=gsr)/input(id=input7)\"," +286 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input7)\"," + 193 287 " \"eventType\":\"onfocus\"" + 194 288 " }," + 195 289 " {" + 196 290 " \"time\":\"8\"," + 197 " \"path\":\"/html[0]/body( id=gsr)/input(id=input8)\"," +291 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input8)\"," + 198 292 " \"eventType\":\"onclick\"," + 199 293 " \"coordinates\": [\"255\", \"4\"]" + … … 201 295 " {" + 202 296 " \"time\":\"9\"," + 203 " \"path\":\"/html[0]/body( id=gsr)\"," +297 " \"path\":\"/html[0]/body(htmlId=gsr)\"," + 204 298 " \"eventType\":\"onscroll\"," + 205 299 " \"scrollPosition\": [\"23\", \"567\"]" + … … 207 301 " {" + 208 302 " \"time\":\"10\"," + 209 " \"path\":\"/html[0]/body( id=gsr)/input(id=input10)\"," +303 " \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input10)\"," + 210 304 " \"eventType\":\"onclick\"," + 211 305 " \"coordinates\": [\"516\", \"154\"]" + … … 214 308 " }" + 215 309 "}"; 216 310 217 311 sendMessageAndAssertResponse(message); 218 312 … … 221 315 } 222 316 317 // check the GUI structure 318 HtmlGUIElement parent = null; 319 HtmlGUIElement element = guiStructure; 320 321 assertGuiElement(element, HtmlServer.class, parent, 1); 322 323 parent = element; 324 element = parent.getChildren().get(0); 325 assertGuiElement(element, HtmlDocument.class, parent, 1); 326 327 HtmlDocument document = (HtmlDocument) element; 328 329 parent = element; 330 element = parent.getChildren().get(0); 331 assertGuiElement(element, HtmlPageElement.class, parent, 2); 332 333 parent = element; 334 element = parent.getChildren().get(0); 335 assertGuiElement(element, HtmlPageElement.class, parent, 0); 336 element = parent.getChildren().get(1); 337 assertGuiElement(element, HtmlPageElement.class, parent, 10); 338 339 parent = element; 340 for (HtmlGUIElement child : parent.getChildren()) { 341 assertGuiElement(child, HtmlPageElement.class, parent, 0); 342 } 343 344 // check the events 223 345 assertNotNull(events); 224 346 assertEquals(10, events.length); 225 347 226 348 for (int i = 0; i < events.length; i++) { 227 assertEquals("event " + i, new Long(i + 1), events[i].getTime()); 349 String targetDOMPath; 350 HtmlGUIElement target; 351 Integer[] scrollPosition = null; 228 352 229 353 if (i == 8) { 230 assertEquals("event " + i, "/html[0]/body(id=gsr)", events[i].getPath()); 354 targetDOMPath = "/html[0]/body(htmlId=gsr)"; 355 target = parent; 356 scrollPosition = new Integer[] { 23, 567 }; 231 357 } 232 358 else { 233 assertEquals("event " + i, "/html[0]/body(id=gsr)/input(id=input" + (i + 1) + ")", 234 events[i].getPath()); 235 } 236 359 targetDOMPath = 360 "/html[0]/body(htmlId=gsr)/input_button(htmlId=input" + (i + 1) + ")"; 361 target = parent.getChildren().get(i); 362 } 363 364 String eventType; 237 365 if ((i == 1)) { 238 assertEquals("event " + i, "ondblclick", events[i].getEventType());366 eventType = "ondblclick"; 239 367 } 240 368 else if ((i == 2) || ((4 <= i) && (i <= 6))) { 241 assertEquals("event " + i, "onfocus", events[i].getEventType());369 eventType = "onfocus"; 242 370 } 243 371 else if ((i == 8)) { 244 assertEquals("event " + i, "onscroll", events[i].getEventType());372 eventType = "onscroll"; 245 373 } 246 374 else { 247 assertEquals("event " + i, "onclick", events[i].getEventType());375 eventType = "onclick"; 248 376 } 249 377 250 378 assertNull("event " + i, events[i].getKey()); 251 379 252 if ((i == 8)) { 253 assertNotNull("event " + i, events[i].getScrollPosition()); 254 assertArrayEquals 255 ("event " + i, new Integer[] { 23, 567 }, events[i].getScrollPosition()); 256 } 257 else { 258 assertNull("event " + i, events[i].getScrollPosition()); 259 } 260 261 if ((i == 2) || ((4 <= i) && (i <= 6)) || (i == 8)) { 262 assertNull("event " + i, events[i].getCoordinates()); 263 } 264 else { 265 assertNotNull("event " + i, events[i].getCoordinates()); 266 assertEquals("event " + i, 2, events[i].getCoordinates().length); 267 } 268 269 assertEquals("event " + i, "Title", events[i].getClientInfos().getTitle()); 270 assertEquals("event " + i, "Agent", events[i].getClientInfos().getUserAgent()); 271 assertEquals("event " + i, "http://host/path", 272 events[i].getClientInfos().getUrl().toString()); 273 assertEquals("event " + i, "123", events[i].getClientInfos().getClientId()); 380 Integer[] coordinates = null; 381 if (i <= 1) { 382 coordinates = new Integer[] { 194, 7 }; 383 } 384 else if (i == 3) { 385 coordinates = new Integer[] { 125, 14 }; 386 } 387 else if (i == 7) { 388 coordinates = new Integer[] { 255, 4 }; 389 } 390 else if (i == 9) { 391 coordinates = new Integer[] { 516, 154 }; 392 } 393 394 assertEvent(i, i + 1, targetDOMPath, target, document, eventType, 395 null, scrollPosition, coordinates, 396 "Title", "Agent", "http://host/path", "123"); 397 274 398 } 275 399 } … … 310 434 " \"url\":\"http://host/path\"" + 311 435 " }," + 436 " \"guiModel\": {" + 437 " \"tagName\":\"html\"," + 438 " \"index\":\"0\"," + 439 " \"children\":" + 440 " [ {" + 441 " \"tagName\":\"head\"," + 442 " \"index\":\"0\"," + 443 " }," + 444 " {" + 445 " \"tagName\":\"body\"," + 446 " \"htmlId\":\"gsr\"," + 447 " }" + 448 " ]" + 449 " }," + 312 450 " \"events\":" + 313 451 " [ {" + 314 " \"time\":\" 12345\"," +315 " \"path\":\"/html[0]/body( id=gsr)\"," +316 " \"eventType\":\"onscroll\" " +452 " \"time\":\"9\"," + 453 " \"path\":\"/html[0]/body(htmlId=gsr)\"," + 454 " \"eventType\":\"onscroll\"," + 317 455 " }" + 318 456 " ]" + … … 337 475 " \"url\":\"http://host/path\"" + 338 476 " }," + 477 " \"guiModel\": {" + 478 " \"tagName\":\"html\"," + 479 " \"index\":\"0\"," + 480 " \"children\":" + 481 " [ {" + 482 " \"tagName\":\"head\"," + 483 " \"index\":\"0\"," + 484 " }," + 485 " {" + 486 " \"tagName\":\"body\"," + 487 " \"htmlId\":\"gsr\"," + 488 " }" + 489 " ]" + 490 " }," + 339 491 " \"events\":" + 340 492 " [ {" + 341 493 " \"time\":\"12345\"," + 342 " \"path\":\"/html[0]/body( id=gsr)\"," +494 " \"path\":\"/html[0]/body(htmlId=gsr)\"," + 343 495 " \"eventType\":\"onunload\"" + 344 496 " }" + … … 365 517 " \"url\":\"http://host/path\"" + 366 518 " }," + 519 " \"guiModel\": {" + 520 " \"tagName\":\"html\"," + 521 " \"index\":\"0\"," + 522 " \"children\":" + 523 " [ {" + 524 " \"tagName\":\"head\"," + 525 " \"index\":\"0\"," + 526 " }," + 527 " {" + 528 " \"tagName\":\"body\"," + 529 " \"htmlId\":\"gsr\"," + 530 " }" + 531 " ]" + 532 " }," + 367 533 " \"events\":" + 368 534 " [ {" + 369 535 " \"time\":\"blub\"," + 370 " \"path\":\"/html[0]/body( id=gsr)\"," +536 " \"path\":\"/html[0]/body(htmlId=gsr)\"," + 371 537 " \"eventType\":\"onunload\"" + 372 538 " }" + … … 389 555 */ 390 556 @Override 391 public void handleMessage(HtmlClientInfos clientInfos, HtmlEvent[] events) { 557 public void handleMessage(HtmlClientInfos clientInfos, 558 HtmlGUIElement guiStructure, 559 HtmlEvent[] events) 560 { 392 561 if (clientInfos == null) { 393 562 eventHandlingError = "client infos were null"; 563 } 564 else if (guiStructure == null) { 565 eventHandlingError = "gui structure was null"; 394 566 } 395 567 else if (events == null) { … … 404 576 405 577 this.events = events; 578 this.guiStructure = guiStructure; 406 579 } 407 580 } … … 435 608 } 436 609 610 /** 611 * 612 */ 613 private void assertGuiElement(HtmlGUIElement element, 614 Class<? extends HtmlGUIElement> type, 615 HtmlGUIElement parent, 616 int noOfChildren) 617 { 618 assertTrue(type.isInstance(element)); 619 620 if (parent != null) { 621 assertEquals(parent.getId(), element.getParentId()); 622 } 623 else { 624 assertNull(element.getParentId()); 625 } 626 627 assertNotNull(element.getId()); 628 629 if (noOfChildren > 0) { 630 assertNotNull(element.getChildren()); 631 assertEquals(noOfChildren, element.getChildren().size()); 632 } 633 else { 634 assertNull(element.getChildren()); 635 } 636 } 637 638 /** 639 * 640 */ 641 private void assertEvent(int index, 642 long timestamp, 643 String targetDOMPath, 644 HtmlGUIElement target, 645 HtmlDocument document, 646 String eventType, 647 Integer key, 648 Integer[] scrollPosition, 649 Integer[] coordinates, 650 String clientInfoTitle, 651 String clientInfoAgent, 652 String clientInfoURL, 653 String clientId) 654 { 655 assertEquals("event " + index, new Long(timestamp), events[index].getTime()); 656 assertEquals("event " + index, targetDOMPath, events[index].getTargetDOMPath()); 657 assertEquals("event " + index, target, events[index].getTarget()); 658 assertEquals("event " + index, document, events[index].getTargetDocument()); 659 assertEquals("event " + index, eventType, events[index].getEventType()); 660 661 assertEquals("event " + index, key, events[index].getKey()); 662 assertArrayEquals("event " + index, scrollPosition, events[index].getScrollPosition()); 663 assertArrayEquals("event " + index, coordinates, events[index].getCoordinates()); 664 665 assertEquals 666 ("event " + index, clientInfoTitle, events[index].getClientInfos().getTitle()); 667 assertEquals 668 ("event " + index, clientInfoAgent, events[index].getClientInfos().getUserAgent()); 669 assertEquals 670 ("event " + index, clientInfoURL, events[index].getClientInfos().getUrl().toString()); 671 assertEquals 672 ("event " + index, clientId, events[index].getClientInfos().getClientId()); 673 } 674 437 675 }
Note: See TracChangeset
for help on using the changeset viewer.