You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2008/07/06 22:28:50 UTC
svn commit: r674342 [1/3] - in
/jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions: ./ gui/
Author: sebb
Date: Sun Jul 6 13:28:49 2008
New Revision: 674342
URL: http://svn.apache.org/viewvc?rev=674342&view=rev
Log:
Detab
Modified:
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/BSFAssertionBeanInfo.java
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/BeanShellAssertion.java
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/DurationAssertion.java
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/HTMLAssertion.java
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/MD5HexAssertion.java
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/ResponseAssertion.java
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/SizeAssertion.java
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/XMLAssertion.java
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/AssertionGui.java
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/BeanShellAssertionGui.java
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/DurationAssertionGui.java
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/HTMLAssertionGui.java
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/MD5HexAssertionGUI.java
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/SizeAssertionGui.java
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/XMLAssertionGui.java
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/XMLConfPanel.java
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/XMLSchemaAssertionGUI.java
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/XPathAssertionGui.java
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/XPathPanel.java
Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/BSFAssertionBeanInfo.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/BSFAssertionBeanInfo.java?rev=674342&r1=674341&r2=674342&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/BSFAssertionBeanInfo.java (original)
+++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/BSFAssertionBeanInfo.java Sun Jul 6 13:28:49 2008
@@ -22,8 +22,8 @@
public class BSFAssertionBeanInfo extends BSFBeanInfoSupport {
- public BSFAssertionBeanInfo() {
- super(BSFAssertion.class);
- }
+ public BSFAssertionBeanInfo() {
+ super(BSFAssertion.class);
+ }
}
Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/BeanShellAssertion.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/BeanShellAssertion.java?rev=674342&r1=674341&r2=674342&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/BeanShellAssertion.java (original)
+++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/BeanShellAssertion.java Sun Jul 6 13:28:49 2008
@@ -33,123 +33,123 @@
*
*/
public class BeanShellAssertion extends BeanShellTestElement implements Assertion {
- private static final Logger log = LoggingManager.getLoggerForClass();
+ private static final Logger log = LoggingManager.getLoggerForClass();
private static final long serialVersionUID = 3;
- public static final String FILENAME = "BeanShellAssertion.filename"; //$NON-NLS-1$
+ public static final String FILENAME = "BeanShellAssertion.filename"; //$NON-NLS-1$
- public static final String SCRIPT = "BeanShellAssertion.query"; //$NON-NLS-1$
+ public static final String SCRIPT = "BeanShellAssertion.query"; //$NON-NLS-1$
- public static final String PARAMETERS = "BeanShellAssertion.parameters"; //$NON-NLS-1$
+ public static final String PARAMETERS = "BeanShellAssertion.parameters"; //$NON-NLS-1$
public static final String RESET_INTERPRETER = "BeanShellAssertion.resetInterpreter"; //$NON-NLS-1$
- // can be specified in jmeter.properties
- public static final String INIT_FILE = "beanshell.assertion.init"; //$NON-NLS-1$
+ // can be specified in jmeter.properties
+ public static final String INIT_FILE = "beanshell.assertion.init"; //$NON-NLS-1$
protected String getInitFileProperty() {
return INIT_FILE;
}
- public String getScript() {
- return getPropertyAsString(SCRIPT);
- }
-
- public String getFilename() {
- return getPropertyAsString(FILENAME);
- }
-
- public String getParameters() {
- return getPropertyAsString(PARAMETERS);
- }
+ public String getScript() {
+ return getPropertyAsString(SCRIPT);
+ }
+
+ public String getFilename() {
+ return getPropertyAsString(FILENAME);
+ }
+
+ public String getParameters() {
+ return getPropertyAsString(PARAMETERS);
+ }
public boolean isResetInterpreter() {
return getPropertyAsBoolean(RESET_INTERPRETER);
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.jmeter.assertions.Assertion#getResult(org.apache.jmeter.samplers.SampleResult)
- */
- public AssertionResult getResult(SampleResult response) {
- AssertionResult result = new AssertionResult(getName());
-
- final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();
- if (bshInterpreter == null) {
- result.setFailure(true);
- result.setError(true);
- result.setFailureMessage("BeanShell Interpreter not found");
- return result;
- }
- try {
- String request = getScript();
- String fileName = getFilename();
-
- bshInterpreter.set("FileName", getFilename());//$NON-NLS-1$
- // Set params as a single line
- bshInterpreter.set("Parameters", getParameters()); // $NON-NLS-1$
- bshInterpreter.set("bsh.args",//$NON-NLS-1$
- JOrphanUtils.split(getParameters(), " "));//$NON-NLS-1$
-
- // Add SamplerData for consistency with BeanShell Sampler
- bshInterpreter.set("SampleResult", response); //$NON-NLS-1$
- bshInterpreter.set("Response", response); //$NON-NLS-1$
- bshInterpreter.set("ResponseData", response.getResponseData());//$NON-NLS-1$
- bshInterpreter.set("ResponseCode", response.getResponseCode());//$NON-NLS-1$
- bshInterpreter.set("ResponseMessage", response.getResponseMessage());//$NON-NLS-1$
- bshInterpreter.set("ResponseHeaders", response.getResponseHeaders());//$NON-NLS-1$
- bshInterpreter.set("RequestHeaders", response.getRequestHeaders());//$NON-NLS-1$
- bshInterpreter.set("SampleLabel", response.getSampleLabel());//$NON-NLS-1$
- bshInterpreter.set("SamplerData", response.getSamplerData());//$NON-NLS-1$
- bshInterpreter.set("Successful", response.isSuccessful());//$NON-NLS-1$
-
- // The following are used to set the Result details on return from
- // the script:
- bshInterpreter.set("FailureMessage", "");//$NON-NLS-1$ //$NON-NLS-2$
- bshInterpreter.set("Failure", false);//$NON-NLS-1$
-
- // Add variables for access to context and variables
- JMeterContext jmctx = JMeterContextService.getContext();
- JMeterVariables vars = jmctx.getVariables();
- bshInterpreter.set("ctx", jmctx);//$NON-NLS-1$
- bshInterpreter.set("vars", vars);//$NON-NLS-1$
-
- // Object bshOut;
-
- if (fileName.length() == 0) {
- // bshOut =
- bshInterpreter.eval(request);
- } else {
- // bshOut =
- bshInterpreter.source(fileName);
- }
-
- result.setFailureMessage(bshInterpreter.get("FailureMessage").toString());//$NON-NLS-1$
- result.setFailure(Boolean.valueOf(bshInterpreter.get("Failure") //$NON-NLS-1$
- .toString()).booleanValue());
- result.setError(false);
- }
- /*
- * To avoid class loading problems when the BSH jar is missing, we don't
- * try to catch this error separately catch (bsh.EvalError ex) {
- * log.debug("",ex); result.setError(true);
- * result.setFailureMessage(ex.toString()); }
- */
- // but we do trap this error to make tests work better
- catch (NoClassDefFoundError ex) {
- log.error("BeanShell Jar missing? " + ex.toString());
- result.setError(true);
- result.setFailureMessage("BeanShell Jar missing? " + ex.toString());
- response.setStopThread(true); // No point continuing
- } catch (Exception ex) // Mainly for bsh.EvalError
- {
- result.setError(true);
- result.setFailureMessage(ex.toString());
- log.warn(ex.toString());
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.jmeter.assertions.Assertion#getResult(org.apache.jmeter.samplers.SampleResult)
+ */
+ public AssertionResult getResult(SampleResult response) {
+ AssertionResult result = new AssertionResult(getName());
+
+ final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();
+ if (bshInterpreter == null) {
+ result.setFailure(true);
+ result.setError(true);
+ result.setFailureMessage("BeanShell Interpreter not found");
+ return result;
+ }
+ try {
+ String request = getScript();
+ String fileName = getFilename();
+
+ bshInterpreter.set("FileName", getFilename());//$NON-NLS-1$
+ // Set params as a single line
+ bshInterpreter.set("Parameters", getParameters()); // $NON-NLS-1$
+ bshInterpreter.set("bsh.args",//$NON-NLS-1$
+ JOrphanUtils.split(getParameters(), " "));//$NON-NLS-1$
+
+ // Add SamplerData for consistency with BeanShell Sampler
+ bshInterpreter.set("SampleResult", response); //$NON-NLS-1$
+ bshInterpreter.set("Response", response); //$NON-NLS-1$
+ bshInterpreter.set("ResponseData", response.getResponseData());//$NON-NLS-1$
+ bshInterpreter.set("ResponseCode", response.getResponseCode());//$NON-NLS-1$
+ bshInterpreter.set("ResponseMessage", response.getResponseMessage());//$NON-NLS-1$
+ bshInterpreter.set("ResponseHeaders", response.getResponseHeaders());//$NON-NLS-1$
+ bshInterpreter.set("RequestHeaders", response.getRequestHeaders());//$NON-NLS-1$
+ bshInterpreter.set("SampleLabel", response.getSampleLabel());//$NON-NLS-1$
+ bshInterpreter.set("SamplerData", response.getSamplerData());//$NON-NLS-1$
+ bshInterpreter.set("Successful", response.isSuccessful());//$NON-NLS-1$
+
+ // The following are used to set the Result details on return from
+ // the script:
+ bshInterpreter.set("FailureMessage", "");//$NON-NLS-1$ //$NON-NLS-2$
+ bshInterpreter.set("Failure", false);//$NON-NLS-1$
+
+ // Add variables for access to context and variables
+ JMeterContext jmctx = JMeterContextService.getContext();
+ JMeterVariables vars = jmctx.getVariables();
+ bshInterpreter.set("ctx", jmctx);//$NON-NLS-1$
+ bshInterpreter.set("vars", vars);//$NON-NLS-1$
+
+ // Object bshOut;
+
+ if (fileName.length() == 0) {
+ // bshOut =
+ bshInterpreter.eval(request);
+ } else {
+ // bshOut =
+ bshInterpreter.source(fileName);
+ }
+
+ result.setFailureMessage(bshInterpreter.get("FailureMessage").toString());//$NON-NLS-1$
+ result.setFailure(Boolean.valueOf(bshInterpreter.get("Failure") //$NON-NLS-1$
+ .toString()).booleanValue());
+ result.setError(false);
+ }
+ /*
+ * To avoid class loading problems when the BSH jar is missing, we don't
+ * try to catch this error separately catch (bsh.EvalError ex) {
+ * log.debug("",ex); result.setError(true);
+ * result.setFailureMessage(ex.toString()); }
+ */
+ // but we do trap this error to make tests work better
+ catch (NoClassDefFoundError ex) {
+ log.error("BeanShell Jar missing? " + ex.toString());
+ result.setError(true);
+ result.setFailureMessage("BeanShell Jar missing? " + ex.toString());
+ response.setStopThread(true); // No point continuing
+ } catch (Exception ex) // Mainly for bsh.EvalError
+ {
+ result.setError(true);
+ result.setFailureMessage(ex.toString());
+ log.warn(ex.toString());
+ }
- return result;
- }
+ return result;
+ }
}
Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/DurationAssertion.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/DurationAssertion.java?rev=674342&r1=674341&r2=674342&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/DurationAssertion.java (original)
+++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/DurationAssertion.java Sun Jul 6 13:28:49 2008
@@ -33,40 +33,40 @@
* @version $Revision$, $Date$
*/
public class DurationAssertion extends AbstractTestElement implements Serializable, Assertion {
- /** Key for storing assertion-informations in the jmx-file. */
- public static final String DURATION_KEY = "DurationAssertion.duration"; // $NON-NLS-1$
+ /** Key for storing assertion-informations in the jmx-file. */
+ public static final String DURATION_KEY = "DurationAssertion.duration"; // $NON-NLS-1$
- /**
- * Returns the result of the Assertion. Here it checks wether the Sample
- * took to long to be considered successful. If so an AssertionResult
- * containing a FailureMessage will be returned. Otherwise the returned
- * AssertionResult will reflect the success of the Sample.
- */
- public AssertionResult getResult(SampleResult response) {
- AssertionResult result = new AssertionResult(getName());
- result.setFailure(false);
- long duration=getAllowedDuration();
- if (duration > 0) {
- long responseTime=response.getTime();
- // has the Sample lasted too long?
- if ( responseTime > duration) {
- result.setFailure(true);
- Object[] arguments = { new Long(responseTime), new Long(duration) };
- String message = MessageFormat.format(
- JMeterUtils.getResString("duration_assertion_failure") // $NON-NLS-1$
- , arguments);
- result.setFailureMessage(message);
- }
- }
- return result;
- }
+ /**
+ * Returns the result of the Assertion. Here it checks wether the Sample
+ * took to long to be considered successful. If so an AssertionResult
+ * containing a FailureMessage will be returned. Otherwise the returned
+ * AssertionResult will reflect the success of the Sample.
+ */
+ public AssertionResult getResult(SampleResult response) {
+ AssertionResult result = new AssertionResult(getName());
+ result.setFailure(false);
+ long duration=getAllowedDuration();
+ if (duration > 0) {
+ long responseTime=response.getTime();
+ // has the Sample lasted too long?
+ if ( responseTime > duration) {
+ result.setFailure(true);
+ Object[] arguments = { new Long(responseTime), new Long(duration) };
+ String message = MessageFormat.format(
+ JMeterUtils.getResString("duration_assertion_failure") // $NON-NLS-1$
+ , arguments);
+ result.setFailureMessage(message);
+ }
+ }
+ return result;
+ }
- /**
- * Returns the duration to be asserted. A duration of 0 indicates this
- * assertion is to be ignored.
- */
- private long getAllowedDuration() {
- return getPropertyAsLong(DURATION_KEY);
- }
+ /**
+ * Returns the duration to be asserted. A duration of 0 indicates this
+ * assertion is to be ignored.
+ */
+ private long getAllowedDuration() {
+ return getPropertyAsLong(DURATION_KEY);
+ }
-}
\ No newline at end of file
+}
Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/HTMLAssertion.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/HTMLAssertion.java?rev=674342&r1=674341&r2=674342&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/HTMLAssertion.java (original)
+++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/HTMLAssertion.java Sun Jul 6 13:28:49 2008
@@ -46,321 +46,321 @@
private static final Logger log = LoggingManager.getLoggerForClass();
- public static final String DEFAULT_DOCTYPE = "omit"; //$NON-NLS-1$
+ public static final String DEFAULT_DOCTYPE = "omit"; //$NON-NLS-1$
- public static final String DOCTYPE_KEY = "html_assertion_doctype"; //$NON-NLS-1$
+ public static final String DOCTYPE_KEY = "html_assertion_doctype"; //$NON-NLS-1$
- public static final String ERRORS_ONLY_KEY = "html_assertion_errorsonly"; //$NON-NLS-1$
+ public static final String ERRORS_ONLY_KEY = "html_assertion_errorsonly"; //$NON-NLS-1$
- public static final String ERROR_THRESHOLD_KEY = "html_assertion_error_threshold"; //$NON-NLS-1$
+ public static final String ERROR_THRESHOLD_KEY = "html_assertion_error_threshold"; //$NON-NLS-1$
- public static final String WARNING_THRESHOLD_KEY = "html_assertion_warning_threshold"; //$NON-NLS-1$
-
- public static final String FORMAT_KEY = "html_assertion_format"; //$NON-NLS-1$
-
- public static final String FILENAME_KEY = "html_assertion_filename"; //$NON-NLS-1$
-
- /**
- *
- */
- public HTMLAssertion() {
- log.debug("HTMLAssertion(): called");
- }
-
- /**
- * Returns the result of the Assertion. If so an AssertionResult containing
- * a FailureMessage will be returned. Otherwise the returned AssertionResult
- * will reflect the success of the Sample.
- */
- public AssertionResult getResult(SampleResult inResponse) {
- log.debug("HTMLAssertions.getResult() called");
-
- // no error as default
- AssertionResult result = new AssertionResult(getName());
-
- if (inResponse.getResponseData().length == 0) {
- return result.setResultForNull();
- }
-
- result.setFailure(false);
-
- // create parser
- Tidy tidy = null;
- try {
- log.debug("HTMLAssertions.getResult(): Setup tidy ...");
- log.debug("doctype: " + getDoctype());
- log.debug("errors only: " + isErrorsOnly());
- log.debug("error threshold: " + getErrorThreshold());
- log.debug("warning threshold: " + getWarningThreshold());
- log.debug("html mode: " + isHTML());
- log.debug("xhtml mode: " + isXHTML());
- log.debug("xml mode: " + isXML());
- tidy = new Tidy();
- tidy.setCharEncoding(org.w3c.tidy.Configuration.UTF8);
- tidy.setQuiet(false);
- tidy.setShowWarnings(true);
- tidy.setOnlyErrors(isErrorsOnly());
- tidy.setDocType(getDoctype());
- if (isXHTML()) {
- tidy.setXHTML(true);
- } else if (isXML()) {
- tidy.setXmlTags(true);
- }
- log.debug("err file: " + getFilename());
- tidy.setErrfile(getFilename());
-
- if (log.isDebugEnabled()) {
- log.debug("getParser : tidy parser created - " + tidy);
- }
- log.debug("HTMLAssertions.getResult(): Tidy instance created!");
-
- } catch (Exception e) {//TODO replace with proper Exception
- log.error("Unable to instantiate tidy parser", e);
- result.setFailure(true);
- result.setFailureMessage("Unable to instantiate tidy parser");
- // return with an error
- return result;
- }
-
- /*
- * Run tidy.
- */
- try {
- log.debug("HTMLAssertions.getResult(): start parsing with tidy ...");
-
- StringWriter errbuf = new StringWriter();
- tidy.setErrout(new PrintWriter(errbuf));
- // Node node = tidy.parseDOM(new
- // ByteArrayInputStream(response.getResponseData()), null);
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- log.debug("Start : parse");
- Node node = tidy.parse(new ByteArrayInputStream(inResponse.getResponseData()), os);
- if (log.isDebugEnabled()) {
- log.debug("node : " + node);
- }
- log.debug("End : parse");
- log.debug("HTMLAssertions.getResult(): parsing with tidy done!");
- log.debug("Output: " + os.toString());
-
- // write output to file
- writeOutput(errbuf.toString());
-
- // evaluate result
- if ((tidy.getParseErrors() > getErrorThreshold())
- || (!isErrorsOnly() && (tidy.getParseWarnings() > getWarningThreshold()))) {
- log.debug("HTMLAssertions.getResult(): errors/warnings detected:");
- log.debug(errbuf.toString());
- result.setFailure(true);
- result.setFailureMessage(MessageFormat.format("Tidy Parser errors: " + tidy.getParseErrors()
- + " (allowed " + getErrorThreshold() + ") " + "Tidy Parser warnings: "
- + tidy.getParseWarnings() + " (allowed " + getWarningThreshold() + ")", new Object[0]));
- // return with an error
-
- } else if ((tidy.getParseErrors() > 0) || (tidy.getParseWarnings() > 0)) {
- // return with no error
- log.debug("HTMLAssertions.getResult(): there were errors/warnings but threshold to high");
- result.setFailure(false);
- } else {
- // return with no error
- log.debug("HTMLAssertions.getResult(): no errors/warnings detected:");
- result.setFailure(false);
- }
-
- } catch (Exception e) {//TODO replace with proper Exception
- // return with an error
- log.warn("Cannot parse result content", e);
- result.setFailure(true);
- result.setFailureMessage(e.getMessage());
- }
- return result;
- }
-
- /**
- * Writes the output of tidy to file.
- *
- * @param inOutput
- */
- private void writeOutput(String inOutput) {
- String lFilename = getFilename();
-
- // check if filename defined
- if ((lFilename != null) && (!"".equals(lFilename.trim()))) {
- FileWriter lOutputWriter = null;
- try {
-
- // open file
- lOutputWriter = new FileWriter(lFilename, false);
-
- // write to file
- lOutputWriter.write(inOutput);
-
- // flush
- lOutputWriter.flush();
-
- log.debug("writeOutput() -> output successfully written to file " + lFilename);
-
- } catch (IOException ex) {
- log.warn("writeOutput() -> could not write output to file " + lFilename, ex);
- } finally {
- // close file
- IOUtils.closeQuietly(lOutputWriter);
- }
- }
- }
-
- /**
- * Gets the doctype
- *
- * @return the documemt type
- */
- public String getDoctype() {
- return getPropertyAsString(DOCTYPE_KEY);
- }
-
- /**
- * Check if errors will be reported only
- *
- * @return boolean - report errors only?
- */
- public boolean isErrorsOnly() {
- return getPropertyAsBoolean(ERRORS_ONLY_KEY);
- }
-
- /**
- * Gets the threshold setting for errors
- *
- * @return long error threshold
- */
- public long getErrorThreshold() {
- return getPropertyAsLong(ERROR_THRESHOLD_KEY);
- }
-
- /**
- * Gets the threshold setting for warnings
- *
- * @return long warning threshold
- */
- public long getWarningThreshold() {
- return getPropertyAsLong(WARNING_THRESHOLD_KEY);
- }
-
- /**
- * Sets the doctype setting
- *
- * @param inDoctype
- */
- public void setDoctype(String inDoctype) {
- if ((inDoctype == null) || (inDoctype.trim().equals(""))) {
- setProperty(new StringProperty(DOCTYPE_KEY, DEFAULT_DOCTYPE));
- } else {
- setProperty(new StringProperty(DOCTYPE_KEY, inDoctype));
- }
- }
-
- /**
- * Sets if errors shoud be tracked only
- *
- * @param inErrorsOnly
- */
- public void setErrorsOnly(boolean inErrorsOnly) {
- setProperty(new BooleanProperty(ERRORS_ONLY_KEY, inErrorsOnly));
- }
-
- /**
- * Sets the threshold on error level
- *
- * @param inErrorThreshold
- */
- public void setErrorThreshold(long inErrorThreshold) {
- if (inErrorThreshold < 0L) {
- throw new IllegalArgumentException(JMeterUtils.getResString("argument_must_not_be_negative")); //$NON-NLS-1$
- }
- if (inErrorThreshold == Long.MAX_VALUE) {
- setProperty(new LongProperty(ERROR_THRESHOLD_KEY, 0));
- } else {
- setProperty(new LongProperty(ERROR_THRESHOLD_KEY, inErrorThreshold));
- }
- }
-
- /**
- * Sets the threshold on warning level
- *
- * @param inWarningThreshold
- */
- public void setWarningThreshold(long inWarningThreshold) {
- if (inWarningThreshold < 0L) {
- throw new IllegalArgumentException(JMeterUtils.getResString("argument_must_not_be_negative")); //$NON-NLS-1$
- }
- if (inWarningThreshold == Long.MAX_VALUE) {
- setProperty(new LongProperty(WARNING_THRESHOLD_KEY, 0));
- } else {
- setProperty(new LongProperty(WARNING_THRESHOLD_KEY, inWarningThreshold));
- }
- }
-
- /**
- * Enables html validation mode
- */
- public void setHTML() {
- setProperty(new LongProperty(FORMAT_KEY, 0));
- }
-
- /**
- * Check if html validation mode is set
- *
- * @return boolean
- */
- public boolean isHTML() {
- return getPropertyAsLong(FORMAT_KEY) == 0;
- }
-
- /**
- * Enables xhtml validation mode
- */
- public void setXHTML() {
- setProperty(new LongProperty(FORMAT_KEY, 1));
- }
-
- /**
- * Check if xhtml validation mode is set
- *
- * @return boolean
- */
- public boolean isXHTML() {
- return getPropertyAsLong(FORMAT_KEY) == 1;
- }
-
- /**
- * Enables xml validation mode
- */
- public void setXML() {
- setProperty(new LongProperty(FORMAT_KEY, 2));
- }
-
- /**
- * Check if xml validation mode is set
- *
- * @return boolean
- */
- public boolean isXML() {
- return getPropertyAsLong(FORMAT_KEY) == 2;
- }
-
- /**
- * Sets the name of the file where tidy writes the output to
- *
- * @return name of file
- */
- public String getFilename() {
- return getPropertyAsString(FILENAME_KEY);
- }
-
- /**
- * Sets the name of the tidy output file
- *
- * @param inName
- */
- public void setFilename(String inName) {
- setProperty(FILENAME_KEY, inName);
- }
+ public static final String WARNING_THRESHOLD_KEY = "html_assertion_warning_threshold"; //$NON-NLS-1$
+
+ public static final String FORMAT_KEY = "html_assertion_format"; //$NON-NLS-1$
+
+ public static final String FILENAME_KEY = "html_assertion_filename"; //$NON-NLS-1$
+
+ /**
+ *
+ */
+ public HTMLAssertion() {
+ log.debug("HTMLAssertion(): called");
+ }
+
+ /**
+ * Returns the result of the Assertion. If so an AssertionResult containing
+ * a FailureMessage will be returned. Otherwise the returned AssertionResult
+ * will reflect the success of the Sample.
+ */
+ public AssertionResult getResult(SampleResult inResponse) {
+ log.debug("HTMLAssertions.getResult() called");
+
+ // no error as default
+ AssertionResult result = new AssertionResult(getName());
+
+ if (inResponse.getResponseData().length == 0) {
+ return result.setResultForNull();
+ }
+
+ result.setFailure(false);
+
+ // create parser
+ Tidy tidy = null;
+ try {
+ log.debug("HTMLAssertions.getResult(): Setup tidy ...");
+ log.debug("doctype: " + getDoctype());
+ log.debug("errors only: " + isErrorsOnly());
+ log.debug("error threshold: " + getErrorThreshold());
+ log.debug("warning threshold: " + getWarningThreshold());
+ log.debug("html mode: " + isHTML());
+ log.debug("xhtml mode: " + isXHTML());
+ log.debug("xml mode: " + isXML());
+ tidy = new Tidy();
+ tidy.setCharEncoding(org.w3c.tidy.Configuration.UTF8);
+ tidy.setQuiet(false);
+ tidy.setShowWarnings(true);
+ tidy.setOnlyErrors(isErrorsOnly());
+ tidy.setDocType(getDoctype());
+ if (isXHTML()) {
+ tidy.setXHTML(true);
+ } else if (isXML()) {
+ tidy.setXmlTags(true);
+ }
+ log.debug("err file: " + getFilename());
+ tidy.setErrfile(getFilename());
+
+ if (log.isDebugEnabled()) {
+ log.debug("getParser : tidy parser created - " + tidy);
+ }
+ log.debug("HTMLAssertions.getResult(): Tidy instance created!");
+
+ } catch (Exception e) {//TODO replace with proper Exception
+ log.error("Unable to instantiate tidy parser", e);
+ result.setFailure(true);
+ result.setFailureMessage("Unable to instantiate tidy parser");
+ // return with an error
+ return result;
+ }
+
+ /*
+ * Run tidy.
+ */
+ try {
+ log.debug("HTMLAssertions.getResult(): start parsing with tidy ...");
+
+ StringWriter errbuf = new StringWriter();
+ tidy.setErrout(new PrintWriter(errbuf));
+ // Node node = tidy.parseDOM(new
+ // ByteArrayInputStream(response.getResponseData()), null);
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ log.debug("Start : parse");
+ Node node = tidy.parse(new ByteArrayInputStream(inResponse.getResponseData()), os);
+ if (log.isDebugEnabled()) {
+ log.debug("node : " + node);
+ }
+ log.debug("End : parse");
+ log.debug("HTMLAssertions.getResult(): parsing with tidy done!");
+ log.debug("Output: " + os.toString());
+
+ // write output to file
+ writeOutput(errbuf.toString());
+
+ // evaluate result
+ if ((tidy.getParseErrors() > getErrorThreshold())
+ || (!isErrorsOnly() && (tidy.getParseWarnings() > getWarningThreshold()))) {
+ log.debug("HTMLAssertions.getResult(): errors/warnings detected:");
+ log.debug(errbuf.toString());
+ result.setFailure(true);
+ result.setFailureMessage(MessageFormat.format("Tidy Parser errors: " + tidy.getParseErrors()
+ + " (allowed " + getErrorThreshold() + ") " + "Tidy Parser warnings: "
+ + tidy.getParseWarnings() + " (allowed " + getWarningThreshold() + ")", new Object[0]));
+ // return with an error
+
+ } else if ((tidy.getParseErrors() > 0) || (tidy.getParseWarnings() > 0)) {
+ // return with no error
+ log.debug("HTMLAssertions.getResult(): there were errors/warnings but threshold to high");
+ result.setFailure(false);
+ } else {
+ // return with no error
+ log.debug("HTMLAssertions.getResult(): no errors/warnings detected:");
+ result.setFailure(false);
+ }
+
+ } catch (Exception e) {//TODO replace with proper Exception
+ // return with an error
+ log.warn("Cannot parse result content", e);
+ result.setFailure(true);
+ result.setFailureMessage(e.getMessage());
+ }
+ return result;
+ }
+
+ /**
+ * Writes the output of tidy to file.
+ *
+ * @param inOutput
+ */
+ private void writeOutput(String inOutput) {
+ String lFilename = getFilename();
+
+ // check if filename defined
+ if ((lFilename != null) && (!"".equals(lFilename.trim()))) {
+ FileWriter lOutputWriter = null;
+ try {
+
+ // open file
+ lOutputWriter = new FileWriter(lFilename, false);
+
+ // write to file
+ lOutputWriter.write(inOutput);
+
+ // flush
+ lOutputWriter.flush();
+
+ log.debug("writeOutput() -> output successfully written to file " + lFilename);
+
+ } catch (IOException ex) {
+ log.warn("writeOutput() -> could not write output to file " + lFilename, ex);
+ } finally {
+ // close file
+ IOUtils.closeQuietly(lOutputWriter);
+ }
+ }
+ }
+
+ /**
+ * Gets the doctype
+ *
+ * @return the documemt type
+ */
+ public String getDoctype() {
+ return getPropertyAsString(DOCTYPE_KEY);
+ }
+
+ /**
+ * Check if errors will be reported only
+ *
+ * @return boolean - report errors only?
+ */
+ public boolean isErrorsOnly() {
+ return getPropertyAsBoolean(ERRORS_ONLY_KEY);
+ }
+
+ /**
+ * Gets the threshold setting for errors
+ *
+ * @return long error threshold
+ */
+ public long getErrorThreshold() {
+ return getPropertyAsLong(ERROR_THRESHOLD_KEY);
+ }
+
+ /**
+ * Gets the threshold setting for warnings
+ *
+ * @return long warning threshold
+ */
+ public long getWarningThreshold() {
+ return getPropertyAsLong(WARNING_THRESHOLD_KEY);
+ }
+
+ /**
+ * Sets the doctype setting
+ *
+ * @param inDoctype
+ */
+ public void setDoctype(String inDoctype) {
+ if ((inDoctype == null) || (inDoctype.trim().equals(""))) {
+ setProperty(new StringProperty(DOCTYPE_KEY, DEFAULT_DOCTYPE));
+ } else {
+ setProperty(new StringProperty(DOCTYPE_KEY, inDoctype));
+ }
+ }
+
+ /**
+ * Sets if errors shoud be tracked only
+ *
+ * @param inErrorsOnly
+ */
+ public void setErrorsOnly(boolean inErrorsOnly) {
+ setProperty(new BooleanProperty(ERRORS_ONLY_KEY, inErrorsOnly));
+ }
+
+ /**
+ * Sets the threshold on error level
+ *
+ * @param inErrorThreshold
+ */
+ public void setErrorThreshold(long inErrorThreshold) {
+ if (inErrorThreshold < 0L) {
+ throw new IllegalArgumentException(JMeterUtils.getResString("argument_must_not_be_negative")); //$NON-NLS-1$
+ }
+ if (inErrorThreshold == Long.MAX_VALUE) {
+ setProperty(new LongProperty(ERROR_THRESHOLD_KEY, 0));
+ } else {
+ setProperty(new LongProperty(ERROR_THRESHOLD_KEY, inErrorThreshold));
+ }
+ }
+
+ /**
+ * Sets the threshold on warning level
+ *
+ * @param inWarningThreshold
+ */
+ public void setWarningThreshold(long inWarningThreshold) {
+ if (inWarningThreshold < 0L) {
+ throw new IllegalArgumentException(JMeterUtils.getResString("argument_must_not_be_negative")); //$NON-NLS-1$
+ }
+ if (inWarningThreshold == Long.MAX_VALUE) {
+ setProperty(new LongProperty(WARNING_THRESHOLD_KEY, 0));
+ } else {
+ setProperty(new LongProperty(WARNING_THRESHOLD_KEY, inWarningThreshold));
+ }
+ }
+
+ /**
+ * Enables html validation mode
+ */
+ public void setHTML() {
+ setProperty(new LongProperty(FORMAT_KEY, 0));
+ }
+
+ /**
+ * Check if html validation mode is set
+ *
+ * @return boolean
+ */
+ public boolean isHTML() {
+ return getPropertyAsLong(FORMAT_KEY) == 0;
+ }
+
+ /**
+ * Enables xhtml validation mode
+ */
+ public void setXHTML() {
+ setProperty(new LongProperty(FORMAT_KEY, 1));
+ }
+
+ /**
+ * Check if xhtml validation mode is set
+ *
+ * @return boolean
+ */
+ public boolean isXHTML() {
+ return getPropertyAsLong(FORMAT_KEY) == 1;
+ }
+
+ /**
+ * Enables xml validation mode
+ */
+ public void setXML() {
+ setProperty(new LongProperty(FORMAT_KEY, 2));
+ }
+
+ /**
+ * Check if xml validation mode is set
+ *
+ * @return boolean
+ */
+ public boolean isXML() {
+ return getPropertyAsLong(FORMAT_KEY) == 2;
+ }
+
+ /**
+ * Sets the name of the file where tidy writes the output to
+ *
+ * @return name of file
+ */
+ public String getFilename() {
+ return getPropertyAsString(FILENAME_KEY);
+ }
+
+ /**
+ * Sets the name of the tidy output file
+ *
+ * @param inName
+ */
+ public void setFilename(String inName) {
+ setProperty(FILENAME_KEY, inName);
+ }
}
Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/MD5HexAssertion.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/MD5HexAssertion.java?rev=674342&r1=674341&r2=674342&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/MD5HexAssertion.java (original)
+++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/MD5HexAssertion.java Sun Jul 6 13:28:49 2008
@@ -22,7 +22,7 @@
* The assertion will fail when the expected hex is different from the <br/>
* one calculated from the response OR when the expected hex is left empty.
*
- * @author <a href="mailto:jh@domek.be">Jorg Heymans</a>
+ * @author <a href="mailto:jh@domek.be">Jorg Heymans</a>
*/
package org.apache.jmeter.assertions;
@@ -41,70 +41,70 @@
public class MD5HexAssertion extends AbstractTestElement implements Serializable, Assertion {
- private static final Logger log = LoggingManager.getLoggerForClass();
+ private static final Logger log = LoggingManager.getLoggerForClass();
- /** Key for storing assertion-informations in the jmx-file. */
- private static final String MD5HEX_KEY = "MD5HexAssertion.size";
+ /** Key for storing assertion-informations in the jmx-file. */
+ private static final String MD5HEX_KEY = "MD5HexAssertion.size";
- /*
- * @param response @return
- */
- public AssertionResult getResult(SampleResult response) {
-
- AssertionResult result = new AssertionResult(getName());
- result.setFailure(false);
- byte[] resultData = response.getResponseData();
-
- if (resultData.length == 0) {
- result.setError(false);
- result.setFailure(true);
- result.setFailureMessage("Response was null");
- return result;
- }
-
- // no point in checking if we don't have anything to compare against
- if (getAllowedMD5Hex().equals("")) {
- result.setError(false);
- result.setFailure(true);
- result.setFailureMessage("MD5Hex to test against is empty");
- return result;
- }
-
- String md5Result = baMD5Hex(resultData);
-
- // String md5Result = DigestUtils.md5Hex(resultData);
-
- if (!md5Result.equalsIgnoreCase(getAllowedMD5Hex())) {
- result.setFailure(true);
-
- Object[] arguments = { md5Result, getAllowedMD5Hex() };
- String message = MessageFormat.format(JMeterUtils.getResString("md5hex_assertion_failure"), arguments); // $NON-NLS-1$
- result.setFailureMessage(message);
-
- }
-
- return result;
- }
-
- public void setAllowedMD5Hex(String hex) {
- setProperty(new StringProperty(MD5HexAssertion.MD5HEX_KEY, hex));
- }
-
- public String getAllowedMD5Hex() {
- return getPropertyAsString(MD5HexAssertion.MD5HEX_KEY);
- }
-
- // package protected so can be accessed by test class
- static String baMD5Hex(byte ba[]) {
- byte[] md5Result = {};
-
- try {
- MessageDigest md;
- md = MessageDigest.getInstance("MD5");
- md5Result = md.digest(ba);
- } catch (NoSuchAlgorithmException e) {
- log.error("", e);
- }
- return JOrphanUtils.baToHexString(md5Result);
- }
+ /*
+ * @param response @return
+ */
+ public AssertionResult getResult(SampleResult response) {
+
+ AssertionResult result = new AssertionResult(getName());
+ result.setFailure(false);
+ byte[] resultData = response.getResponseData();
+
+ if (resultData.length == 0) {
+ result.setError(false);
+ result.setFailure(true);
+ result.setFailureMessage("Response was null");
+ return result;
+ }
+
+ // no point in checking if we don't have anything to compare against
+ if (getAllowedMD5Hex().equals("")) {
+ result.setError(false);
+ result.setFailure(true);
+ result.setFailureMessage("MD5Hex to test against is empty");
+ return result;
+ }
+
+ String md5Result = baMD5Hex(resultData);
+
+ // String md5Result = DigestUtils.md5Hex(resultData);
+
+ if (!md5Result.equalsIgnoreCase(getAllowedMD5Hex())) {
+ result.setFailure(true);
+
+ Object[] arguments = { md5Result, getAllowedMD5Hex() };
+ String message = MessageFormat.format(JMeterUtils.getResString("md5hex_assertion_failure"), arguments); // $NON-NLS-1$
+ result.setFailureMessage(message);
+
+ }
+
+ return result;
+ }
+
+ public void setAllowedMD5Hex(String hex) {
+ setProperty(new StringProperty(MD5HexAssertion.MD5HEX_KEY, hex));
+ }
+
+ public String getAllowedMD5Hex() {
+ return getPropertyAsString(MD5HexAssertion.MD5HEX_KEY);
+ }
+
+ // package protected so can be accessed by test class
+ static String baMD5Hex(byte ba[]) {
+ byte[] md5Result = {};
+
+ try {
+ MessageDigest md;
+ md = MessageDigest.getInstance("MD5");
+ md5Result = md.digest(ba);
+ } catch (NoSuchAlgorithmException e) {
+ log.error("", e);
+ }
+ return JOrphanUtils.baToHexString(md5Result);
+ }
}
Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/ResponseAssertion.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/ResponseAssertion.java?rev=674342&r1=674341&r2=674342&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/ResponseAssertion.java (original)
+++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/ResponseAssertion.java Sun Jul 6 13:28:49 2008
@@ -43,39 +43,39 @@
* Test element to handle Response Assertions, @see AssertionGui
*/
public class ResponseAssertion extends AbstractTestElement implements Serializable, Assertion {
- private static final Logger log = LoggingManager.getLoggerForClass();
+ private static final Logger log = LoggingManager.getLoggerForClass();
- private final static String TEST_FIELD = "Assertion.test_field"; // $NON-NLS-1$
+ private final static String TEST_FIELD = "Assertion.test_field"; // $NON-NLS-1$
- // Values for TEST_FIELD
- // N.B. we cannot change the text value as it is in test plans
- private final static String SAMPLE_URL = "Assertion.sample_label"; // $NON-NLS-1$
+ // Values for TEST_FIELD
+ // N.B. we cannot change the text value as it is in test plans
+ private final static String SAMPLE_URL = "Assertion.sample_label"; // $NON-NLS-1$
- private final static String RESPONSE_DATA = "Assertion.response_data"; // $NON-NLS-1$
+ private final static String RESPONSE_DATA = "Assertion.response_data"; // $NON-NLS-1$
- private final static String RESPONSE_CODE = "Assertion.response_code"; // $NON-NLS-1$
+ private final static String RESPONSE_CODE = "Assertion.response_code"; // $NON-NLS-1$
- private final static String RESPONSE_MESSAGE = "Assertion.response_message"; // $NON-NLS-1$
+ private final static String RESPONSE_MESSAGE = "Assertion.response_message"; // $NON-NLS-1$
- private final static String RESPONSE_HEADERS = "Assertion.response_headers"; // $NON-NLS-1$
+ private final static String RESPONSE_HEADERS = "Assertion.response_headers"; // $NON-NLS-1$
- private final static String ASSUME_SUCCESS = "Assertion.assume_success"; // $NON-NLS-1$
+ private final static String ASSUME_SUCCESS = "Assertion.assume_success"; // $NON-NLS-1$
- private final static String TEST_STRINGS = "Asserion.test_strings"; // $NON-NLS-1$
+ private final static String TEST_STRINGS = "Asserion.test_strings"; // $NON-NLS-1$
- private final static String TEST_TYPE = "Assertion.test_type"; // $NON-NLS-1$
+ private final static String TEST_TYPE = "Assertion.test_type"; // $NON-NLS-1$
- /*
- * Mask values for TEST_TYPE TODO: remove either MATCH or CONTAINS - they
- * are mutually exckusive
- */
- private final static int MATCH = 1 << 0;
+ /*
+ * Mask values for TEST_TYPE TODO: remove either MATCH or CONTAINS - they
+ * are mutually exckusive
+ */
+ private final static int MATCH = 1 << 0;
- final static int CONTAINS = 1 << 1;
+ final static int CONTAINS = 1 << 1;
- private final static int NOT = 1 << 2;
+ private final static int NOT = 1 << 2;
- private final static int EQUALS = 1 << 3;
+ private final static int EQUALS = 1 << 3;
private final static int SUBSTRING = 1 << 4;
@@ -95,324 +95,324 @@
private static final String DIFF_DELTA_END
= JMeterUtils.getPropDefault("assertion.equals_diff_delta_end", "]]]");
- public ResponseAssertion() {
- setProperty(new CollectionProperty(TEST_STRINGS, new ArrayList()));
- }
-
- public void clear() {
- super.clear();
- setProperty(new CollectionProperty(TEST_STRINGS, new ArrayList()));
- }
-
- private void setTestField(String testField) {
- setProperty(TEST_FIELD, testField);
- }
-
- public void setTestFieldURL(){
- setTestField(SAMPLE_URL);
- }
-
- public void setTestFieldResponseCode(){
- setTestField(RESPONSE_CODE);
- }
-
- public void setTestFieldResponseData(){
- setTestField(RESPONSE_DATA);
- }
-
- public void setTestFieldResponseMessage(){
- setTestField(RESPONSE_MESSAGE);
- }
-
- public void setTestFieldResponseHeaders(){
- setTestField(RESPONSE_HEADERS);
- }
-
- public boolean isTestFieldURL(){
- return SAMPLE_URL.equals(getTestField());
- }
-
- public boolean isTestFieldResponseCode(){
- return RESPONSE_CODE.equals(getTestField());
- }
-
- public boolean isTestFieldResponseData(){
- return RESPONSE_DATA.equals(getTestField());
- }
-
- public boolean isTestFieldResponseMessage(){
- return RESPONSE_MESSAGE.equals(getTestField());
- }
-
- public boolean isTestFieldResponseHeaders(){
- return RESPONSE_HEADERS.equals(getTestField());
- }
-
- private void setTestType(int testType) {
- setProperty(new IntegerProperty(TEST_TYPE, testType));
- }
+ public ResponseAssertion() {
+ setProperty(new CollectionProperty(TEST_STRINGS, new ArrayList()));
+ }
+
+ public void clear() {
+ super.clear();
+ setProperty(new CollectionProperty(TEST_STRINGS, new ArrayList()));
+ }
+
+ private void setTestField(String testField) {
+ setProperty(TEST_FIELD, testField);
+ }
+
+ public void setTestFieldURL(){
+ setTestField(SAMPLE_URL);
+ }
+
+ public void setTestFieldResponseCode(){
+ setTestField(RESPONSE_CODE);
+ }
+
+ public void setTestFieldResponseData(){
+ setTestField(RESPONSE_DATA);
+ }
+
+ public void setTestFieldResponseMessage(){
+ setTestField(RESPONSE_MESSAGE);
+ }
+
+ public void setTestFieldResponseHeaders(){
+ setTestField(RESPONSE_HEADERS);
+ }
+
+ public boolean isTestFieldURL(){
+ return SAMPLE_URL.equals(getTestField());
+ }
+
+ public boolean isTestFieldResponseCode(){
+ return RESPONSE_CODE.equals(getTestField());
+ }
+
+ public boolean isTestFieldResponseData(){
+ return RESPONSE_DATA.equals(getTestField());
+ }
+
+ public boolean isTestFieldResponseMessage(){
+ return RESPONSE_MESSAGE.equals(getTestField());
+ }
+
+ public boolean isTestFieldResponseHeaders(){
+ return RESPONSE_HEADERS.equals(getTestField());
+ }
+
+ private void setTestType(int testType) {
+ setProperty(new IntegerProperty(TEST_TYPE, testType));
+ }
private void setTestTypeMasked(int testType) {
int value = getTestType() & ~(TYPE_MASK) | testType;
setProperty(new IntegerProperty(TEST_TYPE, value));
}
- public void addTestString(String testString) {
- getTestStrings().addProperty(new StringProperty(String.valueOf(testString.hashCode()), testString));
- }
-
- public void clearTestStrings() {
- getTestStrings().clear();
- }
-
- public AssertionResult getResult(SampleResult response) {
- AssertionResult result;
-
- // None of the other Assertions check the response status, so remove
- // this check
- // for the time being, at least...
- // if (!response.isSuccessful())
- // {
- // result = new AssertionResult();
- // result.setError(true);
- // byte [] ba = response.getResponseData();
- // result.setFailureMessage(
- // ba == null ? "Unknown Error (responseData is empty)" : new String(ba)
- // );
- // return result;
- // }
-
- result = evaluateResponse(response);
- return result;
- }
-
- /***************************************************************************
- * !ToDoo (Method description)
- *
- * @return !ToDo (Return description)
- **************************************************************************/
- public String getTestField() {
- return getPropertyAsString(TEST_FIELD);
- }
-
- /***************************************************************************
- * !ToDoo (Method description)
- *
- * @return !ToDo (Return description)
- **************************************************************************/
- public int getTestType() {
- JMeterProperty type = getProperty(TEST_TYPE);
- if (type instanceof NullProperty) {
- return CONTAINS;
- }
- return type.getIntValue();
- }
-
- /***************************************************************************
- * !ToDoo (Method description)
- *
- * @return !ToDo (Return description)
- **************************************************************************/
- public CollectionProperty getTestStrings() {
- return (CollectionProperty) getProperty(TEST_STRINGS);
- }
-
- public boolean isEqualsType() {
- return (getTestType() & EQUALS) > 0;
- }
+ public void addTestString(String testString) {
+ getTestStrings().addProperty(new StringProperty(String.valueOf(testString.hashCode()), testString));
+ }
+
+ public void clearTestStrings() {
+ getTestStrings().clear();
+ }
+
+ public AssertionResult getResult(SampleResult response) {
+ AssertionResult result;
+
+ // None of the other Assertions check the response status, so remove
+ // this check
+ // for the time being, at least...
+ // if (!response.isSuccessful())
+ // {
+ // result = new AssertionResult();
+ // result.setError(true);
+ // byte [] ba = response.getResponseData();
+ // result.setFailureMessage(
+ // ba == null ? "Unknown Error (responseData is empty)" : new String(ba)
+ // );
+ // return result;
+ // }
+
+ result = evaluateResponse(response);
+ return result;
+ }
+
+ /***************************************************************************
+ * !ToDoo (Method description)
+ *
+ * @return !ToDo (Return description)
+ **************************************************************************/
+ public String getTestField() {
+ return getPropertyAsString(TEST_FIELD);
+ }
+
+ /***************************************************************************
+ * !ToDoo (Method description)
+ *
+ * @return !ToDo (Return description)
+ **************************************************************************/
+ public int getTestType() {
+ JMeterProperty type = getProperty(TEST_TYPE);
+ if (type instanceof NullProperty) {
+ return CONTAINS;
+ }
+ return type.getIntValue();
+ }
+
+ /***************************************************************************
+ * !ToDoo (Method description)
+ *
+ * @return !ToDo (Return description)
+ **************************************************************************/
+ public CollectionProperty getTestStrings() {
+ return (CollectionProperty) getProperty(TEST_STRINGS);
+ }
+
+ public boolean isEqualsType() {
+ return (getTestType() & EQUALS) > 0;
+ }
public boolean isSubstringType() {
return (getTestType() & SUBSTRING) > 0;
}
- public boolean isContainsType() {
- return (getTestType() & CONTAINS) > 0;
- }
-
- public boolean isMatchType() {
- return (getTestType() & MATCH) > 0;
- }
-
- public boolean isNotType() {
- return (getTestType() & NOT) > 0;
- }
-
- public void setToContainsType() {
- setTestTypeMasked(CONTAINS);
- }
-
- public void setToMatchType() {
- setTestTypeMasked(MATCH);
- }
-
- public void setToEqualsType() {
- setTestTypeMasked(EQUALS);
- }
+ public boolean isContainsType() {
+ return (getTestType() & CONTAINS) > 0;
+ }
+
+ public boolean isMatchType() {
+ return (getTestType() & MATCH) > 0;
+ }
+
+ public boolean isNotType() {
+ return (getTestType() & NOT) > 0;
+ }
+
+ public void setToContainsType() {
+ setTestTypeMasked(CONTAINS);
+ }
+
+ public void setToMatchType() {
+ setTestTypeMasked(MATCH);
+ }
+
+ public void setToEqualsType() {
+ setTestTypeMasked(EQUALS);
+ }
public void setToSubstringType() {
setTestTypeMasked(SUBSTRING);
}
- public void setToNotType() {
- setTestType((getTestType() | NOT));
- }
-
- public void unsetNotType() {
- setTestType(getTestType() & ~NOT);
- }
-
- public boolean getAssumeSuccess() {
- return getPropertyAsBoolean(ASSUME_SUCCESS, false);
- }
-
- public void setAssumeSuccess(boolean b) {
- setProperty(ASSUME_SUCCESS, b);
- }
-
- /**
- * Make sure the response satisfies the specified assertion requirements.
- *
- * @param response
- * an instance of SampleResult
- * @return an instance of AssertionResult
- */
- AssertionResult evaluateResponse(SampleResult response) {
- boolean pass = true;
- boolean not = (NOT & getTestType()) > 0;
- AssertionResult result = new AssertionResult(getName());
- String toCheck = ""; // The string to check (Url or data)
-
- if (getAssumeSuccess()) {
- response.setSuccessful(true);// Allow testing of failure codes
- }
-
- // What are we testing against?
- if (isTestFieldResponseData()) {
- toCheck = response.getResponseDataAsString(); // (bug25052)
- } else if (isTestFieldResponseCode()) {
- toCheck = response.getResponseCode();
- } else if (isTestFieldResponseMessage()) {
- toCheck = response.getResponseMessage();
- } else if (isTestFieldResponseHeaders()) {
- toCheck = response.getResponseHeaders();
- } else { // Assume it is the URL
- toCheck = response.getSamplerData(); // TODO - is this where the URL is stored?
- if (toCheck == null) {
- toCheck = "";
- }
- }
-
- if (toCheck.length() == 0) {
- return result.setResultForNull();
- }
+ public void setToNotType() {
+ setTestType((getTestType() | NOT));
+ }
+
+ public void unsetNotType() {
+ setTestType(getTestType() & ~NOT);
+ }
+
+ public boolean getAssumeSuccess() {
+ return getPropertyAsBoolean(ASSUME_SUCCESS, false);
+ }
+
+ public void setAssumeSuccess(boolean b) {
+ setProperty(ASSUME_SUCCESS, b);
+ }
+
+ /**
+ * Make sure the response satisfies the specified assertion requirements.
+ *
+ * @param response
+ * an instance of SampleResult
+ * @return an instance of AssertionResult
+ */
+ AssertionResult evaluateResponse(SampleResult response) {
+ boolean pass = true;
+ boolean not = (NOT & getTestType()) > 0;
+ AssertionResult result = new AssertionResult(getName());
+ String toCheck = ""; // The string to check (Url or data)
+
+ if (getAssumeSuccess()) {
+ response.setSuccessful(true);// Allow testing of failure codes
+ }
+
+ // What are we testing against?
+ if (isTestFieldResponseData()) {
+ toCheck = response.getResponseDataAsString(); // (bug25052)
+ } else if (isTestFieldResponseCode()) {
+ toCheck = response.getResponseCode();
+ } else if (isTestFieldResponseMessage()) {
+ toCheck = response.getResponseMessage();
+ } else if (isTestFieldResponseHeaders()) {
+ toCheck = response.getResponseHeaders();
+ } else { // Assume it is the URL
+ toCheck = response.getSamplerData(); // TODO - is this where the URL is stored?
+ if (toCheck == null) {
+ toCheck = "";
+ }
+ }
+
+ if (toCheck.length() == 0) {
+ return result.setResultForNull();
+ }
- result.setFailure(false);
- result.setError(false);
+ result.setFailure(false);
+ result.setError(false);
- boolean contains = isContainsType(); // do it once outside loop
- boolean equals = isEqualsType();
+ boolean contains = isContainsType(); // do it once outside loop
+ boolean equals = isEqualsType();
boolean substring = isSubstringType();
- boolean debugEnabled = log.isDebugEnabled();
- if (debugEnabled){
- log.debug("Type:" + (contains?"Contains":"Match") + (not? "(not)": ""));
- }
-
- try {
- // Get the Matcher for this thread
- Perl5Matcher localMatcher = JMeterUtils.getMatcher();
- PropertyIterator iter = getTestStrings().iterator();
- while (iter.hasNext()) {
- String stringPattern = iter.next().getStringValue();
- Pattern pattern = JMeterUtils.getPatternCache().getPattern(stringPattern, Perl5Compiler.READ_ONLY_MASK);
- boolean found;
- if (contains) {
- found = localMatcher.contains(toCheck, pattern);
+ boolean debugEnabled = log.isDebugEnabled();
+ if (debugEnabled){
+ log.debug("Type:" + (contains?"Contains":"Match") + (not? "(not)": ""));
+ }
+
+ try {
+ // Get the Matcher for this thread
+ Perl5Matcher localMatcher = JMeterUtils.getMatcher();
+ PropertyIterator iter = getTestStrings().iterator();
+ while (iter.hasNext()) {
+ String stringPattern = iter.next().getStringValue();
+ Pattern pattern = JMeterUtils.getPatternCache().getPattern(stringPattern, Perl5Compiler.READ_ONLY_MASK);
+ boolean found;
+ if (contains) {
+ found = localMatcher.contains(toCheck, pattern);
} else if (equals) {
found = toCheck.equals(stringPattern);
} else if (substring) {
found = toCheck.indexOf(stringPattern) != -1;
- } else {
- found = localMatcher.matches(toCheck, pattern);
- }
- pass = not ? !found : found;
- if (!pass) {
- if (debugEnabled){log.debug("Failed: "+pattern);}
- result.setFailure(true);
- result.setFailureMessage(getFailText(stringPattern,toCheck));
- break;
- }
- if (debugEnabled){log.debug("Passed: "+pattern);}
- }
- } catch (MalformedCachePatternException e) {
- result.setError(true);
- result.setFailure(false);
- result.setFailureMessage("Bad test configuration " + e);
- }
- return result;
- }
-
- /**
- * Generate the failure reason from the TestType
- *
- * @param stringPattern
- * @return the message for the assertion report
- */
- // TODO strings should be resources
- private String getFailText(String stringPattern, String toCheck) {
-
- StringBuffer sb = new StringBuffer(200);
- sb.append("Test failed: ");
-
- if (isTestFieldResponseData()) {
- sb.append("text");
- } else if (isTestFieldResponseCode()) {
- sb.append("code");
- } else if (isTestFieldResponseMessage()) {
- sb.append("message");
- } else if (isTestFieldResponseHeaders()) {
- sb.append("headers");
- } else // Assume it is the URL
- {
- sb.append("URL");
- }
+ } else {
+ found = localMatcher.matches(toCheck, pattern);
+ }
+ pass = not ? !found : found;
+ if (!pass) {
+ if (debugEnabled){log.debug("Failed: "+pattern);}
+ result.setFailure(true);
+ result.setFailureMessage(getFailText(stringPattern,toCheck));
+ break;
+ }
+ if (debugEnabled){log.debug("Passed: "+pattern);}
+ }
+ } catch (MalformedCachePatternException e) {
+ result.setError(true);
+ result.setFailure(false);
+ result.setFailureMessage("Bad test configuration " + e);
+ }
+ return result;
+ }
+
+ /**
+ * Generate the failure reason from the TestType
+ *
+ * @param stringPattern
+ * @return the message for the assertion report
+ */
+ // TODO strings should be resources
+ private String getFailText(String stringPattern, String toCheck) {
+
+ StringBuffer sb = new StringBuffer(200);
+ sb.append("Test failed: ");
- switch (getTestType()) {
- case CONTAINS:
+ if (isTestFieldResponseData()) {
+ sb.append("text");
+ } else if (isTestFieldResponseCode()) {
+ sb.append("code");
+ } else if (isTestFieldResponseMessage()) {
+ sb.append("message");
+ } else if (isTestFieldResponseHeaders()) {
+ sb.append("headers");
+ } else // Assume it is the URL
+ {
+ sb.append("URL");
+ }
+
+ switch (getTestType()) {
+ case CONTAINS:
case SUBSTRING:
- sb.append(" expected to contain ");
- break;
- case NOT | CONTAINS:
+ sb.append(" expected to contain ");
+ break;
+ case NOT | CONTAINS:
case NOT | SUBSTRING:
- sb.append(" expected not to contain ");
- break;
- case MATCH:
- sb.append(" expected to match ");
- break;
- case NOT | MATCH:
- sb.append(" expected not to match ");
- break;
- case EQUALS:
- sb.append(" expected to equal ");
- break;
- case NOT | EQUALS:
- sb.append(" expected not to equal ");
- break;
- default:// should never happen...
- sb.append(" expected something using ");
- }
-
- sb.append("/");
-
- if (isEqualsType()){
- sb.append(equalsComparisonText(toCheck, stringPattern));
- } else {
- sb.append(stringPattern);
- }
-
- sb.append("/");
-
- return sb.toString();
- }
+ sb.append(" expected not to contain ");
+ break;
+ case MATCH:
+ sb.append(" expected to match ");
+ break;
+ case NOT | MATCH:
+ sb.append(" expected not to match ");
+ break;
+ case EQUALS:
+ sb.append(" expected to equal ");
+ break;
+ case NOT | EQUALS:
+ sb.append(" expected not to equal ");
+ break;
+ default:// should never happen...
+ sb.append(" expected something using ");
+ }
+
+ sb.append("/");
+
+ if (isEqualsType()){
+ sb.append(equalsComparisonText(toCheck, stringPattern));
+ } else {
+ sb.append(stringPattern);
+ }
+
+ sb.append("/");
+
+ return sb.toString();
+ }
private static String trunc(final boolean right, final String str)
Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/SizeAssertion.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/SizeAssertion.java?rev=674342&r1=674341&r2=674342&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/SizeAssertion.java (original)
+++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/SizeAssertion.java Sun Jul 6 13:28:49 2008
@@ -35,131 +35,131 @@
*/
public class SizeAssertion extends AbstractTestElement implements Serializable, Assertion {
- private transient String comparatorErrorMessage;// Only used for communication with compareSize()
+ private transient String comparatorErrorMessage;// Only used for communication with compareSize()
- // * Static int to signify the type of logical comparitor to assert
- public final static int EQUAL = 1;
+ // * Static int to signify the type of logical comparitor to assert
+ public final static int EQUAL = 1;
- public final static int NOTEQUAL = 2;
+ public final static int NOTEQUAL = 2;
- public final static int GREATERTHAN = 3;
+ public final static int GREATERTHAN = 3;
- public final static int LESSTHAN = 4;
-
- public final static int GREATERTHANEQUAL = 5;
-
- public final static int LESSTHANEQUAL = 6;
-
- /** Key for storing assertion-informations in the jmx-file. */
- private static final String SIZE_KEY = "SizeAssertion.size"; // $NON-NLS-1$
-
- private static final String OPERATOR_KEY = "SizeAssertion.operator"; // $NON-NLS-1$
-
- /**
- * Returns the result of the Assertion.
- * Here it checks the Sample responseData length.
- */
- public AssertionResult getResult(SampleResult response) {
- AssertionResult result = new AssertionResult(getName());
- result.setFailure(false);
- long resultSize = response.getBytes();
- // is the Sample the correct size?
- if (!(compareSize(resultSize))) {
- result.setFailure(true);
- Object[] arguments = { new Long(resultSize), comparatorErrorMessage, new Long(getAllowedSize()) };
- String message = MessageFormat.format(JMeterUtils.getResString("size_assertion_failure"), arguments); //$NON-NLS-1$
- result.setFailureMessage(message);
- }
- return result;
- }
-
- /**
- * Returns the size in bytes to be asserted.
- */
- public long getAllowedSize() {
- return getPropertyAsLong(SIZE_KEY);
- }
-
- /***************************************************************************
- * set the Operator
- **************************************************************************/
- public void setCompOper(int operator) {
- setProperty(new IntegerProperty(OPERATOR_KEY, operator));
-
- }
-
- /**
- * Returns the operator to be asserted. EQUAL = 1, NOTEQUAL = 2 GREATERTHAN =
- * 3,LESSTHAN = 4,GREATERTHANEQUAL = 5,LESSTHANEQUAL = 6
- */
-
- public int getCompOper() {
- return getPropertyAsInt(OPERATOR_KEY);
- }
-
- /**
- * Set the size that shall be asserted.
- *
- * @param size -
- * a number of bytes. Is not allowed to be negative. Use
- * Long.MAX_VALUE to indicate illegal or empty inputs. This will
- * result in not checking the assertion.
- *
- * @throws IllegalArgumentException
- * If <code>size</code> is negative.
- */
- public void setAllowedSize(long size) throws IllegalArgumentException {
- if (size < 0L) {
- throw new IllegalArgumentException(JMeterUtils.getResString("argument_must_not_be_negative")); //$NON-NLS-1$
- }
- if (size == Long.MAX_VALUE) {
- setProperty(new LongProperty(SIZE_KEY, 0));
- } else {
- setProperty(new LongProperty(SIZE_KEY, size));
- }
- }
-
- /**
- * Compares the the size of a return result to the set allowed size using a
- * logical comparator set in setLogicalComparator().
- *
- * Possible values are: equal, not equal, greater than, less than, greater
- * than eqaul, less than equal, .
- *
- */
- private boolean compareSize(long resultSize) {
- boolean result = false;
- int comp = getCompOper();
- switch (comp) {
- case EQUAL:
- result = (resultSize == getAllowedSize());
- comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_equal"); //$NON-NLS-1$
- break;
- case NOTEQUAL:
- result = (resultSize != getAllowedSize());
- comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_notequal"); //$NON-NLS-1$
- break;
- case GREATERTHAN:
- result = (resultSize > getAllowedSize());
- comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_greater"); //$NON-NLS-1$
- break;
- case LESSTHAN:
- result = (resultSize < getAllowedSize());
- comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_less"); //$NON-NLS-1$
- break;
- case GREATERTHANEQUAL:
- result = (resultSize >= getAllowedSize());
- comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_greaterequal"); //$NON-NLS-1$
- break;
- case LESSTHANEQUAL:
- result = (resultSize <= getAllowedSize());
- comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_lessequal"); //$NON-NLS-1$
- break;
- default:
- result = false;
- comparatorErrorMessage = "ERROR - invalid condition";
- break;
- }
- return result;
- }
+ public final static int LESSTHAN = 4;
+
+ public final static int GREATERTHANEQUAL = 5;
+
+ public final static int LESSTHANEQUAL = 6;
+
+ /** Key for storing assertion-informations in the jmx-file. */
+ private static final String SIZE_KEY = "SizeAssertion.size"; // $NON-NLS-1$
+
+ private static final String OPERATOR_KEY = "SizeAssertion.operator"; // $NON-NLS-1$
+
+ /**
+ * Returns the result of the Assertion.
+ * Here it checks the Sample responseData length.
+ */
+ public AssertionResult getResult(SampleResult response) {
+ AssertionResult result = new AssertionResult(getName());
+ result.setFailure(false);
+ long resultSize = response.getBytes();
+ // is the Sample the correct size?
+ if (!(compareSize(resultSize))) {
+ result.setFailure(true);
+ Object[] arguments = { new Long(resultSize), comparatorErrorMessage, new Long(getAllowedSize()) };
+ String message = MessageFormat.format(JMeterUtils.getResString("size_assertion_failure"), arguments); //$NON-NLS-1$
+ result.setFailureMessage(message);
+ }
+ return result;
+ }
+
+ /**
+ * Returns the size in bytes to be asserted.
+ */
+ public long getAllowedSize() {
+ return getPropertyAsLong(SIZE_KEY);
+ }
+
+ /***************************************************************************
+ * set the Operator
+ **************************************************************************/
+ public void setCompOper(int operator) {
+ setProperty(new IntegerProperty(OPERATOR_KEY, operator));
+
+ }
+
+ /**
+ * Returns the operator to be asserted. EQUAL = 1, NOTEQUAL = 2 GREATERTHAN =
+ * 3,LESSTHAN = 4,GREATERTHANEQUAL = 5,LESSTHANEQUAL = 6
+ */
+
+ public int getCompOper() {
+ return getPropertyAsInt(OPERATOR_KEY);
+ }
+
+ /**
+ * Set the size that shall be asserted.
+ *
+ * @param size -
+ * a number of bytes. Is not allowed to be negative. Use
+ * Long.MAX_VALUE to indicate illegal or empty inputs. This will
+ * result in not checking the assertion.
+ *
+ * @throws IllegalArgumentException
+ * If <code>size</code> is negative.
+ */
+ public void setAllowedSize(long size) throws IllegalArgumentException {
+ if (size < 0L) {
+ throw new IllegalArgumentException(JMeterUtils.getResString("argument_must_not_be_negative")); //$NON-NLS-1$
+ }
+ if (size == Long.MAX_VALUE) {
+ setProperty(new LongProperty(SIZE_KEY, 0));
+ } else {
+ setProperty(new LongProperty(SIZE_KEY, size));
+ }
+ }
+
+ /**
+ * Compares the the size of a return result to the set allowed size using a
+ * logical comparator set in setLogicalComparator().
+ *
+ * Possible values are: equal, not equal, greater than, less than, greater
+ * than eqaul, less than equal, .
+ *
+ */
+ private boolean compareSize(long resultSize) {
+ boolean result = false;
+ int comp = getCompOper();
+ switch (comp) {
+ case EQUAL:
+ result = (resultSize == getAllowedSize());
+ comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_equal"); //$NON-NLS-1$
+ break;
+ case NOTEQUAL:
+ result = (resultSize != getAllowedSize());
+ comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_notequal"); //$NON-NLS-1$
+ break;
+ case GREATERTHAN:
+ result = (resultSize > getAllowedSize());
+ comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_greater"); //$NON-NLS-1$
+ break;
+ case LESSTHAN:
+ result = (resultSize < getAllowedSize());
+ comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_less"); //$NON-NLS-1$
+ break;
+ case GREATERTHANEQUAL:
+ result = (resultSize >= getAllowedSize());
+ comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_greaterequal"); //$NON-NLS-1$
+ break;
+ case LESSTHANEQUAL:
+ result = (resultSize <= getAllowedSize());
+ comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_lessequal"); //$NON-NLS-1$
+ break;
+ default:
+ result = false;
+ comparatorErrorMessage = "ERROR - invalid condition";
+ break;
+ }
+ return result;
+ }
}
Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/XMLAssertion.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/XMLAssertion.java?rev=674342&r1=674341&r2=674342&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/XMLAssertion.java (original)
+++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/XMLAssertion.java Sun Jul 6 13:28:49 2008
@@ -35,75 +35,75 @@
* @author <a href="mailto:gottfried@szing.at">Gottfried Szing</a>
*/
public class XMLAssertion extends AbstractTestElement implements Serializable, Assertion {
- private static final Logger log = LoggingManager.getLoggerForClass();
+ private static final Logger log = LoggingManager.getLoggerForClass();
- private static final char NEW_LINE = '\n'; // $NON-NLS-1$
+ private static final char NEW_LINE = '\n'; // $NON-NLS-1$
- // one builder for all requests in a thread
+ // one builder for all requests in a thread
private static final ThreadLocal myBuilder = new ThreadLocal() {
protected Object initialValue() {
return new SAXBuilder();
}
};
- /**
- * Returns the result of the Assertion. Here it checks wether the Sample
- * took to long to be considered successful. If so an AssertionResult
- * containing a FailureMessage will be returned. Otherwise the returned
- * AssertionResult will reflect the success of the Sample.
- */
- public AssertionResult getResult(SampleResult response) {
- // no error as default
- AssertionResult result = new AssertionResult(getName());
- byte[] responseData = response.getResponseData();
- if (responseData.length == 0) {
- return result.setResultForNull();
- }
- result.setFailure(false);
+ /**
+ * Returns the result of the Assertion. Here it checks wether the Sample
+ * took to long to be considered successful. If so an AssertionResult
+ * containing a FailureMessage will be returned. Otherwise the returned
+ * AssertionResult will reflect the success of the Sample.
+ */
+ public AssertionResult getResult(SampleResult response) {
+ // no error as default
+ AssertionResult result = new AssertionResult(getName());
+ byte[] responseData = response.getResponseData();
+ if (responseData.length == 0) {
+ return result.setResultForNull();
+ }
+ result.setFailure(false);
- // the result data
- String resultData = new String(getResultBody(responseData));
+ // the result data
+ String resultData = new String(getResultBody(responseData));
SAXBuilder builder = (SAXBuilder) myBuilder.get();
- try {
- builder.build(new StringReader(resultData));
- } catch (JDOMException e) {
- log.debug("Cannot parse result content", e); // may well happen
- result.setFailure(true);
- result.setFailureMessage(e.getMessage());
- } catch (IOException e) {
+ try {
+ builder.build(new StringReader(resultData));
+ } catch (JDOMException e) {
+ log.debug("Cannot parse result content", e); // may well happen
+ result.setFailure(true);
+ result.setFailureMessage(e.getMessage());
+ } catch (IOException e) {
log.error("Cannot read result content", e); // should never happen
result.setError(true);
result.setFailureMessage(e.getMessage());
}
- return result;
- }
+ return result;
+ }
- /**
- * Return the body of the http return.
- */
- private byte[] getResultBody(byte[] resultData) {
- for (int i = 0; i < (resultData.length - 1); i++) {
- if (resultData[i] == NEW_LINE && resultData[i + 1] == NEW_LINE) {
- return getByteArraySlice(resultData, (i + 2), resultData.length - 1);
- }
- }
- return resultData;
- }
-
- /**
- * Return a slice of a byte array
- */
- private byte[] getByteArraySlice(byte[] array, int begin, int end) {
- byte[] slice = new byte[(end - begin + 1)];
- int count = 0;
- for (int i = begin; i <= end; i++) {
- slice[count] = array[i];
- count++;
- }
+ /**
+ * Return the body of the http return.
+ */
+ private byte[] getResultBody(byte[] resultData) {
+ for (int i = 0; i < (resultData.length - 1); i++) {
+ if (resultData[i] == NEW_LINE && resultData[i + 1] == NEW_LINE) {
+ return getByteArraySlice(resultData, (i + 2), resultData.length - 1);
+ }
+ }
+ return resultData;
+ }
+
+ /**
+ * Return a slice of a byte array
+ */
+ private byte[] getByteArraySlice(byte[] array, int begin, int end) {
+ byte[] slice = new byte[(end - begin + 1)];
+ int count = 0;
+ for (int i = begin; i <= end; i++) {
+ slice[count] = array[i];
+ count++;
+ }
- return slice;
- }
+ return slice;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org