Changeset 1390 for trunk/autoquest-httpmonitor-test/src
- Timestamp:
- 02/20/14 16:15:23 (11 years ago)
- 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 22 22 import java.util.logging.Level; 23 23 24 import org.apache.catalina.Context; 25 import org.apache.catalina.startup.Tomcat; 24 26 import org.apache.http.HttpEntity; 25 27 import org.apache.http.HttpResponse; … … 30 32 import org.apache.http.entity.StringEntity; 31 33 import 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;35 34 import org.junit.After; 36 35 import org.junit.Before; … … 56 55 * 57 56 */ 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; 64 68 65 69 /** … … 67 71 */ 68 72 private DummyServlet dummyServlet; 73 74 /** */ 75 private static Tomcat tomcat = new Tomcat(); 69 76 70 77 /** … … 74 81 public void setUp() throws Exception { 75 82 // setup a simple HTTP server 76 dummyServer = new Server(PORT + 1); 83 dummyServlet = new DummyServlet(); 84 85 /*dummyServer = new Server(DUMMY_SERVER_PORT); 77 86 78 87 ServletContextHandler root = 79 new ServletContextHandler(dummyServer, "/ ", ServletContextHandler.SESSIONS);80 81 dummyServlet = new DummyServlet();88 new ServletContextHandler(dummyServer, "/dummyServer", ServletContextHandler.SESSIONS); 89 90 82 91 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(); 85 113 86 114 setUpHook(); … … 103 131 tearDownHook(); 104 132 105 if ( dummyServer!= null) {133 if (tomcat != null) { 106 134 try { 107 dummyServer.stop(); 135 tomcat.stop(); 136 tomcat.getServer().await(); 137 tomcat.destroy(); 108 138 } 109 139 finally { 110 dummyServer= null;140 tomcat = null; 111 141 } 112 142 } … … 133 163 134 164 if ("POST".equals(type)) { 135 httpRequest = new HttpPost("http://localhost:" + P ORT + "/");165 httpRequest = new HttpPost("http://localhost:" + PROXY_PORT + "/dummyServlet"); 136 166 HttpEntity entity = new StringEntity(message, ContentType.TEXT_PLAIN); 137 167 ((HttpPost) httpRequest).setEntity(entity); 138 168 } 139 169 else if ("GET".equals(type)) { 140 httpRequest = new HttpGet("http://localhost:" + P ORT + "/");170 httpRequest = new HttpGet("http://localhost:" + PROXY_PORT + "/dummyServlet"); 141 171 } 142 172 143 173 try { 144 174 HttpResponse response = httpclient.execute(httpRequest); 175 System.err.println(response.getStatusLine()); 145 176 String responseStr = readStreamContentToString(response.getEntity().getContent()); 146 System.err.println("received response: " + message);177 System.err.println("received response: " + responseStr); 147 178 return responseStr; 148 179 } -
trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitorTest.java
r1376 r1390 94 94 @Test 95 95 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 + "" }); 97 97 98 98 monitor.init(); … … 155 155 @Test 156 156 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 + "" }); 158 158 159 159 monitor.init(); … … 161 161 162 162 proxy = new HttpMonitoringProxy 163 (new String[] { LOG_FILE_DIR, P ORT +"",164 "localhost:" + (PORT + 1), "localhost:" + (PORT + 2)});163 (new String[] { LOG_FILE_DIR, PROXY_PORT + "", 164 "localhost:" + DUMMY_SERVER_PORT, "localhost:" + MONITOR_PORT }); 165 165 166 166 proxy.init(); … … 216 216 @Test 217 217 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 + "" }); 219 219 220 220 monitor.init(); … … 222 222 223 223 proxy = new HttpMonitoringProxy 224 (new String[] { LOG_FILE_DIR, P ORT +"",225 "localhost:" + (PORT + 1), "localhost:" + (PORT + 2)});224 (new String[] { LOG_FILE_DIR, PROXY_PORT + "", 225 "localhost:" + DUMMY_SERVER_PORT, "localhost:" + MONITOR_PORT }); 226 226 227 227 proxy.init(); … … 315 315 316 316 for (HttpExchange exchange : exchanges) { 317 HttpPost httpRequest = new HttpPost("http://localhost:" + PORT + "/");317 HttpPost httpRequest = new HttpPost("http://localhost:" + MONITOR_PORT + "/"); 318 318 319 319 JAXBContext jaxbContext = -
trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitoringProxyTest.java
r1376 r1390 20 20 import java.io.IOException; 21 21 import java.io.StringReader; 22 import java.net.URL; 22 23 import java.util.Collection; 23 24 import java.util.Iterator; … … 32 33 import javax.xml.bind.JAXBElement; 33 34 import javax.xml.bind.Unmarshaller; 35 import javax.xml.namespace.QName; 34 36 35 37 import org.eclipse.jetty.server.Server; … … 37 39 import org.eclipse.jetty.servlet.ServletHolder; 38 40 import org.junit.Test; 41 42 import dummyservice.ObjectFactory; 43 import dummyservice.VerifyUserInMsgType; 44 import dummyservice.VerifyUserOutMsgType; 39 45 40 46 import de.ugoe.cs.autoquest.eventcore.Event; … … 45 51 import de.ugoe.cs.autoquest.plugin.http.eventcore.HTTPEventType; 46 52 import de.ugoe.cs.autoquest.plugin.http.eventcore.HTTPTarget; 53 import dummyservice.DummyService; 54 import dummyservice.DummyServicePortType; 47 55 48 56 /** … … 73 81 messages = new LinkedList<String>(); 74 82 75 dummyMonitor = new Server( PORT + 2);83 dummyMonitor = new Server(MONITOR_PORT); 76 84 ServletContextHandler root = 77 85 new ServletContextHandler(dummyMonitor, "/", ServletContextHandler.SESSIONS); … … 113 121 public void test_SimpleText_Local() throws Exception { 114 122 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" }); 116 125 117 126 proxy.init(); … … 155 164 public void test_SimpleText_Remote() throws Exception { 156 165 proxy = new HttpMonitoringProxy 157 (new String[] { LOG_FILE_DIR, P ORT +"",158 "localhost:" + (PORT + 1), "localhost:" + (PORT + 2)});166 (new String[] { LOG_FILE_DIR, PROXY_PORT + "", 167 "localhost:" + DUMMY_SERVER_PORT, "localhost:" + MONITOR_PORT }); 159 168 160 169 proxy.init(); … … 190 199 public void test_XMLMessage_Local() throws Exception { 191 200 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" }); 193 203 194 204 proxy.init(); … … 265 275 public void test_XMLMessage_Remote() throws Exception { 266 276 proxy = new HttpMonitoringProxy 267 (new String[] { LOG_FILE_DIR, P ORT +"",268 "localhost:" + (PORT + 1), "localhost:" + (PORT + 2)});277 (new String[] { LOG_FILE_DIR, PROXY_PORT + "", 278 "localhost:" + DUMMY_SERVER_PORT, "localhost:" + MONITOR_PORT }); 269 279 270 280 proxy.init(); … … 330 340 } 331 341 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 332 448 /** 333 449 * … … 344 460 345 461 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 } 348 476 } 349 477
Note: See TracChangeset
for help on using the changeset viewer.