Changeset 1390 for trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitoringProxyTest.java
- Timestamp:
- 02/20/14 16:15:23 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.