From e0d51e2e1a00bc9bb52cc2d653c647ca4a65fc97 Mon Sep 17 00:00:00 2001 From: Ulrik Sandberg Date: Mon, 3 Sep 2007 22:44:33 +0000 Subject: [PATCH] Improved the control testing code to use lookup with attributes. --- .../ldap/control/SupportedControlsITest.java | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/control/SupportedControlsITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/control/SupportedControlsITest.java index 54676ecf..2b50a90f 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/control/SupportedControlsITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/control/SupportedControlsITest.java @@ -22,11 +22,9 @@ import java.util.LinkedList; import javax.naming.NamingEnumeration; import javax.naming.NamingException; import javax.naming.directory.Attributes; -import javax.naming.directory.DirContext; import org.springframework.ldap.AbstractLdapTemplateIntegrationTest; import org.springframework.ldap.core.AttributesMapper; -import org.springframework.ldap.core.ContextExecutor; import org.springframework.ldap.core.LdapTemplate; /** @@ -35,45 +33,30 @@ import org.springframework.ldap.core.LdapTemplate; * @author Ulrik Sandberg */ public class SupportedControlsITest extends AbstractLdapTemplateIntegrationTest { + /** must use a context source that has no base set */ private LdapTemplate tested; - private static String SUPPORTED_CONTROL = "supportedcontrol"; + private static final String SUPPORTED_CONTROL = "supportedcontrol"; protected String[] getConfigLocations() { - return new String[] { "/conf/ldapTemplateTestContext.xml" }; + return new String[] { "/conf/rootContextSourceTestContext.xml" }; } public void testExpectedControlsSupported() throws Exception { - final String name = "ldap://localhost:3900"; /** * Maps the 'supportedcontrol' attribute to a string array. */ final AttributesMapper mapper = new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { - LinkedList list = new LinkedList(); NamingEnumeration enumeration = attributes.get( SUPPORTED_CONTROL).getAll(); - while (enumeration.hasMoreElements()) { - list.add((String) enumeration.nextElement()); - } - return list.toArray(new String[0]); - } - }; - /** - * Performs a 'getAttributes' operation and maps the result to a string - * array. - */ - ContextExecutor executor = new ContextExecutor() { - public Object executeWithContext(DirContext ctx) - throws NamingException { - Attributes attributes = ctx.getAttributes(name, - new String[] { SUPPORTED_CONTROL }); - return mapper.mapFromAttributes(attributes); + return toStringArray(enumeration); } }; - String[] controls = (String[]) tested.executeReadOnly(executor); + String[] controls = (String[]) tested.lookup("", + new String[] { SUPPORTED_CONTROL }, mapper); System.out.println(Arrays.toString(controls)); assertEquals("Persistent Search LDAPv3 control,", "2.16.840.1.113730.3.4.3", controls[0]); @@ -88,4 +71,12 @@ public class SupportedControlsITest extends AbstractLdapTemplateIntegrationTest public void setTested(LdapTemplate tested) { this.tested = tested; } + + private String[] toStringArray(NamingEnumeration enumeration) { + LinkedList list = new LinkedList(); + while (enumeration.hasMoreElements()) { + list.add((String) enumeration.nextElement()); + } + return (String[]) list.toArray(new String[0]); + } }