Ignore:
Timestamp:
02/14/13 15:20:07 (11 years ago)
Author:
pharms
Message:
  • support of new HTML logging format
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-htmlmonitor-test/src/test/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorServerTest.java

    r943 r1069  
    5656     *  
    5757     */ 
     58    private HtmlGUIElement guiStructure; 
     59 
     60    /** 
     61     *  
     62     */ 
    5863    private String eventHandlingError; 
    5964 
     
    97102    @Test 
    98103    public void testSimpleMessage() throws Exception { 
     104        String clientId = "123"; 
     105         
    99106        String message = 
    100107            "{" + 
    101108            "  \"message\": {" + 
    102109            "    \"clientInfos\": {" + 
    103             "      \"clientId\":\"123\"," + 
     110            "      \"clientId\":\"" + clientId + "\"," + 
    104111            "      \"userAgent\":\"Agent\"," + 
    105112            "      \"title\":\"Title\"," + 
    106113            "      \"url\":\"http://host/path\"" + 
    107114            "    }," + 
     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            "    }," + 
    108129            "    \"events\":" + 
    109130            "    [ {" + 
    110131            "        \"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\"]" + 
    113135            "      }" + 
    114136            "    ]" + 
     
    122144        } 
    123145         
     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 
    124169        assertNotNull(events); 
    125170        assertEquals(1, events.length); 
    126171         
    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         
    139176    } 
    140177 
     
    144181    @Test 
    145182    public void testComplexMessage() throws Exception { 
     183        String clientId = "123"; 
     184         
    146185        String message = 
    147186            "{" + 
    148187            "  \"message\": {" + 
    149188            "    \"clientInfos\": {" + 
    150             "      \"clientId\":\"123\"," + 
     189            "      \"clientId\":\"" + clientId + "\"," + 
    151190            "      \"userAgent\":\"Agent\"," + 
    152191            "      \"title\":\"Title\"," + 
    153192            "      \"url\":\"http://host/path\"" + 
    154193            "    }," + 
     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            "    }," + 
    155250            "    \"events\":" + 
    156             "    [" + 
    157             "      {" + 
     251            "    [ {" + 
    158252            "        \"time\":\"1\"," + 
    159             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input1)\"," + 
     253            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input1)\"," + 
    160254            "        \"eventType\":\"onclick\"," + 
    161255            "        \"coordinates\": [\"194\", \"7\"]" + 
     
    163257            "      {" + 
    164258            "        \"time\":\"2\"," + 
    165             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input2)\"," + 
     259            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input2)\"," + 
    166260            "        \"eventType\":\"ondblclick\"," + 
    167261            "        \"coordinates\": [\"194\", \"7\"]" + 
     
    169263            "      {" + 
    170264            "        \"time\":\"3\"," + 
    171             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input3)\"," + 
     265            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input3)\"," + 
    172266            "        \"eventType\":\"onfocus\"" + 
    173267            "      }," + 
    174268            "      {" + 
    175269            "        \"time\":\"4\"," + 
    176             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input4)\"," + 
     270            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input4)\"," + 
    177271            "        \"eventType\":\"onclick\"," + 
    178272            "        \"coordinates\": [\"125\", \"14\"]" + 
     
    180274            "      {" + 
    181275            "        \"time\":\"5\"," + 
    182             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input5)\"," + 
     276            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input5)\"," + 
    183277            "        \"eventType\":\"onfocus\"" + 
    184278            "      }," + 
    185279            "      {" + 
    186280            "        \"time\":\"6\"," + 
    187             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input6)\"," + 
     281            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input6)\"," + 
    188282            "        \"eventType\":\"onfocus\"" + 
    189283            "      }," + 
    190284            "      {" + 
    191285            "        \"time\":\"7\"," + 
    192             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input7)\"," + 
     286            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input7)\"," + 
    193287            "        \"eventType\":\"onfocus\"" + 
    194288            "      }," + 
    195289            "      {" + 
    196290            "        \"time\":\"8\"," + 
    197             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input8)\"," + 
     291            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input8)\"," + 
    198292            "        \"eventType\":\"onclick\"," + 
    199293            "        \"coordinates\": [\"255\", \"4\"]" + 
     
    201295            "      {" + 
    202296            "        \"time\":\"9\"," + 
    203             "        \"path\":\"/html[0]/body(id=gsr)\"," + 
     297            "        \"path\":\"/html[0]/body(htmlId=gsr)\"," + 
    204298            "        \"eventType\":\"onscroll\"," + 
    205299            "        \"scrollPosition\": [\"23\", \"567\"]" + 
     
    207301            "      {" + 
    208302            "        \"time\":\"10\"," + 
    209             "        \"path\":\"/html[0]/body(id=gsr)/input(id=input10)\"," + 
     303            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input10)\"," + 
    210304            "        \"eventType\":\"onclick\"," + 
    211305            "        \"coordinates\": [\"516\", \"154\"]" + 
     
    214308            "  }" + 
    215309            "}"; 
    216          
     310  
    217311        sendMessageAndAssertResponse(message); 
    218312         
     
    221315        } 
    222316         
     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 
    223345        assertNotNull(events); 
    224346        assertEquals(10, events.length); 
    225347 
    226348        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; 
    228352             
    229353            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 }; 
    231357            } 
    232358            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; 
    237365            if ((i == 1)) { 
    238                 assertEquals("event " + i, "ondblclick", events[i].getEventType()); 
     366                eventType = "ondblclick"; 
    239367            } 
    240368            else if ((i == 2) || ((4 <= i) && (i <= 6))) { 
    241                 assertEquals("event " + i, "onfocus", events[i].getEventType()); 
     369                eventType = "onfocus"; 
    242370            } 
    243371            else if ((i == 8)) { 
    244                 assertEquals("event " + i, "onscroll", events[i].getEventType()); 
     372                eventType = "onscroll"; 
    245373            } 
    246374            else { 
    247                 assertEquals("event " + i, "onclick", events[i].getEventType()); 
     375                eventType = "onclick"; 
    248376            } 
    249377             
    250378            assertNull("event " + i, events[i].getKey()); 
    251379             
    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             
    274398        } 
    275399    } 
     
    310434            "      \"url\":\"http://host/path\"" + 
    311435            "    }," + 
     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            "    }," + 
    312450            "    \"events\":" + 
    313451            "    [ {" + 
    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\"," + 
    317455            "      }" + 
    318456            "    ]" + 
     
    337475            "      \"url\":\"http://host/path\"" + 
    338476            "    }," + 
     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            "    }," + 
    339491            "    \"events\":" + 
    340492            "    [ {" + 
    341493            "        \"time\":\"12345\"," + 
    342             "        \"path\":\"/html[0]/body(id=gsr)\"," + 
     494            "        \"path\":\"/html[0]/body(htmlId=gsr)\"," + 
    343495            "        \"eventType\":\"onunload\"" + 
    344496            "      }" + 
     
    365517            "      \"url\":\"http://host/path\"" + 
    366518            "    }," + 
     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            "    }," + 
    367533            "    \"events\":" + 
    368534            "    [ {" + 
    369535            "        \"time\":\"blub\"," + 
    370             "        \"path\":\"/html[0]/body(id=gsr)\"," + 
     536            "        \"path\":\"/html[0]/body(htmlId=gsr)\"," + 
    371537            "        \"eventType\":\"onunload\"" + 
    372538            "      }" + 
     
    389555     */ 
    390556    @Override 
    391     public void handleMessage(HtmlClientInfos clientInfos, HtmlEvent[] events) { 
     557    public void handleMessage(HtmlClientInfos clientInfos, 
     558                              HtmlGUIElement  guiStructure, 
     559                              HtmlEvent[]     events) 
     560    { 
    392561        if (clientInfos == null) { 
    393562            eventHandlingError = "client infos were null"; 
     563        } 
     564        else if (guiStructure == null) { 
     565            eventHandlingError = "gui structure was null"; 
    394566        } 
    395567        else if (events == null) { 
     
    404576             
    405577            this.events = events; 
     578            this.guiStructure = guiStructure; 
    406579        } 
    407580    } 
     
    435608    } 
    436609 
     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 
    437675} 
Note: See TracChangeset for help on using the changeset viewer.