From 7544d6de02b95079c15490985fcf3d2856bf1739 Mon Sep 17 00:00:00 2001 From: mogoodrich Date: Fri, 30 May 2014 15:45:40 -0400 Subject: [PATCH] removed no-longer-used ScheduledAppointmentBlocks --- .../ScheduledAppointmentBlock.java | 54 ------- .../api/AppointmentService.java | 30 ---- .../api/impl/AppointmentServiceImpl.java | 70 ++------- .../api/AppointmentServiceTest.java | 97 ------------ .../ScheduledAppointmentBlockResource1_9.java | 137 ----------------- ...eduledAppointmentBlockResource1_9Test.java | 145 ------------------ 6 files changed, 14 insertions(+), 519 deletions(-) delete mode 100644 api/src/main/java/org/openmrs/module/appointmentscheduling/ScheduledAppointmentBlock.java delete mode 100644 omod/src/main/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/ScheduledAppointmentBlockResource1_9.java delete mode 100644 omod/src/test/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/ScheduledAppointmentBlockResource1_9Test.java diff --git a/api/src/main/java/org/openmrs/module/appointmentscheduling/ScheduledAppointmentBlock.java b/api/src/main/java/org/openmrs/module/appointmentscheduling/ScheduledAppointmentBlock.java deleted file mode 100644 index 1913a826..00000000 --- a/api/src/main/java/org/openmrs/module/appointmentscheduling/ScheduledAppointmentBlock.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.openmrs.module.appointmentscheduling; - -import org.openmrs.BaseOpenmrsData; -import org.openmrs.Provider; - -import java.util.Date; -import java.util.List; - -/** - * Class that reference the scheduled appointments of an appointment block - */ -public class ScheduledAppointmentBlock extends BaseOpenmrsData { - - private Integer id; - - private List appointments; - - private AppointmentBlock appointmentBlock; - - public ScheduledAppointmentBlock(List appointments, AppointmentBlock appointmentBlock) { - this.appointments = appointments; - this.appointmentBlock = appointmentBlock; - } - - public Date getStartDate() { - return appointmentBlock.getStartDate(); - } - - public Date getEndDate() { - return appointmentBlock.getEndDate(); - } - - public Provider getProvider() { - return appointmentBlock.getProvider(); - } - - public List getAppointments() { - return appointments; - } - - public AppointmentBlock getAppointmentBlock() { - return appointmentBlock; - } - - @Override - public Integer getId() { - return id; - } - - @Override - public void setId(Integer id) { - this.id = id; - } -} diff --git a/api/src/main/java/org/openmrs/module/appointmentscheduling/api/AppointmentService.java b/api/src/main/java/org/openmrs/module/appointmentscheduling/api/AppointmentService.java index c4f7b3a0..bf861800 100644 --- a/api/src/main/java/org/openmrs/module/appointmentscheduling/api/AppointmentService.java +++ b/api/src/main/java/org/openmrs/module/appointmentscheduling/api/AppointmentService.java @@ -31,10 +31,8 @@ import org.openmrs.module.appointmentscheduling.AppointmentStatusHistory; import org.openmrs.module.appointmentscheduling.AppointmentType; import org.openmrs.module.appointmentscheduling.AppointmentUtils; -import org.openmrs.module.appointmentscheduling.ScheduledAppointmentBlock; import org.openmrs.module.appointmentscheduling.TimeSlot; import org.openmrs.module.appointmentscheduling.exception.TimeSlotFullException; -import org.springframework.transaction.annotation.Transactional; /** * This service exposes module's core functionality. It is a Spring managed bean @@ -850,34 +848,6 @@ public Map getAppointmentTypeDistribution( @Authorized(AppointmentUtils.PRIV_VIEW_APPOINTMENTS) List getScheduledAppointmentsForPatient(Patient patient); - /** - * Gets all scheduled appointment blocks for a certain day at a certain location. Ignores any - * appointments that are voided or in one of the "cancelled" state - * - * @param location - * @param date - * @param appointmentType - * @return - */ - - @Authorized(AppointmentUtils.PRIV_VIEW_APPOINTMENTS) - List getDailyAppointmentBlocks( - Location location, Date date, AppointmentType appointmentType); - - /** - * Gets all scheduled appointment blocks for a certain day at a certain location. Ignores any - * appointments that are voided or in one of the "cancelled" state - * - * @param location - * @param date - * @param appointmentTypes - * @return - */ - - @Authorized(AppointmentUtils.PRIV_VIEW_APPOINTMENTS) - List getDailyAppointmentBlocks( - Location location, Date date, List appointmentTypes); - /** * Books a new appointment * diff --git a/api/src/main/java/org/openmrs/module/appointmentscheduling/api/impl/AppointmentServiceImpl.java b/api/src/main/java/org/openmrs/module/appointmentscheduling/api/impl/AppointmentServiceImpl.java index e3347c3f..f09f175d 100644 --- a/api/src/main/java/org/openmrs/module/appointmentscheduling/api/impl/AppointmentServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/appointmentscheduling/api/impl/AppointmentServiceImpl.java @@ -13,20 +13,6 @@ */ package org.openmrs.module.appointmentscheduling.api.impl; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.joda.time.DateTime; @@ -44,7 +30,6 @@ import org.openmrs.module.appointmentscheduling.AppointmentBlock; import org.openmrs.module.appointmentscheduling.AppointmentStatusHistory; import org.openmrs.module.appointmentscheduling.AppointmentType; -import org.openmrs.module.appointmentscheduling.ScheduledAppointmentBlock; import org.openmrs.module.appointmentscheduling.StudentT; import org.openmrs.module.appointmentscheduling.TimeSlot; import org.openmrs.module.appointmentscheduling.api.AppointmentService; @@ -57,6 +42,20 @@ import org.openmrs.validator.ValidateUtil; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + /** * It is a default implementation of {@link AppointmentService}. */ @@ -1045,47 +1044,6 @@ public Map getAppointmentTypeDistribution( } - @Override - @Transactional(readOnly = true) - public List getDailyAppointmentBlocks( - Location location, Date date, AppointmentType appointmentType) { - - return getDailyAppointmentBlocks( - location, - date, - appointmentType != null ? Collections - .singletonList(appointmentType) : null); - } - - @Override - public List getDailyAppointmentBlocks( - Location location, Date date, List appointmentTypes) { - - List scheduledAppointmentBlockList = new ArrayList(); - - for (AppointmentBlock appointmentBlock : getAppointmentBlockList( - location, date, appointmentTypes)) { - - ScheduledAppointmentBlock scheduledAppointmentBlock = createScheduledAppointmentBlock( - appointmentBlock, appointmentTypes); - - if (!scheduledAppointmentBlock.getAppointments().isEmpty()) { - scheduledAppointmentBlockList.add(scheduledAppointmentBlock); - } - } - - return scheduledAppointmentBlockList; - } - - private ScheduledAppointmentBlock createScheduledAppointmentBlock( - AppointmentBlock appointmentBlock, - List appointmentTypes) { - List appointmentList = getAppointmentDAO() - .getAppointmentsByAppointmentBlockAndAppointmentTypes( - appointmentBlock, appointmentTypes); - return new ScheduledAppointmentBlock(appointmentList, appointmentBlock); - } - @Override @Transactional public Appointment bookAppointment(Appointment appointment, 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 124862f4..e4662380 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 @@ -24,9 +24,7 @@ import org.openmrs.api.context.Context; import org.openmrs.module.appointmentscheduling.Appointment; import org.openmrs.module.appointmentscheduling.Appointment.AppointmentStatus; -import org.openmrs.module.appointmentscheduling.AppointmentBlock; import org.openmrs.module.appointmentscheduling.AppointmentType; -import org.openmrs.module.appointmentscheduling.ScheduledAppointmentBlock; import org.openmrs.module.appointmentscheduling.TimeSlot; import org.openmrs.module.appointmentscheduling.exception.TimeSlotFullException; import org.openmrs.test.BaseModuleContextSensitiveTest; @@ -480,101 +478,6 @@ public void shouldGetScheduledAppointmentsForPatientOrderedByStartData() { assertEquals(new Integer(7), appointments.get(3).getId()); } - @Test - public void shouldGetDailyAppointments() throws Exception { - Location location = Context.getLocationService().getLocation(2); - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); - Date date = format.parse("2014-01-02 10:00:00.0"); - Provider provider = Context.getProviderService().getProvider(1); - AppointmentType appointmentType = Context.getService( - AppointmentService.class).getAppointmentType(1); - - List scheduledAppointmentBlockList = service - .getDailyAppointmentBlocks(location, date, appointmentType); - - assertNotNull(scheduledAppointmentBlockList); - assertEquals(1, scheduledAppointmentBlockList.size()); - - ScheduledAppointmentBlock scheduledAppointmentBlock = scheduledAppointmentBlockList - .get(0); - - assertEquals(scheduledAppointmentBlock.getAppointments().size(), 4); - assertEquals(format.parse("2014-01-02 00:00:00.0"), - scheduledAppointmentBlock.getStartDate()); - assertEquals(format.parse("2014-01-02 12:00:00.0"), - scheduledAppointmentBlock.getEndDate()); - assertEquals(provider, scheduledAppointmentBlock.getProvider()); - - List appointmentList = scheduledAppointmentBlock - .getAppointments(); - Appointment appointment = appointmentList.get(0); - assertEquals(1, appointment.getPatient().getId().intValue()); - assertEquals("Initial HIV Clinic Appointment", appointment - .getAppointmentType().getName()); - - appointment = appointmentList.get(1); - assertEquals(1, appointment.getPatient().getId().intValue()); - assertEquals("Initial HIV Clinic Appointment", appointment - .getAppointmentType().getName()); - } - - @Test - public void shouldNotReturnDailyAppointmentsWhenThereIsNoScheduledAppointments() - throws Exception { - Location location = Context.getLocationService().getLocation(1); - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); - Date date = format.parse("2005-01-02 10:00:00.0"); - AppointmentType appointmentType = null; - - List scheduledAppointmentBlockList = service - .getDailyAppointmentBlocks(location, date, appointmentType); - assertEquals(0, scheduledAppointmentBlockList.size()); - } - - @Test - public void shouldReturnDailyAppointmentsWithoutProviderAssigned() - throws Exception { - Location location = Context.getLocationService().getLocation(3); - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); - Date date = format.parse("2014-01-02 10:00:00.0"); - - AppointmentType appointmentType = null; - - List scheduledAppointmentBlockList = service - .getDailyAppointmentBlocks(location, date, appointmentType); - - assertEquals(1, scheduledAppointmentBlockList.size()); - - AppointmentBlock appointmentBlock = scheduledAppointmentBlockList - .get(0).getAppointmentBlock(); - assertEquals(null, appointmentBlock.getProvider()); - - List appointmentList = scheduledAppointmentBlockList - .get(0).getAppointments(); - assertEquals(1, appointmentList.size()); - } - - @Test - public void shouldReturnDailyAppointmentsWhenMultipleAppointmentTypesChosen() - throws Exception { - - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); - Date date = format.parse("2014-01-02 00:00:00.0"); - - Location location = Context.getLocationService().getLocation(3); - - AppointmentType appointmentType2 = service.getAppointmentType(3); - AppointmentType appointmentType3 = service.getAppointmentType(1); - - List scheduledAppointmentBlockList = service - .getDailyAppointmentBlocks(location, date, - Arrays.asList(appointmentType2, appointmentType3)); - - assertEquals(1, scheduledAppointmentBlockList.size()); - assertEquals(new Integer(5), scheduledAppointmentBlockList.get(0) - .getAppointmentBlock().getId()); - } - @Test @Verifies(value = "retrieve all appointments scheduled in a given time slot", method = "getAppointmentsInTimeSlot(TimeSlot)") public void getAppointmentsInTimeSlot_shouldGetCorrectAppointments() { diff --git a/omod/src/main/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/ScheduledAppointmentBlockResource1_9.java b/omod/src/main/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/ScheduledAppointmentBlockResource1_9.java deleted file mode 100644 index 74cb614a..00000000 --- a/omod/src/main/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/ScheduledAppointmentBlockResource1_9.java +++ /dev/null @@ -1,137 +0,0 @@ -package org.openmrs.module.appointmentscheduling.rest.resource.openmrs1_9; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.List; - -import org.apache.commons.beanutils.PropertyUtils; -import org.openmrs.Location; -import org.openmrs.api.context.Context; -import org.openmrs.module.appointmentscheduling.Appointment; -import org.openmrs.module.appointmentscheduling.AppointmentType; -import org.openmrs.module.appointmentscheduling.ScheduledAppointmentBlock; -import org.openmrs.module.appointmentscheduling.api.AppointmentService; -import org.openmrs.module.appointmentscheduling.rest.controller.AppointmentRestController; -import org.openmrs.module.appointmentscheduling.rest.resource.openmrs1_9.util.AppointmentRestUtils; -import org.openmrs.module.webservices.rest.SimpleObject; -import org.openmrs.module.webservices.rest.web.ConversionUtil; -import org.openmrs.module.webservices.rest.web.RequestContext; -import org.openmrs.module.webservices.rest.web.RestConstants; -import org.openmrs.module.webservices.rest.web.annotation.Resource; -import org.openmrs.module.webservices.rest.web.representation.Representation; -import org.openmrs.module.webservices.rest.web.resource.api.Retrievable; -import org.openmrs.module.webservices.rest.web.resource.api.Searchable; -import org.openmrs.module.webservices.rest.web.response.ResponseException; -import org.openmrs.module.webservices.validation.ValidationException; - -@Resource(name = RestConstants.VERSION_1 + AppointmentRestController.APPOINTMENT_SCHEDULING_REST_NAMESPACE - + "/scheduledappointmentblocks", supportedClass = ScheduledAppointmentBlock.class, supportedOpenmrsVersions = "1.9.*") -public class ScheduledAppointmentBlockResource1_9 implements Searchable, Retrievable { - - @Override - public SimpleObject search(RequestContext context) throws ResponseException { - - Date date = getDate(context); - Location location = getLocation(context); - List appointmentTypes = AppointmentRestUtils.getAppointmentTypes(context); - - if (date == null || location == null) { - throw new ValidationException("appointmentscheduling.AppointmentBlock.error.scheduledAppointmentBlocks"); - } - - List dailyAppointmentBlocks = getScheduledAppointmentBlocks(date, location, - appointmentTypes); - - SimpleObject result = new SimpleObject(); - result.add("results", convertToSimpleObjectList(dailyAppointmentBlocks)); - - return result; - } - - private List getScheduledAppointmentBlocks(Date startDate, Location location, - List appointmentTypes) { - return Context.getService(AppointmentService.class).getDailyAppointmentBlocks(location, startDate, appointmentTypes); - } - - private Location getLocation(RequestContext context) { - return context.getParameter("location") != null ? Context.getLocationService().getLocationByUuid( - context.getParameter("location")) : null; - } - - private Date getDate(RequestContext context) { - return context.getParameter("date") != null ? (Date) ConversionUtil - .convert(context.getParameter("date"), Date.class) : null; - } - - private List convertToSimpleObjectList(List dailyAppointmentBlocks) { - List simpleObjects = new ArrayList(); - - for (ScheduledAppointmentBlock dailyAppointmentBlock : dailyAppointmentBlocks) { - simpleObjects.add(getSimpleObject(dailyAppointmentBlock)); - } - - return simpleObjects; - } - - private SimpleObject getSimpleObject(ScheduledAppointmentBlock dailyAppointmentBlock) { - SimpleObject simpleObject = new SimpleObject(); - simpleObject.add("appointmentBlock", getSimpleAppointmentBlock(dailyAppointmentBlock)); - simpleObject.add("appointments",getSimpleAppointments(dailyAppointmentBlock)); - return simpleObject; - } - - private Object getSimpleAppointmentBlock(ScheduledAppointmentBlock scheduledAppointmentBlock) { - return ConversionUtil.getPropertyWithRepresentation(scheduledAppointmentBlock, "appointmentBlock", Representation.DEFAULT); - } - - private List getSimpleAppointments(ScheduledAppointmentBlock scheduledAppointmentBlock) { - - List simpleAppointments = new ArrayList(); - - // we basically made are our custom representation here, because we want only the ref version of the time slot - // (because we already have the overall appointment block, which would be the save for every appointment), - // but we do want the default versions of the appointment type and patient - for (Appointment appointment : scheduledAppointmentBlock.getAppointments()) { - SimpleObject simpleAppointment = new SimpleObject(); - - simpleAppointment.add("timeSlot", ConversionUtil.getPropertyWithRepresentation(appointment, "timeSlot", Representation.REF)); - simpleAppointment.add("appointmentType", ConversionUtil.getPropertyWithRepresentation(appointment, "appointmentType", Representation.DEFAULT)); - simpleAppointment.add("patient", ConversionUtil.getPropertyWithRepresentation(appointment, "patient", Representation.DEFAULT)); - simpleAppointment.add("status", ConversionUtil.getPropertyWithRepresentation(appointment, "status", Representation.DEFAULT)); - simpleAppointment.add("reason", ConversionUtil.getPropertyWithRepresentation(appointment, "reason", Representation.DEFAULT)); - simpleAppointment.add("cancelReason", ConversionUtil.getPropertyWithRepresentation(appointment, "cancelReason", Representation.DEFAULT)); - // note that we don't return the visit because we don't care about it at this point - - simpleAppointments.add(simpleAppointment); - } - - return simpleAppointments; - } - - - @Override - public String getUri(Object delegate) { - - return RestConstants.URI_PREFIX + "/appointmentscheduling/scheduledappointmentblock/startDate=?"; - } - - private String getUniqueId(ScheduledAppointmentBlock delegate) { - try { - return (String) PropertyUtils.getProperty(delegate, "uuid"); - } - catch (Exception ex) { - throw new RuntimeException("Cannot find String uuid property on " + delegate.getClass(), null); - } - } - - @Override - public Object retrieve(String uuid, RequestContext context) throws ResponseException { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public List getAvailableRepresentations() { - return Arrays.asList(Representation.DEFAULT, Representation.FULL, Representation.REF); - } -} diff --git a/omod/src/test/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/ScheduledAppointmentBlockResource1_9Test.java b/omod/src/test/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/ScheduledAppointmentBlockResource1_9Test.java deleted file mode 100644 index 5ddb3049..00000000 --- a/omod/src/test/java/org/openmrs/module/appointmentscheduling/rest/resource/openmrs1_9/ScheduledAppointmentBlockResource1_9Test.java +++ /dev/null @@ -1,145 +0,0 @@ -package org.openmrs.module.appointmentscheduling.rest.resource.openmrs1_9; - -import javax.servlet.http.HttpServletRequest; -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.openmrs.module.webservices.rest.SimpleObject; -import org.openmrs.module.webservices.rest.web.RequestContext; -import org.openmrs.module.webservices.validation.ValidationException; -import org.openmrs.web.test.BaseModuleWebContextSensitiveTest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertFalse; -import static org.mockito.Mockito.when; - -public class ScheduledAppointmentBlockResource1_9Test extends BaseModuleWebContextSensitiveTest { - - @Before - public void setUp() throws Exception { - executeDataSet("standardWebAppointmentTestDataset.xml"); - } - - @Test - public void shouldSearchForScheduledAppointmentBlock() { - ScheduledAppointmentBlockResource1_9 scheduledAppointmentBlockResource1_9 = new ScheduledAppointmentBlockResource1_9(); - - RequestContext context = Mockito.mock(RequestContext.class); - HttpServletRequest request = Mockito.mock(HttpServletRequest.class); - - when(context.getParameter("date")).thenReturn("2005-01-03 00:00:00.0"); - when(context.getParameter("location")).thenReturn("9356400c-a5a2-4532-8f2b-2361b3446eb7"); - when(context.getRequest()).thenReturn(request); - when(request.getParameterValues("appointmentType")).thenReturn( - new String[] { "759799ab-c9a5-435e-b671-77773ada74e6" }); - - SimpleObject search = scheduledAppointmentBlockResource1_9.search(context); - assertSearchResults(search); - - List resultList = (List) search.get("results"); - assertRepresentationOfEachResult(resultList); - - SimpleObject firstResult = (SimpleObject) resultList.get(0); - - SimpleObject appointmentBlock = (SimpleObject) firstResult.get("appointmentBlock"); - assertAppointmentBlockResult(appointmentBlock); - - List appointments = (List) firstResult.get("appointments"); - assertAppointmentsResult(appointments); - - } - - private void assertAppointmentsResult(List appointments) { - assertEquals(2, appointments.size()); - - SimpleObject firstAppointment = (SimpleObject) appointments.get(0); - - assertTrue(firstAppointment.containsKey("patient")); - assertEquals("22b47970-8f52-11e3-baa8-0800200c9a66", ((SimpleObject) firstAppointment.get("patient")).get("uuid") - .toString()); - assertTrue(firstAppointment.containsKey("appointmentType")); - assertEquals("759799ab-c9a5-435e-b671-77773ada74e6", - ((SimpleObject) firstAppointment.get("appointmentType")).get("uuid").toString()); - - // make sure we aren't sending the appointment block along - SimpleObject firstTimeSlot = (SimpleObject) firstAppointment.get("timeSlot"); - assertFalse(firstTimeSlot.containsKey("appointmentBlock")); - - SimpleObject secondAppointment = (SimpleObject) appointments.get(1); - - assertTrue(secondAppointment.containsKey("patient")); - assertEquals("31e09960-8f52-11e3-baa8-0800200c9a66", ((SimpleObject) secondAppointment.get("patient")).get("uuid") - .toString()); - assertTrue(secondAppointment.containsKey("appointmentType")); - assertEquals("759799ab-c9a5-435e-b671-77773ada74e6", - ((SimpleObject) secondAppointment.get("appointmentType")).get("uuid").toString()); - - // make sure we aren't sending the appointment block along - SimpleObject secondTimeSlot = (SimpleObject) firstAppointment.get("timeSlot"); - assertFalse(secondTimeSlot.containsKey("appointmentBlock")); - - } - - private void assertAppointmentBlockResult(SimpleObject appointmentBlock) { - assertTrue(appointmentBlock.containsKey("provider")); - assertEquals("c0c54sd0-8e59-401d-8a4a-976a0b183599", ((SimpleObject) appointmentBlock.get("provider")).get("uuid") - .toString()); - - assertTrue(appointmentBlock.containsKey("location")); - assertEquals("9356400c-a5a2-4532-8f2b-2361b3446eb7", ((SimpleObject) appointmentBlock.get("location")).get("uuid") - .toString()); - - assertTrue(appointmentBlock.containsKey("startDate")); - assertEquals("2005-01-03T00:00:00.000-0500", appointmentBlock.get("startDate").toString()); - - assertTrue(appointmentBlock.containsKey("endDate")); - assertEquals("2005-01-03T11:00:00.000-0500", appointmentBlock.get("endDate").toString()); - } - - private void assertRepresentationOfEachResult(List results) { - SimpleObject firstResult = (SimpleObject) results.get(0); - - assertTrue(firstResult.containsKey("appointmentBlock")); - assertTrue(firstResult.containsKey("appointments")); - } - - private void assertSearchResults(SimpleObject search) { - assertNotNull(search); - assertTrue(search.containsKey("results")); - assertEquals(1, search.size()); - } - - @Test(expected = ValidationException.class) - public void shouldReturnErrorWhenDateParameterIsMissing() { - ScheduledAppointmentBlockResource1_9 scheduledAppointmentBlockResource1_9 = new ScheduledAppointmentBlockResource1_9(); - - RequestContext context = Mockito.mock(RequestContext.class); - HttpServletRequest request = Mockito.mock(HttpServletRequest.class); - - when(context.getParameter("date")).thenReturn(null); - when(context.getParameter("location")).thenReturn("9356400c-a5a2-4532-8f2b-2361b3446eb7"); - when(context.getRequest()).thenReturn(request); - when(request.getParameterValues("appointmentType")).thenReturn(null); - - scheduledAppointmentBlockResource1_9.search(context); - } - - @Test(expected = ValidationException.class) - public void shouldReturnErrorWhenLocationParameterIsMissing() { - ScheduledAppointmentBlockResource1_9 scheduledAppointmentBlockResource1_9 = new ScheduledAppointmentBlockResource1_9(); - - RequestContext context = Mockito.mock(RequestContext.class); - HttpServletRequest request = Mockito.mock(HttpServletRequest.class); - - when(context.getParameter("date")).thenReturn("2005-01-03 00:00:00.0"); - when(context.getParameter("location")).thenReturn(null); - when(context.getRequest()).thenReturn(request); - when(request.getParameterValues("appointmentType")).thenReturn(null); - - scheduledAppointmentBlockResource1_9.search(context); - } -}