@Test public void shouldNotifyProgramsSupportedUpdateForParentAndVirtualFacility() throws Exception { Facility facility = mock(Facility.class); String facilityCode = "F1111"; List<ProgramSupported> supportedPrograms = new ArrayList<>(); when(facility.getCode()).thenReturn(facilityCode); when(facility.getSupportedPrograms()).thenReturn(supportedPrograms); ProgramSupportedEventDTO programSupportedEventDTO = mock(ProgramSupportedEventDTO.class); whenNew(ProgramSupportedEventDTO.class).withArguments(facilityCode, supportedPrograms).thenReturn(programSupportedEventDTO); Event event = mock(Event.class); when(programSupportedEventDTO.createEvent()).thenReturn(event); Facility mockVirtualFacility = mock(Facility.class); List<Facility> virtualFacilities = asList(mockVirtualFacility); when(facilityService.getChildFacilities(facility)).thenReturn(virtualFacilities); String virtualFacilityCode = "VVF1111"; when(mockVirtualFacility.getCode()).thenReturn(virtualFacilityCode); ProgramSupportedEventDTO virtualProgramSupportedEventDTO = mock(ProgramSupportedEventDTO.class); whenNew(ProgramSupportedEventDTO.class).withArguments(virtualFacilityCode, supportedPrograms).thenReturn(virtualProgramSupportedEventDTO); Event virtualFacilityEvent = mock(Event.class); when(virtualProgramSupportedEventDTO.createEvent()).thenReturn(virtualFacilityEvent); service.notifyProgramSupportedUpdated(facility); verify(eventService).notify(event); verify(eventService).notify(virtualFacilityEvent); }
public void notifyProgramSupportedUpdated(Facility facility) { try { List<ProgramSupported> programsSupported = facility.getSupportedPrograms(); ProgramSupportedEventDTO eventDTO = new ProgramSupportedEventDTO(facility.getCode(), programsSupported); eventService.notify(eventDTO.createEvent()); for (Facility virtualFacility : facilityService.getChildFacilities(facility)) { eventDTO = new ProgramSupportedEventDTO(virtualFacility.getCode(), programsSupported); eventService.notify(eventDTO.createEvent()); } } catch (URISyntaxException e) { logger.error("Failed to generate program supported event feed", e); } }
ProgramSupportedService { public void notifyProgramSupportedUpdated(Facility facility) { try { List<ProgramSupported> programsSupported = facility.getSupportedPrograms(); ProgramSupportedEventDTO eventDTO = new ProgramSupportedEventDTO(facility.getCode(), programsSupported); eventService.notify(eventDTO.createEvent()); for (Facility virtualFacility : facilityService.getChildFacilities(facility)) { eventDTO = new ProgramSupportedEventDTO(virtualFacility.getCode(), programsSupported); eventService.notify(eventDTO.createEvent()); } } catch (URISyntaxException e) { logger.error("Failed to generate program supported event feed", e); } } }
ProgramSupportedService { public void notifyProgramSupportedUpdated(Facility facility) { try { List<ProgramSupported> programsSupported = facility.getSupportedPrograms(); ProgramSupportedEventDTO eventDTO = new ProgramSupportedEventDTO(facility.getCode(), programsSupported); eventService.notify(eventDTO.createEvent()); for (Facility virtualFacility : facilityService.getChildFacilities(facility)) { eventDTO = new ProgramSupportedEventDTO(virtualFacility.getCode(), programsSupported); eventService.notify(eventDTO.createEvent()); } } catch (URISyntaxException e) { logger.error("Failed to generate program supported event feed", e); } }  }
ProgramSupportedService { public void notifyProgramSupportedUpdated(Facility facility) { try { List<ProgramSupported> programsSupported = facility.getSupportedPrograms(); ProgramSupportedEventDTO eventDTO = new ProgramSupportedEventDTO(facility.getCode(), programsSupported); eventService.notify(eventDTO.createEvent()); for (Facility virtualFacility : facilityService.getChildFacilities(facility)) { eventDTO = new ProgramSupportedEventDTO(virtualFacility.getCode(), programsSupported); eventService.notify(eventDTO.createEvent()); } } catch (URISyntaxException e) { logger.error("Failed to generate program supported event feed", e); } }  List<ProgramSupported> getAllByFacilityId(Long facilityId); void updateSupportedPrograms(Facility facility); ProgramSupported getFilledByFacilityIdAndProgramId(Long facilityId, Long programId); ProgramSupported getByFacilityIdAndProgramId(Long facilityId, Long programId); void uploadSupportedProgram(ProgramSupported programSupported); ProgramSupported getProgramSupported(ProgramSupported programSupported); void notifyProgramSupportedUpdated(Facility facility); List<ProgramSupported> getActiveByFacilityId(Long facilityId); void updateForVirtualFacilities(Facility parentFacility); }
ProgramSupportedService { public void notifyProgramSupportedUpdated(Facility facility) { try { List<ProgramSupported> programsSupported = facility.getSupportedPrograms(); ProgramSupportedEventDTO eventDTO = new ProgramSupportedEventDTO(facility.getCode(), programsSupported); eventService.notify(eventDTO.createEvent()); for (Facility virtualFacility : facilityService.getChildFacilities(facility)) { eventDTO = new ProgramSupportedEventDTO(virtualFacility.getCode(), programsSupported); eventService.notify(eventDTO.createEvent()); } } catch (URISyntaxException e) { logger.error("Failed to generate program supported event feed", e); } }  List<ProgramSupported> getAllByFacilityId(Long facilityId); void updateSupportedPrograms(Facility facility); ProgramSupported getFilledByFacilityIdAndProgramId(Long facilityId, Long programId); ProgramSupported getByFacilityIdAndProgramId(Long facilityId, Long programId); void uploadSupportedProgram(ProgramSupported programSupported); ProgramSupported getProgramSupported(ProgramSupported programSupported); void notifyProgramSupportedUpdated(Facility facility); List<ProgramSupported> getActiveByFacilityId(Long facilityId); void updateForVirtualFacilities(Facility parentFacility);  }