Author: sebb
Date: Sat Aug 11 04:12:17 2007
New Revision: 564895

URL: http://svn.apache.org/viewvc?view=rev&rev=564895
Log:
Bug 42918 - Size Assertion now treats an empty response as having zero length

Modified:
    
jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/assertions/SizeAssertion.java
    
jakarta/jmeter/branches/rel-2-2/test/src/org/apache/jmeter/assertions/PackageTest.java
    jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml
    jakarta/jmeter/branches/rel-2-2/xdocs/usermanual/component_reference.xml

Modified: 
jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/assertions/SizeAssertion.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/assertions/SizeAssertion.java?view=diff&rev=564895&r1=564894&r2=564895
==============================================================================
--- 
jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/assertions/SizeAssertion.java
 (original)
+++ 
jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/assertions/SizeAssertion.java
 Sat Aug 11 04:12:17 2007
@@ -27,10 +27,12 @@
 import org.apache.jmeter.testelement.property.LongProperty;
 import org.apache.jmeter.util.JMeterUtils;
 
+//@see org.apache.jmeter.assertions.PackageTest for unit tests
+
 /**
  * Checks if the results of a Sample matches a particular size.
  * 
- * @author <a href="mailto:[EMAIL PROTECTED]">Wolfram Rittmeyer</a>
+ * author <a href="mailto:[EMAIL PROTECTED]">Wolfram Rittmeyer</a>
  */
 public class SizeAssertion extends AbstractTestElement implements 
Serializable, Assertion {
 
@@ -50,28 +52,23 @@
        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 = "SizeAssertion.size"; // 
$NON-NLS-1$
 
-       private static final String OPERATOR_KEY = "SizeAssertion.operator";
+       private static final String OPERATOR_KEY = "SizeAssertion.operator"; // 
$NON-NLS-1$
 
        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
-        * containing a FailureMessage will be returned. Otherwise the returned
-        * AssertionResult will reflect the success of the Sample.
+        * Returns the result of the Assertion. 
+        * Here it checks the Sample responseData length.
         */
        public AssertionResult getResult(SampleResult response) {
                AssertionResult result = new AssertionResult(getName());
                result.setFailure(false);
                resultData = response.getResponseData();
                long resultSize = resultData.length;
-               if (resultSize==0) {
-                       return result.setResultForNull();
-               }
                // is the Sample the correct size?
-               if ((!(compareSize(resultSize)) && (getAllowedSize() > 0))) {
+               if (!(compareSize(resultSize))) {
                        result.setFailure(true);
                        Object[] arguments = { new Long(resultSize), 
comparatorErrorMessage, new Long(getAllowedSize()) };
                        String message = 
MessageFormat.format(JMeterUtils.getResString("size_assertion_failure"), 
arguments); //$NON-NLS-1$
@@ -81,8 +78,7 @@
        }
 
        /**
-        * Returns the size in bytes to be asserted. A duration of 0 indicates 
this
-        * assertion is to be ignored.
+        * Returns the size in bytes to be asserted.
         */
        public long getAllowedSize() {
                return getPropertyAsLong(SIZE_KEY);

Modified: 
jakarta/jmeter/branches/rel-2-2/test/src/org/apache/jmeter/assertions/PackageTest.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/test/src/org/apache/jmeter/assertions/PackageTest.java?view=diff&rev=564895&r1=564894&r2=564895
==============================================================================
--- 
jakarta/jmeter/branches/rel-2-2/test/src/org/apache/jmeter/assertions/PackageTest.java
 (original)
+++ 
jakarta/jmeter/branches/rel-2-2/test/src/org/apache/jmeter/assertions/PackageTest.java
 Sat Aug 11 04:12:17 2007
@@ -20,6 +20,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.jmeter.junit.JMeterTestCase;
 import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.threads.JMeterContext;
 import org.apache.jmeter.threads.JMeterContextService;
@@ -83,7 +84,7 @@
                        response.setResponseData(TEST_STRING.getBytes());
                        for (int i = 0; i < 100; i++) {
                                AssertionResult result;
-                               result = assertion.evaluateResponse(response);
+                               result = assertion.getResult(response);
                                if (result.isFailure() || result.isError()) {
                                        failed++;
                                }
@@ -286,14 +287,14 @@
                        assertion.setTestFieldURL();
                        assertion.addTestString("Sampler Label");
                        assertion.addTestString("Sampler labelx");              
-                       result = assertion.evaluateResponse(sample);
+                       result = assertion.getResult(sample);
                        assertFailed();
 
                        assertion.setToNotType();
                        assertion.clearTestStrings();
                        assertion.addTestString("Sampler LabeL");
                        assertion.addTestString("Sampler Labelx");              
-                       result = assertion.evaluateResponse(sample);
+                       result = assertion.getResult(sample);
                        assertPassed();
                }
                
@@ -305,17 +306,17 @@
                        assertion.addTestString("Label");
                        assertion.addTestString(" x");
                        
-                       result = assertion.evaluateResponse(sample);
+                       result = assertion.getResult(sample);
                        assertFailed();
                        
                        assertion.setToNotType();
                        
-                       result = assertion.evaluateResponse(sample);
+                       result = assertion.getResult(sample);
                        assertFailed();
 
                        assertion.clearTestStrings();
                        assertion.addTestString("r l");
-                       result = assertion.evaluateResponse(sample);
+                       result = assertion.getResult(sample);
                        assertPassed();
 
                        assertion.unsetNotType();
@@ -323,19 +324,19 @@
                        
                        assertion.clearTestStrings();
                        assertion.addTestString("line 2");
-                       result = assertion.evaluateResponse(sample);
+                       result = assertion.getResult(sample);
                        assertPassed();
 
                        assertion.clearTestStrings();
                        assertion.addTestString("(?s)line \\d+.*EOF");
-                       result = assertion.evaluateResponse(sample);
+                       result = assertion.getResult(sample);
                        assertPassed();
 
                        assertion.setTestFieldResponseCode();
                        
                        assertion.clearTestStrings();
                        assertion.addTestString("401");
-                       result = assertion.evaluateResponse(sample);
+                       result = assertion.getResult(sample);
                        assertPassed();
 
         }
@@ -359,4 +360,147 @@
                        
                }
 }
+
+       public static class SizeAssertionTest extends JMeterTestCase{
+
+               private JMeterContext jmctx;
+               private SizeAssertion assertion;
+               private SampleResult sample1,sample0;
+               private JMeterVariables vars;
+               private AssertionResult result;
+               private String data1 = "response Data\n" +      "line 2\n\nEOF";
+               private int data1Len=data1.length();
+               public void setUp() {
+                       jmctx = JMeterContextService.getContext();
+                       assertion = new SizeAssertion();
+                       assertion.setThreadContext(jmctx);
+                       vars = new JMeterVariables();
+                       jmctx.setVariables(vars);
+                       sample0 = new SampleResult();
+                       sample1 = new SampleResult();
+                       sample1.setResponseData(data1.getBytes());
+               }
+
+               public void testSizeAssertionEquals() throws Exception{
+                       assertion.setCompOper(SizeAssertion.EQUAL);
+                       assertion.setAllowedSize(0);
+                       result = assertion.getResult(sample1);
+                       assertFailed();
+
+                       result = assertion.getResult(sample0);
+                       assertPassed();
+
+                       assertion.setAllowedSize(data1Len);
+                       result = assertion.getResult(sample1);
+                       assertPassed();
+
+                       result = assertion.getResult(sample0);
+                       assertFailed();
+        }
+               
+               public void testSizeAssertionNotEquals() throws Exception{
+                       assertion.setCompOper(SizeAssertion.NOTEQUAL);
+                       assertion.setAllowedSize(0);
+                       result = assertion.getResult(sample1);
+                       assertPassed();
+
+                       result = assertion.getResult(sample0);
+                       assertFailed();
+
+                       assertion.setAllowedSize(data1Len);
+                       result = assertion.getResult(sample1);
+                       assertFailed();
+
+                       result = assertion.getResult(sample0);
+                       assertPassed();
+        }
+
+               public void testSizeAssertionGreaterThan() throws Exception{
+                       assertion.setCompOper(SizeAssertion.GREATERTHAN);
+                       assertion.setAllowedSize(0);
+                       result = assertion.getResult(sample1);
+                       assertPassed();
+
+                       result = assertion.getResult(sample0);
+                       assertFailed();
+
+                       assertion.setAllowedSize(data1Len);
+                       result = assertion.getResult(sample1);
+                       assertFailed();
+
+                       result = assertion.getResult(sample0);
+                       assertFailed();
+        }
+               
+               public void testSizeAssertionGreaterThanEqual() throws 
Exception{
+                       assertion.setCompOper(SizeAssertion.GREATERTHANEQUAL);
+                       assertion.setAllowedSize(0);
+                       result = assertion.getResult(sample1);
+                       assertPassed();
+
+                       result = assertion.getResult(sample0);
+                       assertPassed();
+
+                       assertion.setAllowedSize(data1Len);
+                       result = assertion.getResult(sample1);
+                       assertPassed();
+
+                       result = assertion.getResult(sample0);
+                       assertFailed();
+        }
+               
+               public void testSizeAssertionLessThan() throws Exception{
+                       assertion.setCompOper(SizeAssertion.LESSTHAN);
+                       assertion.setAllowedSize(0);
+                       result = assertion.getResult(sample1);
+                       assertFailed();
+
+                       result = assertion.getResult(sample0);
+                       assertFailed();
+
+                       assertion.setAllowedSize(data1Len+1);
+                       result = assertion.getResult(sample1);
+                       assertPassed();
+
+                       result = assertion.getResult(sample0);
+                       assertPassed();
+        }
+
+               public void testSizeAssertionLessThanEqual() throws Exception{
+                       assertion.setCompOper(SizeAssertion.LESSTHANEQUAL);
+                       assertion.setAllowedSize(0);
+                       result = assertion.getResult(sample1);
+                       assertFailed();
+
+                       result = assertion.getResult(sample0);
+                       assertPassed();
+
+                       assertion.setAllowedSize(data1Len+1);
+                       result = assertion.getResult(sample1);
+                       assertPassed();
+
+                       result = assertion.getResult(sample0);
+                       assertPassed();
+        }
+// TODO - need a lot more tests
+               
+               private void assertPassed() throws Exception{
+                       if (null != result.getFailureMessage()){
+                               
//System.out.println(result.getFailureMessage());// debug
+                       }
+                       assertNull("Failure message should be 
null",result.getFailureMessage());
+                       assertFalse(result.isError());
+                       assertFalse(result.isFailure());                
+               }
+               
+               private void assertFailed() throws Exception{
+                       assertNotNull("Failure nessage should not be 
null",result.getFailureMessage());
+                       //System.out.println(result.getFailureMessage());
+                       assertFalse("Should not be: Response was 
null","Response was null".equals(result.getFailureMessage()));
+                       assertFalse(result.isError());
+                       assertTrue(result.isFailure());         
+                       
+               }
+}
+
 }

Modified: jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml?view=diff&rev=564895&r1=564894&r2=564895
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml (original)
+++ jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml Sat Aug 11 04:12:17 2007
@@ -37,6 +37,7 @@
 <li>Bug 43054 - SSLManager causes stress tests to saturate and crash</li>
 <li>Clarified HTTP Request Defaults usage of the port field</li>
 <li>Bug 43006 - NPE if icon.properties file not found</li>
+<li>Bug 42918 - Size Assertion now treats an empty response as having zero 
length</li>
 </ul>
 
 <h3>Version 2.3RC3</h3>

Modified: 
jakarta/jmeter/branches/rel-2-2/xdocs/usermanual/component_reference.xml
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/xdocs/usermanual/component_reference.xml?view=diff&rev=564895&r1=564894&r2=564895
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/xdocs/usermanual/component_reference.xml 
(original)
+++ jakarta/jmeter/branches/rel-2-2/xdocs/usermanual/component_reference.xml 
Sat Aug 11 04:12:17 2007
@@ -2519,7 +2519,9 @@
 
 <component name="Size Assertion" index="&sect-num;.5.3"  width="331" 
height="346" screenshot="size_assertion.png">
 <description><p>The Size Assertion tests that each response contains the right 
number of bytes in it.  You can specify that
-the size be equal to, greater than, less than, or not equal to a given number 
of bytes.</p></description>
+the size be equal to, greater than, less than, or not equal to a given number 
of bytes.</p>
+<note>Since JMeter 2.3RC3, an empty response is treated as being 0 bytes 
rather than reported as an error.</note>
+</description>
 
 <properties>
 <property name="Name" required="">Descriptive name for this element that is 
shown in the tree.</property>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to