Author: sebb
Date: Fri Feb  9 17:24:36 2007
New Revision: 505601

URL: http://svn.apache.org/viewvc?view=rev&rev=505601
Log:
Bug 40369 (partial) add equals matching to Response Assertion
Also tidied up the interfaces somewhat

Modified:
    
jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/assertions/ResponseAssertion.java
    
jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/assertions/gui/AssertionGui.java
    
jakarta/jmeter/branches/rel-2-2/test/src/org/apache/jmeter/assertions/PackageTest.java
    jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml

Modified: 
jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/assertions/ResponseAssertion.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/assertions/ResponseAssertion.java?view=diff&rev=505601&r1=505600&r2=505601
==============================================================================
--- 
jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/assertions/ResponseAssertion.java
 (original)
+++ 
jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/assertions/ResponseAssertion.java
 Fri Feb  9 17:24:36 2007
@@ -29,6 +29,7 @@
 import org.apache.jmeter.testelement.property.NullProperty;
 import org.apache.jmeter.testelement.property.PropertyIterator;
 import org.apache.jmeter.testelement.property.StringProperty;
+import org.apache.jmeter.util.JMeterUtils;
 import org.apache.jorphan.logging.LoggingManager;
 import org.apache.jorphan.util.JOrphanUtils;
 import org.apache.log.Logger;
@@ -38,6 +39,8 @@
 import org.apache.oro.text.regex.Perl5Compiler;
 import org.apache.oro.text.regex.Perl5Matcher;
 
+// @see org.apache.jmeter.assertions.PackageTest for unit tests
+
 /**
  * 
  * @author Michael Stover
@@ -46,22 +49,23 @@
 public class ResponseAssertion extends AbstractTestElement implements 
Serializable, Assertion {
        private static final Logger log = LoggingManager.getLoggerForClass();
 
-       public final static String TEST_FIELD = "Assertion.test_field";  // 
$NON-NLS-1$
+       private final static String TEST_FIELD = "Assertion.test_field";  // 
$NON-NLS-1$
 
        // Values for TEST_FIELD
-       public final static String SAMPLE_LABEL = "Assertion.sample_label"; // 
$NON-NLS-1$
+       // N.B. we cannot change the text value as it is in test plans
+       private final static String SAMPLE_URL = "Assertion.sample_label"; // 
$NON-NLS-1$
 
-       public final static String RESPONSE_DATA = "Assertion.response_data"; 
// $NON-NLS-1$
+       private final static String RESPONSE_DATA = "Assertion.response_data"; 
// $NON-NLS-1$
 
-       public final static String RESPONSE_CODE = "Assertion.response_code"; 
// $NON-NLS-1$
+       private final static String RESPONSE_CODE = "Assertion.response_code"; 
// $NON-NLS-1$
 
-       public final static String RESPONSE_MESSAGE = 
"Assertion.response_message"; // $NON-NLS-1$
+       private final static String RESPONSE_MESSAGE = 
"Assertion.response_message"; // $NON-NLS-1$
 
-       public final static String ASSUME_SUCCESS = "Assertion.assume_success"; 
// $NON-NLS-1$
+       private final static String ASSUME_SUCCESS = 
"Assertion.assume_success"; // $NON-NLS-1$
 
-       public final static String TEST_STRINGS = "Asserion.test_strings"; // 
$NON-NLS-1$
+       private final static String TEST_STRINGS = "Asserion.test_strings"; // 
$NON-NLS-1$
 
-       public final static String TEST_TYPE = "Assertion.test_type"; // 
$NON-NLS-1$
+       private final static String TEST_TYPE = "Assertion.test_type"; // 
$NON-NLS-1$
 
        /*
         * Mask values for TEST_TYPE TODO: remove either MATCH or CONTAINS - 
they
@@ -73,6 +77,8 @@
 
        private final static int NOT = 1 << 2;
 
+       private final static int EQUALS = 1 << 3;
+
        private static ThreadLocal matcher = new ThreadLocal() {
                protected Object initialValue() {
                        return new Perl5Matcher();
@@ -81,91 +87,76 @@
 
        private static final PatternCacheLRU patternCache = new 
PatternCacheLRU(1000, new Perl5Compiler());
 
-       
/***************************************************************************
-        * !ToDo (Constructor description)
-        
**************************************************************************/
+    private static final int  EQUALS_SECTION_DIFF_LEN
+            = JMeterUtils.getPropDefault("assertion.equals_section_diff_len", 
100);
+
+    /** Signifies truncated text in diff display. */
+    private static final String EQUALS_DIFF_TRUNC = "...";
+
+    private static final String RECEIVED_STR = "****** received  : ";
+    private static final String COMPARISON_STR = "****** comparison: ";
+    private static final String DIFF_DELTA_START
+            = JMeterUtils.getPropDefault("assertion.equals_diff_delta_start", 
"[[[");
+    private static final String DIFF_DELTA_END
+            = JMeterUtils.getPropDefault("assertion.equals_diff_delta_end", 
"]]]");
+
        public ResponseAssertion() {
                setProperty(new CollectionProperty(TEST_STRINGS, new 
ArrayList()));
        }
 
-       
/***************************************************************************
-        * !ToDo (Constructor description)
-        * 
-        * @param field
-        *            !ToDo (Parameter description)
-        * @param type
-        *            !ToDo (Parameter description)
-        * @param string
-        *            !ToDo (Parameter description)
-        
**************************************************************************/
-       public ResponseAssertion(String field, int type, String string) {
-               this();
-               setTestField(field);
-               setTestType(type);
-               getTestStrings().addProperty(new StringProperty(string, 
string));
-       }
-
        public void clear() {
                super.clear();
                setProperty(new CollectionProperty(TEST_STRINGS, new 
ArrayList()));
        }
 
-       
/***************************************************************************
-        * !ToDo (Method description)
-        * 
-        * @param testField
-        *            !ToDo (Parameter description)
-        
**************************************************************************/
-       public void setTestField(String testField) {
+       private void setTestField(String testField) {
                setProperty(TEST_FIELD, testField);
        }
 
-       
/***************************************************************************
-        * !ToDo (Method description)
-        * 
-        * @param testType
-        *            !ToDo (Parameter description)
-        
**************************************************************************/
-       public void setTestType(int testType) {
-               setProperty(new IntegerProperty(TEST_TYPE, testType));
+       public void setTestFieldURL(){
+               setTestField(SAMPLE_URL);
        }
 
-       
/***************************************************************************
-        * !ToDo (Method description)
-        * 
-        * @param testString
-        *            !ToDo (Parameter description)
-        
**************************************************************************/
-       public void addTestString(String testString) {
-               getTestStrings().addProperty(new 
StringProperty(String.valueOf(testString.hashCode()), testString));
+       public void setTestFieldResponseCode(){
+               setTestField(RESPONSE_CODE);
+       }
+
+       public void setTestFieldResponseData(){
+               setTestField(RESPONSE_DATA);
+       }
+
+       public void setTestFieldResponseMessage(){
+               setTestField(RESPONSE_MESSAGE);
+       }
+
+       public boolean isTestFieldURL(){
+               return SAMPLE_URL.equals(getTestField());
+       }
+
+       public boolean isTestFieldResponseCode(){
+               return RESPONSE_CODE.equals(getTestField());
+       }
+
+       public boolean isTestFieldResponseData(){
+               return RESPONSE_DATA.equals(getTestField());
        }
 
-       public void setTestString(String testString, int index)// NOTUSED?
-       {
-               getTestStrings().set(index, testString);
+       public boolean isTestFieldResponseMessage(){
+               return RESPONSE_MESSAGE.equals(getTestField());
        }
 
-       public void removeTestString(String testString)// NOTUSED?
-       {
-               getTestStrings().remove(testString);
+       private void setTestType(int testType) {
+               setProperty(new IntegerProperty(TEST_TYPE, testType));
        }
 
-       public void removeTestString(int index)// NOTUSED?
-       {
-               getTestStrings().remove(index);
+       public void addTestString(String testString) {
+               getTestStrings().addProperty(new 
StringProperty(String.valueOf(testString.hashCode()), testString));
        }
 
        public void clearTestStrings() {
                getTestStrings().clear();
        }
 
-       
/***************************************************************************
-        * !ToDoo (Method description)
-        * 
-        * @param response
-        *            !ToDo (Parameter description)
-        * @return !ToDo (Return description)
-        
**************************************************************************/
        public AssertionResult getResult(SampleResult response) {
                AssertionResult result;
 
@@ -218,6 +209,10 @@
                return (CollectionProperty) getProperty(TEST_STRINGS);
        }
 
+       public boolean isEqualsType() {
+               return (getTestType() & EQUALS) > 0;
+       }
+
        public boolean isContainsType() {
                return (getTestType() & CONTAINS) > 0;
        }
@@ -231,11 +226,15 @@
        }
 
        public void setToContainsType() {
-               setTestType((getTestType() | CONTAINS) & (~MATCH));
+               setTestType((getTestType() | CONTAINS) & ~(MATCH | EQUALS));
        }
 
        public void setToMatchType() {
-               setTestType((getTestType() | MATCH) & (~CONTAINS));
+               setTestType((getTestType() | MATCH) & ~(CONTAINS | EQUALS));
+       }
+
+       public void setToEqualsType() {
+               setTestType((getTestType() | EQUALS) & ~(MATCH | CONTAINS));
        }
 
        public void setToNotType() {
@@ -272,17 +271,17 @@
                }
 
                // What are we testing against?
-               if (ResponseAssertion.RESPONSE_DATA.equals(getTestField())) {
+               if (isTestFieldResponseData()) {
                        // TODO treat header separately from response? (would 
not apply to
                        // all samplers)
                        String data = response.getResponseDataAsString(); // 
(bug25052)
                        toCheck = new 
StringBuffer(response.getResponseHeaders()).append(data).toString();
-               } else if 
(ResponseAssertion.RESPONSE_CODE.equals(getTestField())) {
+               } else if (isTestFieldResponseCode()) {
                        toCheck = response.getResponseCode();
-               } else if 
(ResponseAssertion.RESPONSE_MESSAGE.equals(getTestField())) {
+               } else if (isTestFieldResponseMessage()) {
                        toCheck = response.getResponseMessage();
                } else { // Assume it is the URL
-                       toCheck = response.getSamplerData();
+                       toCheck = response.getSamplerData(); // TODO - is this 
where the URL is stored?
                        if (toCheck == null)
                                toCheck = "";
                }
@@ -295,6 +294,7 @@
                result.setError(false);
 
                boolean contains = isContainsType(); // do it once outside loop
+               boolean equals = isEqualsType();
                boolean debugEnabled = log.isDebugEnabled();
                if (debugEnabled){
                        log.debug("Type:" + (contains?"Contains":"Match") + 
(not? "(not)": ""));
@@ -310,6 +310,8 @@
                                boolean found;
                                if (contains) {
                                        found = localMatcher.contains(toCheck, 
pattern);
+                } else if (equals) {
+                    found = toCheck.equals(stringPattern);
                                } else {
                                        found = localMatcher.matches(toCheck, 
pattern);
                                }
@@ -317,7 +319,7 @@
                                if (!pass) {
                                        if (debugEnabled){log.debug("Failed: 
"+pattern);}
                                        result.setFailure(true);
-                                       
result.setFailureMessage(getFailText(stringPattern));
+                                       
result.setFailureMessage(getFailText(stringPattern,toCheck));
                                        break;
                                }
                                if (debugEnabled){log.debug("Passed: 
"+pattern);}
@@ -337,36 +339,148 @@
         * @return the message for the assertion report 
         */
        // TODO strings should be resources
-       private String getFailText(String stringPattern) {
-               String text;
-               String what;
+       private String getFailText(String stringPattern, String toCheck) {
+               
+               StringBuffer sb = new StringBuffer(200);
+               sb.append("Test failed, ");
+
                if (ResponseAssertion.RESPONSE_DATA.equals(getTestField())) {
-                       what = "text";
+                       sb.append("text");
                } else if 
(ResponseAssertion.RESPONSE_CODE.equals(getTestField())) {
-                       what = "code";
+                       sb.append("code");
                } else if 
(ResponseAssertion.RESPONSE_MESSAGE.equals(getTestField())) {
-                       what = "message";
+                       sb.append("message");
                } else // Assume it is the URL
                {
-                       what = "URL";
+                       sb.append("URL");
                }
+
                switch (getTestType()) {
                case CONTAINS:
-                       text = " expected to contain ";
+                       sb.append(" expected to contain ");
                        break;
                case NOT | CONTAINS:
-                       text = " expected not to contain ";
+                       sb.append(" expected not to contain ");
                        break;
                case MATCH:
-                       text = " expected to match ";
+                       sb.append(" expected to match ");
                        break;
                case NOT | MATCH:
-                       text = " expected not to match ";
+                       sb.append(" expected not to match ");
+                       break;
+               case EQUALS:
+                       sb.append(" expected to equal ");
+                       break;
+               case NOT | EQUALS:
+                       sb.append(" expected not to equal ");
                        break;
                default:// should never happen...
-                       text = " expected something using ";
+                       sb.append(" expected something using ");
                }
 
-               return "Test failed, " + what + text + "/" + stringPattern + 
"/";
+               sb.append("/");
+               
+               if (isEqualsType()){
+                       sb.append(equalsComparisonText(toCheck, stringPattern));
+               } else {
+                       sb.append(stringPattern);
+               }
+               
+               sb.append("/");
+               
+               return sb.toString();
        }
+
+
+    private static String trunc(final boolean right, final String str)
+    {
+        if (str.length() <= EQUALS_SECTION_DIFF_LEN)
+            return str;
+        else if (right)
+            return str.substring(0, EQUALS_SECTION_DIFF_LEN) + 
EQUALS_DIFF_TRUNC;
+        else
+            return EQUALS_DIFF_TRUNC + str.substring(str.length() - 
EQUALS_SECTION_DIFF_LEN, str.length());
+    }
+
+    /**
+     *   Returns some helpful logging text to determine where equality between 
two strings
+     * is broken, with one pointer working from the front of the strings and 
another working
+     * backwards from the end.
+     *
+     * @param received      String received from sampler.
+     * @param comparison    String specified for "equals" response assertion.
+     * @return  Two lines of text separated by newlines, and then forward and 
backward pointers
+     *      denoting first position of difference.
+     */
+    private static StringBuffer equalsComparisonText(final String received, 
final String comparison)
+    {
+        final StringBuffer      text;
+        int                     firstDiff;
+        int                     lastRecDiff = -1;
+        int                     lastCompDiff = -1;
+        final int               recLength = received.length();
+        final int               compLength = comparison.length();
+        final int               minLength = Math.min(recLength, compLength);
+        final String            startingEqSeq;
+        String                  recDeltaSeq = "";
+        String                  compDeltaSeq = "";
+        String                  endingEqSeq = "";
+        final StringBuffer      pad;
+
+
+        text = new StringBuffer(Math.max(recLength, compLength) * 2);
+        for (firstDiff = 0; firstDiff < minLength; firstDiff++)
+            if (received.charAt(firstDiff) != comparison.charAt(firstDiff))
+                break;
+        if (firstDiff == 0)
+            startingEqSeq = "";
+        else
+            startingEqSeq = trunc(false, received.substring(0, firstDiff));
+
+        lastRecDiff = recLength - 1;
+        lastCompDiff = compLength - 1;
+
+        while ((lastRecDiff > firstDiff) && (lastCompDiff > firstDiff)
+                && received.charAt(lastRecDiff) == 
comparison.charAt(lastCompDiff))
+        {
+            lastRecDiff--;
+            lastCompDiff--;
+        }
+        endingEqSeq = trunc(true, received.substring(lastRecDiff + 1, 
recLength));
+        if (endingEqSeq.length() == 0)
+        {
+            recDeltaSeq = trunc(true, received.substring(firstDiff, 
recLength));
+            compDeltaSeq = trunc(true, comparison.substring(firstDiff, 
compLength));
+        }
+        else
+        {
+            recDeltaSeq = trunc(true, received.substring(firstDiff, 
lastRecDiff + 1));
+            compDeltaSeq = trunc(true, comparison.substring(firstDiff, 
lastCompDiff + 1));
+        }
+        pad = new StringBuffer(Math.abs(recDeltaSeq.length() - 
compDeltaSeq.length()));
+        for (int i = 0; i < pad.capacity(); i++)
+            pad.append(' ');
+        if (recDeltaSeq.length() > compDeltaSeq.length())
+            compDeltaSeq += pad.toString();
+        else
+            recDeltaSeq += pad.toString();
+
+        text.append("\n\n");
+        text.append(RECEIVED_STR);
+        text.append(startingEqSeq);
+        text.append(DIFF_DELTA_START);
+        text.append(recDeltaSeq);
+        text.append(DIFF_DELTA_END);
+        text.append(endingEqSeq);
+        text.append("\n\n");
+        text.append(COMPARISON_STR);
+        text.append(startingEqSeq);
+        text.append(DIFF_DELTA_START);
+        text.append(compDeltaSeq);
+        text.append(DIFF_DELTA_END);
+        text.append(endingEqSeq);
+        text.append("\n\n");
+        return text;
+    }
+
 }

Modified: 
jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/assertions/gui/AssertionGui.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/assertions/gui/AssertionGui.java?view=diff&rev=505601&r1=505600&r2=505601
==============================================================================
--- 
jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/assertions/gui/AssertionGui.java
 (original)
+++ 
jakarta/jmeter/branches/rel-2-2/src/components/org/apache/jmeter/assertions/gui/AssertionGui.java
 Fri Feb  9 17:24:36 2007
@@ -54,7 +54,7 @@
        private JRadioButton responseStringButton;
 
        /** Radio button indicating that the URL should be tested. */
-       private JRadioButton labelButton;
+       private JRadioButton urlButton;
 
        /** Radio button indicating that the responseMessage should be tested. 
*/
        private JRadioButton responseMessageButton;
@@ -81,6 +81,11 @@
        private JRadioButton matchesBox;
 
        /**
+        * Radio button indicating if the field equals the first pattern.
+        */
+       private JRadioButton equalsBox;
+
+    /**
         * Checkbox indicating to test that the field does NOT contain/match the
         * patterns.
         */
@@ -128,20 +133,22 @@
                                ra.addTestString(testStrings[i]);
                        }
 
-                       if (labelButton.isSelected()) {
-                               ra.setTestField(ResponseAssertion.SAMPLE_LABEL);
+                       if (urlButton.isSelected()) {
+                               ra.setTestFieldURL();
                        } else if (responseCodeButton.isSelected()) {
-                               
ra.setTestField(ResponseAssertion.RESPONSE_CODE);
+                               ra.setTestFieldResponseCode();
                        } else if (responseMessageButton.isSelected()) {
-                               
ra.setTestField(ResponseAssertion.RESPONSE_MESSAGE);
+                               ra.setTestFieldResponseMessage();
                        } else {
-                               
ra.setTestField(ResponseAssertion.RESPONSE_DATA);
+                               ra.setTestFieldResponseData();
                        }
 
                        ra.setAssumeSuccess(assumeSuccess.isSelected());
 
                        if (containsBox.isSelected()) {
                                ra.setToContainsType();
+                       } else if (equalsBox.isSelected()) {
+                ra.setToEqualsType();
                        } else {
                                ra.setToMatchType();
                        }
@@ -170,9 +177,15 @@
                if (model.isContainsType()) {
                        containsBox.setSelected(true);
                        matchesBox.setSelected(false);
+            equalsBox.setSelected(false);
+        } else if (model.isEqualsType()) {
+                       containsBox.setSelected(false);
+                       matchesBox.setSelected(false);
+            equalsBox.setSelected(true);
                } else {
                        containsBox.setSelected(false);
                        matchesBox.setSelected(true);
+            equalsBox.setSelected(false);
                }
 
                if (model.isNotType()) {
@@ -181,15 +194,15 @@
                        notBox.setSelected(false);
                }
 
-               if 
(ResponseAssertion.RESPONSE_DATA.equals(model.getTestField())) {
+               if (model.isTestFieldResponseData()) {
                        responseStringButton.setSelected(true);
-               } else if 
(ResponseAssertion.RESPONSE_CODE.equals(model.getTestField())) {
+               } else if (model.isTestFieldResponseCode()) {
                        responseCodeButton.setSelected(true);
-               } else if 
(ResponseAssertion.RESPONSE_MESSAGE.equals(model.getTestField())) {
+               } else if (model.isTestFieldResponseMessage()) {
                        responseMessageButton.setSelected(true);
                } else // Assume it is the URL
                {
-                       labelButton.setSelected(true);
+                       urlButton.setSelected(true);
                }
 
                assumeSuccess.setSelected(model.getAssumeSuccess());
@@ -235,18 +248,18 @@
                
panel.setBorder(BorderFactory.createTitledBorder(JMeterUtils.getResString("assertion_resp_field")));
 
                responseStringButton = new 
JRadioButton(JMeterUtils.getResString("assertion_text_resp"));
-               labelButton = new 
JRadioButton(JMeterUtils.getResString("assertion_url_samp"));
+               urlButton = 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(urlButton);
                group.add(responseCodeButton);
                group.add(responseMessageButton);
 
                panel.add(responseStringButton);
-               panel.add(labelButton);
+               panel.add(urlButton);
                panel.add(responseCodeButton);
                panel.add(responseMessageButton);
 
@@ -278,6 +291,10 @@
                matchesBox = new 
JRadioButton(JMeterUtils.getResString("assertion_matches"));
                group.add(matchesBox);
                panel.add(matchesBox);
+
+               equalsBox = new 
JRadioButton(JMeterUtils.getResString("assertion_equals"));
+               group.add(equalsBox);
+               panel.add(equalsBox);
 
                notBox = new 
JCheckBox(JMeterUtils.getResString("assertion_not"));
                panel.add(notBox);

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=505601&r1=505600&r2=505601
==============================================================================
--- 
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
 Fri Feb  9 17:24:36 2007
@@ -18,15 +18,14 @@
 
 package org.apache.jmeter.assertions;
 
+import junit.framework.TestCase;
+
 import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.threads.JMeterContext;
 import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
 import org.apache.jorphan.logging.LoggingManager;
 import org.apache.log.Logger;
-
-import junit.framework.TestCase;
-import junit.textui.TestRunner;
 public class PackageTest extends TestCase {
 
        public PackageTest() {
@@ -76,8 +75,10 @@
                static final String TEST_PATTERN = ".*A.*\\.";
 
                public void run() {
-                       ResponseAssertion assertion = new ResponseAssertion(
-                                       ResponseAssertion.RESPONSE_DATA, 
ResponseAssertion.CONTAINS, TEST_PATTERN);
+                       ResponseAssertion assertion = new ResponseAssertion();
+                       assertion.setTestFieldResponseData();
+                       assertion.setToContainsType();
+                       assertion.addTestString(TEST_PATTERN);
                        SampleResult response = new SampleResult();
                        response.setResponseData(TEST_STRING.getBytes());
                        for (int i = 0; i < 100; i++) {
@@ -93,6 +94,7 @@
                        }
                }
        }
+       
        public static class XPathAssertionTest extends TestCase {
                private static final Logger log = 
LoggingManager.getLoggerForClass();
 
@@ -251,9 +253,110 @@
                        assertFalse(res.isFailure());
                }
 
-               public static void main(String[] args) {
-                       TestRunner.run(XPathAssertionTest.class);
-               }
        }
 
+       public static class ResponseAssertionTest extends TestCase{
+
+               private JMeterContext jmctx;
+               private ResponseAssertion assertion;
+               private SampleResult sample;
+               private JMeterVariables vars;
+               private AssertionResult result;
+               
+               public void setUp() {
+                       jmctx = JMeterContextService.getContext();
+                       assertion = new ResponseAssertion();
+                       assertion.setThreadContext(jmctx);
+                       sample = new SampleResult();
+                       vars = new JMeterVariables();
+                       jmctx.setVariables(vars);
+                       jmctx.setPreviousResult(sample);
+                       sample.setResponseData(
+                                       (
+                                       "response Data\n" +
+                                       "line 2\n\nEOF"
+                                       ).getBytes());
+                       sample.setSamplerData("Sampler Label");// This is where 
RA checks the URL!
+                       sample.setResponseCode("401");
+               }
+
+               public void testResponseAssertionEquals() throws Exception{
+                       assertion.unsetNotType();
+                       assertion.setToEqualsType();
+                       assertion.setTestFieldURL();
+                       assertion.addTestString("Sampler Label");
+                       assertion.addTestString("Sampler labelx");              
+                       result = assertion.evaluateResponse(sample);
+                       assertFailed();
+
+                       assertion.setToNotType();
+                       assertion.clearTestStrings();
+                       assertion.addTestString("Sampler LabeL");
+                       assertion.addTestString("Sampler Labelx");              
+                       result = assertion.evaluateResponse(sample);
+                       assertPassed();
+               }
+               
+               public void testResponseAssertionContains() throws Exception{
+                       assertion.unsetNotType();
+                       assertion.setToContainsType();
+                       assertion.setTestFieldURL();
+                       assertion.addTestString("Sampler");
+                       assertion.addTestString("Label");
+                       assertion.addTestString(" x");
+                       
+                       result = assertion.evaluateResponse(sample);
+                       assertFailed();
+                       
+                       assertion.setToNotType();
+                       
+                       result = assertion.evaluateResponse(sample);
+                       assertFailed();
+
+                       assertion.clearTestStrings();
+                       assertion.addTestString("r l");
+                       result = assertion.evaluateResponse(sample);
+                       assertPassed();
+
+                       assertion.unsetNotType();
+                       assertion.setTestFieldResponseData();
+                       
+                       assertion.clearTestStrings();
+                       assertion.addTestString("line 2");
+                       result = assertion.evaluateResponse(sample);
+                       assertPassed();
+
+                       assertion.clearTestStrings();
+                       assertion.addTestString("(?s)line \\d+.*EOF");
+                       result = assertion.evaluateResponse(sample);
+                       assertPassed();
+
+                       assertion.setTestFieldResponseCode();
+                       
+                       assertion.clearTestStrings();
+                       assertion.addTestString("401");
+                       result = assertion.evaluateResponse(sample);
+                       assertPassed();
+
+        }
+// TODO - need a lot more tests
+               
+               private void assertPassed() throws Exception{
+                       if (null != result.getFailureMessage()){
+                               
//System.out.println(result.getFailureMessage());// debug
+                       }
+                       assertNull(result.getFailureMessage());
+                       assertFalse(result.isError());
+                       assertFalse(result.isFailure());                
+               }
+               
+               private void assertFailed() throws Exception{
+                       assertNotNull(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=505601&r1=505600&r2=505601
==============================================================================
--- jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml (original)
+++ jakarta/jmeter/branches/rel-2-2/xdocs/changes.xml Fri Feb  9 17:24:36 2007
@@ -86,6 +86,8 @@
 <li>Bug 41543 - exception when webserver returns "500 Internal Server Error" 
and content-length is 0</li>
 <li>Bug 41416 - don't use chunked input for text-box input in SOAP-RPC 
sampler</li>
 <li>Bug 39827 - SOAP Sampler content length for files</li>
+<li>Bug 40381 - LDAP: more descriptive strings</li>
+<li>Bug 40369 (partial) Equals Response Assertion</li>
 </ul>
 
 <h3>Version 2.2</h3>



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

Reply via email to