Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 65   Methods: 2
NCLOC: 42   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
PojoFailedTxMockupInterceptor.java 83.3% 85.7% 50% 81.8%
coverage coverage
 1    /*
 2    * JBoss, Home of Professional Open Source
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    */
 7   
 8    package org.jboss.cache.pojo.interceptors;
 9   
 10    import org.jboss.aop.joinpoint.Invocation;
 11    import org.jboss.aop.joinpoint.MethodInvocation;
 12    import org.jboss.cache.Fqn;
 13    import org.jboss.cache.pojo.impl.InternalConstant;
 14   
 15    import javax.transaction.Transaction;
 16   
 17    /**
 18    * Interceptor to mockup tx failure that resulting in rollback. User can simulate a rollback
 19    * by setting the static method <code>setRollback</code>. Note that you will need to use
 20    * setRollback for every method call, that is, it will reset itself after a rollback
 21    * has been performed.
 22    *
 23    * @author Ben Wang
 24    * @version $Id: PojoFailedTxMockupInterceptor.java,v 1.2 2007/05/30 06:08:02 jgreene Exp $
 25    */
 26    public class PojoFailedTxMockupInterceptor extends AbstractInterceptor
 27    {
 28    public static boolean TX_ROLLBACK = false;
 29   
 30  0 public static void setTxRollback(boolean isTrue)
 31    {
 32  0 TX_ROLLBACK = isTrue;
 33    }
 34   
 35  25119 public Object invoke(Invocation in) throws Throwable
 36    {
 37  25119 if (!(in instanceof MethodInvocation))
 38    {
 39  0 throw new IllegalArgumentException(
 40    "PojoFailedTxMockupInterceptor.invoke(): invocation not MethodInvocation");
 41    }
 42  25119 MethodInvocation invocation = (MethodInvocation) in;
 43  25119 try
 44    {
 45  25119 Object obj = null;
 46  25119 obj = invocation.invokeNext(); // proceed to next advice or actual call
 47  25116 if(TX_ROLLBACK)
 48    {
 49  34 Transaction tx = (Transaction)
 50    invocation.getMetaData().getMetaData(PojoTxInterceptor.TAG, PojoTxInterceptor.TX);
 51   
 52  34 Fqn id = (Fqn) invocation.getArguments()[0];
 53   
 54  34 if(!id.isChildOrEquals(InternalConstant.JBOSS_INTERNAL))
 55    {
 56  11 tx.setRollbackOnly();
 57  11 TX_ROLLBACK = false;
 58    }
 59    }
 60  25116 return obj;
 61    } finally
 62    {
 63    }
 64    }
 65    }