Ignore:
Timestamp:
02/20/14 16:15:23 (10 years ago)
Author:
pharms
Message:
  • added test cases for SOAP message exchange
Location:
trunk/autoquest-httpmonitor-test/src
Files:
14 added
3 edited

Legend:

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

    r1376 r1390  
    2222import java.util.logging.Level; 
    2323 
     24import org.apache.catalina.Context; 
     25import org.apache.catalina.startup.Tomcat; 
    2426import org.apache.http.HttpEntity; 
    2527import org.apache.http.HttpResponse; 
     
    3032import org.apache.http.entity.StringEntity; 
    3133import org.apache.http.impl.client.DefaultHttpClient; 
    32 import org.eclipse.jetty.server.Server; 
    33 import org.eclipse.jetty.servlet.ServletContextHandler; 
    34 import org.eclipse.jetty.servlet.ServletHolder; 
    3534import org.junit.After; 
    3635import org.junit.Before; 
     
    5655     *  
    5756     */ 
    58     protected static final int PORT = 19098; 
    59      
    60     /** 
    61      * the jetty web server used for receiving messages 
    62      */ 
    63     private Server dummyServer; 
     57    protected static final int DUMMY_SERVER_PORT = 19098; 
     58     
     59    /** 
     60     *  
     61     */ 
     62    protected static final int PROXY_PORT = 19099; 
     63     
     64    /** 
     65     *  
     66     */ 
     67    protected static final int MONITOR_PORT = 19100; 
    6468     
    6569    /** 
     
    6771     */ 
    6872    private DummyServlet dummyServlet; 
     73     
     74    /** */ 
     75    private static Tomcat tomcat = new Tomcat(); 
    6976 
    7077    /** 
     
    7481    public void setUp() throws Exception { 
    7582        // setup a simple HTTP server 
    76         dummyServer = new Server(PORT + 1); 
     83        dummyServlet = new DummyServlet(); 
     84         
     85        /*dummyServer = new Server(DUMMY_SERVER_PORT); 
    7786         
    7887        ServletContextHandler root = 
    79             new ServletContextHandler(dummyServer, "/", ServletContextHandler.SESSIONS); 
    80  
    81         dummyServlet = new DummyServlet(); 
     88            new ServletContextHandler(dummyServer, "/dummyServer", ServletContextHandler.SESSIONS); 
     89 
     90         
    8291        root.addServlet(new ServletHolder(dummyServlet), "/*"); 
    83          
    84         dummyServer.start(); 
     92        
     93        dummyServer.start();*/ 
     94         
     95        File tomcatDir = new File("target/test/tomcat"); 
     96        File webappRootDir = new File(tomcatDir, "webapp"); 
     97         
     98        tomcat = new Tomcat(); 
     99        tomcat.setPort(DUMMY_SERVER_PORT); 
     100        tomcat.setBaseDir(tomcatDir.getAbsolutePath()); 
     101 
     102        File warFile = new File(webappRootDir, "dummyService.war"); 
     103        tomcat.addWebapp("/dummyWebapp", warFile.getAbsolutePath()); 
     104        System.out.println("configuring Dummy Service from " + warFile.getAbsolutePath()); 
     105         
     106        File servletRootDir = new File(tomcatDir, "servlet"); 
     107        servletRootDir.mkdirs(); 
     108        Context ctx = tomcat.addContext("/", servletRootDir.getAbsolutePath()); 
     109        Tomcat.addServlet(ctx, "dummyServlet", dummyServlet); 
     110        ctx.addServletMapping("/dummyServlet", "dummyServlet"); 
     111         
     112        tomcat.start(); 
    85113         
    86114        setUpHook(); 
     
    103131        tearDownHook(); 
    104132 
    105         if (dummyServer != null) { 
     133        if (tomcat != null) { 
    106134            try { 
    107                 dummyServer.stop(); 
     135                tomcat.stop(); 
     136                tomcat.getServer().await(); 
     137                tomcat.destroy(); 
    108138            } 
    109139            finally { 
    110                 dummyServer = null; 
     140                tomcat = null; 
    111141            } 
    112142        } 
     
    133163         
    134164        if ("POST".equals(type)) { 
    135             httpRequest = new HttpPost("http://localhost:" + PORT + "/"); 
     165            httpRequest = new HttpPost("http://localhost:" + PROXY_PORT + "/dummyServlet"); 
    136166            HttpEntity entity = new StringEntity(message, ContentType.TEXT_PLAIN); 
    137167            ((HttpPost) httpRequest).setEntity(entity); 
    138168        } 
    139169        else if ("GET".equals(type)) { 
    140             httpRequest = new HttpGet("http://localhost:" + PORT + "/"); 
     170            httpRequest = new HttpGet("http://localhost:" + PROXY_PORT + "/dummyServlet"); 
    141171        } 
    142172         
    143173        try { 
    144174            HttpResponse response = httpclient.execute(httpRequest); 
     175            System.err.println(response.getStatusLine()); 
    145176            String responseStr = readStreamContentToString(response.getEntity().getContent()); 
    146             System.err.println("received response: " + message); 
     177            System.err.println("received response: " + responseStr); 
    147178            return responseStr; 
    148179        } 
  • trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitorTest.java

    r1376 r1390  
    9494    @Test 
    9595    public void test_SimulatedSession_MonitorOnly() throws Exception { 
    96         monitor = new HttpMonitor(new String[] { LOG_FILE_DIR, PORT +"" }); 
     96        monitor = new HttpMonitor(new String[] { LOG_FILE_DIR, MONITOR_PORT + "" }); 
    9797 
    9898        monitor.init(); 
     
    155155    @Test 
    156156    public void test_SimpleText_ProxyAndMonitor() throws Exception { 
    157         monitor = new HttpMonitor(new String[] { LOG_FILE_DIR, (PORT + 2) + "" }); 
     157        monitor = new HttpMonitor(new String[] { LOG_FILE_DIR, MONITOR_PORT + "" }); 
    158158 
    159159        monitor.init(); 
     
    161161 
    162162        proxy = new HttpMonitoringProxy 
    163             (new String[] { LOG_FILE_DIR, PORT +"", 
    164                             "localhost:" + (PORT + 1), "localhost:" + (PORT + 2) }); 
     163            (new String[] { LOG_FILE_DIR, PROXY_PORT + "", 
     164                            "localhost:" + DUMMY_SERVER_PORT, "localhost:" + MONITOR_PORT }); 
    165165 
    166166        proxy.init(); 
     
    216216    @Test 
    217217    public void test_XMLMessage_ProxyAndMonitor() throws Exception { 
    218         monitor = new HttpMonitor(new String[] { LOG_FILE_DIR, (PORT + 2) + "" }); 
     218        monitor = new HttpMonitor(new String[] { LOG_FILE_DIR, MONITOR_PORT + "" }); 
    219219 
    220220        monitor.init(); 
     
    222222 
    223223        proxy = new HttpMonitoringProxy 
    224             (new String[] { LOG_FILE_DIR, PORT +"", 
    225                             "localhost:" + (PORT + 1), "localhost:" + (PORT + 2) }); 
     224            (new String[] { LOG_FILE_DIR, PROXY_PORT + "", 
     225                            "localhost:" + DUMMY_SERVER_PORT, "localhost:" + MONITOR_PORT }); 
    226226 
    227227        proxy.init(); 
     
    315315         
    316316        for (HttpExchange exchange : exchanges) { 
    317             HttpPost httpRequest = new HttpPost("http://localhost:" + PORT + "/"); 
     317            HttpPost httpRequest = new HttpPost("http://localhost:" + MONITOR_PORT + "/"); 
    318318             
    319319            JAXBContext jaxbContext = 
  • 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.