This patch adds a new text field to the User Defined Add and Modify LDAP tests. The 
intent is to allow the user to test for other result codes than zero, which indicates 
success. This allows creating and testing deliberate errors.

For example, a LDAP server will return error 50 if the specified user DN does not have 
adequate permissions to perform the add/modify operation. Under the current build, 
jMeter interprets this as a failed test. However, this does not allow for the tester 
to validate permissions.

Delete operations are more difficult due to the behavior of javax.naming. These were 
not modified in this patch submission as they did not work as expected. If a delete 
operation attempts to delete a non-existent DN, javax.naming does NOT throw the 
NameNotFoundException unless a mid-point branch wasn't found. So, all deletes will be 
marked as successful.

Search operations were not modified as I don't currently need to test for other result 
codes on search operations.

This patch also modifies LDAPSampler.java. Some of these modifications are part of a 
suggested patch I submitted in the incorrect format. There are two major modifications 
to LDAPSampler.java:

1. Adding support for alternate result codes, as described in my patch to
   LdapClient.java.

2. Allowing for multi-valued attribues in the user-defined LDAP Add test.
   An important note about this: the extended test only adds objectclass: top.
   This may cause problems to existing test cases that did not define object
   classes. However, this allows for greater flexibility in testing add
   operations.

Both of these have been tested in our lab environment.


Kayne McGladrey
Member - Technical Group
AT&T Wireless

--- jmeter_cvs/LdapConfigGui.java       2003-11-03 15:53:42.000000000 -0800
+++ 
jakarta-jmeter-1.9.1/src/protocol/ldap/org/apache/jmeter/protocol/ldap/config/gui/LdapConfigGui.java
        2003-11-04 10:41:32.000000000 -0800
@@ -81,9 +81,9 @@
 /**
  * This class LdapConfigGui is user interface gui for getting all the
  * configuration values from the user.
- *
+ *
  * @author    T.Elanjchezhiyan([EMAIL PROTECTED]) - Sip Technologies and
- *            Exports Ltd.
+ *            Exports Ltd.
  * Created     Apr 29 2003 11:45 AM
  * @version   $Revision: 1.5 $ Last updated: $Date: 2003/10/19 23:01:32 $
  */
@@ -98,6 +98,10 @@
     private JTextField modify = new JTextField(20);
     private JTextField servername = new JTextField(20);
     private JTextField port = new JTextField(20);
+
+    //added
+    private JTextField addresultcode = new JTextField(3);
+    private JTextField modifyresultcode = new JTextField(3);

     private JCheckBox user_Defined =
         new JCheckBox(JMeterUtils.getResString("user_defined_test"));
@@ -154,7 +158,8 @@
                 (TestElement) element
                     .getProperty(LDAPSampler.ARGUMENTS)
                     .getObjectValue());
-            cl.show(cards,"Add");
+            
addresultcode.setText(element.getPropertyAsString(LDAPSampler.RESULTCODE));
+           cl.show(cards,"Add");
         }
         else if (element.getPropertyAsString(LDAPSampler.TEST).equals("modify"))
         {
@@ -165,7 +170,8 @@
                 (TestElement) element
                     .getProperty(LDAPSampler.ARGUMENTS)
                     .getObjectValue());
-            cl.show(cards,"Modify");
+            
modifyresultcode.setText(element.getPropertyAsString(LDAPSampler.RESULTCODE));
+           cl.show(cards,"Modify");
         }
         else if (element.getPropertyAsString(LDAPSampler.TEST).equals("delete"))
         {
@@ -228,6 +234,10 @@
                 new TestElementProperty(
                     LDAPSampler.ARGUMENTS,
                     tableAddPanel.createTestElement()));
+            //added
+            element.setProperty(
+                   new StringProperty(LDAPSampler.RESULTCODE,
+                   addresultcode.getText()));
         }

         if (modifyTest.isSelected())
@@ -242,6 +252,10 @@
                 new TestElementProperty(
                     LDAPSampler.ARGUMENTS,
                     tableModifyPanel.createTestElement()));
+            //added
+           element.setProperty(
+               new StringProperty(LDAPSampler.RESULTCODE,
+               modifyresultcode.getText()));
         }

         if (deleteTest.isSelected())
@@ -417,12 +431,20 @@
     {
         JPanel addPanel = new JPanel(new BorderLayout(5,0));
         JPanel addInnerPanel  = new JPanel(new BorderLayout(5, 0));
-        JLabel label = new JLabel(JMeterUtils.getResString("entry_dn"));
+        //added
+       JPanel addResultPanel = new JPanel(new BorderLayout(5,0));
+       JLabel label = new JLabel(JMeterUtils.getResString("entry_dn"));
         label.setLabelFor(add);
-        addInnerPanel.add(label, BorderLayout.WEST);
+        JLabel label2 = new JLabel("Expected Result Code");
+       addInnerPanel.add(label, BorderLayout.WEST);
         addInnerPanel.add(add, BorderLayout.CENTER);
-        addPanel.add(addInnerPanel,BorderLayout.NORTH);
+        //added
+       addResultPanel.add(label2, BorderLayout.WEST);
+       addResultPanel.add(addresultcode, BorderLayout.CENTER);
+       addPanel.add(addInnerPanel,BorderLayout.NORTH);
         addPanel.add(tableAddPanel,BorderLayout.CENTER);
+       //added
+       addPanel.add(addResultPanel, BorderLayout.SOUTH);
         return addPanel;
     }

@@ -433,12 +455,21 @@
     {
         JPanel modifyPanel = new JPanel(new BorderLayout(5,0));
         JPanel modifyInnerPanel  = new JPanel(new BorderLayout(5, 0));
+       //added
+       JPanel modifyResultPanel = new JPanel(new BorderLayout(5,0));
         JLabel label = new JLabel(JMeterUtils.getResString("entry_dn"));
         label.setLabelFor(modify);
+       //added
+       JLabel label2 = new JLabel("Expected Result Code");
         modifyInnerPanel.add(label, BorderLayout.WEST);
         modifyInnerPanel.add(modify, BorderLayout.CENTER);
+       //added
+       modifyResultPanel.add(label2, BorderLayout.WEST);
+       modifyResultPanel.add(modifyresultcode, BorderLayout.CENTER);
         modifyPanel.add(modifyInnerPanel,BorderLayout.NORTH);
         modifyPanel.add(tableModifyPanel,BorderLayout.CENTER);
+       //added
+       modifyPanel.add(modifyResultPanel, BorderLayout.SOUTH);
         return modifyPanel;
     }


--- jmeter_cvs/LDAPSampler.java 2003-11-03 15:54:23.000000000 -0800
+++ 
jakarta-jmeter-1.9.1/src/protocol/ldap/org/apache/jmeter/protocol/ldap/sampler/LDAPSampler.java
     2003-11-04 10:32:13.000000000 -0800
@@ -105,6 +105,9 @@
     public final static String ARGUMENTS = "arguments";
     public final static String BASE_ENTRY_DN = "base_entry_dn";

+    //added
+    public final static String RESULTCODE = "0";
+
     //For In build test case using this counter
     //create the new entry in the server
     public static int counter=0;
@@ -295,22 +298,39 @@
      */
     public BasicAttributes getUserAttributes()
     {
-        BasicAttribute basicattribute = new BasicAttribute("objectclass");
-        basicattribute.add("top");
-        basicattribute.add("person");
-        basicattribute.add("organizationalPerson");
-        basicattribute.add("inetOrgPerson");
         BasicAttributes attrs = new BasicAttributes(true);
-        attrs.put(basicattribute);
-        BasicAttribute attr;
         PropertyIterator iter = getArguments().iterator();
-
-        while (iter.hasNext())
-        {
+
+        String lastSeen = "objectclass";
+       BasicAttribute attr = new BasicAttribute("objectclass");
+       attr.add("top");
+       attrs.put(attr);
+       while (iter.hasNext()) {
             Argument item = (Argument) iter.next().getObjectValue();
-            attr = getBasicAttribute( item.getName(),item.getValue());
-            attrs.put(attr);
+           String current = item.getName();
+           if ( lastSeen.equalsIgnoreCase(current) ) {
+                attr.add( item.getValue() );
+            } else {
+               //check if it's already been added to the attrs
+               Attribute oldAttr = attrs.get(current);
+               if (oldAttr == null) {
+                       //this one is completely new, so add it to attrs
+                       attrs.put(attr);
+                       //make a note of it
+                       lastSeen = current;
+                       //get the next one
+                       attr = getBasicAttribute( item.getName(),item.getValue());
+               } else {
+                       oldAttr.add( item.getValue() );
+                       //overwrite existing value
+                       attrs.remove(current);
+                       attrs.put(oldAttr);
+                       lastSeen = current;
+               }
+            }
         }
+       //put the last one
+       attrs.put(attr);
         return attrs;
     }

@@ -569,23 +589,51 @@
                 time = searchTest(ldap);
             }

-            res.setResponseData("success full".getBytes());
-            isSuccessful = true;
-            ldap.disconnect();
-        }
-        catch (Exception ex)
-        {
-            res.setResponseData(ex.toString().getBytes());
-            log.error("Ldap client - ",ex);
-            ldap.disconnect();
-            isSuccessful = false;
-            time = 0L;
+       if (getPropertyAsString(RESULTCODE).equals("0") || 
getPropertyAsString(RESULTCODE).equals("")) {
+               res.setResponseData("success full".getBytes());
+               isSuccessful = true;
+               ldap.disconnect();
+
+       } else {
+               //it should have failed, actually
+               res.setResponseData("failed".getBytes());
+               ldap.disconnect();
+               isSuccessful = false;
+               time = 0L;
+               }
+        }
+        catch (Exception ex) {
+               //added
+               if (! getPropertyAsString(RESULTCODE).equals("0") ) {
+                       String errormessage = ex.toString();
+                       String expected = "error code ";
+                       expected = 
expected.concat(getPropertyAsString(RESULTCODE).toString());
+                       String splitval[] = ex.toString().split(":", 3);
+                       String errmsg = splitval[2].toString().substring(1, 14);
+                       if (errmsg.equalsIgnoreCase(expected)) {
+                                       res.setResponseData("success full".getBytes());
+                                       isSuccessful = true;
+                                       ldap.disconnect();
+                       } else {
+                               //still failed.
+                                       res.setResponseData(ex.toString().getBytes());
+                                       log.error("Ldap client - ",ex);
+                                       ldap.disconnect();
+                                       isSuccessful = false;
+                                       time = 0L;
+                       }
+               } else {
+                   res.setResponseData(ex.toString().getBytes());
+                   log.error("Ldap client - ",ex);
+                   ldap.disconnect();
+                   isSuccessful = false;
+                   time = 0L;
+               }
         }
-
         // Calculate response time
         res.setTime(time);
         // Set if we were successful or not
         res.setSuccessful(isSuccessful);
         return res;
     }
-}
\ No newline at end of file
+}

Reply via email to