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 2017/02/19 14:16:51 UTC
svn commit: r1783634 - 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/ xdocs/usermanual/
Author: pmouawad
Date: Sun Feb 19 14:16:51 2017
New Revision: 1783634
URL: http://svn.apache.org/viewvc?rev=1783634&view=rev
Log:
Bug 60747 - Response Assertion : Add Request Headers to "Field to Test"
Bugzilla Id: 60747
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
jmeter/trunk/xdocs/usermanual/component_reference.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=1783634&r1=1783633&r2=1783634&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/assertions/ResponseAssertion.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/assertions/ResponseAssertion.java Sun Feb 19 14:16:51 2017
@@ -63,6 +63,8 @@ public class ResponseAssertion extends A
private static final String RESPONSE_MESSAGE = "Assertion.response_message"; // $NON-NLS-1$
private static final String RESPONSE_HEADERS = "Assertion.response_headers"; // $NON-NLS-1$
+
+ private static final String REQUEST_HEADERS = "Assertion.request_headers"; // $NON-NLS-1$
private static final String ASSUME_SUCCESS = "Assertion.assume_success"; // $NON-NLS-1$
@@ -139,6 +141,10 @@ public class ResponseAssertion extends A
public void setTestFieldResponseHeaders(){
setTestField(RESPONSE_HEADERS);
}
+
+ public void setTestFieldRequestHeaders() {
+ setTestField(REQUEST_HEADERS);
+ }
public boolean isTestFieldURL(){
return SAMPLE_URL.equals(getTestField());
@@ -164,6 +170,10 @@ public class ResponseAssertion extends A
return RESPONSE_HEADERS.equals(getTestField());
}
+ public boolean isTestFieldRequestHeaders(){
+ return REQUEST_HEADERS.equals(getTestField());
+ }
+
private void setTestType(int testType) {
setProperty(new IntegerProperty(TEST_TYPE, testType));
}
@@ -292,6 +302,8 @@ public class ResponseAssertion extends A
toCheck = response.getResponseCode();
} else if (isTestFieldResponseMessage()) {
toCheck = response.getResponseMessage();
+ } else if (isTestFieldRequestHeaders()) {
+ toCheck = response.getRequestHeaders();
} else if (isTestFieldResponseHeaders()) {
toCheck = response.getResponseHeaders();
} else { // Assume it is the URL
@@ -399,6 +411,8 @@ public class ResponseAssertion extends A
sb.append("code");
} else if (isTestFieldResponseMessage()) {
sb.append("message");
+ } else if (isTestFieldRequestHeaders()) {
+ sb.append("request headers");
} else if (isTestFieldResponseHeaders()) {
sb.append("headers");
} else if (isTestFieldResponseDataAsDocument()) {
@@ -535,5 +549,4 @@ public class ResponseAssertion extends A
text.append("\n\n");
return text;
}
-
}
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=1783634&r1=1783633&r2=1783634&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 Sun Feb 19 14:16:51 2017
@@ -20,6 +20,8 @@ package org.apache.jmeter.assertions.gui
import java.awt.BorderLayout;
import java.awt.Dimension;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.ActionEvent;
@@ -36,6 +38,7 @@ import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
+import javax.swing.JToggleButton;
import javax.swing.ListSelectionModel;
import org.apache.jmeter.assertions.ResponseAssertion;
@@ -76,6 +79,9 @@ public class AssertionGui extends Abstra
/** Radio button indicating that the headers should be tested. */
private JRadioButton responseHeadersButton;
+
+ /** Radio button indicating that the request headers should be tested. */
+ private JRadioButton requestHeadersButton;
/**
* Checkbox to indicate whether the response should be forced successful
@@ -169,6 +175,8 @@ public class AssertionGui extends Abstra
ra.setTestFieldResponseCode();
} else if (responseMessageButton.isSelected()) {
ra.setTestFieldResponseMessage();
+ } else if (requestHeadersButton.isSelected()) {
+ ra.setTestFieldRequestHeaders();
} else if (responseHeadersButton.isSelected()) {
ra.setTestFieldResponseHeaders();
} else { // Assume URL
@@ -214,6 +222,7 @@ public class AssertionGui extends Abstra
urlButton.setSelected(false);
responseCodeButton.setSelected(false);
responseMessageButton.setSelected(false);
+ requestHeadersButton.setSelected(false);
responseHeadersButton.setSelected(false);
assumeSuccess.setSelected(false);
@@ -259,6 +268,8 @@ public class AssertionGui extends Abstra
responseCodeButton.setSelected(true);
} else if (model.isTestFieldResponseMessage()) {
responseMessageButton.setSelected(true);
+ } else if (model.isTestFieldRequestHeaders()) {
+ requestHeadersButton.setSelected(true);
} else if (model.isTestFieldResponseHeaders()) {
responseHeadersButton.setSelected(true);
} else // Assume it is the URL
@@ -305,15 +316,13 @@ public class AssertionGui extends Abstra
* @return a new panel for selecting the response field
*/
private JPanel createFieldPanel() {
- JPanel panel = new JPanel();
- panel.setBorder(BorderFactory.createTitledBorder(JMeterUtils.getResString("assertion_resp_field"))); //$NON-NLS-1$
-
responseStringButton = new JRadioButton(JMeterUtils.getResString("assertion_text_resp")); //$NON-NLS-1$
responseAsDocumentButton = new JRadioButton(JMeterUtils.getResString("assertion_text_document")); //$NON-NLS-1$
urlButton = new JRadioButton(JMeterUtils.getResString("assertion_url_samp")); //$NON-NLS-1$
responseCodeButton = new JRadioButton(JMeterUtils.getResString("assertion_code_resp")); //$NON-NLS-1$
responseMessageButton = new JRadioButton(JMeterUtils.getResString("assertion_message_resp")); //$NON-NLS-1$
responseHeadersButton = new JRadioButton(JMeterUtils.getResString("assertion_headers")); //$NON-NLS-1$
+ requestHeadersButton = new JRadioButton(JMeterUtils.getResString("assertion_req_headers")); //$NON-NLS-1$
ButtonGroup group = new ButtonGroup();
group.add(responseStringButton);
@@ -321,22 +330,57 @@ public class AssertionGui extends Abstra
group.add(urlButton);
group.add(responseCodeButton);
group.add(responseMessageButton);
+ group.add(requestHeadersButton);
group.add(responseHeadersButton);
-
- panel.add(responseStringButton);
- panel.add(responseAsDocumentButton);
- panel.add(urlButton);
- panel.add(responseCodeButton);
- panel.add(responseMessageButton);
- panel.add(responseHeadersButton);
-
+
responseStringButton.setSelected(true);
assumeSuccess = new JCheckBox(JMeterUtils.getResString("assertion_assume_success")); //$NON-NLS-1$
- panel.add(assumeSuccess);
+ GridBagLayout gridBagLayout = new GridBagLayout();
+ GridBagConstraints gbc = new GridBagConstraints();
+ initConstraints(gbc);
+
+ JPanel panel = new JPanel(gridBagLayout);
+ panel.setBorder(BorderFactory.createTitledBorder(JMeterUtils.getResString("assertion_resp_field"))); //$NON-NLS-1$
+
+ addField(panel, responseStringButton, gbc);
+ addField(panel, responseCodeButton, gbc);
+ addField(panel, responseMessageButton, gbc);
+ addField(panel, responseHeadersButton, gbc);
+
+ resetContraints(gbc);
+ addField(panel, requestHeadersButton, gbc);
+ addField(panel, urlButton, gbc);
+ addField(panel, responseAsDocumentButton, gbc);
+ addField(panel, assumeSuccess, gbc);
return panel;
}
+
+ private void addField(JPanel panel, JToggleButton button, GridBagConstraints gbc) {
+ panel.add(button, gbc.clone());
+ gbc.gridx++;
+ gbc.fill=GridBagConstraints.HORIZONTAL;
+ }
+
+ // Next line
+ private void resetContraints(GridBagConstraints gbc) {
+ gbc.gridx = 0;
+ gbc.gridy++;
+ gbc.fill=GridBagConstraints.NONE;
+ }
+
+ private void initConstraints(GridBagConstraints gbc) {
+ gbc.anchor = GridBagConstraints.NORTHWEST;
+ gbc.fill = GridBagConstraints.NONE;
+ gbc.gridheight = 1;
+ gbc.gridwidth = 1;
+ gbc.gridx = 0;
+ gbc.gridy = 0;
+ gbc.weightx = 1;
+ gbc.weighty = 1;
+ }
+
/**
* Create a panel allowing the user to choose what type of test should be
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=1783634&r1=1783633&r2=1783634&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Sun Feb 19 14:16:51 2017
@@ -119,7 +119,8 @@ 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
-assertion_resp_field=Response Field to Test
+assertion_req_headers=Request Headers
+assertion_resp_field=Field to Test
assertion_resp_size_field=Response Size Field to Test
assertion_substring=Substring
assertion_text_document=Document (text)
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=1783634&r1=1783633&r2=1783634&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 Sun Feb 19 14:16:51 2017
@@ -114,7 +114,8 @@ 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
-assertion_resp_field=Section de r\u00E9ponse \u00E0 tester
+assertion_req_headers=Ent\u00EAtes de requ\u00EAte
+assertion_resp_field=Section \u00E0 tester
assertion_resp_size_field=Taille \u00E0 v\u00E9rifier sur
assertion_substring=Contient (texte brut)
assertion_text_document=Document (texte)
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=1783634&r1=1783633&r2=1783634&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/assertions/ResponseAssertionTest.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/assertions/ResponseAssertionTest.java Sun Feb 19 14:16:51 2017
@@ -57,6 +57,7 @@ public class ResponseAssertionTest {
sample.setURL(new URL("http://localhost/Sampler/Data/"));
sample.setResponseCode("401");
sample.setResponseHeaders("X-Header: abcd");
+ sample.setRequestHeaders("X-reqHeader: cdef");
}
@Test
@@ -78,7 +79,7 @@ public class ResponseAssertionTest {
}
@Test
- public void testResponseAssertionHeaders() throws Exception{
+ public void testResponseAssertionResponseHeaders() throws Exception{
assertion.unsetNotType();
assertion.setToEqualsType();
assertion.setTestFieldResponseHeaders();
@@ -92,6 +93,22 @@ public class ResponseAssertionTest {
result = assertion.getResult(sample);
assertPassed();
}
+
+ @Test
+ public void testResponseAssertionRequestHeaders() throws Exception{
+ assertion.unsetNotType();
+ assertion.setToEqualsType();
+ assertion.setTestFieldRequestHeaders();
+ assertion.addTestString("X-reqHeader: cdef");
+ assertion.addTestString("X-reqHeader: cdefx");
+ result = assertion.getResult(sample);
+ assertFailed();
+
+ assertion.clearTestStrings();
+ assertion.addTestString("X-reqHeader: cdef");
+ result = assertion.getResult(sample);
+ assertPassed();
+ }
@Test
public void testResponseAssertionContains() throws Exception{
Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1783634&r1=1783633&r2=1783634&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Sun Feb 19 14:16:51 2017
@@ -265,6 +265,7 @@ JMeter now requires Java 8. Ensure you u
<li><bug>60607</bug>DNS Cache Manager configuration is ignored</li>
<li><bug>60729</bug>The Random Variable Config Element should allow minimum==maximum</li>
<li><bug>60730</bug>The JSON PostProcessor should set the <code>_ALL</code> variable even if the JSON path matches only once.</li>
+ <li><bug>60747</bug>Response Assertion : Add Request Headers to <code>Field to Test</code></li>
</ul>
<h3>Functions</h3>
Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1783634&r1=1783633&r2=1783634&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Sun Feb 19 14:16:51 2017
@@ -4437,7 +4437,7 @@ DB db = MongoDBHolder.getDBFromSource("v
<component name="Response Assertion" index="§-num;.5.1" anchor="basic_assertion" width="921" height="423" screenshot="assertion/assertion.png">
<description><p>The response assertion control panel lets you add pattern strings to be compared against various
- fields of the response.
+ fields of the request or response.
The pattern strings are:
</p>
<ul>
@@ -4485,16 +4485,17 @@ These can be used anywhere within the ex
<li><code>JMeter Variable</code> - assertion is to be applied to the contents of the named variable</li>
</ul>
</property>
- <property name="Response Field to Test" required="Yes">Instructs JMeter which field of the Response to test.
+ <property name="Field to Test" required="Yes">Instructs JMeter which field of the Request or Response to test.
<ul>
<li><code>Text Response</code> - the response text from the server, i.e. the body, excluding any HTTP headers.</li>
- <li><code>Document (text)</code> - the extract text from various type of documents via Apache Tika (see <complink name="View Results Tree"/> Document view section).</li>
- <li><code>URL sampled</code></li>
<li><code>Response Code</code> - e.g. <code>200</code></li>
<li><code>Response Message</code> - e.g. <code>OK</code></li>
<li><code>Response Headers</code>, including Set-Cookie headers (if any)</li>
+ <li><code>Request Headers</code></li>
+ <li><code>URL sampled</code></li>
+ <li><code>Document (text)</code> - the extract text from various type of documents via Apache Tika (see <complink name="View Results Tree"/> Document view section).</li>
</ul>
- </property>
+ </property>
<property name="Ignore status" required="Yes">Instructs JMeter to set the status to success initially.
<p>
The overall success of the sample is determined by combining the result of the
@@ -4517,7 +4518,8 @@ These can be used anywhere within the ex
<li><code>Substring</code> - true if the text contains the pattern string (case-sensitive)</li>
</ul>
<code>Equals</code> and <code>Substring</code> patterns are plain strings, not regular expressions.
- <code>NOT</code> may also be selected to invert the result of the check.</property>
+ <code>NOT</code> may also be selected to invert the result of the check.
+ <code>OR</code> Apply each assertion in OR combination (if 1 pattern to test maches, Assertion will be ok) instead of AND (All patterns must match so that Assertion is OK).</property>
<property name="Patterns to Test" required="Yes">A list of patterns to
be tested.
Each pattern is tested separately.