directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szoer...@apache.org
Subject svn commit: r330524 - in /directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi: ops/add/AllTests.java ops/add/BinaryDataAddTest.java util/AttributesFactory.java
Date Thu, 03 Nov 2005 10:30:58 GMT
Author: szoerner
Date: Thu Nov  3 02:30:52 2005
New Revision: 330524

URL: http://svn.apache.org/viewcvs?rev=330524&view=rev
Log:
Add test case for adding entries with binary data.
This is to demonstrate that DIREVE-163 does not occur any more.

Added:
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/BinaryDataAddTest.java
  (with props)
Modified:
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/AllTests.java
    directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/util/AttributesFactory.java

Modified: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/AllTests.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/AllTests.java?rev=330524&r1=330523&r2=330524&view=diff
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/AllTests.java
(original)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/AllTests.java
Thu Nov  3 02:30:52 2005
@@ -34,6 +34,7 @@
 
         suite.addTestSuite(BasicAddTests.class);
         suite.addTestSuite(SpecialCharacterAddTests.class);
+        suite.addTestSuite(BinaryDataAddTest.class);
 
         return suite;
     }

Added: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/BinaryDataAddTest.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/BinaryDataAddTest.java?rev=330524&view=auto
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/BinaryDataAddTest.java
(added)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/ops/add/BinaryDataAddTest.java
Thu Nov  3 02:30:52 2005
@@ -0,0 +1,113 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.ldap.testsuite.ldaptests.jndi.ops.add;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Random;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+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 binary data works.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BinaryDataAddTest extends BaseProtocolTest
+{
+
+    private static String PERSON_SN_VALUE = "Amos";
+
+    private static String PERSON_CN_VALUE = "Tori Amos";
+
+    private static String PERSON_RDN = "cn=" + PERSON_CN_VALUE;
+
+    DirContext ctx;
+
+    public void setUp() throws NamingException
+    {
+        super.setUp();
+
+        ctx = this.createContext();
+        ctx = (DirContext) ctx.lookup(this.getTestContainerRdn());
+    }
+
+    public void tearDown() throws NamingException
+    {
+        ctx.close();
+        ctx = null;
+
+        super.tearDown();
+    }
+
+    /**
+     * Add an inetOrgPerson entry with photo and check whether it can be
+     * retrieved back correctly.
+     */
+    public void testInetOrgPersonWithJpegPhoto() throws NamingException
+    {
+        Attributes attrs = AttributesFactory.createInetOrgPersonAttributes(PERSON_CN_VALUE,
PERSON_SN_VALUE);
+
+        // Random data for jpegPhoto, 64k
+        byte[] sourceData = new byte[64 * 1024];
+        Random r = new Random(0);
+        for (int i = 0; i < sourceData.length; i++) {
+            sourceData[i] = (byte) r.nextInt();
+        }
+        attrs.put("jpegPhoto", sourceData);
+
+        // Create entry
+        ctx.bind(PERSON_RDN, null, attrs);
+
+        // Read same entry and compare data bytewise
+        Attributes readAttrs = ctx.getAttributes(PERSON_RDN);
+        Attribute image = readAttrs.get("jpegPhoto");
+        byte[] imageBytes = (byte[]) image.get();
+        for (int i = 0; i < imageBytes.length; i++) {
+            assertEquals("Byte number " + i, sourceData[i], imageBytes[i]);
+        }
+    }
+
+    /**
+     * Add an person entry with userPassword and check whether the value can be
+     * retrieved back correctly.
+     */
+    public void testPersonWithPassword() throws NamingException, UnsupportedEncodingException
+    {
+        Attributes attrs = AttributesFactory.createPersonAttributes(PERSON_CN_VALUE, PERSON_SN_VALUE);
+
+        String password = "MySecret1!";
+        attrs.put("userPassword", password.getBytes("UTF-8"));
+
+        // Create entry
+        ctx.bind(PERSON_RDN, null, attrs);
+
+        // Read same entry and compare password value
+        Attributes readAttrs = ctx.getAttributes(PERSON_RDN);
+        Attribute pwd = readAttrs.get("userPassword");
+        byte[] bytes = (byte[]) pwd.get();
+        String toTest = new String(bytes, "UTF-8");
+        assertEquals(password, toTest);
+    }
+
+}
\ No newline at end of file

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

Modified: directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/util/AttributesFactory.java
URL: http://svn.apache.org/viewcvs/directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/util/AttributesFactory.java?rev=330524&r1=330523&r2=330524&view=diff
==============================================================================
--- directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/util/AttributesFactory.java
(original)
+++ directory/testsuite/trunk/ldaptests/src/main/java/org/apache/ldap/testsuite/ldaptests/jndi/util/AttributesFactory.java
Thu Nov  3 02:30:52 2005
@@ -57,6 +57,36 @@
     }
 
     /**
+     * Creates the required attributes for an inetOrgPerson as defined in RFC
+     * 2798 ("Definition of the inetOrgPerson LDAP Object Class"). The result
+     * contains an objectClass attribute with the appropriate values, and the
+     * attributes sn and cn, which are required from person.
+     * 
+     * @param cn
+     *            common name of person
+     * @param sn
+     *            surname of person
+     * 
+     * @return attributes object with the required attributes for an inetOrgPerson
+     */
+    public static final Attributes createInetOrgPersonAttributes(String cn, String sn)
+    {
+        Attributes person = new BasicAttributes();
+
+        Attribute ocls = new BasicAttribute("objectClass");
+        ocls.add("top");
+        ocls.add("person");
+        ocls.add("organizationalPerson");
+        ocls.add("inetOrgPerson");
+        person.put(ocls);
+
+        person.put("cn", cn);
+        person.put("sn", sn);
+
+        return person;
+    }
+
+    /**
      * Creates the required attributes for an organizational unit as defined in
      * RFC 2256. The result contains an objectClass attribute with values top
      * and organizationalUnit, and the mandatory attribute ou.



Mime
View raw message