# HG changeset patch # User Dirk Olmes # Date 1477408873 0 # Node ID 886a28c5898cf0b55ea505b8cac6ebcb14d05fb4 # Parent e1a9127a7d57b682398415287795576b09a133b6 add code to list the highest group number diff -r e1a9127a7d57 -r 886a28c5898c jndi/src/test/java/de/codedo/jndi/JndiTestCase.java --- a/jndi/src/test/java/de/codedo/jndi/JndiTestCase.java Tue Oct 25 14:56:08 2016 +0000 +++ b/jndi/src/test/java/de/codedo/jndi/JndiTestCase.java Tue Oct 25 15:21:13 2016 +0000 @@ -8,10 +8,11 @@ public class JndiTestCase extends Object { + private static final String GROUP_BASE = "ou=groups,dc=ldap,dc=example,dc=org"; private static final String USER_BASE = "ou=users,dc=ldap,dc=example,dc=org"; + @Ignore @Test - @Ignore public void connectToJndi() throws Exception { DirContext context = createContext(); @@ -39,6 +40,7 @@ context.close(); } + @Ignore @Test public void createInLdap() throws Exception { @@ -66,6 +68,36 @@ context.close(); } + @Test + public void findHighestGroupNumber() throws Exception + { + DirContext context = createContext(); + + int highest = 0; + + NamingEnumeration groupEnum = context.list(GROUP_BASE); + while (groupEnum.hasMore()) + { + NameClassPair pair = groupEnum.next(); + int groupNumber = getGroupNumber(context, pair.getName()); + highest = Math.max(highest, groupNumber); + } + + Assert.assertEquals(10002, highest); + } + + private int getGroupNumber(DirContext context, String groupCn) throws Exception + { + String dn = groupCn + "," + GROUP_BASE; + Attributes attributes = context.getAttributes(dn); + //System.out.println(attributes); + + Attribute gidNumber = attributes.get("gidNumber"); + //System.out.println(gidNumber); + String value = gidNumber.get().toString(); + return Integer.valueOf(value); + } + private DirContext createContext() throws Exception { Hashtable env = new Hashtable<>();