Changeset 1614 for trunk/autoquest-httpmonitor-test/src/test/java
- Timestamp:
- 07/15/14 13:45:31 (10 years ago)
- Location:
- trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor/AbstractTC.java
r1567 r1614 18 18 import static org.junit.Assert.assertNotNull; 19 19 import static org.junit.Assert.assertTrue; 20 import static org.junit.Assert.fail; 20 21 21 22 import java.io.BufferedReader; … … 188 189 * 189 190 */ 190 protected String sendDummyMessage(String type, String message, String respMsg)191 protected String sendDummyMessage(String type, String query, String message, String respMsg) 191 192 throws Exception 192 193 { … … 197 198 HttpRequestBase httpRequest = null; 198 199 200 String uri = "http://localhost:" + PROXY_PORT + "/dummyServlet"; 201 202 if (query != null) { 203 uri += "?" + query; 204 } 205 199 206 if ("POST".equals(type)) { 200 httpRequest = new HttpPost( "http://localhost:" + PROXY_PORT + "/dummyServlet");207 httpRequest = new HttpPost(uri); 201 208 HttpEntity entity = new StringEntity(message, ContentType.TEXT_PLAIN); 202 209 ((HttpPost) httpRequest).setEntity(entity); 203 210 } 204 211 else if ("GET".equals(type)) { 205 httpRequest = new HttpGet( "http://localhost:" + PROXY_PORT + "/dummyServlet");212 httpRequest = new HttpGet(uri); 206 213 } 207 214 … … 210 217 211 218 assertEquals(message, dummyServlet.getRequest()); 219 assertEquals(query, dummyServlet.getQuery()); 212 220 System.err.println(response.getStatusLine()); 213 221 String responseStr = readStreamContentToString(response.getEntity().getContent()); … … 223 231 * 224 232 */ 225 protected void assertEvent(Event event, String method, String message, String response) { 233 protected void assertEvent(Event event, 234 String method, 235 String query, 236 String message, 237 String response) 238 { 226 239 assertNotNull(event); 227 240 assertNotNull(event.getType()); … … 231 244 assertTrue(event.getTarget() instanceof HTTPTarget); 232 245 233 HttpExchange exchange = ((HTTPEventType) event.getType()).getExchange(); 234 246 assertExchange(((HTTPEventType) event.getType()).getExchange(), 247 method, query, message, response); 248 } 249 250 /** 251 * 252 */ 253 protected void assertExchange(HttpExchange exchange, 254 String method, 255 String query, 256 String message, 257 String response) 258 { 235 259 assertEquals(Method.fromValue(method), exchange.getRequest().getMethod()); 260 261 if (query != null) { 262 assertEquals(query, exchange.getRequest().getQuery()); 263 } 264 else if (exchange.getRequest().getQuery() != null) { 265 System.err.println(exchange.getRequest().getQuery()); 266 fail("unexpected query"); 267 } 236 268 237 269 if (message != null) { -
trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor/DummyServlet.java
r1567 r1614 31 31 32 32 /** */ 33 private String query; 34 35 /** */ 33 36 private String requestMessage; 34 37 … … 43 46 throws ServletException, IOException 44 47 { 48 query = request.getQueryString(); 45 49 requestMessage = AbstractTC.readStreamContentToString(request.getInputStream()); 46 50 … … 56 60 throws ServletException, IOException 57 61 { 62 query = request.getQueryString(); 58 63 requestMessage = AbstractTC.readStreamContentToString(request.getInputStream()); 59 64 … … 69 74 throws ServletException, IOException 70 75 { 76 query = request.getQueryString(); 71 77 requestMessage = AbstractTC.readStreamContentToString(request.getInputStream()); 72 78 … … 88 94 return this.requestMessage; 89 95 } 96 97 /** 98 * 99 */ 100 String getQuery() { 101 return this.query; 102 } 90 103 } -
trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitorTest.java
r1561 r1614 98 98 } 99 99 100 /** 101 * 102 */ 100 103 @Test 101 104 public void test_SimulatedSession_MonitorOnly() throws Exception { … … 158 161 System.out.println("\n\n"); 159 162 } 160 163 164 /** 165 * 166 */ 161 167 @Test 162 168 public void test_SimpleText_ProxyAndMonitor() throws Exception { … … 175 181 String message = "dummy message"; 176 182 String expectedResponse = "response content"; 177 String response = sendDummyMessage("POST", message, expectedResponse);183 String response = sendDummyMessage("POST", null, message, expectedResponse); 178 184 179 185 assertEquals(expectedResponse, response); … … 207 213 assertEquals(1, sequence.size()); 208 214 209 assertEvent(sequence.get(0), "POST", message, response); 210 } 211 215 assertEvent(sequence.get(0), "POST", null, message, response); 216 } 217 218 /** 219 * 220 */ 212 221 @Test 213 222 public void test_XMLMessage_ProxyAndMonitor() throws Exception { … … 259 268 "</httpEvent>"; 260 269 261 String response = sendDummyMessage("POST", message, expectedResponse);270 String response = sendDummyMessage("POST", null, message, expectedResponse); 262 271 263 272 assertEquals(expectedResponse, response); … … 291 300 assertEquals(1, sequence.size()); 292 301 293 assertEvent(sequence.get(0), "POST", message, response); 294 } 295 302 assertEvent(sequence.get(0), "POST", null, message, response); 303 } 304 305 /** 306 * 307 */ 296 308 @Test 297 309 public void test_SOAP_ProxyAndMonitor() throws Exception { … … 348 360 assertEquals(2, sequence.size()); 349 361 350 assertEvent(sequence.get(0), "GET", null, null); // get WSDL 351 assertEvent(sequence.get(1), "POST", null, null); // send request 352 } 353 362 assertEvent(sequence.get(0), "GET", "wsdl", null, null); // get WSDL 363 assertEvent(sequence.get(1), "POST", null, null, null); // send request 364 } 365 366 /** 367 * 368 */ 369 @Test 370 public void test_LargeRequest_ProxyAndMonitor() throws Exception { 371 monitor = new HttpMonitor(new String[] { LOG_FILE_DIR, MONITOR_PORT + "" }); 372 373 monitor.init(); 374 monitor.start(); 375 376 proxy = new HttpMonitoringProxy 377 (new String[] { LOG_FILE_DIR, PROXY_PORT + "", 378 "localhost:" + DUMMY_SERVER_PORT, "localhost:" + MONITOR_PORT }); 379 380 proxy.init(); 381 proxy.start(); 382 383 StringBuffer message = new StringBuffer(); 384 StringBuffer expectedResponse = new StringBuffer(); 385 386 for (int i = 0; i < 1000; i++) { 387 message.append(" # " + i + " test request data"); 388 expectedResponse.append(" # " + i + " test response data"); 389 } 390 391 String response = 392 sendDummyMessage("POST", null, message.toString(), expectedResponse.toString()); 393 394 assertEquals(expectedResponse.toString(), response); 395 396 // the monitor needs some time to receive the exchange --> give it 397 Thread.sleep(1000); 398 399 monitor.stop(); 400 monitor = null; 401 402 File logFile = new File(LOG_FILE_DIR + File.separator + "httpmonitor_000.log"); 403 404 assertTrue(logFile.exists()); 405 406 HTTPLogParser parser = new HTTPLogParser(); 407 408 parser.parseFile(logFile); 409 410 // check the sequences 411 Collection<List<Event>> sequences = parser.getSequences(); 412 413 assertNotNull(sequences); 414 415 Iterator<List<Event>> iterator = sequences.iterator(); 416 assertTrue(iterator.hasNext()); 417 418 List<Event> sequence = iterator.next(); 419 assertFalse(iterator.hasNext()); 420 421 assertNotNull(sequence); 422 assertEquals(1, sequence.size()); 423 424 assertEvent(sequence.get(0), "POST", null, message.toString(), response); 425 } 426 427 /** 428 * 429 */ 430 @Test 431 public void test_Query_ProxyAndMonitor() throws Exception { 432 monitor = new HttpMonitor(new String[] { LOG_FILE_DIR, MONITOR_PORT + "" }); 433 434 monitor.init(); 435 monitor.start(); 436 437 proxy = new HttpMonitoringProxy 438 (new String[] { LOG_FILE_DIR, PROXY_PORT + "", 439 "localhost:" + DUMMY_SERVER_PORT, "localhost:" + MONITOR_PORT }); 440 441 proxy.init(); 442 proxy.start(); 443 444 String message = "dummy message"; 445 String query = "key=value&key2=value2&key3=%3E%3CXXX"; 446 String expectedResponse = "response content"; 447 String response = sendDummyMessage("POST", query, message, expectedResponse); 448 449 assertEquals(expectedResponse, response); 450 451 // the monitor needs some time to receive the exchange --> give it 452 Thread.sleep(1000); 453 454 monitor.stop(); 455 monitor = null; 456 457 File logFile = new File(LOG_FILE_DIR + File.separator + "httpmonitor_000.log"); 458 459 assertTrue(logFile.exists()); 460 461 HTTPLogParser parser = new HTTPLogParser(); 462 463 parser.parseFile(logFile); 464 465 // check the sequences 466 Collection<List<Event>> sequences = parser.getSequences(); 467 468 assertNotNull(sequences); 469 470 Iterator<List<Event>> iterator = sequences.iterator(); 471 assertTrue(iterator.hasNext()); 472 473 List<Event> sequence = iterator.next(); 474 assertFalse(iterator.hasNext()); 475 476 assertNotNull(sequence); 477 assertEquals(1, sequence.size()); 478 479 assertEvent(sequence.get(0), "POST", query, message, response); 480 } 481 354 482 /** 355 483 * -
trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitoringProxyTest.java
r1563 r1614 48 48 import de.ugoe.cs.autoquest.plugin.http.HTTPLogParser; 49 49 import de.ugoe.cs.autoquest.plugin.http.logdata.HttpExchange; 50 import de.ugoe.cs.autoquest.plugin.http.logdata.Method;51 50 import dummyservice.DummyService; 52 51 import dummyservice.DummyServicePortType; … … 111 110 } 112 111 112 /** 113 * 114 */ 113 115 @Test(expected=java.lang.IllegalArgumentException.class) 114 116 public void test_InvalidInitialization_01() throws Exception { … … 116 118 } 117 119 120 /** 121 * 122 */ 118 123 @Test 119 124 public void test_SimpleText_Local() throws Exception { … … 127 132 String message = "dummy message"; 128 133 String expectedResponse = "response content"; 129 String response = sendDummyMessage("POST", message, expectedResponse);134 String response = sendDummyMessage("POST", null, message, expectedResponse); 130 135 131 136 assertEquals(expectedResponse, response); … … 156 161 assertEquals(1, sequence.size()); 157 162 158 assertEvent(sequence.get(0), "POST", message, expectedResponse); 159 } 160 163 assertEvent(sequence.get(0), "POST", null, message, expectedResponse); 164 } 165 166 /** 167 * 168 */ 161 169 @Test 162 170 public void test_SimpleText_Remote() throws Exception { … … 170 178 String message = "dummy message"; 171 179 String expectedResponse = "response content"; 172 String response = sendDummyMessage("POST", message, expectedResponse);180 String response = sendDummyMessage("POST", null, message, expectedResponse); 173 181 174 182 assertEquals(expectedResponse, response); … … 176 184 // give the proxy some time to send the copy of the message 177 185 while(messages.size() < 1) { 186 System.out.println("waiting for message to be send by the proxy"); 178 187 Thread.sleep(1000); 179 188 } … … 188 197 (JAXBElement<HttpExchange>) unmarshaller.unmarshal(new StringReader(messages.get(0))); 189 198 190 HttpExchange exchange = jaxObject.getValue();191 192 assertEquals(message, exchange.getRequest().getContent().getData());193 assertEquals(response, exchange.getResponse().getContent().getData());194 }195 199 assertExchange(jaxObject.getValue(), "POST", null, message, expectedResponse); 200 } 201 202 /** 203 * 204 */ 196 205 @Test 197 206 public void test_XMLMessage_Local() throws Exception { … … 238 247 "</httpEvent>"; 239 248 240 String response = sendDummyMessage("POST", message, expectedResponse);249 String response = sendDummyMessage("POST", null, message, expectedResponse); 241 250 242 251 assertEquals(expectedResponse, response); … … 267 276 assertEquals(1, sequence.size()); 268 277 269 assertEvent(sequence.get(0), "POST", message, expectedResponse); 270 } 271 278 assertEvent(sequence.get(0), "POST", null, message, expectedResponse); 279 } 280 281 /** 282 * 283 */ 272 284 @Test 273 285 public void test_XMLMessage_Remote() throws Exception { … … 314 326 "</httpEvent>"; 315 327 316 String response = sendDummyMessage("POST", message, expectedResponse);328 String response = sendDummyMessage("POST", null, message, expectedResponse); 317 329 318 330 assertEquals(expectedResponse, response); … … 320 332 // give the proxy some time to send the copy of the message 321 333 while(messages.size() < 1) { 334 System.out.println("waiting for message to be send by the proxy"); 322 335 Thread.sleep(1000); 323 336 } … … 332 345 (JAXBElement<HttpExchange>) unmarshaller.unmarshal(new StringReader(messages.get(0))); 333 346 334 HttpExchange exchange = jaxObject.getValue();335 336 assertEquals(message, exchange.getRequest().getContent().getData());337 assertEquals(response, exchange.getResponse().getContent().getData());338 }339 347 assertExchange(jaxObject.getValue(), "POST", null, message, expectedResponse); 348 } 349 350 /** 351 * 352 */ 340 353 @Test 341 354 public void test_SOAP_Local() throws Exception { … … 384 397 assertEquals(2, sequence.size()); 385 398 386 assertEvent(sequence.get(0), "GET", null, null); // get WSDL 387 assertEvent(sequence.get(1), "POST", null, null); // send request 388 } 389 399 assertEvent(sequence.get(0), "GET", "wsdl", null, null); // get WSDL 400 assertEvent(sequence.get(1), "POST", null, null, null); // send request 401 } 402 403 /** 404 * 405 */ 390 406 @SuppressWarnings("unchecked") 391 407 @Test … … 415 431 // give the proxy some time to send the copy of the message 416 432 while(messages.size() < 1) { 433 System.out.println("waiting for message to be send by the proxy"); 417 434 Thread.sleep(1000); 418 435 } … … 426 443 (JAXBElement<HttpExchange>) unmarshaller.unmarshal(new StringReader(messages.get(0))); 427 444 428 HttpExchange exchange = jaxObject.getValue(); 429 430 assertEquals(Method.GET, exchange.getRequest().getMethod()); 431 432 assertNull(exchange.getRequest().getContent()); 433 assertNotNull(exchange.getResponse().getContent().getData()); 445 assertExchange(jaxObject.getValue(), "GET", "wsdl", null, null); 434 446 435 447 jaxObject = 436 448 (JAXBElement<HttpExchange>) unmarshaller.unmarshal(new StringReader(messages.get(1))); 437 449 438 exchange = jaxObject.getValue(); 439 440 assertEquals(Method.POST, exchange.getRequest().getMethod()); 441 442 assertNotNull(exchange.getRequest().getContent().getData()); 443 assertNotNull(exchange.getResponse().getContent().getData()); 444 } 445 450 assertExchange(jaxObject.getValue(), "POST", null, null, null); 451 } 452 453 /** 454 * 455 */ 446 456 @Test 447 457 public void test_LargeRequest_Local() throws Exception { … … 461 471 } 462 472 463 String response = sendDummyMessage("POST", message.toString(), expectedResponse.toString()); 473 String response = 474 sendDummyMessage("POST", null, message.toString(), expectedResponse.toString()); 464 475 465 476 assertEquals(expectedResponse.toString(), response); … … 490 501 assertEquals(1, sequence.size()); 491 502 492 assertEvent(sequence.get(0), "POST", message.toString(), expectedResponse.toString()); 493 } 494 503 assertEvent(sequence.get(0), "POST", null, message.toString(), expectedResponse.toString()); 504 } 505 506 /** 507 * 508 */ 495 509 @Test 496 510 public void test_LargeRequest_Remote() throws Exception { … … 511 525 } 512 526 513 String response = sendDummyMessage("POST", message.toString(), expectedResponse.toString()); 527 String response = 528 sendDummyMessage("POST", null, message.toString(), expectedResponse.toString()); 514 529 515 530 assertEquals(expectedResponse.toString(), response); … … 517 532 // give the proxy some time to send the copy of the message 518 533 while(messages.size() < 1) { 534 System.out.println("waiting for message to be send by the proxy"); 519 535 Thread.sleep(1000); 520 536 } … … 529 545 (JAXBElement<HttpExchange>) unmarshaller.unmarshal(new StringReader(messages.get(0))); 530 546 531 HttpExchange exchange = jaxObject.getValue(); 532 533 assertEquals(message.toString(), exchange.getRequest().getContent().getData()); 534 assertEquals(response.toString(), exchange.getResponse().getContent().getData()); 547 assertExchange(jaxObject.getValue(), "POST", null, 548 message.toString(), expectedResponse.toString()); 549 } 550 551 /** 552 * 553 */ 554 @Test 555 public void test_Query_Local() throws Exception { 556 proxy = new HttpMonitoringProxy 557 (new String[] { LOG_FILE_DIR, PROXY_PORT + "", "localhost:" + DUMMY_SERVER_PORT, 558 "local" }); 559 560 proxy.init(); 561 proxy.start(); 562 563 String message = "dummy message"; 564 String expectedResponse = "response content"; 565 String query = "key=value&key2=value2&key3=%3E%3CXXX"; 566 String response = sendDummyMessage("POST", query, message, expectedResponse); 567 568 assertEquals(expectedResponse, response); 569 570 proxy.stop(); 571 proxy = null; 572 573 File logFile = new File(LOG_FILE_DIR + File.separator + "httpmonitor_000.log"); 574 575 assertTrue(logFile.exists()); 576 577 HTTPLogParser parser = new HTTPLogParser(); 578 579 parser.parseFile(logFile); 580 581 // check the sequences 582 Collection<List<Event>> sequences = parser.getSequences(); 583 584 assertNotNull(sequences); 585 586 Iterator<List<Event>> iterator = sequences.iterator(); 587 assertTrue(iterator.hasNext()); 588 589 List<Event> sequence = iterator.next(); 590 assertFalse(iterator.hasNext()); 591 592 assertNotNull(sequence); 593 assertEquals(1, sequence.size()); 594 595 assertEvent(sequence.get(0), "POST", query, message, expectedResponse); 596 } 597 598 /** 599 * 600 */ 601 @Test 602 public void test_Query_Remote() throws Exception { 603 proxy = new HttpMonitoringProxy 604 (new String[] { LOG_FILE_DIR, PROXY_PORT + "", 605 "localhost:" + DUMMY_SERVER_PORT, "localhost:" + MONITOR_PORT }); 606 607 proxy.init(); 608 proxy.start(); 609 610 String message = "dummy message"; 611 String expectedResponse = "response content"; 612 String query = "key=value&key2=value2&key3=%3E%3CXXX"; 613 String response = sendDummyMessage("POST", query, message, expectedResponse); 614 615 assertEquals(expectedResponse, response); 616 617 // give the proxy some time to send the copy of the message 618 while(messages.size() < 1) { 619 System.out.println("waiting for message to be send by the proxy"); 620 Thread.sleep(1000); 621 } 622 623 assertEquals(1, messages.size()); 624 625 JAXBContext jaxbContext = JAXBContext.newInstance(HttpExchange.class.getPackage().getName()); 626 Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 627 628 @SuppressWarnings("unchecked") 629 JAXBElement<HttpExchange> jaxObject = 630 (JAXBElement<HttpExchange>) unmarshaller.unmarshal(new StringReader(messages.get(0))); 631 632 assertExchange(jaxObject.getValue(), "POST", query, message, expectedResponse); 535 633 } 536 634 … … 553 651 554 652 resp.setStatus(HttpServletResponse.SC_OK); 653 System.out.println("send ok response"); 555 654 } 556 655
Note: See TracChangeset
for help on using the changeset viewer.