From c8bf52aa53243c419e24b623cf1c5b2ce2650fbe Mon Sep 17 00:00:00 2001 From: pamcdm Date: Thu, 2 Jan 2014 13:48:40 -0200 Subject: [PATCH] #950 - Add unit tests to verify time slosts are sorted by start date --- .../api/AppointmentServiceTest.java | 64 ++++++++++++++----- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/api/src/test/java/org/openmrs/module/appointmentscheduling/api/AppointmentServiceTest.java b/api/src/test/java/org/openmrs/module/appointmentscheduling/api/AppointmentServiceTest.java index c4e0b550..18aecf98 100644 --- a/api/src/test/java/org/openmrs/module/appointmentscheduling/api/AppointmentServiceTest.java +++ b/api/src/test/java/org/openmrs/module/appointmentscheduling/api/AppointmentServiceTest.java @@ -13,21 +13,9 @@ */ package org.openmrs.module.appointmentscheduling.api; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertTrue; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - import junit.framework.Assert; - import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.openmrs.Location; import org.openmrs.Patient; @@ -36,13 +24,20 @@ import org.openmrs.api.APIException; import org.openmrs.api.context.Context; import org.openmrs.module.appointmentscheduling.Appointment; +import org.openmrs.module.appointmentscheduling.Appointment.AppointmentStatus; import org.openmrs.module.appointmentscheduling.AppointmentType; import org.openmrs.module.appointmentscheduling.TimeSlot; -import org.openmrs.module.appointmentscheduling.Appointment.AppointmentStatus; -import org.openmrs.module.appointmentscheduling.api.AppointmentService; import org.openmrs.test.BaseModuleContextSensitiveTest; import org.openmrs.test.Verifies; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; + +import static junit.framework.Assert.*; + /** * Tests Appointment methods in the {@link $ AppointmentService} . */ @@ -394,5 +389,42 @@ public void shouldChangeCorrectAppointments_cleanOpenAppointments() { assertTrue(appointment.getStatus().equals(AppointmentStatus.MISSED)); } - + + + @Ignore + @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 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)); + } + + @Ignore + @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 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(2)); + } + }