Esempio n. 1
0
 /**
  * Tests if an auction is started an Ended, if i get a successRatio 0 and an AverageTime of 50ms
  */
 @Test
 public void testAuctionStartedEndedNoBid() {
   Date d = new Date();
   AuctionStarted as = new AuctionStarted("Auction1", "AUCTION_STARTED", d.getTime(), 1);
   dummyAs.processEvent(as);
   try {
     Thread.sleep(400);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   AuctionEnded ae = new AuctionEnded("Auction2", "AUCTION_ENDED", d.getTime() + 50, 1);
   dummyAs.processEvent(ae);
   // Wait for processing
   try {
     Thread.sleep(400);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   // Tests the Events
   ArrayList<Event> al = ci.getEvents();
   Iterator<Event> it = al.iterator();
   // AuctionStart
   assertEquals("AUCTION_STARTED", it.next().getType());
   assertEquals("AUCTION_ENDED", it.next().getType());
   // AuctionTime Average should be 50
   AuctionTimeAvg atavg = (AuctionTimeAvg) it.next();
   assertEquals(atavg.getValue(), 50, 0);
   // AuctionSuccessRatio should be 0
   AuctionSuccessRatio asuc = (AuctionSuccessRatio) it.next();
   assertEquals(asuc.getValue(), 0, 0);
 }
Esempio n. 2
0
 /** Test if the auctionSuccessFullRatio will be 1, if there is a bid placed on it */
 @Test
 public void testBidOnAuctionChangesRatio() {
   Date d = new Date();
   AuctionStarted as = new AuctionStarted("Auction1", "AUCTION_STARTED", d.getTime(), 1);
   dummyAs.processEvent(as);
   BidPlaced bp = new BidPlaced("AuctionBid1", "BID_PLACED", d.getTime(), "Daniel", 1, 100);
   dummyAs.processEvent(bp);
   try {
     Thread.sleep(200);
   } catch (InterruptedException e1) {
     e1.printStackTrace();
   }
   AuctionEnded ae = new AuctionEnded("Auction2", "AUCTION_ENDED", d.getTime() + 50, 1);
   dummyAs.processEvent(ae);
   // Wait for processing
   try {
     Thread.sleep(1000);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   // Tests the Events
   ArrayList<Event> al = ci.getEvents();
   Iterator<Event> it = al.iterator();
   // AuctionStart
   assertEquals("AUCTION_STARTED", it.next().getType());
   // First Event should be BidPlaced
   assertEquals("BID_PLACED", it.next().getType());
   // NExt event is new BidPriceMax -> 100
   BidPriceMax bpmax = (BidPriceMax) it.next();
   assertEquals(bpmax.getValue(), 100, 0);
   assertEquals("AUCTION_ENDED", it.next().getType());
   // AuctionTime Average should be 50
   AuctionTimeAvg atavg = (AuctionTimeAvg) it.next();
   assertEquals(atavg.getValue(), 50, 0);
   // AuctionSuccessRatio should be 1
   AuctionSuccessRatio asuc = (AuctionSuccessRatio) it.next();
   assertEquals(asuc.getValue(), 1, 0);
 }