1 package org.hibernate.ce.auction.test; 2 3 import junit.framework.*; 4 import junit.textui.TestRunner; 5 import org.hibernate.ce.auction.dao.*; 6 import org.hibernate.ce.auction.exceptions.*; 7 import org.hibernate.ce.auction.model.*; 8 import org.hibernate.ce.auction.persistence.HibernateUtil; 9 10 import java.math.BigDecimal ; 11 import java.util.*; 12 13 public class ItemTest extends TestCaseWithData { 14 15 17 public void testItemData() throws Exception { 18 initData(); 19 20 ItemDAO itemDAO = new ItemDAO(); 21 22 Item a1 = itemDAO.getItemById(auctionOne.getId(), false); 23 assertEquals(a1.getInitialPrice(), 24 new MonetaryAmount(new BigDecimal ("1.99"), Currency.getInstance(Locale.US))); 25 26 HibernateUtil.commitTransaction(); 27 HibernateUtil.closeSession(); 28 } 29 30 32 public void testPlaceBid() throws Exception { 33 initData(); 34 35 37 ItemDAO itemDAO = new ItemDAO(); 38 UserDAO userDAO = new UserDAO(); 39 40 Bid currentMaxBid = itemDAO.getMaxBid(auctionTwo.getId()); 41 Bid currentMinBid = itemDAO.getMinBid(auctionTwo.getId()); 42 Item a2 = itemDAO.getItemById(auctionTwo.getId(), true); 43 44 try { 46 BigDecimal bidAmount = new BigDecimal ("99.99"); 47 MonetaryAmount newAmount = new MonetaryAmount(bidAmount, Currency.getInstance("USD")); 48 a2.placeBid(userDAO.getUserById(u3.getId(), false), 49 newAmount, 50 currentMaxBid, 51 currentMinBid); 52 } catch (BusinessException success) {} 53 54 try { 56 a2.approve(u3); 57 } catch (PermissionException success) {} 58 59 a2.setPendingForApproval(); 61 a2.approve(u1); 62 63 try { 65 BigDecimal bidAmount = new BigDecimal ("100.00"); 66 MonetaryAmount newAmount = new MonetaryAmount(bidAmount, Currency.getInstance("USD")); 67 a2.placeBid(userDAO.getUserById(u3.getId(), false), 68 newAmount, 69 currentMaxBid, 70 currentMinBid); 71 72 } catch (BusinessException failure) { 73 throw failure; 74 } 75 76 try { 78 BigDecimal bidAmount = new BigDecimal ("99.99"); 79 MonetaryAmount newAmount = new MonetaryAmount(bidAmount, Currency.getInstance("USD")); 80 a2.placeBid(userDAO.getUserById(u3.getId(), false), 81 newAmount, 82 currentMaxBid, 83 currentMinBid); 84 } catch (BusinessException success) {} 85 86 88 HibernateUtil.commitTransaction(); 89 HibernateUtil.closeSession(); 90 91 } 92 93 95 public ItemTest(String x) { 96 super(x); 97 } 98 99 public static Test suite() { 100 return new TestSuite(ItemTest.class); 101 } 102 103 public static void main(String [] args) throws Exception { 104 TestRunner.run( suite() ); 105 } 106 107 } 108 | Popular Tags |