Clover coverage report -
Coverage timestamp: Thu Jun 22 2006 14:24:50 CEST
file stats: LOC: 206   Methods: 8
NCLOC: 79   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TestTransactionCommitSLSB.java 50% 81% 100% 83.9%
coverage coverage
 1    /**
 2    * EasyBeans
 3    * Copyright (C) 2006 Bull S.A.S.
 4    * Contact: easybeans@objectweb.org
 5    *
 6    * This library is free software; you can redistribute it and/or
 7    * modify it under the terms of the GNU Lesser General Public
 8    * License as published by the Free Software Foundation; either
 9    * version 2.1 of the License, or any later version.
 10    *
 11    * This library is distributed in the hope that it will be useful,
 12    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 14    * Lesser General Public License for more details.
 15    *
 16    * You should have received a copy of the GNU Lesser General Public
 17    * License along with this library; if not, write to the Free Software
 18    * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 19    * USA
 20    *
 21    * --------------------------------------------------------------------------
 22    * $Id: TestTransactionCommitSLSB.java 364 2006-04-20 11:41:05Z pinheirg $
 23    * --------------------------------------------------------------------------
 24    */
 25    package org.objectweb.easybeans.tests.transaction.beanmanaged;
 26   
 27    import static org.testng.Assert.fail;
 28   
 29    import java.sql.SQLException;
 30   
 31    import javax.naming.NamingException;
 32   
 33    import org.objectweb.easybeans.log.JLog;
 34    import org.objectweb.easybeans.log.JLogFactory;
 35    import org.objectweb.easybeans.tests.common.ejbs.base.ItfBeanManagedTransaction;
 36    import org.objectweb.easybeans.tests.common.ejbs.stateless.beanmanaged.SLSBBeanManagedTransaction;
 37    import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.ItfDatabaseManager;
 38    import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.SLSBDatabaseManager;
 39    import org.objectweb.easybeans.tests.common.helper.EJBHelper;
 40    import org.objectweb.easybeans.tests.common.helper.EmbeddedHelper;
 41    import org.testng.annotations.Configuration;
 42    import org.testng.annotations.ExpectedExceptions;
 43    import org.testng.annotations.Test;
 44   
 45    /**
 46    * Verifies if the container manages correctly the beand-managed transaction for
 47    * stateless bean.
 48    * @reference JSR220-PROPOSED FINAL
 49    * @requirement Application Server must be running; the bean
 50    * org.objectweb.easybeans.tests.common.ejbs.stateless.beanmanaged.SLSBBeanManagedTransaction
 51    * must be deployed.
 52    * @setup gets the reference of SLSBBeanManagedTransaction and binds the
 53    * databases specified in the EmbeddedTest.
 54    * @author Gisele Pinheiro Souza
 55    * @author Eduardo Studzinski Estima de Castro
 56    */
 57    public class TestTransactionCommitSLSB {
 58   
 59    /**
 60    * Bean used during the tests.
 61    */
 62    private ItfBeanManagedTransaction slsbBeanManagedTransaction;
 63   
 64    /**
 65    * Bean used to manage the database in the server side.
 66    */
 67    private ItfDatabaseManager slsbDatabaseManager;
 68   
 69    /**
 70    * Logger.
 71    */
 72    private static JLog logger = JLogFactory.getLog(TestTransactionCommitSLSB.class);
 73   
 74    /**
 75    * The database used during the tests.
 76    */
 77    private static final String DATABASE = "jdbc_1";
 78   
 79    /**
 80    * Publishes the databases.
 81    * @throws Exception if an error during the test startup occurs.
 82    */
 83  2 @Configuration(beforeTestClass = true)
 84    public void setup() throws Exception {
 85    // Inserts all database before execute the test
 86    // used because the container does not provide this feature yet
 87    // Is defined in each test to allows run each test separately.
 88  2 EmbeddedHelper.bindDatasource();
 89    // creates the bean used to manages the databse in the server site.
 90  2 slsbDatabaseManager = EJBHelper.getBeanRemoteInstance(SLSBDatabaseManager.class, ItfDatabaseManager.class);
 91    }
 92   
 93    /**
 94    * Tests if the container supports the bean does not close the transaction
 95    * in the same method that the transaction was opened. The container must
 96    * to: <ul> <li>Makes a log to alert the system administrator.</li> <li>Rollbacks
 97    * the transaction.</li> <li>Discard the session bean instance</li> <li>Throws
 98    * the javax.ejb.EJBException if using EJB3 client</li> </ul>
 99    * @input -
 100    * @output all actions listed above.
 101    * @throws Exception if an error during the test occurs.
 102    */
 103  1 @Test
 104    public void testBeginWithoutCommit() throws Exception {
 105  1 try {
 106    // inserts a table without making the commit.
 107  1 slsbBeanManagedTransaction.insertTableWithoutCommit(ItfBeanManagedTransaction.CREATE_TABLE, DATABASE);
 108  0 fail("The container must to throw the javax.ejb.EJBException, if the stateless bean does not make the commit. "
 109    + "However the container did not throw any exception.");
 110    } catch (Exception e) {
 111  1 if (!(e instanceof javax.ejb.EJBException)) {
 112  0 fail("The container must to throw the javax.ejb.EJBException, if the stateless bean does not makes the commit. "
 113    + "However the container did not throw the correct exception.");
 114    }
 115    }
 116    // verifies if the container makes the roll back
 117  1 try {
 118  1 slsbDatabaseManager.verifyTable(DATABASE, ItfBeanManagedTransaction.TABLE);
 119  0 fail("The container must to make the rollback, if the stateless bean does not make the commit.");
 120    } catch (SQLException e) {
 121  1 logger.debug("the container made the rollback {0}", e);
 122    }
 123    //TODO - verifies if the container discard the bean
 124   
 125    // test if the application log the error
 126    // TODO - verify how easybeans makes the log
 127    }
 128   
 129    /**
 130    * Calls userTransaction.begin(), inserts the table and calls userTransaction.commit().
 131    * @input -
 132    * @output the table created.
 133    * @throws Exception if an error during the tests occurs.
 134    */
 135  1 @Test
 136    public void testTransInSameMethod() throws Exception {
 137  1 slsbBeanManagedTransaction.insertTableWithBeginCommit(ItfBeanManagedTransaction.CREATE_TABLE, DATABASE);
 138    // verifies if the table was created
 139  1 slsbDatabaseManager.verifyTable(DATABASE, ItfBeanManagedTransaction.TABLE);
 140    }
 141   
 142    /**
 143    * Tests if the container does not allow the bean to use the setRollbackOnly.
 144    * @input -
 145    * @output an IllegalStateException
 146    * @throws Exception if an error during the tests occurs.
 147    */
 148  1 @Test
 149    @ExpectedExceptions(value = java.lang.IllegalStateException.class)
 150    public void testSetRollbackOnly() throws Exception {
 151    // calls the setRollbackOnly that must to throw exception
 152  1 slsbBeanManagedTransaction.setRollbackOnly();
 153    }
 154   
 155    /**
 156    * Tests if the container does not allow the bean to use the getRollbackOnly.
 157    * @input -
 158    * @output an IllegalStateException
 159    * @throws Exception if a erro during the tests occurs.
 160    */
 161  1 @Test
 162    @ExpectedExceptions(value = java.lang.IllegalStateException.class)
 163    public void testGetRollbackOnly() throws Exception {
 164    // calls the setRollbackOnly that must to throw exception
 165  1 slsbBeanManagedTransaction.getRollbackOnly();
 166    }
 167   
 168    /**
 169    * Deletes the databases entries from the registry.
 170    * @throws Exception if an error occurs during the unbind.
 171    */
 172  1 @Configuration(afterTestClass = true)
 173    public void tierDown() throws Exception {
 174    // Remove all database after execute the test
 175    // used because the container does not provide this feature yet.
 176  1 EmbeddedHelper.unbindDatasource();
 177    }
 178   
 179    /**
 180    * Deletes the table to avoid errors in each test.
 181    */
 182  4 @Configuration(beforeTestMethod = true)
 183    public void deletesTable() {
 184    // deletes the table after each test to avoid errors.
 185  4 try {
 186  4 slsbDatabaseManager.deleteTable(DATABASE, ItfBeanManagedTransaction.TABLE);
 187    } catch (SQLException e) {
 188  1 logger.debug("The table delete threw an error during the execution {0}", e);
 189    } catch (NamingException e) {
 190  0 logger.debug("The table delete threw an error during the execution {0}", e);
 191    }
 192    }
 193   
 194    /**
 195    * Creates the bean before each test, because there are test that discard
 196    * the bean.
 197    * @throws Exception if an error during the bea lookup occurs.
 198    */
 199  4 @Configuration(beforeTestMethod = true)
 200    public void createBean() throws Exception {
 201    // creates the bean
 202  4 slsbBeanManagedTransaction = EJBHelper.getBeanRemoteInstance(SLSBBeanManagedTransaction.class,
 203    ItfBeanManagedTransaction.class);
 204    }
 205   
 206    }