@Test public void testUpdate() { Flight f = flightDao.read(1); int ticketAmount = 20; f.setTicketAmount(ticketAmount); flightDao.getEntityManager().getTransaction().begin(); flightDao.update(f); flightDao.getEntityManager().getTransaction().commit(); Flight fReaded = flightDao.read(1); assertTrue(f.getId() == fReaded.getId()); assertTrue(f.getDateCreated().equals(fReaded.getDateCreated())); assertTrue(f.getFlightNumber().equals(fReaded.getFlightNumber())); assertTrue(f.getDeparture().equals(fReaded.getDeparture())); assertTrue(f.getArrival().equals(fReaded.getArrival())); assertTrue(f.getDateDeparture().equals(fReaded.getDateDeparture())); assertTrue(f.getDateArrival().equals(fReaded.getDateArrival())); assertTrue(ticketAmount == fReaded.getTicketAmount()); assertTrue(f.getTicketPrice() == fReaded.getTicketPrice()); ticketAmount = 10; f.setTicketAmount(ticketAmount); flightDao.getEntityManager().getTransaction().begin(); flightDao.update(f); flightDao.getEntityManager().getTransaction().commit(); }
@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(); }
@AfterClass public static void tearDown() throws Exception { flightDao.getEntityManager().close(); }