Changeset 1390 for trunk/autoquest-httpmonitor-test
- Timestamp:
- 02/20/14 16:15:23 (11 years ago)
- Location:
- trunk/autoquest-httpmonitor-test
- Files:
-
- 14 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-httpmonitor-test/.classpath
r1376 r1390 2 2 <classpath> 3 3 <classpathentry kind="src" output="target/test-classes" path="src/test/java"> 4 <attributes> 5 <attribute name="optional" value="true"/> 6 <attribute name="maven.pomderived" value="true"/> 7 </attributes> 8 </classpathentry> 9 <classpathentry including="**/*.java" kind="src" path="src/main/resources"/> 10 <classpathentry kind="src" output="target/classes" path="src/main/java"> 11 <attributes> 12 <attribute name="optional" value="true"/> 13 <attribute name="maven.pomderived" value="true"/> 14 </attributes> 15 </classpathentry> 16 <classpathentry kind="src" output="target/classes" path="target/generated-sources/cxf"> 4 17 <attributes> 5 18 <attribute name="optional" value="true"/> -
trunk/autoquest-httpmonitor-test/pom.xml
r1377 r1390 19 19 <properties> 20 20 <tested-artifactId>autoquest-httpmonitor</tested-artifactId> 21 <tomcat.version>7.0.34</tomcat.version> 21 22 </properties> 22 23 <dependencies> 24 <dependency> 25 <groupId>org.apache.tomcat.embed</groupId> 26 <artifactId>tomcat-embed-core</artifactId> 27 <version>${tomcat.version}</version> 28 <scope>test</scope> 29 </dependency> 30 <dependency> 31 <groupId>org.apache.tomcat.embed</groupId> 32 <artifactId>tomcat-embed-logging-juli</artifactId> 33 <version>${tomcat.version}</version> 34 <scope>test</scope> 35 </dependency> 36 <dependency> 37 <groupId>org.apache.tomcat.embed</groupId> 38 <artifactId>tomcat-embed-jasper</artifactId> 39 <version>${tomcat.version}</version> 40 <scope>test</scope> 41 </dependency> 42 <dependency> 43 <groupId>org.apache.tomcat</groupId> 44 <artifactId>tomcat-jasper</artifactId> 45 <version>${tomcat.version}</version> 46 <scope>test</scope> 47 </dependency> 48 <dependency> 49 <groupId>org.apache.tomcat</groupId> 50 <artifactId>tomcat-jasper-el</artifactId> 51 <version>${tomcat.version}</version> 52 <scope>test</scope> 53 </dependency> 54 <dependency> 55 <groupId>org.apache.tomcat</groupId> 56 <artifactId>tomcat-jsp-api</artifactId> 57 <version>${tomcat.version}</version> 58 <scope>test</scope> 59 </dependency> 60 <dependency> 61 <groupId>org.apache.cxf</groupId> 62 <artifactId>cxf-rt-frontend-jaxws</artifactId> 63 <version>2.7.7</version> 64 <scope>test</scope> 65 </dependency> 66 <dependency> 67 <groupId>org.springframework</groupId> 68 <artifactId>spring-context</artifactId> 69 <version>3.1.4.RELEASE</version> 70 <scope>test</scope> 71 </dependency> 72 <dependency> 73 <groupId>org.springframework.security</groupId> 74 <artifactId>spring-security-web</artifactId> 75 <version>3.1.4.RELEASE</version> 76 <scope>test</scope> 77 </dependency> 23 78 <dependency> 24 79 <groupId>org.apache.httpcomponents</groupId> … … 27 82 <scope>test</scope> 28 83 </dependency> 84 <dependency> 85 <groupId>org.eclipse.jetty</groupId> 86 <artifactId>jetty-webapp</artifactId> 87 <version>9.1.0.M0</version> 88 <scope>test</scope> 89 </dependency> 29 90 </dependencies> 91 <build> 92 <plugins> 93 <plugin> 94 <groupId>org.apache.cxf</groupId> 95 <artifactId>cxf-codegen-plugin</artifactId> 96 <version>2.7.7</version> 97 <executions> 98 <execution> 99 <id>generate-sources</id> 100 <phase>generate-sources</phase> 101 <configuration> 102 <wsdlOptions> 103 <wsdlOption> 104 <wsdl>${basedir}/src/main/resources/DummyService.wsdl</wsdl> 105 <wsdlLocation>classpath:DummyService.wsdl</wsdlLocation> 106 <extraargs> 107 <extraarg>-impl</extraarg> 108 </extraargs> 109 </wsdlOption> 110 </wsdlOptions> 111 </configuration> 112 <goals> 113 <goal>wsdl2java</goal> 114 </goals> 115 </execution> 116 </executions> 117 </plugin> 118 <plugin> 119 <artifactId>maven-war-plugin</artifactId> 120 <version>2.1</version> 121 <executions> 122 <execution> 123 <id>dummyServiceWarGeneration</id> 124 <phase>process-test-classes</phase> 125 <configuration> 126 <webXml>${basedir}/src/main/webapp/WEB-INF/web.xml</webXml> 127 <outputDirectory>${project.build.directory}/test/tomcat/webapp</outputDirectory> 128 <warName>dummyService</warName> 129 </configuration> 130 <goals> 131 <goal>war</goal> 132 </goals> 133 </execution> 134 </executions> 135 </plugin> 136 </plugins> 137 <pluginManagement> 138 <plugins> 139 <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no 140 influence on the Maven build itself. --> 141 <plugin> 142 <groupId>org.eclipse.m2e</groupId> 143 <artifactId>lifecycle-mapping</artifactId> 144 <version>1.0.0</version> 145 <configuration> 146 <lifecycleMappingMetadata> 147 <pluginExecutions> 148 <pluginExecution> 149 <pluginExecutionFilter> 150 <groupId>org.apache.maven.plugins</groupId> 151 <artifactId>maven-war-plugin</artifactId> 152 <versionRange>[2.1,)</versionRange> 153 <goals> 154 <goal>war</goal> 155 </goals> 156 </pluginExecutionFilter> 157 <action> 158 <ignore></ignore> 159 </action> 160 </pluginExecution> 161 </pluginExecutions> 162 </lifecycleMappingMetadata> 163 </configuration> 164 </plugin> 165 </plugins> 166 </pluginManagement> 167 </build> 30 168 </project> -
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.