ndlesiecki 2003/06/21 20:39:14 Modified: framework/src/java/share/org/apache/cactus WebRequest.java AbstractWebServerTestCase.java HttpServiceDefinition.java framework/src/java/share/org/apache/cactus/client/connector/http DefaultHttpClient.java Log: Fixed checkstyle errors Revision Changes Path 1.20 +52 -43 jakarta-cactus/framework/src/java/share/org/apache/cactus/WebRequest.java Index: WebRequest.java =================================================================== RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/WebRequest.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- WebRequest.java 22 Jun 2003 02:52:32 -0000 1.19 +++ WebRequest.java 22 Jun 2003 03:39:14 -0000 1.20 @@ -77,9 +77,12 @@ */ public class WebRequest extends BaseWebRequest { + /** + * The unique identifier for this test case. + */ private String uniqueId; - - /** + + /** * The URL to simulate */ private ServletURL url; @@ -336,45 +339,51 @@ return sessionCookie; } - /** - * Adds a cactus-specific command to the URL - * The URL is used to allow the user to send whatever he wants - * in the request body. For example a file, ... - */ - public void addCactusCommand(String commandName, String commandValue) - { - if(!commandName.startsWith(HttpServiceDefinition.COMMAND)) - { - throw new IllegalArgumentException("Cactus commands must begin with " + - HttpServiceDefinition.COMMAND + - " offending command was " + - commandName); - } - addParameter(commandName, commandValue, GET_METHOD); - } - - /** - * Sets the unique id of the test case. Also adds - * a cactus command consisting of the id - * to the actual HTTP request. - */ - public void setUniqueId(String uniqueId) - { - if(this.uniqueId != null){ - throw new IllegalStateException("uniqueId already set!"); - } - this.uniqueId = uniqueId; - addCactusCommand(HttpServiceDefinition.TEST_ID, uniqueId); - } - - /** - * Gets the unique id of the test case. Also adds - * a cactus command consisting of the id - * to the actual HTTP request. - */ - public String getUniqueId() - { - return uniqueId; - } + /** + * Adds a cactus-specific command to the URL + * The URL is used to allow the user to send whatever he wants + * in the request body. For example a file, ... + * + * @param theCommandName The name of the command to add--must start with + * "Cactus_" + * @param theCommandValue Value of the command + */ + public void addCactusCommand(String theCommandName, String theCommandValue) + { + if (!theCommandName.startsWith(HttpServiceDefinition.COMMAND)) + { + throw new IllegalArgumentException( + "Cactus commands must begin with " + + HttpServiceDefinition.COMMAND + + " offending command was " + + theCommandName); + } + addParameter(theCommandName, theCommandValue, GET_METHOD); + } + + /** + * Sets the unique id of the test case. Also adds + * a cactus command consisting of the id + * to the actual HTTP request. + * @param theUniqueId new uniqueId for the test case associated + * with this request + */ + public void setUniqueId(String theUniqueId) + { + if (this.uniqueId != null) + { + throw new IllegalStateException("uniqueId already set!"); + } + this.uniqueId = theUniqueId; + addCactusCommand(HttpServiceDefinition.TEST_ID, theUniqueId); + } + + /** + * @return Gets the unique id of the test case + */ + public String getUniqueId() + { + return uniqueId; + } } 1.9 +84 -57 jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractWebServerTestCase.java Index: AbstractWebServerTestCase.java =================================================================== RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/AbstractWebServerTestCase.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- AbstractWebServerTestCase.java 22 Jun 2003 02:50:41 -0000 1.8 +++ AbstractWebServerTestCase.java 22 Jun 2003 03:39:14 -0000 1.9 @@ -76,7 +76,7 @@ * on the server side. * * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a> - * <a href="mailto:[EMAIL PROTECTED]>Nicholas Lesiecki</a> + * <a href="mailto:[EMAIL PROTECTED]>Nicholas Lesiecki</a> * * @version $Id$ */ @@ -240,31 +240,36 @@ * @exception Throwable any error that occurred when calling the test method * for the current test case. */ - private HttpURLConnection runWebTest(WebRequest theRequest, - DefaultHttpClient theHttpClient) throws Throwable + private HttpURLConnection runWebTest( + WebRequest theRequest, + DefaultHttpClient theHttpClient) + throws Throwable { // Add the class name, the method name, to the request to simulate and // automatic session creation flag to the request - addCactusCommand(HttpServiceDefinition.CLASS_NAME_PARAM, - this.getClass().getName(), - theRequest); - addCactusCommand(HttpServiceDefinition.METHOD_NAME_PARAM, - this.getCurrentTestMethod(), - theRequest); - addCactusCommand(HttpServiceDefinition.AUTOSESSION_NAME_PARAM, - theRequest.getAutomaticSession() ? "true" : "false", - theRequest); + addCactusCommand( + HttpServiceDefinition.CLASS_NAME_PARAM, + this.getClass().getName(), + theRequest); + addCactusCommand( + HttpServiceDefinition.METHOD_NAME_PARAM, + this.getCurrentTestMethod(), + theRequest); + addCactusCommand( + HttpServiceDefinition.AUTOSESSION_NAME_PARAM, + theRequest.getAutomaticSession() ? "true" : "false", + theRequest); - theRequest.setUniqueId(generateUniqueId()); + theRequest.setUniqueId(generateUniqueId()); // Add the wrapped test if it is not equal to our current instance if (wrappingATest()) { - addCactusCommand(HttpServiceDefinition.WRAPPED_CLASS_NAME_PARAM, - wrappedTestName(), - theRequest); + addCactusCommand( + HttpServiceDefinition.WRAPPED_CLASS_NAME_PARAM, + wrappedTestName(), + theRequest); } - // Add the simulated URL (if one has been defined) if (theRequest.getURL() != null) { @@ -279,45 +284,67 @@ return connection; } - private String wrappedTestName() - { - return getWrappedTest().getClass().getName(); - } - - private boolean wrappingATest() { - return getWrappedTest() != this; - } - - private String generateUniqueId() { - String id = "testCase:" +this.getClass().getName()+"_"; - id += "testMethod:" + this.getCurrentTestMethod()+"_"; - if(wrappingATest()){ - id += "wrapping:"+wrappedTestName()+"_"; - } - id += "thread:" + Thread.currentThread().toString()+"_"; - id += "runtime_hash:" + Runtime.getRuntime().hashCode()+"_"; - id += "client_ip:" + getIp()+"_"; - id += "time:" + System.currentTimeMillis()+"_"; - return id; - } - - private String getIp() - { - InetAddress thisIp; - try - { - thisIp = InetAddress.getLocalHost(); - } catch (UnknownHostException e) - { - throw new ChainedRuntimeException(e); - } - return thisIp.getHostAddress(); - } - - - private void addCactusCommand(String commandName, String commandValue, WebRequest theRequest) { - theRequest.addCactusCommand(commandName, commandValue); - } + /** + * Shortcut to the wrappedTest's name. + */ + private String wrappedTestName() + { + return getWrappedTest().getClass().getName(); + } + + /** + * Shortcut to determine wrapping of status. + */ + private boolean wrappingATest() + { + return getWrappedTest() != this; + } + + /** + * Generates a (possibly) unique id for this testcase. + */ + private String generateUniqueId() + { + String id = "testCase:" + this.getClass().getName() + "_"; + id += "testMethod:" + this.getCurrentTestMethod() + "_"; + if (wrappingATest()) + { + id += "wrapping:" + wrappedTestName() + "_"; + } + id += "thread:" + Thread.currentThread().toString() + "_"; + id += "runtime_hash:" + Runtime.getRuntime().hashCode() + "_"; + id += "client_ip:" + getIp() + "_"; + id += "time:" + System.currentTimeMillis() + "_"; + return id; + } + + /** + * Obtains the client machine's IP. + */ + private String getIp() + { + InetAddress thisIp; + try + { + thisIp = InetAddress.getLocalHost(); + } + catch (UnknownHostException e) + { + throw new ChainedRuntimeException(e); + } + return thisIp.getHostAddress(); + } + + /** + * Shortcut to addCactusCommand. + */ + private void addCactusCommand( + String theCommandName, + String theCommandValue, + WebRequest theRequest) + { + theRequest.addCactusCommand(theCommandName, theCommandValue); + } /** * Runs a test case. This method is overriden from the JUnit 1.10 +11 -9 jakarta-cactus/framework/src/java/share/org/apache/cactus/HttpServiceDefinition.java Index: HttpServiceDefinition.java =================================================================== RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/HttpServiceDefinition.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- HttpServiceDefinition.java 22 Jun 2003 02:51:19 -0000 1.9 +++ HttpServiceDefinition.java 22 Jun 2003 03:39:14 -0000 1.10 @@ -73,17 +73,19 @@ */ public interface HttpServiceDefinition { - - String COMMAND = "Cactus_"; + /** + * Prefix indicating that a String is an official Cactus command. + */ + String COMMAND = "Cactus_"; - /** - * Name of the parameter in the HTTP request that represents the unique id - * of the test case (to ensure that the client-side test gets the correct - * results). - */ + /** + * Name of the parameter in the HTTP request that represents the unique id + * of the test case (to ensure that the client-side test gets the correct + * results). + */ String TEST_ID = COMMAND + "UniqueId"; - /** + /** * Name of the parameter in the HTTP request that represents the name of the * Test class to call. The name is voluntarily long so that it will not * clash with a user-defined parameter. 1.7 +3 -2 jakarta-cactus/framework/src/java/share/org/apache/cactus/client/connector/http/DefaultHttpClient.java Index: DefaultHttpClient.java =================================================================== RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/client/connector/http/DefaultHttpClient.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- DefaultHttpClient.java 22 Jun 2003 02:48:54 -0000 1.6 +++ DefaultHttpClient.java 22 Jun 2003 03:39:14 -0000 1.7 @@ -223,7 +223,8 @@ { WebRequest resultsRequest = new WebRequest(this.configuration); - resultsRequest.addCactusCommand(HttpServiceDefinition.SERVICE_NAME_PARAM, + resultsRequest.addCactusCommand( + HttpServiceDefinition.SERVICE_NAME_PARAM, ServiceEnumeration.GET_RESULTS_SERVICE.toString()); // Use the same redirector as was used by the original request
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]