Coverage Report - org.mule.tck.functional.TransactionalFunctionalTestComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
TransactionalFunctionalTestComponent
0%
0/19
0%
0/8
1.8
 
 1  
 /*
 2  
  * $Id: TransactionalFunctionalTestComponent.java 10787 2008-02-12 18:51:50Z dfeist $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.tck.functional;
 12  
 
 13  
 import org.mule.api.MuleEventContext;
 14  
 import org.mule.api.transaction.Transaction;
 15  
 import org.mule.api.transaction.TransactionException;
 16  
 import org.mule.config.i18n.MessageFactory;
 17  
 
 18  
 /**
 19  
  * This service is useful for unit tests involving transactionality because it
 20  
  * will roll back the current transaction upon message arrival.  
 21  
  */
 22  0
 public class TransactionalFunctionalTestComponent extends FunctionalTestComponent
 23  
 {
 24  0
     private boolean expectTransaction = true;
 25  0
     private boolean rollback = true;
 26  
 
 27  
     /** {@inheritDoc} */
 28  
     public Object onCall(MuleEventContext context) throws Exception
 29  
     {
 30  0
         Object replyMessage = super.onCall(context);
 31  
 
 32  0
         if (expectTransaction)
 33  
         {
 34  
             // Verify transaction has begun.
 35  0
             Transaction currentTx = context.getCurrentTransaction();
 36  0
             if (currentTx == null || currentTx.isBegun() == false)
 37  
             {    
 38  0
                 context.setStopFurtherProcessing(true);
 39  0
                 throw new TransactionException(MessageFactory.createStaticMessage("Trying to roll back transaction but no transaction is underway."));
 40  
             }            
 41  
 
 42  0
             if (rollback)
 43  
             {
 44  
                 // Mark the transaction for rollback.
 45  0
                 logger.info("@@@@ Rolling back transaction @@@@");
 46  0
                 currentTx.setRollbackOnly();
 47  
             }        
 48  
         }
 49  
         
 50  0
         return replyMessage;
 51  
     }
 52  
 
 53  
     public boolean isRollback()
 54  
     {
 55  0
         return rollback;
 56  
     }
 57  
 
 58  
     public void setRollback(boolean rollback)
 59  
     {
 60  0
         this.rollback = rollback;
 61  0
     }
 62  
 
 63  
     public boolean isExpectTransaction()
 64  
     {
 65  0
         return expectTransaction;
 66  
     }
 67  
 
 68  
     public void setExpectTransaction(boolean expectTransaction)
 69  
     {
 70  0
         this.expectTransaction = expectTransaction;
 71  0
     }
 72  
 }
 73