Ignore:
Timestamp:
07/15/14 13:45:31 (10 years ago)
Author:
pharms
Message:
  • bugfix and test for correct query handling
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitoringProxyTest.java

    r1563 r1614  
    4848import de.ugoe.cs.autoquest.plugin.http.HTTPLogParser; 
    4949import de.ugoe.cs.autoquest.plugin.http.logdata.HttpExchange; 
    50 import de.ugoe.cs.autoquest.plugin.http.logdata.Method; 
    5150import dummyservice.DummyService; 
    5251import dummyservice.DummyServicePortType; 
     
    111110    } 
    112111     
     112    /** 
     113     * 
     114     */ 
    113115    @Test(expected=java.lang.IllegalArgumentException.class) 
    114116    public void test_InvalidInitialization_01() throws Exception { 
     
    116118    } 
    117119     
     120    /** 
     121     * 
     122     */ 
    118123    @Test 
    119124    public void test_SimpleText_Local() throws Exception { 
     
    127132        String message = "dummy message"; 
    128133        String expectedResponse = "response content"; 
    129         String response = sendDummyMessage("POST", message, expectedResponse); 
     134        String response = sendDummyMessage("POST", null, message, expectedResponse); 
    130135         
    131136        assertEquals(expectedResponse, response); 
     
    156161        assertEquals(1, sequence.size()); 
    157162 
    158         assertEvent(sequence.get(0), "POST", message, expectedResponse); 
    159     } 
    160  
     163        assertEvent(sequence.get(0), "POST", null, message, expectedResponse); 
     164    } 
     165     
     166    /** 
     167     * 
     168     */ 
    161169    @Test 
    162170    public void test_SimpleText_Remote() throws Exception { 
     
    170178        String message = "dummy message"; 
    171179        String expectedResponse = "response content"; 
    172         String response = sendDummyMessage("POST", message, expectedResponse); 
     180        String response = sendDummyMessage("POST", null, message, expectedResponse); 
    173181         
    174182        assertEquals(expectedResponse, response); 
     
    176184        // give the proxy some time to send the copy of the message 
    177185        while(messages.size() < 1) { 
     186            System.out.println("waiting for message to be send by the proxy"); 
    178187            Thread.sleep(1000); 
    179188        } 
     
    188197            (JAXBElement<HttpExchange>) unmarshaller.unmarshal(new StringReader(messages.get(0))); 
    189198         
    190         HttpExchange exchange = jaxObject.getValue(); 
    191          
    192         assertEquals(message, exchange.getRequest().getContent().getData()); 
    193         assertEquals(response, exchange.getResponse().getContent().getData()); 
    194     } 
    195      
     199        assertExchange(jaxObject.getValue(), "POST", null, message, expectedResponse); 
     200    } 
     201     
     202    /** 
     203     * 
     204     */ 
    196205    @Test 
    197206    public void test_XMLMessage_Local() throws Exception { 
     
    238247            "</httpEvent>"; 
    239248 
    240         String response = sendDummyMessage("POST", message, expectedResponse); 
     249        String response = sendDummyMessage("POST", null, message, expectedResponse); 
    241250         
    242251        assertEquals(expectedResponse, response); 
     
    267276        assertEquals(1, sequence.size()); 
    268277 
    269         assertEvent(sequence.get(0), "POST", message, expectedResponse); 
    270     } 
    271      
     278        assertEvent(sequence.get(0), "POST", null, message, expectedResponse); 
     279    } 
     280     
     281    /** 
     282     * 
     283     */ 
    272284    @Test 
    273285    public void test_XMLMessage_Remote() throws Exception { 
     
    314326            "</httpEvent>"; 
    315327 
    316         String response = sendDummyMessage("POST", message, expectedResponse); 
     328        String response = sendDummyMessage("POST", null, message, expectedResponse); 
    317329         
    318330        assertEquals(expectedResponse, response); 
     
    320332        // give the proxy some time to send the copy of the message 
    321333        while(messages.size() < 1) { 
     334            System.out.println("waiting for message to be send by the proxy"); 
    322335            Thread.sleep(1000); 
    323336        } 
     
    332345            (JAXBElement<HttpExchange>) unmarshaller.unmarshal(new StringReader(messages.get(0))); 
    333346         
    334         HttpExchange exchange = jaxObject.getValue(); 
    335          
    336         assertEquals(message, exchange.getRequest().getContent().getData()); 
    337         assertEquals(response, exchange.getResponse().getContent().getData()); 
    338     } 
    339      
     347        assertExchange(jaxObject.getValue(), "POST", null, message, expectedResponse); 
     348    } 
     349     
     350    /** 
     351     * 
     352     */ 
    340353    @Test 
    341354    public void test_SOAP_Local() throws Exception { 
     
    384397        assertEquals(2, sequence.size()); 
    385398 
    386         assertEvent(sequence.get(0), "GET", null, null); // get WSDL 
    387         assertEvent(sequence.get(1), "POST", null, null); // send request 
    388     } 
    389      
     399        assertEvent(sequence.get(0), "GET", "wsdl", null, null); // get WSDL 
     400        assertEvent(sequence.get(1), "POST", null, null, null); // send request 
     401    } 
     402     
     403    /** 
     404     * 
     405     */ 
    390406    @SuppressWarnings("unchecked") 
    391407    @Test 
     
    415431        // give the proxy some time to send the copy of the message 
    416432        while(messages.size() < 1) { 
     433            System.out.println("waiting for message to be send by the proxy"); 
    417434            Thread.sleep(1000); 
    418435        } 
     
    426443            (JAXBElement<HttpExchange>) unmarshaller.unmarshal(new StringReader(messages.get(0))); 
    427444         
    428         HttpExchange exchange = jaxObject.getValue(); 
    429          
    430         assertEquals(Method.GET, exchange.getRequest().getMethod()); 
    431  
    432         assertNull(exchange.getRequest().getContent()); 
    433         assertNotNull(exchange.getResponse().getContent().getData()); 
     445        assertExchange(jaxObject.getValue(), "GET", "wsdl", null, null); 
    434446 
    435447        jaxObject = 
    436448            (JAXBElement<HttpExchange>) unmarshaller.unmarshal(new StringReader(messages.get(1))); 
    437449             
    438         exchange = jaxObject.getValue(); 
    439              
    440         assertEquals(Method.POST, exchange.getRequest().getMethod()); 
    441  
    442         assertNotNull(exchange.getRequest().getContent().getData()); 
    443         assertNotNull(exchange.getResponse().getContent().getData()); 
    444     } 
    445      
     450        assertExchange(jaxObject.getValue(), "POST", null, null, null); 
     451    } 
     452     
     453    /** 
     454     * 
     455     */ 
    446456    @Test 
    447457    public void test_LargeRequest_Local() throws Exception { 
     
    461471        } 
    462472         
    463         String response = sendDummyMessage("POST", message.toString(), expectedResponse.toString()); 
     473        String response = 
     474            sendDummyMessage("POST", null, message.toString(), expectedResponse.toString()); 
    464475         
    465476        assertEquals(expectedResponse.toString(), response); 
     
    490501        assertEquals(1, sequence.size()); 
    491502 
    492         assertEvent(sequence.get(0), "POST", message.toString(), expectedResponse.toString()); 
    493     } 
    494  
     503        assertEvent(sequence.get(0), "POST", null, message.toString(), expectedResponse.toString()); 
     504    } 
     505     
     506    /** 
     507     * 
     508     */ 
    495509    @Test 
    496510    public void test_LargeRequest_Remote() throws Exception { 
     
    511525        } 
    512526         
    513         String response = sendDummyMessage("POST", message.toString(), expectedResponse.toString()); 
     527        String response = 
     528            sendDummyMessage("POST", null, message.toString(), expectedResponse.toString()); 
    514529         
    515530        assertEquals(expectedResponse.toString(), response); 
     
    517532        // give the proxy some time to send the copy of the message 
    518533        while(messages.size() < 1) { 
     534            System.out.println("waiting for message to be send by the proxy"); 
    519535            Thread.sleep(1000); 
    520536        } 
     
    529545            (JAXBElement<HttpExchange>) unmarshaller.unmarshal(new StringReader(messages.get(0))); 
    530546         
    531         HttpExchange exchange = jaxObject.getValue(); 
    532          
    533         assertEquals(message.toString(), exchange.getRequest().getContent().getData()); 
    534         assertEquals(response.toString(), exchange.getResponse().getContent().getData()); 
     547        assertExchange(jaxObject.getValue(), "POST", null, 
     548                       message.toString(), expectedResponse.toString()); 
     549    } 
     550     
     551    /** 
     552     * 
     553     */ 
     554    @Test 
     555    public void test_Query_Local() throws Exception { 
     556        proxy = new HttpMonitoringProxy 
     557            (new String[] { LOG_FILE_DIR, PROXY_PORT + "", "localhost:" + DUMMY_SERVER_PORT, 
     558                            "local" }); 
     559 
     560        proxy.init(); 
     561        proxy.start(); 
     562         
     563        String message = "dummy message"; 
     564        String expectedResponse = "response content"; 
     565        String query = "key=value&key2=value2&key3=%3E%3CXXX"; 
     566        String response = sendDummyMessage("POST", query, message, expectedResponse); 
     567         
     568        assertEquals(expectedResponse, response); 
     569         
     570        proxy.stop(); 
     571        proxy = null; 
     572 
     573        File logFile = new File(LOG_FILE_DIR + File.separator + "httpmonitor_000.log"); 
     574         
     575        assertTrue(logFile.exists()); 
     576         
     577        HTTPLogParser parser = new HTTPLogParser(); 
     578 
     579        parser.parseFile(logFile); 
     580 
     581        // check the sequences 
     582        Collection<List<Event>> sequences = parser.getSequences(); 
     583 
     584        assertNotNull(sequences); 
     585 
     586        Iterator<List<Event>> iterator = sequences.iterator(); 
     587        assertTrue(iterator.hasNext()); 
     588 
     589        List<Event> sequence = iterator.next(); 
     590        assertFalse(iterator.hasNext()); 
     591 
     592        assertNotNull(sequence); 
     593        assertEquals(1, sequence.size()); 
     594 
     595        assertEvent(sequence.get(0), "POST", query, message, expectedResponse); 
     596    } 
     597     
     598    /** 
     599     * 
     600     */ 
     601    @Test 
     602    public void test_Query_Remote() throws Exception { 
     603        proxy = new HttpMonitoringProxy 
     604            (new String[] { LOG_FILE_DIR, PROXY_PORT + "", 
     605                            "localhost:" + DUMMY_SERVER_PORT, "localhost:" + MONITOR_PORT }); 
     606 
     607        proxy.init(); 
     608        proxy.start(); 
     609         
     610        String message = "dummy message"; 
     611        String expectedResponse = "response content"; 
     612        String query = "key=value&key2=value2&key3=%3E%3CXXX"; 
     613        String response = sendDummyMessage("POST", query, message, expectedResponse); 
     614         
     615        assertEquals(expectedResponse, response); 
     616         
     617        // give the proxy some time to send the copy of the message 
     618        while(messages.size() < 1) { 
     619            System.out.println("waiting for message to be send by the proxy"); 
     620            Thread.sleep(1000); 
     621        } 
     622         
     623        assertEquals(1, messages.size()); 
     624         
     625        JAXBContext jaxbContext = JAXBContext.newInstance(HttpExchange.class.getPackage().getName()); 
     626        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 
     627         
     628        @SuppressWarnings("unchecked") 
     629        JAXBElement<HttpExchange> jaxObject = 
     630            (JAXBElement<HttpExchange>) unmarshaller.unmarshal(new StringReader(messages.get(0))); 
     631         
     632        assertExchange(jaxObject.getValue(), "POST", query, message, expectedResponse); 
    535633    } 
    536634 
     
    553651             
    554652            resp.setStatus(HttpServletResponse.SC_OK); 
     653            System.out.println("send ok response"); 
    555654        } 
    556655         
Note: See TracChangeset for help on using the changeset viewer.