Changeset 1614 for trunk/autoquest-httpmonitor-test/src/test/java/de/ugoe/cs/autoquest/httpmonitor/HttpMonitoringProxyTest.java
- Timestamp:
- 07/15/14 13:45:31 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.