Ejemplo n.º 1
0
  @Test
  public void testCreate() {
    Flight f = new Flight();

    GregorianCalendar gcCreated = new GregorianCalendar(2013, Calendar.DECEMBER, 22, 9, 44, 0);
    Timestamp dtCreated = new java.sql.Timestamp(gcCreated.getTime().getTime());

    String flightNumber = "PF-143";

    String departure = "Kyiv";

    String arrival = "London";

    GregorianCalendar gcDeparture = new GregorianCalendar(2013, Calendar.DECEMBER, 25, 10, 50, 0);
    Timestamp dtDeparture = new java.sql.Timestamp(gcDeparture.getTime().getTime());

    GregorianCalendar gcArrival = new GregorianCalendar(2013, Calendar.DECEMBER, 25, 12, 5, 0);
    Timestamp dtArrival = new java.sql.Timestamp(gcArrival.getTime().getTime());

    int ticketAmount = 3;

    double ticketPrice = 3000;
    f.setDateCreated(dtCreated);
    f.setFlightNumber(flightNumber);
    f.setDeparture(departure);
    f.setArrival(arrival);
    f.setDateDeparture(dtDeparture);
    f.setDateArrival(dtArrival);
    f.setTicketAmount(ticketAmount);
    f.setTicketPrice(ticketPrice);

    flightDao.getEntityManager().getTransaction().begin();
    flightDao.create(f);
    flightDao.getEntityManager().getTransaction().commit();

    int id = f.getId();
    Flight fReaded = flightDao.read(id);
    assertTrue(id == fReaded.getId());
    assertTrue(flightNumber.equals(fReaded.getFlightNumber()));
    assertTrue(departure.equals(fReaded.getDeparture()));
    assertTrue(arrival.equals(fReaded.getArrival()));
    assertTrue(dtDeparture.equals(fReaded.getDateDeparture()));
    assertTrue(dtArrival.equals(fReaded.getDateArrival()));
    assertTrue(ticketAmount == fReaded.getTicketAmount());
    assertTrue(ticketPrice == fReaded.getTicketPrice());

    flightDao.getEntityManager().getTransaction().begin();
    flightDao.delete(id);
    flightDao.getEntityManager().getTransaction().commit();
  }