예제 #1
0
 /**
  * Verifies if the container re-throws the application exception that extends a runtime exception
  * (with rollback = false) and does not do the rollback in this case. The test uses a client
  * transaction.
  *
  * @throws Exception if an error during the tests occurs.
  */
 public void testUsingClientTransWithAppRuntimeException() throws Exception {
   UserTransaction utx = ExceptionHandleUtil.getUserTransaction();
   utx.begin();
   try {
     sfsbContainerTransactionApp01.insertCorrectFirstErrorSecond(DATABASE_1, DATABASE_2);
     fail("The container did not re-throw the application exception.");
   } catch (AppRuntimeException e) {
     logger.debug("The bean threw an expected error during the execution {0}", e);
   }
   // tries to commit
   try {
     utx.commit();
   } catch (Exception e) {
     logger.debug("The bean threw an expected error during the execution {0}", e);
   }
   // verifies if the table was created in the DATABASE_1
   ExceptionHandleUtil.verifyTable(DATABASE_1, ItfContainerTransaction.TABLE);
 }
예제 #2
0
  /**
   * Verifies if the container throws the correct exception (EJBException for RequiresNew and
   * NotSupports, and EJBTransactionRolledbackException for Require, Supports and Mandatory) when
   * the bean throws a RuntimeException, discards the bean and does the rollback if the bean uses
   * the client transaction.
   *
   * @param expectedException EJBException for RequiresNew and NotSupports, and
   *     EJBTransactionRolledbackException for Require, Supports and Mandatory
   * @param canCommit true if the bean does not use the client transaction.
   * @throws Exception if an error during the tests occurs.
   */
  public void testUsingClientTransWithRuntimeException(
      final Class expectedException, final boolean canCommit) throws Exception {
    UserTransaction utx = ExceptionHandleUtil.getUserTransaction();
    utx.begin();
    // verifies if the exception thrown is correct
    try {
      sfsbContainerTransactionRuntime.insertCorrectFirstErrorSecond(DATABASE_1, DATABASE_2);
    } catch (Exception e) {
      assertTrue(
          ExceptionHelper.isEquals(e, expectedException),
          "The container did not throw the correct exception, the expected exception is "
              + expectedException.getName()
              + ", but the container threw "
              + e.getClass().getName());
    }
    // tries to commit
    try {
      utx.commit();
      if (!canCommit) {
        fail("The transaction was marked as rolled back, the client cannot make the commit.");
      }
    } catch (Exception e) {
      logger.debug("The bean threw an expected error during the execution {0}", e);
    }
    // verifies if the bean was discarded
    assertTrue(
        ExceptionHandleUtil.isDiscarded(sfsbContainerTransactionRuntime),
        "There was a runtime exception and the container did not discarded the bean.");
    // verifies if the transaction was rolled back
    if (!canCommit) {
      try {
        // verifies if the table was created in the DATABASE_1
        ExceptionHandleUtil.verifyTable(DATABASE_1, ItfContainerTransaction.TABLE);
        fail("There was an error during the commit and the transaction was not rolled back.");
      } catch (SQLException e) {
        logger.debug("The bean threw an expected error during the execution {0}", e);
      }
    }

    // TODO - verifies if the container log the error.

  }
예제 #3
0
 /**
  * Verifies if the container re-throws the application exception that extends a runtime exception
  * (with rollback = true) and marks the transaction for rollback in this case. This test uses a
  * client transaction.
  *
  * @param canCommit says if the bean is able to commit the client transaction. The client is able
  *     to commit when the bean does not use the client transaction.
  * @throws Exception if an error during the tests occurs.
  */
 public void testUsingClientTransWithAppRuntimeRollbackException(final boolean canCommit)
     throws Exception {
   UserTransaction utx = ExceptionHandleUtil.getUserTransaction();
   utx.begin();
   try {
     sfsbContainerTransactionApp02.insertCorrectFirstErrorSecond(DATABASE_1, DATABASE_2);
     fail("The container did not re-throw the application exception.");
   } catch (RollbackAppRuntimeException e) {
     logger.debug("The bean threw an expected error during the execution {0}", e);
   }
   // tries to commit
   try {
     utx.commit();
     if (!canCommit) {
       fail("The transaction was marked as rolled back, the client cannot make the commit.");
     }
   } catch (Exception e) {
     logger.debug("The bean threw an expected error during the execution {0}", e);
   }
   // verifies if the table was created in the DATABASE_1
   ExceptionHandleUtil.verifyTable(DATABASE_1, ItfContainerTransaction.TABLE);
 }