]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.security.core/ext/test/org/argeo/osgi/useradmin/LdifParserTest.java
Improve checks and fix unit tests.
[lgpl/argeo-commons.git] / org.argeo.security.core / ext / test / org / argeo / osgi / useradmin / LdifParserTest.java
index dd32dca171632641a5c15359e696dc7b028389d8..75a5c34b3442c4d39129b4c343349dcc2ead8ccc 100644 (file)
@@ -1,22 +1,25 @@
 package org.argeo.osgi.useradmin;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.SortedMap;
 
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.ldap.LdapName;
 
+import junit.framework.TestCase;
+
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.codec.digest.DigestUtils;
 
-import junit.framework.TestCase;
-
-public class LdifParserTest extends TestCase {
-       public void testSimpleLdif() throws Exception {
+public class LdifParserTest extends TestCase implements BasicTestConstants {
+       public void testBasicLdif() throws Exception {
                LdifParser ldifParser = new LdifParser();
                SortedMap<LdapName, Attributes> res = ldifParser.read(getClass()
-                               .getResourceAsStream("test.ldif"));
-               LdapName rootDn = new LdapName(
-                               "uid=root,ou=People,dc=demo,dc=example,dc=org");
+                               .getResourceAsStream("basic.ldif"));
+               LdapName rootDn = new LdapName(ROOT_USER_DN);
                Attributes rootAttributes = res.get(rootDn);
                assertNotNull(rootAttributes);
                assertEquals("Superuser", rootAttributes.get("description").get());
@@ -27,5 +30,19 @@ public class LdifParserTest extends TestCase {
                assertEquals("{SHA}" + Base64.encodeBase64String(hashedPassword),
                                new String(rawPwEntry));
 
+               LdapName adminDn = new LdapName(
+                               ADMIN_GROUP_DN);
+               Attributes adminAttributes = res.get(adminDn);
+               assertNotNull(adminAttributes);
+               Attribute memberAttribute = adminAttributes.get("member");
+               assertNotNull(memberAttribute);
+               NamingEnumeration<?> members = memberAttribute.getAll();
+               List<String> users = new ArrayList<String>();
+               while (members.hasMore()) {
+                       Object value = members.next();
+                       users.add(value.toString());
+               }
+               assertEquals(1, users.size());
+               assertEquals(rootDn, new LdapName(users.get(0)));
        }
 }