You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2013/01/05 22:18:21 UTC

svn commit: r1429387 - in /jmeter/trunk: src/components/org/apache/jmeter/assertions/XPathAssertion.java src/components/org/apache/jmeter/assertions/gui/XPathAssertionGui.java xdocs/changes.xml

Author: pmouawad
Date: Sat Jan  5 21:18:21 2013
New Revision: 1429387

URL: http://svn.apache.org/viewvc?rev=1429387&view=rev
Log:
Bug 54160 - Add support for xpath assertion to apply to a JMeter variable.
Bugzilla Id: 54160

Modified:
    jmeter/trunk/src/components/org/apache/jmeter/assertions/XPathAssertion.java
    jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/XPathAssertionGui.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/components/org/apache/jmeter/assertions/XPathAssertion.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/assertions/XPathAssertion.java?rev=1429387&r1=1429386&r2=1429387&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/assertions/XPathAssertion.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/assertions/XPathAssertion.java Sat Jan  5 21:18:21 2013
@@ -25,7 +25,7 @@ import java.io.Serializable;
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.jmeter.samplers.SampleResult;
-import org.apache.jmeter.testelement.AbstractTestElement;
+import org.apache.jmeter.testelement.AbstractScopedAssertion;
 import org.apache.jmeter.testelement.property.BooleanProperty;
 import org.apache.jmeter.testelement.property.StringProperty;
 import org.apache.jmeter.util.TidyException;
@@ -41,7 +41,7 @@ import org.xml.sax.SAXException;
  * XPath
  *
  */
-public class XPathAssertion extends AbstractTestElement implements Serializable, Assertion {
+public class XPathAssertion extends AbstractScopedAssertion implements Serializable, Assertion {
     private static final Logger log = LoggingManager.getLoggerForClass();
 
     private static final long serialVersionUID = 240L;
@@ -70,24 +70,32 @@ public class XPathAssertion extends Abst
     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 StringBuilder("Validation is set to ").append(isValidating()).toString());
-            log.debug(new StringBuilder("Whitespace is set to ").append(isWhitespace()).toString());
-            log.debug(new StringBuilder("Tolerant is set to ").append(isTolerant()).toString());
-        }
-
+        byte[] responseData = null;
         Document doc = null;
 
-        boolean isXML = JOrphanUtils.isXML(responseData);
-
         try {
+            if (isScopeVariable()){
+                responseData = getThreadContext().getVariables().get(getVariableName()).getBytes("UTF-8");
+            } else {
+                responseData = response.getResponseData();
+            }
+            
+            if (responseData.length == 0) {
+                return result.setResultForNull();
+            }
+    
+            if (log.isDebugEnabled()) {
+                log.debug(new StringBuilder("Validation is set to ").append(isValidating()).toString());
+                log.debug(new StringBuilder("Whitespace is set to ").append(isWhitespace()).toString());
+                log.debug(new StringBuilder("Tolerant is set to ").append(isTolerant()).toString());
+            }
+    
+    
+            boolean isXML = JOrphanUtils.isXML(responseData);
+
             doc = XPathUtil.makeDocument(new ByteArrayInputStream(responseData), isValidating(),
                     isWhitespace(), isNamespace(), isTolerant(), isQuiet(), showWarnings() , reportErrors(), isXML
                     , isDownloadDTDs());

Modified: jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/XPathAssertionGui.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/XPathAssertionGui.java?rev=1429387&r1=1429386&r2=1429387&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/XPathAssertionGui.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/XPathAssertionGui.java Sat Jan  5 21:18:21 2013
@@ -21,6 +21,7 @@ package org.apache.jmeter.assertions.gui
 import java.awt.BorderLayout;
 
 import javax.swing.BorderFactory;
+import javax.swing.Box;
 import javax.swing.JPanel;
 
 import org.apache.jmeter.assertions.XPathAssertion;
@@ -37,6 +38,7 @@ public class XPathAssertionGui extends A
     private XMLConfPanel xml;
 
     public XPathAssertionGui() {
+        super();
         init();
     }
 
@@ -66,6 +68,7 @@ public class XPathAssertionGui extends A
     public void configure(TestElement el) {
         super.configure(el);
         XPathAssertion assertion = (XPathAssertion) el;
+        showScopeSettings(assertion, true);
         xpath.setXPath(assertion.getXPathString());
         xpath.setNegated(assertion.isNegated());
 
@@ -77,7 +80,10 @@ public class XPathAssertionGui extends A
         setBorder(makeBorder());
 
         add(makeTitlePanel());
-
+        Box box = Box.createVerticalBox();
+        box.add(createScopePanel(true));
+        add(box);
+        
         // USER_INPUT
         JPanel sizePanel = new JPanel(new BorderLayout());
         sizePanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
@@ -104,6 +110,7 @@ public class XPathAssertionGui extends A
         super.configureTestElement(el);
         if (el instanceof XPathAssertion) {
             XPathAssertion assertion = (XPathAssertion) el;
+            saveScopeSettings(assertion);
             assertion.setNegated(xpath.isNegated());
             assertion.setXPathString(xpath.getXPath());
             xml.modifyTestElement(assertion);

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1429387&r1=1429386&r2=1429387&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Sat Jan  5 21:18:21 2013
@@ -225,6 +225,7 @@ to the elements View Results Tree, Asser
 <ul>
 <li><bugzilla>54259</bugzilla> - Introduce a new Extractor that uses CSS or jquery-like selector syntax</li>
 <li><bugzilla>45772</bugzilla> - RegEx User Parameters Post Processor</li>
+<li><bugzilla>54160</bugzilla> - Add support for xpath assertion to apply to a JMeter variable.</li>
 </ul>
 
 <h3>Functions</h3>