FileDocCategorySizeDatePackage
TransactionTemplateTest.javaAPI DocExample1929Mon Apr 25 09:06:36 BST 2005None

TransactionTemplateTest

public class TransactionTemplateTest extends TestCase

Fields Summary
private org.springframework.context.ApplicationContext
ctx
com.springbook.RentABike
store
Constructors Summary
Methods Summary
public voidsetUp()


          
         ctx = new FileSystemXmlApplicationContext("/war/WEB-INF/rentaBikeApp-servlet.xml");
         store = (RentABike)ctx.getBean("rentaBike");
     
public voidtestTx()

         Reservation oldres = new Reservation(1234, store.getBike(1), store.getCustomer(1), new Date());
         Reservation newres = new Reservation(-1, store.getBike(1), store.getCustomer(2), new Date());
         int rescount = store.getReservations().size();
         try {
             store.transferReservation(oldres, newres);
         } catch (ReservationTransferException rte) {
             System.out.println("RTE caught.");
         } catch (Exception ex) {
             System.out.println("Just an exception.");
         }

         assertEquals(rescount, store.getReservations().size());
     
public voidtestTxSucceed()

        Reservation oldres = store.getReservation(1);
        Reservation newres = new Reservation(-1, store.getBike(1), store.getCustomer(2), new Date());
        int rescount = store.getReservations().size();
        try {
           store.transferReservation(oldres, newres);
        } catch (ReservationTransferException rte) {
           fail("Should not have thrown an RTE, but did.");
        } catch (Exception ex) {
           fail("Threw an unexpected exception: " + ex.getMessage());
        }

        assertEquals(rescount, store.getReservations().size());