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/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        } 
Note: See TracChangeset for help on using the changeset viewer.