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 dg...@apache.org on 2003/01/08 03:07:35 UTC
cvs commit: jakarta-jmeter/src/core/org/apache/jmeter/resources messages_no.properties messages.properties messages_ja.properties messages_de.properties
dgulino 2003/01/07 18:07:34
Modified: src/components/org/apache/jmeter/assertions/gui
SizeAssertionGui.java
src/components/org/apache/jmeter/assertions
SizeAssertion.java
src/core/org/apache/jmeter/resources messages_no.properties
messages.properties messages_ja.properties
messages_de.properties
Log:
Updated SizeAssertion to allow asserting new logical comparators.
Now will can assert =, !=, >, <, >=, <=
Revision Changes Path
1.2 +71 -9 jakarta-jmeter/src/components/org/apache/jmeter/assertions/gui/SizeAssertionGui.java
Index: SizeAssertionGui.java
===================================================================
RCS file: /home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/assertions/gui/SizeAssertionGui.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SizeAssertionGui.java 11 Dec 2002 16:07:08 -0000 1.1
+++ SizeAssertionGui.java 8 Jan 2003 02:07:34 -0000 1.2
@@ -1,4 +1,5 @@
-/* ====================================================================
+/*
+ * ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
@@ -54,9 +55,12 @@
package org.apache.jmeter.assertions.gui;
import java.awt.FlowLayout;
+import java.awt.GridLayout;
import java.awt.Font;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
@@ -65,6 +69,8 @@
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
+import javax.swing.ButtonGroup;
+import javax.swing.JRadioButton;
import org.apache.jmeter.assertions.SizeAssertion;
import org.apache.jmeter.testelement.TestElement;
@@ -83,12 +89,13 @@
*@version 1.0
***************************************/
-public class SizeAssertionGui extends AbstractAssertionGui implements FocusListener
+public class SizeAssertionGui extends AbstractAssertionGui implements FocusListener, ActionListener
{
transient private static Logger log = Hierarchy.getDefaultHierarchy().getLoggerFor(
"jmeter.elements");
private JTextField size;
+ SizeAssertion sa = new SizeAssertion();
/****************************************
* !ToDo (Constructor description)
@@ -114,8 +121,7 @@
public TestElement createTestElement()
{
//ResponseAssertion el = new ResponseAssertion();
- SizeAssertion el = new SizeAssertion();
- configureTestElement(el);
+ configureTestElement(sa);
String sizeString = size.getText();
long assertionSize = 0;
try {
@@ -124,8 +130,8 @@
catch (NumberFormatException e) {
assertionSize = Long.MAX_VALUE;
}
- el.setAllowedSize(assertionSize);
- return el;
+ sa.setAllowedSize(assertionSize);
+ return sa;
}
/****************************************
@@ -169,7 +175,53 @@
size = new JTextField(5);
size.addFocusListener(this);
sizePanel.add(size);
-
+
+ ButtonGroup comparatorButtonGroup = new ButtonGroup();
+
+ JRadioButton equalButton = new JRadioButton("=");
+ equalButton.setSelected(true);
+ equalButton.setActionCommand(new Integer(SizeAssertion.EQUAL).toString());
+ equalButton.addActionListener(this);
+ comparatorButtonGroup.add(equalButton);
+
+ JRadioButton notequalButton = new JRadioButton("!=");
+ notequalButton.setActionCommand(new Integer(SizeAssertion.NOTEQUAL).toString());
+ notequalButton.addActionListener(this);
+ comparatorButtonGroup.add(notequalButton);
+
+ JRadioButton greaterthanButton = new JRadioButton(">");
+ greaterthanButton.setActionCommand(new Integer(SizeAssertion.GREATERTHAN).toString());
+ greaterthanButton.addActionListener(this);
+ comparatorButtonGroup.add(greaterthanButton);
+
+ JRadioButton lessthanButton = new JRadioButton("<");
+ lessthanButton.setActionCommand(new Integer(SizeAssertion.LESSTHAN).toString());
+ lessthanButton.addActionListener(this);
+ comparatorButtonGroup.add(lessthanButton);
+
+ JRadioButton greaterthanequalButton = new JRadioButton(">=");
+ greaterthanequalButton.setActionCommand(new Integer(SizeAssertion.GREATERTHANEQUAL).toString());
+ greaterthanequalButton.addActionListener(this);
+ comparatorButtonGroup.add(greaterthanequalButton);
+
+ JRadioButton lessthanequalButton = new JRadioButton("<=");
+ lessthanequalButton.setActionCommand(new Integer(SizeAssertion.LESSTHANEQUAL).toString());
+ lessthanequalButton.addActionListener(this);
+ comparatorButtonGroup.add(lessthanequalButton);
+
+ //Put the check boxes in a column in a panel
+ JPanel checkPanel = new JPanel();
+ checkPanel.setLayout(new GridLayout(0, 1));
+ JLabel compareLabel = new JLabel(JMeterUtils.getResString("size_assertion_comparator_label"));
+ checkPanel.add(compareLabel);
+ checkPanel.add(equalButton);
+ checkPanel.add(notequalButton);
+ checkPanel.add(greaterthanButton);
+ checkPanel.add(lessthanButton);
+ checkPanel.add(greaterthanequalButton);
+ checkPanel.add(lessthanequalButton);
+ sizePanel.add(checkPanel);
+
mainPanel.add(sizePanel);
this.add(mainPanel);
@@ -208,5 +260,15 @@
***************************************/
public void focusGained(FocusEvent e) {
}
-
+
+ /****************************************
+ * Description of the Method
+ *
+ *@param e ActionEvent
+ ***************************************/
+ public void actionPerformed(ActionEvent e) {
+ int comparator = new Integer(e.getActionCommand()).intValue();
+ sa.setLogicalComparator(comparator);
+ }
+
}
1.2 +75 -7 jakarta-jmeter/src/components/org/apache/jmeter/assertions/SizeAssertion.java
Index: SizeAssertion.java
===================================================================
RCS file: /home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/assertions/SizeAssertion.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SizeAssertion.java 11 Dec 2002 16:07:08 -0000 1.1
+++ SizeAssertion.java 8 Jan 2003 02:07:34 -0000 1.2
@@ -1,4 +1,5 @@
-/* ====================================================================
+/*
+ * ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
@@ -73,9 +74,19 @@
*/
public class SizeAssertion extends AbstractTestElement implements Serializable, Assertion {
+ int comparator = 1;
+ String comparatorErrorMessage = "ERROR!";
+ //* Static int to signify the type of logical comparitor to assert
+ public final static int EQUAL = 1;
+ public final static int NOTEQUAL = 2;
+ public final static int GREATERTHAN = 3;
+ public final static int LESSTHAN = 4;
+ public final static int GREATERTHANEQUAL = 5;
+ public final static int LESSTHANEQUAL = 6;
/** Key for storing assertion-informations in the jmx-file. */
- private static final String SIZE_KEY = "SizeAssertion.size";
+ private static final String SIZE_KEY = "size_assertion_size";
byte[] resultData;
+
/**
* Returns the result of the Assertion. Here it checks wether the
* Sample took to long to be considered successful. If so an AssertionResult
@@ -89,9 +100,9 @@
// is the Sample the correct size?
resultData = getResultBody(response.getResponseData());
long resultSize = resultData.length;
- if (((resultSize != getAllowedSize()) && (getAllowedSize() > 0))) {
+ if ((!(compareSize(resultSize)) && (getAllowedSize() > 0))) {
result.setFailure(true);
- Object[] arguments = { new Long(resultSize), new Long(getAllowedSize())};
+ Object[] arguments = { new Long(resultSize), new String(comparatorErrorMessage), new Long(getAllowedSize())};
String message = MessageFormat.format(JMeterUtils.getResString("size_assertion_failure"), arguments);
result.setFailureMessage(message);
}
@@ -157,5 +168,62 @@
}
return slice;
}
-
-}
\ No newline at end of file
+
+ /**
+ * Set the type of logical comparator to assert.
+ *
+ * Possible values are:
+ * equal, not equal,
+ * greater than, less than,
+ * greater than eqaul, less than equal, .
+ *
+ *@param comparator is an int value indicating logical comparator type
+ *
+ */
+ public void setLogicalComparator(int comparator) {
+ this.comparator = comparator;
+ }
+
+ /**
+ * Compares the the size of a return result to the set allowed size
+ *using a logical comparator set in setLogicalComparator().
+ *
+ * Possible values are:
+ * equal, not equal,
+ * greater than, less than,
+ * greater than eqaul, less than equal, .
+ *
+ */
+
+ private boolean compareSize(long resultSize) {
+ boolean result = false;
+ switch (comparator)
+ {
+ case EQUAL:
+ result = (resultSize == getAllowedSize());
+ comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_equal");
+ break;
+ case NOTEQUAL:
+ result = (resultSize != getAllowedSize());
+ comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_notequal");
+ break;
+ case GREATERTHAN:
+ result = (resultSize > getAllowedSize());
+ comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_greater");
+ break;
+ case LESSTHAN:
+ result = (resultSize < getAllowedSize());
+ comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_less");
+ break;
+ case GREATERTHANEQUAL:
+ result = (resultSize >= getAllowedSize());
+ comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_greaterequal");
+ break;
+ case LESSTHANEQUAL:
+ result = (resultSize <= getAllowedSize());
+ comparatorErrorMessage = JMeterUtils.getResString("size_assertion_comparator_error_lessequal");
+ break;
+ }
+ return result;
+ }
+}
1.16 +16 -2 jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_no.properties
Index: messages_no.properties
===================================================================
RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_no.properties,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- messages_no.properties 30 Dec 2002 05:08:28 -0000 1.15
+++ messages_no.properties 8 Jan 2003 02:07:34 -0000 1.16
@@ -289,8 +289,22 @@
max=Maximum
error_loading_help=Error loading help page
log_errors_only=Log Errors Only
-size_assertion_failure=The result was the wrong size: It was {0} bytes, but should have been {1} bytes.
+size_assertion_comparator_error_equal=been equal to
+size_assertion_comparator_error_notequal=not been equal to
+size_assertion_comparator_error_greater=been greater than
+size_assertion_comparator_error_less=been less then
+size_assertion_comparator_error_greaterequal=been greater or equal to
+size_assertion_comparator_error_lessequal=been less than or equal to
+size_assertion_failure=The result was the wrong size: It was {0} bytes, but should have {1} {2} bytes.
size_assertion_input_error=Please enter a valid positive integer.
size_assertion_label=Size in bytes:
size_assertion_size_test=Size to Assert
-size_assertion_title=Size Assertion
\ No newline at end of file
+size_assertion_title=Size Assertion
+size_assertion_equal=1
+size_assertion_notequal=2
+size_assertion_greaterthan=3
+size_assertion_lessthan=4
+size_assertion_greaterthanequal=5
+size_assertion_lessthanequal=6
+size_assertion_size=99999999
+size_assertion_comparator_label=Type of Comparison
\ No newline at end of file
1.21 +15 -1 jakarta-jmeter/src/core/org/apache/jmeter/resources/messages.properties
Index: messages.properties
===================================================================
RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages.properties,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- messages.properties 30 Dec 2002 05:08:28 -0000 1.20
+++ messages.properties 8 Jan 2003 02:07:34 -0000 1.21
@@ -305,8 +305,22 @@
max=Maximum
error_loading_help=Error loading help page
log_errors_only=Log Errors Only
-size_assertion_failure=The result was the wrong size: It was {0} bytes, but should have been {1} bytes.
+size_assertion_comparator_error_equal=been equal to
+size_assertion_comparator_error_notequal=not been equal to
+size_assertion_comparator_error_greater=been greater than
+size_assertion_comparator_error_less=been less then
+size_assertion_comparator_error_greaterequal=been greater or equal to
+size_assertion_comparator_error_lessequal=been less than or equal to
+size_assertion_failure=The result was the wrong size: It was {0} bytes, but should have {1} {2} bytes.
size_assertion_input_error=Please enter a valid positive integer.
size_assertion_label=Size in bytes:
size_assertion_size_test=Size to Assert
size_assertion_title=Size Assertion
+size_assertion_equal=1
+size_assertion_notequal=2
+size_assertion_greaterthan=3
+size_assertion_lessthan=4
+size_assertion_greaterthanequal=5
+size_assertion_lessthanequal=6
+size_assertion_size=99999999
+size_assertion_comparator_label=Type of Comparison
1.16 +16 -2 jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_ja.properties
Index: messages_ja.properties
===================================================================
RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_ja.properties,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- messages_ja.properties 30 Dec 2002 05:08:28 -0000 1.15
+++ messages_ja.properties 8 Jan 2003 02:07:34 -0000 1.16
@@ -297,8 +297,22 @@
max=Maximum
error_loading_help=Error loading help page
log_errors_only=Log Errors Only
-size_assertion_failure=The result was the wrong size: It was {0} bytes, but should have been {1} bytes.
+size_assertion_comparator_error_equal=been equal to
+size_assertion_comparator_error_notequal=not been equal to
+size_assertion_comparator_error_greater=been greater than
+size_assertion_comparator_error_less=been less then
+size_assertion_comparator_error_greaterequal=been greater or equal to
+size_assertion_comparator_error_lessequal=been less than or equal to
+size_assertion_failure=The result was the wrong size: It was {0} bytes, but should have {1} {2} bytes.
size_assertion_input_error=Please enter a valid positive integer.
size_assertion_label=Size in bytes:
size_assertion_size_test=Size to Assert
-size_assertion_title=Size Assertion
\ No newline at end of file
+size_assertion_title=Size Assertion
+size_assertion_equal=1
+size_assertion_notequal=2
+size_assertion_greaterthan=3
+size_assertion_lessthan=4
+size_assertion_greaterthanequal=5
+size_assertion_lessthanequal=6
+size_assertion_size=99999999
+size_assertion_comparator_label=Type of Comparison
\ No newline at end of file
1.19 +16 -2 jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_de.properties
Index: messages_de.properties
===================================================================
RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/resources/messages_de.properties,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- messages_de.properties 30 Dec 2002 05:08:28 -0000 1.18
+++ messages_de.properties 8 Jan 2003 02:07:34 -0000 1.19
@@ -302,8 +302,22 @@
max=Maximum
error_loading_help=Error loading help page
log_errors_only=Log Errors Only
-size_assertion_failure=The result was the wrong size: It was {0} bytes, but should have been {1} bytes.
+size_assertion_comparator_error_equal=been equal to
+size_assertion_comparator_error_notequal=not been equal to
+size_assertion_comparator_error_greater=been greater than
+size_assertion_comparator_error_less=been less then
+size_assertion_comparator_error_greaterequal=been greater or equal to
+size_assertion_comparator_error_lessequal=been less than or equal to
+size_assertion_failure=The result was the wrong size: It was {0} bytes, but should have {1} {2} bytes.
size_assertion_input_error=Please enter a valid positive integer.
size_assertion_label=Size in bytes:
size_assertion_size_test=Size to Assert
-size_assertion_title=Size Assertion
\ No newline at end of file
+size_assertion_title=Size Assertion
+size_assertion_equal=1
+size_assertion_notequal=2
+size_assertion_greaterthan=3
+size_assertion_lessthan=4
+size_assertion_greaterthanequal=5
+size_assertion_lessthanequal=6
+size_assertion_size=99999999
+size_assertion_comparator_label=Type of Comparison
\ No newline at end of file
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>