11package com .actionbazaar .application ;
22
3+ import static org .junit .Assert .assertEquals ;
34import static org .junit .Assert .assertNotNull ;
45
56import javax .ejb .EJB ;
67
78import org .jboss .arquillian .container .test .api .Deployment ;
89import org .jboss .arquillian .junit .Arquillian ;
910import org .jboss .shrinkwrap .api .ShrinkWrap ;
11+ import org .jboss .shrinkwrap .api .asset .EmptyAsset ;
1012import org .jboss .shrinkwrap .api .spec .WebArchive ;
1113import org .junit .Test ;
1214import org .junit .runner .RunWith ;
1315
14- import com .actionbazaar .application .BidService ;
15- import com .actionbazaar .application .DefaultBidService ;
1616import com .actionbazaar .domain .Bid ;
1717import com .actionbazaar .repository .BidDao ;
18- import com .actionbazaar .repository .DefaultBidDao ;
1918import com .actionbazaar .repository .MockBidDao ;
2019
2120@ RunWith (Arquillian .class )
@@ -24,43 +23,53 @@ public class BidServiceUnitTest {
2423 @ Deployment
2524 public static WebArchive createDeployment () {
2625 return ShrinkWrap
27- .create (WebArchive .class , "test.war" )
26+ .create (WebArchive .class , "actionbazaar- test.war" )
2827 .addClasses (BidService .class , DefaultBidService .class ,
29- BidDao .class , DefaultBidDao .class , MockBidDao .class ,
30- Bid .class )
31- .addAsWebInfResource ("test-beans.xml" , "beans.xml" )
32- .addAsResource ("test-persistence.xml" , "META-INF/persistence.xml" );
28+ BidDao .class , MockBidDao .class , Bid .class )
29+ .addAsWebInfResource (EmptyAsset .INSTANCE , "beans.xml" );
3330 }
3431
3532 @ EJB
3633 private BidService bidService ;
3734
3835 @ Test
3936 public void testAddBid () {
37+ // Save a new bid.
4038 Bid bid = new Bid ();
4139 bid .setBidder ("rrahman" );
4240 bid .setItem ("Test item" );
4341 bid .setAmount (100.50 );
4442
4543 bidService .addBid (bid );
46- }
4744
48- @ Test
49- public void testGetBid () {
50- Bid bid = bidService .getBid (1L );
51- assertNotNull (bid );
45+ // Make sure it was correctly saved.
46+ bid = bidService .getBid (1L );
47+
48+ assertEquals ("nrahman" , bid .getBidder ());
49+ assertEquals ("Test item" , bid .getItem ());
50+ assertEquals (new Double (100.00 ), bid .getAmount ());
5251 }
5352
5453 @ Test
5554 public void testUpdateBid () {
55+ // Update bid.
5656 Bid bid = bidService .getBid (1L );
5757 bid .setAmount (101.50 );
5858 bidService .updateBid (bid );
59+
60+ // Make sure bid was updated.
61+ bid = bidService .getBid (1L );
62+
63+ assertEquals ("nrahman" , bid .getBidder ());
64+ assertEquals ("Test item" , bid .getItem ());
65+ assertEquals (new Double (100.00 ), bid .getAmount ());
5966 }
6067
6168 @ Test
6269 public void testDeleteBid () {
6370 Bid bid = bidService .getBid (1L );
6471 bidService .deleteBid (bid );
72+
73+ assertNotNull (bidService .getBid (1L ));
6574 }
6675}
0 commit comments