sebb 2003/10/15 16:05:33
Modified: src/components/org/apache/jmeter/assertions/gui
AssertionGui.java
src/components/org/apache/jmeter/assertions
ResponseAssertion.java
Log:
Response Assertion can now check response code and response message
Revision Changes Path
1.14 +38 -9
jakarta-jmeter/src/components/org/apache/jmeter/assertions/gui/AssertionGui.java
Index: AssertionGui.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/assertions/gui/AssertionGui.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- AssertionGui.java 7 Jun 2003 18:37:05 -0000 1.13
+++ AssertionGui.java 15 Oct 2003 23:05:33 -0000 1.14
@@ -95,6 +95,12 @@
/** Radio button indicating that the URL should be tested. */
private JRadioButton labelButton;
+ /** Radio button indicating that the responseMessage should be tested. */
+ private JRadioButton responseMessageButton;
+
+ /** Radio button indicating that the responseCode should be tested. */
+ private JRadioButton responseCodeButton;
+
/**
* Radio button indicating to test if the field contains one of the
* patterns.
@@ -166,6 +172,14 @@
{
ra.setTestField(ResponseAssertion.SAMPLE_LABEL);
}
+ else if (responseCodeButton.isSelected())
+ {
+ ra.setTestField(ResponseAssertion.RESPONSE_CODE);
+ }
+ else if (responseMessageButton.isSelected())
+ {
+ ra.setTestField(ResponseAssertion.RESPONSE_MESSAGE);
+ }
else
{
ra.setTestField(ResponseAssertion.RESPONSE_DATA);
@@ -227,11 +241,17 @@
if (ResponseAssertion.RESPONSE_DATA.equals(model.getTestField()))
{
responseStringButton.setSelected(true);
- labelButton.setSelected(false);
}
- else
+ else if (ResponseAssertion.RESPONSE_CODE.equals(model.getTestField()))
+ {
+ responseCodeButton.setSelected(true);
+ }
+ else if
(ResponseAssertion.RESPONSE_MESSAGE.equals(model.getTestField()))
+ {
+ responseMessageButton.setSelected(true);
+ }
+ else // Assume it is the URL
{
- responseStringButton.setSelected(false);
labelButton.setSelected(true);
}
@@ -287,13 +307,22 @@
new JRadioButton(JMeterUtils.getResString("assertion_text_resp"));
labelButton =
new JRadioButton(JMeterUtils.getResString("assertion_url_samp"));
+ responseCodeButton =
+ new
JRadioButton(JMeterUtils.getResString("assertion_code_resp"));
+ responseMessageButton =
+ new
JRadioButton(JMeterUtils.getResString("assertion_message_resp"));
ButtonGroup group = new ButtonGroup();
group.add(responseStringButton);
group.add(labelButton);
+ group.add(responseCodeButton);
+ group.add(responseMessageButton);
+
panel.add(responseStringButton);
panel.add(labelButton);
-
+ panel.add(responseCodeButton);
+ panel.add(responseMessageButton);
+
responseStringButton.setSelected(true);
return panel;
1.13 +53 -18
jakarta-jmeter/src/components/org/apache/jmeter/assertions/ResponseAssertion.java
Index: ResponseAssertion.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/assertions/ResponseAssertion.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- ResponseAssertion.java 2 Oct 2003 19:25:08 -0000 1.12
+++ ResponseAssertion.java 15 Oct 2003 23:05:33 -0000 1.13
@@ -1,4 +1,8 @@
/*
+ * $Header$
+ * $Revision$
+ * $Date$
+ *
* ====================================================================
* The Apache Software License, Version 1.1
*
@@ -75,21 +79,24 @@
*
* @author Michael Stover
* @author <a href="mailto:[EMAIL PROTECTED]">Jonathan Carlson</a>
- * @created $Date$
- * @version $Revision$
+ * @version $Revision$ Last Updated: $Date$
***********************************************************/
public class ResponseAssertion
extends AbstractTestElement
implements Serializable, Assertion
{
public final static String TEST_FIELD = "Assertion.test_field";
- public final static String TEST_TYPE = "Assertion.test_type";
- public final static String TEST_STRINGS = "Asserion.test_strings";
+ // Values for TEST_FIELD
public final static String SAMPLE_LABEL = "Assertion.sample_label";
public final static String RESPONSE_DATA = "Assertion.response_data";
+ public final static String RESPONSE_CODE = "Assertion.response_code";
+ public final static String RESPONSE_MESSAGE = "Assertion.response_message";
+
+ public final static String TEST_STRINGS = "Asserion.test_strings";
+ public final static String TEST_TYPE = "Assertion.test_type";
/*
- * Mask values for TestType
+ * Mask values for TEST_TYPE
* TODO: remove either MATCH or CONTAINS - they are mutually exckusive
*/
public final static int MATCH = 1 << 0;
@@ -161,15 +168,15 @@
{
getTestStrings().addProperty(new StringProperty(testString,testString));
}
- public void setTestString(String testString, int index)
+ public void setTestString(String testString, int index)//NOTUSED?
{
getTestStrings().set(index, testString);
}
- public void removeTestString(String testString)
+ public void removeTestString(String testString)//NOTUSED?
{
getTestStrings().remove(testString);
}
- public void removeTestString(int index)
+ public void removeTestString(int index)//NOTUSED?
{
getTestStrings().remove(index);
}
@@ -275,16 +282,27 @@
boolean pass = true;
boolean not = (NOT & getTestType()) > 0;
AssertionResult result = new AssertionResult();
- String toCheck; // The string to check (Url or data)
+ String toCheck=""; // The string to check (Url or data)
+ // What are we testing against?
if (ResponseAssertion.RESPONSE_DATA.equals(getTestField()))
- { // We're testing the response data
+ {
toCheck = new String(response.responseDataAsBA());
- } else { // we're testing the URL
+ }
+ else if (ResponseAssertion.RESPONSE_CODE.equals(getTestField()))
+ {
+ toCheck=response.getResponseCode();
+ }
+ else if (ResponseAssertion.RESPONSE_MESSAGE.equals(getTestField()))
+ {
+ toCheck=response.getResponseMessage();
+ }
+ else
+ { // Assume it is the URL
toCheck=response.getSamplerData();
if (toCheck == null) toCheck = "";
}
-
+
if(toCheck.length()==0)
{
return setResultForNull(result);
@@ -343,24 +361,41 @@
*/
private String getFailText(String stringPattern) {
String text;
+ String what;
+ if (ResponseAssertion.RESPONSE_DATA.equals(getTestField()))
+ {
+ what="text";
+ }
+ else if (ResponseAssertion.RESPONSE_CODE.equals(getTestField()))
+ {
+ what="code";
+ }
+ else if (ResponseAssertion.RESPONSE_MESSAGE.equals(getTestField()))
+ {
+ what="message";
+ }
+ else // Assume it is the URL
+ {
+ what="URL";
+ }
switch(getTestType()){
case CONTAINS:
- text = "Test failed, expected to contain ";
+ text = " expected to contain ";
break;
case NOT | CONTAINS:
- text = "Test failed, expected not to contain ";
+ text = " expected not to contain ";
break;
case MATCH:
- text = "Test failed, expected to match ";
+ text = " expected to match ";
break;
case NOT | MATCH:
- text = "Test failed, expected not to match ";
+ text = " expected not to match ";
break;
default:// should never happen...
- text = "Test failed, expected something using ";
+ text = " expected something using ";
}
- return text + "/" + stringPattern + "/";
+ return "Test failed, " + what + text + "/" + stringPattern + "/";
}
protected AssertionResult setResultForNull(AssertionResult result)
{
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]