directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szoer...@apache.org
Subject svn commit: r307345 - in /directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add: BasicAddTests.java SpecialCharacterAddTests.java
Date Sun, 09 Oct 2005 02:41:29 GMT
Author: szoerner
Date: Sat Oct  8 19:41:23 2005
New Revision: 307345

URL: http://svn.apache.org/viewcvs?rev=307345&view=rev
Log:
Several changes
* new tool class for attribute creation of person entry used
* setUp and tearDown added
* documentation added

Modified:
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/BasicAddTests.java
  (contents, props changed)
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/SpecialCharacterAddTests.java
  (contents, props changed)

Modified: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/BasicAddTests.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/BasicAddTests.java?rev=307345&r1=307344&r2=307345&view=diff
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/BasicAddTests.java
(original)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/BasicAddTests.java
Sat Oct  8 19:41:23 2005
@@ -21,37 +21,42 @@
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttribute;
-import javax.naming.directory.BasicAttributes;
 import javax.naming.directory.DirContext;
 
+import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
+import org.apache.ldap.testsuite.ldaptests.jndi.util.AttributesFactory;
+
 /**
+ * Basic tests for the LDAP add operation.
+ * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev: $
+ * @version $Rev$
  */
-public class BasicAddTests extends org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest
+public class BasicAddTests extends BaseProtocolTest
 {
 
     private static String PERSON_SN_VALUE = "Amos";
 
     private static String PERSON_CN_VALUE = "Tori Amos";
 
-    private static String PERSON_CN_ALTERNATE = "Myra Ellen Amos";
-
     private static String PERSON_RDN = "cn=" + PERSON_CN_VALUE;
+    
+    DirContext ctx;
 
-    private Attributes createPersonAttributes(String cn, String sn)
+    public void setUp() throws NamingException
     {
-        Attributes person = new BasicAttributes();
+        super.setUp();
 
-        Attribute ocls = new BasicAttribute("objectClass");
-        ocls.add("top");
-        ocls.add("person");
-        person.put(ocls);
+        ctx = this.createContext();
+        ctx = (DirContext) ctx.lookup(this.getTestContainerRdn());
+    }
 
-        person.put("cn", cn);
-        person.put("sn", sn);
+    public void tearDown() throws NamingException
+    {
+        ctx.close();
+        ctx = null;
 
-        return person;
+        super.tearDown();
     }
 
     /**
@@ -61,20 +66,17 @@
      */
     public void testAddEntry() throws NamingException
     {
-
-        DirContext ctx = this.createContext();
-        DirContext target = (DirContext) ctx.lookup(this.getTestContainerRdn());
-
         // Add a person
-        Attributes attributes = createPersonAttributes(PERSON_CN_VALUE, PERSON_SN_VALUE);
-        DirContext person = target.createSubcontext(PERSON_RDN, attributes);
+        Attributes attributes = AttributesFactory.createPersonAttributes(PERSON_CN_VALUE,
PERSON_SN_VALUE);
+        DirContext person = ctx.createSubcontext(PERSON_RDN, attributes);
 
         // Check wether person looks fine
-        person = (DirContext) target.lookup(PERSON_RDN);
+        person = (DirContext) ctx.lookup(PERSON_RDN);
         assertNotNull(person);
         attributes = person.getAttributes("");
 
         // objectclasses
+        // TODO: Move this useful algorithm to a tool class
         Attribute ocls = attributes.get("objectClass");
         String[] expectedOcls = { "top", "person" };
         for (int i = 0; i < expectedOcls.length; i++) {
@@ -85,64 +87,58 @@
                     found = true;
                 }
             }
-            assertTrue("object class " + name + " is present", found);
+            assertTrue("object class " + name + " is not present", found);
         }
 
         // Other attributes
         Attribute cn = attributes.get("cn");
-        assertTrue(cn.contains(PERSON_CN_VALUE));
+        assertTrue("cn value", cn.contains(PERSON_CN_VALUE));
         Attribute sn = attributes.get("sn");
-        assertTrue(sn.contains(PERSON_SN_VALUE));
-
-        ctx.close();
+        assertTrue("sn value", sn.contains(PERSON_SN_VALUE));
     }
 
     /**
-     * Checks whether a duplicate entry causes a NameAlreadyBoundException.
+     * Checks whether adding an entry with existing DN causes an error.
      * 
      * @throws NamingException
      */
     public void testAddDuplicateEntry() throws NamingException
     {
-
-        DirContext ctx = this.createContext();
-        DirContext target = (DirContext) ctx.lookup(this.getTestContainerRdn());
-
-        Attributes attributes = createPersonAttributes(PERSON_CN_VALUE, PERSON_SN_VALUE);
-        target.createSubcontext(PERSON_RDN, attributes);
+        Attributes attributes = AttributesFactory.createPersonAttributes(PERSON_CN_VALUE,
PERSON_SN_VALUE);
+        ctx.createSubcontext(PERSON_RDN, attributes);
 
         try {
-            target.createSubcontext(PERSON_RDN, attributes);
+            ctx.createSubcontext(PERSON_RDN, attributes);
             fail("duplicate entry should fail");
         } catch (NameAlreadyBoundException e) {
             // Excepted behaviour;
             assertTrue(true);
         }
-        ctx.close();
     }
 
+    /**
+     * Checks whether adding an entry with multi valued attribute succeeds.
+     * 
+     * @throws NamingException
+     */
     public void testAddEntryWithMultipleValues() throws NamingException
     {
-
-        DirContext ctx = this.createContext();
-        DirContext target = (DirContext) ctx.lookup(this.getTestContainerRdn());
-
         // Create a person, description has multiple attributes
-        Attributes attributes = createPersonAttributes(PERSON_CN_VALUE, PERSON_SN_VALUE);
+        Attributes attributes = AttributesFactory.createPersonAttributes(PERSON_CN_VALUE,
PERSON_SN_VALUE);
         Attribute descr = new BasicAttribute("description");
         descr.add("a description for the person");
         descr.add("another description for this person");
         attributes.put(descr);
         int two = descr.size();
 
-        target.createSubcontext(PERSON_RDN, attributes);
+        ctx.createSubcontext(PERSON_RDN, attributes);
 
-        DirContext tori = (DirContext) target.lookup(PERSON_RDN);
+        DirContext tori = (DirContext) ctx.lookup(PERSON_RDN);
         attributes = tori.getAttributes("");
         descr = attributes.get("description");
 
         assertEquals(two, descr.size());
-
-        ctx.close();
     }
+    
+    // TODO: Add test for binary data (here, or in an own test case 
 }

Propchange: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/BasicAddTests.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/SpecialCharacterAddTests.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/SpecialCharacterAddTests.java?rev=307345&r1=307344&r2=307345&view=diff
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/SpecialCharacterAddTests.java
(original)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/SpecialCharacterAddTests.java
Sat Oct  8 19:41:23 2005
@@ -19,15 +19,16 @@
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttribute;
-import javax.naming.directory.BasicAttributes;
 import javax.naming.directory.DirContext;
 
 import org.apache.ldap.testsuite.ldaptests.jndi.BaseProtocolTest;
+import org.apache.ldap.testsuite.ldaptests.jndi.util.AttributesFactory;
 
 /**
+ * Check whether adding entries with special characters (e.g. German umlauts) works.
+ * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev: $
+ * @version $Rev$
  */
 public class SpecialCharacterAddTests extends BaseProtocolTest
 {
@@ -50,21 +51,6 @@
         super.tearDown();
     }
 
-    private Attributes createPersonAttributes(String cn, String sn)
-    {
-        Attributes person = new BasicAttributes();
-
-        Attribute ocls = new BasicAttribute("objectClass");
-        ocls.add("top");
-        ocls.add("person");
-        person.put(ocls);
-
-        person.put("cn", cn);
-        person.put("sn", sn);
-
-        return person;
-    }
-
     public void testAddEntryWithGermanUmlauts() throws NamingException
     {
 
@@ -73,7 +59,7 @@
         String snValue = "Zörner";
         String rdn = "cn=" + cnValue;
         String allUmlauts = "äöüÄÖÜß";
-        Attributes attributes = createPersonAttributes(cnValue, snValue);
+        Attributes attributes = AttributesFactory.createPersonAttributes(cnValue, snValue);
         attributes.put("description", allUmlauts);
 
         // add entry
@@ -97,7 +83,6 @@
         assertNotNull(description);
         assertEquals("number of description values", 1, description.size());
         assertTrue(description.contains(allUmlauts));
-
     }
 
     /**
@@ -118,18 +103,15 @@
                 new byte[] { 0x4A, (byte) 0xC3, (byte) 0xA9, 0x72, (byte) 0xC3, (byte) 0xB4,
0x6D, 0x65 });
         String sn = "baumgarten";
 
-        DirContext ctx = this.createContext();
-        DirContext target = (DirContext) ctx.lookup(getTestContainerRdn());
-
         // Add a person
-        Attributes attributes = createPersonAttributes(cn, sn);
+        Attributes attributes = AttributesFactory.createPersonAttributes(cn, sn);
 
         String rdn = "cn=" + cn;
 
-        DirContext person = target.createSubcontext(rdn, attributes);
+        DirContext person = ctx.createSubcontext(rdn, attributes);
 
         // Check whether person looks fine
-        person = (DirContext) target.lookup(rdn);
+        person = (DirContext) ctx.lookup(rdn);
         assertNotNull(person);
         attributes = person.getAttributes("");
 
@@ -147,7 +129,5 @@
         assertTrue(cnRes.contains(cn));
         Attribute snRes = attributes.get("sn");
         assertTrue(snRes.contains(sn));
-
-        ctx.close();
     }
 }

Propchange: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/SpecialCharacterAddTests.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision



Mime
View raw message