modules/plugins/netservices/pom.xml | 15 +++--- modules/plugins/netservices/src/test/java/org/rhq/plugins/netservices/itest/HTTPNetServiceComponentTest.java | 25 +++++++++- 2 files changed, 32 insertions(+), 8 deletions(-)
New commits: commit 244a9489ab126f59fc7559f6547a7949b3c0b2dd Author: Thomas Segismont tsegismo@redhat.com Date: Wed Feb 27 13:58:43 2013 +0100
Netservices plugin: make itest http port configurable (useful for Jenkins multijob context)
diff --git a/modules/plugins/netservices/pom.xml b/modules/plugins/netservices/pom.xml index 184f1db..4a661a0 100644 --- a/modules/plugins/netservices/pom.xml +++ b/modules/plugins/netservices/pom.xml @@ -16,6 +16,10 @@ <name>RHQ Network Services Plugin</name> <description>A plugin for monitoring network services.</description>
+ <properties> + <netservices.itest.http.server.port>31158</netservices.itest.http.server.port> + </properties> + <dependencies>
<dependency> @@ -111,6 +115,9 @@ </properties> <useSystemClassLoader>false</useSystemClassLoader> <argLine>${jacoco.integration-test.args}</argLine> + <systemPropertyVariables> + <netservices.itest.http.server.port>${netservices.itest.http.server.port}</netservices.itest.http.server.port> + </systemPropertyVariables> </configuration> <executions> <execution> @@ -167,11 +174,9 @@
<build> <plugins> - <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> - <execution> <id>deploy</id> <phase>compile</phase> @@ -187,7 +192,6 @@ <goal>run</goal> </goals> </execution> - <execution> <id>deploy-jar-meta-inf</id> <phase>package</phase> @@ -209,7 +213,6 @@ <goal>run</goal> </goals> </execution> - <execution> <id>undeploy</id> <phase>clean</phase> @@ -224,13 +227,13 @@ <goal>run</goal> </goals> </execution> - </executions> </plugin> - </plugins> </build> + </profile> + </profiles>
</project> diff --git a/modules/plugins/netservices/src/test/java/org/rhq/plugins/netservices/itest/HTTPNetServiceComponentTest.java b/modules/plugins/netservices/src/test/java/org/rhq/plugins/netservices/itest/HTTPNetServiceComponentTest.java index 24b6644..fc02516 100644 --- a/modules/plugins/netservices/src/test/java/org/rhq/plugins/netservices/itest/HTTPNetServiceComponentTest.java +++ b/modules/plugins/netservices/src/test/java/org/rhq/plugins/netservices/itest/HTTPNetServiceComponentTest.java @@ -53,6 +53,7 @@ import org.rhq.core.domain.measurement.MeasurementData; import org.rhq.core.domain.measurement.MeasurementReport; import org.rhq.core.domain.measurement.MeasurementScheduleRequest; import org.rhq.core.pluginapi.inventory.ResourceComponent; +import org.rhq.core.util.StringUtil; import org.rhq.plugins.netservices.HTTPNetServiceComponent; import org.rhq.plugins.netservices.HTTPNetServiceComponent.ConfigKeys; import org.rhq.plugins.netservices.HTTPNetServiceComponent.HttpMethod; @@ -70,8 +71,12 @@ public class HTTPNetServiceComponentTest extends NetServiceComponentTest {
private static final int HTTP_PORT = 31158;
+ private static final String HTTP_PORT_VARIABLE = "netservices.itest.http.server.port"; + private static final int SERVLET_SLEEP = 1000;
+ private int httpPort; + private Server jettyServer;
private HTTPNetServiceComponent httpNetServiceComponent; @@ -79,7 +84,8 @@ public class HTTPNetServiceComponentTest extends NetServiceComponentTest { @BeforeClass public void startJetty() throws Exception { LOG.info("Setting up Jetty test server"); - jettyServer = new Server(new InetSocketAddress(HTTP_HOST, HTTP_PORT)); + httpPort = getJettyPort(); + jettyServer = new Server(new InetSocketAddress(HTTP_HOST, httpPort)); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); jettyServer.setHandler(context); @@ -101,6 +107,21 @@ public class HTTPNetServiceComponentTest extends NetServiceComponentTest { jettyServer.start(); }
+ private static int getJettyPort() { + String httpPortVariable = System.getProperty(HTTP_PORT_VARIABLE); + if (StringUtil.isNotBlank(httpPortVariable)) { + try { + int port = Integer.parseInt(httpPortVariable); + LOG.info("Using port " + httpPortVariable + " for http server"); + return port; + } catch (NumberFormatException e) { + LOG.warn("Invalid port variable: " + httpPortVariable); + } + } + LOG.info("Using default port " + String.valueOf(HTTP_PORT) + " for http server"); + return HTTP_PORT; + } + @AfterClass public void stopJetty() { LOG.info("Shutting down Jetty test server"); @@ -115,7 +136,7 @@ public class HTTPNetServiceComponentTest extends NetServiceComponentTest { @Test(dependsOnMethods = "testPluginLoad") public void testManualAdd() throws Exception { Configuration configuration = new Configuration(); - configuration.setSimpleValue(ConfigKeys.URL, "http://" + HTTP_HOST + ":" + HTTP_PORT + "/pipo/molo"); + configuration.setSimpleValue(ConfigKeys.URL, "http://" + HTTP_HOST + ":" + httpPort + "/pipo/molo"); configuration.setSimpleValue(ConfigKeys.METHOD, HttpMethod.GET.name()); configuration.setSimpleValue(ConfigKeys.VALIDATE_RESPONSE_CODE, "true"); configuration.setSimpleValue(ConfigKeys.VALIDATE_RESPONSE_PATTERN, "success");
rhq-commits@lists.fedorahosted.org