diff --git a/core/src/main/java/org/springframework/ldap/control/PagedResultsRequestControl.java b/core/src/main/java/org/springframework/ldap/control/PagedResultsRequestControl.java index f5bd6a28..bc3786ac 100644 --- a/core/src/main/java/org/springframework/ldap/control/PagedResultsRequestControl.java +++ b/core/src/main/java/org/springframework/ldap/control/PagedResultsRequestControl.java @@ -29,176 +29,187 @@ import java.lang.reflect.Method; /** * DirContextProcessor implementation for managing the paged results control. - * + * * @author Mattias Hellborg Arthursson * @author Ulrik Sandberg */ -public class PagedResultsRequestControl extends - AbstractRequestControlDirContextProcessor { +public class PagedResultsRequestControl extends AbstractRequestControlDirContextProcessor { - private static final boolean CRITICAL_CONTROL = true; + private static final boolean CRITICAL_CONTROL = true; - private static final String DEFAULT_REQUEST_CONTROL = "javax.naming.ldap.PagedResultsControl"; - private static final String LDAPBP_REQUEST_CONTROL = "com.sun.jndi.ldap.ctl.PagedResultsControl"; - private static final String DEFAULT_RESPONSE_CONTROL = "javax.naming.ldap.PagedResultsResponseControl"; - private static final String LDAPBP_RESPONSE_CONTROL = "com.sun.jndi.ldap.ctl.PagedResultsResponseControl"; + private static final String DEFAULT_REQUEST_CONTROL = "javax.naming.ldap.PagedResultsControl"; - private int pageSize; + private static final String LDAPBP_REQUEST_CONTROL = "com.sun.jndi.ldap.ctl.PagedResultsControl"; - private PagedResultsCookie cookie; + private static final String DEFAULT_RESPONSE_CONTROL = "javax.naming.ldap.PagedResultsResponseControl"; - private int resultSize; + private static final String LDAPBP_RESPONSE_CONTROL = "com.sun.jndi.ldap.ctl.PagedResultsResponseControl"; - private boolean critical = CRITICAL_CONTROL; + private int pageSize; - private Class responseControlClass; - private Class requestControlClass; + private PagedResultsCookie cookie; - /** - * Constructs a new instance. This constructor should be used when - * performing the first paged search operation, when no other results have - * been retrieved. - * - * @param pageSize the page size. - */ - public PagedResultsRequestControl(int pageSize) { - this(pageSize, null); - } + private int resultSize; - /** - * Constructs a new instance with the supplied page size and cookie. The - * cookie must be the exact same instance as received from a previous paged - * resullts search, or null if it is the first in an - * operation sequence. - * - * @param pageSize the page size. - * @param cookie the cookie, as received from a previous search. - */ - public PagedResultsRequestControl(int pageSize, PagedResultsCookie cookie) { - this.pageSize = pageSize; - this.cookie = cookie; + private boolean critical = CRITICAL_CONTROL; - loadControlClasses(); - } + private Class responseControlClass; - private void loadControlClasses() { - try { - requestControlClass = Class.forName(DEFAULT_REQUEST_CONTROL); - responseControlClass = Class.forName(DEFAULT_RESPONSE_CONTROL); - } catch (ClassNotFoundException e) { - log.debug("Default control classes not found - falling back to LdapBP classes", e); + private Class requestControlClass; - try { - requestControlClass = Class.forName(LDAPBP_REQUEST_CONTROL); - responseControlClass = Class.forName(LDAPBP_RESPONSE_CONTROL); - } catch (ClassNotFoundException e1) { - throw new UncategorizedLdapException("Neither default nor fallback classes are available - unable to proceed", e); - } + /** + * Constructs a new instance. This constructor should be used when + * performing the first paged search operation, when no other results have + * been retrieved. + * + * @param pageSize the page size. + */ + public PagedResultsRequestControl(int pageSize) { + this(pageSize, null); + } - } - } + /** + * Constructs a new instance with the supplied page size and cookie. The + * cookie must be the exact same instance as received from a previous paged + * resullts search, or null if it is the first in an operation + * sequence. + * + * @param pageSize the page size. + * @param cookie the cookie, as received from a previous search. + */ + public PagedResultsRequestControl(int pageSize, PagedResultsCookie cookie) { + this.pageSize = pageSize; + this.cookie = cookie; - /** - * Get the cookie. - * - * @return the cookie. - */ - public PagedResultsCookie getCookie() { - return cookie; - } + loadControlClasses(); + } - /** - * Get the page size. - * - * @return the page size. - */ - public int getPageSize() { - return pageSize; - } + private void loadControlClasses() { + try { + requestControlClass = Class.forName(DEFAULT_REQUEST_CONTROL); + responseControlClass = Class.forName(DEFAULT_RESPONSE_CONTROL); + } + catch (ClassNotFoundException e) { + log.debug("Default control classes not found - falling back to LdapBP classes", e); - /** - * Get the total estimated number of entries that matches the issued search. - * Note that this value is optional for the LDAP server to return, so it - * does not always contain any valid data. - * - * @return the estimated result size, if returned from the server. - */ - public int getResultSize() { - return resultSize; - } + try { + requestControlClass = Class.forName(LDAPBP_REQUEST_CONTROL); + responseControlClass = Class.forName(LDAPBP_RESPONSE_CONTROL); + } + catch (ClassNotFoundException e1) { + throw new UncategorizedLdapException( + "Neither default nor fallback classes are available - unable to proceed", e); + } - /** - * Set the class of the expected ResponseControl for the paged results - * response. - * - * @param responseControlClass Class of the expected response control. - */ - public void setResponseControlClass(Class responseControlClass) { - this.responseControlClass = responseControlClass; - } + } + } - public void setRequestControlClass(Class requestControlClass) { - this.requestControlClass = requestControlClass; - } + /** + * Get the cookie. + * + * @return the cookie. + */ + public PagedResultsCookie getCookie() { + return cookie; + } - /* - * @see org.springframework.ldap.control.AbstractRequestControlDirContextProcessor#createRequestControl() - */ + /** + * Get the page size. + * + * @return the page size. + */ + public int getPageSize() { + return pageSize; + } - public Control createRequestControl() { - byte[] actualCookie = null; - if (cookie != null) { - actualCookie = cookie.getCookie(); - } - Constructor constructor = ClassUtils.getConstructorIfAvailable(requestControlClass, new Class[]{int.class, byte[].class, boolean.class}); - if (constructor == null) { - throw new IllegalArgumentException("Failed to find an appropriate RequestControl constructor"); - } + /** + * Get the total estimated number of entries that matches the issued search. + * Note that this value is optional for the LDAP server to return, so it + * does not always contain any valid data. + * + * @return the estimated result size, if returned from the server. + */ + public int getResultSize() { + return resultSize; + } - Control result = null; - try { - result = (Control) constructor.newInstance(new Object[]{new Integer(pageSize), actualCookie, new Boolean(critical)}); - } catch (Exception e) { - ReflectionUtils.handleReflectionException(e); - } + /** + * Set the class of the expected ResponseControl for the paged results + * response. + * + * @param responseControlClass Class of the expected response control. + */ + public void setResponseControlClass(Class responseControlClass) { + this.responseControlClass = responseControlClass; + } - return result; - } + public void setRequestControlClass(Class requestControlClass) { + this.requestControlClass = requestControlClass; + } - /* - * @see org.springframework.ldap.core.DirContextProcessor#postProcess(javax.naming.directory.DirContext) - */ + /* + * @see + * org.springframework.ldap.control.AbstractRequestControlDirContextProcessor + * #createRequestControl() + */ - public void postProcess(DirContext ctx) throws NamingException { + public Control createRequestControl() { + byte[] actualCookie = null; + if (cookie != null) { + actualCookie = cookie.getCookie(); + } + Constructor constructor = ClassUtils.getConstructorIfAvailable(requestControlClass, new Class[] { int.class, + byte[].class, boolean.class }); + if (constructor == null) { + throw new IllegalArgumentException("Failed to find an appropriate RequestControl constructor"); + } - LdapContext ldapContext = (LdapContext) ctx; - Control[] responseControls = ldapContext.getResponseControls(); - if (responseControls == null) { - responseControls = new Control[0]; - } + Control result = null; + try { + result = (Control) constructor.newInstance(new Object[] { new Integer(pageSize), actualCookie, + Boolean.valueOf(critical) }); + } + catch (Exception e) { + ReflectionUtils.handleReflectionException(e); + } - // Go through response controls and get info, regardless of class - for (int i = 0; i < responseControls.length; i++) { - Control responseControl = responseControls[i]; + return result; + } - // check for match, try fallback otherwise - if (responseControl.getClass().isAssignableFrom(responseControlClass)) { - Object control = responseControl; - byte[] result = (byte[]) invokeMethod("getCookie", - responseControlClass, control); - this.cookie = new PagedResultsCookie(result); - Integer wrapper = (Integer) invokeMethod("getResultSize", - responseControlClass, control); - this.resultSize = wrapper.intValue(); - return; - } - } + /* + * @see + * org.springframework.ldap.core.DirContextProcessor#postProcess(javax.naming + * .directory.DirContext) + */ - log.fatal("No matching response control found for paged results - looking for '" + responseControlClass); - } + public void postProcess(DirContext ctx) throws NamingException { - private Object invokeMethod(String method, Class clazz, Object control) { - Method actualMethod = ReflectionUtils.findMethod(clazz, method); - return ReflectionUtils.invokeMethod(actualMethod, control); - } + LdapContext ldapContext = (LdapContext) ctx; + Control[] responseControls = ldapContext.getResponseControls(); + if (responseControls == null) { + responseControls = new Control[0]; + } + + // Go through response controls and get info, regardless of class + for (int i = 0; i < responseControls.length; i++) { + Control responseControl = responseControls[i]; + + // check for match, try fallback otherwise + if (responseControl.getClass().isAssignableFrom(responseControlClass)) { + Object control = responseControl; + byte[] result = (byte[]) invokeMethod("getCookie", responseControlClass, control); + this.cookie = new PagedResultsCookie(result); + Integer wrapper = (Integer) invokeMethod("getResultSize", responseControlClass, control); + this.resultSize = wrapper.intValue(); + return; + } + } + + log.fatal("No matching response control found for paged results - looking for '" + responseControlClass); + } + + private Object invokeMethod(String method, Class clazz, Object control) { + Method actualMethod = ReflectionUtils.findMethod(clazz, method); + return ReflectionUtils.invokeMethod(actualMethod, control); + } } diff --git a/core/src/main/java/org/springframework/ldap/core/AttributesMapperCallbackHandler.java b/core/src/main/java/org/springframework/ldap/core/AttributesMapperCallbackHandler.java index 17bd94e5..47b7db46 100644 --- a/core/src/main/java/org/springframework/ldap/core/AttributesMapperCallbackHandler.java +++ b/core/src/main/java/org/springframework/ldap/core/AttributesMapperCallbackHandler.java @@ -32,35 +32,37 @@ import org.springframework.ldap.support.LdapUtils; * @author Ulrik Sandberg * @since 1.2 */ -public class AttributesMapperCallbackHandler extends - CollectingNameClassPairCallbackHandler { - private AttributesMapper mapper; +public class AttributesMapperCallbackHandler extends CollectingNameClassPairCallbackHandler { + private AttributesMapper mapper; - /** - * Constructs a new instance around the specified {@link AttributesMapper}. - * - * @param mapper - * the target mapper. - */ - public AttributesMapperCallbackHandler(AttributesMapper mapper) { - this.mapper = mapper; - } + /** + * Constructs a new instance around the specified {@link AttributesMapper}. + * + * @param mapper the target mapper. + */ + public AttributesMapperCallbackHandler(AttributesMapper mapper) { + this.mapper = mapper; + } - /** - * Cast the NameClassPair to a SearchResult and pass its attributes to the - * {@link AttributesMapper}. - * - * @param nameClassPair - * a SearchResult instance. - * @return the Object returned from the mapper. - */ - public Object getObjectFromNameClassPair(NameClassPair nameClassPair) { - SearchResult searchResult = (SearchResult) nameClassPair; - Attributes attributes = searchResult.getAttributes(); - try { - return mapper.mapFromAttributes(attributes); - } catch (javax.naming.NamingException e) { - throw LdapUtils.convertLdapException(e); - } - } + /** + * Cast the NameClassPair to a SearchResult and pass its attributes to the + * {@link AttributesMapper}. + * + * @param nameClassPair a SearchResult instance. + * @return the Object returned from the mapper. + */ + public Object getObjectFromNameClassPair(NameClassPair nameClassPair) { + if (!(nameClassPair instanceof SearchResult)) { + throw new IllegalArgumentException("Parameter must be an instance of SearchResult"); + } + + SearchResult searchResult = (SearchResult) nameClassPair; + Attributes attributes = searchResult.getAttributes(); + try { + return mapper.mapFromAttributes(attributes); + } + catch (javax.naming.NamingException e) { + throw LdapUtils.convertLdapException(e); + } + } } \ No newline at end of file diff --git a/core/src/main/java/org/springframework/ldap/core/ContextMapperCallbackHandler.java b/core/src/main/java/org/springframework/ldap/core/ContextMapperCallbackHandler.java index 4758543f..507303d7 100644 --- a/core/src/main/java/org/springframework/ldap/core/ContextMapperCallbackHandler.java +++ b/core/src/main/java/org/springframework/ldap/core/ContextMapperCallbackHandler.java @@ -54,7 +54,11 @@ public class ContextMapperCallbackHandler extends * @return the Object returned from the mapper. */ public Object getObjectFromNameClassPair(NameClassPair nameClassPair) { - Binding binding = (Binding) nameClassPair; + if (!(nameClassPair instanceof Binding)) { + throw new IllegalArgumentException("Parameter must be an instance of Binding"); + } + + Binding binding = (Binding) nameClassPair; Object object = binding.getObject(); if (object == null) { throw new ObjectRetrievalException( diff --git a/core/src/main/java/org/springframework/ldap/core/DistinguishedName.java b/core/src/main/java/org/springframework/ldap/core/DistinguishedName.java index cd339718..f7922355 100644 --- a/core/src/main/java/org/springframework/ldap/core/DistinguishedName.java +++ b/core/src/main/java/org/springframework/ldap/core/DistinguishedName.java @@ -29,6 +29,8 @@ import javax.naming.Name; import javax.naming.ldap.Rdn; import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.ldap.BadLdapGrammarException; import org.springframework.ldap.support.ListComparator; @@ -88,6 +90,8 @@ public class DistinguishedName implements Name { */ public static final String SPACED_DN_FORMAT_PROPERTY = "org.springframework.ldap.core.spacedDnFormat"; + private static final Log log = LogFactory.getLog(DistinguishedName.class); + private static final boolean COMPACT = true; private static final boolean NON_COMPACT = false; @@ -462,11 +466,15 @@ public class DistinguishedName implements Name { * @see java.lang.Object#clone() */ public Object clone() { - - // just duplicate the list, the rdns are immutable. - LinkedList list = new LinkedList(getNames()); - - return new DistinguishedName(list); + try { + DistinguishedName result = (DistinguishedName) super.clone(); + result.names = new LinkedList(names); + return result; + } + catch (CloneNotSupportedException e) { + log.fatal("CloneNotSupported thrown from superclass - this should not happen"); + throw new RuntimeException("Fatal error in clone", e); + } } /** diff --git a/core/src/main/java/org/springframework/ldap/core/LdapTemplate.java b/core/src/main/java/org/springframework/ldap/core/LdapTemplate.java index 279b08ca..6a206e77 100644 --- a/core/src/main/java/org/springframework/ldap/core/LdapTemplate.java +++ b/core/src/main/java/org/springframework/ldap/core/LdapTemplate.java @@ -1255,7 +1255,7 @@ public class LdapTemplate implements LdapOperations, InitializingBean { } } - private final class NullDirContextProcessor implements DirContextProcessor { + private final static class NullDirContextProcessor implements DirContextProcessor { public void postProcess(DirContext ctx) throws NamingException { // Do nothing } @@ -1271,7 +1271,8 @@ public class LdapTemplate implements LdapOperations, InitializingBean { * * @author Mattias Hellborg Arthursson */ - public class MappingCollectingNameClassPairCallbackHandler extends CollectingNameClassPairCallbackHandler { + public final static class MappingCollectingNameClassPairCallbackHandler extends + CollectingNameClassPairCallbackHandler { private NameClassPairMapper mapper; diff --git a/core/src/main/java/org/springframework/ldap/core/support/AbstractContextSource.java b/core/src/main/java/org/springframework/ldap/core/support/AbstractContextSource.java index e15250e1..a1b38de0 100644 --- a/core/src/main/java/org/springframework/ldap/core/support/AbstractContextSource.java +++ b/core/src/main/java/org/springframework/ldap/core/support/AbstractContextSource.java @@ -393,7 +393,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource * @param urls the urls of all servers. */ public void setUrls(String[] urls) { - this.urls = urls; + this.urls = (String[]) urls.clone(); } /** @@ -402,7 +402,7 @@ public abstract class AbstractContextSource implements BaseLdapPathContextSource * @return the urls of all servers. */ public String[] getUrls() { - return urls; + return (String[]) urls.clone(); } /** diff --git a/core/src/main/java/org/springframework/ldap/support/ListComparator.java b/core/src/main/java/org/springframework/ldap/support/ListComparator.java index 9114e09d..43eef2ad 100644 --- a/core/src/main/java/org/springframework/ldap/support/ListComparator.java +++ b/core/src/main/java/org/springframework/ldap/support/ListComparator.java @@ -15,6 +15,7 @@ */ package org.springframework.ldap.support; +import java.io.Serializable; import java.util.Comparator; import java.util.List; @@ -23,7 +24,8 @@ import java.util.List; * * @author Mattias Hellborg Arthursson */ -public class ListComparator implements Comparator { +public class ListComparator implements Comparator, Serializable { + private static final long serialVersionUID = -3068381879731157178L; /** * Compare two lists of Comparable objects. diff --git a/core/src/main/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationExecutor.java b/core/src/main/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationExecutor.java index 600f0581..24a38dd9 100644 --- a/core/src/main/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationExecutor.java +++ b/core/src/main/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationExecutor.java @@ -65,8 +65,8 @@ public class ModifyAttributesOperationExecutor implements ModificationItem[] compensatingModifications) { this.ldapOperations = ldapOperations; this.dn = dn; - this.actualModifications = actualModifications; - this.compensatingModifications = compensatingModifications; + this.actualModifications = (ModificationItem[]) actualModifications.clone(); + this.compensatingModifications = (ModificationItem[]) compensatingModifications.clone(); } /* diff --git a/core/src/main/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceAndDataSourceTransactionManager.java b/core/src/main/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceAndDataSourceTransactionManager.java index e616f658..78563448 100644 --- a/core/src/main/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceAndDataSourceTransactionManager.java +++ b/core/src/main/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceAndDataSourceTransactionManager.java @@ -160,7 +160,7 @@ public class ContextSourceAndDataSourceTransactionManager extends ldapManagerDelegate.setRenamingStrategy(renamingStrategy); } - private class ContextSourceAndDataSourceTransactionObject { + private final static class ContextSourceAndDataSourceTransactionObject { private Object ldapTransactionObject; private Object dataSourceTransactionObject; diff --git a/core/src/main/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceAndHibernateTransactionManager.java b/core/src/main/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceAndHibernateTransactionManager.java index 96bed5ee..fdf588b3 100755 --- a/core/src/main/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceAndHibernateTransactionManager.java +++ b/core/src/main/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceAndHibernateTransactionManager.java @@ -160,7 +160,7 @@ public class ContextSourceAndHibernateTransactionManager extends HibernateTransa ldapManagerDelegate.setRenamingStrategy(renamingStrategy); } - private class ContextSourceAndHibernateTransactionObject { + private final static class ContextSourceAndHibernateTransactionObject { private Object ldapTransactionObject; private Object hibernateTransactionObject; diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationExecutorTest.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationExecutorTest.java index 942711c2..8b6b2766 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationExecutorTest.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationExecutorTest.java @@ -19,6 +19,7 @@ import javax.naming.Name; import javax.naming.directory.ModificationItem; import org.easymock.MockControl; +import org.easymock.internal.ArrayMatcher; import org.springframework.ldap.core.DistinguishedName; import org.springframework.ldap.core.LdapOperations; import org.springframework.ldap.transaction.compensating.ModifyAttributesOperationExecutor; @@ -26,84 +27,82 @@ import org.springframework.ldap.transaction.compensating.ModifyAttributesOperati import junit.framework.TestCase; public class ModifyAttributesOperationExecutorTest extends TestCase { - private MockControl ldapOperationsControl; + private MockControl ldapOperationsControl; - private LdapOperations ldapOperationsMock; + private LdapOperations ldapOperationsMock; - protected void setUp() throws Exception { - ldapOperationsControl = MockControl.createControl(LdapOperations.class); - ldapOperationsMock = (LdapOperations) ldapOperationsControl.getMock(); - } + protected void setUp() throws Exception { + ldapOperationsControl = MockControl.createControl(LdapOperations.class); + ldapOperationsMock = (LdapOperations) ldapOperationsControl.getMock(); + } - protected void tearDown() throws Exception { - ldapOperationsControl = null; - ldapOperationsMock = null; - } + protected void tearDown() throws Exception { + ldapOperationsControl = null; + ldapOperationsMock = null; + } - protected void replay() { - ldapOperationsControl.replay(); - } + protected void replay() { + ldapOperationsControl.replay(); + } - protected void verify() { - ldapOperationsControl.verify(); - } + protected void verify() { + ldapOperationsControl.verify(); + } - public void testPerformOperation() { - ModificationItem[] expectedCompensatingItems = new ModificationItem[0]; - ModificationItem[] expectedActualItems = new ModificationItem[0]; + public void testPerformOperation() { + ModificationItem[] expectedCompensatingItems = new ModificationItem[0]; + ModificationItem[] expectedActualItems = new ModificationItem[0]; - Name expectedDn = new DistinguishedName("cn=john doe"); + Name expectedDn = new DistinguishedName("cn=john doe"); - ModifyAttributesOperationExecutor tested = new ModifyAttributesOperationExecutor( - ldapOperationsMock, expectedDn, expectedActualItems, - expectedCompensatingItems); + ModifyAttributesOperationExecutor tested = new ModifyAttributesOperationExecutor(ldapOperationsMock, + expectedDn, expectedActualItems, expectedCompensatingItems); - ldapOperationsMock.modifyAttributes(expectedDn, expectedActualItems); + ldapOperationsMock.modifyAttributes(expectedDn, expectedActualItems); + ldapOperationsControl.setMatcher(new ArrayMatcher()); - replay(); - // Perform test - tested.performOperation(); + replay(); + // Perform test + tested.performOperation(); - verify(); - } + verify(); + } - public void testCommit() { - ModificationItem[] expectedCompensatingItems = new ModificationItem[0]; - ModificationItem[] expectedActualItems = new ModificationItem[0]; + public void testCommit() { + ModificationItem[] expectedCompensatingItems = new ModificationItem[0]; + ModificationItem[] expectedActualItems = new ModificationItem[0]; - Name expectedDn = new DistinguishedName("cn=john doe"); + Name expectedDn = new DistinguishedName("cn=john doe"); - ModifyAttributesOperationExecutor tested = new ModifyAttributesOperationExecutor( - ldapOperationsMock, expectedDn, expectedActualItems, - expectedCompensatingItems); + ModifyAttributesOperationExecutor tested = new ModifyAttributesOperationExecutor(ldapOperationsMock, + expectedDn, expectedActualItems, expectedCompensatingItems); - // No operation here - - replay(); - // Perform test - tested.commit(); + // No operation here - verify(); - } + replay(); + // Perform test + tested.commit(); - public void testRollback() { - ModificationItem[] expectedCompensatingItems = new ModificationItem[0]; - ModificationItem[] expectedActualItems = new ModificationItem[0]; + verify(); + } - Name expectedDn = new DistinguishedName("cn=john doe"); + public void testRollback() { + ModificationItem[] expectedCompensatingItems = new ModificationItem[0]; + ModificationItem[] expectedActualItems = new ModificationItem[0]; - ModifyAttributesOperationExecutor tested = new ModifyAttributesOperationExecutor( - ldapOperationsMock, expectedDn, expectedActualItems, - expectedCompensatingItems); + Name expectedDn = new DistinguishedName("cn=john doe"); - ldapOperationsMock.modifyAttributes(expectedDn, - expectedCompensatingItems); + ModifyAttributesOperationExecutor tested = new ModifyAttributesOperationExecutor(ldapOperationsMock, + expectedDn, expectedActualItems, expectedCompensatingItems); - replay(); - // Perform test - tested.rollback(); + ldapOperationsMock.modifyAttributes(expectedDn, expectedCompensatingItems); + ldapOperationsControl.setMatcher(new ArrayMatcher()); - verify(); - } + replay(); + // Perform test + tested.rollback(); + + verify(); + } } diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationRecorderTest.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationRecorderTest.java index 41e268da..df1cf318 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationRecorderTest.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationRecorderTest.java @@ -116,7 +116,9 @@ public class ModifyAttributesOperationRecorderTest extends TestCase { ModifyAttributesOperationExecutor rollbackOperation = (ModifyAttributesOperationExecutor) operation; assertSame(expectedName, rollbackOperation.getDn()); assertSame(ldapOperationsMock, rollbackOperation.getLdapOperations()); - assertSame(incomingMods, rollbackOperation.getActualModifications()); + ModificationItem[] actualModifications = rollbackOperation.getActualModifications(); + assertEquals(incomingMods.length, actualModifications.length); + assertEquals(incomingMods[0], actualModifications[0]); assertEquals(1, rollbackOperation.getCompensatingModifications().length); assertSame(compensatingItem, rollbackOperation .getCompensatingModifications()[0]); diff --git a/src/assembly/all.xml b/src/assembly/all.xml index fa196eda..1ed89f55 100644 --- a/src/assembly/all.xml +++ b/src/assembly/all.xml @@ -10,7 +10,7 @@ org.springframework.ldap:spring-ldap-core org.springframework.ldap:spring-ldap-core-tiger - org.springframework.ldap:spring-ldap-acegi-support + org.springframework.ldap:spring-ldap-test diff --git a/src/assembly/minimal.xml b/src/assembly/minimal.xml index a2bcaa75..3d5ef6ce 100644 --- a/src/assembly/minimal.xml +++ b/src/assembly/minimal.xml @@ -14,7 +14,6 @@ org.springframework.ldap:spring-ldap-core org.springframework.ldap:spring-ldap-core-tiger org.springframework.ldap:spring-ldap-test - org.springframework.ldap:spring-ldap-acegi-support false diff --git a/src/assembly/sources.xml b/src/assembly/sources.xml index 8ea0f705..81cceed8 100644 --- a/src/assembly/sources.xml +++ b/src/assembly/sources.xml @@ -18,9 +18,5 @@ test-support/src/main/java - - acegi-support/src/main/java - -