jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1776651 - in /jmeter/trunk: src/components/org/apache/jmeter/assertions/ src/components/org/apache/jmeter/assertions/gui/ src/core/org/apache/jmeter/resources/ test/src/org/apache/jmeter/assertions/ xdocs/
Date Fri, 30 Dec 2016 22:23:59 GMT
Author: pmouawad
Date: Fri Dec 30 22:23:59 2016
New Revision: 1776651

URL: http://svn.apache.org/viewvc?rev=1776651&view=rev
Log:
Bug 60507 - Added 'Or' Function into ResponseAssertion
Based on contribution by  忻隆 
Bugzilla Id: 60507

Modified:
    jmeter/trunk/src/components/org/apache/jmeter/assertions/ResponseAssertion.java
    jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/AssertionGui.java
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_zh_CN.properties
    jmeter/trunk/test/src/org/apache/jmeter/assertions/ResponseAssertionTest.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/components/org/apache/jmeter/assertions/ResponseAssertion.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/assertions/ResponseAssertion.java?rev=1776651&r1=1776650&r2=1776651&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/assertions/ResponseAssertion.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/assertions/ResponseAssertion.java Fri Dec
30 22:23:59 2016
@@ -39,15 +39,14 @@ import org.apache.oro.text.regex.Pattern
 import org.apache.oro.text.regex.Perl5Compiler;
 import org.apache.oro.text.regex.Perl5Matcher;
 
-// @see org.apache.jmeter.assertions.ResponseAssertionTest for unit tests
-
 /**
  * Test element to handle Response Assertions, @see AssertionGui
+ * see org.apache.jmeter.assertions.ResponseAssertionTest for unit tests
  */
 public class ResponseAssertion extends AbstractScopedAssertion implements Serializable, Assertion
{
     private static final Logger log = LoggingManager.getLoggerForClass();
 
-    private static final long serialVersionUID = 240L;
+    private static final long serialVersionUID = 241L;
 
     private static final String TEST_FIELD = "Assertion.test_field";  // $NON-NLS-1$
 
@@ -85,7 +84,9 @@ public class ResponseAssertion extends A
 
     private static final int SUBSTRING = 1 << 4;
 
-    // Mask should contain all types (but not NOT)
+    private static final int OR = 1 << 5;
+
+    // Mask should contain all types (but not NOT nor OR)
     private static final int TYPE_MASK = CONTAINS | EQUALS | MATCH | SUBSTRING;
 
     private static final int  EQUALS_SECTION_DIFF_LEN
@@ -220,6 +221,10 @@ public class ResponseAssertion extends A
     public boolean isNotType() {
         return (getTestType() & NOT) != 0;
     }
+    
+    public boolean isOrType() {
+        return (getTestType() & OR) != 0;
+    }
 
     public void setToContainsType() {
         setTestTypeMasked(CONTAINS);
@@ -244,6 +249,14 @@ public class ResponseAssertion extends A
     public void unsetNotType() {
         setTestType(getTestType() & ~NOT);
     }
+    
+    public void setToOrType() {
+        setTestType((getTestType() | OR));
+    }
+
+    public void unsetOrType() {
+        setTestType(getTestType() & ~OR);
+    }
 
     public boolean getAssumeSuccess() {
         return getPropertyAsBoolean(ASSUME_SUCCESS, false);
@@ -290,9 +303,9 @@ public class ResponseAssertion extends A
         }
 
         result.setFailure(false);
-        result.setError(false);
-
+        result.setError(false); 
         boolean notTest = (NOT & getTestType()) > 0;
+        boolean orTest = (OR & getTestType()) > 0;
         boolean contains = isContainsType(); // do it once outside loop
         boolean equals = isEqualsType();
         boolean substring = isSubstringType();
@@ -300,6 +313,7 @@ public class ResponseAssertion extends A
         boolean debugEnabled = log.isDebugEnabled();
         if (debugEnabled){
             log.debug("Type:" + (contains?"Contains" : "Match") + (notTest? "(not)" : ""));
+            log.debug("Type:" + (contains?"Contains" : "Match") + (orTest? "(or)" : ""));
         }
 
         if (StringUtils.isEmpty(toCheck)) {
@@ -313,6 +327,8 @@ public class ResponseAssertion extends A
         }
 
         boolean pass = true;
+        boolean hasTrue = false;
+        ArrayList<String> allCheckMessage = new ArrayList<>();
         try {
             // Get the Matcher for this thread
             Perl5Matcher localMatcher = JMeterUtils.getMatcher();
@@ -333,17 +349,37 @@ public class ResponseAssertion extends A
                     found = localMatcher.matches(toCheck, pattern);
                 }
                 pass = notTest ? !found : found;
-                if (!pass) {
+                if (orTest) {
+                    if (!pass) {
+                        if (debugEnabled) {
+                            log.debug("Failed: "+stringPattern);
+                        }
+                        allCheckMessage.add(getFailText(stringPattern,toCheck));
+                    } else {
+                        hasTrue=true;
+                        break;
+                    }
+                } else {
+                    if (!pass) {
+                        if (debugEnabled){
+                            log.debug("Failed: "+stringPattern);
+                        }
+                        result.setFailure(true);
+                        result.setFailureMessage(getFailText(stringPattern,toCheck));
+                        break;
+                    }
                     if (debugEnabled){
-                        log.debug("Failed: "+stringPattern);
+                        log.debug("Passed: "+stringPattern);
                     }
-                    result.setFailure(true);
-                    result.setFailureMessage(getFailText(stringPattern,toCheck));
-                    break;
                 }
-                if (debugEnabled){
-                    log.debug("Passed: "+stringPattern);
+            }
+            if (orTest && !hasTrue){
+                StringBuilder errorMsg = new StringBuilder();
+                for(String tmp : allCheckMessage){
+                    errorMsg.append(tmp).append('\t');
                 }
+                result.setFailure(true);
+                result.setFailureMessage(errorMsg.toString());   
             }
         } catch (MalformedCachePatternException e) {
             result.setError(true);
@@ -415,7 +451,6 @@ public class ResponseAssertion extends A
         }
 
         sb.append("/");
-
         return sb.toString();
     }
 

Modified: jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/AssertionGui.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/AssertionGui.java?rev=1776651&r1=1776650&r2=1776651&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/AssertionGui.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/assertions/gui/AssertionGui.java Fri Dec
30 22:23:59 2016
@@ -110,6 +110,11 @@ public class AssertionGui extends Abstra
      * patterns.
      */
     private JCheckBox notBox;
+    
+    /**
+	 * Add new OR checkbox.
+     */
+    private JCheckBox orBox;
 
     /** A table of patterns to test against. */
     private JTable stringTable;
@@ -187,6 +192,12 @@ public class AssertionGui extends Abstra
             } else {
                 ra.unsetNotType();
             }
+
+            if (orBox.isSelected()) {
+                ra.setToOrType();
+            } else {
+                ra.unsetOrType();
+            }
         }
     }
 
@@ -208,6 +219,7 @@ public class AssertionGui extends Abstra
 
         substringBox.setSelected(true);
         notBox.setSelected(false);
+        orBox.setSelected(false);
     }
 
     /**
@@ -237,6 +249,7 @@ public class AssertionGui extends Abstra
         }
 
         notBox.setSelected(model.isNotType());
+        orBox.setSelected(model.isOrType());
 
         if (model.isTestFieldResponseData()) {
             responseStringButton.setSelected(true);
@@ -357,6 +370,9 @@ public class AssertionGui extends Abstra
         notBox = new JCheckBox(JMeterUtils.getResString("assertion_not")); //$NON-NLS-1$
         panel.add(notBox);
 
+        orBox = new JCheckBox(JMeterUtils.getResString("assertion_or")); //$NON-NLS-1$
+        panel.add(orBox);
+
         return panel;
     }
 

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=1776651&r1=1776650&r2=1776651&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Fri Dec 30 22:23:59
2016
@@ -111,6 +111,7 @@ assertion_matches=Matches
 assertion_message_resp=Response Message
 assertion_network_size=Full Response
 assertion_not=Not
+assertion_or=Or
 assertion_pattern_match_rules=Pattern Matching Rules
 assertion_patterns_to_test=Patterns to Test
 assertion_regex_empty_default_value=Use empty default value
@@ -1343,4 +1344,4 @@ xpath_tidy_report_errors=Report errors
 xpath_tidy_show_warnings=Show warnings
 you_must_enter_a_valid_number=You must enter a valid number
 zh_cn=Chinese (Simplified)
-zh_tw=Chinese (Traditional)
+zh_tw=Chinese (Traditional)
\ No newline at end of file

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties?rev=1776651&r1=1776650&r2=1776651&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties Fri Dec 30 22:23:59
2016
@@ -104,6 +104,7 @@ assertion_matches=Correspond \u00E0 (exp
 assertion_message_resp=Message de r\u00E9ponse
 assertion_network_size=R\u00E9ponse compl\u00E8te
 assertion_not=Inverser
+assertion_or=Ou
 assertion_pattern_match_rules=Type de correspondance du motif
 assertion_patterns_to_test=Motifs \u00E0 tester
 assertion_regex_empty_default_value=Utiliser la cha\u00EEne vide comme valeur par d\u00E9faut

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages_zh_CN.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_zh_CN.properties?rev=1776651&r1=1776650&r2=1776651&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_zh_CN.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_zh_CN.properties Fri Dec 30
22:23:59 2016
@@ -35,6 +35,7 @@ assertion_contains=\u5305\u62EC
 assertion_matches=\u5339\u914D
 assertion_message_resp=\u54CD\u5E94\u4FE1\u606F
 assertion_not=\u5426
+assertion_or=\u6216\u8005
 assertion_pattern_match_rules=\u6A21\u5F0F\u5339\u914D\u89C4\u5219
 assertion_patterns_to_test=\u8981\u6D4B\u8BD5\u7684\u6A21\u5F0F
 assertion_resp_field=\u8981\u6D4B\u8BD5\u7684\u54CD\u5E94\u5B57\u6BB5
@@ -401,5 +402,4 @@ web_testing_retrieve_images=\u4ECEHTML\u
 web_testing_title=HTTP\u8BF7\u6C42
 workbench_title=\u5DE5\u4F5C\u53F0
 xml_assertion_title=XML\u65AD\u8A00
-you_must_enter_a_valid_number=\u5FC5\u987B\u8F93\u5165\u6709\u6548\u7684\u6570\u5B57
-
+you_must_enter_a_valid_number=\u5FC5\u987B\u8F93\u5165\u6709\u6548\u7684\u6570\u5B57
\ No newline at end of file

Modified: jmeter/trunk/test/src/org/apache/jmeter/assertions/ResponseAssertionTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/assertions/ResponseAssertionTest.java?rev=1776651&r1=1776650&r2=1776651&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/assertions/ResponseAssertionTest.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/assertions/ResponseAssertionTest.java Fri Dec
30 22:23:59 2016
@@ -122,7 +122,38 @@ public class ResponseAssertionTest {
         assertion.addTestString("line 2");
         result = assertion.getResult(sample);
         assertPassed();
-
+        
+        assertion.clearTestStrings();
+        assertion.addTestString("line 2");
+        assertion.addTestString("NOTINSAMPLEDATA");
+        result = assertion.getResult(sample);
+        assertFailed();
+        
+        assertion.clearTestStrings();
+        assertion.setToOrType();
+        assertion.addTestString("line 2");
+        assertion.addTestString("NOTINSAMPLEDATA");
+        result = assertion.getResult(sample);
+        assertPassed();
+        assertion.unsetOrType();
+        
+        assertion.clearTestStrings();
+        assertion.setToOrType();
+        assertion.addTestString("NOTINSAMPLEDATA");
+        assertion.addTestString("line 2");
+        result = assertion.getResult(sample);
+        assertPassed();
+        assertion.unsetOrType();
+        
+        
+        assertion.clearTestStrings();
+        assertion.setToNotType();
+        assertion.addTestString("NOTINSAMPLEDATA");
+        result = assertion.getResult(sample);
+        assertPassed();
+        assertion.unsetNotType();
+        
+        
         assertion.clearTestStrings();
         assertion.addTestString("(?s)line \\d+.*EOF");
         result = assertion.getResult(sample);

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1776651&r1=1776650&r2=1776651&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Fri Dec 30 22:23:59 2016
@@ -123,6 +123,7 @@ Fill in some detail.
 <h3>Timers, Assertions, Config, Pre- &amp; Post-Processors</h3>
 <ul>
     <li><bug>60154</bug>User Parameters GUI: allow rows to be moved up
&amp; down in the list. Contributed by Murdecai777 (https://github.com/Murdecai777).</li>
+    <li><bug>60507</bug>Added 'Or' Function into ResponseAssertion. Based
on a contributed from \u5ffb\u9686 (298015902 at qq.com)</li>
 </ul>
 
 <h3>Functions</h3>
@@ -211,6 +212,7 @@ Fill in some detail.
 <li>Murdecai777 (https://github.com/Murdecai777)</li>
 <li>Logan Mauzaize (https://github.com/loganmzz)</li>
 <li>Maxime Chassagneux (https://github.com/max3163)</li>
+<li>\u5ffb\u9686 (298015902 at qq.com)</li>
 </ul>
 <p>We also thank bug reporters who helped us improve JMeter. <br/>
 For this release we want to give special thanks to the following reporters for the clear
reports and tests made after our fixes:</p>



Mime
View raw message