Renamed CompensatingTransactionDataManager and made it responsible for performing operations as well as keeping track of OperationExecutors.
Also made it possilbe to specify TempEntryRenamingStrategy in ContextSourceTransactionManager.
This commit is contained in:
@@ -16,25 +16,27 @@
|
||||
package org.springframework.ldap.support.transaction;
|
||||
|
||||
/**
|
||||
* A CompensatingTransactionDataManager implementation records operations that
|
||||
* are performed in a transaction and keeps track of compensating actions
|
||||
* necessary for rolling back each individual operation.
|
||||
* A CompensatingTransactionOperationManager implementation records and performs
|
||||
* operations that are to be performed within a compensating transaction and
|
||||
* keeps track of compensating actions necessary for rolling back each
|
||||
* individual operation.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*
|
||||
*/
|
||||
public interface CompensatingTransactionDataManager {
|
||||
public interface CompensatingTransactionOperationManager {
|
||||
/**
|
||||
* Indicates that the supplied operation (method name) has been performed
|
||||
* and that the supplied {@link CompensatingTransactionOperationExecutor}
|
||||
* should be stored for possible rollback. This method is called after the
|
||||
* the actual invocation of the target method.
|
||||
* Indicates that the supplied operation (method name) is to be performed.
|
||||
* This method is responsible for recording the current state (prior to the
|
||||
* operation), performing the operation, and storing the necessary
|
||||
* information to roll back or commit the performed operation.
|
||||
*
|
||||
* @param operation
|
||||
* the method to be invoked.
|
||||
* The method to be invoked.
|
||||
* @param args
|
||||
* Arguments supplied to the method.
|
||||
*/
|
||||
public void operationPerformed(
|
||||
CompensatingTransactionOperationExecutor operation);
|
||||
public void performOperation(String operation, Object[] args);
|
||||
|
||||
/**
|
||||
* Rollback all recorded operations, by performing each of the recorded
|
||||
@@ -61,6 +61,8 @@ public class ContextSourceTransactionManager extends
|
||||
|
||||
private ContextSource contextSource;
|
||||
|
||||
private TempEntryRenamingStrategy renamingStrategy = new DefaultTempEntryRenamingStrategy();
|
||||
|
||||
/**
|
||||
* Set the ContextSource to work on. Even though the actual ContextSource
|
||||
* sent to the LdapTemplate instance should be a
|
||||
@@ -109,7 +111,8 @@ public class ContextSourceTransactionManager extends
|
||||
|
||||
if (txObject.getContextHolder() == null) {
|
||||
DirContext newCtx = getContextSource().getReadOnlyContext();
|
||||
DirContextHolder contextHolder = new DirContextHolder(newCtx);
|
||||
DirContextHolder contextHolder = new DirContextHolder(newCtx,
|
||||
renamingStrategy);
|
||||
|
||||
txObject.setContextHolder(contextHolder);
|
||||
TransactionSynchronizationManager.bindResource(getContextSource(),
|
||||
@@ -163,4 +166,16 @@ public class ContextSourceTransactionManager extends
|
||||
|
||||
txObject.getContextHolder().clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link TempEntryRenamingStrategy} to be used when renaming
|
||||
* temporary entries in unbind and rebind operations. Default value is a
|
||||
* {@link DefaultTempEntryRenamingStrategy}.
|
||||
*
|
||||
* @param renamingStrategy
|
||||
* the {@link TempEntryRenamingStrategy} to use.
|
||||
*/
|
||||
public void setRenamingStrategy(TempEntryRenamingStrategy renamingStrategy) {
|
||||
this.renamingStrategy = renamingStrategy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,34 +21,49 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Default implementation of {@link CompensatingTransactionDataManager}.
|
||||
* Default implementation of {@link CompensatingTransactionOperationManager}.
|
||||
* Manages a stack of {@link CompensatingTransactionOperationExecutor} objects
|
||||
* and manages rollback of these in the reverse order.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
public class DefaultCompensatingTransactionDataManager implements
|
||||
CompensatingTransactionDataManager {
|
||||
public class DefaultCompensatingTransactionOperationManager implements
|
||||
CompensatingTransactionOperationManager {
|
||||
|
||||
private static Log log = LogFactory
|
||||
.getLog(DefaultCompensatingTransactionDataManager.class);
|
||||
.getLog(DefaultCompensatingTransactionOperationManager.class);
|
||||
|
||||
private Stack rollbackOperations = new Stack();
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.support.transaction.CompensatingTransactionDataManager#operationPerformed(org.springframework.ldap.support.transaction.CompensatingTransactionOperationExecutor)
|
||||
*/
|
||||
public void operationPerformed(
|
||||
CompensatingTransactionOperationExecutor operation) {
|
||||
rollbackOperations.push(operation);
|
||||
private CompensatingTransactionOperationFactory operationFactory;
|
||||
|
||||
public DefaultCompensatingTransactionOperationManager(
|
||||
CompensatingTransactionOperationFactory operationFactory) {
|
||||
this.operationFactory = operationFactory;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.support.transaction.CompensatingTransactionDataManager#rollback()
|
||||
* @see org.springframework.ldap.support.transaction.CompensatingTransactionOperationManager#operationPerformed(java.lang.String,
|
||||
* java.lang.Object[])
|
||||
*/
|
||||
public void performOperation(String operation, Object[] args) {
|
||||
CompensatingTransactionOperationRecorder recorder = operationFactory
|
||||
.createRecordingOperation(operation);
|
||||
CompensatingTransactionOperationExecutor executor = recorder
|
||||
.recordOperation(args);
|
||||
|
||||
executor.performOperation();
|
||||
|
||||
// Don't push the executor until the actual operation passed.
|
||||
rollbackOperations.push(executor);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.support.transaction.CompensatingTransactionOperationManager#rollback()
|
||||
*/
|
||||
public void rollback() {
|
||||
log.debug("Performing rollback");
|
||||
@@ -79,8 +94,10 @@ public class DefaultCompensatingTransactionDataManager implements
|
||||
this.rollbackOperations = rollbackOperations;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.ldap.support.transaction.CompensatingTransactionDataManager#commit()
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.support.transaction.CompensatingTransactionOperationManager#commit()
|
||||
*/
|
||||
public void commit() {
|
||||
log.debug("Performing rollback");
|
||||
@@ -22,9 +22,9 @@ import org.springframework.transaction.support.ResourceHolderSupport;
|
||||
/**
|
||||
* Keeps track of the transaction DirContext. The same DirContext instance will
|
||||
* be reused throughout a transaction. Also keeps a
|
||||
* {@link CompensatingTransactionDataManager}, responsible for keeping track of
|
||||
* all changes and storing compensating rollback operations, should the
|
||||
* transaction need to be rolled back.
|
||||
* {@link CompensatingTransactionOperationManager}, responsible for performing
|
||||
* operations and keeping track of all changes and storing information necessary
|
||||
* for commit or rollback.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
*
|
||||
@@ -32,34 +32,49 @@ import org.springframework.transaction.support.ResourceHolderSupport;
|
||||
public class DirContextHolder extends ResourceHolderSupport {
|
||||
private DirContext ctx;
|
||||
|
||||
private CompensatingTransactionDataManager transactionDataManager;
|
||||
private CompensatingTransactionOperationManager transactionDataManager;
|
||||
|
||||
private CompensatingTransactionOperationFactory operationFactory;
|
||||
|
||||
private TempEntryRenamingStrategy renamingStrategy;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param ctx
|
||||
* The DirContext associated with the current transaction.
|
||||
*/
|
||||
public DirContextHolder(DirContext ctx) {
|
||||
public DirContextHolder(DirContext ctx,
|
||||
TempEntryRenamingStrategy renamingStrategy) {
|
||||
this.ctx = ctx;
|
||||
this.transactionDataManager = new DefaultCompensatingTransactionDataManager();
|
||||
this.operationFactory = new LdapCompensatingTransactionOperationFactory(
|
||||
ctx);
|
||||
this.renamingStrategy = renamingStrategy;
|
||||
this.transactionDataManager = new DefaultCompensatingTransactionOperationManager(
|
||||
createOperationFactory());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the DirContext associated with the current transaction.
|
||||
*
|
||||
* @param ctx
|
||||
* the DirContext associated with the current transaction.
|
||||
* The DirContext associated with the current transaction.
|
||||
*/
|
||||
public void setCtx(DirContext ctx) {
|
||||
this.ctx = ctx;
|
||||
this.transactionDataManager = new DefaultCompensatingTransactionDataManager();
|
||||
this.operationFactory = new LdapCompensatingTransactionOperationFactory(
|
||||
ctx);
|
||||
this.transactionDataManager = new DefaultCompensatingTransactionOperationManager(
|
||||
createOperationFactory());
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method to create a
|
||||
* {@link CompensatingTransactionOperationFactory} using the settings and
|
||||
* current state of this object.
|
||||
*
|
||||
* @return a new {@link LdapCompensatingTransactionOperationFactory}
|
||||
* referncing the current transaction context.
|
||||
*/
|
||||
private CompensatingTransactionOperationFactory createOperationFactory() {
|
||||
return new LdapCompensatingTransactionOperationFactory(ctx,
|
||||
renamingStrategy);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,27 +91,32 @@ public class DirContextHolder extends ResourceHolderSupport {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the CompensatingTransactionDataManager to handle the data for the
|
||||
* current transaction.
|
||||
* Get the CompensatingTransactionOperationManager to handle the data for
|
||||
* the current transaction.
|
||||
*
|
||||
* @return the CompensatingTransactionDataManager.
|
||||
* @return the CompensatingTransactionOperationManager.
|
||||
*/
|
||||
public CompensatingTransactionDataManager getTransactionDataManager() {
|
||||
public CompensatingTransactionOperationManager getTransactionDataManager() {
|
||||
return transactionDataManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the CompensatingTransactionDataManager. For testing purposes only.
|
||||
* Set the CompensatingTransactionOperationManager. For testing purposes
|
||||
* only.
|
||||
*
|
||||
* @param transactionDataManager
|
||||
* the CompensatingTransactionDataManager to use.
|
||||
* the CompensatingTransactionOperationManager to use.
|
||||
*/
|
||||
void setTransactionDataManager(
|
||||
CompensatingTransactionDataManager transactionDataManager) {
|
||||
CompensatingTransactionOperationManager transactionDataManager) {
|
||||
this.transactionDataManager = transactionDataManager;
|
||||
}
|
||||
|
||||
public CompensatingTransactionOperationFactory getOperationFactory() {
|
||||
return operationFactory;
|
||||
}
|
||||
|
||||
public TempEntryRenamingStrategy getRenamingStrategy() {
|
||||
return renamingStrategy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,14 +22,18 @@ public class LdapCompensatingTransactionOperationFactory implements
|
||||
|
||||
private LdapOperations ldapOperations;
|
||||
|
||||
private TempEntryRenamingStrategy renamingStrategy;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param ctx
|
||||
* The transactional DirContext.
|
||||
*/
|
||||
public LdapCompensatingTransactionOperationFactory(DirContext ctx) {
|
||||
public LdapCompensatingTransactionOperationFactory(DirContext ctx,
|
||||
TempEntryRenamingStrategy renamingStrategy) {
|
||||
this.ldapOperations = new LdapTemplate(new SingleContextSource(ctx));
|
||||
this.renamingStrategy = renamingStrategy;
|
||||
}
|
||||
|
||||
public CompensatingTransactionOperationRecorder createRecordingOperation(
|
||||
@@ -39,7 +43,7 @@ public class LdapCompensatingTransactionOperationFactory implements
|
||||
return new BindOperationRecorder(ldapOperations);
|
||||
} else if (StringUtils.equals(operation, LdapUtils.REBIND_METHOD_NAME)) {
|
||||
log.debug("Rebind operation recorded");
|
||||
return new RebindOperationRecorder(ldapOperations);
|
||||
return new RebindOperationRecorder(ldapOperations, renamingStrategy);
|
||||
} else if (StringUtils.equals(operation, LdapUtils.RENAME_METHOD_NAME)) {
|
||||
log.debug("Rename operation recorded");
|
||||
return new RenameOperationRecorder(ldapOperations);
|
||||
@@ -47,7 +51,7 @@ public class LdapCompensatingTransactionOperationFactory implements
|
||||
LdapUtils.MODIFY_ATTRIBUTES_METHOD_NAME)) {
|
||||
return new ModifyAttributesOperationRecorder(ldapOperations);
|
||||
} else if (StringUtils.equals(operation, LdapUtils.UNBIND_METHOD_NAME)) {
|
||||
return new UnbindOperationRecorder(ldapOperations);
|
||||
return new UnbindOperationRecorder(ldapOperations, renamingStrategy);
|
||||
}
|
||||
|
||||
log
|
||||
|
||||
@@ -133,8 +133,8 @@ public class LdapUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Store compensating transaction data for the supplied operation and
|
||||
* arguments. TODO: Clean up this mess.
|
||||
* Perform the specified operation, storing the state prior to the
|
||||
* operation, to enable commit/rollback later.
|
||||
*
|
||||
* @param contextSource
|
||||
* the ContextSource we are operating on.
|
||||
@@ -143,40 +143,22 @@ public class LdapUtils {
|
||||
* @param args
|
||||
* arguments with which the operation is invoked.
|
||||
*/
|
||||
public static Object operationPerformed(ContextSource contextSource,
|
||||
public static void performOperation(ContextSource contextSource,
|
||||
Method method, Object[] args) throws Throwable {
|
||||
DirContextHolder transactionContextHolder = (DirContextHolder) TransactionSynchronizationManager
|
||||
.getResource(contextSource);
|
||||
if (transactionContextHolder != null) {
|
||||
CompensatingTransactionDataManager transactionDataManager = transactionContextHolder
|
||||
|
||||
CompensatingTransactionOperationManager transactionDataManager = transactionContextHolder
|
||||
.getTransactionDataManager();
|
||||
CompensatingTransactionOperationFactory operationFactory = transactionContextHolder
|
||||
.getOperationFactory();
|
||||
|
||||
// Record the operation
|
||||
CompensatingTransactionOperationRecorder operation = operationFactory
|
||||
.createRecordingOperation(method.getName());
|
||||
CompensatingTransactionOperationExecutor rollbackOperation = operation
|
||||
.recordOperation(args);
|
||||
|
||||
Object result = null;
|
||||
// Perform the target operation
|
||||
rollbackOperation.performOperation();
|
||||
// result = method.invoke(transactionContextHolder.getCtx(),
|
||||
// args);
|
||||
transactionDataManager.operationPerformed(rollbackOperation);
|
||||
|
||||
return result;
|
||||
transactionDataManager.performOperation(method.getName(), args);
|
||||
} else {
|
||||
Object result = null;
|
||||
// Perform the target operation
|
||||
try {
|
||||
result = method.invoke(transactionContextHolder.getCtx(), args);
|
||||
method.invoke(transactionContextHolder.getCtx(), args);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw e.getTargetException();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.ldap.support.transaction;
|
||||
* A {@link CompensatingTransactionOperationRecorder} performing nothing,
|
||||
* returning a {@link NullOperationExecutor} regardless of the input. Instances
|
||||
* of this class will be created if the
|
||||
* {@link CompensatingTransactionDataManager} cannot determine any appropriate
|
||||
* {@link CompensatingTransactionOperationManager} cannot determine any appropriate
|
||||
* {@link CompensatingTransactionOperationRecorder} for the current operation.
|
||||
*
|
||||
* @author Mattias Arthursson
|
||||
|
||||
@@ -32,7 +32,7 @@ public class RebindOperationRecorder implements
|
||||
|
||||
private LdapOperations ldapOperations;
|
||||
|
||||
private TempEntryRenamingStrategy renamingStrategy = new DefaultTempEntryRenamingStrategy();
|
||||
private TempEntryRenamingStrategy renamingStrategy;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -40,9 +40,14 @@ public class RebindOperationRecorder implements
|
||||
* @param ldapOperations
|
||||
* {@link LdapOperations} to use for getting the rollback
|
||||
* information and supply to the {@link RebindOperationExecutor}.
|
||||
* @param the
|
||||
* {@link TempEntryRenamingStrategy} to use for generating temp
|
||||
* DNs.
|
||||
*/
|
||||
public RebindOperationRecorder(LdapOperations ldapOperations) {
|
||||
public RebindOperationRecorder(LdapOperations ldapOperations,
|
||||
TempEntryRenamingStrategy renamingStrategy) {
|
||||
this.ldapOperations = ldapOperations;
|
||||
this.renamingStrategy = renamingStrategy;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -84,8 +89,4 @@ public class RebindOperationRecorder implements
|
||||
public TempEntryRenamingStrategy getRenamingStrategy() {
|
||||
return renamingStrategy;
|
||||
}
|
||||
|
||||
public void setRenamingStrategy(TempEntryRenamingStrategy renamingStrategy) {
|
||||
this.renamingStrategy = renamingStrategy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
|
||||
* @author Mattias Arthursson
|
||||
*/
|
||||
public class TransactionAwareContextSourceProxy implements ContextSource {
|
||||
|
||||
private ContextSource target;
|
||||
|
||||
/**
|
||||
|
||||
@@ -75,7 +75,8 @@ public class TransactionAwareDirContextInvocationHandler implements
|
||||
return null;
|
||||
} else if (LdapUtils.isSupportedWriteTransactionOperation(methodName)) {
|
||||
// Store transaction data and allow operation to proceed.
|
||||
return LdapUtils.operationPerformed(contextSource, method, args);
|
||||
LdapUtils.performOperation(contextSource, method, args);
|
||||
return null;
|
||||
} else {
|
||||
try {
|
||||
return method.invoke(target, args);
|
||||
|
||||
@@ -31,7 +31,7 @@ public class UnbindOperationRecorder implements
|
||||
|
||||
private LdapOperations ldapOperations;
|
||||
|
||||
private TempEntryRenamingStrategy renamingStrategy = new DefaultTempEntryRenamingStrategy();
|
||||
private TempEntryRenamingStrategy renamingStrategy;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -40,9 +40,14 @@ public class UnbindOperationRecorder implements
|
||||
* {@link LdapOperations} to use for getting the data prior to
|
||||
* unbinding the entry and to supply to the
|
||||
* {@link UnbindOperationExecutor} for rollback.
|
||||
* @param renamingStrategy
|
||||
* the {@link TempEntryRenamingStrategy} to use when generating
|
||||
* DNs for temporary entries.
|
||||
*/
|
||||
public UnbindOperationRecorder(LdapOperations ldapOperations) {
|
||||
public UnbindOperationRecorder(LdapOperations ldapOperations,
|
||||
TempEntryRenamingStrategy renamingStrategy) {
|
||||
this.ldapOperations = ldapOperations;
|
||||
this.renamingStrategy = renamingStrategy;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -65,9 +70,4 @@ public class UnbindOperationRecorder implements
|
||||
public TempEntryRenamingStrategy getRenamingStrategy() {
|
||||
return renamingStrategy;
|
||||
}
|
||||
|
||||
public void setRenamingStrategy(TempEntryRenamingStrategy renamingStrategy) {
|
||||
this.renamingStrategy = renamingStrategy;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,10 +28,14 @@ public class ContextSourceTransactionManagerTest extends TestCase {
|
||||
|
||||
private MockControl transactionDataManagerControl;
|
||||
|
||||
private CompensatingTransactionDataManager transactionDataManagerMock;
|
||||
private CompensatingTransactionOperationManager transactionDataManagerMock;
|
||||
|
||||
private TransactionDefinition transactionDefinitionMock;
|
||||
|
||||
private MockControl renamingStrategyControl;
|
||||
|
||||
private TempEntryRenamingStrategy renamingStrategyMock;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
if (TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
@@ -50,12 +54,18 @@ public class ContextSourceTransactionManagerTest extends TestCase {
|
||||
.getMock();
|
||||
|
||||
transactionDataManagerControl = MockControl
|
||||
.createControl(CompensatingTransactionDataManager.class);
|
||||
transactionDataManagerMock = (CompensatingTransactionDataManager) transactionDataManagerControl
|
||||
.createControl(CompensatingTransactionOperationManager.class);
|
||||
transactionDataManagerMock = (CompensatingTransactionOperationManager) transactionDataManagerControl
|
||||
.getMock();
|
||||
|
||||
renamingStrategyControl = MockControl
|
||||
.createControl(TempEntryRenamingStrategy.class);
|
||||
renamingStrategyMock = (TempEntryRenamingStrategy) renamingStrategyControl
|
||||
.getMock();
|
||||
|
||||
tested = new ContextSourceTransactionManager();
|
||||
tested.setContextSource(contextSourceMock);
|
||||
tested.setRenamingStrategy(renamingStrategyMock);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
@@ -73,6 +83,9 @@ public class ContextSourceTransactionManagerTest extends TestCase {
|
||||
transactionDataManagerControl = null;
|
||||
transactionDataManagerMock = null;
|
||||
|
||||
renamingStrategyControl = null;
|
||||
renamingStrategyMock = null;
|
||||
|
||||
if (TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
TransactionSynchronizationManager.clearSynchronization();
|
||||
}
|
||||
@@ -88,11 +101,11 @@ public class ContextSourceTransactionManagerTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testDoGetTransactionTransactionActive() {
|
||||
DirContextHolder expectedContextHolder = new DirContextHolder(null);
|
||||
DirContextHolder expectedContextHolder = new DirContextHolder(null,
|
||||
null);
|
||||
TransactionSynchronizationManager.bindResource(contextSourceMock,
|
||||
expectedContextHolder);
|
||||
Object result = tested.doGetTransaction();
|
||||
|
||||
assertSame(expectedContextHolder,
|
||||
((ContextSourceTransactionObject) result).getContextHolder());
|
||||
}
|
||||
@@ -112,6 +125,8 @@ public class ContextSourceTransactionManagerTest extends TestCase {
|
||||
DirContextHolder foundContextHolder = (DirContextHolder) TransactionSynchronizationManager
|
||||
.getResource(contextSourceMock);
|
||||
assertSame(contextMock, foundContextHolder.getCtx());
|
||||
assertSame(renamingStrategyMock, foundContextHolder
|
||||
.getRenamingStrategy());
|
||||
}
|
||||
|
||||
public void testDoCommit() {
|
||||
@@ -120,7 +135,7 @@ public class ContextSourceTransactionManagerTest extends TestCase {
|
||||
public void testDoRollback() {
|
||||
|
||||
DirContextHolder expectedContextHolder = new DirContextHolder(
|
||||
contextMock);
|
||||
contextMock, renamingStrategyMock);
|
||||
expectedContextHolder
|
||||
.setTransactionDataManager(transactionDataManagerMock);
|
||||
TransactionSynchronizationManager.bindResource(contextSourceMock,
|
||||
@@ -138,7 +153,7 @@ public class ContextSourceTransactionManagerTest extends TestCase {
|
||||
|
||||
public void testDoCleanupAfterCompletion() throws Exception {
|
||||
DirContextHolder expectedContextHolder = new DirContextHolder(
|
||||
contextMock);
|
||||
contextMock, renamingStrategyMock);
|
||||
TransactionSynchronizationManager.bindResource(contextSourceMock,
|
||||
expectedContextHolder);
|
||||
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
package org.springframework.ldap.support.transaction;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
|
||||
public class DefaultCompensatingTransactionDataManagerTest extends TestCase {
|
||||
|
||||
private MockControl rollbackOperationControl;
|
||||
|
||||
private CompensatingTransactionOperationExecutor rollbackOperationMock;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
rollbackOperationControl = MockControl
|
||||
.createControl(CompensatingTransactionOperationExecutor.class);
|
||||
rollbackOperationMock = (CompensatingTransactionOperationExecutor) rollbackOperationControl
|
||||
.getMock();
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
rollbackOperationControl = null;
|
||||
rollbackOperationMock = null;
|
||||
}
|
||||
|
||||
protected void replay() {
|
||||
rollbackOperationControl.replay();
|
||||
}
|
||||
|
||||
protected void verify() {
|
||||
rollbackOperationControl.verify();
|
||||
}
|
||||
|
||||
public void testOperationPerformed() {
|
||||
DefaultCompensatingTransactionDataManager tested = new DefaultCompensatingTransactionDataManager();
|
||||
|
||||
replay();
|
||||
tested.operationPerformed(rollbackOperationMock);
|
||||
verify();
|
||||
|
||||
Stack result = tested.getRollbackOperations();
|
||||
assertFalse(result.isEmpty());
|
||||
assertSame(rollbackOperationMock, result.peek());
|
||||
}
|
||||
|
||||
public void testRollback() {
|
||||
DefaultCompensatingTransactionDataManager tested = new DefaultCompensatingTransactionDataManager();
|
||||
tested.getRollbackOperations().push(rollbackOperationMock);
|
||||
|
||||
rollbackOperationMock.rollback();
|
||||
|
||||
replay();
|
||||
tested.rollback();
|
||||
verify();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package org.springframework.ldap.support.transaction;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
|
||||
public class DefaultCompensatingTransactionOperationManagerTest extends
|
||||
TestCase {
|
||||
|
||||
private MockControl operationExecutorControl;
|
||||
|
||||
private CompensatingTransactionOperationExecutor operationExecutorMock;
|
||||
|
||||
private MockControl operationFactoryControl;
|
||||
|
||||
private CompensatingTransactionOperationFactory operationFactoryMock;
|
||||
|
||||
private MockControl operationRecorderControl;
|
||||
|
||||
private CompensatingTransactionOperationRecorder operationRecorderMock;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
operationExecutorControl = MockControl
|
||||
.createControl(CompensatingTransactionOperationExecutor.class);
|
||||
operationExecutorMock = (CompensatingTransactionOperationExecutor) operationExecutorControl
|
||||
.getMock();
|
||||
|
||||
operationFactoryControl = MockControl
|
||||
.createControl(CompensatingTransactionOperationFactory.class);
|
||||
operationFactoryMock = (CompensatingTransactionOperationFactory) operationFactoryControl
|
||||
.getMock();
|
||||
|
||||
operationRecorderControl = MockControl
|
||||
.createControl(CompensatingTransactionOperationRecorder.class);
|
||||
operationRecorderMock = (CompensatingTransactionOperationRecorder) operationRecorderControl
|
||||
.getMock();
|
||||
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
operationExecutorControl = null;
|
||||
operationExecutorMock = null;
|
||||
|
||||
operationFactoryControl = null;
|
||||
operationFactoryMock = null;
|
||||
|
||||
operationRecorderControl = null;
|
||||
operationRecorderMock = null;
|
||||
}
|
||||
|
||||
protected void replay() {
|
||||
operationExecutorControl.replay();
|
||||
operationFactoryControl.replay();
|
||||
operationRecorderControl.replay();
|
||||
}
|
||||
|
||||
protected void verify() {
|
||||
operationExecutorControl.verify();
|
||||
operationFactoryControl.verify();
|
||||
operationRecorderControl.verify();
|
||||
}
|
||||
|
||||
public void testPerformOperation() {
|
||||
Object[] expectedArgs = new Object[0];
|
||||
|
||||
operationFactoryControl
|
||||
.expectAndReturn(operationFactoryMock
|
||||
.createRecordingOperation("some method"),
|
||||
operationRecorderMock);
|
||||
operationRecorderControl.expectAndReturn(operationRecorderMock
|
||||
.recordOperation(expectedArgs), operationExecutorMock);
|
||||
operationExecutorMock.performOperation();
|
||||
|
||||
DefaultCompensatingTransactionOperationManager tested = new DefaultCompensatingTransactionOperationManager(
|
||||
operationFactoryMock);
|
||||
replay();
|
||||
tested.performOperation("some method", expectedArgs);
|
||||
verify();
|
||||
|
||||
Stack result = tested.getRollbackOperations();
|
||||
assertFalse(result.isEmpty());
|
||||
assertSame(operationExecutorMock, result.peek());
|
||||
}
|
||||
|
||||
public void testRollback() {
|
||||
DefaultCompensatingTransactionOperationManager tested = new DefaultCompensatingTransactionOperationManager(
|
||||
operationFactoryMock);
|
||||
tested.getRollbackOperations().push(operationExecutorMock);
|
||||
|
||||
operationExecutorMock.rollback();
|
||||
|
||||
replay();
|
||||
tested.rollback();
|
||||
verify();
|
||||
}
|
||||
|
||||
public void testCommit() {
|
||||
DefaultCompensatingTransactionOperationManager tested = new DefaultCompensatingTransactionOperationManager(
|
||||
operationFactoryMock);
|
||||
tested.getRollbackOperations().push(operationExecutorMock);
|
||||
|
||||
operationExecutorMock.commit();
|
||||
|
||||
replay();
|
||||
tested.commit();
|
||||
verify();
|
||||
}
|
||||
}
|
||||
@@ -10,27 +10,42 @@ public class LdapCompensatingTransactionOperationFactoryTest extends TestCase {
|
||||
|
||||
private LdapOperations ldapOperationsMock;
|
||||
|
||||
private MockControl renamingStrategyControl;
|
||||
|
||||
private TempEntryRenamingStrategy renamingStrategyMock;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
ldapOperationsControl = MockControl.createControl(LdapOperations.class);
|
||||
ldapOperationsMock = (LdapOperations) ldapOperationsControl.getMock();
|
||||
|
||||
renamingStrategyControl = MockControl
|
||||
.createControl(TempEntryRenamingStrategy.class);
|
||||
renamingStrategyMock = (TempEntryRenamingStrategy) renamingStrategyControl
|
||||
.getMock();
|
||||
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
ldapOperationsControl = null;
|
||||
ldapOperationsMock = null;
|
||||
|
||||
renamingStrategyControl = null;
|
||||
renamingStrategyMock = null;
|
||||
}
|
||||
|
||||
protected void replay() {
|
||||
ldapOperationsControl.replay();
|
||||
renamingStrategyControl.replay();
|
||||
}
|
||||
|
||||
protected void verify() {
|
||||
ldapOperationsControl.verify();
|
||||
renamingStrategyControl.verify();
|
||||
}
|
||||
|
||||
public void testGetRecordingOperation_Bind() throws Exception {
|
||||
LdapCompensatingTransactionOperationFactory tested = new LdapCompensatingTransactionOperationFactory(
|
||||
null);
|
||||
null, renamingStrategyMock);
|
||||
tested.setLdapOperations(ldapOperationsMock);
|
||||
|
||||
CompensatingTransactionOperationRecorder result = tested
|
||||
@@ -43,7 +58,7 @@ public class LdapCompensatingTransactionOperationFactoryTest extends TestCase {
|
||||
|
||||
public void testGetRecordingOperation_Rebind() throws Exception {
|
||||
LdapCompensatingTransactionOperationFactory tested = new LdapCompensatingTransactionOperationFactory(
|
||||
null);
|
||||
null, renamingStrategyMock);
|
||||
tested.setLdapOperations(ldapOperationsMock);
|
||||
|
||||
CompensatingTransactionOperationRecorder result = tested
|
||||
@@ -52,11 +67,13 @@ public class LdapCompensatingTransactionOperationFactoryTest extends TestCase {
|
||||
RebindOperationRecorder rebindOperationRecorder = (RebindOperationRecorder) result;
|
||||
assertSame(ldapOperationsMock, rebindOperationRecorder
|
||||
.getLdapOperations());
|
||||
assertSame(renamingStrategyMock, rebindOperationRecorder
|
||||
.getRenamingStrategy());
|
||||
}
|
||||
|
||||
public void testGetRecordingOperation_Rename() throws Exception {
|
||||
LdapCompensatingTransactionOperationFactory tested = new LdapCompensatingTransactionOperationFactory(
|
||||
null);
|
||||
null, renamingStrategyMock);
|
||||
tested.setLdapOperations(ldapOperationsMock);
|
||||
|
||||
CompensatingTransactionOperationRecorder result = tested
|
||||
@@ -68,7 +85,7 @@ public class LdapCompensatingTransactionOperationFactoryTest extends TestCase {
|
||||
|
||||
public void testGetRecordingOperation_ModifyAttributes() throws Exception {
|
||||
LdapCompensatingTransactionOperationFactory tested = new LdapCompensatingTransactionOperationFactory(
|
||||
null);
|
||||
null, renamingStrategyMock);
|
||||
tested.setLdapOperations(ldapOperationsMock);
|
||||
|
||||
CompensatingTransactionOperationRecorder result = tested
|
||||
@@ -80,7 +97,7 @@ public class LdapCompensatingTransactionOperationFactoryTest extends TestCase {
|
||||
|
||||
public void testGetRecordingOperation_Unbind() throws Exception {
|
||||
LdapCompensatingTransactionOperationFactory tested = new LdapCompensatingTransactionOperationFactory(
|
||||
null);
|
||||
null, renamingStrategyMock);
|
||||
tested.setLdapOperations(ldapOperationsMock);
|
||||
|
||||
CompensatingTransactionOperationRecorder result = tested
|
||||
@@ -88,6 +105,8 @@ public class LdapCompensatingTransactionOperationFactoryTest extends TestCase {
|
||||
assertTrue(result instanceof UnbindOperationRecorder);
|
||||
UnbindOperationRecorder recordingOperation = (UnbindOperationRecorder) result;
|
||||
assertSame(ldapOperationsMock, recordingOperation.getLdapOperations());
|
||||
assertSame(renamingStrategyMock, recordingOperation
|
||||
.getRenamingStrategy());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,8 +53,7 @@ public class RebindOperationRecorderTest extends TestCase {
|
||||
final DistinguishedName expectedTempDn = new DistinguishedName(
|
||||
"cn=john doe");
|
||||
RebindOperationRecorder tested = new RebindOperationRecorder(
|
||||
ldapOperationsMock);
|
||||
tested.setRenamingStrategy(renamingStrategyMock);
|
||||
ldapOperationsMock, renamingStrategyMock);
|
||||
|
||||
renamingStrategyControl.expectAndReturn(renamingStrategyMock
|
||||
.getTemporaryName(expectedDn), expectedTempDn);
|
||||
@@ -62,7 +61,7 @@ public class RebindOperationRecorderTest extends TestCase {
|
||||
replay();
|
||||
Object expectedObject = new Object();
|
||||
BasicAttributes expectedAttributes = new BasicAttributes();
|
||||
|
||||
|
||||
// perform test
|
||||
CompensatingTransactionOperationExecutor result = tested
|
||||
.recordOperation(new Object[] { expectedDn, expectedObject,
|
||||
|
||||
@@ -51,8 +51,7 @@ public class UnbindOperationRecorderTest extends TestCase {
|
||||
final DistinguishedName expectedDn = new DistinguishedName(
|
||||
"cn=john doe");
|
||||
UnbindOperationRecorder tested = new UnbindOperationRecorder(
|
||||
ldapOperationsMock);
|
||||
tested.setRenamingStrategy(renamingStrategyMock);
|
||||
ldapOperationsMock, renamingStrategyMock);
|
||||
|
||||
renamingStrategyControl.expectAndReturn(renamingStrategyMock
|
||||
.getTemporaryName(expectedDn), expectedTempName);
|
||||
|
||||
Reference in New Issue
Block a user