jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1820745 - 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 Wed, 10 Jan 2018 12:50:49 GMT
Author: pmouawad
Date: Wed Jan 10 12:50:48 2018
New Revision: 1820745

URL: http://svn.apache.org/viewvc?rev=1820745&view=rev
Log:
Bug 51140 - Response Assertion: add ability to set a specific error/failure message that is
later shown in the Assertion Result
Contributed by UbikLoadPack
Bugzilla Id: 51140

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/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=1820745&r1=1820744&r2=1820745&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/assertions/ResponseAssertion.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/assertions/ResponseAssertion.java Wed Jan
10 12:50:48 2018
@@ -23,6 +23,7 @@ import java.net.URL;
 import java.util.ArrayList;
 
 import org.apache.commons.lang3.StringUtils;
+import org.apache.jmeter.assertions.gui.AssertionGui;
 import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.testelement.AbstractScopedAssertion;
 import org.apache.jmeter.testelement.property.CollectionProperty;
@@ -63,6 +64,7 @@ public class ResponseAssertion extends A
     private static final String ASSUME_SUCCESS = "Assertion.assume_success"; // $NON-NLS-1$
     private static final String TEST_STRINGS = "Asserion.test_strings"; // $NON-NLS-1$
     private static final String TEST_TYPE = "Assertion.test_type"; // $NON-NLS-1$
+    private static final String CUSTOM_MESSAGE = "Assertion.custom_message"; // $NON-NLS-1$
 
     /**
      * Mask values for TEST_TYPE 
@@ -137,6 +139,14 @@ public class ResponseAssertion extends A
         setTestField(REQUEST_DATA);
     }
 
+    public void setCustomFailureMessage(String customFailureMessage) {
+        setProperty(CUSTOM_MESSAGE, customFailureMessage);
+    }
+    
+    public String getCustomFailureMessage() {
+        return getPropertyAsString(CUSTOM_MESSAGE);
+    }
+    
     public boolean isTestFieldURL(){
         return SAMPLE_URL.equals(getTestField());
     }
@@ -365,7 +375,12 @@ public class ResponseAssertion extends A
                     if (!pass) {
                         log.debug("Failed: {}", stringPattern);
                         result.setFailure(true);
-                        result.setFailureMessage(getFailText(stringPattern,toCheck));
+                        String customMsg = getCustomFailureMessage();
+                        if(StringUtils.isEmpty(customMsg)) {
+                            result.setFailureMessage(getFailText(stringPattern,toCheck));
+                        } else {
+                            result.setFailureMessage(customMsg);
+                        }
                         break;
                     }
                     log.debug("Passed: {}", stringPattern);
@@ -377,7 +392,12 @@ public class ResponseAssertion extends A
                     errorMsg.append(tmp).append('\t');
                 }
                 result.setFailure(true);
-                result.setFailureMessage(errorMsg.toString());   
+                String customMsg = getCustomFailureMessage();
+                if(StringUtils.isEmpty(customMsg)) {
+                    result.setFailureMessage(errorMsg.toString());
+                } else {
+                    result.setFailureMessage(customMsg);
+                }
             }
         } catch (MalformedCachePatternException e) {
             result.setError(true);

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=1820745&r1=1820744&r2=1820745&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 Wed Jan
10 12:50:48 2018
@@ -45,6 +45,8 @@ import org.apache.jmeter.assertions.Resp
 import org.apache.jmeter.gui.GUIMenuSortOrder;
 import org.apache.jmeter.gui.GuiPackage;
 import org.apache.jmeter.gui.util.HeaderAsPropertyRenderer;
+import org.apache.jmeter.gui.util.JSyntaxTextArea;
+import org.apache.jmeter.gui.util.JTextScrollPane;
 import org.apache.jmeter.gui.util.PowerTableModel;
 import org.apache.jmeter.gui.util.TextAreaCellRenderer;
 import org.apache.jmeter.gui.util.TextAreaTableCellEditor;
@@ -134,6 +136,8 @@ public class AssertionGui extends Abstra
 
     /** Table model for the pattern table. */
     private PowerTableModel tableModel;
+    
+    private JSyntaxTextArea alternativeFailureMessage;
 
     /**
      * Create a new AssertionGui panel.
@@ -162,7 +166,7 @@ public class AssertionGui extends Abstra
         configureTestElement(el);
         if (el instanceof ResponseAssertion) {
             ResponseAssertion ra = (ResponseAssertion) el;
-
+            ra.setCustomFailureMessage(alternativeFailureMessage.getText());
             saveScopeSettings(ra);
 
             ra.clearTestStrings();
@@ -236,6 +240,7 @@ public class AssertionGui extends Abstra
         substringBox.setSelected(true);
         notBox.setSelected(false);
         orBox.setSelected(false);
+        alternativeFailureMessage.setText(""); //$NON-NLS-1$
     }
 
     /**
@@ -254,6 +259,9 @@ public class AssertionGui extends Abstra
 
         showScopeSettings(model, true);
 
+        if(model.getCustomFailureMessage() != null) {
+            alternativeFailureMessage.setText(model.getCustomFailureMessage());
+        }
         if (model.isContainsType()) {
             containsBox.setSelected(true);
         } else if (model.isEqualsType()) {
@@ -316,6 +324,7 @@ public class AssertionGui extends Abstra
         box.add(createTypePanel());
         add(box, BorderLayout.NORTH);
         add(createStringPanel(), BorderLayout.CENTER);
+        add(createCustomAssertionMessagePanel(), BorderLayout.SOUTH);
     }
 
     /**
@@ -463,6 +472,14 @@ public class AssertionGui extends Abstra
 
         return panel;
     }
+    
+    private JPanel createCustomAssertionMessagePanel() {
+        JPanel panel = new JPanel();
+        panel.setBorder(BorderFactory.createTitledBorder(JMeterUtils.getResString("assertion_custom_message")));
//$NON-NLS-1$
+        alternativeFailureMessage = JSyntaxTextArea.getInstance(3, 80);
+        panel.add(JTextScrollPane.getInstance(alternativeFailureMessage));
+        return panel;
+    }
 
     /**
      * Create a panel with buttons to add and delete string patterns.

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=1820745&r1=1820744&r2=1820745&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Wed Jan 10 12:50:48
2018
@@ -109,6 +109,7 @@ ask_existing_file=The file {0} already e
 assertion_assume_success=Ignore Status
 assertion_body_resp=Response Body
 assertion_code_resp=Response Code
+assertion_custom_message=Custom failure message
 assertion_contains=Contains
 assertion_equals=Equals
 assertion_headers=Response Headers

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=1820745&r1=1820744&r2=1820745&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 Wed Jan 10 12:50:48
2018
@@ -106,6 +106,7 @@ assertion_assume_success=Ignorer le stat
 assertion_body_resp=Corps de r\u00E9ponse
 assertion_code_resp=Code de r\u00E9ponse
 assertion_contains=Contient (exp. r\u00E9guli\u00E8re)
+assertion_custom_message=Message d''erreur sp\u00e9cifique \u00e0 utiliser
 assertion_equals=Est \u00E9gale \u00E0 (texte brut)
 assertion_headers=Ent\u00EAtes de r\u00E9ponse
 assertion_matches=Correspond \u00E0 (exp. r\u00E9guli\u00E8re)

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=1820745&r1=1820744&r2=1820745&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/assertions/ResponseAssertionTest.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/assertions/ResponseAssertionTest.java Wed Jan
10 12:50:48 2018
@@ -32,6 +32,7 @@ import org.apache.jmeter.samplers.Sample
 import org.apache.jmeter.threads.JMeterContext;
 import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
+import org.apache.oro.text.MalformedCachePatternException;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -90,6 +91,43 @@ public class ResponseAssertionTest {
     }
     
     @Test
+    public void testCustomFailureMessage() throws Exception {
+        assertion.unsetNotType();
+        assertion.setToEqualsType();
+        assertion.setTestFieldURL();
+        assertion.addTestString("Sampler Label");
+        assertion.addTestString("Sampler labelx");
+        assertion.setCustomFailureMessage("Custom failure message");
+        result = assertion.getResult(sample);
+        assertFailed();
+        assertEquals("Custom failure message", result.getFailureMessage());
+        
+        assertion.setToOrType();
+        result = assertion.getResult(sample);
+        assertFailed();
+        assertEquals("Custom failure message", result.getFailureMessage());
+    }
+    
+    @Test
+    public void testMalformedCachePatternException() throws Exception{
+        assertion.unsetNotType();
+        assertion.setToMatchType();
+        assertion.setTestFieldResponseHeaders();
+        assertion.addTestString("[]");
+        result = assertion.getResult(sample);
+        assertNotNull(result.getFailureMessage());
+        assertFalse("Should not be: Response was null","Response was null".equals(result.getFailureMessage()));
+        assertTrue("Not expecting error: "+result.getFailureMessage(),result.isError());
+        
+        assertion.setCustomFailureMessage("Custom failure message");
+        result = assertion.getResult(sample);
+        assertTrue("Did not get expected error: "+result.getFailureMessage(),result.isError());
+        assertFalse("Failure message must not be custom failure message for error", 
+                "Custom failure message".equals(result.getFailureMessage()));
+
+    }
+    
+    @Test
     public void testResponseAssertionResponseHeaders() throws Exception{
         assertion.unsetNotType();
         assertion.setToEqualsType();

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1820745&r1=1820744&r2=1820745&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Wed Jan 10 12:50:48 2018
@@ -139,6 +139,7 @@ Summary
     <li><bug>61931</bug>New Component : Precise Throughput Timer, timer
that produces poisson arrivals with given constant throughput. Contributed by Vladimir Sitnikov
(sitnikov.vladimir at gmail.com)</li>
     <li><bug>61644</bug>HTTP Cache Manager: "Use Cache-Control/Expires
header when processing GET requests" should be checked by default</li>
     <li><bug>61645</bug>Response Assertion: Add ability to assert on Request
Data</li>
+    <li><bug>51140</bug>Response Assertion: add ability to set a specific
error/failure message that is later shown in the Assertion Result. Contributed by Ubik Load
Pack (support at ubikloadpack.com)</li>
     <li><bug>61534</bug>Convert AssertionError to a failed assertion in
the JSR223Assertion allowing users to use assert in their code</li>
     <li><bug>61756</bug>Extractors: Improve label name "Reference name"
to make it clear what it makes</li>
     <li><bug>61758</bug><code>Apply to:</code> field in Extractors,
Assertions : When entering a value in <code>JMeter Variable Name</code>, the radio
box <code>JMeter Variable Name</code> should be selected by default. Contributed
by Ubik Load Pack (support at ubikloadpack.com)</li>



Mime
View raw message