From 7eee4a98dec3ff0af719295586ba76164779ac95 Mon Sep 17 00:00:00 2001 From: Kalaiyarasan Raja Date: Wed, 8 May 2024 16:51:45 +0530 Subject: [PATCH] Added test cases to increase branch coverage & set threshold to 0.60 --- api/pom.xml | 2 +- .../dao/impl/AppointmentDaoImplIT.java | 73 +++++++++++++++++++ .../impl/AppointmentsServiceImplTest.java | 11 +++ .../test/resources/appointmentTestData.xml | 2 +- 4 files changed, 86 insertions(+), 2 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 678a74be1..fcc8c1dda 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -87,7 +87,7 @@ BRANCH COVEREDRATIO - 0.65 + 0.60 diff --git a/api/src/test/java/org/openmrs/module/appointments/dao/impl/AppointmentDaoImplIT.java b/api/src/test/java/org/openmrs/module/appointments/dao/impl/AppointmentDaoImplIT.java index 42607becd..e36c75b00 100644 --- a/api/src/test/java/org/openmrs/module/appointments/dao/impl/AppointmentDaoImplIT.java +++ b/api/src/test/java/org/openmrs/module/appointments/dao/impl/AppointmentDaoImplIT.java @@ -268,4 +268,77 @@ public void shouldReturnDateLessAppointments() { assertNotNull(appointments); assertEquals(3, appointments.size()); } + + @Test + public void shouldReturnAppointmentsBasedOnAppointmentSearchRequestModelPatientAndLocation() { + + List allAppointments = appointmentDao.getAllAppointments(null); + AppointmentSearchRequestModel searchQuery = new AppointmentSearchRequestModel(); + List patientUuids=new ArrayList<>(); + patientUuids.add(allAppointments.get(0).getPatient().getUuid()); + List locationUuids=new ArrayList<>(); + locationUuids.add(allAppointments.get(0).getLocation().getUuid()); + + searchQuery.setPatientUuids(patientUuids); + searchQuery.setLocationUuids(locationUuids); + searchQuery.setStatus(null); + + List appointments = appointmentDao.search(searchQuery); + + assertNotNull(appointments); + assertEquals(3, appointments.size()); + } + + @Test + public void shouldReturnAppointmentsBasedOnAppointmentSearchRequestModelServiceAndServiceType() { + + List allAppointments = appointmentDao.getAllAppointments(null); + AppointmentSearchRequestModel searchQuery = new AppointmentSearchRequestModel(); + List serviceUuids=new ArrayList<>(); + serviceUuids.add(allAppointments.get(0).getService().getUuid()); + List serviceTypeUuids=new ArrayList<>(); + serviceTypeUuids.add(allAppointments.get(0).getServiceType().getUuid()); + + searchQuery.setServiceUuids(serviceUuids); + searchQuery.setServiceTypeUuids(serviceTypeUuids); + searchQuery.setStatus(null); + + List appointments = appointmentDao.search(searchQuery); + + assertNotNull(appointments); + assertEquals(2, appointments.size()); + } + + @Test + public void shouldReturnAppointmentsBasedOnAppointmentSearchRequestModelPriority() { + + List allAppointments = appointmentDao.getAllAppointments(null); + AppointmentSearchRequestModel searchQuery = new AppointmentSearchRequestModel(); + List priorities=new ArrayList<>(); + priorities.add("AsNeeded"); + + searchQuery.setPriorities(priorities); + searchQuery.setStatus(null); + + List appointments = appointmentDao.search(searchQuery); + + assertNotNull(appointments); + assertEquals(1, appointments.size()); + } + + @Test + public void shouldReturnEmptyAppointmentsBasedOnAppointmentSearchRequestModelProviderWhenNoAppointmentsAreAssignedToProvider() { + + AppointmentSearchRequestModel searchQuery = new AppointmentSearchRequestModel(); + List providerUuids=new ArrayList<>(); + providerUuids.add(UUID.randomUUID().toString()); + + searchQuery.setProviderUuids(providerUuids); + searchQuery.setStatus(null); + + List appointments = appointmentDao.search(searchQuery); + + assertNotNull(appointments); + assertEquals(0, appointments.size()); + } } diff --git a/api/src/test/java/org/openmrs/module/appointments/service/impl/AppointmentsServiceImplTest.java b/api/src/test/java/org/openmrs/module/appointments/service/impl/AppointmentsServiceImplTest.java index 9731a23bf..d5022f483 100644 --- a/api/src/test/java/org/openmrs/module/appointments/service/impl/AppointmentsServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/appointments/service/impl/AppointmentsServiceImplTest.java @@ -317,6 +317,17 @@ public void shouldSearchForAnAppointment() { verify(appointmentDao, times(1)).search(appointment); } + @Test + public void shouldSearchForAnAppointmentBasedOnAppointmentSearchRequestModel() { + AppointmentSearchRequestModel appointmentSearchRequestModel = new AppointmentSearchRequestModel(); + appointmentSearchRequestModel.setStatus("Scheduled"); + List appointmentList = new ArrayList<>(); + appointmentList.add(appointment); + when(appointmentDao.search(appointmentSearchRequestModel)).thenReturn(appointmentList); + appointmentsService.search(appointmentSearchRequestModel); + verify(appointmentDao, times(1)).search(appointmentSearchRequestModel); + } + @Test public void shouldThrowExceptionIfValidationFailsOnAppointmentSave() { String errorMessage = "Appointment cannot be created without Patient"; diff --git a/api/src/test/resources/appointmentTestData.xml b/api/src/test/resources/appointmentTestData.xml index bfaa79ddf..4b69620d7 100644 --- a/api/src/test/resources/appointmentTestData.xml +++ b/api/src/test/resources/appointmentTestData.xml @@ -35,7 +35,7 @@ - +