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