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:29:23 UTC
svn commit: r674343 - in
/jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions:
XMLSchemaAssertion.java XPathAssertion.java
Author: sebb
Date: Sun Jul 6 13:29:22 2008
New Revision: 674343
URL: http://svn.apache.org/viewvc?rev=674343&view=rev
Log:
Detab
Modified:
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/XMLSchemaAssertion.java
jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/XPathAssertion.java
Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/XMLSchemaAssertion.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/XMLSchemaAssertion.java?rev=674343&r1=674342&r2=674343&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/XMLSchemaAssertion.java (original)
+++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/XMLSchemaAssertion.java Sun Jul 6 13:29:22 2008
@@ -44,181 +44,181 @@
*
*/
public class XMLSchemaAssertion extends AbstractTestElement implements Serializable, Assertion {
- public static final String FILE_NAME_IS_REQUIRED = "FileName is required";
+ public static final String FILE_NAME_IS_REQUIRED = "FileName is required";
- public static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
+ public static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
- public static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
+ public static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
- public static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
+ public static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
- private static final Logger log = LoggingManager.getLoggerForClass();
-
- public static final String XSD_FILENAME_KEY = "xmlschema_assertion_filename";
-
- // private StringBuffer failureMessage = new StringBuffer();
-
- /**
- * getResult
- *
- */
- public AssertionResult getResult(SampleResult response) {
- AssertionResult result = new AssertionResult(getName());
- // Note: initialised with error = failure = false
-
- byte data[] = response.getResponseData();
- if (data.length == 0) {
- return result.setResultForNull();
- }
- String resultData = new String(getResultBody(data));
-
- String xsdFileName = getXsdFileName();
- if (log.isDebugEnabled()) {
- log.debug("xmlString: " + resultData);
- log.debug("xsdFileName: " + xsdFileName);
- }
- if (xsdFileName == null || xsdFileName.length() == 0) {
- result.setResultForFailure(FILE_NAME_IS_REQUIRED);
- } else {
- setSchemaResult(result, resultData, xsdFileName);
- }
- return result;
- }
-
- /*
- * TODO move to SampleResult class? Return the body of the http return.
- */
- private byte[] getResultBody(byte[] resultData) {
- for (int i = 0; i < (resultData.length - 1); i++) {
- if (resultData[i] == '\n' && resultData[i + 1] == '\n') {
- return JOrphanUtils.getByteArraySlice(resultData, (i + 2), resultData.length - 1);
- }
- }
- return resultData;
- }
-
- public void setXsdFileName(String xmlSchemaFileName) throws IllegalArgumentException {
- setProperty(XSD_FILENAME_KEY, xmlSchemaFileName);
- }
-
- public String getXsdFileName() {
- return getPropertyAsString(XSD_FILENAME_KEY);
- }
-
- /**
- * set Schema result
- *
- * @param result
- * @param xmlStr
- * @param xsdFileName
- */
- private void setSchemaResult(AssertionResult result, String xmlStr, String xsdFileName) {
- try {
- // boolean toReturn = true;
-
- // Document doc = null;
- DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance();
- parserFactory.setValidating(true);
- parserFactory.setNamespaceAware(true);
- parserFactory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
- parserFactory.setAttribute(JAXP_SCHEMA_SOURCE, xsdFileName);
-
- // create a parser:
- DocumentBuilder parser = parserFactory.newDocumentBuilder();
- parser.setErrorHandler(new SAXErrorHandler(result));
-
- // doc =
- parser.parse(new InputSource(new StringReader(xmlStr)));
- // if everything went fine then xml schema validation is valid
- } catch (SAXParseException e) {
-
- // Only set message if error not yet flagged
- if (!result.isError() && !result.isFailure()) {
- result.setError(true);
- result.setFailureMessage(errorDetails(e));
- }
-
- } catch (SAXException e) {
-
- log.warn(e.toString());
- result.setResultForFailure(e.getMessage());
-
- } catch (IOException e) {
-
- log.warn("IO error", e);
- result.setResultForFailure(e.getMessage());
-
- } catch (ParserConfigurationException e) {
-
- log.warn("Problem with Parser Config", e);
- result.setResultForFailure(e.getMessage());
-
- }
-
- }
-
- // Helper method to construct SAX error details
- private static String errorDetails(SAXParseException spe) {
- StringBuffer str = new StringBuffer(80);
- int i;
- i = spe.getLineNumber();
- if (i != -1) {
- str.append("line=");
- str.append(i);
- str.append(" col=");
- str.append(spe.getColumnNumber());
- str.append(" ");
- }
- str.append(spe.getLocalizedMessage());
- return str.toString();
- }
-
- /**
- * SAXErrorHandler class
- */
- private static class SAXErrorHandler implements ErrorHandler {
- private AssertionResult result;
-
- public SAXErrorHandler(AssertionResult result) {
- this.result = result;
- }
-
- /*
- * Can be caused by: - failure to read XSD file - xml does not match XSD
- */
- public void error(SAXParseException exception) throws SAXParseException {
-
- String msg = "error: " + errorDetails(exception);
- log.debug(msg);
- result.setFailureMessage(msg);
- result.setError(true);
- throw exception;
- }
-
- /*
- * Can be caused by: - premature end of file - non-whitespace content
- * after trailer
- */
- public void fatalError(SAXParseException exception) throws SAXParseException {
-
- String msg = "fatal: " + errorDetails(exception);
- log.debug(msg);
- result.setFailureMessage(msg);
- result.setError(true);
- throw exception;
- }
-
- /*
- * Not clear what can cause this ? conflicting versions perhaps
- */
- public void warning(SAXParseException exception) throws SAXParseException {
-
- String msg = "warning: " + errorDetails(exception);
- log.debug(msg);
- result.setFailureMessage(msg);
- // result.setError(true); // TODO is this the correct strategy?
- // throw exception; // allow assertion to pass
-
- }
- }
-}
\ No newline at end of file
+ private static final Logger log = LoggingManager.getLoggerForClass();
+
+ public static final String XSD_FILENAME_KEY = "xmlschema_assertion_filename";
+
+ // private StringBuffer failureMessage = new StringBuffer();
+
+ /**
+ * getResult
+ *
+ */
+ public AssertionResult getResult(SampleResult response) {
+ AssertionResult result = new AssertionResult(getName());
+ // Note: initialised with error = failure = false
+
+ byte data[] = response.getResponseData();
+ if (data.length == 0) {
+ return result.setResultForNull();
+ }
+ String resultData = new String(getResultBody(data));
+
+ String xsdFileName = getXsdFileName();
+ if (log.isDebugEnabled()) {
+ log.debug("xmlString: " + resultData);
+ log.debug("xsdFileName: " + xsdFileName);
+ }
+ if (xsdFileName == null || xsdFileName.length() == 0) {
+ result.setResultForFailure(FILE_NAME_IS_REQUIRED);
+ } else {
+ setSchemaResult(result, resultData, xsdFileName);
+ }
+ return result;
+ }
+
+ /*
+ * TODO move to SampleResult class? Return the body of the http return.
+ */
+ private byte[] getResultBody(byte[] resultData) {
+ for (int i = 0; i < (resultData.length - 1); i++) {
+ if (resultData[i] == '\n' && resultData[i + 1] == '\n') {
+ return JOrphanUtils.getByteArraySlice(resultData, (i + 2), resultData.length - 1);
+ }
+ }
+ return resultData;
+ }
+
+ public void setXsdFileName(String xmlSchemaFileName) throws IllegalArgumentException {
+ setProperty(XSD_FILENAME_KEY, xmlSchemaFileName);
+ }
+
+ public String getXsdFileName() {
+ return getPropertyAsString(XSD_FILENAME_KEY);
+ }
+
+ /**
+ * set Schema result
+ *
+ * @param result
+ * @param xmlStr
+ * @param xsdFileName
+ */
+ private void setSchemaResult(AssertionResult result, String xmlStr, String xsdFileName) {
+ try {
+ // boolean toReturn = true;
+
+ // Document doc = null;
+ DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance();
+ parserFactory.setValidating(true);
+ parserFactory.setNamespaceAware(true);
+ parserFactory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
+ parserFactory.setAttribute(JAXP_SCHEMA_SOURCE, xsdFileName);
+
+ // create a parser:
+ DocumentBuilder parser = parserFactory.newDocumentBuilder();
+ parser.setErrorHandler(new SAXErrorHandler(result));
+
+ // doc =
+ parser.parse(new InputSource(new StringReader(xmlStr)));
+ // if everything went fine then xml schema validation is valid
+ } catch (SAXParseException e) {
+
+ // Only set message if error not yet flagged
+ if (!result.isError() && !result.isFailure()) {
+ result.setError(true);
+ result.setFailureMessage(errorDetails(e));
+ }
+
+ } catch (SAXException e) {
+
+ log.warn(e.toString());
+ result.setResultForFailure(e.getMessage());
+
+ } catch (IOException e) {
+
+ log.warn("IO error", e);
+ result.setResultForFailure(e.getMessage());
+
+ } catch (ParserConfigurationException e) {
+
+ log.warn("Problem with Parser Config", e);
+ result.setResultForFailure(e.getMessage());
+
+ }
+
+ }
+
+ // Helper method to construct SAX error details
+ private static String errorDetails(SAXParseException spe) {
+ StringBuffer str = new StringBuffer(80);
+ int i;
+ i = spe.getLineNumber();
+ if (i != -1) {
+ str.append("line=");
+ str.append(i);
+ str.append(" col=");
+ str.append(spe.getColumnNumber());
+ str.append(" ");
+ }
+ str.append(spe.getLocalizedMessage());
+ return str.toString();
+ }
+
+ /**
+ * SAXErrorHandler class
+ */
+ private static class SAXErrorHandler implements ErrorHandler {
+ private AssertionResult result;
+
+ public SAXErrorHandler(AssertionResult result) {
+ this.result = result;
+ }
+
+ /*
+ * Can be caused by: - failure to read XSD file - xml does not match XSD
+ */
+ public void error(SAXParseException exception) throws SAXParseException {
+
+ String msg = "error: " + errorDetails(exception);
+ log.debug(msg);
+ result.setFailureMessage(msg);
+ result.setError(true);
+ throw exception;
+ }
+
+ /*
+ * Can be caused by: - premature end of file - non-whitespace content
+ * after trailer
+ */
+ public void fatalError(SAXParseException exception) throws SAXParseException {
+
+ String msg = "fatal: " + errorDetails(exception);
+ log.debug(msg);
+ result.setFailureMessage(msg);
+ result.setError(true);
+ throw exception;
+ }
+
+ /*
+ * Not clear what can cause this ? conflicting versions perhaps
+ */
+ public void warning(SAXParseException exception) throws SAXParseException {
+
+ String msg = "warning: " + errorDetails(exception);
+ log.debug(msg);
+ result.setFailureMessage(msg);
+ // result.setError(true); // TODO is this the correct strategy?
+ // throw exception; // allow assertion to pass
+
+ }
+ }
+}
Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/XPathAssertion.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/XPathAssertion.java?rev=674343&r1=674342&r2=674343&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/XPathAssertion.java (original)
+++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/assertions/XPathAssertion.java Sun Jul 6 13:29:22 2008
@@ -46,256 +46,256 @@
*
*/
public class XPathAssertion extends AbstractTestElement implements Serializable, Assertion {
- private static final Logger log = LoggingManager.getLoggerForClass();
+ private static final Logger log = LoggingManager.getLoggerForClass();
- // private static XPathAPI xpath = null;
+ // private static XPathAPI xpath = null;
- //+ JMX file attributes
- private static final String XPATH_KEY = "XPath.xpath"; // $NON-NLS-1$
- private static final String WHITESPACE_KEY = "XPath.whitespace"; // $NON-NLS-1$
- private static final String VALIDATE_KEY = "XPath.validate"; // $NON-NLS-1$
- private static final String TOLERANT_KEY = "XPath.tolerant"; // $NON-NLS-1$
- private static final String NEGATE_KEY = "XPath.negate"; // $NON-NLS-1$
- private static final String NAMESPACE_KEY = "XPath.namespace"; // $NON-NLS-1$
- private static final String QUIET_KEY = "XPath.quiet"; // $NON-NLS-1$
- private static final String REPORT_ERRORS_KEY = "XPath.report_errors"; // $NON-NLS-1$
- private static final String SHOW_WARNINGS_KEY = "XPath.show_warnings"; // $NON-NLS-1$
- //- JMX file attributes
-
- public static final String DEFAULT_XPATH = "/";
-
- /**
- * Returns the result of the Assertion. Checks if the result is well-formed
- * XML, and that the XPath expression is matched (or not, as the case may
- * be)
- */
- 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);
- result.setFailureMessage("");
-
- if (log.isDebugEnabled()) {
- log.debug(new StringBuffer("Validation is set to ").append(isValidating()).toString());
- log.debug(new StringBuffer("Whitespace is set to ").append(isWhitespace()).toString());
- log.debug(new StringBuffer("Tolerant is set to ").append(isTolerant()).toString());
- }
+ //+ JMX file attributes
+ private static final String XPATH_KEY = "XPath.xpath"; // $NON-NLS-1$
+ private static final String WHITESPACE_KEY = "XPath.whitespace"; // $NON-NLS-1$
+ private static final String VALIDATE_KEY = "XPath.validate"; // $NON-NLS-1$
+ private static final String TOLERANT_KEY = "XPath.tolerant"; // $NON-NLS-1$
+ private static final String NEGATE_KEY = "XPath.negate"; // $NON-NLS-1$
+ private static final String NAMESPACE_KEY = "XPath.namespace"; // $NON-NLS-1$
+ private static final String QUIET_KEY = "XPath.quiet"; // $NON-NLS-1$
+ private static final String REPORT_ERRORS_KEY = "XPath.report_errors"; // $NON-NLS-1$
+ private static final String SHOW_WARNINGS_KEY = "XPath.show_warnings"; // $NON-NLS-1$
+ //- JMX file attributes
+
+ public static final String DEFAULT_XPATH = "/";
+
+ /**
+ * Returns the result of the Assertion. Checks if the result is well-formed
+ * XML, and that the XPath expression is matched (or not, as the case may
+ * be)
+ */
+ 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);
+ result.setFailureMessage("");
+
+ if (log.isDebugEnabled()) {
+ log.debug(new StringBuffer("Validation is set to ").append(isValidating()).toString());
+ log.debug(new StringBuffer("Whitespace is set to ").append(isWhitespace()).toString());
+ log.debug(new StringBuffer("Tolerant is set to ").append(isTolerant()).toString());
+ }
- Document doc = null;
+ Document doc = null;
boolean isXML = JOrphanUtils.isXML(responseData);
-
+
try {
- doc = XPathUtil.makeDocument(new ByteArrayInputStream(responseData), isValidating(),
- isWhitespace(), isNamespace(), isTolerant(), isQuiet(), showWarnings() , reportErrors(), isXML);
- } catch (SAXException e) {
- log.debug("Caught sax exception: " + e);
- result.setError(true);
- result.setFailureMessage(new StringBuffer("SAXException: ").append(e.getMessage()).toString());
- return result;
- } catch (IOException e) {
- log.warn("Cannot parse result content", e);
- result.setError(true);
- result.setFailureMessage(new StringBuffer("IOException: ").append(e.getMessage()).toString());
- return result;
- } catch (ParserConfigurationException e) {
- log.warn("Cannot parse result content", e);
- result.setError(true);
- result.setFailureMessage(new StringBuffer("ParserConfigurationException: ").append(e.getMessage())
- .toString());
- return result;
- } catch (TidyException e) {
- result.setError(true);
- result.setFailureMessage(e.getMessage());
- return result;
- }
-
- if (doc == null || doc.getDocumentElement() == null) {
- result.setError(true);
- result.setFailureMessage("Document is null, probably not parsable");
- return result;
- }
-
- NodeList nodeList = null;
-
- final String pathString = getXPathString();
- try {
- XObject xObject = XPathAPI.eval(doc, pathString);
- switch (xObject.getType()) {
- case XObject.CLASS_NODESET:
- nodeList = xObject.nodelist();
- break;
- case XObject.CLASS_BOOLEAN:
- if (!xObject.bool()){
- result.setFailure(!isNegated());
- result.setFailureMessage("No Nodes Matched " + pathString);
- }
- return result;
- default:
- result.setFailure(true);
- result.setFailureMessage("Cannot understand: " + pathString);
- return result;
- }
- } catch (TransformerException e) {
- result.setError(true);
- result.setFailureMessage(
- new StringBuffer("TransformerException: ")
- .append(e.getMessage())
- .append(" for:")
- .append(pathString)
- .toString());
- return result;
- }
-
- if (nodeList == null || nodeList.getLength() == 0) {
- log.debug(new StringBuffer("nodeList null no match ").append(pathString).toString());
- result.setFailure(!isNegated());
- result.setFailureMessage("No Nodes Matched " + pathString);
- return result;
- }
- log.debug("nodeList length " + nodeList.getLength());
- if (log.isDebugEnabled() & !isNegated()) {
- for (int i = 0; i < nodeList.getLength(); i++){
- log.debug(new StringBuffer("nodeList[").append(i).append("] ").append(nodeList.item(i)).toString());
- }
- }
- result.setFailure(isNegated());
- if (isNegated()) {
- result.setFailureMessage("Specified XPath was found... Turn off negate if this is not desired");
- }
- return result;
- }
-
- /**
- * Get The XPath String that will be used in matching the document
- *
- * @return String xpath String
- */
- public String getXPathString() {
- return getPropertyAsString(XPATH_KEY, DEFAULT_XPATH);
- }
-
- /**
- * Set the XPath String this will be used as an xpath
- *
- * @param xpath
- * String
- */
- public void setXPathString(String xpath) {
- setProperty(new StringProperty(XPATH_KEY, xpath));
- }
-
- /**
- * Set whether to ignore element whitespace
- *
- * @param whitespace
- */
- public void setWhitespace(boolean whitespace) {
- setProperty(new BooleanProperty(WHITESPACE_KEY, whitespace));
- }
-
- /**
- * Set use validation
- *
- * @param validate
- */
- public void setValidating(boolean validate) {
- setProperty(new BooleanProperty(VALIDATE_KEY, validate));
- }
-
- /**
- * Set whether this is namespace aware
- *
- * @param namespace
- */
- public void setNamespace(boolean namespace) {
- setProperty(new BooleanProperty(NAMESPACE_KEY, namespace));
- }
-
- /**
- * Set tolerant mode if required
- *
- * @param tolerant
- * true/false
- */
- public void setTolerant(boolean tolerant) {
- setProperty(new BooleanProperty(TOLERANT_KEY, tolerant));
- }
-
- public void setNegated(boolean negate) {
- setProperty(new BooleanProperty(NEGATE_KEY, negate));
- }
-
- /**
- * Is this whitepsace ignored.
- *
- * @return boolean
- */
- public boolean isWhitespace() {
- return getPropertyAsBoolean(WHITESPACE_KEY, false);
- }
-
- /**
- * Is this validating
- *
- * @return boolean
- */
- public boolean isValidating() {
- return getPropertyAsBoolean(VALIDATE_KEY, false);
- }
-
- /**
- * Is this namespace aware?
- *
- * @return boolean
- */
- public boolean isNamespace() {
- return getPropertyAsBoolean(NAMESPACE_KEY, false);
- }
-
- /**
- * Is this using tolerant mode?
- *
- * @return boolean
- */
- public boolean isTolerant() {
- return getPropertyAsBoolean(TOLERANT_KEY, false);
- }
-
- /**
- * Negate the XPath test, that is return true if something is not found.
- *
- * @return boolean negated
- */
- public boolean isNegated() {
- return getPropertyAsBoolean(NEGATE_KEY, false);
- }
-
- public void setReportErrors(boolean val) {
- setProperty(REPORT_ERRORS_KEY, val, false);
- }
-
- public boolean reportErrors() {
- return getPropertyAsBoolean(REPORT_ERRORS_KEY, false);
- }
-
- public void setShowWarnings(boolean val) {
- setProperty(SHOW_WARNINGS_KEY, val, false);
- }
-
- public boolean showWarnings() {
- return getPropertyAsBoolean(SHOW_WARNINGS_KEY, false);
- }
-
- public void setQuiet(boolean val) {
- setProperty(QUIET_KEY, val, true);
- }
-
- public boolean isQuiet() {
- return getPropertyAsBoolean(QUIET_KEY, true);
- }
-}
\ No newline at end of file
+ doc = XPathUtil.makeDocument(new ByteArrayInputStream(responseData), isValidating(),
+ isWhitespace(), isNamespace(), isTolerant(), isQuiet(), showWarnings() , reportErrors(), isXML);
+ } catch (SAXException e) {
+ log.debug("Caught sax exception: " + e);
+ result.setError(true);
+ result.setFailureMessage(new StringBuffer("SAXException: ").append(e.getMessage()).toString());
+ return result;
+ } catch (IOException e) {
+ log.warn("Cannot parse result content", e);
+ result.setError(true);
+ result.setFailureMessage(new StringBuffer("IOException: ").append(e.getMessage()).toString());
+ return result;
+ } catch (ParserConfigurationException e) {
+ log.warn("Cannot parse result content", e);
+ result.setError(true);
+ result.setFailureMessage(new StringBuffer("ParserConfigurationException: ").append(e.getMessage())
+ .toString());
+ return result;
+ } catch (TidyException e) {
+ result.setError(true);
+ result.setFailureMessage(e.getMessage());
+ return result;
+ }
+
+ if (doc == null || doc.getDocumentElement() == null) {
+ result.setError(true);
+ result.setFailureMessage("Document is null, probably not parsable");
+ return result;
+ }
+
+ NodeList nodeList = null;
+
+ final String pathString = getXPathString();
+ try {
+ XObject xObject = XPathAPI.eval(doc, pathString);
+ switch (xObject.getType()) {
+ case XObject.CLASS_NODESET:
+ nodeList = xObject.nodelist();
+ break;
+ case XObject.CLASS_BOOLEAN:
+ if (!xObject.bool()){
+ result.setFailure(!isNegated());
+ result.setFailureMessage("No Nodes Matched " + pathString);
+ }
+ return result;
+ default:
+ result.setFailure(true);
+ result.setFailureMessage("Cannot understand: " + pathString);
+ return result;
+ }
+ } catch (TransformerException e) {
+ result.setError(true);
+ result.setFailureMessage(
+ new StringBuffer("TransformerException: ")
+ .append(e.getMessage())
+ .append(" for:")
+ .append(pathString)
+ .toString());
+ return result;
+ }
+
+ if (nodeList == null || nodeList.getLength() == 0) {
+ log.debug(new StringBuffer("nodeList null no match ").append(pathString).toString());
+ result.setFailure(!isNegated());
+ result.setFailureMessage("No Nodes Matched " + pathString);
+ return result;
+ }
+ log.debug("nodeList length " + nodeList.getLength());
+ if (log.isDebugEnabled() & !isNegated()) {
+ for (int i = 0; i < nodeList.getLength(); i++){
+ log.debug(new StringBuffer("nodeList[").append(i).append("] ").append(nodeList.item(i)).toString());
+ }
+ }
+ result.setFailure(isNegated());
+ if (isNegated()) {
+ result.setFailureMessage("Specified XPath was found... Turn off negate if this is not desired");
+ }
+ return result;
+ }
+
+ /**
+ * Get The XPath String that will be used in matching the document
+ *
+ * @return String xpath String
+ */
+ public String getXPathString() {
+ return getPropertyAsString(XPATH_KEY, DEFAULT_XPATH);
+ }
+
+ /**
+ * Set the XPath String this will be used as an xpath
+ *
+ * @param xpath
+ * String
+ */
+ public void setXPathString(String xpath) {
+ setProperty(new StringProperty(XPATH_KEY, xpath));
+ }
+
+ /**
+ * Set whether to ignore element whitespace
+ *
+ * @param whitespace
+ */
+ public void setWhitespace(boolean whitespace) {
+ setProperty(new BooleanProperty(WHITESPACE_KEY, whitespace));
+ }
+
+ /**
+ * Set use validation
+ *
+ * @param validate
+ */
+ public void setValidating(boolean validate) {
+ setProperty(new BooleanProperty(VALIDATE_KEY, validate));
+ }
+
+ /**
+ * Set whether this is namespace aware
+ *
+ * @param namespace
+ */
+ public void setNamespace(boolean namespace) {
+ setProperty(new BooleanProperty(NAMESPACE_KEY, namespace));
+ }
+
+ /**
+ * Set tolerant mode if required
+ *
+ * @param tolerant
+ * true/false
+ */
+ public void setTolerant(boolean tolerant) {
+ setProperty(new BooleanProperty(TOLERANT_KEY, tolerant));
+ }
+
+ public void setNegated(boolean negate) {
+ setProperty(new BooleanProperty(NEGATE_KEY, negate));
+ }
+
+ /**
+ * Is this whitepsace ignored.
+ *
+ * @return boolean
+ */
+ public boolean isWhitespace() {
+ return getPropertyAsBoolean(WHITESPACE_KEY, false);
+ }
+
+ /**
+ * Is this validating
+ *
+ * @return boolean
+ */
+ public boolean isValidating() {
+ return getPropertyAsBoolean(VALIDATE_KEY, false);
+ }
+
+ /**
+ * Is this namespace aware?
+ *
+ * @return boolean
+ */
+ public boolean isNamespace() {
+ return getPropertyAsBoolean(NAMESPACE_KEY, false);
+ }
+
+ /**
+ * Is this using tolerant mode?
+ *
+ * @return boolean
+ */
+ public boolean isTolerant() {
+ return getPropertyAsBoolean(TOLERANT_KEY, false);
+ }
+
+ /**
+ * Negate the XPath test, that is return true if something is not found.
+ *
+ * @return boolean negated
+ */
+ public boolean isNegated() {
+ return getPropertyAsBoolean(NEGATE_KEY, false);
+ }
+
+ public void setReportErrors(boolean val) {
+ setProperty(REPORT_ERRORS_KEY, val, false);
+ }
+
+ public boolean reportErrors() {
+ return getPropertyAsBoolean(REPORT_ERRORS_KEY, false);
+ }
+
+ public void setShowWarnings(boolean val) {
+ setProperty(SHOW_WARNINGS_KEY, val, false);
+ }
+
+ public boolean showWarnings() {
+ return getPropertyAsBoolean(SHOW_WARNINGS_KEY, false);
+ }
+
+ public void setQuiet(boolean val) {
+ setProperty(QUIET_KEY, val, true);
+ }
+
+ public boolean isQuiet() {
+ return getPropertyAsBoolean(QUIET_KEY, true);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org