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 2010/02/08 00:16:18 UTC

svn commit: r907510 - in /jakarta/jmeter/trunk: src/components/org/apache/jmeter/extractor/RegexExtractor.java src/components/org/apache/jmeter/extractor/gui/RegexExtractorGui.java xdocs/changes.xml xdocs/usermanual/component_reference.xml

Author: sebb
Date: Sun Feb  7 23:16:18 2010
New Revision: 907510

URL: http://svn.apache.org/viewvc?rev=907510&view=rev
Log:
Regex Extractor can now be applied to a variable

Modified:
    jakarta/jmeter/trunk/src/components/org/apache/jmeter/extractor/RegexExtractor.java
    jakarta/jmeter/trunk/src/components/org/apache/jmeter/extractor/gui/RegexExtractorGui.java
    jakarta/jmeter/trunk/xdocs/changes.xml
    jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml

Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/extractor/RegexExtractor.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/extractor/RegexExtractor.java?rev=907510&r1=907509&r2=907510&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/components/org/apache/jmeter/extractor/RegexExtractor.java (original)
+++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/extractor/RegexExtractor.java Sun Feb  7 23:16:18 2010
@@ -111,7 +111,7 @@
 
         String regex = getRegex();
         try {
-            List<MatchResult> matches = processMatches(regex, previousResult, matchNumber);
+            List<MatchResult> matches = processMatches(regex, previousResult, matchNumber, vars);
             int prevCount = 0;
             String prevString = vars.get(refName + REF_MATCH_NR);
             if (prevString != null) {
@@ -176,9 +176,7 @@
        return inputString;
     }
     
-    private List<MatchResult> processMatches(String regex, SampleResult result, int matchNumber) {
-        List<SampleResult> sampleList = getSampleList(result);
-
+    private List<MatchResult> processMatches(String regex, SampleResult result, int matchNumber, JMeterVariables vars) {
         if (log.isDebugEnabled()) {
             log.debug("Regex = " + regex);
         }
@@ -188,23 +186,38 @@
         List<MatchResult> matches = new ArrayList<MatchResult>();
         int found = 0;
 
-        for (SampleResult sr : sampleList) {
-            String inputString = getInputString(sr);
-            PatternMatcherInput input = new PatternMatcherInput(inputString);
-            while (matchNumber <=0 || found != matchNumber) {
-                if (matcher.contains(input, pattern)) {
-                    log.debug("RegexExtractor: Match found!");
-                    matches.add(matcher.getMatch());
-                    found++;
-                } else {
+        if (isScopeVariable()){
+            String inputString=vars.get(getVariableName());
+            matchStrings(matchNumber, matcher, pattern, matches, found,
+                    inputString);            
+        } else {
+            List<SampleResult> sampleList = getSampleList(result);
+            for (SampleResult sr : sampleList) {
+                String inputString = getInputString(sr);
+                found = matchStrings(matchNumber, matcher, pattern, matches, found,
+                        inputString);
+                if (matchNumber > 0 && found == matchNumber){// no need to process further
                     break;
                 }
             }
-            if (matchNumber > 0 && found == matchNumber){// no need to process further
+        }
+        return matches;
+    }
+
+    private int matchStrings(int matchNumber, Perl5Matcher matcher,
+            Pattern pattern, List<MatchResult> matches, int found,
+            String inputString) {
+        PatternMatcherInput input = new PatternMatcherInput(inputString);
+        while (matchNumber <=0 || found != matchNumber) {
+            if (matcher.contains(input, pattern)) {
+                log.debug("RegexExtractor: Match found!");
+                matches.add(matcher.getMatch());
+                found++;
+            } else {
                 break;
             }
         }
-        return matches;
+        return found;
     }
 
     /**

Modified: jakarta/jmeter/trunk/src/components/org/apache/jmeter/extractor/gui/RegexExtractorGui.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/extractor/gui/RegexExtractorGui.java?rev=907510&r1=907509&r2=907510&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/components/org/apache/jmeter/extractor/gui/RegexExtractorGui.java (original)
+++ jakarta/jmeter/trunk/src/components/org/apache/jmeter/extractor/gui/RegexExtractorGui.java Sun Feb  7 23:16:18 2010
@@ -146,7 +146,7 @@
 
         Box box = Box.createVerticalBox();
         box.add(makeTitlePanel());
-        box.add(createScopePanel());
+        box.add(createScopePanel(true));
         box.add(makeSourcePanel());
         add(box, BorderLayout.NORTH);
         add(makeParameterPanel(), BorderLayout.CENTER);

Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=907510&r1=907509&r2=907510&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Sun Feb  7 23:16:18 2010
@@ -188,7 +188,7 @@
 <li>Bug 48331 - XpathExtractor does not return XML string representations for a Nodeset</li>
 <li>Bug 48511 - add parent,child,all selection to regex extractor</li>
 <li>Add Sampler scope selection to XPathExtractor</li>
-<li>Response Assertion and Size Assertion can now be applied to a JMeter variable</li>
+<li>Regular Expression Extractor, Response Assertion and Size Assertion can now be applied to a JMeter variable</li>
 </ul>
 
 <h3>Functions</h3>

Modified: jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=907510&r1=907509&r2=907510&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml Sun Feb  7 23:16:18 2010
@@ -4040,6 +4040,7 @@
         <li>Main sample only - only applies to the main sample</li>
         <li>Sub-samples only - only applies to the sub-samples</li>
         <li>Main sample and sub-samples - applies to both.</li>
+        <li>JMeter Variable - assertion is to be applied to the contents of the named variable</li>
         </ul>
         Matching is applied to all qualifying samples in turn.
         For example if there is a main sample and 3 sub-samples, each of which contains a single match for the regex,



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org