/** * Tests to place a bid because 1 bid is placed in one minute. Thread has to wait one Minute. Also * the highest bid shall be updated to 100 */ @Test public void testPlaceBidAndBPM() { try { Thread.sleep(500); } catch (InterruptedException e1) { e1.printStackTrace(); } Date d = new Date(); AuctionStarted as = new AuctionStarted("Auction1", "AUCTION_STARTED", d.getTime(), 1); dummyAs.processEvent(as); BidPlaced bp = new BidPlaced("Bid1", "BID_PLACED", d.getTime(), "User1", 1, 100); dummyAs.processEvent(bp); try { Thread.sleep(60000); } catch (InterruptedException e) { e.printStackTrace(); } // Tests the Events ArrayList<Event> al = ci.getEvents(); Iterator<Event> it = al.iterator(); it.next(); // Skip Auction Started // Next 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); // NextEvent is BidCount perMinute BidCountPerMinute bpm = (BidCountPerMinute) it.next(); assertEquals(bpm.getValue(), 1, 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); }