ComplaintRouterService { public Position getComplaintAssignee(Complaint complaint) { ComplaintRouter complaintRouter = getComplaintRouter(complaint); if (complaintRouter == null) { if (LOGGER.isWarnEnabled()) { String complaintLocation = complaint.getLocation() == null ? EMPTY : complaint.getLocation().getName(); String complaintType = complaint.getComplaintType().getName(); LOGGER.warn("There is no routing defined for Complaint Type : {}, Location : {}", complaintType, complaintLocation); } throw new ApplicationValidationException("PGR.001"); } else { return complaintRouter.getPosition(); } }  Position getComplaintAssignee(Complaint complaint); @Transactional ComplaintRouter createComplaintRouter(ComplaintRouter complaintRouter); @Transactional ComplaintRouter updateComplaintRouter(ComplaintRouter complaintRouter); @Transactional void deleteComplaintRouter(ComplaintRouter complaintRouter); @Transactional void createBulkRouter(BulkRouterGenerator bulkRouterGenerator); Boolean validateRouter(ComplaintRouter complaintRouter); ComplaintRouter getExistingRouter(ComplaintRouter complaintRouter); ComplaintRouter getRouterById(Long id); @ReadOnly Page<ComplaintRouter> getComplaintRouter(ComplaintRouterSearchRequest routerSearchRequest); @ReadOnly ReportOutput generateRouterReport(ComplaintRouterSearchRequest reportCriteria); List<ComplaintRouter> getRoutersByComplaintTypeBoundary(List<ComplaintType> complaintTypes,
                                                                   List<Boundary> boundaries); ComplaintRouter getComplaintRouter(Complaint complaint); ComplaintRouter getComplaintRouterByComplaintTypeAndBoundaries(ComplaintType complaintType, List<Boundary> boundaries); ComplaintRouter getComplaintRouterByBoundaries(List<Boundary> boundaries);  }
@Test public void testGetAssigneeByTypeLocation() { complaint = new ComplaintBuilder().withComplaintType(complaintType).withLocation(ward).withDbDefaults().build(); final Position assignee = complaintRouterService.getComplaintAssignee(complaint); assertEquals(wardOfficer, assignee); }
@Test public void testGetAssigneeByType() { complaint = new ComplaintBuilder().withComplaintType(complaintType).withDbDefaults().build(); final Position assignee = complaintRouterService.getComplaintAssignee(complaint); assertEquals(healthInspector, assignee); }
@Test public void testGetAssigneeByBoundary() { complaint = new ComplaintBuilder().withComplaintType(complaintType).withLocation(zone).withDbDefaults().build(); final Position assignee = complaintRouterService.getComplaintAssignee(complaint); assertEquals(healthInspector, assignee); }
@Test(expected = ApplicationValidationException.class) public void testGetAssigneeByGoWithoutGoInsertion() { complaintType = new ComplaintTypeBuilder().withDbDefaults().build(); complaint = new ComplaintBuilder().withComplaintType(complaintType).withLocation(city).build(); final Position assignee = complaintRouterService.getComplaintAssignee(complaint); assertNull(assignee); }
@Test public void testGetAssigneeByGoAfterGoInsertion() { final ComplaintRouter GoPosition = new ComplaintRouterBuilder().withBoundary(city) .withPosition(grievanceOfficer).build(); when(complaintRouterRepository.findGrievanceOfficer()).thenReturn(GoPosition); complaint = new ComplaintBuilder().withComplaintType(complaintType).withLocation(city).withDbDefaults().build(); final Position assignee = complaintRouterService.getComplaintAssignee(complaint); assertEquals(healthInspector, assignee); }