|
Spring Framework example source code file (TopLinkInterceptorTests.java)
The Spring Framework TopLinkInterceptorTests.java source code
/*
* Created on Mar 20, 2005
*
*/
package org.springframework.orm.toplink;
import junit.framework.TestCase;
import org.aopalliance.intercept.MethodInvocation;
import org.easymock.MockControl;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import oracle.toplink.sessions.Session;
/**
* @author Juergen Hoeller
* @author <a href="mailto:james.x.clark@oracle.com">James Clark
* @since 28.04.2005
*/
public class TopLinkInterceptorTests extends TestCase {
public void testInterceptorWithNoSessionBoundAndNoSynchronizations() throws Throwable {
MockControl sessionControl = MockControl.createControl(Session.class);
Session session = (Session) sessionControl.getMock();
MockControl methodInvocationControl = MockControl.createControl(MethodInvocation.class);
MethodInvocation methodInvocation = (MethodInvocation) methodInvocationControl.getMock();
SessionFactory factory = new SingleSessionFactory(session);
TopLinkInterceptor interceptor = new TopLinkInterceptor();
interceptor.setSessionFactory(factory);
methodInvocation.proceed();
methodInvocationControl.setReturnValue(null, 1);
session.release();
sessionControl.setVoidCallable(1);
methodInvocationControl.replay();
sessionControl.replay();
try {
interceptor.invoke(methodInvocation);
}
catch (Throwable t) {
System.out.println(t);
t.printStackTrace();
fail();
}
assertFalse(TransactionSynchronizationManager.hasResource(factory));
sessionControl.verify();
methodInvocationControl.verify();
sessionControl.verify();
}
public void testInterceptorWithNoSessionBoundAndSynchronizationsActive() {
MockControl sessionControl = MockControl.createControl(Session.class);
Session session = (Session) sessionControl.getMock();
MockControl methodInvocationControl = MockControl.createControl(MethodInvocation.class);
MethodInvocation methodInvocation = (MethodInvocation) methodInvocationControl.getMock();
SessionFactory factory = new SingleSessionFactory(session);
TopLinkInterceptor interceptor = new TopLinkInterceptor();
interceptor.setSessionFactory(factory);
try {
methodInvocation.proceed();
}
catch (Throwable e) {
fail();
}
methodInvocationControl.setReturnValue(null, 1);
methodInvocationControl.replay();
sessionControl.replay();
TransactionSynchronizationManager.initSynchronization();
try {
interceptor.invoke(methodInvocation);
}
catch (Throwable t) {
fail();
}
assertTrue(TransactionSynchronizationManager.hasResource(factory));
assertTrue(TransactionSynchronizationManager.getSynchronizations().size() == 1);
TransactionSynchronizationManager.clearSynchronization();
TransactionSynchronizationManager.unbindResource(factory);
sessionControl.verify();
methodInvocationControl.verify();
}
}
Other Spring Framework examples (source code examples)Here is a short list of links related to this Spring Framework TopLinkInterceptorTests.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.