Ejemplo n.º 1
0
  @Test(expected = SeatNotAvailable.class)
  public void test_seat_not_available_exception()
      throws FlightCapacityExceededException, SeatNotAvailable, UnknownAirTicketException {
    // given
    Timestamp date = Timestamp.valueOf("2012-12-20 16:00:00");
    Flight flight1 = new Flight(date, 200, "praha", "london", 300);
    genericDao.save(flight1);
    AirTicket airTicket1 = bookingService.bookFlight(flight1.getId());

    // when
    bookingService.changeSeat(airTicket1.getId(), airTicket1.getSeatNumber());
  }
Ejemplo n.º 2
0
  @Test
  public void test_book_flight() throws FlightCapacityExceededException {
    // given
    Timestamp date = Timestamp.valueOf("2012-12-20 16:00:00");

    Flight flight1 = new Flight(date, 200, "praha", "london", 300);

    genericDao.save(flight1);

    // when
    AirTicket airTicket1 = bookingService.bookFlight(flight1.getId());
    Flight retrieved = airTicket1.getFlight();

    // then
    assertEquals(flight1, retrieved);
    assertEquals(299, retrieved.getCapacity());
  }
Ejemplo n.º 3
0
  @Test
  public void test_cancell_flight()
      throws FlightCapacityExceededException, UnknownAirTicketException {
    // given
    Timestamp date = Timestamp.valueOf("2012-12-20 16:00:00");
    Flight flight1 = new Flight(date, 200, "praha", "london", 300);
    genericDao.save(flight1);
    int fullCapacity = flight1.getCapacity();
    AirTicket airTicket1 = bookingService.bookFlight(flight1.getId());
    int afterCapacity1 = flight1.getCapacity();
    assertEquals(fullCapacity, afterCapacity1 + 1);

    // when
    bookingService.cancelFlight(airTicket1.getId());
    int afterCapacity2 = flight1.getCapacity();

    // then
    assertEquals(fullCapacity, afterCapacity2);
    assertTrue(
        "Flight's airtickets should be empty after deleting the airticket",
        flight1.getAirTickets().isEmpty());
  }
Ejemplo n.º 4
0
  @Test
  public void test_change_ticket()
      throws FlightCapacityExceededException, SeatNotAvailable, UnknownAirTicketException {
    // given
    Timestamp date = Timestamp.valueOf("2012-12-20 16:00:00");
    Flight flight1 = new Flight(date, 200, "praha", "london", 300);
    genericDao.save(flight1);
    int initialCapacity = flight1.getCapacity();
    AirTicket airTicket1 = bookingService.bookFlight(flight1.getId());
    Random r = new Random();
    int seatNumber = r.nextInt(flight1.getCapacity());
    while (seatNumber == airTicket1.getSeatNumber()) {
      seatNumber = r.nextInt(flight1.getCapacity());
    }
    // when
    AirTicket retrieved = bookingService.changeSeat(airTicket1.getId(), seatNumber);

    // then
    System.out.println(">>>" + retrieved.getSeatNumber() + " " + airTicket1.getSeatNumber());
    assertNotSame(retrieved.getSeatNumber(), airTicket1.getSeatNumber());
    assertEquals(airTicket1.getFlight(), retrieved.getFlight());
    assertEquals(flight1.getCapacity() + 1, initialCapacity);
  }