Skip to content

Commit

Permalink
UHM-974 Fix unit tests and move then to TimeSlotServiceTest
Browse files Browse the repository at this point in the history
  • Loading branch information
pamcdm committed Jan 7, 2014
1 parent 13e796f commit fa43351
Show file tree
Hide file tree
Showing 3 changed files with 433 additions and 431 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,24 @@ else if (fromDate != null && toDate != null && !fromDate.before(toDate))
Date startDate = (fromDate == null) ? new Date() : fromDate;

String stringQuery = "SELECT timeSlot FROM TimeSlot AS timeSlot WHERE timeSlot.appointmentBlock IN("
+ " FROM AppointmentBlock WHERE :appointmentType IN elements(types)) AND voided = 0 AND endDate > :startDate ORDER BY startDate";
+ " FROM AppointmentBlock WHERE :appointmentType IN elements(types)) AND voided = 0 AND endDate > :startDate";

if (toDate != null)
stringQuery += " AND endDate <= :endDate";
if (provider != null)
stringQuery += " AND timeSlot.appointmentBlock.provider = :provider";

stringQuery += " ORDER BY startDate";

Query query = super.sessionFactory.getCurrentSession().createQuery(stringQuery)
.setParameter("appointmentType", appointmentType).setParameter("startDate", startDate);

if (toDate != null)
query.setParameter("endDate", toDate);
if (provider != null)
query.setParameter("provider", provider);

return query.list();
return query.list();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,38 +390,4 @@ public void shouldChangeCorrectAppointments_cleanOpenAppointments() {

}

@Test
public void shouldGetAllTimeSlotsByConstraintsSortedByStartDate() throws ParseException {
AppointmentType type = service.getAppointmentType(1);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date fromDate = format.parse("2005-01-01 00:00:00.0");

List<TimeSlot> result = service.getTimeSlotsByConstraintsIncludingFull(type, fromDate, null, null, null);
assertNotNull(result);
assertTrue(result.size() == 6);

TimeSlot firstTimeSlot = result.get(0);
assertTrue(firstTimeSlot.getTimeSlotId().equals(5));

TimeSlot lastTimeSlot = result.get(result.size() - 1);
assertTrue(lastTimeSlot.getTimeSlotId().equals(4));
}

@Test
public void shouldGetOnlyAvailableTimeSlotsByConstraintsSortedByStartDate() throws ParseException {
AppointmentType type = service.getAppointmentType(1);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date fromDate = format.parse("2005-01-01 00:00:00.0");

List<TimeSlot> result = service.getTimeSlotsByConstraints(type, fromDate, null, null, null);
assertNotNull(result);
assertTrue(result.size() == 4);

TimeSlot firstTimeSlot = result.get(0);
assertTrue(firstTimeSlot.getTimeSlotId().equals(5));

TimeSlot lastTimeSlot = result.get(result.size() - 1);
assertTrue(lastTimeSlot.getTimeSlotId().equals(4));
}

}
Loading

0 comments on commit fa43351

Please sign in to comment.