Ignore:
Timestamp:
02/20/14 16:15:23 (10 years ago)
Author:
pharms
Message:
  • added test cases for SOAP message exchange
File:
1 edited

Legend:

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

    r1376 r1390  
    2020import java.io.IOException; 
    2121import java.io.StringReader; 
     22import java.net.URL; 
    2223import java.util.Collection; 
    2324import java.util.Iterator; 
     
    3233import javax.xml.bind.JAXBElement; 
    3334import javax.xml.bind.Unmarshaller; 
     35import javax.xml.namespace.QName; 
    3436 
    3537import org.eclipse.jetty.server.Server; 
     
    3739import org.eclipse.jetty.servlet.ServletHolder; 
    3840import org.junit.Test; 
     41 
     42import dummyservice.ObjectFactory; 
     43import dummyservice.VerifyUserInMsgType; 
     44import dummyservice.VerifyUserOutMsgType; 
    3945 
    4046import de.ugoe.cs.autoquest.eventcore.Event; 
     
    4551import de.ugoe.cs.autoquest.plugin.http.eventcore.HTTPEventType; 
    4652import de.ugoe.cs.autoquest.plugin.http.eventcore.HTTPTarget; 
     53import dummyservice.DummyService; 
     54import dummyservice.DummyServicePortType; 
    4755 
    4856/** 
     
    7381        messages = new LinkedList<String>(); 
    7482         
    75         dummyMonitor = new Server(PORT + 2); 
     83        dummyMonitor = new Server(MONITOR_PORT); 
    7684        ServletContextHandler root = 
    7785            new ServletContextHandler(dummyMonitor, "/", ServletContextHandler.SESSIONS); 
     
    113121    public void test_SimpleText_Local() throws Exception { 
    114122        proxy = new HttpMonitoringProxy 
    115             (new String[] { LOG_FILE_DIR, PORT +"", "localhost:" + (PORT + 1), "local" }); 
     123            (new String[] { LOG_FILE_DIR, PROXY_PORT + "", "localhost:" + DUMMY_SERVER_PORT, 
     124                            "local" }); 
    116125 
    117126        proxy.init(); 
     
    155164    public void test_SimpleText_Remote() throws Exception { 
    156165        proxy = new HttpMonitoringProxy 
    157             (new String[] { LOG_FILE_DIR, PORT +"", 
    158                             "localhost:" + (PORT + 1), "localhost:" + (PORT + 2) }); 
     166            (new String[] { LOG_FILE_DIR, PROXY_PORT + "", 
     167                            "localhost:" + DUMMY_SERVER_PORT, "localhost:" + MONITOR_PORT }); 
    159168 
    160169        proxy.init(); 
     
    190199    public void test_XMLMessage_Local() throws Exception { 
    191200        proxy = new HttpMonitoringProxy 
    192             (new String[] { LOG_FILE_DIR, PORT +"", "localhost:" + (PORT + 1), "local" }); 
     201            (new String[] { LOG_FILE_DIR, PROXY_PORT + "", "localhost:" + DUMMY_SERVER_PORT, 
     202                            "local" }); 
    193203 
    194204        proxy.init(); 
     
    265275    public void test_XMLMessage_Remote() throws Exception { 
    266276        proxy = new HttpMonitoringProxy 
    267             (new String[] { LOG_FILE_DIR, PORT +"", 
    268                             "localhost:" + (PORT + 1), "localhost:" + (PORT + 2) }); 
     277            (new String[] { LOG_FILE_DIR, PROXY_PORT + "", 
     278                            "localhost:" + DUMMY_SERVER_PORT, "localhost:" + MONITOR_PORT }); 
    269279 
    270280        proxy.init(); 
     
    330340    } 
    331341     
     342    @Test 
     343    public void test_SOAP_Local() throws Exception { 
     344        proxy = new HttpMonitoringProxy 
     345            (new String[] { LOG_FILE_DIR, PROXY_PORT + "", "localhost:" + DUMMY_SERVER_PORT, 
     346                            "local" }); 
     347 
     348        proxy.init(); 
     349        proxy.start(); 
     350 
     351        DummyService service = new DummyService 
     352            (new URL("http://localhost:" + PROXY_PORT + "/dummyWebapp/DummyServiceSOAPPort?wsdl"), 
     353             new QName("DummyService", "DummyService")); 
     354 
     355        DummyServicePortType dummyService = service.getDummyServiceSOAPPort(); 
     356         
     357        ObjectFactory factory = new ObjectFactory(); 
     358        VerifyUserInMsgType request = factory.createVerifyUserInMsgType(); 
     359        VerifyUserOutMsgType response = dummyService.verifyUser(request); 
     360 
     361        assertNotNull(response); 
     362         
     363        proxy.stop(); 
     364        proxy = null; 
     365 
     366        File logFile = new File(LOG_FILE_DIR + File.separator + "httpmonitor_000.log"); 
     367         
     368        assertTrue(logFile.exists()); 
     369         
     370        HTTPLogParser parser = new HTTPLogParser(); 
     371 
     372        parser.parseFile(logFile); 
     373 
     374        // check the sequences 
     375        Collection<List<Event>> sequences = parser.getSequences(); 
     376 
     377        assertNotNull(sequences); 
     378 
     379        Iterator<List<Event>> iterator = sequences.iterator(); 
     380        assertTrue(iterator.hasNext()); 
     381 
     382        List<Event> sequence = iterator.next(); 
     383        assertFalse(iterator.hasNext()); 
     384 
     385        assertNotNull(sequence); 
     386        assertEquals(2, sequence.size()); 
     387 
     388        assertEvent(sequence.get(0), "GET", null, null); // get WSDL 
     389        assertEvent(sequence.get(1), "POST", null, null); // send request 
     390    } 
     391     
     392    @SuppressWarnings("unchecked") 
     393    @Test 
     394    public void test_SOAP_Remote() throws Exception { 
     395        proxy = new HttpMonitoringProxy 
     396            (new String[] { LOG_FILE_DIR, PROXY_PORT + "", "localhost:" + DUMMY_SERVER_PORT, 
     397                            "localhost:" + MONITOR_PORT  }); 
     398 
     399        proxy.init(); 
     400        proxy.start(); 
     401 
     402        DummyService service = new DummyService 
     403            (new URL("http://localhost:" + PROXY_PORT + "/dummyWebapp/DummyServiceSOAPPort?wsdl"), 
     404             new QName("DummyService", "DummyService")); 
     405 
     406        DummyServicePortType dummyService = service.getDummyServiceSOAPPort(); 
     407         
     408        ObjectFactory factory = new ObjectFactory(); 
     409        VerifyUserInMsgType request = factory.createVerifyUserInMsgType(); 
     410        VerifyUserOutMsgType response = dummyService.verifyUser(request); 
     411 
     412        assertNotNull(response); 
     413         
     414        proxy.stop(); 
     415        proxy = null; 
     416 
     417        // give the proxy some time to send the copy of the message 
     418        while(messages.size() < 1) { 
     419            Thread.sleep(1000); 
     420        } 
     421         
     422        assertEquals(2, messages.size()); 
     423         
     424        JAXBContext jaxbContext = JAXBContext.newInstance(HttpExchange.class.getPackage().getName()); 
     425        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 
     426         
     427        JAXBElement<HttpExchange> jaxObject = 
     428            (JAXBElement<HttpExchange>) unmarshaller.unmarshal(new StringReader(messages.get(0))); 
     429         
     430        HttpExchange exchange = jaxObject.getValue(); 
     431         
     432        assertEquals(Method.GET, exchange.getRequest().getMethod()); 
     433 
     434        assertNull(exchange.getRequest().getContent()); 
     435        assertNotNull(exchange.getResponse().getContent().getData()); 
     436 
     437        jaxObject = 
     438            (JAXBElement<HttpExchange>) unmarshaller.unmarshal(new StringReader(messages.get(1))); 
     439             
     440        exchange = jaxObject.getValue(); 
     441             
     442        assertEquals(Method.POST, exchange.getRequest().getMethod()); 
     443 
     444        assertNotNull(exchange.getRequest().getContent().getData()); 
     445        assertNotNull(exchange.getResponse().getContent().getData()); 
     446    } 
     447     
    332448    /** 
    333449     * 
     
    344460         
    345461        assertEquals(Method.fromValue(method), exchange.getRequest().getMethod()); 
    346         assertEquals(message, exchange.getRequest().getContent().getData()); 
    347         assertEquals(response, exchange.getResponse().getContent().getData()); 
     462         
     463        if (message != null) { 
     464            assertEquals(message, exchange.getRequest().getContent().getData()); 
     465        } 
     466        else if (exchange.getRequest().getContent() != null) { 
     467            System.err.println(exchange.getRequest().getContent().getData()); 
     468        } 
     469         
     470        if (response != null) { 
     471            assertEquals(response, exchange.getResponse().getContent().getData()); 
     472        } 
     473        else if (exchange.getResponse().getContent() != null) { 
     474            System.err.println(exchange.getResponse().getContent().getData()); 
     475        } 
    348476    } 
    349477 
Note: See TracChangeset for help on using the changeset viewer.