@Test public void testInsert() { Booking b = new Booking(); b.setApartment(apartment); b.setCustomer(customer); b = repository.save(b); assertEquals(b, repository.findOne(b.getId())); }
@Test public void number_of_booking_during_time_period_returns_1_if_queried_with_end_date_in_the_middle_of_an_existing_booking() { LocalDate booking_from = LocalDate.of(2015, 7, 1); LocalDate booking_to = LocalDate.of(2015, 7, 18); LocalDate query_from = LocalDate.of(2015, 6, 12); LocalDate query_to = LocalDate.of(2015, 7, 12); Date from_date = Date.from(booking_from.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()); Date to_date = Date.from(booking_to.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()); Booking booking1 = Booking.builder() .apartment(apartment) .customer(customer) .startDate(from_date) .endDate(to_date) .build(); repository.save(booking1); Date query_from_date = Date.from(query_from.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()); Date query_to_date = Date.from(query_to.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()); assertThat( repository.findNumberOfBookingDuringTimePeriod(apartment, query_from_date, query_to_date), is(1)); }