Index: integration/ant/build.xml =================================================================== RCS file: /home/cvs/jakarta-cactus/integration/ant/build.xml,v retrieving revision 1.61 diff -u -r1.61 build.xml --- integration/ant/build.xml 26 Apr 2005 09:57:59 -0000 1.61 +++ integration/ant/build.xml 21 Jul 2005 10:55:11 -0000 @@ -170,6 +170,8 @@ comment="Cactus Tasks for Ant"> + + this.timeout) + { + throw new BuildException("Failed to start the container after " + + "more than [" + this.timeout + "] ms. Trying to connect " + + "to the [" + this.contextURL + "] test URL yielded a [" + + responseCode + "] error code. Please run in debug mode " + + "for more details about the error."); + } + sleep(this.checkInterval); + + responseCode = testConnectivity(testURL); + } while (!isAvailable(responseCode)); + + + log("Starting up tests", Project.MSG_VERBOSE); + try + { + + Enumeration tests = getIndividualTests(); + while (tests.hasMoreElements()) + { + JUnitTest test = (JUnitTest) tests.nextElement(); + if (test.shouldRun(getProject())) + { + test.setTodir(toDir); + execute(test); + } + } + } + finally + { + log("Finishing tests", Project.MSG_VERBOSE); + + } + } + + /** + * Sets the enterprise application archive that will be tested. It must + * already contain the test-cases and the required libraries as a web + * module. + * + * @param theEarFile + * The EAR file to set + */ + public final void setEarFile(File theEarFile) + { + if (this.warFile != null) + { + throw new BuildException( + "You may only specify one of [earfile] and [warfile]"); + } + this.earFile = theEarFile; + } + + /** + * Sets the web application archive that will be tested. It must already + * contain the test-cases and the required libraries. + * + * @param theWarFile + * The WAR file to set + */ + public final void setWarFile(File theWarFile) + { + if (this.earFile != null) + { + throw new BuildException( + "You may only specify one of [earfile] and [warfile]"); + } + this.warFile = theWarFile; + } + + /** + * Sets the context url that will be tested. + * + * @param theContextURL + * The context + */ + public final void setContextURL(String theContextURL) + { + this.contextURL = theContextURL; + } + + /** + * Sets the web application archive that should be cactified. + * + * @param theToDir + * The test report to set + */ + public final void setToDir(File theToDir) + { + this.toDir = theToDir; + } + /** + * Sets the web application archive that should be cactified. + * + * @param theLogs + * Different logs define + */ + public final void setLogs(File theLogs) + { + this.logs = theLogs; + } + // Private Methods --------------------------------------------------------- + + /** + * Tests whether we are able to connect to the HTTP server identified by the + * specified URL. + * + * @param theUrl The URL to check + * @return the HTTP response code or -1 if no connection could be + * established + */ + private int testConnectivity(URL theUrl) + { + int code; + try + { + HttpURLConnection connection = + (HttpURLConnection) theUrl.openConnection(); + connection.setRequestProperty("Connection", "close"); + connection.connect(); + readFully(connection); + connection.disconnect(); + code = connection.getResponseCode(); + } + catch (IOException e) + { + log("Failed to connect to [" + theUrl + "]", Project.MSG_DEBUG); + code = -1; + } + return code; + } + + + /** + * Tests whether an HTTP return code corresponds to a valid connection + * to the test URL or not. Success is 200 up to but excluding 300. + * + * @param theCode the HTTP response code to verify + * @return true if the test URL could be called without error, + * false otherwise + */ + private boolean isAvailable(int theCode) + { + boolean result; + if ((theCode != -1) && (theCode < 300)) + { + result = true; + } + else + { + result = false; + } + return result; + } + + /** + * Retrieves the server name of the container. + * + * @param theUrl The URL to retrieve + * @return The server name, or null if the server name could + * not be retrieved + */ + private String retrieveServerName(URL theUrl) + { + String retVal = null; + try + { + HttpURLConnection connection = + (HttpURLConnection) theUrl.openConnection(); + connection.connect(); + retVal = connection.getHeaderField("Server"); + connection.disconnect(); + } + catch (IOException e) + { + log("Could not get server name from [" + + theUrl + "]", Project.MSG_DEBUG); + } + return retVal; + } + + /** + * Fully reads the input stream from the passed HTTP URL connection to + * prevent (harmless) server-side exception. + * + * @param theConnection the HTTP URL connection to read from + * @exception IOException if an error happens during the read + */ + static void readFully(HttpURLConnection theConnection) + throws IOException + { + // Only read if there is data to read ... The problem is that not + // all servers return a content-length header. If there is no header + // getContentLength() returns -1. It seems to work and it seems + // that all servers that return no content-length header also do + // not block on read() operations! + if (theConnection.getContentLength() != 0) + { + byte[] buf = new byte[256]; + InputStream in = theConnection.getInputStream(); + while (in.read(buf) != -1) + { + // Make sure we read all the data in the stream + } + } + } + + /** + * Pauses the current thread for the specified amount. + * + * @param theMs The time to sleep in milliseconds + * @throws BuildException If the sleeping thread is interrupted + */ + private void sleep(long theMs) throws BuildException + { + try + { + Thread.sleep(theMs); + } + catch (InterruptedException e) + { + throw new BuildException("Interruption during sleep", e); + } + } + /** + * @param theTimeout the timeout after which we stop trying to call the test + * URL. + */ + public void setTimeout(long theTimeout) + { + this.timeout = theTimeout; + } + /** + * Set up the logs + */ + public void setupLogs() + { + + if (this.logs == null) + { + throw new BuildException("Missing 'logs' attribute"); + } + + ResourceBundle bundle = null; + try + { + bundle = new PropertyResourceBundle( + new FileInputStream(this.logs)); + } + catch (IOException e) + { + throw new BuildException("Failed to load properties " + + "file [" + this.logs + "]"); + } + Enumeration keys = bundle.getKeys(); + while (keys.hasMoreElements()) + { + String key = (String) keys.nextElement(); + Variable var = new Variable(); + var.setKey(key); + var.setValue(bundle.getString(key)); + super.addSysproperty(var); + + } + + } +} Index: samples/servlet/src/scripts/share/build.xml =================================================================== RCS file: /home/cvs/jakarta-cactus/samples/servlet/src/scripts/share/build.xml,v retrieving revision 1.32 diff -u -r1.32 build.xml --- samples/servlet/src/scripts/share/build.xml 21 Jul 2005 03:40:00 -0000 1.32 +++ samples/servlet/src/scripts/share/build.xml 21 Jul 2005 10:55:19 -0000 @@ -116,6 +116,8 @@ location="../../lib/@junit.jar.name@"/> + @@ -151,7 +153,7 @@ (check your build.properties file) - + @@ -315,144 +317,150 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <@clover.begin@pathelement location="${clover.jar}"/@clover.end@> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Running tests on ${containerKey} container... + + + + + + + + + Not running tests on ${containerKey} container as [cactus.home.${containerKey}] property not defined + + + + + + + + + + + + + + - - - - - - - - - - <@clover.begin@pathelement location="${clover.jar}"/@clover.end@> - + - - - <@clover.begin@pathelement location="${clover.jar}"/@clover.end@> - - - - - - + + + + + + + + + - - <@j2ee13.begin@jboss3x if="cactus.home.jboss3x" - dir="${cactus.home.jboss3x}" - output="${target.testreports.dir}/jboss3x.out" - todir="${target.testreports.dir}/jboss3x"/@j2ee13.end@> - - - - - <@j2ee12.begin@tomcat3x if="cactus.home.tomcat3x" - dir="${cactus.home.tomcat3x}" port="${cactus.port}" - output="${target.testreports.dir}/tomcat3x.out" - todir="${target.testreports.dir}/tomcat3x"/@j2ee12.end@> - - - - - - - - - - - - - - - - - - - - - - - - - - <@j2ee13.begin@junitreport todir="${target.testreports.dir}/jboss3x"> - - - - - - - - - - - - - - - - <@j2ee12.begin@junitreport todir="${target.testreports.dir}/tomcat3x"> - - - - - - - - - - - - - - - At least one test failed!