changeset 22:886a28c5898c

add code to list the highest group number
author Dirk Olmes <dirk.olmes@codedo.de>
date Tue, 25 Oct 2016 15:21:13 +0000
parents e1a9127a7d57
children 99472565ba0b
files jndi/src/test/java/de/codedo/jndi/JndiTestCase.java
diffstat 1 files changed, 33 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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<NameClassPair> 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<String, Object> env = new Hashtable<>();