Index: trunk/autoquest-htmlmonitor-test/src/test/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorServerTest.java
===================================================================
--- trunk/autoquest-htmlmonitor-test/src/test/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorServerTest.java	(revision 943)
+++ trunk/autoquest-htmlmonitor-test/src/test/java/de/ugoe/cs/autoquest/htmlmonitor/HtmlMonitorServerTest.java	(revision 1069)
@@ -56,4 +56,9 @@
      * 
      */
+    private HtmlGUIElement guiStructure;
+
+    /**
+     * 
+     */
     private String eventHandlingError;
 
@@ -97,18 +102,35 @@
     @Test
     public void testSimpleMessage() throws Exception {
+        String clientId = "123";
+        
         String message =
             "{" +
             "  \"message\": {" +
             "    \"clientInfos\": {" +
-            "      \"clientId\":\"123\"," +
+            "      \"clientId\":\"" + clientId + "\"," +
             "      \"userAgent\":\"Agent\"," +
             "      \"title\":\"Title\"," +
             "      \"url\":\"http://host/path\"" +
             "    }," +
+            "    \"guiModel\": {" +
+            "      \"tagName\":\"html\"," +
+            "      \"index\":\"0\"," +
+            "      \"children\":" +
+            "      [ {" +
+            "          \"tagName\":\"head\"," +
+            "          \"index\":\"0\"," +
+            "        }," +
+            "        {" +
+            "          \"tagName\":\"body\"," +
+            "          \"htmlId\":\"gsr\"," +
+            "        }" +
+            "      ]" +
+            "    }," +
             "    \"events\":" +
             "    [ {" +
             "        \"time\":\"12345\"," +
-            "        \"path\":\"/html[0]/body(id=gsr)\"," +
-            "        \"eventType\":\"onunload\"" +
+            "        \"path\":\"/html[0]/body(htmlId=gsr)\"," +
+            "        \"eventType\":\"onclick\"" +
+            "        \"coordinates\": [\"194\", \"7\"]" +
             "      }" +
             "    ]" +
@@ -122,19 +144,34 @@
         }
         
+        // check the GUI structure
+        HtmlGUIElement parent = null;
+        HtmlGUIElement element = guiStructure;
+        
+        assertGuiElement(element, HtmlServer.class, parent, 1);
+        
+        parent = element;
+        element = parent.getChildren().get(0);
+        assertGuiElement(element, HtmlDocument.class, parent, 1);
+        
+        HtmlDocument document = (HtmlDocument) element;
+        
+        parent = element;
+        element = parent.getChildren().get(0);
+        assertGuiElement(element, HtmlPageElement.class, parent, 2);
+
+        parent = element;
+        element = parent.getChildren().get(0);
+        assertGuiElement(element, HtmlPageElement.class, parent, 0);
+        element = parent.getChildren().get(1);
+        assertGuiElement(element, HtmlPageElement.class, parent, 0);
+
+        // check the event
         assertNotNull(events);
         assertEquals(1, events.length);
         
-        assertEquals(new Long(12345), events[0].getTime());
-        assertEquals("/html[0]/body(id=gsr)", events[0].getPath());
-        assertEquals("onunload", events[0].getEventType());
-        
-        assertNull(events[0].getKey());
-        assertNull(events[0].getScrollPosition());
-        assertNull(events[0].getCoordinates());
-        
-        assertEquals("Title", events[0].getClientInfos().getTitle());
-        assertEquals("Agent", events[0].getClientInfos().getUserAgent());
-        assertEquals("http://host/path", events[0].getClientInfos().getUrl().toString());
-        assertEquals("123", events[0].getClientInfos().getClientId());
+        assertEvent(0, 12345, "/html[0]/body(htmlId=gsr)", element, document, "onclick",
+                    null, null, new Integer[] {194, 7},
+                    "Title", "Agent", "http://host/path", "123");
+        
     }
 
@@ -144,18 +181,75 @@
     @Test
     public void testComplexMessage() throws Exception {
+        String clientId = "123";
+        
         String message =
             "{" +
             "  \"message\": {" +
             "    \"clientInfos\": {" +
-            "      \"clientId\":\"123\"," +
+            "      \"clientId\":\"" + clientId + "\"," +
             "      \"userAgent\":\"Agent\"," +
             "      \"title\":\"Title\"," +
             "      \"url\":\"http://host/path\"" +
             "    }," +
+            "    \"guiModel\": {" +
+            "      \"tagName\":\"html\"," +
+            "      \"index\":\"0\"," +
+            "      \"children\":" +
+            "      [ {" +
+            "          \"tagName\":\"head\"," +
+            "          \"index\":\"0\"," +
+            "        }," +
+            "        {" +
+            "          \"tagName\":\"body\"," +
+            "          \"htmlId\":\"gsr\"," +
+            "          \"children\":" +
+            "          [ {" +
+            "              \"tagName\":\"input_button\"," +
+            "              \"htmlId\":\"input1\"," +
+            "            }," +
+            "            {" +
+            "              \"tagName\":\"input_button\"," +
+            "              \"htmlId\":\"input2\"," +
+            "            }," +
+            "            {" +
+            "              \"tagName\":\"input_button\"," +
+            "              \"htmlId\":\"input3\"," +
+            "            }," +
+            "            {" +
+            "              \"tagName\":\"input_button\"," +
+            "              \"htmlId\":\"input4\"," +
+            "            }," +
+            "            {" +
+            "              \"tagName\":\"input_button\"," +
+            "              \"htmlId\":\"input5\"," +
+            "            }," +
+            "            {" +
+            "              \"tagName\":\"input_button\"," +
+            "              \"htmlId\":\"input6\"," +
+            "            }," +
+            "            {" +
+            "              \"tagName\":\"input_button\"," +
+            "              \"htmlId\":\"input7\"," +
+            "            }," +
+            "            {" +
+            "              \"tagName\":\"input_button\"," +
+            "              \"htmlId\":\"input8\"," +
+            "            }," +
+            "            {" +
+            "              \"tagName\":\"input_button\"," +
+            "              \"htmlId\":\"input9\"," +
+            "            }," +
+            "            {" +
+            "              \"tagName\":\"input_button\"," +
+            "              \"htmlId\":\"input10\"," +
+            "            }," +
+            "          ]" +
+            "        }" +
+            "      ]" +
+            "    }," +
             "    \"events\":" +
-            "    [" +
-            "      {" +
+            "    [ {" +
             "        \"time\":\"1\"," +
-            "        \"path\":\"/html[0]/body(id=gsr)/input(id=input1)\"," +
+            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input1)\"," +
             "        \"eventType\":\"onclick\"," +
             "        \"coordinates\": [\"194\", \"7\"]" +
@@ -163,5 +257,5 @@
             "      {" +
             "        \"time\":\"2\"," +
-            "        \"path\":\"/html[0]/body(id=gsr)/input(id=input2)\"," +
+            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input2)\"," +
             "        \"eventType\":\"ondblclick\"," +
             "        \"coordinates\": [\"194\", \"7\"]" +
@@ -169,10 +263,10 @@
             "      {" +
             "        \"time\":\"3\"," +
-            "        \"path\":\"/html[0]/body(id=gsr)/input(id=input3)\"," +
+            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input3)\"," +
             "        \"eventType\":\"onfocus\"" +
             "      }," +
             "      {" +
             "        \"time\":\"4\"," +
-            "        \"path\":\"/html[0]/body(id=gsr)/input(id=input4)\"," +
+            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input4)\"," +
             "        \"eventType\":\"onclick\"," +
             "        \"coordinates\": [\"125\", \"14\"]" +
@@ -180,20 +274,20 @@
             "      {" +
             "        \"time\":\"5\"," +
-            "        \"path\":\"/html[0]/body(id=gsr)/input(id=input5)\"," +
+            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input5)\"," +
             "        \"eventType\":\"onfocus\"" +
             "      }," +
             "      {" +
             "        \"time\":\"6\"," +
-            "        \"path\":\"/html[0]/body(id=gsr)/input(id=input6)\"," +
+            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input6)\"," +
             "        \"eventType\":\"onfocus\"" +
             "      }," +
             "      {" +
             "        \"time\":\"7\"," +
-            "        \"path\":\"/html[0]/body(id=gsr)/input(id=input7)\"," +
+            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input7)\"," +
             "        \"eventType\":\"onfocus\"" +
             "      }," +
             "      {" +
             "        \"time\":\"8\"," +
-            "        \"path\":\"/html[0]/body(id=gsr)/input(id=input8)\"," +
+            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input8)\"," +
             "        \"eventType\":\"onclick\"," +
             "        \"coordinates\": [\"255\", \"4\"]" +
@@ -201,5 +295,5 @@
             "      {" +
             "        \"time\":\"9\"," +
-            "        \"path\":\"/html[0]/body(id=gsr)\"," +
+            "        \"path\":\"/html[0]/body(htmlId=gsr)\"," +
             "        \"eventType\":\"onscroll\"," +
             "        \"scrollPosition\": [\"23\", \"567\"]" +
@@ -207,5 +301,5 @@
             "      {" +
             "        \"time\":\"10\"," +
-            "        \"path\":\"/html[0]/body(id=gsr)/input(id=input10)\"," +
+            "        \"path\":\"/html[0]/body(htmlId=gsr)/input_button(htmlId=input10)\"," +
             "        \"eventType\":\"onclick\"," +
             "        \"coordinates\": [\"516\", \"154\"]" +
@@ -214,5 +308,5 @@
             "  }" +
             "}";
-        
+ 
         sendMessageAndAssertResponse(message);
         
@@ -221,55 +315,85 @@
         }
         
+        // check the GUI structure
+        HtmlGUIElement parent = null;
+        HtmlGUIElement element = guiStructure;
+        
+        assertGuiElement(element, HtmlServer.class, parent, 1);
+        
+        parent = element;
+        element = parent.getChildren().get(0);
+        assertGuiElement(element, HtmlDocument.class, parent, 1);
+        
+        HtmlDocument document = (HtmlDocument) element;
+        
+        parent = element;
+        element = parent.getChildren().get(0);
+        assertGuiElement(element, HtmlPageElement.class, parent, 2);
+
+        parent = element;
+        element = parent.getChildren().get(0);
+        assertGuiElement(element, HtmlPageElement.class, parent, 0);
+        element = parent.getChildren().get(1);
+        assertGuiElement(element, HtmlPageElement.class, parent, 10);
+        
+        parent = element;
+        for (HtmlGUIElement child : parent.getChildren()) {
+            assertGuiElement(child, HtmlPageElement.class, parent, 0);
+        }
+
+        // check the events
         assertNotNull(events);
         assertEquals(10, events.length);
 
         for (int i = 0; i < events.length; i++) {
-            assertEquals("event " + i, new Long(i + 1), events[i].getTime());
+            String targetDOMPath;
+            HtmlGUIElement target;
+            Integer[] scrollPosition = null;
             
             if (i == 8) {
-                assertEquals("event " + i, "/html[0]/body(id=gsr)", events[i].getPath());
+                targetDOMPath = "/html[0]/body(htmlId=gsr)";
+                target = parent;
+                scrollPosition = new Integer[] { 23, 567 };
             }
             else {
-                assertEquals("event " + i, "/html[0]/body(id=gsr)/input(id=input" + (i + 1) + ")",
-                             events[i].getPath());
-            }
-            
+                targetDOMPath =
+                    "/html[0]/body(htmlId=gsr)/input_button(htmlId=input" + (i + 1) + ")";
+                target = parent.getChildren().get(i);
+            }
+            
+            String eventType;
             if ((i == 1)) {
-                assertEquals("event " + i, "ondblclick", events[i].getEventType());
+                eventType = "ondblclick";
             }
             else if ((i == 2) || ((4 <= i) && (i <= 6))) {
-                assertEquals("event " + i, "onfocus", events[i].getEventType());
+                eventType = "onfocus";
             }
             else if ((i == 8)) {
-                assertEquals("event " + i, "onscroll", events[i].getEventType());
+                eventType = "onscroll";
             }
             else {
-                assertEquals("event " + i, "onclick", events[i].getEventType());
+                eventType = "onclick";
             }
             
             assertNull("event " + i, events[i].getKey());
             
-            if ((i == 8)) {
-                assertNotNull("event " + i, events[i].getScrollPosition());
-                assertArrayEquals
-                    ("event " + i, new Integer[] { 23, 567 }, events[i].getScrollPosition());
-            }
-            else {
-                assertNull("event " + i, events[i].getScrollPosition());
-            }
-            
-            if ((i == 2) || ((4 <= i) && (i <= 6)) || (i == 8)) {
-                assertNull("event " + i, events[i].getCoordinates());
-            }
-            else {
-                assertNotNull("event " + i, events[i].getCoordinates());
-                assertEquals("event " + i, 2, events[i].getCoordinates().length);
-            }
-            
-            assertEquals("event " + i, "Title", events[i].getClientInfos().getTitle());
-            assertEquals("event " + i, "Agent", events[i].getClientInfos().getUserAgent());
-            assertEquals("event " + i, "http://host/path",
-                         events[i].getClientInfos().getUrl().toString());
-            assertEquals("event " + i, "123", events[i].getClientInfos().getClientId());
+            Integer[] coordinates = null;
+            if (i <= 1) {
+                coordinates = new Integer[] { 194, 7 };
+            }
+            else if (i == 3) {
+                coordinates = new Integer[] { 125, 14 };
+            }
+            else if (i == 7) {
+                coordinates = new Integer[] { 255, 4 };
+            }
+            else if (i == 9) {
+                coordinates = new Integer[] { 516, 154 };
+            }
+            
+            assertEvent(i, i + 1, targetDOMPath, target, document, eventType,
+                        null, scrollPosition, coordinates,
+                        "Title", "Agent", "http://host/path", "123");
+            
         }
     }
@@ -310,9 +434,23 @@
             "      \"url\":\"http://host/path\"" +
             "    }," +
+            "    \"guiModel\": {" +
+            "      \"tagName\":\"html\"," +
+            "      \"index\":\"0\"," +
+            "      \"children\":" +
+            "      [ {" +
+            "          \"tagName\":\"head\"," +
+            "          \"index\":\"0\"," +
+            "        }," +
+            "        {" +
+            "          \"tagName\":\"body\"," +
+            "          \"htmlId\":\"gsr\"," +
+            "        }" +
+            "      ]" +
+            "    }," +
             "    \"events\":" +
             "    [ {" +
-            "        \"time\":\"12345\"," +
-            "        \"path\":\"/html[0]/body(id=gsr)\"," +
-            "        \"eventType\":\"onscroll\"" +
+            "        \"time\":\"9\"," +
+            "        \"path\":\"/html[0]/body(htmlId=gsr)\"," +
+            "        \"eventType\":\"onscroll\"," +
             "      }" +
             "    ]" +
@@ -337,8 +475,22 @@
             "      \"url\":\"http://host/path\"" +
             "    }," +
+            "    \"guiModel\": {" +
+            "      \"tagName\":\"html\"," +
+            "      \"index\":\"0\"," +
+            "      \"children\":" +
+            "      [ {" +
+            "          \"tagName\":\"head\"," +
+            "          \"index\":\"0\"," +
+            "        }," +
+            "        {" +
+            "          \"tagName\":\"body\"," +
+            "          \"htmlId\":\"gsr\"," +
+            "        }" +
+            "      ]" +
+            "    }," +
             "    \"events\":" +
             "    [ {" +
             "        \"time\":\"12345\"," +
-            "        \"path\":\"/html[0]/body(id=gsr)\"," +
+            "        \"path\":\"/html[0]/body(htmlId=gsr)\"," +
             "        \"eventType\":\"onunload\"" +
             "      }" +
@@ -365,8 +517,22 @@
             "      \"url\":\"http://host/path\"" +
             "    }," +
+            "    \"guiModel\": {" +
+            "      \"tagName\":\"html\"," +
+            "      \"index\":\"0\"," +
+            "      \"children\":" +
+            "      [ {" +
+            "          \"tagName\":\"head\"," +
+            "          \"index\":\"0\"," +
+            "        }," +
+            "        {" +
+            "          \"tagName\":\"body\"," +
+            "          \"htmlId\":\"gsr\"," +
+            "        }" +
+            "      ]" +
+            "    }," +
             "    \"events\":" +
             "    [ {" +
             "        \"time\":\"blub\"," +
-            "        \"path\":\"/html[0]/body(id=gsr)\"," +
+            "        \"path\":\"/html[0]/body(htmlId=gsr)\"," +
             "        \"eventType\":\"onunload\"" +
             "      }" +
@@ -389,7 +555,13 @@
      */
     @Override
-    public void handleMessage(HtmlClientInfos clientInfos, HtmlEvent[] events) {
+    public void handleMessage(HtmlClientInfos clientInfos,
+                              HtmlGUIElement  guiStructure,
+                              HtmlEvent[]     events)
+    {
         if (clientInfos == null) {
             eventHandlingError = "client infos were null";
+        }
+        else if (guiStructure == null) {
+            eventHandlingError = "gui structure was null";
         }
         else if (events == null) {
@@ -404,4 +576,5 @@
             
             this.events = events;
+            this.guiStructure = guiStructure;
         }
     }
@@ -435,3 +608,68 @@
     }
 
+    /**
+     *
+     */
+    private void assertGuiElement(HtmlGUIElement                  element,
+                                  Class<? extends HtmlGUIElement> type,
+                                  HtmlGUIElement                  parent,
+                                  int                             noOfChildren)
+    {
+        assertTrue(type.isInstance(element));
+        
+        if (parent != null) {
+            assertEquals(parent.getId(), element.getParentId());
+        }
+        else {
+            assertNull(element.getParentId());
+        }
+        
+        assertNotNull(element.getId());
+        
+        if (noOfChildren > 0) {
+            assertNotNull(element.getChildren());
+            assertEquals(noOfChildren, element.getChildren().size());
+        }
+        else {
+            assertNull(element.getChildren());
+        }
+    }
+
+    /**
+     *
+     */
+    private void assertEvent(int            index,
+                             long           timestamp,
+                             String         targetDOMPath,
+                             HtmlGUIElement target,
+                             HtmlDocument   document,
+                             String         eventType,
+                             Integer        key,
+                             Integer[]      scrollPosition,
+                             Integer[]      coordinates,
+                             String         clientInfoTitle,
+                             String         clientInfoAgent,
+                             String         clientInfoURL,
+                             String         clientId)
+    {
+        assertEquals("event " + index, new Long(timestamp), events[index].getTime());
+        assertEquals("event " + index, targetDOMPath, events[index].getTargetDOMPath());
+        assertEquals("event " + index, target, events[index].getTarget());
+        assertEquals("event " + index, document, events[index].getTargetDocument());
+        assertEquals("event " + index, eventType, events[index].getEventType());
+        
+        assertEquals("event " + index, key, events[index].getKey());
+        assertArrayEquals("event " + index, scrollPosition, events[index].getScrollPosition());
+        assertArrayEquals("event " + index, coordinates, events[index].getCoordinates());
+        
+        assertEquals
+            ("event " + index, clientInfoTitle, events[index].getClientInfos().getTitle());
+        assertEquals
+            ("event " + index, clientInfoAgent, events[index].getClientInfos().getUserAgent());
+        assertEquals
+            ("event " + index, clientInfoURL, events[index].getClientInfos().getUrl().toString());
+        assertEquals
+            ("event " + index, clientId, events[index].getClientInfos().getClientId());
+    }
+
 }
